Re: [PATCH] newlib: riscv: Remove unnecessary byte load/store for stpcpy()/strcpy()
Kito Cheng <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <CA+yXCZDuFyCP=-HOsWxQqqbN7aC_k7h-PX=4EhjUBO5JPC1-bA@mail.gmail.com> |
This patch LGTM, thanks :) On Tue, Apr 15, 2025 at 6:19 AM Jeff Johnston <[email protected]> wrote: > > 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 <[email protected]> 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 <[email protected]> >> Signed-off-by: Eric Salem <[email protected]> >> --- >> 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 >>