[PW_SID:1090752] riscv: lib: optimize strchr() with Zbb extension#1876
[PW_SID:1090752] riscv: lib: optimize strchr() with Zbb extension#1876linux-riscv-bot wants to merge 2 commits into
Conversation
Add a Zbb-powered optimization to the existing strchr() implementation using the 'orc.b' instruction, following the same pattern established by strnlen(). The Zbb variant processes data in word-sized chunks using orc.b to detect both NUL terminators and target characters in parallel. On systems without Zbb support, the original byte-by-byte implementation is used as a fallback via the alternatives mechanism. Benchmark results (QEMU TCG, rv64): Length | zbb=off (MB/s) | zbb=on (MB/s) | Improvement -------|----------------|---------------|------------ 1 B | 27 | 25 | -7.4% 7 B | 147 | 128 | -12.9% 16 B | 216 | 372 | +72.2% 64 B | 378 | 958 | +153.4% 512 B | 480 | 1990 | +314.6% 4096 B | 501 | 2269 | +352.9% The regression on very short strings (1-7 bytes) is due to the fixed overhead of the word-level path: broadcasting the target character to all byte lanes via multiplication and checking pointer alignment before entering the main loop. For strings shorter than one machine word, this setup cost outweighs the benefit of parallel comparison. As string length increases beyond 16 bytes, the word-at-a-time processing shows significant gains. Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "riscv: lib: optimize strchr() with Zbb extension" |
2c3b264 to
2d4fcdd
Compare
PR for series 1090752 applied to workflow__riscv__fixes
Name: riscv: lib: optimize strchr() with Zbb extension
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1090752
Version: 1