tile: switch to using <fenv.h> fallback functions
[glibc.git] / benchtests / bench-memset.c
blobea29cf37fc43d56e7f268f7e07ebbc440c7743f9
1 /* Measure memset functions.
2 Copyright (C) 2013 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_BZERO
21 # define TEST_NAME "bzero"
22 #else
23 # define TEST_NAME "memset"
24 #endif
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
28 char *simple_memset (char *, int, size_t);
30 #ifdef TEST_BZERO
31 typedef void (*proto_t) (char *, size_t);
32 void simple_bzero (char *, size_t);
33 void builtin_bzero (char *, size_t);
35 IMPL (simple_bzero, 0)
36 IMPL (builtin_bzero, 0)
37 IMPL (bzero, 1)
39 void
40 simple_bzero (char *s, size_t n)
42 simple_memset (s, 0, n);
45 void
46 builtin_bzero (char *s, size_t n)
48 __builtin_bzero (s, n);
50 #else
51 typedef char *(*proto_t) (char *, int, size_t);
52 char *builtin_memset (char *, int, size_t);
54 IMPL (simple_memset, 0)
55 IMPL (builtin_memset, 0)
56 IMPL (memset, 1)
58 char *
59 builtin_memset (char *s, int c, size_t n)
61 return __builtin_memset (s, c, n);
63 #endif
65 char *
66 inhibit_loop_to_libcall
67 simple_memset (char *s, int c, size_t n)
69 char *r = s, *end = s + n;
70 while (r < end)
71 *r++ = c;
72 return s;
75 static void
76 do_one_test (impl_t *impl, char *s, int c __attribute ((unused)), size_t n)
78 char tstbuf[n];
79 #ifdef TEST_BZERO
80 simple_bzero (tstbuf, n);
81 CALL (impl, s, n);
82 if (memcmp (s, tstbuf, n) != 0)
83 #else
84 char *res = CALL (impl, s, c, n);
85 if (res != s
86 || simple_memset (tstbuf, c, n) != tstbuf
87 || memcmp (s, tstbuf, n) != 0)
88 #endif
90 error (0, 0, "Wrong result in function %s", impl->name);
91 ret = 1;
92 return;
95 if (HP_TIMING_AVAIL)
97 hp_timing_t start __attribute ((unused));
98 hp_timing_t stop __attribute ((unused));
99 hp_timing_t best_time = ~ (hp_timing_t) 0;
100 size_t i;
102 for (i = 0; i < 32; ++i)
104 HP_TIMING_NOW (start);
105 #ifdef TEST_BZERO
106 CALL (impl, s, n);
107 #else
108 CALL (impl, s, c, n);
109 #endif
111 HP_TIMING_NOW (stop);
112 HP_TIMING_BEST (best_time, start, stop);
115 printf ("\t%zd", (size_t) best_time);
119 static void
120 do_test (size_t align, int c, size_t len)
122 align &= 7;
123 if (align + len > page_size)
124 return;
126 if (HP_TIMING_AVAIL)
127 printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
129 FOR_EACH_IMPL (impl, 0)
130 do_one_test (impl, (char *) buf1 + align, c, len);
132 if (HP_TIMING_AVAIL)
133 putchar ('\n');
137 test_main (void)
139 size_t i;
140 int c = 0;
142 test_init ();
144 printf ("%24s", "");
145 FOR_EACH_IMPL (impl, 0)
146 printf ("\t%s", impl->name);
147 putchar ('\n');
149 #ifndef TEST_BZERO
150 for (c = -65; c <= 130; c += 65)
151 #endif
153 for (i = 0; i < 18; ++i)
154 do_test (0, c, 1 << i);
155 for (i = 1; i < 32; ++i)
157 do_test (i, c, i);
158 if (i & (i - 1))
159 do_test (0, c, i);
161 do_test (1, c, 14);
162 do_test (3, c, 1024);
163 do_test (4, c, 64);
164 do_test (2, c, 25);
167 return ret;
170 #include "../test-skeleton.c"