feat: Dynamic shuffle methods #317
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 436 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.364
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #317"
general
weight: 0.35
Lokathor
This PR adds functionality for runtime-index based shuffling, from one or more input vectors.
(Note: This PR copy pastes the
swizzle2helper functions from the unmerged PR #305)All functionality is added for all types, not just 8-bit types. My reasoning is that non-8-bit shuffles do have native support on x86, and for other targets, emulating it is quite efficient using a trick with shifts bitors and 8-bit shuffles.
Shuffles from a single input vector are added as the methods:
shuffle(assumes indices are in bounds)zeroing_shuffle(returns zero for out of bounds indices. this has native support on neon and wasm)wrapping_shuffle(uses the modulo of indices. this has native support on avx512)Shuffles from multiple input vectors (avx512 supports shuffling from 2 vectors, and neon supports from 2, 3 and 4) are added in the
ShuffleExttrait implemented for arrays of SIMD types, and uses the syntax[simd_a, simd_b].shuffle(indices), with the same three method names.My reasoning for not just adding
shuffle_2/3/4methods is that those would result in a large matrix of function names which looks more complicated than this simpler syntax.Reasoning behind naming
vec3.zxy, so hereshuffleis more descriptive thanswizzleswizzleis already taken by the old function which, depending on the type, uses signed integers for indices or even returns the wrong type (u8x16::shufflereturnsi8x16)shuffleandshuffle_constis a better choice thanshuffle_dynandshuffle. Since dynamic shuffling has multiple variants for out of bounds handling, and constant shuffling does not, its better to put the postfix on constant shuffling, in order to avoid long names likewrapping_shuffle_dynFuture issue with
shuffle_constAfter this PR, I intend to also add constant-index shuffling via
shuffle_const. This function will take a const-generic parameter for each lane index (In the future if the type system advances, this can be changed toshuffle_const<const INDICES: [usize; N]>, but for now that's impossible).Because for each different lane-count the function has a different signature,
shuffle_constcannot be added toShuffleExtdirectly, since that requires a uniform signature. To support multi-input constant-index shuffles, we would need to add a trait per supported lane count:Shuffle2Ext,Shuffle4Ext, (same for 8, 16, 32, 64?).This could be a reason to not go with the array extension trait design, and instead use inherit methods (e.g.,
f32x4::shuffle_n([simd_a, simd_b], indices)?). What should be done with this?Deprecated old methods
This PR deprecates
swizzlesincezeroing_shufflehas its exact guarantees, and deprecatesswizzle_relaxedreplaced withshuffle. The old type-specific guarantees made forswizzle_relaxedare retained forshufflefor the appropriate types, so old users don't loose any guarantees.swizzle_halfandswizzle_half_relaxedare not deprecated, since they are not covered by the new methods. I have a design for making those consistent with the new methods, but chose to separate that into another PR.Before merging
ShuffleExtused here really the best choice? Also consider the issue withshuffle_const