Skip to content
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

Only enable SIMD on targets which feature SSE #77

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 15 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
}
15 changes: 15 additions & 0 deletions src/tests/x86_64-soft_float.json
Original file line number Diff line number Diff line change
@@ -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"
}