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
14 #include "stringlib.h"
16 static const struct fun
19 void *(*fun
)(const void *, int c
, size_t n
);
25 # if __ARM_FEATURE_SVE
26 F(__memchr_aarch64_sve
)
35 static int test_status
;
36 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
41 static unsigned char sbuf
[LEN
+2*A
];
43 static void *alignup(void *p
)
45 return (void*)(((uintptr_t)p
+ A
-1) & -A
);
48 static void test(const struct fun
*fun
, int align
, int seekpos
, int len
)
50 unsigned char *src
= alignup(sbuf
);
51 unsigned char *s
= src
+ align
;
52 unsigned char *f
= len
? s
+ seekpos
: 0;
57 if (len
> LEN
|| seekpos
>= len
|| align
>= A
)
60 for (i
= 0; i
< seekpos
; i
++)
66 p
= fun
->fun(s
, seekchar
, len
);
69 ERR("%s(%p,0x%02x,%d) returned %p\n", fun
->name
, s
, seekchar
, len
, p
);
70 ERR("expected: %p\n", f
);
78 for (int i
=0; funtab
[i
].name
; i
++) {
80 for (int a
= 0; a
< A
; a
++) {
81 for (int n
= 0; n
< 100; n
++)
82 for (int sp
= 0; sp
< n
-1; sp
++)
83 test(funtab
+i
, a
, sp
, n
);
84 for (int n
= 100; n
< LEN
; n
*= 2) {
85 test(funtab
+i
, a
, n
-1, n
);
86 test(funtab
+i
, a
, n
/2, n
);
89 printf("%s %s\n", test_status
? "FAIL" : "PASS", funtab
[i
].name
);