]>
Commit | Line | Data |
---|---|---|
97020474 | 1 | /* Measure memset functions. |
688903eb | 2 | Copyright (C) 2013-2018 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_BZERO | |
21 | # define TEST_NAME "bzero" | |
22 | #else | |
2e9e1667 SL |
23 | # ifndef WIDE |
24 | # define TEST_NAME "memset" | |
25 | # else | |
26 | # define TEST_NAME "wmemset" | |
27 | # endif /* WIDE */ | |
28 | #endif /* !TEST_BZERO */ | |
97020474 SP |
29 | #define MIN_PAGE_SIZE 131072 |
30 | #include "bench-string.h" | |
31 | ||
2e9e1667 SL |
32 | #ifndef WIDE |
33 | # define MEMSET memset | |
34 | # define CHAR char | |
35 | # define SIMPLE_MEMSET simple_memset | |
36 | # define MEMCMP memcmp | |
37 | #else | |
38 | # include <wchar.h> | |
39 | # define MEMSET wmemset | |
40 | # define CHAR wchar_t | |
41 | # define SIMPLE_MEMSET simple_wmemset | |
42 | # define MEMCMP wmemcmp | |
43 | #endif /* WIDE */ | |
44 | ||
29c933fb SP |
45 | #include "json-lib.h" |
46 | ||
2e9e1667 | 47 | CHAR *SIMPLE_MEMSET (CHAR *, int, size_t); |
97020474 SP |
48 | |
49 | #ifdef TEST_BZERO | |
50 | typedef void (*proto_t) (char *, size_t); | |
51 | void simple_bzero (char *, size_t); | |
52 | void builtin_bzero (char *, size_t); | |
53 | ||
54 | IMPL (simple_bzero, 0) | |
55 | IMPL (builtin_bzero, 0) | |
56 | IMPL (bzero, 1) | |
57 | ||
58 | void | |
59 | simple_bzero (char *s, size_t n) | |
60 | { | |
2e9e1667 | 61 | SIMPLE_MEMSET (s, 0, n); |
97020474 SP |
62 | } |
63 | ||
64 | void | |
65 | builtin_bzero (char *s, size_t n) | |
66 | { | |
67 | __builtin_bzero (s, n); | |
68 | } | |
69 | #else | |
2e9e1667 | 70 | typedef CHAR *(*proto_t) (CHAR *, int, size_t); |
97020474 | 71 | |
2e9e1667 SL |
72 | IMPL (SIMPLE_MEMSET, 0) |
73 | # ifndef WIDE | |
74 | char *builtin_memset (char *, int, size_t); | |
97020474 | 75 | IMPL (builtin_memset, 0) |
2e9e1667 SL |
76 | # endif /* !WIDE */ |
77 | IMPL (MEMSET, 1) | |
97020474 | 78 | |
2e9e1667 | 79 | # ifndef WIDE |
97020474 SP |
80 | char * |
81 | builtin_memset (char *s, int c, size_t n) | |
82 | { | |
83 | return __builtin_memset (s, c, n); | |
84 | } | |
2e9e1667 SL |
85 | # endif /* !WIDE */ |
86 | #endif /* !TEST_BZERO */ | |
97020474 | 87 | |
2e9e1667 | 88 | CHAR * |
85c2e611 | 89 | inhibit_loop_to_libcall |
2e9e1667 | 90 | SIMPLE_MEMSET (CHAR *s, int c, size_t n) |
97020474 | 91 | { |
2e9e1667 | 92 | CHAR *r = s, *end = s + n; |
97020474 SP |
93 | while (r < end) |
94 | *r++ = c; | |
95 | return s; | |
96 | } | |
97 | ||
98 | static void | |
29c933fb SP |
99 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, |
100 | int c __attribute ((unused)), size_t n) | |
97020474 | 101 | { |
44558701 WN |
102 | size_t i, iters = INNER_LOOP_ITERS; |
103 | timing_t start, stop, cur; | |
97020474 | 104 | |
44558701 WN |
105 | TIMING_NOW (start); |
106 | for (i = 0; i < iters; ++i) | |
97020474 | 107 | { |
97020474 | 108 | #ifdef TEST_BZERO |
44558701 | 109 | CALL (impl, s, n); |
97020474 | 110 | #else |
44558701 | 111 | CALL (impl, s, c, n); |
2e9e1667 | 112 | #endif /* !TEST_BZERO */ |
44558701 WN |
113 | } |
114 | TIMING_NOW (stop); | |
97020474 | 115 | |
44558701 | 116 | TIMING_DIFF (cur, start, stop); |
97020474 | 117 | |
29c933fb | 118 | json_element_double (json_ctx, (double) cur / (double) iters); |
97020474 SP |
119 | } |
120 | ||
121 | static void | |
29c933fb | 122 | do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len) |
97020474 | 123 | { |
344303f3 | 124 | align &= 63; |
2e9e1667 | 125 | if ((align + len) * sizeof (CHAR) > page_size) |
97020474 SP |
126 | return; |
127 | ||
29c933fb SP |
128 | json_element_object_begin (json_ctx); |
129 | json_attr_uint (json_ctx, "length", len); | |
130 | json_attr_uint (json_ctx, "alignment", align); | |
131 | json_attr_int (json_ctx, "char", c); | |
132 | json_array_begin (json_ctx, "timings"); | |
97020474 SP |
133 | |
134 | FOR_EACH_IMPL (impl, 0) | |
503c92c3 SP |
135 | { |
136 | do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len); | |
137 | realloc_bufs (); | |
138 | } | |
97020474 | 139 | |
29c933fb SP |
140 | json_array_end (json_ctx); |
141 | json_element_object_end (json_ctx); | |
97020474 SP |
142 | } |
143 | ||
144 | int | |
145 | test_main (void) | |
146 | { | |
29c933fb | 147 | json_ctx_t json_ctx; |
97020474 SP |
148 | size_t i; |
149 | int c = 0; | |
150 | ||
151 | test_init (); | |
152 | ||
29c933fb SP |
153 | json_init (&json_ctx, 0, stdout); |
154 | ||
155 | json_document_begin (&json_ctx); | |
156 | json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); | |
157 | ||
158 | json_attr_object_begin (&json_ctx, "functions"); | |
159 | json_attr_object_begin (&json_ctx, TEST_NAME); | |
160 | json_attr_string (&json_ctx, "bench-variant", ""); | |
161 | ||
162 | json_array_begin (&json_ctx, "ifuncs"); | |
97020474 | 163 | FOR_EACH_IMPL (impl, 0) |
29c933fb SP |
164 | json_element_string (&json_ctx, impl->name); |
165 | json_array_end (&json_ctx); | |
166 | ||
167 | json_array_begin (&json_ctx, "results"); | |
97020474 SP |
168 | |
169 | #ifndef TEST_BZERO | |
170 | for (c = -65; c <= 130; c += 65) | |
171 | #endif | |
172 | { | |
173 | for (i = 0; i < 18; ++i) | |
29c933fb | 174 | do_test (&json_ctx, 0, c, 1 << i); |
97020474 SP |
175 | for (i = 1; i < 32; ++i) |
176 | { | |
29c933fb | 177 | do_test (&json_ctx, i, c, i); |
97020474 | 178 | if (i & (i - 1)) |
29c933fb | 179 | do_test (&json_ctx, 0, c, i); |
97020474 | 180 | } |
71ae8647 AZ |
181 | for (i = 32; i < 512; i+=32) |
182 | { | |
29c933fb SP |
183 | do_test (&json_ctx, 0, c, i); |
184 | do_test (&json_ctx, i, c, i); | |
71ae8647 | 185 | } |
29c933fb SP |
186 | do_test (&json_ctx, 1, c, 14); |
187 | do_test (&json_ctx, 3, c, 1024); | |
188 | do_test (&json_ctx, 4, c, 64); | |
189 | do_test (&json_ctx, 2, c, 25); | |
97020474 | 190 | } |
344303f3 L |
191 | for (i = 33; i <= 256; i += 4) |
192 | { | |
29c933fb SP |
193 | do_test (&json_ctx, 0, c, 32 * i); |
194 | do_test (&json_ctx, i, c, 32 * i); | |
344303f3 | 195 | } |
97020474 | 196 | |
29c933fb SP |
197 | json_array_end (&json_ctx); |
198 | json_attr_object_end (&json_ctx); | |
199 | json_attr_object_end (&json_ctx); | |
200 | json_document_end (&json_ctx); | |
201 | ||
97020474 SP |
202 | return ret; |
203 | } | |
204 | ||
b598e134 | 205 | #include <support/test-driver.c> |