From 39a6e70da55d5c7f72aeb52359f8d24eab236db5 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 18 Mar 2019 20:11:18 +0100 Subject: [PATCH] _mm_pause does not require SSE2 Closes #705 . --- crates/core_arch/src/x86/sse2.rs | 14 +++++++++----- crates/stdsimd-verify/src/lib.rs | 10 +++++----- crates/stdsimd-verify/tests/x86-intel.rs | 6 ++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/core_arch/src/x86/sse2.rs b/crates/core_arch/src/x86/sse2.rs index 8a1448790a..fdd6aa9f9b 100644 --- a/crates/core_arch/src/x86/sse2.rs +++ b/crates/core_arch/src/x86/sse2.rs @@ -17,10 +17,14 @@ use crate::{ /// /// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_pause) #[inline] -#[target_feature(enable = "sse2")] -#[cfg_attr(test, assert_instr(pause))] +#[cfg_attr( + all(test, target_feature = "sse2"), + assert_instr(pause) +)] #[stable(feature = "simd_x86", since = "1.27.0")] pub unsafe fn _mm_pause() { + // note: `pause` is guaranteed to be interpreted as a `nop` by CPUs without + // the SSE2 target-feature - therefore it does not require any target features pause() } @@ -3191,9 +3195,9 @@ mod tests { use stdsimd_test::simd_test; use test::black_box; // Used to inhibit constant-folding. - #[simd_test(enable = "sse2")] - unsafe fn test_mm_pause() { - _mm_pause(); + #[test] + fn test_mm_pause() { + unsafe { _mm_pause() } } #[simd_test(enable = "sse2")] diff --git a/crates/stdsimd-verify/src/lib.rs b/crates/stdsimd-verify/src/lib.rs index 45cb5f5dbc..919c9f88a4 100644 --- a/crates/stdsimd-verify/src/lib.rs +++ b/crates/stdsimd-verify/src/lib.rs @@ -23,7 +23,7 @@ pub fn arm_functions(input: TokenStream) -> TokenStream { fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream { let dir = Path::new(env!("CARGO_MANIFEST_DIR")); - let root = dir.parent().unwrap(); + let root = dir.parent().expect("root-dir not found"); let mut files = Vec::new(); for dir in dirs { @@ -199,11 +199,11 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident { if path.segments.len() != 1 { panic!("unsupported path that needs name resolution") } - match path.segments.first().unwrap().value().arguments { + match path.segments.first().expect("segment not found").value().arguments { syn::PathArguments::None => {} _ => panic!("unsupported path that has path arguments"), } - path.segments.first().unwrap().value().ident.clone() + path.segments.first().expect("segment not found").value().ident.clone() } fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) { @@ -224,9 +224,9 @@ fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) { let mut contents = String::new(); File::open(&path) - .unwrap() + .expect(&format!("can't open file at path: {}", path.display())) .read_to_string(&mut contents) - .unwrap(); + .expect("failed to read file to string"); files.push(( syn::parse_str::(&contents).expect("failed to parse"), diff --git a/crates/stdsimd-verify/tests/x86-intel.rs b/crates/stdsimd-verify/tests/x86-intel.rs index 29995454ea..cd798bd2d3 100644 --- a/crates/stdsimd-verify/tests/x86-intel.rs +++ b/crates/stdsimd-verify/tests/x86-intel.rs @@ -254,6 +254,12 @@ fn matches(rust: &Function, intel: &Intrinsic) -> Result<(), String> { } for cpuid in &intel.cpuid { + // The pause intrinsic is in the SSE2 module, but it is backwards + // compatible with CPUs without SSE2, and it therefore does not need the + // target-feature attribute. + if rust.name == "_mm_pause" { + continue; + } // this is needed by _xsave and probably some related intrinsics, // but let's just skip it for now. if *cpuid == "XSS" {