feat(simd): add runtime CPU feature detection for x86_64 using multiversion#221
Open
utkarshgupta137 wants to merge 2 commits into
Open
feat(simd): add runtime CPU feature detection for x86_64 using multiversion#221utkarshgupta137 wants to merge 2 commits into
utkarshgupta137 wants to merge 2 commits into
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.
What type of PR is this?
feat: A new feature
Check the PR title.
(Optional) More detailed description for this PR(en: English/zh: Chinese).
Previously, all SIMD feature selection was done at compile time via
#[cfg(target_feature = "...")]. This meant binaries compiled without-C target-cpu=native(e.g., for distribution) fell back to scalar code on x86_64, leaving significant performance on the table even on machines with AVX2/PCLMULQDQ support.This PR adds runtime CPU feature detection for x86_64 using the
multiversioncrate. The changes are:Runtime dispatch for
get_nonspace_bitsandprefix_xor(src/util/arch/):-C target-cpu=nativeor explicit feature flags: zero overhead — the runtime detection module is not compiled at all, and the optimized implementations are used directly (identical to before).multiversiondetects AVX2/PCLMULQDQ support at runtime (once, cached in a static atomic) and dispatches to either the optimized x86_64 implementations or the scalar fallback.Fix
sonic-numberSSE2 gating (sonic-number/src/arch/mod.rs):simd_str2int) only uses SSE2 intrinsics but was incorrectly gated behindtarget_feature = "avx2". Relaxed totarget_feature = "sse2", which is baseline on all x86_64 CPUs. This means SIMD-accelerated number parsing is now always available on x86_64 regardless of compiler flags.Performance impact (binaries compiled without
-C target-cpu=native, running on AVX2 CPU):get_nonspace_bitsprefix_xorsimd_str2intThe
sonic-simdabstract types (u8x32,u8x64,StringBlock, etc.) continue to use compile-time selection. When AVX2 is not a compile-time feature,u8x32is emulated as 2×SSE2u8x16— still much faster than scalar. I intend to raise a followup PR for that.(Optional) Which issue(s) this PR fixes:
Addresses the "runtime CPU detection" item from
ROADMAP.md.(optional) The PR that updates user documentation:
N/A — no user-facing API changes. The runtime detection is transparent and automatic.