Use common bits/shm.h for more architectures.
[glibc.git] / benchtests / bench-memmove.c
blob93de6719811d1226bc264462ab4b2508ce5c6b15
1 /* Measure memmove functions.
2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
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 #include "json-lib.h"
28 char *simple_memmove (char *, const char *, size_t);
30 #ifdef TEST_BCOPY
31 typedef void (*proto_t) (const char *, char *, size_t);
32 void simple_bcopy (const char *, char *, size_t);
34 IMPL (simple_bcopy, 0)
35 IMPL (bcopy, 1)
37 void
38 simple_bcopy (const char *src, char *dst, size_t n)
40 simple_memmove (dst, src, n);
42 #else
43 typedef char *(*proto_t) (char *, const char *, size_t);
45 IMPL (simple_memmove, 0)
46 IMPL (memmove, 1)
47 #endif
49 char *
50 inhibit_loop_to_libcall
51 simple_memmove (char *dst, const char *src, size_t n)
53 char *ret = dst;
54 if (src < dst)
56 dst += n;
57 src += n;
58 while (n--)
59 *--dst = *--src;
61 else
62 while (n--)
63 *dst++ = *src++;
64 return ret;
67 static void
68 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, const
69 char *orig_src, size_t len)
71 size_t i, iters = INNER_LOOP_ITERS;
72 timing_t start, stop, cur;
74 TIMING_NOW (start);
75 for (i = 0; i < iters; ++i)
77 #ifdef TEST_BCOPY
78 CALL (impl, src, dst, len);
79 #else
80 CALL (impl, dst, src, len);
81 #endif
83 TIMING_NOW (stop);
85 TIMING_DIFF (cur, start, stop);
87 json_element_double (json_ctx, (double) cur / (double) iters);
90 static void
91 do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
93 size_t i, j;
94 char *s1, *s2;
96 align1 &= 63;
97 if (align1 + len >= page_size)
98 return;
100 align2 &= 63;
101 if (align2 + len >= page_size)
102 return;
104 s1 = (char *) (buf1 + align1);
105 s2 = (char *) (buf2 + align2);
107 for (i = 0, j = 1; i < len; i++, j += 23)
108 s1[i] = j;
110 json_element_object_begin (json_ctx);
111 json_attr_uint (json_ctx, "length", (double) len);
112 json_attr_uint (json_ctx, "align1", (double) align1);
113 json_attr_uint (json_ctx, "align2", (double) align2);
114 json_array_begin (json_ctx, "timings");
116 FOR_EACH_IMPL (impl, 0)
117 do_one_test (json_ctx, impl, s2, (char *) (buf2 + align1), s1, len);
119 json_array_end (json_ctx);
120 json_element_object_end (json_ctx);
123 static int
124 test_main (void)
126 json_ctx_t json_ctx;
127 size_t i;
129 test_init ();
131 json_init (&json_ctx, 0, stdout);
133 json_document_begin (&json_ctx);
134 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
136 json_attr_object_begin (&json_ctx, "functions");
137 json_attr_object_begin (&json_ctx, "memmove");
138 json_attr_string (&json_ctx, "bench-variant", "default");
140 json_array_begin (&json_ctx, "ifuncs");
142 FOR_EACH_IMPL (impl, 0)
143 json_element_string (&json_ctx, impl->name);
144 json_array_end (&json_ctx);
146 json_array_begin (&json_ctx, "results");
147 for (i = 0; i < 14; ++i)
149 do_test (&json_ctx, 0, 32, 1 << i);
150 do_test (&json_ctx, 32, 0, 1 << i);
151 do_test (&json_ctx, 0, i, 1 << i);
152 do_test (&json_ctx, i, 0, 1 << i);
155 for (i = 0; i < 32; ++i)
157 do_test (&json_ctx, 0, 32, i);
158 do_test (&json_ctx, 32, 0, i);
159 do_test (&json_ctx, 0, i, i);
160 do_test (&json_ctx, i, 0, i);
163 for (i = 3; i < 32; ++i)
165 if ((i & (i - 1)) == 0)
166 continue;
167 do_test (&json_ctx, 0, 32, 16 * i);
168 do_test (&json_ctx, 32, 0, 16 * i);
169 do_test (&json_ctx, 0, i, 16 * i);
170 do_test (&json_ctx, i, 0, 16 * i);
173 for (i = 32; i < 64; ++i)
175 do_test (&json_ctx, 0, 0, 32 * i);
176 do_test (&json_ctx, i, 0, 32 * i);
177 do_test (&json_ctx, 0, i, 32 * i);
178 do_test (&json_ctx, i, i, 32 * i);
181 json_array_end (&json_ctx);
182 json_attr_object_end (&json_ctx);
183 json_attr_object_end (&json_ctx);
184 json_document_end (&json_ctx);
186 return ret;
189 #include <support/test-driver.c>