[PATCH 11/12] RISC-V: strcmp() size optimized version: Use compressed registers

m fally marlene.fally@gmail.com
Wed Apr 9 06:47:00 GMT 2025


From: puranikvinit <kvp933.vinit@gmail.com>

Swap uncompressed registers with compressed registers. Move the
li instruction downwards, so t2 can be replaced with a5.

Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: puranikvinit <kvp933.vinit@gmail.com>
---
 newlib/libc/machine/riscv/strcmp.S | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S
index cc29b7b8b..b49569db5 100644
--- a/newlib/libc/machine/riscv/strcmp.S
+++ b/newlib/libc/machine/riscv/strcmp.S
@@ -30,8 +30,6 @@ strcmp:
 
 .size	strcmp, .-strcmp
 #else
-  li    t2, -1
-
 #if !(__riscv_misaligned_slow || __riscv_misaligned_fast)
   or    a4, a0, a1
   and   a4, a4, SZREG-1
@@ -48,12 +46,13 @@ strcmp:
     REG_L a2, \i*SZREG(a0)
     REG_L a3, \i*SZREG(a1)
 
-    and   t0, a2, a5
-    or    t1, a2, a5
-    add   t0, t0, a5
-    or    t0, t0, t1
+    and   a4, a2, a5
+    or    t0, a2, a5
+    add   a4, a4, a5
+    or    a4, a4, t0
 
-    bne   t0, t2, .Lnull\i
+    li    a5, -1
+    bne   a4, a5, .Lnull\i
     .if \i+1-\n
       bne   a2, a3, .Lmismatch
     .else
-- 
2.49.0



More information about the Newlib mailing list