From a1e4b4b521d9807abc5b34e5039535e15145f8ef Mon Sep 17 00:00:00 2001 From: Anton Kirilov Date: Thu, 28 Apr 2022 15:27:32 +0100 Subject: [PATCH] Enable AArch64 processor feature detection unconditionally (#4034) std::arch::is_aarch64_feature_detected!() is now part of stable Rust, so we can always use it. Copyright (c) 2022, Arm Limited. --- .github/workflows/main.yml | 4 +-- cranelift/native/src/lib.rs | 5 ++-- crates/fuzzing/src/generators.rs | 7 ++++- crates/wasmtime/src/engine.rs | 45 +++++++++++++++++++++++--------- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2e02c5f679..0d843bb808 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -62,7 +62,7 @@ jobs: submodules: true - uses: ./.github/actions/install-rust with: - toolchain: nightly-2021-12-15 + toolchain: nightly-2022-04-27 # Build C API documentation - run: sudo apt-get update -y && sudo apt-get install -y libclang1-9 libclang-cpp9 @@ -178,7 +178,7 @@ jobs: # flags to rustc. - uses: ./.github/actions/install-rust with: - toolchain: nightly-2021-12-15 + toolchain: nightly-2022-04-27 - run: cargo install cargo-fuzz --vers "^0.11" # Install OCaml packages necessary for 'differential_spec' fuzz target. - run: sudo apt install -y ocaml-nox ocamlbuild ocaml-findlib libzarith-ocaml-dev diff --git a/cranelift/native/src/lib.rs b/cranelift/native/src/lib.rs index 30c7a346e5..62df2c6c91 100644 --- a/cranelift/native/src/lib.rs +++ b/cranelift/native/src/lib.rs @@ -105,8 +105,7 @@ pub fn builder_with_options(infer_native_flags: bool) -> Result Result Arbitrary<'a> for CodegenSettings { // print a warning and return an error because this fuzz // input must be discarded. #[cfg(target_arch = $arch)] - if enable && !std::$test!($std) { + if enable && !std::arch::$test!($std) { log::warn!("want to enable clif `{}` but host doesn't support it", $clif); return Err(arbitrary::Error::EmptyChoose) @@ -752,6 +752,11 @@ impl<'a> Arbitrary<'a> for CodegenSettings { std:"avx512vl" => clif:"has_avx512vl" ratio: 1 in 1000, std:"avx512vbmi" => clif:"has_avx512vbmi" ratio: 1 in 1000, }, + "aarch64" => { + test: is_aarch64_feature_detected, + + std: "lse" => clif: "has_lse", + }, }; return Ok(CodegenSettings::Target { target: target_lexicon::Triple::host().to_string(), diff --git a/crates/wasmtime/src/engine.rs b/crates/wasmtime/src/engine.rs index abb7881837..e7e438161a 100644 --- a/crates/wasmtime/src/engine.rs +++ b/crates/wasmtime/src/engine.rs @@ -388,9 +388,23 @@ impl Engine { )) } } + + let enabled; + + #[cfg(target_arch = "aarch64")] + { + enabled = match flag { + "has_lse" => Some(std::arch::is_aarch64_feature_detected!("lse")), + // fall through to the very bottom to indicate that support is + // not enabled to test whether this feature is enabled on the + // host. + _ => None, + }; + } + #[cfg(target_arch = "x86_64")] { - let enabled = match flag { + enabled = match flag { "has_sse3" => Some(std::is_x86_feature_detected!("sse3")), "has_ssse3" => Some(std::is_x86_feature_detected!("ssse3")), "has_sse41" => Some(std::is_x86_feature_detected!("sse4.1")), @@ -412,18 +426,25 @@ impl Engine { // host. _ => None, }; - match enabled { - Some(true) => return Ok(()), - Some(false) => { - return Err(format!( - "compilation setting {:?} is enabled but not available on the host", - flag - )) - } - // fall through - None => {} - } } + + #[cfg(not(any(target_arch = "aarch64", target_arch = "x86_64")))] + { + enabled = None; + } + + match enabled { + Some(true) => return Ok(()), + Some(false) => { + return Err(format!( + "compilation setting {:?} is enabled, but not available on the host", + flag + )) + } + // fall through + None => {} + } + Err(format!( "cannot test if target-specific flag {:?} is available at runtime", flag