← Back to Pull requests

feat: Dynamic shuffle methods #317

Closed
unknown closed this pull request without merging on Aug 17, 2026 05:40 UTC
View on GitHub
unknown unknown commented on Aug 14, 2026 13:10 UTC
Author

This PR adds functionality for runtime-index based shuffling, from one or more input vectors.

(Note: This PR copy pastes the swizzle2 helper 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 ShuffleExt trait 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/4 methods is that those would result in a large matrix of function names which looks more complicated than this simpler syntax.

    Reasoning behind naming

  • "shuffle" is better associated with SIMD, while "swizzle" is commonly associated with shader syntax vec3.zxy, so here shuffle is more descriptive than swizzle
  • swizzle is already taken by the old function which, depending on the type, uses signed integers for indices or even returns the wrong type (u8x16::shuffle returns i8x16)
  • I think shuffle and shuffle_const is a better choice than shuffle_dyn and shuffle. 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 like wrapping_shuffle_dyn
  • Future issue with shuffle_const

    After 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 to shuffle_const<const INDICES: [usize; N]>, but for now that's impossible).

    Because for each different lane-count the function has a different signature, shuffle_const cannot be added to ShuffleExt directly, 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 swizzle since zeroing_shuffle has its exact guarantees, and deprecates swizzle_relaxed replaced with shuffle. The old type-specific guarantees made for swizzle_relaxed are retained for shuffle for the appropriate types, so old users don't loose any guarantees.

    swizzle_half and swizzle_half_relaxed are 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

  • Is the array syntax with ShuffleExt used here really the best choice? Also consider the issue with shuffle_const

  • Are there better names for these methods?
  • Diff: 436 lines (+327 / -109) across 5 files Reviewer: Lokathor Review duration: 3870m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.9% · Safe to merge
    17.9%
    Repository