[PATCH] RISC-V: strcpy size optimized: do not compile unreacheble code

Jeff Johnston jjohnstn@redhat.com
Tue Aug 26 15:11:24 GMT 2025


Hi Alexey,

Could you please reformat the condition to avoid double negatives?

-- Jeff J.

On Mon, Aug 25, 2025 at 8:20 AM Alexey Lapshin <alexey.lapshin@espressif.com>
wrote:

> If misaligned access is allowed on the target machine, there is no need
> to compile the byte-to-byte copy loop at the end of the strcpy function.
> All bytes are already in place due to the earlier logic.
>
> Signed-off-by: Konstantin Kondrashov <konstantin@espressif.com>
> ---
>  newlib/libc/machine/riscv/rv_string.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/newlib/libc/machine/riscv/rv_string.h
> b/newlib/libc/machine/riscv/rv_string.h
> index dc2a26daf..9f5eb4099 100644
> --- a/newlib/libc/machine/riscv/rv_string.h
> +++ b/newlib/libc/machine/riscv/rv_string.h
> @@ -112,6 +112,8 @@ static __inline char *__libc_strcpy(char *dst, const
> char *src, bool ret_start)
>      }
>  #endif /* not PREFER_SIZE_OVER_SPEED */
>
> +#if !(!defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) &&
> +      !(__riscv_misaligned_slow || __riscv_misaligned_fast))
>    char ch;
>    do
>      {
> @@ -122,6 +124,7 @@ static __inline char *__libc_strcpy(char *dst, const
> char *src, bool ret_start)
>      } while (ch);
>
>    return ret_start ? dst0 : dst - 1;
> +#endif
>  }
>
>
> --
> 2.43.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20250826/e9e38b9d/attachment.htm>


More information about the Newlib mailing list