[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / AOR_v20.02 / string / test / memmove.c
blob6bb9eee1c3d978ba52c0189fec0f575d7047f62b
1 /*
2 * memmove test.
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
7 */
9 #include <stdint.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "stringlib.h"
15 static const struct fun
17 const char *name;
18 void *(*fun)(void *, const void *, size_t);
19 } funtab[] = {
20 #define F(x) {#x, x},
21 F(memmove)
22 #if __aarch64__
23 F(__memmove_aarch64)
24 # if __ARM_NEON
25 F(__memmove_aarch64_simd)
26 # endif
27 #endif
28 #undef F
29 {0, 0}
32 static int test_status;
33 #define ERR(...) (test_status=1, printf(__VA_ARGS__))
35 #define A 32
36 #define LEN 250000
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;
54 void *p;
55 int i;
57 if (len > LEN || dalign >= A || salign >= A)
58 abort();
59 for (i = 0; i < len+A; i++) {
60 src[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);
67 if (p != d)
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);
74 break;
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;
87 void *p;
89 if (len > LEN || dalign >= A || salign >= A)
90 abort();
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. */
99 if (s < d) {
100 for (int i = 0; i < (uintptr_t)d-(uintptr_t)s; i++)
101 want[salign+i] = src[salign+i];
102 } else {
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);
108 if (p != d)
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);
115 abort();
116 break;
121 int main()
123 test_overlap(funtab+0, 2, 1, 1);
125 int r = 0;
126 for (int i=0; funtab[i].name; i++) {
127 test_status = 0;
128 for (int d = 0; d < A; d++)
129 for (int s = 0; s < A; s++) {
130 int n;
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);
141 if (test_status)
142 r = -1;
144 return r;