From patchwork Wed Mar 8 10:41:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 66119 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBCA2385B53B for ; Wed, 8 Mar 2023 10:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBCA2385B53B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678272127; bh=7S/ck5uPfMy4I+Y9MIjkYVAgRmVUsOcF/OGf9Q0ve38=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oERi/U38dROkZD4IqDAnOzoYdh4OM3i/FPrVjOrFmZJNuiq3b2GrJNqZURywx2hYe mSPU32O3XysIjUQkqRDOq/chrwXwx98Ygye+ZK8fKMk/7XKVVJ9ZfSdQh1culU1ZWO 8lJyR3mgtAIvFZmdesvjAy6QTFcPUO8qmXJcYwPA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2077.outbound.protection.outlook.com [40.107.249.77]) by sourceware.org (Postfix) with ESMTPS id 52EC43858C54 for ; Wed, 8 Mar 2023 10:41:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52EC43858C54 Received: from AM5PR0601CA0048.eurprd06.prod.outlook.com (2603:10a6:203:68::34) by AS8PR08MB6549.eurprd08.prod.outlook.com (2603:10a6:20b:33d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16; Wed, 8 Mar 2023 10:41:39 +0000 Received: from VI1EUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:68:cafe::6d) by AM5PR0601CA0048.outlook.office365.com (2603:10a6:203:68::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29 via Frontend Transport; Wed, 8 Mar 2023 10:41:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT059.mail.protection.outlook.com (100.127.144.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.29 via Frontend Transport; Wed, 8 Mar 2023 10:41:39 +0000 Received: ("Tessian outbound 0df938784972:v135"); Wed, 08 Mar 2023 10:41:39 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 79104c575203a25d X-CR-MTA-TID: 64aa7808 Received: from b24b270155b4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id E737A5AF-8CF0-4EE6-8421-0389BB4A6250.1; Wed, 08 Mar 2023 10:41:32 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b24b270155b4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 08 Mar 2023 10:41:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7GkdwayBWkW/4U9qVK9YFSZLmAyAZsxyw84KsVIKscYEaOBIrC7ChiqDmE4U21FHzL6PwAtWqOlqHBcqTNK+lWhrjuvoQGglMC4Iud4HRzhWZJ6ViY+AjQB+2vKq2m/7U03FfFIUHtkIlCXyLfLyMymHUB7jngWOXlJ4XjA/X94IEUfCFOQu+ZQur7UOtExJzFkHujmh4XLfSFzITMAGXLlNi/Npjf1cxm+ge+rNqINcfkb3WjzoX38Yqzpt0MiHuJVj1WSJHPPuGtQbwsyibGyKn9Wh01RhqY32J+ymn3m8ewJIH33gVdKoGoytKErh0fBNSSnQfKFqeymg6te8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7S/ck5uPfMy4I+Y9MIjkYVAgRmVUsOcF/OGf9Q0ve38=; b=aBg+g3GhbqIm7HlythwcYCegRZWfCY7FxD9OnFvzFZjhpCFLPeuY0cYMV8GUCwMbLgnkprsibdm2yLOlzfVE12nhx3CK1yH15k7eFTeJumeo+z+QYnIEF0utvi2TObmtGm5MQDN1AnUiOLPiuIVcZZHvkPIZNebDMJcmwW3diHuIXiCsZuH3Ouh0TLNCKmXn4rmtZ0qlCjAKur5Cqt7mAfLzWmpiuw1WogqPUzOrJy0hllmP/2gmjxklzk44MlNoTLrCLOZQU30ifrAwFKou25AMT1jH4/60OOTrsfrLZRvX4rHgbqHc1PL4CNXVSQj6RiMGDEW+U8+SgE2fg3NMvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from PAWPR08MB8982.eurprd08.prod.outlook.com (2603:10a6:102:33f::20) by AS4PR08MB8096.eurprd08.prod.outlook.com (2603:10a6:20b:58b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.16; Wed, 8 Mar 2023 10:41:24 +0000 Received: from PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::dc17:8fa2:cce5:3573]) by PAWPR08MB8982.eurprd08.prod.outlook.com ([fe80::dc17:8fa2:cce5:3573%7]) with mapi id 15.20.6156.025; Wed, 8 Mar 2023 10:41:24 +0000 To: 'GNU C Library' Subject: [PATCH] Benchtests: Remove simple_str(n)cmp Thread-Topic: [PATCH] Benchtests: Remove simple_str(n)cmp Thread-Index: AQHZUapJRmrkRAgZP0m1HpzoCJB4MQ== Date: Wed, 8 Mar 2023 10:41:24 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; x-ms-traffictypediagnostic: PAWPR08MB8982:EE_|AS4PR08MB8096:EE_|VI1EUR03FT059:EE_|AS8PR08MB6549:EE_ X-MS-Office365-Filtering-Correlation-Id: c0774f39-8811-42f0-3016-08db1fc1b313 x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: kg223/K3P3ZaKXkJaJKlWDKv++1TtPKN4owZJdVHVqC48NeokBuL77Ewb2WNfSqJ+k8QyXac1wKHX7SzVIW8aCUIYLLuyYvpVoNYxBTujQ7cLrmeuo9NubNnQtzDC149a558fNvhjMdECtw8QPOzDVjUi/oQb8NdSdtLwmgh0D0Q/s/lJ3ippaa1lfjsLdE1wLu36mMU4LGPLvxnak33KuUz7NqF/XlocXgE0oGOk9UC/t7zzjt3nNWwcc5R2z6y3z+YzARPcqK+4DStYXKGTQrL87pDfeWkH1toKsfErslSfQB1CwSRoMR2AS/cbuptjpQWbh/86YVnRsMSdxxPFOxkTsXkYP3ih8o+DAjoxhCNGK79oI6FfPrDJV8e5AD4izswfqYLcfAxsr6m8D2+ExpFPBFawMHaHxHju4abEZyzgilR9RuJoZU8TuDjkWD5wSXtvIbRZuhCz1N+83YpKe+Wal81HsHvS7BxMG80JyPreNy/hIOosBHahXTIf/B+Kq/UBxM+9GSPiYQ912SXmt/3O3b9NAgDAD9ahdkT8b5elFvSp0UyGUPEsmAO4DL8gMhHeNlJac8novmEfgKzqPcUAGYtCO2xgW3F1wFsn4FBvecLSJg6lpFC099p+BzwIj6r4uJ5vAeLs7f4AN3EJTEXjSiqHsk7F2Bt0LTZmC2FRoImisu7/8HdNSNibVoJgZWFnzrkbjJ38insb6z+bA== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAWPR08MB8982.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(4636009)(39860400002)(366004)(346002)(396003)(376002)(136003)(451199018)(9686003)(7696005)(38070700005)(55016003)(41300700001)(186003)(316002)(8676002)(64756008)(66446008)(66476007)(66946007)(66556008)(26005)(76116006)(91956017)(6506007)(122000001)(86362001)(71200400001)(38100700002)(33656002)(6916009)(5660300002)(2906002)(478600001)(52536014)(8936002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB8096 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 8890008e-5d53-46ea-41b7-08db1fc1a9e1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ld2hlKxeQYTojDZcpK+MRh1vdxn/0opHOfEOFiWOtAyLLgK5hSGbnRecVVNP/HodHoayW/kiG+V8Yp1HhAwccm1vHvbefq3bkWb0rJWmCfjasbyE3hLbH3C/ZZiAg+s8s+SHtSbcFPtwPmih6qmE3WuqaVbiZi2fU6oeqm2sAuLZdKvQAKmd1sILK1k6M8DD5p1yQCYr8Wa++tQQLwucDULzD9q1mhojoOKX32usgTSqOz20HYPpED/t1Iy0mw+eHpCLXbOMOYJlmm03JuaawmM8gMy9/E+AHIBMNR8TFeoPZE+FKZ4YN8nLyJjS4vr6yLS6a4vc1raTItus1mCt0cxQh8IEsy0leUbqTCWjF9lKv/GOIR9BnoqAEbvGQI7lKOLWU4ps5Df8ZFVvZZzxsZrrfzFW+X6ZPcRpYKEnHVVPTvmxJZIcbzGY6aJG9oM/eq0i+WB7p0PmEK3vrSvKOsG59RRhjz3NGMdBVhMQcHqxafQQbVqA6t7GOPqJbXRsqYLshTqe5mELJBz7/+TsHL12mIDIIfWIKqs2Lzvl8cXeTL8nF9nKrOc/kLYOyRRf3UX5Fy3Uc6/vmSV7O67OLJzn5tkQ4hqsg6xhppErF6b/TSB/mJe2w3pshBraonYq6aAZRMLxXaqYW1ftdM8kC9LLAQ4fZ+abktyTBLhsT/1mnY8WlkQv31w78zwF3oLY189clcF+X6k/zh95pKZCRA== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230025)(4636009)(136003)(39860400002)(396003)(376002)(346002)(451199018)(36840700001)(46966006)(40470700004)(356005)(6916009)(8936002)(41300700001)(70586007)(70206006)(8676002)(5660300002)(82740400003)(81166007)(86362001)(36860700001)(33656002)(2906002)(7696005)(6506007)(26005)(316002)(55016003)(478600001)(52536014)(82310400005)(47076005)(83380400001)(9686003)(40480700001)(186003)(40460700003)(336012); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2023 10:41:39.5179 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c0774f39-8811-42f0-3016-08db1fc1b313 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6549 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Wilco Dijkstra via Libc-alpha From: Wilco Dijkstra Reply-To: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 --git a/benchtests/bench-strcmp.c b/benchtests/bench-strcmp.c index 8cd690bac1a612d99ecd11c8dc917f7cc36e19ea..65fd04b43a2aeaab85ee4996f083333a32d7b29f 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 a714e5a9d42541f8781c3e92f0212cb9ab18e61f..53707e6bca675efe57a16cce3c343153a18894ab 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