]>
Commit | Line | Data |
---|---|---|
c1f75dc3 | 1 | /* Measure memcpy functions. |
dff8da6b | 2 | Copyright (C) 2013-2024 Free Software Foundation, Inc. |
c1f75dc3 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 | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
c1f75dc3 SP |
18 | |
19 | #ifndef MEMCPY_RESULT | |
20 | # define MEMCPY_RESULT(dst, len) dst | |
21 | # define MIN_PAGE_SIZE 131072 | |
22 | # define TEST_MAIN | |
23 | # define TEST_NAME "memcpy" | |
24 | # include "bench-string.h" | |
25 | ||
3c05dd79 | 26 | void *generic_memcpy (void *, const void *, size_t); |
c1f75dc3 | 27 | |
16f87cfd | 28 | IMPL (memcpy, 1) |
3c05dd79 | 29 | IMPL (generic_memcpy, 0) |
16f87cfd | 30 | |
c1f75dc3 SP |
31 | #endif |
32 | ||
5ee1e3ce SP |
33 | # include "json-lib.h" |
34 | ||
3c05dd79 | 35 | typedef void *(*proto_t) (void *, const void *, size_t); |
c1f75dc3 SP |
36 | |
37 | static void | |
5ee1e3ce | 38 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src, |
c1f75dc3 SP |
39 | size_t len) |
40 | { | |
26234791 | 41 | size_t i, iters = INNER_LOOP_ITERS / 2; |
44558701 | 42 | timing_t start, stop, cur; |
5e6cce9b NG |
43 | for (i = 0; i < iters / 64; ++i) |
44 | { | |
45 | CALL (impl, dst, src, len); | |
46 | } | |
44558701 WN |
47 | TIMING_NOW (start); |
48 | for (i = 0; i < iters; ++i) | |
c1f75dc3 | 49 | { |
44558701 | 50 | CALL (impl, dst, src, len); |
c1f75dc3 | 51 | } |
44558701 WN |
52 | TIMING_NOW (stop); |
53 | ||
54 | TIMING_DIFF (cur, start, stop); | |
55 | ||
5ee1e3ce | 56 | json_element_double (json_ctx, (double) cur / (double) iters); |
c1f75dc3 SP |
57 | } |
58 | ||
59 | static void | |
fc335a0d NG |
60 | do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, |
61 | int both_ways) | |
c1f75dc3 SP |
62 | { |
63 | size_t i, j; | |
64 | char *s1, *s2; | |
fc335a0d | 65 | size_t repeats; |
5e6cce9b | 66 | align1 &= (getpagesize () - 1); |
c1f75dc3 SP |
67 | if (align1 + len >= page_size) |
68 | return; | |
69 | ||
5e6cce9b | 70 | align2 &= (getpagesize () - 1); |
c1f75dc3 SP |
71 | if (align2 + len >= page_size) |
72 | return; | |
73 | ||
74 | s1 = (char *) (buf1 + align1); | |
75 | s2 = (char *) (buf2 + align2); | |
76 | ||
fc335a0d NG |
77 | for (repeats = both_ways ? 2 : 1; repeats; --repeats) |
78 | { | |
79 | for (i = 0, j = 1; i < len; i++, j += 23) | |
80 | s1[i] = j; | |
c1f75dc3 | 81 | |
fc335a0d NG |
82 | json_element_object_begin (json_ctx); |
83 | json_attr_uint (json_ctx, "length", (double) len); | |
84 | json_attr_uint (json_ctx, "align1", (double) align1); | |
85 | json_attr_uint (json_ctx, "align2", (double) align2); | |
86 | json_attr_uint (json_ctx, "dst > src", (double) (s2 > s1)); | |
87 | json_array_begin (json_ctx, "timings"); | |
c1f75dc3 | 88 | |
fc335a0d NG |
89 | FOR_EACH_IMPL (impl, 0) |
90 | do_one_test (json_ctx, impl, s2, s1, len); | |
c1f75dc3 | 91 | |
fc335a0d NG |
92 | json_array_end (json_ctx); |
93 | json_element_object_end (json_ctx); | |
94 | ||
95 | s1 = (char *) (buf2 + align1); | |
96 | s2 = (char *) (buf1 + align2); | |
97 | } | |
c1f75dc3 SP |
98 | } |
99 | ||
100 | int | |
101 | test_main (void) | |
102 | { | |
5ee1e3ce | 103 | json_ctx_t json_ctx; |
c1f75dc3 | 104 | size_t i; |
5e6cce9b | 105 | size_t half_page = getpagesize () / 2; |
c1f75dc3 SP |
106 | test_init (); |
107 | ||
5ee1e3ce SP |
108 | json_init (&json_ctx, 0, stdout); |
109 | ||
110 | json_document_begin (&json_ctx); | |
111 | json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); | |
112 | ||
113 | json_attr_object_begin (&json_ctx, "functions"); | |
7ee38e60 | 114 | json_attr_object_begin (&json_ctx, TEST_NAME); |
5ee1e3ce SP |
115 | json_attr_string (&json_ctx, "bench-variant", "default"); |
116 | ||
117 | json_array_begin (&json_ctx, "ifuncs"); | |
c1f75dc3 | 118 | FOR_EACH_IMPL (impl, 0) |
5ee1e3ce SP |
119 | json_element_string (&json_ctx, impl->name); |
120 | json_array_end (&json_ctx); | |
c1f75dc3 | 121 | |
5ee1e3ce | 122 | json_array_begin (&json_ctx, "results"); |
c1f75dc3 SP |
123 | for (i = 0; i < 18; ++i) |
124 | { | |
fc335a0d NG |
125 | do_test (&json_ctx, 0, 0, 1 << i, 1); |
126 | do_test (&json_ctx, i, 0, 1 << i, 1); | |
5e6cce9b | 127 | do_test (&json_ctx, i + 32, 0, 1 << i, 1); |
fc335a0d | 128 | do_test (&json_ctx, 0, i, 1 << i, 1); |
5e6cce9b | 129 | do_test (&json_ctx, 0, i + 32, 1 << i, 1); |
fc335a0d | 130 | do_test (&json_ctx, i, i, 1 << i, 1); |
5e6cce9b NG |
131 | do_test (&json_ctx, i + 32, i + 32, 1 << i, 1); |
132 | do_test (&json_ctx, half_page, 0, 1 << i, 1); | |
133 | do_test (&json_ctx, half_page + i, 0, 1 << i, 1); | |
134 | do_test (&json_ctx, half_page, i, 1 << i, 1); | |
135 | do_test (&json_ctx, half_page + i, i, 1 << i, 1); | |
c1f75dc3 SP |
136 | } |
137 | ||
138 | for (i = 0; i < 32; ++i) | |
139 | { | |
fc335a0d NG |
140 | do_test (&json_ctx, 0, 0, i, 0); |
141 | do_test (&json_ctx, i, 0, i, 0); | |
142 | do_test (&json_ctx, 0, i, i, 0); | |
143 | do_test (&json_ctx, i, i, i, 0); | |
5e6cce9b NG |
144 | do_test (&json_ctx, half_page, 0, i, 0); |
145 | do_test (&json_ctx, half_page + i, 0, i, 0); | |
146 | do_test (&json_ctx, half_page, i, i, 0); | |
147 | do_test (&json_ctx, half_page + i, i, i, 0); | |
148 | do_test (&json_ctx, getpagesize () - 1, 0, i, 0); | |
149 | do_test (&json_ctx, 0, getpagesize () - 1, i, 0); | |
c1f75dc3 SP |
150 | } |
151 | ||
152 | for (i = 3; i < 32; ++i) | |
153 | { | |
154 | if ((i & (i - 1)) == 0) | |
5e6cce9b | 155 | continue; |
fc335a0d NG |
156 | do_test (&json_ctx, 0, 0, 16 * i, 1); |
157 | do_test (&json_ctx, i, 0, 16 * i, 1); | |
158 | do_test (&json_ctx, 0, i, 16 * i, 1); | |
159 | do_test (&json_ctx, i, i, 16 * i, 1); | |
5e6cce9b NG |
160 | do_test (&json_ctx, half_page, 0, 16 * i, 1); |
161 | do_test (&json_ctx, half_page + i, 0, 16 * i, 1); | |
162 | do_test (&json_ctx, half_page, i, 16 * i, 1); | |
163 | do_test (&json_ctx, half_page + i, i, 16 * i, 1); | |
c1f75dc3 SP |
164 | } |
165 | ||
32b28d24 L |
166 | for (i = 32; i < 64; ++i) |
167 | { | |
fc335a0d NG |
168 | do_test (&json_ctx, 0, 0, 32 * i, 1); |
169 | do_test (&json_ctx, i, 0, 32 * i, 1); | |
170 | do_test (&json_ctx, 0, i, 32 * i, 1); | |
171 | do_test (&json_ctx, i, i, 32 * i, 1); | |
5e6cce9b NG |
172 | do_test (&json_ctx, half_page, 0, 32 * i, 1); |
173 | do_test (&json_ctx, half_page + i, 0, 32 * i, 1); | |
174 | do_test (&json_ctx, half_page, i, 32 * i, 1); | |
175 | do_test (&json_ctx, half_page + i, i, 32 * i, 1); | |
32b28d24 L |
176 | } |
177 | ||
fc335a0d | 178 | do_test (&json_ctx, 0, 0, getpagesize (), 1); |
5ee1e3ce | 179 | |
5e6cce9b | 180 | for (i = 0; i <= 48; ++i) |
98544f5b | 181 | { |
fc335a0d NG |
182 | do_test (&json_ctx, 0, 0, 2048 + 64 * i, 1); |
183 | do_test (&json_ctx, i, 0, 2048 + 64 * i, 1); | |
5e6cce9b | 184 | do_test (&json_ctx, i + 32, 0, 2048 + 64 * i, 1); |
fc335a0d | 185 | do_test (&json_ctx, 0, i, 2048 + 64 * i, 1); |
5e6cce9b | 186 | do_test (&json_ctx, 0, i + 32, 2048 + 64 * i, 1); |
fc335a0d | 187 | do_test (&json_ctx, i, i, 2048 + 64 * i, 1); |
5e6cce9b NG |
188 | do_test (&json_ctx, i + 32, i + 32, 2048 + 64 * i, 1); |
189 | do_test (&json_ctx, half_page, 0, 2048 + 64 * i, 1); | |
190 | do_test (&json_ctx, half_page + i, 0, 2048 + 64 * i, 1); | |
191 | do_test (&json_ctx, half_page, i, 2048 + 64 * i, 1); | |
192 | do_test (&json_ctx, half_page + i, i, 2048 + 64 * i, 1); | |
193 | do_test (&json_ctx, i, 1, 2048 + 64 * i, 1); | |
194 | do_test (&json_ctx, 1, i, 2048 + 64 * i, 1); | |
195 | do_test (&json_ctx, i + 32, 1, 2048 + 64 * i, 1); | |
196 | do_test (&json_ctx, 1, i + 32, 2048 + 64 * i, 1); | |
197 | do_test (&json_ctx, half_page + i, 1, 2048 + 64 * i, 1); | |
198 | do_test (&json_ctx, half_page + 1, i, 2048 + 64 * i, 1); | |
98544f5b L |
199 | } |
200 | ||
5ee1e3ce SP |
201 | json_array_end (&json_ctx); |
202 | json_attr_object_end (&json_ctx); | |
203 | json_attr_object_end (&json_ctx); | |
204 | json_document_end (&json_ctx); | |
c1f75dc3 SP |
205 | |
206 | return ret; | |
207 | } | |
208 | ||
b598e134 | 209 | #include <support/test-driver.c> |
3c05dd79 WD |
210 | |
211 | #define libc_hidden_builtin_def(X) | |
212 | #undef MEMCPY | |
213 | #define MEMCPY generic_memcpy | |
214 | #include <string/memcpy.c> | |
215 | #include <string/wordcopy.c> |