Message ID | 20230202181149.2181553-15-adhemerval.zanella@linaro.org (mailing list archive) |
---|---|
State | Committed |
Commit | 167f6230af97690985ccbc9b3026a7c32ec2d6e9 |
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 303E5382E6B5 for <patchwork@sourceware.org>; Thu, 2 Feb 2023 18:16:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 303E5382E6B5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675361781; bh=NEs74f/T44NZOxbSYnquYKRGf5z3hN+b5jVwTA7327U=; 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=RFFhdzsM78xD9fx0OVlhKiWAH2TkMsmyqweeFsW9/Ui8U92XDN2XgSnv/cfyB3w4L xhxtpv11PTlbB4w0rpD/xRSCTUNATa37A+oz/3ytF004qZFTJ49w37A/Zmjyv7PEI/ uzRCD/u59wqH+Vt6RwZYDgeIQn3LGxQgtPOUOFRU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 8516D385483F for <libc-alpha@sourceware.org>; Thu, 2 Feb 2023 18:12:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8516D385483F Received: by mail-ot1-x331.google.com with SMTP id k91-20020a9d19e4000000b0068bca1294aaso690339otk.8 for <libc-alpha@sourceware.org>; Thu, 02 Feb 2023 10:12:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NEs74f/T44NZOxbSYnquYKRGf5z3hN+b5jVwTA7327U=; b=yreE0X2QJZSot5mzTWBxPcH+ObnFgqw6DDonWHR+Y4dzwYEiKCyLpKGwqpqFxAMsx1 6u4ltOriVBvM9ngK37sS5TEnrduJUwRCN24tYgdTm7eB1yXctz6rNyhdOAdWhqBgbPpe pSUi6RAfe6ViO3VELcL5q5YLBzk6mfX63fa8f0TDtzQIBBeWJ0gsXD4nFMFRHl2oUQFD P5x7bVjwohsdOsk4+LC1SWrAIEa2AAvoyjTSUjjJF2AtqYGy9sUYMFS9e5gZCW3mgs8G TDvqXLrzhrJgJExEYl3gsYKvlI4kAxtMRoZSHXkH3TYECzvZMpbh8TzrnBGFvTwwljLL xTEA== X-Gm-Message-State: AO0yUKXFz9pGHaJGi23cKXHry/p5J7a+/sKpASawbtmgmdJ0bylFJNmO 1bobsbnsYoqYnHHUSOuSRZMD4iXIc8hLMUNKmfk= X-Google-Smtp-Source: AK7set/Gy/dDQ7DPIncVlRHQNNV+Js5zgyVb2VO+kW41UM8pjuZVvtOPl6sEGJmNfH+jwrC2qS+TIw== X-Received: by 2002:a05:6830:918:b0:68b:c490:5372 with SMTP id v24-20020a056830091800b0068bc4905372mr4833781ott.22.1675361550181; Thu, 02 Feb 2023 10:12:30 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:1887:da12:b9d3:2162:a28c]) by smtp.gmail.com with ESMTPSA id ci10-20020a05683063ca00b00684a10970adsm126689otb.16.2023.02.02.10.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 10:12:29 -0800 (PST) To: libc-alpha@sourceware.org, Richard Henderson <richard.henderson@linaro.org>, Jeff Law <jeffreyalaw@gmail.com>, Xi Ruoyao <xry111@xry111.site>, Noah Goldstein <goldstein.w.n@gmail.com> Subject: [PATCH v12 14/31] string: Improve generic strrchr with memrchr and strlen Date: Thu, 2 Feb 2023 15:11:32 -0300 Message-Id: <20230202181149.2181553-15-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> References: <20230202181149.2181553-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Adhemerval Zanella <adhemerval.zanella@linaro.org> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Improve generic string routines
|
|
Checks
Context | Check | Description |
---|---|---|
dj/TryBot-apply_patch | success | Patch applied to master at the time it was sent |
Commit Message
Adhemerval Zanella
Feb. 2, 2023, 6:11 p.m. UTC
Now that both strlen and memrchr have word vectorized implementation, it should be faster to implement strrchr based on memrchr over the string length instead of calling strchr on a loop. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, and powerpc64-linux-gnu by removing the arch-specific assembly implementation and disabling multi-arch (it covers both LE and BE for 64 and 32 bits). --- string/strrchr.c | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-)
Comments
On 2/2/23 08:11, Adhemerval Zanella wrote: > Now that both strlen and memrchr have word vectorized implementation, > it should be faster to implement strrchr based on memrchr over the > string length instead of calling strchr on a loop. > > Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, > and powerpc64-linux-gnu by removing the arch-specific assembly > implementation and disabling multi-arch (it covers both LE and BE > for 64 and 32 bits). > --- > string/strrchr.c | 18 +----------------- > 1 file changed, 1 insertion(+), 17 deletions(-) memrchr needs libc_hidden_builtin_proto. On riscv64: c: 00000097 auipc ra,0x0 c: R_RISCV_CALL __GI_strlen c: R_RISCV_RELAX *ABS* 10: 000080e7 jalr ra # c <__GI_strrchr+0xc> ... 24: 00000317 auipc t1,0x0 24: R_RISCV_CALL_PLT __memrchr 24: R_RISCV_RELAX *ABS* 28: 00030067 jr t1 # 24 <.LVL2+0x8> r~
On 04/02/23 00:06, Richard Henderson wrote: > On 2/2/23 08:11, Adhemerval Zanella wrote: >> Now that both strlen and memrchr have word vectorized implementation, >> it should be faster to implement strrchr based on memrchr over the >> string length instead of calling strchr on a loop. >> >> Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu, >> and powerpc64-linux-gnu by removing the arch-specific assembly >> implementation and disabling multi-arch (it covers both LE and BE >> for 64 and 32 bits). >> --- >> string/strrchr.c | 18 +----------------- >> 1 file changed, 1 insertion(+), 17 deletions(-) > > memrchr needs libc_hidden_builtin_proto. On riscv64: > > c: 00000097 auipc ra,0x0 > c: R_RISCV_CALL __GI_strlen > c: R_RISCV_RELAX *ABS* > 10: 000080e7 jalr ra # c <__GI_strrchr+0xc> > ... > 24: 00000317 auipc t1,0x0 > 24: R_RISCV_CALL_PLT __memrchr > 24: R_RISCV_RELAX *ABS* > 28: 00030067 jr t1 # 24 <.LVL2+0x8> > > > r~ Similar to strchr [1], static linker ends up creating the expected local call: $ riscv64-glibc-linux-gnu-objdump -dr libc.so [...] 0000000000088f5c <strrchr>: 88f5c: 7179 addi sp,sp,-48 88f5e: e84a sd s2,16(sp) 88f60: 000e7917 auipc s2,0xe7 88f64: 73893903 ld s2,1848(s2) # 170698 <__stack_chk_guard@GLIBC_2.27> 88f68: 00093783 ld a5,0(s2) [...] 88f9a: 6145 addi sp,sp,48 88f9c: c70fd06f j 8640c <memrchr> 88fa0: 193500ef jal ra,d9932 <__stack_chk_fail> [...] But I agree that we should change to have the libc_hidden_builin_proto in this case. I will send a patch to fix it. [1] https://sourceware.org/pipermail/libc-alpha/2023-February/145322.html
diff --git a/string/strrchr.c b/string/strrchr.c index 3c6e715d3b..7b76dea4e0 100644 --- a/string/strrchr.c +++ b/string/strrchr.c @@ -27,23 +27,7 @@ char * STRRCHR (const char *s, int c) { - const char *found, *p; - - c = (unsigned char) c; - - /* Since strchr is fast, we use it rather than the obvious loop. */ - - if (c == '\0') - return strchr (s, '\0'); - - found = NULL; - while ((p = strchr (s, c)) != NULL) - { - found = p; - s = p + 1; - } - - return (char *) found; + return __memrchr (s, c, strlen (s) + 1); } #ifdef weak_alias