1 /* Measure memset functions.
2 Copyright (C) 2013-2014 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"
23 # define TEST_NAME "memset"
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
28 char *simple_memset (char *, int, size_t);
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)
40 simple_bzero (char *s
, size_t n
)
42 simple_memset (s
, 0, n
);
46 builtin_bzero (char *s
, size_t n
)
48 __builtin_bzero (s
, n
);
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)
59 builtin_memset (char *s
, int c
, size_t n
)
61 return __builtin_memset (s
, c
, n
);
66 inhibit_loop_to_libcall
67 simple_memset (char *s
, int c
, size_t n
)
69 char *r
= s
, *end
= s
+ n
;
76 do_one_test (impl_t
*impl
, char *s
, int c
__attribute ((unused
)), size_t n
)
78 size_t i
, iters
= INNER_LOOP_ITERS
;
79 timing_t start
, stop
, cur
;
82 simple_bzero (tstbuf
, n
);
84 if (memcmp (s
, tstbuf
, n
) != 0)
86 char *res
= CALL (impl
, s
, c
, n
);
88 || simple_memset (tstbuf
, c
, n
) != tstbuf
89 || memcmp (s
, tstbuf
, n
) != 0)
92 error (0, 0, "Wrong result in function %s", impl
->name
);
98 for (i
= 0; i
< iters
; ++i
)
103 CALL (impl
, s
, c
, n
);
108 TIMING_DIFF (cur
, start
, stop
);
110 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
114 do_test (size_t align
, int c
, size_t len
)
117 if (align
+ len
> page_size
)
120 printf ("Length %4zd, alignment %2zd, c %2d:", len
, align
, c
);
122 FOR_EACH_IMPL (impl
, 0)
123 do_one_test (impl
, (char *) buf1
+ align
, c
, len
);
137 FOR_EACH_IMPL (impl
, 0)
138 printf ("\t%s", impl
->name
);
142 for (c
= -65; c
<= 130; c
+= 65)
145 for (i
= 0; i
< 18; ++i
)
146 do_test (0, c
, 1 << i
);
147 for (i
= 1; i
< 32; ++i
)
154 do_test (3, c
, 1024);
162 #include "../test-skeleton.c"