elf: Add a DTV setup test [BZ #27136]
[glibc.git] / benchtests / bench-memcpy.c
blob5bddaeb8fc989f99d1bade4a0759f03241b22375
1 /* Measure memcpy functions.
2 Copyright (C) 2013-2021 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 <https://www.gnu.org/licenses/>. */
19 #ifndef MEMCPY_RESULT
20 # define MEMCPY_RESULT(dst, len) dst
21 # define MIN_PAGE_SIZE 131072
22 # define TEST_MAIN
23 # define TEST_NAME "memcpy"
24 # include "bench-string.h"
26 void *generic_memcpy (void *, const void *, size_t);
28 IMPL (memcpy, 1)
29 IMPL (generic_memcpy, 0)
31 #endif
33 # include "json-lib.h"
35 typedef void *(*proto_t) (void *, const void *, size_t);
37 static void
38 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
39 size_t len)
41 size_t i, iters = INNER_LOOP_ITERS;
42 timing_t start, stop, cur;
44 TIMING_NOW (start);
45 for (i = 0; i < iters; ++i)
47 CALL (impl, dst, src, len);
49 TIMING_NOW (stop);
51 TIMING_DIFF (cur, start, stop);
53 json_element_double (json_ctx, (double) cur / (double) iters);
56 static void
57 do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
59 size_t i, j;
60 char *s1, *s2;
62 align1 &= 63;
63 if (align1 + len >= page_size)
64 return;
66 align2 &= 63;
67 if (align2 + len >= page_size)
68 return;
70 s1 = (char *) (buf1 + align1);
71 s2 = (char *) (buf2 + align2);
73 for (i = 0, j = 1; i < len; i++, j += 23)
74 s1[i] = j;
76 json_element_object_begin (json_ctx);
77 json_attr_uint (json_ctx, "length", (double) len);
78 json_attr_uint (json_ctx, "align1", (double) align1);
79 json_attr_uint (json_ctx, "align2", (double) align2);
80 json_array_begin (json_ctx, "timings");
82 FOR_EACH_IMPL (impl, 0)
83 do_one_test (json_ctx, impl, s2, s1, len);
85 json_array_end (json_ctx);
86 json_element_object_end (json_ctx);
89 int
90 test_main (void)
92 json_ctx_t json_ctx;
93 size_t i;
95 test_init ();
97 json_init (&json_ctx, 0, stdout);
99 json_document_begin (&json_ctx);
100 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
102 json_attr_object_begin (&json_ctx, "functions");
103 json_attr_object_begin (&json_ctx, TEST_NAME);
104 json_attr_string (&json_ctx, "bench-variant", "default");
106 json_array_begin (&json_ctx, "ifuncs");
107 FOR_EACH_IMPL (impl, 0)
108 json_element_string (&json_ctx, impl->name);
109 json_array_end (&json_ctx);
111 json_array_begin (&json_ctx, "results");
112 for (i = 0; i < 18; ++i)
114 do_test (&json_ctx, 0, 0, 1 << i);
115 do_test (&json_ctx, i, 0, 1 << i);
116 do_test (&json_ctx, 0, i, 1 << i);
117 do_test (&json_ctx, i, i, 1 << i);
120 for (i = 0; i < 32; ++i)
122 do_test (&json_ctx, 0, 0, i);
123 do_test (&json_ctx, i, 0, i);
124 do_test (&json_ctx, 0, i, i);
125 do_test (&json_ctx, i, i, i);
128 for (i = 3; i < 32; ++i)
130 if ((i & (i - 1)) == 0)
131 continue;
132 do_test (&json_ctx, 0, 0, 16 * i);
133 do_test (&json_ctx, i, 0, 16 * i);
134 do_test (&json_ctx, 0, i, 16 * i);
135 do_test (&json_ctx, i, i, 16 * i);
138 for (i = 32; i < 64; ++i)
140 do_test (&json_ctx, 0, 0, 32 * i);
141 do_test (&json_ctx, i, 0, 32 * i);
142 do_test (&json_ctx, 0, i, 32 * i);
143 do_test (&json_ctx, i, i, 32 * i);
146 do_test (&json_ctx, 0, 0, getpagesize ());
148 json_array_end (&json_ctx);
149 json_attr_object_end (&json_ctx);
150 json_attr_object_end (&json_ctx);
151 json_document_end (&json_ctx);
153 return ret;
156 #include <support/test-driver.c>
158 #define libc_hidden_builtin_def(X)
159 #undef MEMCPY
160 #define MEMCPY generic_memcpy
161 #include <string/memcpy.c>
162 #include <string/wordcopy.c>