Re: [PATCH 2/3] newlib: riscv: Optimize memchr() and memrchr()

Kito Cheng <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <CA+yXCZDX=oCHkVeauksnT2uf6_SSE_pYeVE-jeEW-uj9c8=qGQ@mail.gmail.com>
> diff --git a/newlib/libc/machine/riscv/memchr.c b/newlib/libc/machine/riscv/memchr.c
> index 5c08c12813fe..4202c704e2f3 100644
> --- a/newlib/libc/machine/riscv/memchr.c
> +++ b/newlib/libc/machine/riscv/memchr.c
> @@ -29,10 +29,15 @@ QUICKREF
>         memchr ansi pure
>  */
>
> -#include <_ansi.h>
> -#include <string.h>
> -#include <limits.h>
> -#include "../../string/local.h"
> +#include <sys/asm.h>
> +#include <stddef.h>
> +#include "rv_string.h"
> +
> +#if __riscv_zilsd
> +#undef  SZREG
> +#define SZREG           8

Could you define a MOVE_UNIT rather than SZREG here? It's kinda confusing.

>
> -      src = (unsigned char *) asrc;
> +  if (src < end_addr)
> +    {
> +      uintxlen_t mask = __libc_splat_byte(d);
> +      uintlslen_t val;
> +
> +      do
> +        {
> +#if __riscv_zilsd
> +          asm volatile ("ld %0, 0(%1)"
> +                        : "=R" (val)
> +                        : "r" (src)
> +          );

I strongly prefer not to use inline asm here, let the compiler do
that, although I know upstream GCC doesn't implement that yet...

> diff --git a/newlib/libc/machine/riscv/memrchr.c b/newlib/libc/machine/riscv/memrchr.c
> index 8d15ccb780ec..a67c2fefe124 100644
> --- a/newlib/libc/machine/riscv/memrchr.c
> +++ b/newlib/libc/machine/riscv/memrchr.c
> @@ -29,61 +29,141 @@ QUICKREF
>         memrchr
>  */
>
> -#include <_ansi.h>
> -#include <string.h>
> -#include <limits.h>
> -#include "../../string/local.h"
> +#include <sys/asm.h>
> +#include <stddef.h>
> +#include "rv_string.h"
> +
> +#if __riscv_zilsd
> +#undef  SZREG
> +#define SZREG           8

Same here
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.