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 void *(*fun
)(void *, const void *, size_t);
25 F(__memmove_aarch64_simd
)
32 static int test_status
;
33 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
37 static unsigned char dbuf
[LEN
+2*A
];
38 static unsigned char sbuf
[LEN
+2*A
];
39 static unsigned char wbuf
[LEN
+2*A
];
41 static void *alignup(void *p
)
43 return (void*)(((uintptr_t)p
+ A
-1) & -A
);
46 static void test(const struct fun
*fun
, int dalign
, int salign
, int len
)
48 unsigned char *src
= alignup(sbuf
);
49 unsigned char *dst
= alignup(dbuf
);
50 unsigned char *want
= wbuf
;
51 unsigned char *s
= src
+ salign
;
52 unsigned char *d
= dst
+ dalign
;
53 unsigned char *w
= want
+ dalign
;
57 if (len
> LEN
|| dalign
>= A
|| salign
>= A
)
59 for (i
= 0; i
< len
+A
; i
++) {
61 want
[i
] = dst
[i
] = '*';
63 for (i
= 0; i
< len
; i
++)
64 s
[i
] = w
[i
] = 'a' + i
%23;
66 p
= fun
->fun(d
, s
, len
);
68 ERR("%s(%p,..) returned %p\n", fun
->name
, d
, p
);
69 for (i
= 0; i
< len
+A
; i
++) {
70 if (dst
[i
] != want
[i
]) {
71 ERR("%s(align %d, align %d, %d) failed\n", fun
->name
, dalign
, salign
, len
);
72 ERR("got : %.*s\n", dalign
+len
+1, dst
);
73 ERR("want: %.*s\n", dalign
+len
+1, want
);
79 static void test_overlap(const struct fun
*fun
, int dalign
, int salign
, int len
)
81 unsigned char *src
= alignup(sbuf
);
82 unsigned char *dst
= alignup(sbuf
);
83 unsigned char *want
= wbuf
;
84 unsigned char *s
= src
+ salign
;
85 unsigned char *d
= dst
+ dalign
;
86 unsigned char *w
= wbuf
+ dalign
;
89 if (len
> LEN
|| dalign
>= A
|| salign
>= A
)
92 for (int i
= 0; i
< len
+A
; i
++)
93 src
[i
] = want
[i
] = '?';
95 for (int i
= 0; i
< len
; i
++)
96 s
[i
] = w
[i
] = 'a' + i
%23;
98 /* Copy the potential overlap range. */
100 for (int i
= 0; i
< (uintptr_t)d
-(uintptr_t)s
; i
++)
101 want
[salign
+i
] = src
[salign
+i
];
103 for (int i
= 0; i
< (uintptr_t)s
-(uintptr_t)d
; i
++)
104 want
[len
+ dalign
+ i
] = src
[len
+ dalign
+ i
];
107 p
= fun
->fun(d
, s
, len
);
109 ERR("%s(%p,..) returned %p\n", fun
->name
, d
, p
);
110 for (int i
= 0; i
< len
+A
; i
++) {
111 if (dst
[i
] != want
[i
]) {
112 ERR("%s(align %d, align %d, %d) failed\n", fun
->name
, dalign
, salign
, len
);
113 ERR("got : %.*s\n", dalign
+len
+1, dst
);
114 ERR("want: %.*s\n", dalign
+len
+1, want
);
123 test_overlap(funtab
+0, 2, 1, 1);
126 for (int i
=0; funtab
[i
].name
; i
++) {
128 for (int d
= 0; d
< A
; d
++)
129 for (int s
= 0; s
< A
; s
++) {
131 for (n
= 0; n
< 100; n
++) {
132 test(funtab
+i
, d
, s
, n
);
133 test_overlap(funtab
+i
, d
, s
, n
);
135 for (; n
< LEN
; n
*= 2) {
136 test(funtab
+i
, d
, s
, n
);
137 test_overlap(funtab
+i
, d
, s
, n
);
140 printf("%s %s\n", test_status
? "FAIL" : "PASS", funtab
[i
].name
);