]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memcpy-large.c
Disable TSX on some Haswell processors.
[thirdparty/glibc.git] / benchtests / bench-memcpy-large.c
CommitLineData
a25322f4
L
1/* Measure memcpy functions with large data sizes.
2 Copyright (C) 2016 Free Software Foundation, Inc.
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
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef MEMCPY_RESULT
20# define MEMCPY_RESULT(dst, len) dst
21# define START_SIZE (64 * 1024)
22# define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
23# define TEST_MAIN
24# define TEST_NAME "memcpy"
25# define TIMEOUT (20 * 60)
26# include "bench-string.h"
27
28IMPL (memcpy, 1)
29#endif
30
31typedef char *(*proto_t) (char *, const char *, size_t);
32
33static void
34do_one_test (impl_t *impl, char *dst, const char *src,
35 size_t len)
36{
37 size_t i, iters = 16;
38 timing_t start, stop, cur;
39
40 /* Must clear the destination buffer updated by the previous run. */
41 for (i = 0; i < len; i++)
42 dst[i] = 0;
43
44 if (CALL (impl, dst, src, len) != MEMCPY_RESULT (dst, len))
45 {
46 error (0, 0, "Wrong result in function %s %p %p", impl->name,
47 CALL (impl, dst, src, len), MEMCPY_RESULT (dst, len));
48 ret = 1;
49 return;
50 }
51
52 if (memcmp (dst, src, len) != 0)
53 {
54 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
55 impl->name, dst, src);
56 ret = 1;
57 return;
58 }
59
60 TIMING_NOW (start);
61 for (i = 0; i < iters; ++i)
62 {
63 CALL (impl, dst, src, len);
64 }
65 TIMING_NOW (stop);
66
67 TIMING_DIFF (cur, start, stop);
68
69 TIMING_PRINT_MEAN ((double) cur, (double) iters);
70}
71
72static void
73do_test (size_t align1, size_t align2, size_t len)
74{
75 size_t i, j;
76 char *s1, *s2;
77
78 align1 &= 63;
79 if (align1 + len >= page_size)
80 return;
81
82 align2 &= 63;
83 if (align2 + len >= page_size)
84 return;
85
86 s1 = (char *) (buf1 + align1);
87 s2 = (char *) (buf2 + align2);
88
89 for (i = 0, j = 1; i < len; i++, j += 23)
90 s1[i] = j;
91
92 printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
93
94 FOR_EACH_IMPL (impl, 0)
95 do_one_test (impl, s2, s1, len);
96
97 putchar ('\n');
98}
99
100int
101test_main (void)
102{
103 size_t i;
104
105 test_init ();
106
107 printf ("%23s", "");
108 FOR_EACH_IMPL (impl, 0)
109 printf ("\t%s", impl->name);
110 putchar ('\n');
111
112 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
113 {
114 do_test (0, 0, i + 7);
115 do_test (0, 3, i + 15);
116 do_test (3, 0, i + 31);
117 do_test (3, 5, i + 63);
118 }
119
120 return ret;
121}
122
123#include "../test-skeleton.c"