s390: Use dl-symbol-redir-ifunc.h on cpu-tunables
[glibc.git] / benchtests / bench-hash-funcs-kernel.h
blobf6474111228552928cb16e0a0f6d9adbf4153d69
1 /* Actual benchmark kernels used by bench-hash-funcs.h
2 Copyright (C) 2022-2023 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 #include "bench-util.h"
22 /* We go through the trouble of using macros here because many of the
23 hash functions are meant to be inlined so its not fair to benchmark
24 them with a function pointer where they won't be inlinable. */
25 #undef RUN_FUNC
26 #undef POSTFIX
27 #ifdef SIMPLE
28 # define RUN_FUNC SIMPLE_TEST_FUNC
29 # define POSTFIX _simple
30 #else
31 # define RUN_FUNC TEST_FUNC
32 # define POSTFIX _optimized
33 #endif
35 #define PRIMITIVE_CAT(x, y) x ## y
36 #define CAT(x, y) PRIMITIVE_CAT (x, y)
38 static double __attribute__ ((noinline, noclone))
39 CAT (do_one_test_kernel, POSTFIX) (const char *s, size_t len)
42 unsigned int iters;
43 timing_t start, stop, cur;
45 /* Warmup. */
46 for (iters = NFIXED_ITERS / 32; iters; --iters)
47 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (s, len));
49 TIMING_NOW (start);
50 for (iters = NFIXED_ITERS; iters; --iters)
51 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (s, len));
53 TIMING_NOW (stop);
55 TIMING_DIFF (cur, start, stop);
57 (void) (len);
58 return (double) cur / (double) NFIXED_ITERS;
61 static double __attribute__ ((noinline, noclone))
62 CAT (do_rand_test_kernel, POSTFIX) (char const *bufs,
63 unsigned int const *sizes)
65 unsigned int i, iters;
66 size_t offset;
67 timing_t start, stop, cur;
69 /* Warmup. */
70 for (i = 0, offset = 0; i < NRAND_BUFS; ++i, offset += RAND_BENCH_MAX_LEN)
71 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (bufs + offset, sizes[i]));
73 TIMING_NOW (start);
74 for (iters = NRAND_ITERS; iters; --iters)
76 for (i = 0, offset = 0; i < NRAND_BUFS;
77 ++i, offset += RAND_BENCH_MAX_LEN)
78 DO_NOT_OPTIMIZE_OUT (RUN_FUNC (bufs + offset, sizes[i]));
81 TIMING_NOW (stop);
83 TIMING_DIFF (cur, start, stop);
85 (void) (sizes);
86 return (double) cur / (double) (NRAND_ITERS * NRAND_BUFS);