diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2020-06-11 09:00:12 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2020-09-24 10:46:38 -0700 |
commit | 06e95b93f0bb5943363ad3dcf0cd0fb9d8613b61 (patch) | |
tree | c3df004f538721f6135c1fd26259406f4b7b9577 | |
parent | c4277ba2347d17fb2c62914621cab16489a6f5f3 (diff) | |
download | glibc-06e95b93f0bb5943363ad3dcf0cd0fb9d8613b61.tar.gz glibc-06e95b93f0bb5943363ad3dcf0cd0fb9d8613b61.tar.xz glibc-06e95b93f0bb5943363ad3dcf0cd0fb9d8613b61.zip |
bench-strcmp.c: Add workloads on page boundary
Add strcmp workloads on page boundary.
-rw-r--r-- | benchtests/bench-strcmp.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/benchtests/bench-strcmp.c b/benchtests/bench-strcmp.c index 47d0a35299..c6f8446978 100644 --- a/benchtests/bench-strcmp.c +++ b/benchtests/bench-strcmp.c @@ -144,6 +144,60 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len, int json_element_object_end (json_ctx); } +static void +do_one_test_page_boundary (json_ctx_t *json_ctx, CHAR *s1, CHAR *s2, + size_t align1, size_t align2, size_t len, + int exp_result) +{ + json_element_object_begin (json_ctx); + json_attr_uint (json_ctx, "length", (double) len); + json_attr_uint (json_ctx, "align1", (double) align1); + json_attr_uint (json_ctx, "align2", (double) align2); + json_array_begin (json_ctx, "timings"); + FOR_EACH_IMPL (impl, 0) + do_one_test (json_ctx, impl, s1, s2, exp_result); + json_array_end (json_ctx); + json_element_object_end (json_ctx); +} + +static void +do_test_page_boundary (json_ctx_t *json_ctx) +{ + /* To trigger bug 25933, we need a size that is equal to the vector + length times 4. In the case of AVX2 for Intel, we need 32 * 4. We + make this test generic and run it for all architectures as additional + boundary testing for such related algorithms. */ + size_t size = 32 * 4; + size_t len; + CHAR *s1 = (CHAR *) (buf1 + (BUF1PAGES - 1) * page_size); + CHAR *s2 = (CHAR *) (buf2 + (BUF1PAGES - 1) * page_size); + int exp_result; + + memset (s1, 'a', page_size); + memset (s2, 'a', page_size); + + s1[(page_size / CHARBYTES) - 1] = (CHAR) 0; + s2[(page_size / CHARBYTES) - 1] = (CHAR) 0; + + /* Iterate over a size that is just below where we expect the bug to + trigger up to the size we expect will trigger the bug e.g. [99-128]. + Likewise iterate the start of two strings between 30 and 31 bytes + away from the boundary to simulate alignment changes. */ + for (size_t s = 99; s <= size; s++) + for (size_t s1a = 30; s1a < 32; s1a++) + for (size_t s2a = 30; s2a < 32; s2a++) + { + size_t align1 = (page_size / CHARBYTES - s) - s1a; + size_t align2 = (page_size / CHARBYTES - s) - s2a; + CHAR *s1p = s1 + align1; + CHAR *s2p = s2 + align2; + len = (page_size / CHARBYTES) - 1 - align1; + exp_result = SIMPLE_STRCMP (s1p, s2p); + do_one_test_page_boundary (json_ctx, s1p, s2p, align1, align2, + len, exp_result); + } +} + int test_main (void) { @@ -197,6 +251,8 @@ test_main (void) do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, -1); } + do_test_page_boundary (&json_ctx); + json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); |