From patchwork Wed Apr 6 06:52:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 1613796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=RYchTb+j; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KYFZy6880z9sFr for ; Wed, 6 Apr 2022 16:53:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8A1C385843E for ; Wed, 6 Apr 2022 06:53:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B8A1C385843E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649227991; bh=YtNKcQbt1V9Fz10cvKaaj6EM9NAYW8cq7P9ND4irbMA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=RYchTb+j141MhPJ/ORDvs2qj0Jd5dGdh6Ju2pAfM4jRaBWSkdNbGHlw+5srRrihJo 8HWy4dNpmbm2/8xXypbBZcfUEgo3A/EC7KwDx/R4ntxWrlMXi0O/3+AwHlZ2Yq36a/ HxlNQPYEs+5UmxV4MxRdy1AC5dOdd4KlWk6OUBhw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from fossa.birch.relay.mailchannels.net (fossa.birch.relay.mailchannels.net [23.83.209.62]) by sourceware.org (Postfix) with ESMTPS id 0FD0B3858C50 for ; Wed, 6 Apr 2022 06:52:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0FD0B3858C50 X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 50E6E6C175A; Wed, 6 Apr 2022 06:52:53 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C21A96C1738; Wed, 6 Apr 2022 06:52:52 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1649227972; a=rsa-sha256; cv=none; b=mvveKDixFnisHaAftb8lN98YtFUzJpdIL+QCLNpNttEOGpRXsEGSSjO/SDNLoYS0I+Arx9 xP81viktKza1zPA8Q2X6mMI/GB3rfYs3KR/zXFf+YeTuN3mImSTUCJKigqYEB6NVLbyuK/ 8Ggyf8a85TKwDPYzYBctNhC9ryJA1XgdiURGp8INtTc98NsTWpOSInkOu2rFilwL2mRupF ZS1WMk06ngMs4k0E50dl2WWEemF9/slCFbNuVXLFJAnQdI2HXFmp7Wp6wcHjTVXFPSvN10 yk0+7lGrnHXeeEBHglASENKELvTDRTSb6SjhPCn9EZzfmqksh5Itn6RgFqwNcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1649227972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YtNKcQbt1V9Fz10cvKaaj6EM9NAYW8cq7P9ND4irbMA=; b=NR4ZR5x32f2RRT0IaCf4rAHmd00v4CaGrP5CAFzrOzYrapuZj8K7V5MsTYKVBe6ouniZwH AEZizKJJQmSiwPieHyxnxOlUsG+rPwPmBcf6L+CBtvcdV4IDROM6GxntxDXp58FMm1UueP c38if4f1lV1AvsX8sLtWZEUtUHhaHtRJiAJUnK8qOADAOKdCg8LRqrA3JV/xZVPXJdQ73F NZzZVgHrHnF+U7IDYkVpJdzLUex2EbvoSTdA2PqLkHRf48ALIkxazotDRAFDL1RfW6566D nuyXczpxB+59scAstjrntzBpqM6dtGYSWysk7XCNexhK64rK0CPxjhG+sqysUw== ARC-Authentication-Results: i=1; rspamd-786f77c8d-tg6l4; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.107.255.190 (trex/6.7.1); Wed, 06 Apr 2022 06:52:53 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Continue-Reign: 2258247d104cdfde_1649227973058_1299186638 X-MC-Loop-Signature: 1649227973058:3224429168 X-MC-Ingress-Time: 1649227973058 Received: from rhbox.redhat.com (unknown [49.248.235.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307.dreamhost.com (Postfix) with ESMTPSA id 4KYFZV4Kx8z2L; Tue, 5 Apr 2022 23:52:50 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2] tests/string: Drop simple/stupid/builtin tests Date: Wed, 6 Apr 2022 12:22:43 +0530 Message-Id: <20220406065243.122946-1-siddhesh@sourceware.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405050501.39309-1-siddhesh@sourceware.org> References: <20220405050501.39309-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1170.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Siddhesh Poyarekar via Libc-alpha From: Siddhesh Poyarekar Reply-To: Siddhesh Poyarekar Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" In most cases the simple/stupid/builtin functions were in there to benchmark optimized implementations against. Only in some cases the functions are used to check expected results. Remove these tests from IMPL() and only keep one simple implementation to generate expected results if needed. This improves timing of `make subdirs=string` by over a minute and a half (over 15%) on a Whiskey Lake laptop. Signed-off-by: Siddhesh Poyarekar --- Changes from v1: - Retain a simple_* implementation for future need. string/test-memccpy.c | 18 +--------------- string/test-memchr.c | 3 +-- string/test-memcmp.c | 1 - string/test-memcpy-support.h | 12 ++--------- string/test-memmem.c | 3 +-- string/test-memmove.c | 6 +++--- string/test-mempcpy.c | 4 +--- string/test-memrchr.c | 3 +-- string/test-memset.c | 42 +++++------------------------------- string/test-strcasecmp.c | 25 ++------------------- string/test-strcasestr.c | 11 +++++----- string/test-strcat.c | 3 +-- string/test-strchr.c | 16 ++------------ string/test-strcmp.c | 1 - string/test-strcpy.c | 4 +--- string/test-strlen.c | 2 +- string/test-strncasecmp.c | 25 +-------------------- string/test-strncat.c | 8 ++----- string/test-strncmp.c | 1 - string/test-strncpy.c | 19 +--------------- string/test-strnlen.c | 3 +-- string/test-strpbrk.c | 21 ++---------------- string/test-strrchr.c | 3 +-- string/test-strspn.c | 24 +-------------------- string/test-strstr.c | 15 ++++++------- 25 files changed, 43 insertions(+), 230 deletions(-) diff --git a/string/test-memccpy.c b/string/test-memccpy.c index ee2cf8b8af..c7cc866fa2 100644 --- a/string/test-memccpy.c +++ b/string/test-memccpy.c @@ -20,13 +20,9 @@ #define TEST_NAME "memccpy" #include "test-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) +/* Naive implementation to verify results. */ void * simple_memccpy (void *dst, const void *src, int c, size_t n) { @@ -40,18 +36,6 @@ simple_memccpy (void *dst, const void *src, int c, size_t n) return NULL; } -void * -stupid_memccpy (void *dst, const void *src, int c, size_t n) -{ - void *p = memchr (src, c, n); - - if (p != NULL) - return mempcpy (dst, src, p - src + 1); - - memcpy (dst, src, n); - return NULL; -} - typedef void *(*proto_t) (void *, const void *, int c, size_t); static void diff --git a/string/test-memchr.c b/string/test-memchr.c index a4617086b3..279a67ebe6 100644 --- a/string/test-memchr.c +++ b/string/test-memchr.c @@ -44,11 +44,10 @@ #endif /* WIDE */ typedef CHAR *(*proto_t) (const CHAR *, int, size_t); -CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t); -IMPL (SIMPLE_MEMCHR, 0) IMPL (MEMCHR, 1) +/* Naive implementation to verify results. */ CHAR * SIMPLE_MEMCHR (const CHAR *s, int c, size_t n) { diff --git a/string/test-memcmp.c b/string/test-memcmp.c index 89ef3419a0..181b689f68 100644 --- a/string/test-memcmp.c +++ b/string/test-memcmp.c @@ -85,7 +85,6 @@ SIMPLE_MEMCMP (const char *s1, const char *s2, size_t n) typedef int (*proto_t) (const CHAR *, const CHAR *, size_t); -IMPL (SIMPLE_MEMCMP, 0) IMPL (MEMCMP, 1) static int diff --git a/string/test-memcpy-support.h b/string/test-memcpy-support.h index f1763da895..7759fd22f4 100644 --- a/string/test-memcpy-support.h +++ b/string/test-memcpy-support.h @@ -29,12 +29,9 @@ #define TIMEOUT (8 * 60) #include "test-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) + +/* Naive implementation to verify results. */ char * simple_memcpy (char *dst, const char *src, size_t n) { @@ -44,11 +41,6 @@ simple_memcpy (char *dst, const char *src, size_t n) return ret; } -char * -builtin_memcpy (char *dst, const char *src, size_t n) -{ - return __builtin_memcpy (dst, src, n); -} #endif typedef char *(*proto_t) (char *, const char *, size_t); typedef uint32_t __attribute__ ((may_alias, aligned (1))) unaligned_uint32_t; diff --git a/string/test-memmem.c b/string/test-memmem.c index 37d3ea4fca..69803be0ca 100644 --- a/string/test-memmem.c +++ b/string/test-memmem.c @@ -23,11 +23,10 @@ #include "test-string.h" typedef char *(*proto_t) (const void *, size_t, const void *, size_t); -void *simple_memmem (const void *, size_t, const void *, size_t); -IMPL (simple_memmem, 0) IMPL (memmem, 1) +/* Naive implementation to verify results. */ void * simple_memmem (const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) diff --git a/string/test-memmove.c b/string/test-memmove.c index 8d9ac86b4f..be8752e833 100644 --- a/string/test-memmove.c +++ b/string/test-memmove.c @@ -29,23 +29,23 @@ 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) +/* Naive implementation to verify results. */ 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 +/* Naive implementation to verify results. */ char * inhibit_loop_to_libcall simple_memmove (char *dst, const char *src, size_t n) diff --git a/string/test-mempcpy.c b/string/test-mempcpy.c index 9637d02787..75808b2831 100644 --- a/string/test-mempcpy.c +++ b/string/test-mempcpy.c @@ -22,11 +22,9 @@ #define TEST_NAME "mempcpy" #include "test-string.h" -char *simple_mempcpy (char *, const char *, size_t); - -IMPL (simple_mempcpy, 0) IMPL (mempcpy, 1) +/* Naive implementation to verify results. */ char * simple_mempcpy (char *dst, const char *src, size_t n) { diff --git a/string/test-memrchr.c b/string/test-memrchr.c index 8d60d178a0..80419a6561 100644 --- a/string/test-memrchr.c +++ b/string/test-memrchr.c @@ -21,11 +21,10 @@ #include "test-string.h" typedef char *(*proto_t) (const char *, int, size_t); -char *simple_memrchr (const char *, int, size_t); -IMPL (simple_memrchr, 0) IMPL (memrchr, 1) +/* Naive implementation to verify results. */ char * simple_memrchr (const char *s, int c, size_t n) { diff --git a/string/test-memset.c b/string/test-memset.c index ee548f6924..00582c881c 100644 --- a/string/test-memset.c +++ b/string/test-memset.c @@ -50,51 +50,19 @@ # define BIG_CHAR WCHAR_MAX #endif /* WIDE */ -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) -#ifdef TEST_EXPLICIT_BZERO +# ifdef TEST_EXPLICIT_BZERO IMPL (explicit_bzero, 1) -#else +# else IMPL (bzero, 1) -#endif - -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); -} +# endif #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) - -# ifndef WIDE -char * -builtin_memset (char *s, int c, size_t n) -{ - return __builtin_memset (s, c, n); -} -# endif /* !WIDE */ #endif /* !TEST_BZERO */ +/* Naive implementation to verify results. */ CHAR * inhibit_loop_to_libcall SIMPLE_MEMSET (CHAR *s, int c, size_t n) @@ -116,7 +84,7 @@ do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n, int s[n] = sentinel; SIMPLE_MEMSET(s, ~c, n); #ifdef TEST_BZERO - simple_bzero (buf, n); + SIMPLE_MEMSET (buf, 0, n); CALL (impl, s, n); if (memcmp (s, buf, n) != 0 || (space_below && s[-1] != sentinel) diff --git a/string/test-strcasecmp.c b/string/test-strcasecmp.c index 438a9713ac..fe48d1197f 100644 --- a/string/test-strcasecmp.c +++ b/string/test-strcasecmp.c @@ -27,14 +27,11 @@ #include "test-string.h" typedef int (*proto_t) (const char *, const char *); -static int simple_strcasecmp (const char *, const char *); -static int stupid_strcasecmp (const char *, const char *); -IMPL (stupid_strcasecmp, 0) -IMPL (simple_strcasecmp, 0) IMPL (strcasecmp, 1) -static int +/* Naive implementation to verify results. */ +int simple_strcasecmp (const char *s1, const char *s2) { int ret; @@ -46,24 +43,6 @@ simple_strcasecmp (const char *s1, const char *s2) return ret; } -static int -stupid_strcasecmp (const char *s1, const char *s2) -{ - size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1; - size_t n = ns1 < ns2 ? ns1 : ns2; - int ret = 0; - - while (n--) - { - if ((ret = ((unsigned char) tolower (*s1) - - (unsigned char) tolower (*s2))) != 0) - break; - ++s1; - ++s2; - } - return ret; -} - static void do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result) { diff --git a/string/test-strcasestr.c b/string/test-strcasestr.c index b73bcfe8b4..0d39c62d09 100644 --- a/string/test-strcasestr.c +++ b/string/test-strcasestr.c @@ -21,15 +21,15 @@ #include "test-string.h" -#define STRCASESTR simple_strcasestr +#define STRCASESTR c_strcasestr #define NO_ALIAS #define __strncasecmp strncasecmp #define __strnlen strnlen #include "strcasestr.c" - +/* Naive implementation to verify results. */ static char * -stupid_strcasestr (const char *s1, const char *s2) +simple_strcasestr (const char *s1, const char *s2) { ssize_t s1len = strlen (s1); ssize_t s2len = strlen (s2); @@ -53,8 +53,7 @@ stupid_strcasestr (const char *s1, const char *s2) typedef char *(*proto_t) (const char *, const char *); -IMPL (stupid_strcasestr, 0) -IMPL (simple_strcasestr, 0) +IMPL (c_strcasestr, 0) IMPL (strcasestr, 1) @@ -129,7 +128,7 @@ check1 (void) const char s2[] = "OK"; char *exp_result; - exp_result = stupid_strcasestr (s1, s2); + exp_result = simple_strcasestr (s1, s2); FOR_EACH_IMPL (impl, 0) check_result (impl, s1, s2, exp_result); } diff --git a/string/test-strcat.c b/string/test-strcat.c index b5aab0f66f..59b953c962 100644 --- a/string/test-strcat.c +++ b/string/test-strcat.c @@ -54,11 +54,10 @@ #endif /* WIDE */ typedef CHAR *(*proto_t) (CHAR *, const CHAR *); -CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *); -IMPL (SIMPLE_STRCAT, 0) IMPL (STRCAT, 1) +/* Naive implementation to verify results. */ CHAR * SIMPLE_STRCAT (CHAR *dst, const CHAR *src) { diff --git a/string/test-strchr.c b/string/test-strchr.c index 4d2ab5fbeb..631e377991 100644 --- a/string/test-strchr.c +++ b/string/test-strchr.c @@ -35,7 +35,6 @@ #ifndef WIDE # ifdef USE_FOR_STRCHRNUL # define STRCHR strchrnul -# define stupid_STRCHR stupid_STRCHRNUL # define simple_STRCHR simple_STRCHRNUL # else # define STRCHR strchr @@ -51,7 +50,6 @@ # include # ifdef USE_FOR_STRCHRNUL # define STRCHR wcschrnul -# define stupid_STRCHR stupid_WCSCHRNUL # define simple_STRCHR simple_WCSCHRNUL # else # define STRCHR wcschr @@ -74,17 +72,9 @@ typedef CHAR *(*proto_t) (const CHAR *, int); +/* Naive implementation to verify results. */ CHAR * simple_STRCHR (const CHAR *s, int c) -{ - for (; *s != (CHAR) c; ++s) - if (*s == '\0') - return NULLRET ((CHAR *) s); - return (CHAR *) s; -} - -CHAR * -stupid_STRCHR (const CHAR *s, int c) { size_t n = STRLEN (s) + 1; @@ -94,8 +84,6 @@ stupid_STRCHR (const CHAR *s, int c) return NULLRET ((CHAR *) s - 1); } -IMPL (stupid_STRCHR, 0) -IMPL (simple_STRCHR, 0) IMPL (STRCHR, 1) static int @@ -231,7 +219,7 @@ check1 (void) { CHAR s[] __attribute__((aligned(16))) = L ("\xff"); CHAR c = L ('\xfe'); - CHAR *exp_result = stupid_STRCHR (s, c); + CHAR *exp_result = simple_STRCHR (s, c); FOR_EACH_IMPL (impl, 0) check_result (impl, s, c, exp_result); diff --git a/string/test-strcmp.c b/string/test-strcmp.c index ece03c6d0b..2372e92eaf 100644 --- a/string/test-strcmp.c +++ b/string/test-strcmp.c @@ -99,7 +99,6 @@ simple_strcmp (const char *s1, const char *s2) typedef int (*proto_t) (const CHAR *, const CHAR *); -IMPL (SIMPLE_STRCMP, 1) IMPL (STRCMP, 1) static int diff --git a/string/test-strcpy.c b/string/test-strcpy.c index 83b77073bb..7e7d10af63 100644 --- a/string/test-strcpy.c +++ b/string/test-strcpy.c @@ -54,11 +54,9 @@ # define STRCPY wcscpy # endif -CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *); - -IMPL (SIMPLE_STRCPY, 0) IMPL (STRCPY, 1) +/* Naive implementation to verify results. */ CHAR * SIMPLE_STRCPY (CHAR *dst, const CHAR *src) { diff --git a/string/test-strlen.c b/string/test-strlen.c index dd394dadc5..21a9cc10a6 100644 --- a/string/test-strlen.c +++ b/string/test-strlen.c @@ -37,6 +37,7 @@ typedef size_t (*proto_t) (const CHAR *); +/* Naive implementation to verify results. */ size_t simple_STRLEN (const CHAR *s) { @@ -55,7 +56,6 @@ builtin_strlen (const CHAR *p) IMPL (builtin_strlen, 0) #endif -IMPL (simple_STRLEN, 0) IMPL (STRLEN, 1) diff --git a/string/test-strncasecmp.c b/string/test-strncasecmp.c index 1aebc37bb6..126ced9e58 100644 --- a/string/test-strncasecmp.c +++ b/string/test-strncasecmp.c @@ -29,12 +29,10 @@ typedef int (*proto_t) (const char *, const char *, size_t); static int simple_strncasecmp (const char *, const char *, size_t); -static int stupid_strncasecmp (const char *, const char *, size_t); -IMPL (stupid_strncasecmp, 0) -IMPL (simple_strncasecmp, 0) IMPL (strncasecmp, 1) +/* Naive implementation to verify results. */ static int simple_strncasecmp (const char *s1, const char *s2, size_t n) { @@ -54,27 +52,6 @@ simple_strncasecmp (const char *s1, const char *s2, size_t n) return ret; } -static int -stupid_strncasecmp (const char *s1, const char *s2, size_t max) -{ - size_t ns1 = strlen (s1) + 1; - size_t ns2 = strlen (s2) + 1; - size_t n = ns1 < ns2 ? ns1 : ns2; - if (n > max) - n = max; - int ret = 0; - - while (n--) - { - if ((ret = ((unsigned char) tolower (*s1) - - (unsigned char) tolower (*s2))) != 0) - break; - ++s1; - ++s2; - } - return ret; -} - static int check_result (impl_t *impl, const char *s1, const char *s2, size_t n, int exp_result) diff --git a/string/test-strncat.c b/string/test-strncat.c index 86ec101258..5fcaa8637c 100644 --- a/string/test-strncat.c +++ b/string/test-strncat.c @@ -28,7 +28,6 @@ # define CHAR char # define UCHAR unsigned char # define SIMPLE_STRNCAT simple_strncat -# define STUPID_STRNCAT stupid_strncat # define STRLEN strlen # define MEMSET memset # define MEMCPY memcpy @@ -41,7 +40,6 @@ # define CHAR wchar_t # define UCHAR wchar_t # define SIMPLE_STRNCAT simple_wcsncat -# define STUPID_STRNCAT stupid_wcsncat # define STRLEN wcslen # define MEMSET wmemset # define MEMCPY wmemcpy @@ -51,14 +49,12 @@ #endif /* WIDE */ typedef 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) +/* Naive implementation to verify results. */ CHAR * -STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n) +SIMPLE_STRNCAT (CHAR *dst, const CHAR *src, size_t n) { CHAR *ret = dst; while (*dst++ != '\0'); diff --git a/string/test-strncmp.c b/string/test-strncmp.c index 3e35142548..693ab4d6c9 100644 --- a/string/test-strncmp.c +++ b/string/test-strncmp.c @@ -88,7 +88,6 @@ simple_strncmp (const char *s1, const char *s2, size_t n) typedef int (*proto_t) (const CHAR *, const CHAR *, size_t); -IMPL (SIMPLE_STRNCMP, 0) IMPL (STRNCMP, 1) diff --git a/string/test-strncpy.c b/string/test-strncpy.c index 4ae08abe44..f1f627a0b5 100644 --- a/string/test-strncpy.c +++ b/string/test-strncpy.c @@ -47,21 +47,16 @@ # include "test-string.h" # ifndef WIDE # define SIMPLE_STRNCPY simple_strncpy -# define STUPID_STRNCPY stupid_strncpy # define STRNCPY strncpy # else # define SIMPLE_STRNCPY simple_wcsncpy -# define STUPID_STRNCPY stupid_wcsncpy # define STRNCPY 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) +/* Naive implementation to verify results. */ CHAR * SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n) { @@ -76,18 +71,6 @@ SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n) return ret; } -CHAR * -STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n) -{ - size_t nc = STRNLEN (src, n); - size_t i; - - for (i = 0; i < nc; ++i) - dst[i] = src[i]; - for (; i < n; ++i) - dst[i] = '\0'; - return dst; -} #endif /* !STRNCPY_RESULT */ typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t); diff --git a/string/test-strnlen.c b/string/test-strnlen.c index 726c630db2..83c4502b9a 100644 --- a/string/test-strnlen.c +++ b/string/test-strnlen.c @@ -42,11 +42,10 @@ #endif /* !WIDE */ typedef size_t (*proto_t) (const CHAR *, size_t); -size_t SIMPLE_STRNLEN (const CHAR *, size_t); -IMPL (SIMPLE_STRNLEN, 0) IMPL (STRNLEN, 1) +/* Naive implementation to verify results. */ size_t SIMPLE_STRNLEN (const CHAR *s, size_t maxlen) { diff --git a/string/test-strpbrk.c b/string/test-strpbrk.c index 05fd81e0fc..de8dc0a9c3 100644 --- a/string/test-strpbrk.c +++ b/string/test-strpbrk.c @@ -47,22 +47,17 @@ # ifndef WIDE # define STRPBRK strpbrk # define SIMPLE_STRPBRK simple_strpbrk -# define STUPID_STRPBRK stupid_strpbrk # else # include # define STRPBRK wcspbrk # define SIMPLE_STRPBRK simple_wcspbrk -# define STUPID_STRPBRK stupid_wcspbrk # endif /* WIDE */ typedef CHAR *(*proto_t) (const CHAR *, const CHAR *); -CHAR *SIMPLE_STRPBRK (const CHAR *, const CHAR *); -CHAR *STUPID_STRPBRK (const CHAR *, const CHAR *); -IMPL (STUPID_STRPBRK, 0) -IMPL (SIMPLE_STRPBRK, 0) IMPL (STRPBRK, 1) +/* Naive implementation to verify results. */ CHAR * SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej) { @@ -72,22 +67,10 @@ SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej) while ((c = *s++) != '\0') for (r = rej; *r != '\0'; ++r) if (*r == c) - return (CHAR *) s - 1; + return (CHAR *) s - 1; return NULL; } -CHAR * -STUPID_STRPBRK (const CHAR *s, const CHAR *rej) -{ - size_t ns = STRLEN (s), nrej = STRLEN (rej); - size_t i, j; - - for (i = 0; i < ns; ++i) - for (j = 0; j < nrej; ++j) - if (s[i] == rej[j]) - return (CHAR *) s + i; - return NULL; -} #endif /* !STRPBRK_RESULT */ static void diff --git a/string/test-strrchr.c b/string/test-strrchr.c index a610200c11..bf4decb358 100644 --- a/string/test-strrchr.c +++ b/string/test-strrchr.c @@ -42,11 +42,10 @@ #endif typedef CHAR *(*proto_t) (const CHAR *, int); -CHAR *SIMPLE_STRRCHR (const CHAR *, int); -IMPL (SIMPLE_STRRCHR, 0) IMPL (STRRCHR, 1) +/* Naive implementation to verify results. */ CHAR * SIMPLE_STRRCHR (const CHAR *s, int c) { diff --git a/string/test-strspn.c b/string/test-strspn.c index 1680cb7828..a9c42458fe 100644 --- a/string/test-strspn.c +++ b/string/test-strspn.c @@ -29,7 +29,6 @@ # define CHAR char # define UCHAR unsigned char # define SIMPLE_STRSPN simple_strspn -# define STUPID_STRSPN stupid_strspn # define STRLEN strlen # define STRCHR strchr # define BIG_CHAR CHAR_MAX @@ -40,7 +39,6 @@ # define CHAR wchar_t # define UCHAR wchar_t # define SIMPLE_STRSPN simple_wcsspn -# define STUPID_STRSPN stupid_wcsspn # define STRLEN wcslen # define STRCHR wcschr # define BIG_CHAR WCHAR_MAX @@ -48,13 +46,10 @@ #endif /* WIDE */ typedef size_t (*proto_t) (const CHAR *, const CHAR *); -size_t SIMPLE_STRSPN (const CHAR *, const CHAR *); -size_t STUPID_STRSPN (const CHAR *, const CHAR *); -IMPL (STUPID_STRSPN, 0) -IMPL (SIMPLE_STRSPN, 0) IMPL (STRSPN, 1) +/* Naive implementation to verify results. */ size_t SIMPLE_STRSPN (const CHAR *s, const CHAR *acc) { @@ -72,23 +67,6 @@ SIMPLE_STRSPN (const CHAR *s, const CHAR *acc) return s - str - 1; } -size_t -STUPID_STRSPN (const CHAR *s, const CHAR *acc) -{ - size_t ns = STRLEN (s), nacc = STRLEN (acc); - size_t i, j; - - for (i = 0; i < ns; ++i) - { - for (j = 0; j < nacc; ++j) - if (s[i] == acc[j]) - break; - if (j == nacc) - return i; - } - return i; -} - static void do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res) { diff --git a/string/test-strstr.c b/string/test-strstr.c index 7f610f4cac..b1f2134360 100644 --- a/string/test-strstr.c +++ b/string/test-strstr.c @@ -21,14 +21,14 @@ #include "test-string.h" -#define STRSTR simple_strstr +#define STRSTR c_strstr #define libc_hidden_builtin_def(arg) /* nothing */ #define __strnlen strnlen #include "strstr.c" - +/* Naive implementation to verify results. */ static char * -stupid_strstr (const char *s1, const char *s2) +simple_strstr (const char *s1, const char *s2) { ssize_t s1len = strlen (s1); ssize_t s2len = strlen (s2); @@ -52,8 +52,7 @@ stupid_strstr (const char *s1, const char *s2) typedef char *(*proto_t) (const char *, const char *); -IMPL (stupid_strstr, 0) -IMPL (simple_strstr, 0) +IMPL (c_strstr, 0) IMPL (strstr, 1) @@ -130,7 +129,7 @@ check1 (void) const char s2[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD"; char *exp_result; - exp_result = stupid_strstr (s1, s2); + exp_result = simple_strstr (s1, s2); FOR_EACH_IMPL (impl, 0) check_result (impl, s1, s2, exp_result); } @@ -163,7 +162,7 @@ check2 (void) char *s2_page_cross = (void *) buf2 + page_size_real - 8; strcpy (s2_page_cross, s2_stack); - exp_result = stupid_strstr (s1_stack, s2_stack); + exp_result = simple_strstr (s1_stack, s2_stack); FOR_EACH_IMPL (impl, 0) { check_result (impl, s1_stack, s2_stack, exp_result); @@ -201,7 +200,7 @@ pr23637 (void) /* Ensure we don't match at the first 'x'. */ h[0] = 'x'; - char *exp_result = stupid_strstr (h, n); + char *exp_result = simple_strstr (h, n); FOR_EACH_IMPL (impl, 0) check_result (impl, h, n, exp_result); }