]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
riscv: lib: add strrchr() implementation
authorFeng Jiang <jiangfeng@kylinos.cn>
Sat, 4 Apr 2026 01:28:47 +0000 (19:28 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 5 Apr 2026 00:42:44 +0000 (18:42 -0600)
commitbef64bcb940269a503d12eb1bc180d1aa9adf74d
tree3e71a4e6ab11d7eb513cc0ca8e91bb0c278f4c7f
parentadf542133960d402f63c976b00e46be4d986d4c3
riscv: lib: add strrchr() implementation

Add an assembly implementation of strrchr() for RISC-V.

This implementation minimizes instruction count and avoids unnecessary
memory access to the stack. The performance benefits are most visible
on small workloads (1-16 bytes) where the architectural savings in
function overhead outweigh the execution time of the scan loop.

Benchmark results (QEMU TCG, rv64):
  Length | Original (MB/s) | Optimized (MB/s) | Improvement
  -------|-----------------|------------------|------------
  1 B    | 20              | 21               | +5.0%
  7 B    | 111             | 120              | +8.1%
  16 B   | 189             | 199              | +5.3%
  512 B  | 361             | 382              | +5.8%
  4096 B | 388             | 391              | +0.8%

Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn>
Tested-by: Joel Stanley <joel@jms.id.au>
Link: https://patch.msgid.link/20260130025018.172925-9-jiangfeng@kylinos.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/include/asm/string.h
arch/riscv/lib/Makefile
arch/riscv/lib/strrchr.S [new file with mode: 0644]
arch/riscv/purgatory/Makefile