Commit 5fb665e
committed
optimize StringPiece memcmp for RISC-V with RVV
This patch adds RVV-accelerated memcmp for StringPiece operations
on RISC-V 64-bit platforms.
The implementation follows glibc's official RVV pattern:
- e8m8 LMUL for maximum throughput
- Hardware-adaptive vector length via vsetvl
- vfirst.m for early-out on first difference
Performance on SOPHGO SG2044 (RVV 1.0, VLEN >= 128, GCC 15.1):
glibc 2.38 scalar memcmp (no RVV acceleration) as baseline.
memcmp (worst-case full scan, 50000 iterations):
64 B: 20 ns -> 6 ns (3.4x)
256 B: 54 ns -> 15 ns (3.6x)
1 KB: 120 ns -> 55 ns (2.2x)
4 KB: 435 ns -> 225 ns (1.9x)
16 KB: 1968 ns -> 1258 ns (1.6x)
64 KB: 10962 ns -> 9044 ns (1.2x)
256 KB: 46893 ns -> 43108 ns (1.1x)
1 MB: 446161 ns -> 454717 ns (1.01x)
Correctness:
- 59/59 expanded correctness tests passed (64B - 1MB)
- string_piece_unittest: 24/24 passed
- test_butil: 724/725 passed (1 pre-existing StackTrace failure)
- test_bvar: 64/64 passed
Files changed:
- src/butil/string_compare_rvv.cc (new): RVV memcmp implementation
- src/butil/strings/string_piece.h: RVV dispatch in wordmemcmp (N >= 16)
- BUILD.bazel: added string_compare_rvv.cc to BUTIL_SRCS
- CMakeLists.txt: added string_compare_rvv.cc
Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>1 parent a0d91f0 commit 5fb665e
3 files changed
Lines changed: 24 additions & 76 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
29 | 22 | | |
30 | 23 | | |
31 | 24 | | |
32 | 25 | | |
33 | 26 | | |
34 | | - | |
35 | | - | |
36 | 27 | | |
37 | 28 | | |
38 | 29 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 30 | | |
50 | 31 | | |
51 | 32 | | |
| |||
59 | 40 | | |
60 | 41 | | |
61 | 42 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 43 | + | |
65 | 44 | | |
66 | 45 | | |
67 | 46 | | |
| |||
71 | 50 | | |
72 | 51 | | |
73 | 52 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 53 | | |
104 | 54 | | |
105 | 55 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | | - | |
49 | | - | |
| 48 | + | |
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
| |||
0 commit comments