[PW_SID:1093340] [v2] riscv: lib: optimize strchr() with Zbb extension#1914
[PW_SID:1093340] [v2] riscv: lib: optimize strchr() with Zbb extension#1914linux-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 | 24 | -11.1% 7 B | 148 | 125 | -15.5% 16 B | 218 | 363 | +66.5% 64 B | 384 | 1044 | +171.9% 512 B | 424 | 2081 | +390.8% 4096 B | 498 | 2636 | +429.3% 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. Suggested-by: David Laight <david.laight.linux@gmail.com> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
|
Patch 1: "[v2] riscv: lib: optimize strchr() with Zbb extension" |
2d4fcdd to
cd9d421
Compare
PR for series 1093340 applied to workflow__riscv__fixes
Name: [v2] riscv: lib: optimize strchr() with Zbb extension
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1093340
Version: 2