Skip to content

riscv: optimize FindMatchLengthWithLimit and memmove16 with RVV#1489

Closed
Felix-Gong wants to merge 1 commit into
google:masterfrom
Felix-Gong:riscv-rvv-optimize
Closed

riscv: optimize FindMatchLengthWithLimit and memmove16 with RVV#1489
Felix-Gong wants to merge 1 commit into
google:masterfrom
Felix-Gong:riscv-rvv-optimize

Conversation

@Felix-Gong

Copy link
Copy Markdown

Summary

Add RISC-V Vector Extension (RVV) 1.0 optimizations for two hot paths in brotli.

1. FindMatchLengthWithLimit (compression path, c/enc/find_match_length.h)

Uses RVV vector comparison to process up to 16 bytes per iteration:

  • vle8.v loads 16 bytes from both strings
  • vmsne.vv compares vectors, producing mismatch mask
  • vfirst.m finds index of first mismatch

Falls back to original scalar code for remaining bytes via vsetvl dynamic length.

2. memmove16 (decompression path, c/dec/decode.c)

Uses RVV vector load/store for 16-byte copy, symmetric with existing NEON optimization.

3. Platform detection (c/common/platform.h)

Auto-detects RVV 1.0+ from compiler predefined macros. No manual configuration needed.

Performance

Tested on RISC-V 64-bit server with GCC 15.1.0, -O2 -march=rv64gcv.

Q11 compression (best of 3 runs, brotli official testdata):

  • lcet10.txt: +25.1%
  • alice29.txt: +25.0%
  • bb.binast: +14.4%

Notes

Supersedes #1410. Zero impact on non-RISC-V targets.

Add RISC-V Vector Extension (RVV) 1.0 optimizations for two hot paths:

1. FindMatchLengthWithLimit (compression path):
   - Uses RVV vector comparison to process up to 16 bytes per iteration
   - vle8.v loads, vmsne.vv compares, vfirst.m finds first mismatch
   - Up to 25% compression speedup at Q11 on text data

2. memmove16 (decompression path):
   - Uses RVV vector load/store for 16-byte copy
   - Symmetric with existing NEON optimization
   - ~5% decompression speedup on large files

Both optimizations are gated behind BROTLI_RVV_1 macro, auto-detected
from __riscv_v >= 1.0.0. Falls back to scalar code on non-RVV targets.

Tested: 28 roundtrip tests + 22 compatibility tests all pass.
@Felix-Gong Felix-Gong closed this by deleting the head repository Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant