Repository navigation
simd: coordinate folds back on the read-in-place loop (removes the random-data regression merged in #426) - #427
Merged
Merged
Conversation
…esolved by blend + reduce Replaces the lane-candidate kernel of the previous commit. Disassembly showed its regression on random data came from copying each 16-lane group by value (the group went through the stack and the candidate was compared from memory), not from the select. This kernel keeps the merged loop, which compares against the group where it lies, and only changes how an improving group is resolved: non-improving lanes are overwritten with the worst value (I32x16::mask_blend), one horizontal reduction gives the best value, one compare gives its lowest lane. AVX-512, release, 65,536 rows, ns per element, old -> new: random dense argmin 0.163 -> 0.113, fused 0.190 -> 0.184; descending dense argmin 1.664 -> 0.550, fused 1.685 -> 0.551; random 1-in-64 argmin 0.041 -> 0.049. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
AdaWorldAPI
marked this pull request as ready for review
November 14, 2026 21:29
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Why this PR exists
#426 was merged at commit
b28eb33, which carries the lane-candidate kernel formasked_argmin_i32/masked_argmax_i32/masked_argminmax_i32. That kernel is about 20% slower than the one before it on random data (fused min+max about 50% slower). The fix was pushed to the branch after the merge and never reachedmaster. This PR is that fix. The description of #426 was edited after the merge and describes this kernel, not the one that was merged.I32x16::mask_blenditself (all seven backends) is already onmasterand is unchanged here.What changes
src/simd_masking_ops.rsonly. The loop from before #426 is restored: one scalar candidate per side, one packed compare per 16-lane group against the group where it lies in the caller's slice. An improving group is no longer read lane by lane: the lanes that are not better are overwritten with the worst value (I32x16::mask_blend), onereduce_min/reduce_maxgives the group's best value, and one compare gives its lowest lane. The lane candidates, thei32group-ordinal lane and the 2^30-row segmenting are removed. Results and the lowest-position tie rule are unchanged.What the disassembly showed
llvm-objdumpon non-inlined probes of the three kernels:mastercopies each 16-lane group by value before the compare. The group goes through the stack (vmovdqa64 [rsp+..]), the candidate is compared from memory, and the bookkeeping for four groups per mask word is vectorized into stack stores and reloads.vpcmpgtd k0, zmm1, zmmword ptr [rax].So the regression came from the loop shape, not from the select.
Measured
Unit: microseconds (µs) for one fold over 65,536 rows. The second table gives the same measurements in nanoseconds (ns) per row.
Intel Xeon 2.10 GHz, AVX-512, release,
target-cpu=native, binaries interleaved, minimum over rounds, 0 allocations. "before #426" and "this PR" were measured in the same interleaved session; "master" in an earlier interleaved session against the same "before #426" binary.µs per fold of 65,536 rows:
ns per row (the same runs):
master(36 µs against 18 to 25 µs per 65,536 rows), still about 3 times faster than before simd: I32x16::mask_blend on every backend; coordinate folds resolve an improving group by blend + reduce #426 (109 to 118 µs).master's monotone speed without its random-data cost.Tests
tests/masked_argminmax_i32.rs(17) andtests/i32x16_mask_blend.rs(10): green, unchanged.cargo clippy --lib --tests -- -D warnings,cargo fmt --checkand the facet-stride guard are clean.Scope note
These are
i32value lanes. They are kept as a fallback for lanes that exist only asi32; no further tuning of this path is planned.🤖 Generated with Claude Code
https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU