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/>. */
20 # define MEMCPY_RESULT(dst, len) dst
21 # define MIN_PAGE_SIZE 131072
23 # define TEST_NAME "memcpy"
24 # include "bench-string.h"
26 void *generic_memcpy (void *, const void *, size_t);
29 IMPL (generic_memcpy, 0)
33 # include "json-lib.h"
35 typedef void *(*proto_t) (void *, const void *, size_t);
38 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
41 size_t i, iters = INNER_LOOP_ITERS;
42 timing_t start, stop, cur;
45 for (i = 0; i < iters; ++i)
47 CALL (impl, dst, src, len);
51 TIMING_DIFF (cur, start, stop);
53 json_element_double (json_ctx, (double) cur / (double) iters);
57 do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,
64 if (align1 + len >= page_size)
68 if (align2 + len >= page_size)
71 s1 = (char *) (buf1 + align1);
72 s2 = (char *) (buf2 + align2);
74 for (repeats = both_ways ? 2 : 1; repeats; --repeats)
76 for (i = 0, j = 1; i < len; i++, j += 23)
79 json_element_object_begin (json_ctx);
80 json_attr_uint (json_ctx, "length", (double) len);
81 json_attr_uint (json_ctx, "align1", (double) align1);
82 json_attr_uint (json_ctx, "align2", (double) align2);
83 json_attr_uint (json_ctx, "dst > src", (double) (s2 > s1));
84 json_array_begin (json_ctx, "timings");
86 FOR_EACH_IMPL (impl, 0)
87 do_one_test (json_ctx, impl, s2, s1, len);
89 json_array_end (json_ctx);
90 json_element_object_end (json_ctx);
92 s1 = (char *) (buf2 + align1);
93 s2 = (char *) (buf1 + align2);
105 json_init (&json_ctx, 0, stdout);
107 json_document_begin (&json_ctx);
108 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
110 json_attr_object_begin (&json_ctx, "functions");
111 json_attr_object_begin (&json_ctx, TEST_NAME);
112 json_attr_string (&json_ctx, "bench-variant", "default");
114 json_array_begin (&json_ctx, "ifuncs");
115 FOR_EACH_IMPL (impl, 0)
116 json_element_string (&json_ctx, impl->name);
117 json_array_end (&json_ctx);
119 json_array_begin (&json_ctx, "results");
120 for (i = 0; i < 18; ++i)
122 do_test (&json_ctx, 0, 0, 1 << i, 1);
123 do_test (&json_ctx, i, 0, 1 << i, 1);
124 do_test (&json_ctx, 0, i, 1 << i, 1);
125 do_test (&json_ctx, i, i, 1 << i, 1);
128 for (i = 0; i < 32; ++i)
130 do_test (&json_ctx, 0, 0, i, 0);
131 do_test (&json_ctx, i, 0, i, 0);
132 do_test (&json_ctx, 0, i, i, 0);
133 do_test (&json_ctx, i, i, i, 0);
136 for (i = 3; i < 32; ++i)
138 if ((i & (i - 1)) == 0)
140 do_test (&json_ctx, 0, 0, 16 * i, 1);
141 do_test (&json_ctx, i, 0, 16 * i, 1);
142 do_test (&json_ctx, 0, i, 16 * i, 1);
143 do_test (&json_ctx, i, i, 16 * i, 1);
146 for (i = 32; i < 64; ++i)
148 do_test (&json_ctx, 0, 0, 32 * i, 1);
149 do_test (&json_ctx, i, 0, 32 * i, 1);
150 do_test (&json_ctx, 0, i, 32 * i, 1);
151 do_test (&json_ctx, i, i, 32 * i, 1);
154 do_test (&json_ctx, 0, 0, getpagesize (), 1);
156 for (i = 0; i <= 32; ++i)
158 do_test (&json_ctx, 0, 0, 2048 + 64 * i, 1);
159 do_test (&json_ctx, i, 0, 2048 + 64 * i, 1);
160 do_test (&json_ctx, 0, i, 2048 + 64 * i, 1);
161 do_test (&json_ctx, i, i, 2048 + 64 * i, 1);
164 json_array_end (&json_ctx);
165 json_attr_object_end (&json_ctx);
166 json_attr_object_end (&json_ctx);
167 json_document_end (&json_ctx);
172 #include <support/test-driver.c>
174 #define libc_hidden_builtin_def(X)
176 #define MEMCPY generic_memcpy
177 #include <string/memcpy.c>
178 #include <string/wordcopy.c>