]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memset.c
sparc (64bit): Regenerate ulps
[thirdparty/glibc.git] / benchtests / bench-memset.c
CommitLineData
97020474 1/* Measure memset functions.
6d7e8eda 2 Copyright (C) 2013-2023 Free Software Foundation, Inc.
97020474
SP
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
5a82c748 17 <https://www.gnu.org/licenses/>. */
97020474
SP
18
19#define TEST_MAIN
2e9e1667 20#ifndef WIDE
16f87cfd 21# define TEST_NAME "memset"
2e9e1667 22#else
16f87cfd 23# define TEST_NAME "wmemset"
3c05dd79 24# define generic_memset generic_wmemset
2e9e1667 25#endif /* WIDE */
16f87cfd
WD
26#define MIN_PAGE_SIZE 131072
27#include "bench-string.h"
2e9e1667 28
29c933fb
SP
29#include "json-lib.h"
30
3c05dd79
WD
31#ifdef WIDE
32CHAR *generic_wmemset (CHAR *, CHAR, size_t);
33#else
34void *generic_memset (void *, int, size_t);
35#endif
97020474 36
3c05dd79 37typedef void *(*proto_t) (void *, int, size_t);
97020474 38
2e9e1667 39IMPL (MEMSET, 1)
3c05dd79 40IMPL (generic_memset, 0)
97020474
SP
41
42static void
29c933fb
SP
43do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
44 int c __attribute ((unused)), size_t n)
97020474 45{
5d26d12f 46 size_t i, iters = INNER_LOOP_ITERS_LARGE;
44558701 47 timing_t start, stop, cur;
97020474 48
44558701
WN
49 TIMING_NOW (start);
50 for (i = 0; i < iters; ++i)
97020474 51 {
44558701 52 CALL (impl, s, c, n);
44558701
WN
53 }
54 TIMING_NOW (stop);
97020474 55
44558701 56 TIMING_DIFF (cur, start, stop);
97020474 57
29c933fb 58 json_element_double (json_ctx, (double) cur / (double) iters);
97020474
SP
59}
60
61static void
29c933fb 62do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
97020474 63{
81f6dd21 64 align &= 4095;
2e9e1667 65 if ((align + len) * sizeof (CHAR) > page_size)
97020474
SP
66 return;
67
29c933fb
SP
68 json_element_object_begin (json_ctx);
69 json_attr_uint (json_ctx, "length", len);
70 json_attr_uint (json_ctx, "alignment", align);
71 json_attr_int (json_ctx, "char", c);
72 json_array_begin (json_ctx, "timings");
97020474
SP
73
74 FOR_EACH_IMPL (impl, 0)
503c92c3
SP
75 {
76 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
503c92c3 77 }
97020474 78
29c933fb
SP
79 json_array_end (json_ctx);
80 json_element_object_end (json_ctx);
97020474
SP
81}
82
83int
84test_main (void)
85{
29c933fb 86 json_ctx_t json_ctx;
97020474
SP
87 size_t i;
88 int c = 0;
89
97020474 90
90cbb806
NG
91 test_init ();
92 alloc_bufs ();
29c933fb
SP
93 json_init (&json_ctx, 0, stdout);
94
95 json_document_begin (&json_ctx);
96 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
97
98 json_attr_object_begin (&json_ctx, "functions");
99 json_attr_object_begin (&json_ctx, TEST_NAME);
7960c5ee 100 json_attr_string (&json_ctx, "bench-variant", "default");
29c933fb
SP
101
102 json_array_begin (&json_ctx, "ifuncs");
97020474 103 FOR_EACH_IMPL (impl, 0)
29c933fb
SP
104 json_element_string (&json_ctx, impl->name);
105 json_array_end (&json_ctx);
106
107 json_array_begin (&json_ctx, "results");
97020474 108
97020474 109 for (c = -65; c <= 130; c += 65)
97020474
SP
110 {
111 for (i = 0; i < 18; ++i)
29c933fb 112 do_test (&json_ctx, 0, c, 1 << i);
69e6992d 113 for (i = 0; i < 64; ++i)
97020474 114 {
29c933fb 115 do_test (&json_ctx, i, c, i);
81f6dd21
NG
116 do_test (&json_ctx, 4096 - i, c, i);
117 do_test (&json_ctx, 4095, c, i);
97020474 118 if (i & (i - 1))
29c933fb 119 do_test (&json_ctx, 0, c, i);
97020474 120 }
5d26d12f 121 for (i = 32; i < 1024; i+=32)
71ae8647 122 {
29c933fb
SP
123 do_test (&json_ctx, 0, c, i);
124 do_test (&json_ctx, i, c, i);
71ae8647 125 }
29c933fb
SP
126 do_test (&json_ctx, 1, c, 14);
127 do_test (&json_ctx, 3, c, 1024);
128 do_test (&json_ctx, 4, c, 64);
129 do_test (&json_ctx, 2, c, 25);
97020474 130 }
344303f3
L
131 for (i = 33; i <= 256; i += 4)
132 {
29c933fb
SP
133 do_test (&json_ctx, 0, c, 32 * i);
134 do_test (&json_ctx, i, c, 32 * i);
344303f3 135 }
97020474 136
29c933fb
SP
137 json_array_end (&json_ctx);
138 json_attr_object_end (&json_ctx);
139 json_attr_object_end (&json_ctx);
140 json_document_end (&json_ctx);
141
97020474
SP
142 return ret;
143}
144
b598e134 145#include <support/test-driver.c>
3c05dd79
WD
146
147#define libc_hidden_builtin_def(X)
148#define libc_hidden_def(X)
149#define libc_hidden_weak(X)
150#define weak_alias(X,Y)
151#ifndef WIDE
152# undef MEMSET
153# define MEMSET generic_memset
154# include <string/memset.c>
155#else
156# define WMEMSET generic_wmemset
157# include <wcsmbs/wmemset.c>
158#endif