[PATCH v2 11/11] RISC-V: Size optimized versions: Replace add with addi
m fally
marlene.fally@gmail.com
Thu Apr 10 11:23:08 GMT 2025
Replace add instructions with addi where applicable in
the size optimized versions of memmove(), memset(), memcpy(),
and strcmp(). This change does not affect the functions themselves
and is only done to improve syntactic accuracy.
Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: m fally <marlene.fally@gmail.com>
---
newlib/libc/machine/riscv/memcpy-asm.S | 6 +++---
newlib/libc/machine/riscv/memmove.S | 2 +-
newlib/libc/machine/riscv/memset.S | 4 ++--
newlib/libc/machine/riscv/strcmp.S | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/newlib/libc/machine/riscv/memcpy-asm.S b/newlib/libc/machine/riscv/memcpy-asm.S
index e9fe381d9..2771285f9 100644
--- a/newlib/libc/machine/riscv/memcpy-asm.S
+++ b/newlib/libc/machine/riscv/memcpy-asm.S
@@ -20,9 +20,9 @@ memcpy:
1:
lbu a4, 0(a1)
sb a4, 0(a3)
- add a2, a2, -1
- add a3, a3, 1
- add a1, a1, 1
+ addi a2, a2, -1
+ addi a3, a3, 1
+ addi a1, a1, 1
bnez a2, 1b
2:
diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S
index 6ecad9ad6..061472ca2 100644
--- a/newlib/libc/machine/riscv/memmove.S
+++ b/newlib/libc/machine/riscv/memmove.S
@@ -29,7 +29,7 @@ memmove:
add a1, a1, a3
.Lcopy:
lbu a5, 0(a1)
- add a2, a2, -1 /* copy bytes as long as a2 (= the number of bytes to be copied) > 0. the increment is done here to relax the RAW dependency between load and store */
+ addi a2, a2, -1 /* copy bytes as long as a2 (= the number of bytes to be copied) > 0. the increment is done here to relax the RAW dependency between load and store */
sb a5, 0(a4)
bnez a2, .Lincrement
diff --git a/newlib/libc/machine/riscv/memset.S b/newlib/libc/machine/riscv/memset.S
index 943835dc5..3d207e7eb 100644
--- a/newlib/libc/machine/riscv/memset.S
+++ b/newlib/libc/machine/riscv/memset.S
@@ -19,8 +19,8 @@ memset:
.Lset:
sb a1, 0(a3)
- add a2, a2, -1
- add a3, a3, 1
+ addi a2, a2, -1
+ addi a3, a3, 1
bnez a2, .Lset
.Ldone:
diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S
index cc29b7b8b..5d3370f6b 100644
--- a/newlib/libc/machine/riscv/strcmp.S
+++ b/newlib/libc/machine/riscv/strcmp.S
@@ -19,8 +19,8 @@ strcmp:
1:
lbu a2, 0(a0)
lbu a3, 0(a1)
- add a0, a0, 1
- add a1, a1, 1
+ addi a0, a0, 1
+ addi a1, a1, 1
bne a2, a3, 2f
bnez a2, 1b
--
2.49.0
More information about the Newlib
mailing list