Repository navigation
Fix AVX-512 reduce_max/reduce_min missing bytes 32-39 for 8-bit types - #1431
Merged
Merged
Conversation
The avx512f kernels folded the upper 256 bits into the lower half with
_mm512_permutexvar_epi64 using indices {5, 6, 7, 8, ...}. The intrinsic
only uses the low 3 bits of each index, so 8 wraps to 0 and qword 4
(bytes 32-39) was never compared. An extremum located there was missed.
Take the max/min of the two 256-bit halves directly (lower_half /
upper_half) and continue with the AVX2 reduction. This also drops the
512-bit max whose upper half was discarded, and it extends the kernel to
16-bit types, which previously used the generic swizzle reduction (up to
4x slower with GCC).
Add a test that places the extremum at each position of every batch type.
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
DiamonDinoia
approved these changes
Oct 23, 2026
DiamonDinoia
left a comment
Contributor
There was a problem hiding this comment.
I like this, the code is also simpler.
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.
The avx512f kernels folded the upper 256 bits into the lower half with _mm512_permutexvar_epi64 using indices {5, 6, 7, 8, ...}. The intrinsic only uses the low 3 bits of each index, so 8 wraps to 0 and qword 4 (bytes 32-39) was never compared. An extremum located there was missed.
Take the max/min of the two 256-bit halves directly (lower_half / upper_half) and continue with the AVX2 reduction. This also drops the 512-bit max whose upper half was discarded, and it extends the kernel to 16-bit types, which previously used the generic swizzle reduction (up to 4x slower with GCC).
Add a test that places the extremum at each position of every batch type.
Assisted-By: Claude Opus 5.5 noreply@anthropic.com
I found this issue via AI-review of my PR that uses xsimd. Instead of fixing the batch_constant indices I decided to use lower_half/upper_half functions since I thought it made the code more readable and understandable and not bug prone.