[PATCH 1/4] RISC-V: strcmp: refactor labels for improved readability
puranikvinit
kvp933.vinit@gmail.com
Wed May 28 05:47:33 GMT 2025
Renames labels in strcmp.S to use descriptive .L prefixes (e.g.,
.Lcompare, .Lreturn_diff) instead of numeric labels (e.g., 1f, 2f). This
improves maintainability and aligns with modern assembly conventions
without affecting functionality.
Signed-off-by: puranikvinit <kvp933.vinit@gmail.com>
Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
---
newlib/libc/machine/riscv/strcmp.S | 31 +++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S
index 5d3370f6b..25ad9ef2e 100644
--- a/newlib/libc/machine/riscv/strcmp.S
+++ b/newlib/libc/machine/riscv/strcmp.S
@@ -16,15 +16,15 @@
.type strcmp, @function
strcmp:
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
-1:
+.Lcompare:
lbu a2, 0(a0)
lbu a3, 0(a1)
addi a0, a0, 1
addi a1, a1, 1
- bne a2, a3, 2f
- bnez a2, 1b
+ bne a2, a3, .Lreturn_diff
+ bnez a2, .Lcompare
-2:
+.Lreturn_diff:
sub a0, a2, a3
ret
@@ -114,7 +114,7 @@ strcmp:
srl a5, a3, 8*SZREG-16
sub a0, a4, a5
and a1, a0, 0xff
- bnez a1, 1f
+ bnez a1, .Lfinal_upper_diff
ret
.Lmismatch_upper:
@@ -122,10 +122,11 @@ strcmp:
srl a5, a5, 8*SZREG-16
sub a0, a4, a5
and a1, a0, 0xff
- bnez a1, 1f
+ bnez a1, .Lfinal_upper_diff
ret
-1:and a4, a4, 0xff
+.Lfinal_upper_diff:
+ and a4, a4, 0xff
and a5, a5, 0xff
sub a0, a4, a5
ret
@@ -146,19 +147,23 @@ strcmp:
srl a4, a2, 8
srl a5, a3, 8
- bne a4, a5, 1f
+ bne a4, a5, .Lbyte_diff
and a4, a2, 0xff
and a5, a3, 0xff
-1:sub a0, a4, a5
+
+.Lbyte_diff:
+ sub a0, a4, a5
ret
.Lmismatch_lower:
srl a2, a4, 8
srl a3, a5, 8
- bne a2, a3, 1f
+ bne a2, a3, .Lfinal_lower_diff
and a2, a4, 0xff
and a3, a5, 0xff
-1:sub a0, a2, a3
+
+.Lfinal_lower_diff:
+ sub a0, a2, a3
ret
#endif
@@ -169,10 +174,10 @@ strcmp:
lbu a3, 0(a1)
add a0, a0, 1
add a1, a1, 1
- bne a2, a3, 1f
+ bne a2, a3, .Lmisaligned_diff
bnez a2, .Lmisaligned
-1:
+.Lmisaligned_diff:
sub a0, a2, a3
ret
--
2.34.1
More information about the Newlib
mailing list