From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,BODY_8BITS, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 8037D1F453 for ; Fri, 1 Feb 2019 15:37:00 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; q=dns; s=default; b=GpbUY/f6yuZLE3yTwrkkYV1oF1HPE BQQKQZGKMGpo6oWG30hr3Ne73tIoD8VOrebSHIqDPaKEOMjjTGBmo2UXiV+PxN81 tZ2ii7Tqshrn8aGFJ73ilccjA9ev/Y1ljfL4m5INMap5RUsHQe6FLTPplc1CmyFs xQWxXioSElXEoQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:references :in-reply-to:content-type:content-transfer-encoding :mime-version; s=default; bh=hZ/9etydSs2YD7ZW5N6HpIGFOBs=; b=x0n 6z5b3nFkaSJV0n74zj4kGFtu4FAdd7UzS7gY9K/Fbt4lPx8PmuRkqb944JaunrU0 H27GPsWxMUp/gHGuJI8Qq5Ckw6nSFz4zxIte/JoBnnAg135HJFnb/BP66zDAMYQO ucdLMuwyMskesNJnZzTk//8JzyFoD4/BeQ9Dt+Uk= Received: (qmail 82987 invoked by alias); 1 Feb 2019 15:36:58 -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 Received: (qmail 82976 invoked by uid 89); 1 Feb 2019 15:36:57 -0000 Authentication-Results: sourceware.org; auth=none 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=0M6UUbplqgOU22jXwYKy4Ud/5M7JiG0ziyMeors/b5U=; b=JeHA9yVwfW1Fft7NgvrBr2AO4j/EU7dS0aSzQr5ygzHlbXDgShAZ9qZajwOKzH8qTk3XngAQ+Ul6YP3Gb8NDKaxgai2QHCRIwTzUK3NuwW1RRsjpfjk8KQgn7RZi2nHGWUi2AzejGcr7eRDKQ9msP1qO5RXRMkTfIYkLQ3PGulU= From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: Re: [PATCH] Improve string benchtests Date: Fri, 1 Feb 2019 15:36:51 +0000 Message-ID: References: In-Reply-To: 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) x-ms-exchange-senderadcheck: 1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 ping From: Wilco Dijkstra Sent: 27 December 2018 18:26 To: 'GNU C Library' Cc: nd Subject: [PATCH] Improve string benchtests =A0=20 Replace slow byte-oriented tests in several string benchmarks with the generic implementations from the string/ directory so the comparisons are more realistic and useful. OK to commit? ChangeLog: 2018-12-27=A0 Wilco Dijkstra=A0 =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-stpcpy.c (SIMPLE_STPCPY): Remove f= unction. =A0=A0=A0=A0=A0=A0=A0 (generic_stpcpy): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-stpncpy.c (SIMPLE_STPNCPY): Remove= function. =A0=A0=A0=A0=A0=A0=A0 (generic_stpncpy): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-strcat.c (SIMPLE_STRCAT): Remove f= unction. =A0=A0=A0=A0=A0=A0=A0 (generic_strcat): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-strcpy.c (SIMPLE_STRCPY): Remove f= unction. =A0=A0=A0=A0=A0=A0=A0 (generic_strcpy): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-strncat.c (SIMPLE_STRNCAT): Remove= function. =A0=A0=A0=A0=A0=A0=A0 (STUPID_STRNCAT): Remove function. =A0=A0=A0=A0=A0=A0=A0 (generic_strncat): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-strncpy.c (SIMPLE_STRNCPY): Remove= function. =A0=A0=A0=A0=A0=A0=A0 (STUPID_STRNCPY): Remove function. =A0=A0=A0=A0=A0=A0=A0 (generic_strncpy): New function. =A0=A0=A0=A0=A0=A0=A0 * benchtests/bench-strnlen.c (SIMPLE_STRNLEN): Remove= function. =A0=A0=A0=A0=A0=A0=A0 (generic_strnlen): New function. =A0=A0=A0=A0=A0=A0=A0 (memchr_strnlen): New function. -- diff --git a/benchtests/bench-stpcpy.c b/benchtests/bench-stpcpy.c index 77ffb0f5c22b8d8ba83d46e903a23c90d8c983c1..7982c1886bb0af680b00757d838= 3b2ef84503533 100644 --- a/benchtests/bench-stpcpy.c +++ b/benchtests/bench-stpcpy.c @@ -24,22 +24,15 @@ =A0# define TEST_NAME "wcpcpy" =A0#endif /* WIDE */ =A0#include "bench-string.h" -#ifndef WIDE -# define SIMPLE_STPCPY simple_stpcpy -#else -# define SIMPLE_STPCPY simple_wcpcpy -#endif /* WIDE */ - -CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *); - -IMPL (SIMPLE_STPCPY, 0) -IMPL (STPCPY, 1) =A0 =A0CHAR * -SIMPLE_STPCPY (CHAR *dst, const CHAR *src) +generic_stpcpy (CHAR *dst, const CHAR *src) =A0{ -=A0 while ((*dst++ =3D *src++) !=3D '\0'); -=A0 return dst - 1; +=A0 size_t len =3D STRLEN (src); +=A0 return (CHAR*)MEMCPY (dst, src, len + 1) + len; =A0} =A0 +IMPL (STPCPY, 1) +IMPL (generic_stpcpy, 0) + =A0#include "bench-strcpy.c" diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c index 40c82cf716e6d7bc8fcb8d5a390da1ee8fee3245..331f5e67b7fc054bd678dbd264a= 24e43f940c0ed 100644 --- a/benchtests/bench-stpncpy.c +++ b/benchtests/bench-stpncpy.c @@ -24,47 +24,19 @@ =A0# define TEST_NAME "wcpncpy" =A0#endif /* WIDE */ =A0#include "bench-string.h" -#ifndef WIDE -# define SIMPLE_STPNCPY simple_stpncpy -# define STUPID_STPNCPY stupid_stpncpy -#else -# define SIMPLE_STPNCPY simple_wcpncpy -# define STUPID_STPNCPY stupid_wcpncpy -#endif /* WIDE */ - -CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t); -CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t); - -IMPL (STUPID_STPNCPY, 0) -IMPL (SIMPLE_STPNCPY, 0) -IMPL (STPNCPY, 1) - -CHAR * -SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n) -{ -=A0 while (n--) -=A0=A0=A0 if ((*dst++ =3D *src++) =3D=3D '\0') -=A0=A0=A0=A0=A0 { -=A0=A0=A0=A0=A0=A0 size_t i; - -=A0=A0=A0=A0=A0=A0 for (i =3D 0; i < n; ++i) -=A0=A0=A0=A0=A0=A0=A0=A0 dst[i] =3D '\0'; -=A0=A0=A0=A0=A0=A0 return dst - 1; -=A0=A0=A0=A0=A0 } -=A0 return dst; -} =A0 =A0CHAR * -STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n) +generic_stpncpy (CHAR *dst, const CHAR *src, size_t n) =A0{ =A0=A0 size_t nc =3D STRNLEN (src, n); -=A0 size_t i; - -=A0 for (i =3D 0; i < nc; ++i) -=A0=A0=A0 dst[i] =3D src[i]; -=A0 for (; i < n; ++i) -=A0=A0=A0 dst[i] =3D '\0'; -=A0 return dst + nc; +=A0 MEMCPY (dst, src, nc); +=A0 dst +=3D nc; +=A0 if (nc =3D=3D n) +=A0=A0=A0 return dst; +=A0 return MEMSET (dst, 0, n - nc); =A0} =A0 +IMPL (STPNCPY, 1) +IMPL (generic_stpncpy, 0) + =A0#include "bench-strncpy.c" diff --git a/benchtests/bench-strcat.c b/benchtests/bench-strcat.c index 6b3b084ae19a931cb2bda07794380b5745ccfc86..d3e96f4ec6331bea0027016eb6a= f4a276d0e6714 100644 --- a/benchtests/bench-strcat.c +++ b/benchtests/bench-strcat.c @@ -28,31 +28,25 @@ =A0 =A0#ifndef WIDE =A0# define sfmt "s" -# define SIMPLE_STRCAT simple_strcat =A0# define SMALL_CHAR 127 =A0#else =A0# define sfmt "ls" -# define SIMPLE_STRCAT simple_wcscat =A0# define SMALL_CHAR 1273 =A0#endif /* WIDE */ =A0 =A0 =A0typedef CHAR *(*proto_t) (CHAR *, const CHAR *); -CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *); - -IMPL (SIMPLE_STRCAT, 0) -IMPL (STRCAT, 1) =A0 =A0CHAR * -SIMPLE_STRCAT (CHAR *dst, const CHAR *src) +generic_strcat (CHAR *dst, const CHAR *src) =A0{ -=A0 CHAR *ret =3D dst; -=A0 while (*dst++ !=3D '\0'); -=A0 --dst; -=A0 while ((*dst++ =3D *src++) !=3D '\0'); -=A0 return ret; +=A0 STRCPY (dst + STRLEN (dst), src); +=A0 return dst; =A0} =A0 +IMPL (STRCAT, 1) +IMPL (generic_strcat, 0) + =A0static void =A0do_one_test (impl_t *impl, CHAR *dst, const CHAR *src) =A0{ diff --git a/benchtests/bench-strcpy.c b/benchtests/bench-strcpy.c index e5fd27ffba9ca6dd871e658d1cffc22f28047e49..426ee8f79ad8400b5ceddad5d6c= dfc3523f49f16 100644 --- a/benchtests/bench-strcpy.c +++ b/benchtests/bench-strcpy.c @@ -34,25 +34,17 @@ =A0# else =A0#=A0 define TEST_NAME "wcscpy" =A0# endif -# include "bench-string.h" -# ifndef WIDE -#=A0 define SIMPLE_STRCPY simple_strcpy -# else -#=A0 define SIMPLE_STRCPY simple_wcscpy -# endif - -CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *); - -IMPL (SIMPLE_STRCPY, 0) -IMPL (STRCPY, 1) +#include "bench-string.h" =A0 =A0CHAR * -SIMPLE_STRCPY (CHAR *dst, const CHAR *src) +generic_strcpy (CHAR *dst, const CHAR *src) =A0{ -=A0 CHAR *ret =3D dst; -=A0 while ((*dst++ =3D *src++) !=3D '\0'); -=A0 return ret; +=A0 return MEMCPY (dst, src, STRLEN (src) + 1); =A0} + +IMPL (STRCPY, 1) +IMPL (generic_strcpy, 0) + =A0#endif =A0 =A0typedef CHAR *(*proto_t) (CHAR *, const CHAR *); diff --git a/benchtests/bench-strncat.c b/benchtests/bench-strncat.c index 7e0112273ba0727ae29407e38724c39159ce1c93..da8318e9a24e50ca491b65e092c= c5152b3c47715 100644 --- a/benchtests/bench-strncat.c +++ b/benchtests/bench-strncat.c @@ -27,35 +27,26 @@ =A0#define BIG_CHAR MAX_CHAR =A0 =A0#ifndef WIDE -# define SIMPLE_STRNCAT simple_strncat -# define STUPID_STRNCAT stupid_strncat =A0# define SMALL_CHAR 127 =A0#else -# define SIMPLE_STRNCAT simple_wcsncat -# define STUPID_STRNCAT stupid_wcsncat =A0# define SMALL_CHAR 1273 =A0#endif /* WIDE */ =A0 =A0typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t); -CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t); -CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t); - -IMPL (STUPID_STRNCAT, 0) -IMPL (STRNCAT, 2) =A0 =A0CHAR * -STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n) +generic_strncat (CHAR *dst, const CHAR *src, size_t n) =A0{ -=A0 CHAR *ret =3D dst; -=A0 while (*dst++ !=3D '\0'); -=A0 --dst; -=A0 while (n--) -=A0=A0=A0 if ((*dst++ =3D *src++) =3D=3D '\0') -=A0=A0=A0=A0=A0 return ret; -=A0 *dst =3D '\0'; -=A0 return ret; +=A0 CHAR *end =3D dst + STRLEN (dst); +=A0 n =3D STRNLEN (src, n); +=A0 end[n] =3D 0; +=A0 MEMCPY (end, src, n); +=A0 return dst; =A0} =A0 +IMPL (STRNCAT, 2) +IMPL (generic_strncat, 0) + =A0static void =A0do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t n) =A0{ diff --git a/benchtests/bench-strncpy.c b/benchtests/bench-strncpy.c index 79953759bfbd7201b9e3a846b59666375cb76348..e32a1519cd95af5456277e76581= 3eb78211a3a2a 100644 --- a/benchtests/bench-strncpy.c +++ b/benchtests/bench-strncpy.c @@ -33,47 +33,19 @@ =A0#=A0 define TEST_NAME "wcsncpy" =A0# endif /* WIDE */ =A0# include "bench-string.h" -# ifndef WIDE -#=A0 define SIMPLE_STRNCPY simple_strncpy -#=A0 define STUPID_STRNCPY stupid_strncpy -# else -#=A0 define SIMPLE_STRNCPY simple_wcsncpy -#=A0 define STUPID_STRNCPY stupid_wcsncpy -# endif /* WIDE */ - -CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t); -CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t); - -IMPL (STUPID_STRNCPY, 0) -IMPL (SIMPLE_STRNCPY, 0) -IMPL (STRNCPY, 1) =A0 =A0CHAR * -SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n) +generic_strncpy (CHAR *dst, const CHAR *src, size_t n) =A0{ -=A0 CHAR *ret =3D dst; -=A0 while (n--) -=A0=A0=A0 if ((*dst++ =3D *src++) =3D=3D '\0') -=A0=A0=A0=A0=A0 { -=A0=A0=A0=A0=A0=A0 while (n--) -=A0=A0=A0=A0=A0=A0=A0=A0 *dst++ =3D '\0'; -=A0=A0=A0=A0=A0=A0 return ret; -=A0=A0=A0=A0=A0 } -=A0 return ret; +=A0 size_t nc =3D STRNLEN (src, n); +=A0 if (nc !=3D n) +=A0=A0=A0 MEMSET (dst + nc, 0, n - nc); +=A0 return MEMCPY (dst, src, nc); =A0} =A0 -CHAR * -STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n) -{ -=A0 size_t nc =3D STRNLEN (src, n); -=A0 size_t i; +IMPL (STRNCPY, 1) +IMPL (generic_strncpy, 0) =A0 -=A0 for (i =3D 0; i < nc; ++i) -=A0=A0=A0 dst[i] =3D src[i]; -=A0 for (; i < n; ++i) -=A0=A0=A0 dst[i] =3D '\0'; -=A0 return dst; -} =A0#endif /* !STRNCPY_RESULT */ =A0 =A0typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t); diff --git a/benchtests/bench-strnlen.c b/benchtests/bench-strnlen.c index 8a7641669a36603e3943b5ca3b9cb0f648dd18f0..8a0fabfcf6c4223dceab3a8eb58= 1851c6ab6be5d 100644 --- a/benchtests/bench-strnlen.c +++ b/benchtests/bench-strnlen.c @@ -28,27 +28,24 @@ =A0 =A0#ifndef WIDE =A0# define MIDDLE_CHAR 127 -# define SIMPLE_STRNLEN simple_strnlen =A0#else =A0# define MIDDLE_CHAR 1121 -# define SIMPLE_STRNLEN simple_wcsnlen =A0#endif /* WIDE */ =A0 =A0typedef size_t (*proto_t) (const CHAR *, size_t); -size_t SIMPLE_STRNLEN (const CHAR *, size_t); - -IMPL (SIMPLE_STRNLEN, 0) -IMPL (STRNLEN, 1) +size_t generic_strnlen (const CHAR *, size_t); =A0 =A0size_t -SIMPLE_STRNLEN (const CHAR *s, size_t maxlen) +memchr_strnlen (const CHAR *s, size_t maxlen) =A0{ -=A0 size_t i; - -=A0 for (i =3D 0; i < maxlen && s[i]; ++i); -=A0 return i; +=A0 const CHAR *s1 =3D MEMCHR (s, 0, maxlen); +=A0 return (s1 =3D=3D NULL) ? maxlen : s1 - s; =A0} =A0 +IMPL (STRNLEN, 1) +IMPL (memchr_strnlen, 0) +IMPL (generic_strnlen, 0) + =A0static void =A0do_one_test (impl_t *impl, const CHAR *s, size_t maxlen, size_t exp_len) =A0{ @@ -146,3 +143,13 @@ test_main (void) =A0} =A0 =A0#include + +#define libc_hidden_def(X) +#ifndef WIDE +# undef STRNLEN +# define STRNLEN generic_strnlen +# include +#else +# define WCSNLEN generic_strnlen +# include +#endif =