[PATCH v12 14/31] string: Improve generic strrchr with memrchr and strlen
Richard Henderson
richard.henderson@linaro.org
Sat Feb 4 03:06:55 GMT 2023
On 2/2/23 08:11, Adhemerval Zanella wrote:
> Now that both strlen and memrchr have word vectorized implementation,
> it should be faster to implement strrchr based on memrchr over the
> string length instead of calling strchr on a loop.
>
> Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc-linux-gnu,
> and powerpc64-linux-gnu by removing the arch-specific assembly
> implementation and disabling multi-arch (it covers both LE and BE
> for 64 and 32 bits).
> ---
> string/strrchr.c | 18 +-----------------
> 1 file changed, 1 insertion(+), 17 deletions(-)
memrchr needs libc_hidden_builtin_proto. On riscv64:
c: 00000097 auipc ra,0x0
c: R_RISCV_CALL __GI_strlen
c: R_RISCV_RELAX *ABS*
10: 000080e7 jalr ra # c <__GI_strrchr+0xc>
...
24: 00000317 auipc t1,0x0
24: R_RISCV_CALL_PLT __memrchr
24: R_RISCV_RELAX *ABS*
28: 00030067 jr t1 # 24 <.LVL2+0x8>
r~
More information about the Libc-alpha
mailing list