packaging: add 64bit libs on 32bit build env
[platform/upstream/linaro-glibc.git] / benchtests / bench-memset.c
1 /* Measure memset functions.
2    Copyright (C) 2013-2014 Free Software Foundation, Inc.
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
23 # define TEST_NAME "memset"
24 #endif
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
27
28 char *simple_memset (char *, int, size_t);
29
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);
34
35 IMPL (simple_bzero, 0)
36 IMPL (builtin_bzero, 0)
37 IMPL (bzero, 1)
38
39 void
40 simple_bzero (char *s, size_t n)
41 {
42   simple_memset (s, 0, n);
43 }
44
45 void
46 builtin_bzero (char *s, size_t n)
47 {
48   __builtin_bzero (s, n);
49 }
50 #else
51 typedef char *(*proto_t) (char *, int, size_t);
52 char *builtin_memset (char *, int, size_t);
53
54 IMPL (simple_memset, 0)
55 IMPL (builtin_memset, 0)
56 IMPL (memset, 1)
57
58 char *
59 builtin_memset (char *s, int c, size_t n)
60 {
61   return __builtin_memset (s, c, n);
62 }
63 #endif
64
65 char *
66 inhibit_loop_to_libcall
67 simple_memset (char *s, int c, size_t n)
68 {
69   char *r = s, *end = s + n;
70   while (r < end)
71     *r++ = c;
72   return s;
73 }
74
75 static void
76 do_one_test (impl_t *impl, char *s, int c __attribute ((unused)), size_t n)
77 {
78   size_t i, iters = INNER_LOOP_ITERS;
79   timing_t start, stop, cur;
80   char tstbuf[n];
81 #ifdef TEST_BZERO
82   simple_bzero (tstbuf, n);
83   CALL (impl, s, n);
84   if (memcmp (s, tstbuf, n) != 0)
85 #else
86   char *res = CALL (impl, s, c, n);
87   if (res != s
88       || simple_memset (tstbuf, c, n) != tstbuf
89       || memcmp (s, tstbuf, n) != 0)
90 #endif
91     {
92       error (0, 0, "Wrong result in function %s", impl->name);
93       ret = 1;
94       return;
95     }
96
97   TIMING_NOW (start);
98   for (i = 0; i < iters; ++i)
99     {
100 #ifdef TEST_BZERO
101       CALL (impl, s, n);
102 #else
103       CALL (impl, s, c, n);
104 #endif
105     }
106   TIMING_NOW (stop);
107
108   TIMING_DIFF (cur, start, stop);
109
110   TIMING_PRINT_MEAN ((double) cur, (double) iters);
111 }
112
113 static void
114 do_test (size_t align, int c, size_t len)
115 {
116   align &= 7;
117   if (align + len > page_size)
118     return;
119
120   printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
121
122   FOR_EACH_IMPL (impl, 0)
123     do_one_test (impl, (char *) buf1 + align, c, len);
124
125   putchar ('\n');
126 }
127
128 int
129 test_main (void)
130 {
131   size_t i;
132   int c = 0;
133
134   test_init ();
135
136   printf ("%24s", "");
137   FOR_EACH_IMPL (impl, 0)
138     printf ("\t%s", impl->name);
139   putchar ('\n');
140
141 #ifndef TEST_BZERO
142   for (c = -65; c <= 130; c += 65)
143 #endif
144     {
145       for (i = 0; i < 18; ++i)
146         do_test (0, c, 1 << i);
147       for (i = 1; i < 32; ++i)
148         {
149           do_test (i, c, i);
150           if (i & (i - 1))
151             do_test (0, c, i);
152         }
153       do_test (1, c, 14);
154       do_test (3, c, 1024);
155       do_test (4, c, 64);
156       do_test (2, c, 25);
157     }
158
159   return ret;
160 }
161
162 #include "../test-skeleton.c"