]>
Commit | Line | Data |
---|---|---|
97020474 | 1 | /* Measure memset functions. |
f7a9f785 | 2 | Copyright (C) 2013-2016 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 | ||
45 | CHAR *SIMPLE_MEMSET (CHAR *, int, size_t); | |
97020474 SP |
46 | |
47 | #ifdef TEST_BZERO | |
48 | typedef void (*proto_t) (char *, size_t); | |
49 | void simple_bzero (char *, size_t); | |
50 | void builtin_bzero (char *, size_t); | |
51 | ||
52 | IMPL (simple_bzero, 0) | |
53 | IMPL (builtin_bzero, 0) | |
54 | IMPL (bzero, 1) | |
55 | ||
56 | void | |
57 | simple_bzero (char *s, size_t n) | |
58 | { | |
2e9e1667 | 59 | SIMPLE_MEMSET (s, 0, n); |
97020474 SP |
60 | } |
61 | ||
62 | void | |
63 | builtin_bzero (char *s, size_t n) | |
64 | { | |
65 | __builtin_bzero (s, n); | |
66 | } | |
67 | #else | |
2e9e1667 | 68 | typedef CHAR *(*proto_t) (CHAR *, int, size_t); |
97020474 | 69 | |
2e9e1667 SL |
70 | IMPL (SIMPLE_MEMSET, 0) |
71 | # ifndef WIDE | |
72 | char *builtin_memset (char *, int, size_t); | |
97020474 | 73 | IMPL (builtin_memset, 0) |
2e9e1667 SL |
74 | # endif /* !WIDE */ |
75 | IMPL (MEMSET, 1) | |
97020474 | 76 | |
2e9e1667 | 77 | # ifndef WIDE |
97020474 SP |
78 | char * |
79 | builtin_memset (char *s, int c, size_t n) | |
80 | { | |
81 | return __builtin_memset (s, c, n); | |
82 | } | |
2e9e1667 SL |
83 | # endif /* !WIDE */ |
84 | #endif /* !TEST_BZERO */ | |
97020474 | 85 | |
2e9e1667 | 86 | CHAR * |
85c2e611 | 87 | inhibit_loop_to_libcall |
2e9e1667 | 88 | SIMPLE_MEMSET (CHAR *s, int c, size_t n) |
97020474 | 89 | { |
2e9e1667 | 90 | CHAR *r = s, *end = s + n; |
97020474 SP |
91 | while (r < end) |
92 | *r++ = c; | |
93 | return s; | |
94 | } | |
95 | ||
96 | static void | |
2e9e1667 | 97 | do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n) |
97020474 | 98 | { |
44558701 WN |
99 | size_t i, iters = INNER_LOOP_ITERS; |
100 | timing_t start, stop, cur; | |
2e9e1667 | 101 | CHAR tstbuf[n]; |
97020474 SP |
102 | #ifdef TEST_BZERO |
103 | simple_bzero (tstbuf, n); | |
104 | CALL (impl, s, n); | |
105 | if (memcmp (s, tstbuf, n) != 0) | |
106 | #else | |
2e9e1667 | 107 | CHAR *res = CALL (impl, s, c, n); |
97020474 | 108 | if (res != s |
2e9e1667 SL |
109 | || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf |
110 | || MEMCMP (s, tstbuf, n) != 0) | |
111 | #endif /* !TEST_BZERO */ | |
97020474 SP |
112 | { |
113 | error (0, 0, "Wrong result in function %s", impl->name); | |
114 | ret = 1; | |
115 | return; | |
116 | } | |
117 | ||
44558701 WN |
118 | TIMING_NOW (start); |
119 | for (i = 0; i < iters; ++i) | |
97020474 | 120 | { |
97020474 | 121 | #ifdef TEST_BZERO |
44558701 | 122 | CALL (impl, s, n); |
97020474 | 123 | #else |
44558701 | 124 | CALL (impl, s, c, n); |
2e9e1667 | 125 | #endif /* !TEST_BZERO */ |
44558701 WN |
126 | } |
127 | TIMING_NOW (stop); | |
97020474 | 128 | |
44558701 | 129 | TIMING_DIFF (cur, start, stop); |
97020474 | 130 | |
44558701 | 131 | TIMING_PRINT_MEAN ((double) cur, (double) iters); |
97020474 SP |
132 | } |
133 | ||
134 | static void | |
135 | do_test (size_t align, int c, size_t len) | |
136 | { | |
137 | align &= 7; | |
2e9e1667 | 138 | if ((align + len) * sizeof (CHAR) > page_size) |
97020474 SP |
139 | return; |
140 | ||
44558701 | 141 | printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c); |
97020474 SP |
142 | |
143 | FOR_EACH_IMPL (impl, 0) | |
2e9e1667 | 144 | do_one_test (impl, (CHAR *) (buf1) + align, c, len); |
97020474 | 145 | |
44558701 | 146 | putchar ('\n'); |
97020474 SP |
147 | } |
148 | ||
149 | int | |
150 | test_main (void) | |
151 | { | |
152 | size_t i; | |
153 | int c = 0; | |
154 | ||
155 | test_init (); | |
156 | ||
157 | printf ("%24s", ""); | |
158 | FOR_EACH_IMPL (impl, 0) | |
159 | printf ("\t%s", impl->name); | |
160 | putchar ('\n'); | |
161 | ||
162 | #ifndef TEST_BZERO | |
163 | for (c = -65; c <= 130; c += 65) | |
164 | #endif | |
165 | { | |
166 | for (i = 0; i < 18; ++i) | |
167 | do_test (0, c, 1 << i); | |
168 | for (i = 1; i < 32; ++i) | |
169 | { | |
170 | do_test (i, c, i); | |
171 | if (i & (i - 1)) | |
172 | do_test (0, c, i); | |
173 | } | |
71ae8647 AZ |
174 | for (i = 32; i < 512; i+=32) |
175 | { | |
176 | do_test (0, c, i); | |
177 | do_test (i, c, i); | |
178 | } | |
97020474 SP |
179 | do_test (1, c, 14); |
180 | do_test (3, c, 1024); | |
181 | do_test (4, c, 64); | |
182 | do_test (2, c, 25); | |
183 | } | |
184 | ||
185 | return ret; | |
186 | } | |
187 | ||
188 | #include "../test-skeleton.c" |