1 /* Measure memset functions.
2 Copyright (C) 2013-2016 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/>. */
21 # define TEST_NAME "bzero"
24 # define TEST_NAME "memset"
26 # define TEST_NAME "wmemset"
28 #endif /* !TEST_BZERO */
29 #define MIN_PAGE_SIZE 131072
30 #include "bench-string.h"
33 # define MEMSET memset
35 # define SIMPLE_MEMSET simple_memset
36 # define MEMCMP memcmp
39 # define MEMSET wmemset
41 # define SIMPLE_MEMSET simple_wmemset
42 # define MEMCMP wmemcmp
45 CHAR
*SIMPLE_MEMSET (CHAR
*, int, size_t);
48 typedef void (*proto_t
) (char *, size_t);
49 void simple_bzero (char *, size_t);
50 void builtin_bzero (char *, size_t);
52 IMPL (simple_bzero
, 0)
53 IMPL (builtin_bzero
, 0)
57 simple_bzero (char *s
, size_t n
)
59 SIMPLE_MEMSET (s
, 0, n
);
63 builtin_bzero (char *s
, size_t n
)
65 __builtin_bzero (s
, n
);
68 typedef CHAR
*(*proto_t
) (CHAR
*, int, size_t);
70 IMPL (SIMPLE_MEMSET
, 0)
72 char *builtin_memset (char *, int, size_t);
73 IMPL (builtin_memset
, 0)
79 builtin_memset (char *s
, int c
, size_t n
)
81 return __builtin_memset (s
, c
, n
);
84 #endif /* !TEST_BZERO */
87 inhibit_loop_to_libcall
88 SIMPLE_MEMSET (CHAR
*s
, int c
, size_t n
)
90 CHAR
*r
= s
, *end
= s
+ n
;
97 do_one_test (impl_t
*impl
, CHAR
*s
, int c
__attribute ((unused
)), size_t n
)
99 size_t i
, iters
= INNER_LOOP_ITERS
;
100 timing_t start
, stop
, cur
;
103 simple_bzero (tstbuf
, n
);
105 if (memcmp (s
, tstbuf
, n
) != 0)
107 CHAR
*res
= CALL (impl
, s
, c
, n
);
109 || SIMPLE_MEMSET (tstbuf
, c
, n
) != tstbuf
110 || MEMCMP (s
, tstbuf
, n
) != 0)
111 #endif /* !TEST_BZERO */
113 error (0, 0, "Wrong result in function %s", impl
->name
);
119 for (i
= 0; i
< iters
; ++i
)
124 CALL (impl
, s
, c
, n
);
125 #endif /* !TEST_BZERO */
129 TIMING_DIFF (cur
, start
, stop
);
131 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
135 do_test (size_t align
, int c
, size_t len
)
138 if ((align
+ len
) * sizeof (CHAR
) > page_size
)
141 printf ("Length %4zd, alignment %2zd, c %2d:", len
, align
, c
);
143 FOR_EACH_IMPL (impl
, 0)
144 do_one_test (impl
, (CHAR
*) (buf1
) + align
, c
, len
);
158 FOR_EACH_IMPL (impl
, 0)
159 printf ("\t%s", impl
->name
);
163 for (c
= -65; c
<= 130; c
+= 65)
166 for (i
= 0; i
< 18; ++i
)
167 do_test (0, c
, 1 << i
);
168 for (i
= 1; i
< 32; ++i
)
174 for (i
= 32; i
< 512; i
+=32)
180 do_test (3, c
, 1024);
184 for (i
= 33; i
<= 256; i
+= 4)
186 do_test (0, c
, 32 * i
);
187 do_test (i
, c
, 32 * i
);
193 #include "../test-skeleton.c"