| 1 | /* Measure memmove functions. |
| 2 | Copyright (C) 2013-2024 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 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #define TEST_MAIN |
| 20 | #define TEST_NAME "memmove" |
| 21 | #include "bench-string.h" |
| 22 | #include "json-lib.h" |
| 23 | |
| 24 | void *generic_memmove (void *, const void *, size_t); |
| 25 | |
| 26 | typedef void *(*proto_t) (void *, const void *, size_t); |
| 27 | |
| 28 | IMPL (memmove, 1) |
| 29 | IMPL (generic_memmove, 0) |
| 30 | |
| 31 | static void |
| 32 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, |
| 33 | size_t len) |
| 34 | { |
| 35 | size_t i, iters = INNER_LOOP_ITERS; |
| 36 | timing_t start, stop, cur; |
| 37 | for (i = 0; i < iters / 64; ++i) |
| 38 | { |
| 39 | CALL (impl, dst, src, len); |
| 40 | } |
| 41 | TIMING_NOW (start); |
| 42 | for (i = 0; i < iters; ++i) |
| 43 | { |
| 44 | CALL (impl, dst, src, len); |
| 45 | } |
| 46 | TIMING_NOW (stop); |
| 47 | |
| 48 | TIMING_DIFF (cur, start, stop); |
| 49 | |
| 50 | json_element_double (ctx: json_ctx, d: (double) cur / (double) iters); |
| 51 | } |
| 52 | |
| 53 | static void |
| 54 | do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) |
| 55 | { |
| 56 | size_t i, j; |
| 57 | char *s1, *s2; |
| 58 | |
| 59 | align1 &= (getpagesize () - 1); |
| 60 | if (align1 + len >= page_size) |
| 61 | return; |
| 62 | |
| 63 | align2 &= (getpagesize () - 1); |
| 64 | if (align2 + len >= page_size) |
| 65 | return; |
| 66 | |
| 67 | s1 = (char *) (buf2 + align1); |
| 68 | s2 = (char *) (buf2 + align2); |
| 69 | |
| 70 | for (i = 0, j = 1; i < len; i++, j += 23) |
| 71 | s1[i] = j; |
| 72 | |
| 73 | json_element_object_begin (ctx: json_ctx); |
| 74 | json_attr_uint (ctx: json_ctx, name: "length" , d: (double) len); |
| 75 | json_attr_uint (ctx: json_ctx, name: "align1" , d: (double) align1); |
| 76 | json_attr_uint (ctx: json_ctx, name: "align2" , d: (double) align2); |
| 77 | json_array_begin (ctx: json_ctx, name: "timings" ); |
| 78 | |
| 79 | FOR_EACH_IMPL (impl, 0) |
| 80 | do_one_test (json_ctx, impl, dst: s2, src: s1, len); |
| 81 | |
| 82 | json_array_end (ctx: json_ctx); |
| 83 | json_element_object_end (ctx: json_ctx); |
| 84 | } |
| 85 | |
| 86 | static int |
| 87 | test_main (void) |
| 88 | { |
| 89 | json_ctx_t json_ctx; |
| 90 | size_t i; |
| 91 | size_t half_page = getpagesize () / 2; |
| 92 | |
| 93 | test_init (); |
| 94 | |
| 95 | json_init (ctx: &json_ctx, indent_level: 0, stdout); |
| 96 | |
| 97 | json_document_begin (ctx: &json_ctx); |
| 98 | json_attr_string (ctx: &json_ctx, name: "timing_type" , TIMING_TYPE); |
| 99 | |
| 100 | json_attr_object_begin (ctx: &json_ctx, name: "functions" ); |
| 101 | json_attr_object_begin (ctx: &json_ctx, name: "memmove" ); |
| 102 | json_attr_string (ctx: &json_ctx, name: "bench-variant" , s: "default" ); |
| 103 | |
| 104 | json_array_begin (ctx: &json_ctx, name: "ifuncs" ); |
| 105 | |
| 106 | FOR_EACH_IMPL (impl, 0) |
| 107 | json_element_string (ctx: &json_ctx, s: impl->name); |
| 108 | json_array_end (ctx: &json_ctx); |
| 109 | |
| 110 | json_array_begin (ctx: &json_ctx, name: "results" ); |
| 111 | for (i = 0; i < 14; ++i) |
| 112 | { |
| 113 | do_test (json_ctx: &json_ctx, align1: 0, align2: 32, len: 1 << i); |
| 114 | do_test (json_ctx: &json_ctx, align1: 32, align2: 0, len: 1 << i); |
| 115 | do_test (json_ctx: &json_ctx, align1: 0, align2: i, len: 1 << i); |
| 116 | do_test (json_ctx: &json_ctx, align1: i, align2: 0, len: 1 << i); |
| 117 | } |
| 118 | |
| 119 | for (i = 0; i < 32; ++i) |
| 120 | { |
| 121 | do_test (json_ctx: &json_ctx, align1: 0, align2: 32, len: i); |
| 122 | do_test (json_ctx: &json_ctx, align1: 32, align2: 0, len: i); |
| 123 | do_test (json_ctx: &json_ctx, align1: 0, align2: i, len: i); |
| 124 | do_test (json_ctx: &json_ctx, align1: i, align2: 0, len: i); |
| 125 | } |
| 126 | |
| 127 | for (i = 3; i < 32; ++i) |
| 128 | { |
| 129 | if ((i & (i - 1)) == 0) |
| 130 | continue; |
| 131 | do_test (json_ctx: &json_ctx, align1: 0, align2: 32, len: 16 * i); |
| 132 | do_test (json_ctx: &json_ctx, align1: 32, align2: 0, len: 16 * i); |
| 133 | do_test (json_ctx: &json_ctx, align1: 0, align2: i, len: 16 * i); |
| 134 | do_test (json_ctx: &json_ctx, align1: i, align2: 0, len: 16 * i); |
| 135 | } |
| 136 | |
| 137 | for (i = 32; i < 64; ++i) |
| 138 | { |
| 139 | do_test (json_ctx: &json_ctx, align1: 0, align2: 0, len: 32 * i); |
| 140 | do_test (json_ctx: &json_ctx, align1: i, align2: 0, len: 32 * i); |
| 141 | do_test (json_ctx: &json_ctx, align1: 0, align2: i, len: 32 * i); |
| 142 | do_test (json_ctx: &json_ctx, align1: i, align2: i, len: 32 * i); |
| 143 | } |
| 144 | |
| 145 | for (i = 0; i <= 48; ++i) |
| 146 | { |
| 147 | do_test (json_ctx: &json_ctx, align1: 0, align2: 0, len: 2048 + 64 * i); |
| 148 | do_test (json_ctx: &json_ctx, align1: i, align2: 0, len: 2048 + 64 * i); |
| 149 | do_test (json_ctx: &json_ctx, align1: 0, align2: i, len: 2048 + 64 * i); |
| 150 | do_test (json_ctx: &json_ctx, align1: i, align2: i, len: 2048 + 64 * i); |
| 151 | do_test (json_ctx: &json_ctx, align1: half_page, align2: 0, len: 2048 + 64 * i); |
| 152 | do_test (json_ctx: &json_ctx, align1: 0, align2: half_page, len: 2048 + 64 * i); |
| 153 | do_test (json_ctx: &json_ctx, align1: half_page + i, align2: 0, len: 2048 + 64 * i); |
| 154 | do_test (json_ctx: &json_ctx, align1: i, align2: half_page, len: 2048 + 64 * i); |
| 155 | do_test (json_ctx: &json_ctx, align1: half_page, align2: i, len: 2048 + 64 * i); |
| 156 | do_test (json_ctx: &json_ctx, align1: 0, align2: half_page + i, len: 2048 + 64 * i); |
| 157 | do_test (json_ctx: &json_ctx, align1: half_page + i, align2: i, len: 2048 + 64 * i); |
| 158 | do_test (json_ctx: &json_ctx, align1: i, align2: half_page + i, len: 2048 + 64 * i); |
| 159 | } |
| 160 | |
| 161 | json_array_end (ctx: &json_ctx); |
| 162 | json_attr_object_end (ctx: &json_ctx); |
| 163 | json_attr_object_end (ctx: &json_ctx); |
| 164 | json_document_end (ctx: &json_ctx); |
| 165 | |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | #include <support/test-driver.c> |
| 170 | |
| 171 | #define libc_hidden_builtin_def(X) |
| 172 | #undef MEMMOVE |
| 173 | #define MEMMOVE generic_memmove |
| 174 | #include <string/memmove.c> |
| 175 | #include <string/wordcopy.c> |
| 176 | |