From 9cd3f212375108b34a07f66a0d8ec1dc8501c16e Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Tue, 16 Aug 2022 10:24:14 +0100 Subject: [PATCH 1/2] To use avx2, both avx and avx2 must be checked. --- sha2/src/sha512/x86.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sha2/src/sha512/x86.rs b/sha2/src/sha512/x86.rs index bb7904088..c1e59ba3f 100644 --- a/sha2/src/sha512/x86.rs +++ b/sha2/src/sha512/x86.rs @@ -11,12 +11,13 @@ use core::arch::x86_64::*; use crate::consts::K64; +cpufeatures::new!(avx_cpuid, "avx"); cpufeatures::new!(avx2_cpuid, "avx2"); pub fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) { // TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725 // after stabilization - if avx2_cpuid::get() { + if avx_cpuid::get() && avx2_cpuid::get() { unsafe { sha512_compress_x86_64_avx2(state, blocks); } From fcb9cf4e1121a1db30dc2c9d0e82d02cf8276156 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Tue, 16 Aug 2022 14:00:43 +0100 Subject: [PATCH 2/2] Combine avx and avx2 check. Add reference to PR. --- sha2/src/sha512/x86.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sha2/src/sha512/x86.rs b/sha2/src/sha512/x86.rs index c1e59ba3f..b80cfc1ae 100644 --- a/sha2/src/sha512/x86.rs +++ b/sha2/src/sha512/x86.rs @@ -11,13 +11,14 @@ use core::arch::x86_64::*; use crate::consts::K64; -cpufeatures::new!(avx_cpuid, "avx"); -cpufeatures::new!(avx2_cpuid, "avx2"); +// We need to check availability of both AVX and AVX2, see: +// https://github.com/RustCrypto/hashes/pull/386 +cpufeatures::new!(avx2_cpuid, "avx", "avx2"); pub fn compress(state: &mut [u64; 8], blocks: &[[u8; 128]]) { // TODO: Replace with https://github.com/rust-lang/rfcs/pull/2725 // after stabilization - if avx_cpuid::get() && avx2_cpuid::get() { + if avx2_cpuid::get() { unsafe { sha512_compress_x86_64_avx2(state, blocks); }