tile: switch to using <fenv.h> fallback functions
[glibc.git] / benchtests / bench-memmove.c
blob8925606af84c52f72ec1195096e8acb28662d8b1
1 /* Measure memmove 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_BCOPY
21 # define TEST_NAME "bcopy"
22 #else
23 # define TEST_NAME "memmove"
24 #endif
25 #include "bench-string.h"
27 char *simple_memmove (char *, const char *, size_t);
29 #ifdef TEST_BCOPY
30 typedef void (*proto_t) (const char *, char *, size_t);
31 void simple_bcopy (const char *, char *, size_t);
33 IMPL (simple_bcopy, 0)
34 IMPL (bcopy, 1)
36 void
37 simple_bcopy (const char *src, char *dst, size_t n)
39 simple_memmove (dst, src, n);
41 #else
42 typedef char *(*proto_t) (char *, const char *, size_t);
44 IMPL (simple_memmove, 0)
45 IMPL (memmove, 1)
46 #endif
48 char *
49 inhibit_loop_to_libcall
50 simple_memmove (char *dst, const char *src, size_t n)
52 char *ret = dst;
53 if (src < dst)
55 dst += n;
56 src += n;
57 while (n--)
58 *--dst = *--src;
60 else
61 while (n--)
62 *dst++ = *src++;
63 return ret;
66 static void
67 do_one_test (impl_t *impl, char *dst, char *src, const char *orig_src,
68 size_t len)
70 memcpy (src, orig_src, len);
71 #ifdef TEST_BCOPY
72 CALL (impl, src, dst, len);
73 #else
74 char *res;
76 res = CALL (impl, dst, src, len);
77 if (res != dst)
79 error (0, 0, "Wrong result in function %s %p %p", impl->name,
80 res, dst);
81 ret = 1;
82 return;
84 #endif
86 if (memcmp (dst, orig_src, len) != 0)
88 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
89 impl->name, dst, src);
90 ret = 1;
91 return;
94 if (HP_TIMING_AVAIL)
96 hp_timing_t start __attribute ((unused));
97 hp_timing_t stop __attribute ((unused));
98 hp_timing_t best_time = ~ (hp_timing_t) 0;
99 size_t i;
101 for (i = 0; i < 32; ++i)
103 HP_TIMING_NOW (start);
104 #ifdef TEST_BCOPY
105 CALL (impl, src, dst, len);
106 #else
107 CALL (impl, dst, src, len);
108 #endif
109 HP_TIMING_NOW (stop);
110 HP_TIMING_BEST (best_time, start, stop);
113 printf ("\t%zd", (size_t) best_time);
117 static void
118 do_test (size_t align1, size_t align2, size_t len)
120 size_t i, j;
121 char *s1, *s2;
123 align1 &= 63;
124 if (align1 + len >= page_size)
125 return;
127 align2 &= 63;
128 if (align2 + len >= page_size)
129 return;
131 s1 = (char *) (buf1 + align1);
132 s2 = (char *) (buf2 + align2);
134 for (i = 0, j = 1; i < len; i++, j += 23)
135 s1[i] = j;
137 if (HP_TIMING_AVAIL)
138 printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
140 FOR_EACH_IMPL (impl, 0)
141 do_one_test (impl, s2, (char *) (buf2 + align1), s1, len);
143 if (HP_TIMING_AVAIL)
144 putchar ('\n');
148 test_main (void)
150 size_t i;
152 test_init ();
154 printf ("%23s", "");
155 FOR_EACH_IMPL (impl, 0)
156 printf ("\t%s", impl->name);
157 putchar ('\n');
159 for (i = 0; i < 14; ++i)
161 do_test (0, 32, 1 << i);
162 do_test (32, 0, 1 << i);
163 do_test (0, i, 1 << i);
164 do_test (i, 0, 1 << i);
167 for (i = 0; i < 32; ++i)
169 do_test (0, 32, i);
170 do_test (32, 0, i);
171 do_test (0, i, i);
172 do_test (i, 0, i);
175 for (i = 3; i < 32; ++i)
177 if ((i & (i - 1)) == 0)
178 continue;
179 do_test (0, 32, 16 * i);
180 do_test (32, 0, 16 * i);
181 do_test (0, i, 16 * i);
182 do_test (i, 0, 16 * i);
185 return ret;
188 #include "../test-skeleton.c"