[PATCH] riscv: Use LMUL=8 for RVV strchr

Ning Tian <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
The RVV strchr implementation currently uses LMUL=1.  On VLEN=128
hardware this processes 16 bytes per iteration, so the fixed cost of
the fault-only-first load, two byte comparisons, two vfirst.m
operations, and scalar branch logic is paid every 16 bytes.

Use LMUL=8 so each iteration processes 128 bytes on VLEN=128 systems.
The character-match mask is moved from v9 to v16 because v0-v7 is now
used by the m8 data vector group.  The end-of-string mask remains in
v8.

On Sophgo SG2044 (VLEN=128, GCC 12.3.1), bench-strchr over 445 cases
shows a 4.63x geometric-mean speedup compared with the LMUL=1 RVV
version.  Full-scan cases improve by 5.52x to 8.96x for lengths from
64 to 8192 bytes.  Short strings that complete in the first vector
chunk regress by about 50% because LMUL=8 has higher vector setup cost;
a later scalar fast path can address that case.

Tested on riscv64-linux-gnu (Sophgo SG2044):
  make subdirs=string check
  make -C benchtests objdir=`pwd` bench-build BENCHSET=string-benchset
  bench-strchr: 445 cases

Signed-off-by: Ning Tian <[email protected]>
---
 sysdeps/riscv/rvv/strchr.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/riscv/rvv/strchr.S b/sysdeps/riscv/rvv/strchr.S
index 2fa95c31ba..f14f93a315 100644
--- a/sysdeps/riscv/rvv/strchr.S
+++ b/sysdeps/riscv/rvv/strchr.S
@@ -32,10 +32,10 @@
 #define cur_vl a6
 #define ivl t0
 
-#define ELEM_LMUL_SETTING m1
+#define ELEM_LMUL_SETTING m8
 #define vstr v0
 #define vmask_end v8
-#define vmask_ch v9
+#define vmask_ch v16
 
 ENTRY (STRCHR)
 .option push
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.