diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index f3002de..962ba02 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -33,7 +33,7 @@ jobs: run: rustup default nightly - name: Benchmark - run: cargo bench --bench throughput --features bench-plot + run: cargo bench --bench throughput --features bench-plot hybrid - uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 79713e8..f6ad127 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -40,10 +40,10 @@ jobs: run: cargo rustc -- --version - name: Build - run: cargo build --release + run: cargo build --release --features hybrid - name: Test - run: cargo test --release --lib + run: cargo test --release --lib --features hybrid build_test_arm: name: Build & Test ARM diff --git a/Cargo.toml b/Cargo.toml index a3d5df9..dc85d73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ exclude = ["article/*"] bench-csv = [] bench-md = [] bench-plot = [] +hybrid = [] [dependencies] rand = "0.8" diff --git a/build.rs b/build.rs index 63571f7..38f2910 100644 --- a/build.rs +++ b/build.rs @@ -2,18 +2,5 @@ extern crate rustc_version; use rustc_version::{version_meta, Channel}; fn main() { - // When conditions permits, enable hybrid feature to leverage wider intrinsics for even more throughput - if version_meta().unwrap().channel == Channel::Nightly - && cfg!(target_arch = "x86_64") - && cfg!(target_feature = "avx2") - && cfg!(target_feature = "vaes") { - println!("cargo:rustc-cfg=hybrid"); - } - // If not cross compiling, make sure the aes feature is available - if std::env::var("HOST").unwrap_or_default() == std::env::var("TARGET").unwrap_or_default() - && cfg!(not(target_feature = "aes")) { - panic!("| GxHash requires target-feature 'aes' to be enabled.\n\ - | Build with RUSTFLAGS=\"-C target-cpu=native\" or RUSTFLAGS=\"-C target-feature=+aes\" to enable."); - } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 863d67e..c522bbb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,12 @@ // Hybrid SIMD width usage currently requires unstable 'stdsimd' #![cfg_attr(hybrid, feature(stdarch_x86_avx512))] +#[cfg(all(feature = "hybrid", not(any(target_arch = "x86_64", target_feature = "avx2", target_feature = "vaes"))))] +compile_error!{"Hybrid feature is only available on x86 processors with avx2 and vaes intrinsics."} + +#[cfg(not(target_feature = "aes"))] +compile_error!{"Gxhash requires aes intrinsics. Make sure the processor supports it and build with RUSTFLAGS=\"-C target-cpu=native\" or RUSTFLAGS=\"-C target-feature=+aes\"."} + #[rustfmt::skip] mod gxhash; mod hasher;