Support building on CPUs with AVX but not AVX2#3040
Merged
Conversation
This change corrects an issue causing AVX2 intrinsics to be called on CPUs that do not support them. These intrinsics were conditionally compiled in behind an `avx` feature gate. This change correctly uses them only if `avx2` is available. This change should have no impact on modern CPUs, but it allows older CPUs to work properly using the unoptimized code path.
Contributor
|
Thanks for the contribution! According to the Steam Hardware Survey, ~97% of users have AVX and ~95% have AVX2 support. Given this data, I agree that reworking the code to avoid AVX2 instructions isn't worth the effort just to provide optimizations for the ~2% of users on older hardware. For anyone looking at this in the future, at least one of the AVX2 instructions is found here: |
This was referenced Jul 31, 2025
john-sharratt
pushed a commit
to john-sharratt/candle
that referenced
this pull request
May 7, 2026
This change corrects an issue causing AVX2 intrinsics to be called on CPUs that do not support them. These intrinsics were conditionally compiled in behind an `avx` feature gate. This change correctly uses them only if `avx2` is available. This change should have no impact on modern CPUs, but it allows older CPUs to work properly using the unoptimized code path.
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.
This change corrects an issue causing AVX2 intrinsics to be called on CPUs that do not support them. These intrinsics were conditionally compiled in behind an
avxfeature gate. This change correctly uses them only ifavx2is available. This change should have no impact on modern CPUs, but it allows older CPUs to work properly using the unoptimized code path.An alternative to this change would be to rework the AVX code paths to avoid AVX2 intrinsics, but that would be a larger change and likely less desirable as AVX2 seems like a very reasonable baseline these days. Dropping AVX2 intrinsics would likely be a performance regression on modern CPUs.
This change corrects an issue that I was facing related to an
Illegal Instructionafter building the crate, and should also address similar issues that have been encountered by others such as #1327 and #2140.