From patchwork Thu Jan 3 15:47:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 30955 Received: (qmail 71003 invoked by alias); 3 Jan 2019 15:47:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 70988 invoked by uid 89); 3 Jan 2019 15:47:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=benchmarks X-HELO: EUR03-VE1-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WZvMTOm3j1mSM+G6NE1U3pHGjBUxGldwhIJ1buokonE=; b=pMalbDp8MwLcrv+sj9afDzjT6UdnSsrx6tg3EXhYybOePMhlsqKXCVfs+ontHhnu10YqHG1sdQX0y1xAkVIErTSBnNHOUQqgtkpGS2kgeWdl8dn6w5iHfWqlvAVRAghGgQYEGT7SVZnbZm3jlbSzDy+dXSN1EaPv0O3YCILcSDE= From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: [PATCH] More string benchtest cleanups Date: Thu, 3 Jan 2019 15:47:19 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) MIME-Version: 1.0 Continue cleanup of the string benchtests. Remove simplistic byte-oriented versions with faster generic implementations. Remove bcopy/bzero benchmarks (bcopy/bzero are obsolete and never emitted by compilers). OK for commit? 2019-01-03 Wilco Dijkstra * benchtests/Makefile: Remove bench-bcopy.c and bench-bzero.c. * benchtests/bench-bcopy.c: Delete file. * benchtests/bench-bzero.c: Likewise. * benchtests/bench-memccpy.c (stupid_memccpy): Remove. (simple_memccpy): Remove. (generic_memccpy): Add function. * benchtests/bench-memcpy.c: Minor cleanup. * benchtests/bench-memmove.c (simple_bcopy): Remove. * benchtests/bench-mempcpy.c (simple_mempcpy): Remove. (generic_mempcpy): Add new function. * benchtests/bench-memset.c (simple_bzero): Remove. (builtin_bzero): Remove. * benchtests/bench-rawmemchr.c (simple_rawmemchr): Remove. (generic_rawmemchr): Add new function. diff --git a/benchtests/Makefile b/benchtests/Makefile index 3ccd250c403d5bfb05a54fbb43ba0ab850616cce..1afa71bf4a0706fabefe0b1299c164cf4a843472 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -37,7 +37,7 @@ bench := $(foreach B,$(filter bench-%,${BENCHSET}), ${${B}}) endif # String function benchmarks. -string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \ +string-benchset := memccpy memchr memcmp memcpy memmem memmove \ mempcpy memset rawmemchr stpcpy stpncpy strcasecmp strcasestr \ strcat strchr strchrnul strcmp strcpy strcspn strlen \ strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \ diff --git a/benchtests/bench-bcopy.c b/benchtests/bench-bcopy.c deleted file mode 100644 index 09f923585f2192f1e2a78e7a7bc7a59544603ee6..0000000000000000000000000000000000000000 --- a/benchtests/bench-bcopy.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Measure bcopy functions. - Copyright (C) 2013-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#define TEST_BCOPY -#include "bench-memmove.c" diff --git a/benchtests/bench-bzero.c b/benchtests/bench-bzero.c deleted file mode 100644 index 70a2e05806b79db1d17057a69a45d22bd6698254..0000000000000000000000000000000000000000 --- a/benchtests/bench-bzero.c +++ /dev/null @@ -1,19 +0,0 @@ -/* Measure bzero functions. - Copyright (C) 2013-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ -#define TEST_BZERO -#include "bench-memset.c" diff --git a/benchtests/bench-memccpy.c b/benchtests/bench-memccpy.c index c7424130d64a5d216866ca6ee5d6dc6923f6d062..a6a856efaea64b60bd71809247e3da345a66ab61 100644 --- a/benchtests/bench-memccpy.c +++ b/benchtests/bench-memccpy.c @@ -20,28 +20,8 @@ #define TEST_NAME "memccpy" #include "bench-string.h" -void *simple_memccpy (void *, const void *, int, size_t); -void *stupid_memccpy (void *, const void *, int, size_t); - -IMPL (stupid_memccpy, 0) -IMPL (simple_memccpy, 0) -IMPL (memccpy, 1) - -void * -simple_memccpy (void *dst, const void *src, int c, size_t n) -{ - const char *s = src; - char *d = dst; - - while (n-- > 0) - if ((*d++ = *s++) == (char) c) - return d; - - return NULL; -} - void * -stupid_memccpy (void *dst, const void *src, int c, size_t n) +generic_memccpy (void *dst, const void *src, int c, size_t n) { void *p = memchr (src, c, n); @@ -52,6 +32,9 @@ stupid_memccpy (void *dst, const void *src, int c, size_t n) return NULL; } +IMPL (memccpy, 1) +IMPL (generic_memccpy, 0) + typedef void *(*proto_t) (void *, const void *, int c, size_t); static void diff --git a/benchtests/bench-memcpy.c b/benchtests/bench-memcpy.c index 6a52a1b0a072d06fc51aad9738a3ff2e407682ab..99186d7212936d45582752cad0f0338527192d52 100644 --- a/benchtests/bench-memcpy.c +++ b/benchtests/bench-memcpy.c @@ -23,13 +23,6 @@ # define TEST_NAME "memcpy" # include "bench-string.h" -char *simple_memcpy (char *, const char *, size_t); -char *builtin_memcpy (char *, const char *, size_t); - -IMPL (simple_memcpy, 0) -IMPL (builtin_memcpy, 0) -IMPL (memcpy, 1) - char * simple_memcpy (char *dst, const char *src, size_t n) { @@ -44,6 +37,11 @@ builtin_memcpy (char *dst, const char *src, size_t n) { return __builtin_memcpy (dst, src, n); } + +IMPL (memcpy, 1) +IMPL (builtin_memcpy, 0) +IMPL (simple_memcpy, 0) + #endif # include "json-lib.h" diff --git a/benchtests/bench-memmove.c b/benchtests/bench-memmove.c index 93de6719811d1226bc264462ab4b2508ce5c6b15..ce9dd1e8ebc3a537bc2aa4830712ac8065b75066 100644 --- a/benchtests/bench-memmove.c +++ b/benchtests/bench-memmove.c @@ -17,34 +17,16 @@ . */ #define TEST_MAIN -#ifdef TEST_BCOPY -# define TEST_NAME "bcopy" -#else -# define TEST_NAME "memmove" -#endif +#define TEST_NAME "memmove" #include "bench-string.h" #include "json-lib.h" char *simple_memmove (char *, const char *, size_t); -#ifdef TEST_BCOPY -typedef void (*proto_t) (const char *, char *, size_t); -void simple_bcopy (const char *, char *, size_t); - -IMPL (simple_bcopy, 0) -IMPL (bcopy, 1) - -void -simple_bcopy (const char *src, char *dst, size_t n) -{ - simple_memmove (dst, src, n); -} -#else typedef char *(*proto_t) (char *, const char *, size_t); -IMPL (simple_memmove, 0) IMPL (memmove, 1) -#endif +IMPL (simple_memmove, 0) char * inhibit_loop_to_libcall @@ -74,11 +56,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src, const TIMING_NOW (start); for (i = 0; i < iters; ++i) { -#ifdef TEST_BCOPY - CALL (impl, src, dst, len); -#else CALL (impl, dst, src, len); -#endif } TIMING_NOW (stop); diff --git a/benchtests/bench-mempcpy.c b/benchtests/bench-mempcpy.c index bb76881b5e18a4bf0e8234e15271f1bc346aa981..230a8af8cc98b9f33f4c363d018b57067047bfac 100644 --- a/benchtests/bench-mempcpy.c +++ b/benchtests/bench-mempcpy.c @@ -21,17 +21,13 @@ #define TEST_NAME "mempcpy" #include "bench-string.h" -char *simple_mempcpy (char *, const char *, size_t); - -IMPL (simple_mempcpy, 0) -IMPL (mempcpy, 1) - char * -simple_mempcpy (char *dst, const char *src, size_t n) +generic_mempcpy (char *dst, const char *src, size_t n) { - while (n--) - *dst++ = *src++; - return dst; + return memcpy (dst, src, n) + n; } +IMPL (mempcpy, 1) +IMPL (generic_mempcpy, 0) + #include "bench-memcpy.c" diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c index 85bb2b314a98827f6a19e073212ecb56801e3c4e..f9348fc1e26a3809efb5370e54dca7f4324bd87f 100644 --- a/benchtests/bench-memset.c +++ b/benchtests/bench-memset.c @@ -17,66 +17,32 @@ . */ #define TEST_MAIN -#ifdef TEST_BZERO -# define TEST_NAME "bzero" -#else -# ifndef WIDE -# define TEST_NAME "memset" -# else -# define TEST_NAME "wmemset" -# endif /* WIDE */ -#endif /* !TEST_BZERO */ -#define MIN_PAGE_SIZE 131072 -#include "bench-string.h" - #ifndef WIDE -# define SIMPLE_MEMSET simple_memset +# define TEST_NAME "memset" #else -# define SIMPLE_MEMSET simple_wmemset +# define TEST_NAME "wmemset" #endif /* WIDE */ +#define MIN_PAGE_SIZE 131072 +#include "bench-string.h" #include "json-lib.h" CHAR *SIMPLE_MEMSET (CHAR *, int, size_t); -#ifdef TEST_BZERO -typedef void (*proto_t) (char *, size_t); -void simple_bzero (char *, size_t); -void builtin_bzero (char *, size_t); - -IMPL (simple_bzero, 0) -IMPL (builtin_bzero, 0) -IMPL (bzero, 1) - -void -simple_bzero (char *s, size_t n) -{ - SIMPLE_MEMSET (s, 0, n); -} - -void -builtin_bzero (char *s, size_t n) -{ - __builtin_bzero (s, n); -} -#else typedef CHAR *(*proto_t) (CHAR *, int, size_t); -IMPL (SIMPLE_MEMSET, 0) -# ifndef WIDE -char *builtin_memset (char *, int, size_t); -IMPL (builtin_memset, 0) -# endif /* !WIDE */ IMPL (MEMSET, 1) +IMPL (SIMPLE_MEMSET, 0) -# ifndef WIDE +#ifndef WIDE char * builtin_memset (char *s, int c, size_t n) { return __builtin_memset (s, c, n); } -# endif /* !WIDE */ -#endif /* !TEST_BZERO */ + +IMPL (builtin_memset, 0) +#endif /* !WIDE */ CHAR * inhibit_loop_to_libcall @@ -95,14 +61,12 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t i, iters = INNER_LOOP_ITERS; timing_t start, stop, cur; + memset (s, 0, n); + TIMING_NOW (start); for (i = 0; i < iters; ++i) { -#ifdef TEST_BZERO - CALL (impl, s, n); -#else CALL (impl, s, c, n); -#endif /* !TEST_BZERO */ } TIMING_NOW (stop); @@ -159,9 +123,7 @@ test_main (void) json_array_begin (&json_ctx, "results"); -#ifndef TEST_BZERO for (c = -65; c <= 130; c += 65) -#endif { for (i = 0; i < 18; ++i) do_test (&json_ctx, 0, c, 1 << i); diff --git a/benchtests/bench-rawmemchr.c b/benchtests/bench-rawmemchr.c index 8664fe51078b236bac0455ee988f781dac5ea7d0..5a7d607040229f1199ab9b2c504f051dea426021 100644 --- a/benchtests/bench-rawmemchr.c +++ b/benchtests/bench-rawmemchr.c @@ -23,20 +23,18 @@ #include "bench-string.h" typedef char *(*proto_t) (const char *, int); -char *simple_rawmemchr (const char *, int); - -IMPL (simple_rawmemchr, 0) -IMPL (rawmemchr, 1) char * -simple_rawmemchr (const char *s, int c) +generic_rawmemchr (const char *s, int c) { - while (1) - if (*s++ == (char) c) - return (char *) s - 1; - return NULL; + if (c != 0) + return memchr (s, c, PTRDIFF_MAX); + return (char *)s + strlen (s); } +IMPL (rawmemchr, 1) +IMPL (generic_rawmemchr, 0) + static void do_one_test (impl_t *impl, const char *s, int c, char *exp_res) {