[08/12] RISC-V: memcpy() size optimized version: Use compressed registers

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

Commit Message

m fally April 9, 2025, 6:46 a.m. UTC
  From: Mahmoud Abumandour <ma.mandourr@gmail.com>

Replace registers t1 and t2 with registers a3 and a4 respectively,
so that the affected instructions can be compressed.

Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
---
 newlib/libc/machine/riscv/memcpy-asm.S | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Kito Cheng April 9, 2025, 7:48 a.m. UTC | #1
LGTM

On Wed, Apr 9, 2025 at 2:52 PM m fally <marlene.fally@gmail.com> wrote:
>
> From: Mahmoud Abumandour <ma.mandourr@gmail.com>
>
> Replace registers t1 and t2 with registers a3 and a4 respectively,
> so that the affected instructions can be compressed.
>
> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
> Signed-off-by: Mahmoud Abumandour <ma.mandourr@gmail.com>
> ---
>  newlib/libc/machine/riscv/memcpy-asm.S | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/newlib/libc/machine/riscv/memcpy-asm.S b/newlib/libc/machine/riscv/memcpy-asm.S
> index d05ff5055..e9fe381d9 100644
> --- a/newlib/libc/machine/riscv/memcpy-asm.S
> +++ b/newlib/libc/machine/riscv/memcpy-asm.S
> @@ -14,14 +14,14 @@
>  .global memcpy
>  .type  memcpy, @function
>  memcpy:
> -  mv t1, a0
> +  mv a3, a0
>    beqz a2, 2f
>
>  1:
> -  lbu t2, 0(a1)
> -  sb t2, 0(t1)
> +  lbu a4, 0(a1)
> +  sb a4, 0(a3)
>    add   a2, a2, -1
> -  add   t1, t1, 1
> +  add   a3, a3, 1
>    add   a1, a1, 1
>    bnez a2, 1b
>
> --
> 2.49.0
>
  

Patch

diff --git a/newlib/libc/machine/riscv/memcpy-asm.S b/newlib/libc/machine/riscv/memcpy-asm.S
index d05ff5055..e9fe381d9 100644
--- a/newlib/libc/machine/riscv/memcpy-asm.S
+++ b/newlib/libc/machine/riscv/memcpy-asm.S
@@ -14,14 +14,14 @@ 
 .global memcpy
 .type	memcpy, @function
 memcpy:
-  mv t1, a0
+  mv a3, a0
   beqz a2, 2f
 
 1:
-  lbu t2, 0(a1)
-  sb t2, 0(t1)
+  lbu a4, 0(a1)
+  sb a4, 0(a3)
   add   a2, a2, -1
-  add   t1, t1, 1
+  add   a3, a3, 1
   add   a1, a1, 1
   bnez a2, 1b