diff --git a/src/hashing/blake2/mod.rs b/src/hashing/blake2/mod.rs index 0e3f350..7da4ae1 100644 --- a/src/hashing/blake2/mod.rs +++ b/src/hashing/blake2/mod.rs @@ -9,10 +9,16 @@ mod reference; pub use common::LastBlock; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[cfg(all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "avx" +))] mod avx; -#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] +#[cfg(all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "avx2" +))] mod avx2; use common::{b, s}; @@ -59,8 +65,11 @@ impl EngineS { #[cfg(not(target_feature = "avx"))] const HAS_AVX: bool = false; - if HAS_AVX { - return avx::compress_s(&mut self.h, &mut self.t, buf, last); + #[cfg(target_feature = "avx")] + { + if HAS_AVX { + return avx::compress_s(&mut self.h, &mut self.t, buf, last); + } } } reference::compress_s(&mut self.h, &mut self.t, buf, last) @@ -115,11 +124,18 @@ impl EngineB { #[cfg(not(target_feature = "avx2"))] const HAS_AVX2: bool = false; - if HAS_AVX2 { - return avx2::compress_b(&mut self.h, &mut self.t, buf, last); + #[cfg(target_feature = "avx2")] + { + if HAS_AVX2 { + return avx2::compress_b(&mut self.h, &mut self.t, buf, last); + } } - if HAS_AVX { - return avx::compress_b(&mut self.h, &mut self.t, buf, last); + + #[cfg(target_feature = "avx")] + { + if HAS_AVX { + return avx::compress_b(&mut self.h, &mut self.t, buf, last); + } } } reference::compress_b(&mut self.h, &mut self.t, buf, last) diff --git a/src/hashing/sha2/impl256/mod.rs b/src/hashing/sha2/impl256/mod.rs index 30365ab..a8ef0cb 100644 --- a/src/hashing/sha2/impl256/mod.rs +++ b/src/hashing/sha2/impl256/mod.rs @@ -10,9 +10,17 @@ #[cfg(all(target_arch = "aarch64", feature = "use-stdsimd"))] mod aarch64; -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + +#[cfg(all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "avx" +))] mod avx; -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] + +#[cfg(all( + any(target_arch = "x86", target_arch = "x86_64"), + target_feature = "sse4.1" +))] mod sse41; //TODO not finished yet //#[cfg(all(target_arch = "x86_64", target_feature = "sha"))] @@ -35,11 +43,18 @@ pub(crate) fn digest_block(state: &mut [u32; 8], block: &[u8]) { #[cfg(not(target_feature = "sse4.1"))] const HAS_SSE41: bool = false; - if HAS_AVX { - return avx::digest_block(state, block); + #[cfg(target_feature = "avx")] + { + if HAS_AVX { + return avx::digest_block(state, block); + } } - if HAS_SSE41 { - return sse41::digest_block(state, block); + + #[cfg(target_feature = "sse4.1")] + { + if HAS_SSE41 { + return sse41::digest_block(state, block); + } } } #[cfg(target_arch = "aarch64")]