]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memmove.c
robust mutexes: Fix broken x86 assembly by removing it
[thirdparty/glibc.git] / benchtests / bench-memmove.c
CommitLineData
97020474 1/* Measure memmove functions.
bfff8b1b 2 Copyright (C) 2013-2017 Free Software Foundation, Inc.
97020474
SP
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#define TEST_MAIN
20#ifdef TEST_BCOPY
21# define TEST_NAME "bcopy"
22#else
23# define TEST_NAME "memmove"
24#endif
25#include "bench-string.h"
26
27char *simple_memmove (char *, const char *, size_t);
28
29#ifdef TEST_BCOPY
30typedef void (*proto_t) (const char *, char *, size_t);
31void simple_bcopy (const char *, char *, size_t);
32
33IMPL (simple_bcopy, 0)
34IMPL (bcopy, 1)
35
36void
37simple_bcopy (const char *src, char *dst, size_t n)
38{
39 simple_memmove (dst, src, n);
40}
41#else
42typedef char *(*proto_t) (char *, const char *, size_t);
43
44IMPL (simple_memmove, 0)
45IMPL (memmove, 1)
46#endif
47
48char *
85c2e611 49inhibit_loop_to_libcall
97020474
SP
50simple_memmove (char *dst, const char *src, size_t n)
51{
52 char *ret = dst;
53 if (src < dst)
54 {
55 dst += n;
56 src += n;
57 while (n--)
58 *--dst = *--src;
59 }
60 else
61 while (n--)
62 *dst++ = *src++;
63 return ret;
64}
65
66static void
67do_one_test (impl_t *impl, char *dst, char *src, const char *orig_src,
68 size_t len)
69{
44558701
WN
70 size_t i, iters = INNER_LOOP_ITERS;
71 timing_t start, stop, cur;
72
447720b0 73 /* This also clears the destination buffer set by the previous run. */
97020474
SP
74 memcpy (src, orig_src, len);
75#ifdef TEST_BCOPY
76 CALL (impl, src, dst, len);
77#else
78 char *res;
79
80 res = CALL (impl, dst, src, len);
81 if (res != dst)
82 {
83 error (0, 0, "Wrong result in function %s %p %p", impl->name,
84 res, dst);
85 ret = 1;
86 return;
87 }
88#endif
89
90 if (memcmp (dst, orig_src, len) != 0)
91 {
92 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
93 impl->name, dst, src);
94 ret = 1;
95 return;
96 }
97
44558701
WN
98 TIMING_NOW (start);
99 for (i = 0; i < iters; ++i)
97020474 100 {
97020474 101#ifdef TEST_BCOPY
44558701 102 CALL (impl, src, dst, len);
97020474 103#else
44558701 104 CALL (impl, dst, src, len);
97020474 105#endif
97020474 106 }
44558701
WN
107 TIMING_NOW (stop);
108
109 TIMING_DIFF (cur, start, stop);
110
111 TIMING_PRINT_MEAN ((double) cur, (double) iters);
97020474
SP
112}
113
114static void
115do_test (size_t align1, size_t align2, size_t len)
116{
117 size_t i, j;
118 char *s1, *s2;
119
120 align1 &= 63;
121 if (align1 + len >= page_size)
122 return;
123
124 align2 &= 63;
125 if (align2 + len >= page_size)
126 return;
127
128 s1 = (char *) (buf1 + align1);
129 s2 = (char *) (buf2 + align2);
130
131 for (i = 0, j = 1; i < len; i++, j += 23)
132 s1[i] = j;
133
44558701 134 printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
97020474
SP
135
136 FOR_EACH_IMPL (impl, 0)
137 do_one_test (impl, s2, (char *) (buf2 + align1), s1, len);
138
44558701 139 putchar ('\n');
97020474
SP
140}
141
b598e134 142static int
97020474
SP
143test_main (void)
144{
145 size_t i;
146
147 test_init ();
148
149 printf ("%23s", "");
150 FOR_EACH_IMPL (impl, 0)
151 printf ("\t%s", impl->name);
152 putchar ('\n');
153
154 for (i = 0; i < 14; ++i)
155 {
156 do_test (0, 32, 1 << i);
157 do_test (32, 0, 1 << i);
158 do_test (0, i, 1 << i);
159 do_test (i, 0, 1 << i);
160 }
161
162 for (i = 0; i < 32; ++i)
163 {
164 do_test (0, 32, i);
165 do_test (32, 0, i);
166 do_test (0, i, i);
167 do_test (i, 0, i);
168 }
169
170 for (i = 3; i < 32; ++i)
171 {
172 if ((i & (i - 1)) == 0)
173 continue;
174 do_test (0, 32, 16 * i);
175 do_test (32, 0, 16 * i);
176 do_test (0, i, 16 * i);
177 do_test (i, 0, 16 * i);
178 }
179
aea44bf6
L
180 for (i = 32; i < 64; ++i)
181 {
182 do_test (0, 0, 32 * i);
183 do_test (i, 0, 32 * i);
184 do_test (0, i, 32 * i);
185 do_test (i, i, 32 * i);
186 }
187
97020474
SP
188 return ret;
189}
190
b598e134 191#include <support/test-driver.c>