From 9d3752e6564c9b2c8b292641d31b3a51bb6715ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 28 Oct 2020 09:11:39 +0100 Subject: [PATCH 1/2] CI: Build for non-SSE target --- .github/workflows/ci.yml | 17 +++++++++++++++++ src/tests/x86_64-soft_float.json | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/tests/x86_64-soft_float.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef9388e..ce38a62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,6 +129,23 @@ jobs: name: Run benchmarks as tests run: cargo bench --manifest-path bench/Cargo.toml --verbose -- --test + build-for-non_sse-target: + name: build for non-SSE target + runs-on: ubuntu-18.04 + steps: + - name: Checkout repository + uses: actions/checkout@v1 + with: + fetch-depth: 1 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + override: true + components: rust-src + - run: cargo build -Z build-std=core --target=src/tests/x86_64-soft_float.json --verbose --no-default-features + test-with-miri: name: test with miri runs-on: ubuntu-18.04 diff --git a/src/tests/x86_64-soft_float.json b/src/tests/x86_64-soft_float.json new file mode 100644 index 0000000..b77649e --- /dev/null +++ b/src/tests/x86_64-soft_float.json @@ -0,0 +1,15 @@ +{ + "llvm-target": "x86_64-unknown-none", + "target-endian": "little", + "target-pointer-width": "64", + "target-c-int-width": "32", + "os": "none", + "arch": "x86_64", + "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float", + "executables": true, + "disable-redzone": true, + "panic-strategy": "abort" +} From cf049c42a811064c8ccdd25c70d5de2d276f6a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Tue, 27 Oct 2020 16:18:31 +0100 Subject: [PATCH 2/2] Only enable simd on targets which feature SSE --- build.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 4ae3184..e07ad6f 100644 --- a/build.rs +++ b/build.rs @@ -5,12 +5,19 @@ fn main() { enable_libc(); } -// This adds various simd cfgs if this compiler supports it. +// This adds various simd cfgs if this compiler and target support it. // // This can be disabled with RUSTFLAGS="--cfg memchr_disable_auto_simd", but // this is generally only intended for testing. +// +// On targets which don't feature SSE2, this is disabled, as LLVM wouln't know +// how to work with SSE2 operands. Enabling SSE4.2 and AVX on SSE2-only targets +// is not a problem. In that case, the fastest option will be chosen at +// runtime. fn enable_simd_optimizations() { - if is_env_set("CARGO_CFG_MEMCHR_DISABLE_AUTO_SIMD") { + if is_env_set("CARGO_CFG_MEMCHR_DISABLE_AUTO_SIMD") + || !target_has_feature("sse2") + { return; } println!("cargo:rustc-cfg=memchr_runtime_simd"); @@ -59,3 +66,9 @@ fn is_feature_set(name: &str) -> bool { fn is_env_set(name: &str) -> bool { env::var_os(name).is_some() } + +fn target_has_feature(feature: &str) -> bool { + env::var("CARGO_CFG_TARGET_FEATURE") + .map(|features| features.contains(feature)) + .unwrap_or(false) +}