Message ID | 20231220064340.36505-1-zengxiao@eswincomputing.com |
---|---|
State | New |
Headers |
Return-Path: <newlib-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 C996738618B5 for <patchwork@sourceware.org>; Wed, 20 Dec 2023 06:45:02 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from sgoci-sdnproxy-4.icoremail.net (sgoci-sdnproxy-4.icoremail.net [129.150.39.64]) by sourceware.org (Postfix) with ESMTP id E2E9B385E019 for <newlib@sourceware.org>; Wed, 20 Dec 2023 06:44:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2E9B385E019 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E2E9B385E019 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.150.39.64 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703054693; cv=none; b=GpJ6hgzpUitb4ZlORc7hpQEfurhbfWHUzLlkSkH8CMlXXjF+HdOrlLgbuv6Sl4aRPPdMc7YzIHldQ92j0/tK7Bex3ES9FI84IJOwoZB51epl2sNj0oMymIcsBR9+pzU3+h2kltqAPymh4NMTxJgWiqNRq8WqV15Gz9EDO8osIIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703054693; c=relaxed/simple; bh=LvHgi2RmfhBMyIgLYkjixibcx7VbNihckv7AW8OYkjU=; h=From:To:Subject:Date:Message-Id; b=SvgRDglLUB6M/V+mVH6A8A4UBlDHrd6zpSHEmLmqUi8aOd/PyrbzJg3s5R0TiNz+Js/LohxMzkZvQalksnuFYxTaNJt/ebwXnxgrFYScLGUT+6wB1mopdfj94vJf+GeuOaWfjfArErtIlfHmAu4ee+pJWixolmZ9ePh0IGU2fO4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.31]) by app2 (Coremail) with SMTP id TQJkCgB3BdQDjYJl4EoCAA--.22906S4; Wed, 20 Dec 2023 14:43:15 +0800 (CST) From: Xiao Zeng <zengxiao@eswincomputing.com> To: newlib@sourceware.org Cc: jjohnstn@redhat.com, palmer@rivosinc.com, jeffreyalaw@gmail.com, torbjorn.svensson@foss.st.com, Xiao Zeng <zengxiao@eswincomputing.com> Subject: [PATCH] newlib: libc: Improved the readability of strspn with minor optimization Date: Wed, 20 Dec 2023 14:43:40 +0800 Message-Id: <20231220064340.36505-1-zengxiao@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: TQJkCgB3BdQDjYJl4EoCAA--.22906S4 X-Coremail-Antispam: 1UD129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY07AC8VAFwI0_Gr0_Xr1l1xkIjI8I6I8E 6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28Cjx kF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8I cVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87 Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE 6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72 CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7 MxkIecxEwVCm-wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_ Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v2 6r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0J UdHUDUUUUU= X-CM-SenderInfo: p2hqw5xldrqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org |
Series |
newlib: libc: Improved the readability of strspn with minor optimization
|
|
Commit Message
Xiao Zeng
Dec. 20, 2023, 6:43 a.m. UTC
Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
---
newlib/libc/string/strspn.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
As mentioned in [PATCH] newlib: libc: Improved the readability of strcspn with minor optimization: <https://sourceware.org/pipermail/newlib/2023/020766.html> This patch did the same thing and passed the testcases. Similarly, provide a comparison of risc-v assembly: no-patch: --------------------------------------------------------- libc_a-strspn.o: file format elf64-littleriscv Disassembly of section .text: 0000000000000000 <strspn>: 0: 00054683 lbu a3,0(a0) 4: 00050893 mv a7,a0 0000000000000008 <.LVL1>: 8: 04068463 beqz a3,50 <.L6> c: 0005c803 lbu a6,0(a1) 0000000000000010 <.LVL2>: 10: 00000513 li a0,0 0000000000000014 <.LVL3>: 14: 00081463 bnez a6,1c <.L13> 18: 00008067 ret 000000000000001c <.L13>: 1c: 00088613 mv a2,a7 0000000000000020 <.L5>: 20: 00058793 mv a5,a1 24: 00080713 mv a4,a6 28: 00c0006f j 34 <.L4> 000000000000002c <.L14>: 2c: 0007c703 lbu a4,0(a5) 30: 00070c63 beqz a4,48 <.L11> 0000000000000034 <.L4>: 34: 00178793 addi a5,a5,1 0000000000000038 <.LVL7>: 38: fee69ae3 bne a3,a4,2c <.L14> 3c: 00164683 lbu a3,1(a2) 40: 00160613 addi a2,a2,1 44: fc069ee3 bnez a3,20 <.L5> 0000000000000048 <.L11>: 48: 41160533 sub a0,a2,a7 4c: 00008067 ret 0000000000000050 <.L6>: 50: 00000513 li a0,0 0000000000000054 <.LVL10>: 54: 00008067 ret --------------------------------------------------------- patch --------------------------------------------------------- libc_a-strspn.o: file format elf64-littleriscv Disassembly of section .text: 0000000000000000 <strspn>: 0: 00054683 lbu a3,0(a0) 4: 04068063 beqz a3,44 <.L11> 8: 0005c803 lbu a6,0(a1) 000000000000000c <.LVL1>: c: 00050613 mv a2,a0 10: 02080a63 beqz a6,44 <.L11> 0000000000000014 <.L5>: 14: 00058793 mv a5,a1 18: 00080713 mv a4,a6 1c: 00c0006f j 28 <.L6> 0000000000000020 <.L4>: 20: 0007c703 lbu a4,0(a5) 24: 00070c63 beqz a4,3c <.L12> 0000000000000028 <.L6>: 28: 00178793 addi a5,a5,1 000000000000002c <.LVL5>: 2c: fee69ae3 bne a3,a4,20 <.L4> 0000000000000030 <.LDL1>: 30: 00164683 lbu a3,1(a2) 34: 00160613 addi a2,a2,1 38: fc069ee3 bnez a3,14 <.L5> 000000000000003c <.L12>: 3c: 40a60533 sub a0,a2,a0 0000000000000040 <.LVL7>: 40: 00008067 ret 0000000000000044 <.L11>: 44: 00000513 li a0,0 0000000000000048 <.LVL9>: 48: 00008067 ret --------------------------------------------------------- After careful comparison, it was found that there are fewer assembly instructions after the patch. 2023-12-20 14:43 Xiao Zeng <zengxiao@eswincomputing.com> wrote: > >Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com> >--- > newlib/libc/string/strspn.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > >diff --git a/newlib/libc/string/strspn.c b/newlib/libc/string/strspn.c >index baf239947..9d46ce2eb 100644 >--- a/newlib/libc/string/strspn.c >+++ b/newlib/libc/string/strspn.c >@@ -41,10 +41,11 @@ strspn (const char *s1, > for (c = s2; *c; c++) > { > if (*s1 == *c) >- break; >+ goto end; > } > if (*c == '\0') > break; >+end: > s1++; > } > >-- >2.17.1 Thanks Xiao Zeng
diff --git a/newlib/libc/string/strspn.c b/newlib/libc/string/strspn.c index baf239947..9d46ce2eb 100644 --- a/newlib/libc/string/strspn.c +++ b/newlib/libc/string/strspn.c @@ -41,10 +41,11 @@ strspn (const char *s1, for (c = s2; *c; c++) { if (*s1 == *c) - break; + goto end; } if (*c == '\0') break; +end: s1++; }