Optimize ZSTD_count with RISC-V Vector (RVV) intrinsics#4629
Open
Polaris-911 wants to merge 1 commit intofacebook:devfrom
Open
Optimize ZSTD_count with RISC-V Vector (RVV) intrinsics#4629Polaris-911 wants to merge 1 commit intofacebook:devfrom
Polaris-911 wants to merge 1 commit intofacebook:devfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces RISC-V Vector (RVV) intrinsics to optimize the
ZSTD_countfunction inzstd_compress_internal.h.ZSTD_countis a highly frequently called function during the match-finding phase. The original scalar implementation processes data in machine-word chunks (sizeof(size_t)) and requires a fallback mechanism to handle the remaining tail bytes safely.By leveraging the RISC-V Vector extension (
__riscv_vsetvl_e8m1), we can dramatically simplify the loop. Thevsetvlinstruction automatically manages the application vector length (AVL), seamlessly absorbing the tail without the need for additional branching or scalar tail-handling code, while safely avoiding out-of-bounds reads.To maximize performance, the initial scalar fast-path (
MEM_readST) is preserved to quickly catch early mismatches (which covers the vast majority of cases), switching to the RVV loop only for longer matches.Performance Evaluation
Test Environment:
silesia.tar(211,957,760 bytes)numactl -l -C 12 ./zstd -b1 -e1 ../silesia.tarBenchmark Results
Before PR (Scalar):

After PR (RVV Optimized):
