Add concat_swizzle_dyn and concat_swizzle_dyn_precise - #354
Open
Shnatsel wants to merge 3 commits into
Open
Conversation
Contributor
Author
|
@Novum please let me know if this looks good to you |
|
Looks good for me for those operations |
…wizzle_dyn_precise SSE4.2 formulation somewhat so that recursive decomposition optimizes better.
…vectorization on RISC-V (16-bit case now vectorizes) and better fallback performance (no more 3x degradation on unpredictable indices) without too much of a hit on predictable ones
Shnatsel
force-pushed
the
concat-swizzle-dyn-2
branch
from
August 30, 2026 10:05
8c3d911 to
f5de48d
Compare
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.
select_unpredictablestabilized in 1.88 in scalar fallbacks of concat_swizzle_dyn_precise and swizzle_dyn_precise.Rationale for the branchless formulation:
cmovis far from a silver bullet and is often a bad idea. In my benchmarks this is 20% to 40% slower than branches for swizzle_dyn_precise if the indices are all out of range, but avoids a 5x (400%) performance degradation on unpredictable indices. If you know your indices are predictable, you don't use_precisein the first place, so tuning for unpredictability seems fine. Most importantly, removing branches helps autovectorizer a lot, so we get more reliable autovectorization on e.g. RISC-V, which is the primary use case.Implementation-wise, NEON and AVX-512 are straightforward with native-ish instructions, SSE4.2 uses the same decomposition idea as swizzle_dyn_precise, and AVX2 needs babysitting as always.
The first commit is squashed because I did a bunch of experiments with different formulations, e.g. a specialized one for 256-bit AVX2 that reduces shuffle port pressure on haswell and doesn't regress recent AVX2 much if at all, but in the end decided those are not worth the extra complexity.
I'm not thrilled by the
lhs.concat_swizzle_dyn(rhs, indices)API but I don't see how to do better without it getting really awkward in other ways:concat_swizzle_dyn(simd, lhs, rhs, indices)isn't any better and breaks convention, andindices.concat_swizzle_dyn(lhs, rhs)runs into issues with matching vector lengths.