From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1895) id CD939385B508; Wed, 8 Mar 2023 18:46:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CD939385B508 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678301185; bh=oYhV4OWvtbGh4W/+B2+5jyAOTYZINEVJOmbND7T5SKQ=; h=From:To:Subject:Date:From; b=Anso6f58uSrN4Fgp+wJxuo/LjefEKG5qR4mAwCuwcOxfn5Rsehn+DJS35ZlyDszZD BNBIeJba6RuFIFRjQ06OmTmXNgZScOOS4F6W5mVBka3oEbAW4xWWNnhunbn6wtc5XL MCYbKMvjiu91P6FWmkt9c9rtwWOTGKmuFc/njnrM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Wilco Dijkstra To: glibc-cvs@sourceware.org Subject: [glibc] Benchtests: Remove simple_str(n)cmp X-Act-Checkin: glibc X-Git-Author: Wilco Dijkstra X-Git-Refname: refs/heads/master X-Git-Oldrev: 6a734e62f1557de3449c689effd2b37066ea34eb X-Git-Newrev: d1c3c0e4fefb92634fd2583d369cdb71b804e7a6 Message-Id: <20230308184625.CD939385B508@sourceware.org> Date: Wed, 8 Mar 2023 18:46:25 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d1c3c0e4fefb92634fd2583d369cdb71b804e7a6 commit d1c3c0e4fefb92634fd2583d369cdb71b804e7a6 Author: Wilco Dijkstra Date: Fri Mar 3 12:40:22 2023 +0000 Benchtests: Remove simple_str(n)cmp Instead of benchmarking slow byte oriented loops, include the optimized generic strcmp/strncmp implementation. Adjust iteration count to reduce benchmark time. Reviewed-by: Adhemerval Zanella Diff: --- benchtests/bench-strcmp.c | 49 +++++++++++----------------------------------- benchtests/bench-strncmp.c | 49 ++++++++++++---------------------------------- 2 files changed, 24 insertions(+), 74 deletions(-) diff --git a/benchtests/bench-strcmp.c b/benchtests/bench-strcmp.c index 8cd690bac1..65fd04b43a 100644 --- a/benchtests/bench-strcmp.c +++ b/benchtests/bench-strcmp.c @@ -23,59 +23,26 @@ # define TEST_NAME "strcmp" #endif #include "bench-string.h" +#include "json-lib.h" #ifdef WIDE -# define L(str) L##str -# define SIMPLE_STRCMP simple_wcscmp # define CHARBYTESLOG 2 # define MIDCHAR 0x7fffffff # define LARGECHAR 0xfffffffe - -/* Wcscmp uses signed semantics for comparison, not unsigned */ -/* Avoid using substraction since possible overflow */ - -int -simple_wcscmp (const wchar_t *s1, const wchar_t *s2) -{ - wchar_t c1, c2; - do - { - c1 = *s1++; - c2 = *s2++; - if (c2 == L'\0') - return c1 - c2; - } - while (c1 == c2); - - return c1 < c2 ? -1 : 1; -} - #else -# include - -# define L(str) str -# define SIMPLE_STRCMP simple_strcmp # define CHARBYTESLOG 0 # define MIDCHAR 0x7f # define LARGECHAR 0xfe -/* Strcmp uses unsigned semantics for comparison. */ int -simple_strcmp (const char *s1, const char *s2) -{ - int ret; +generic_strcmp (const char *s1, const char *s2); - while ((ret = *(unsigned char *) s1 - *(unsigned char*) s2++) == 0 && *s1++); - return ret; -} +IMPL (generic_strcmp, 0) #endif -# include "json-lib.h" - typedef int (*proto_t) (const CHAR *, const CHAR *); -IMPL (SIMPLE_STRCMP, 1) IMPL (STRCMP, 1) static void @@ -83,7 +50,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s1, const CHAR *s2, int exp_result) { - size_t i, iters = INNER_LOOP_ITERS8; + size_t i, iters = INNER_LOOP_ITERS; timing_t start, stop, cur; TIMING_NOW (start); @@ -201,7 +168,7 @@ do_test_page_boundary (json_ctx_t *json_ctx) CHAR *s1p = s1 + align1; CHAR *s2p = s2 + align2; len = (page_size / CHARBYTES) - 1 - align1; - exp_result = SIMPLE_STRCMP (s1p, s2p); + exp_result = STRCMP (s1p, s2p); do_one_test_page_boundary (json_ctx, s1p, s2p, align1, align2, len, exp_result); } @@ -324,3 +291,9 @@ test_main (void) } #include + +#ifndef WIDE +# undef STRCMP +# define STRCMP generic_strcmp +# include +#endif diff --git a/benchtests/bench-strncmp.c b/benchtests/bench-strncmp.c index a714e5a9d4..53707e6bca 100644 --- a/benchtests/bench-strncmp.c +++ b/benchtests/bench-strncmp.c @@ -21,61 +21,31 @@ # define TEST_NAME "wcsncmp" #else # define TEST_NAME "strncmp" -#endif /* !WIDE */ +#endif #include "bench-string.h" #include "json-lib.h" #ifdef WIDE -# define L(str) L##str # define STRDUP wcsdup -# define SIMPLE_STRNCMP simple_wcsncmp - -/* Wcsncmp uses signed semantics for comparison, not unsigned. - Avoid using substraction since possible overflow. */ -int -simple_wcsncmp (const CHAR *s1, const CHAR *s2, size_t n) -{ - wchar_t c1, c2; - - while (n--) - { - c1 = *s1++; - c2 = *s2++; - if (c1 == L ('\0') || c1 != c2) - return c1 > c2 ? 1 : (c1 < c2 ? -1 : 0); - } - return 0; -} - #else -# define L(str) str # define STRDUP strdup -# define SIMPLE_STRNCMP simple_strncmp -/* Strncmp uses unsigned semantics for comparison. */ int -simple_strncmp (const char *s1, const char *s2, size_t n) -{ - int ret = 0; +generic_strncmp (const char *s1, const char *s2, size_t n); - while (n-- && (ret = *(unsigned char *) s1 - * (unsigned char *) s2++) == 0 - && *s1++); - return ret; -} +IMPL (generic_strncmp, 0) -#endif /* !WIDE */ +#endif typedef int (*proto_t) (const CHAR *, const CHAR *, size_t); -IMPL (SIMPLE_STRNCMP, 0) IMPL (STRNCMP, 1) - static void do_one_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s1, const CHAR *s2, size_t n, int exp_result) { - size_t i, iters = INNER_LOOP_ITERS8; + size_t i, iters = INNER_LOOP_ITERS; timing_t start, stop, cur; TIMING_NOW (start); @@ -240,7 +210,7 @@ do_test_page_boundary (json_ctx_t *json_ctx) CHAR *s1p = s1 + align1; CHAR *s2p = s2 + align2; len = (page_size / CHARBYTES) - 1 - align1; - exp_result = SIMPLE_STRNCMP (s1p, s2p, s); + exp_result = STRNCMP (s1p, s2p, s); do_one_test_page_boundary (json_ctx, s1p, s2p, align1, align2, len, s, exp_result); } @@ -456,3 +426,10 @@ test_main (void) } #include + +#ifndef WIDE +# undef STRNCMP +# define STRNCMP generic_strncmp +# define libc_hidden_builtin_def(X) +# include +#endif