]> git.ipfire.org Git - thirdparty/linux.git/commit
riscv: lib: optimize strlen loop efficiency
authorFeng Jiang <jiangfeng@kylinos.cn>
Mon, 26 Jan 2026 04:09:58 +0000 (21:09 -0700)
committerPaul Walmsley <pjw@kernel.org>
Mon, 9 Feb 2026 22:27:33 +0000 (15:27 -0700)
commit18be4ca5cb4e5a86833de97d331f5bc14a6c5a6d
tree47e35ff53c678798ffb96b03d8e72405a350ccd7
parent098921ec6818291d98bd3a4002c9dfbe2e75aac2
riscv: lib: optimize strlen loop efficiency

Optimize the generic strlen implementation by using a pre-decrement
pointer. This reduces the loop body from 4 instructions to 3 and
eliminates the unconditional jump ('j').

Old loop (4 instructions, 2 branches):
  1: lbu t0, 0(t1); beqz t0, 2f; addi t1, t1, 1; j 1b

New loop (3 instructions, 1 branch):
  1: addi t1, t1, 1; lbu t0, 0(t1); bnez t0, 1b

This change improves execution efficiency and reduces branch pressure
for systems without the Zbb extension.

Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn>
Link: https://patch.msgid.link/20251218032614.57356-1-jiangfeng@kylinos.cn
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/lib/strlen.S