[07/12] RISC-V: memcpy() size optimized version: Replace lb with lbu

Message ID 20250409064701.3435-8-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 lb with lbu to avoid unnecessary sign extension.

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Kito Cheng April 9, 2025, 7:19 a.m. UTC | #1
Although I think it's no difference, but maybe some arch may have
higher cost to doing the sign-extension, so LGTM

On Wed, Apr 9, 2025 at 2:59 PM m fally <marlene.fally@gmail.com> wrote:
>
> From: Mahmoud Abumandour <ma.mandourr@gmail.com>
>
> Replace lb with lbu to avoid unnecessary sign extension.
>
> 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 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/newlib/libc/machine/riscv/memcpy-asm.S b/newlib/libc/machine/riscv/memcpy-asm.S
> index 5571e4704..d05ff5055 100644
> --- a/newlib/libc/machine/riscv/memcpy-asm.S
> +++ b/newlib/libc/machine/riscv/memcpy-asm.S
> @@ -18,7 +18,7 @@ memcpy:
>    beqz a2, 2f
>
>  1:
> -  lb t2, 0(a1)
> +  lbu t2, 0(a1)
>    sb t2, 0(t1)
>    add   a2, a2, -1
>    add   t1, t1, 1
> --
> 2.49.0
>
  

Patch

diff --git a/newlib/libc/machine/riscv/memcpy-asm.S b/newlib/libc/machine/riscv/memcpy-asm.S
index 5571e4704..d05ff5055 100644
--- a/newlib/libc/machine/riscv/memcpy-asm.S
+++ b/newlib/libc/machine/riscv/memcpy-asm.S
@@ -18,7 +18,7 @@  memcpy:
   beqz a2, 2f
 
 1:
-  lb t2, 0(a1)
+  lbu t2, 0(a1)
   sb t2, 0(t1)
   add   a2, a2, -1
   add   t1, t1, 1