1 /* Measure memmove 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 "bcopy"
23 # define TEST_NAME "memmove"
25 #include "bench-string.h"
27 char *simple_memmove (char *, const char *, size_t);
30 typedef void (*proto_t
) (const char *, char *, size_t);
31 void simple_bcopy (const char *, char *, size_t);
33 IMPL (simple_bcopy
, 0)
37 simple_bcopy (const char *src
, char *dst
, size_t n
)
39 simple_memmove (dst
, src
, n
);
42 typedef char *(*proto_t
) (char *, const char *, size_t);
44 IMPL (simple_memmove
, 0)
49 inhibit_loop_to_libcall
50 simple_memmove (char *dst
, const char *src
, size_t n
)
67 do_one_test (impl_t
*impl
, char *dst
, char *src
, const char *orig_src
,
70 size_t i
, iters
= INNER_LOOP_ITERS
;
71 timing_t start
, stop
, cur
;
73 /* This also clears the destination buffer set by the previous run. */
74 memcpy (src
, orig_src
, len
);
76 CALL (impl
, src
, dst
, len
);
80 res
= CALL (impl
, dst
, src
, len
);
83 error (0, 0, "Wrong result in function %s %p %p", impl
->name
,
90 if (memcmp (dst
, orig_src
, len
) != 0)
92 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
93 impl
->name
, dst
, src
);
99 for (i
= 0; i
< iters
; ++i
)
102 CALL (impl
, src
, dst
, len
);
104 CALL (impl
, dst
, src
, len
);
109 TIMING_DIFF (cur
, start
, stop
);
111 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
115 do_test (size_t align1
, size_t align2
, size_t len
)
121 if (align1
+ len
>= page_size
)
125 if (align2
+ len
>= page_size
)
128 s1
= (char *) (buf1
+ align1
);
129 s2
= (char *) (buf2
+ align2
);
131 for (i
= 0, j
= 1; i
< len
; i
++, j
+= 23)
134 printf ("Length %4zd, alignment %2zd/%2zd:", len
, align1
, align2
);
136 FOR_EACH_IMPL (impl
, 0)
137 do_one_test (impl
, s2
, (char *) (buf2
+ align1
), s1
, len
);
150 FOR_EACH_IMPL (impl
, 0)
151 printf ("\t%s", impl
->name
);
154 for (i
= 0; i
< 14; ++i
)
156 do_test (0, 32, 1 << i
);
157 do_test (32, 0, 1 << i
);
158 do_test (0, i
, 1 << i
);
159 do_test (i
, 0, 1 << i
);
162 for (i
= 0; i
< 32; ++i
)
170 for (i
= 3; i
< 32; ++i
)
172 if ((i
& (i
- 1)) == 0)
174 do_test (0, 32, 16 * i
);
175 do_test (32, 0, 16 * i
);
176 do_test (0, i
, 16 * i
);
177 do_test (i
, 0, 16 * i
);
180 for (i
= 32; i
< 64; ++i
)
182 do_test (0, 0, 32 * i
);
183 do_test (i
, 0, 32 * i
);
184 do_test (0, i
, 32 * i
);
185 do_test (i
, i
, 32 * i
);
191 #include "../test-skeleton.c"