4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 * See https://llvm.org/LICENSE.txt for license information.
6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 #include "stringlib.h"
15 static const struct fun
18 int (*fun
)(const void *s1
, const void *s2
, size_t n
);
24 # if __ARM_FEATURE_SVE
25 F(__memcmp_aarch64_sve
)
32 static int test_status
;
33 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
37 static unsigned char s1buf
[LEN
+2*A
];
38 static unsigned char s2buf
[LEN
+2*A
];
40 static void *alignup(void *p
)
42 return (void*)(((uintptr_t)p
+ A
-1) & -A
);
45 static void test(const struct fun
*fun
, int s1align
, int s2align
, int len
, int diffpos
)
47 unsigned char *src1
= alignup(s1buf
);
48 unsigned char *src2
= alignup(s2buf
);
49 unsigned char *s1
= src1
+ s1align
;
50 unsigned char *s2
= src2
+ s2align
;
53 if (len
> LEN
|| s1align
>= A
|| s2align
>= A
)
55 if (diffpos
&& diffpos
>= len
)
58 for (int i
= 0; i
< len
+A
; i
++)
59 src1
[i
] = src2
[i
] = '?';
60 for (int i
= 0; i
< len
; i
++)
61 s1
[i
] = s2
[i
] = 'a' + i
%23;
65 r
= fun
->fun(s1
, s2
, len
);
67 if ((!diffpos
&& r
!= 0) || (diffpos
&& r
== 0)) {
68 ERR("%s(align %d, align %d, %d) failed, returned %d\n",
69 fun
->name
, s1align
, s2align
, len
, r
);
70 ERR("src1: %.*s\n", s1align
+len
+1, src1
);
71 ERR("src2: %.*s\n", s2align
+len
+1, src2
);
78 for (int i
=0; funtab
[i
].name
; i
++) {
80 for (int d
= 0; d
< A
; d
++)
81 for (int s
= 0; s
< A
; s
++) {
83 for (n
= 0; n
< 100; n
++) {
84 test(funtab
+i
, d
, s
, n
, 0);
85 test(funtab
+i
, d
, s
, n
, n
/ 2);
87 for (; n
< LEN
; n
*= 2) {
88 test(funtab
+i
, d
, s
, n
, 0);
89 test(funtab
+i
, d
, s
, n
, n
/ 2);
92 printf("%s %s\n", test_status
? "FAIL" : "PASS", funtab
[i
].name
);