Felix-Gong opened a new pull request, #3390:
URL: https://github.com/apache/brpc/pull/3390
## Summary
This patch adds RVV-accelerated `memcmp` and `memchr` implementations 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/match
## Performance
Test environment: SOPHGO SG2044 (RVV 1.0, VLEN >= 128, GCC 15.1)
Baseline: glibc 2.38 scalar memcmp/memchr (no RVV acceleration)
### memcmp (worst-case full scan, 50000 iterations)
| Size | glibc (ns) | RVV (ns) | Speedup |
|------|-----------|---------|---------|
| 64 B | 25 | 5 | **5.00x** |
| 256 B | 52 | 15 | **3.47x** |
| 1 KB | 120 | 55 | **2.18x** |
| 4 KB | 419 | 224 | **1.87x** |
| 16 KB | 1,640 | 864 | **1.90x** |
| 64 KB | 10,937 | 9,508 | **1.15x** |
| 256 KB | 54,005 | 45,537 | **1.19x** |
| 1 MB | 324,601 | 413,379 | 0.79x |
### memchr (worst-case full scan, 50000 iterations)
| Size | glibc (ns) | RVV (ns) | Speedup |
|------|-----------|---------|---------|
| 64 B | 28 | 3 | **9.33x** |
| 256 B | 60 | 9 | **6.67x** |
| 1 KB | 184 | 36 | **5.11x** |
| 4 KB | 637 | 154 | **4.14x** |
| 16 KB | 2,568 | 594 | **4.32x** |
| 64 KB | 10,664 | 3,614 | **2.95x** |
| 256 KB | 41,660 | 17,262 | **2.41x** |
| 1 MB | 163,354 | 55,354 | **2.95x** |
## Correctness
| Test | Result |
|------|--------|
| Expanded correctness (24,950 cases, 64B–1MB) | **24,950/24,950 PASSED** |
| `string_piece_unittest` | **22/22 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/memchr implementations
- `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`
## Build
```bash
cmake ..
-DCMAKE_CXX_COMPILER=/opt/gcc-15.1/bin/riscv64-unknown-linux-gnu-g++ \
-DCMAKE_CXX_FLAGS='-O2 -march=rv64gcv'
make -j$(nproc)
```
RISC-V optimization for butil StringPiece operations.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]