From: "Xiao Zeng" <zengxiao@eswincomputing.com>
To: "Xiao Zeng" <zengxiao@eswincomputing.com>,
"newlib@sourceware.org" <newlib@sourceware.org>
Cc: "Jeff Johnston" <jjohnstn@redhat.com>,
"palmer@rivosinc.com" <palmer@rivosinc.com>,
jeffreyalaw <jeffreyalaw@gmail.com>,
"Torbjorn SVENSSON" <torbjorn.svensson@foss.st.com>
Subject: Re: [PATCH] newlib: libc: Improved the readability of strspn with minor optimization
Date: Wed, 20 Dec 2023 14:46:59 +0800 [thread overview]
Message-ID: <202312201446596692171@eswincomputing.com> (raw)
In-Reply-To: <20231220064340.36505-1-zengxiao@eswincomputing.com>
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
prev parent reply other threads:[~2023-12-20 6:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 6:43 Xiao Zeng
2023-12-20 6:46 ` Xiao Zeng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202312201446596692171@eswincomputing.com \
--to=zengxiao@eswincomputing.com \
--cc=jeffreyalaw@gmail.com \
--cc=jjohnstn@redhat.com \
--cc=newlib@sourceware.org \
--cc=palmer@rivosinc.com \
--cc=torbjorn.svensson@foss.st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).