[PATCH] newlib: riscv: Remove unnecessary byte load/store for stpcpy()/strcpy()
Jeff Johnston
jjohnstn@redhat.com
Mon Apr 14 22:19:02 GMT 2025
Kito, this patch seemed to slip through the cracks. Could you please
review?
Thanks
-- Jeff J.
On Sun, Apr 6, 2025 at 4:04 PM Eric Salem <ericsalem@gmail.com> wrote:
> For architectures where XLEN is 32 bits, when detecting a null byte, a
> word is read at a time. Once a null is found in the word, its precise
> location is then determined. Make clear to the compiler that if the
> first three bytes are not null, the last byte must be null, and does not
> need to be read from the source string, since its value is always zero.
>
> Reviewed-by: Christian Herber <christian.herber@oss.nxp.com>
> Signed-off-by: Eric Salem <ericsalem@gmail.com>
> ---
> newlib/libc/machine/riscv/rv_string.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/newlib/libc/machine/riscv/rv_string.h
> b/newlib/libc/machine/riscv/rv_string.h
> index 362f66a024bf..7754303064c9 100644
> --- a/newlib/libc/machine/riscv/rv_string.h
> +++ b/newlib/libc/machine/riscv/rv_string.h
> @@ -82,8 +82,8 @@ static __inline char *__libc_strcpy(char *dst, const
> char *src, bool ret_start)
> if (!(*dst++ = src[0])) return dst0;
> if (!(*dst++ = src[1])) return dst0;
> if (!(*dst++ = src[2])) return dst0;
> - if (!(*dst++ = src[3])) return dst0;
> #if __riscv_xlen == 64
> + if (!(*dst++ = src[3])) return dst0;
> if (!(*dst++ = src[4])) return dst0;
> if (!(*dst++ = src[5])) return dst0;
> if (!(*dst++ = src[6])) return dst0;
> @@ -94,13 +94,13 @@ static __inline char *__libc_strcpy(char *dst, const
> char *src, bool ret_start)
> if (!(*dst++ = src[0])) return dst - 1;
> if (!(*dst++ = src[1])) return dst - 1;
> if (!(*dst++ = src[2])) return dst - 1;
> - if (!(*dst++ = src[3])) return dst - 1;
> #if __riscv_xlen == 64
> + if (!(*dst++ = src[3])) return dst - 1;
> if (!(*dst++ = src[4])) return dst - 1;
> if (!(*dst++ = src[5])) return dst - 1;
> if (!(*dst++ = src[6])) return dst - 1;
> - dst0 = dst;
> #endif
> + dst0 = dst;
> }
>
> *dst = 0;
> --
> 2.49.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20250414/d73c27b7/attachment.htm>
More information about the Newlib
mailing list