[v2,06/11] RISC-V: memmove() size optimized version: Relax RAW dependency

Message ID 20250410112308.77247-7-marlene.fally@gmail.com
State New
Headers
Series newlib: RISC-V: Optimize memory and string functions for code size |

Commit Message

m fally April 10, 2025, 11:23 a.m. UTC
  Move the instruction that increments the remaining number of
bytes to be copied inbetween the load and store instructions.
This is done in order to relax the RAW dependency between the
load and store instructions.

Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: m fally <marlene.fally@gmail.com>
---
 newlib/libc/machine/riscv/memmove.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Patch

diff --git a/newlib/libc/machine/riscv/memmove.S b/newlib/libc/machine/riscv/memmove.S
index 671a6a158..6ecad9ad6 100644
--- a/newlib/libc/machine/riscv/memmove.S
+++ b/newlib/libc/machine/riscv/memmove.S
@@ -28,9 +28,9 @@  memmove:
   add   a4, a4, a3 		/* in case of source address < destination address, increment both addresses by -1 before copying any data to obtain the correct start addresses */
   add   a1, a1, a3
 .Lcopy:
-  lbu a5, 0(a1)			/* copy bytes as long as a2 (= the number of bytes to be copied) > 0 */
+  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 */
   sb a5, 0(a4)
-  add   a2, a2, -1
   bnez a2, .Lincrement
 
 .Ldone: