Skip to content

Commit

Permalink
Fix simd default on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkforest committed Jun 17, 2023
1 parent 0bc5de2 commit b11fa4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ fn main() {
Ok("simd") => {
// simd override is not guaranteed as:
// simd can only be enabled on x86_64 & 64bit target_pointer_width
if target_arch == "x86_64" && curve25519_dalek_bits == DalekBits::Dalek64 {
if is_capable_simd(&target_arch, curve25519_dalek_bits) {
"simd"
// fallback to serial with a warning
} else {
println!("cargo:warning=Could not override curve25519_dalek_backend to simd - defaulting to serial");
"serial"
}
}
// default serial
_ => "serial",
// default between serial / simd (if potentially capable)
_ => match is_capable_simd(&target_arch, curve25519_dalek_bits) {
true => "simd",
false => "serial",
},
};
println!("cargo:rustc-cfg=curve25519_dalek_backend=\"{curve25519_dalek_backend}\"");
}

// Is the target arch & curve25519_dalek_bits potentially simd capable ?
fn is_capable_simd(arch: &str, bits: DalekBits) -> bool {
arch == "x86_64" && bits == DalekBits::Dalek64
}

// Deterministic cfg(curve25519_dalek_bits) when this is not explicitly set.
mod deterministic {

Expand Down
2 changes: 1 addition & 1 deletion tests/build_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function match_and_report() {
cargo clean
OUT=build_1.txt
env RUSTFLAGS="--cfg curve25519_dalek_diagnostics=\"build\"" cargo build > "$OUT" 2>&1
match_and_report "curve25519_dalek_backend is 'serial'" "$OUT"
match_and_report "curve25519_dalek_backend is 'simd'" "$OUT"
match_and_report "curve25519_dalek_bits is '64'" "$OUT"

# Override to 32 bits assuming naively 64 bit build host
Expand Down

0 comments on commit b11fa4d

Please sign in to comment.