-
Notifications
You must be signed in to change notification settings - Fork 286
To use avx2, both avx and avx2 must be checked. #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, we have been following the Rust reference which assumes that enabled AVX2 implies AVX.
Can you check what the following snippet prints on the CPU?
println!("avx: {}", is_x86_feature_detected!("avx"));
println!("avx2: {}", is_x86_feature_detected!("avx2"));
Either way, I think it's worth to merge this fix, although in a slightly different form.
But isn't this to manually enable target features? I read this as: If you enable The Intel note is quite clear on this: "Application Software must identify that hardware supports AVX ...., after that it must also detect support for AVX2 ....".
println!("avx: {}", is_x86_feature_detected!("avx"));
println!("avx2: {}", is_x86_feature_detected!("avx2")); Output:
The output of: cpufeatures::new!(avx_cpuid, "avx");
cpufeatures::new!(avx2_cpuid, "avx2");
fn main() {
println!("Supports avx: {}", avx_cpuid::get());
println!("Supports avx2: {}", avx2_cpuid::get());
}
The output of: cpufeatures::new!(avx2_cpuid, "avx", "avx2");
fn main() {
println!("Supports avx2: {}", avx2_cpuid::get());
}
|
I've updated the pull-request. After merging, would you be able to create a new release? |
Hm, the @tarcieri |
Sure, sounds good |
The above PR solved this issue. Thanks! 👍 |
In some scenarios, this check returned true while the avx2 extension was not available (e.g. QEMU emulated CPU). See for more details: RustCrypto/hashes#386.
Please see the Intel note about detecting the
avx2
extension:https://www.intel.com/content/dam/develop/external/us/en/documents/36945
It states that both the support for AVX and AVX2 must be detected.
Some context:
I had a bug report that trying to login caused the application (ChirpStack) to panic. After a deep dive, it turned out that the host (Qemu CPU) does not support these instructions, but
avx2_cpuid::get()
returns true.Then I noticed that the Intel docs state that both
AVX
andAVX2
must be checked. Running this application on this specific Qemu CPU returns:As reference, this is the content of
/proc/cpuinfo
: