Skip to content

Commit 12bdc2e

Browse files
committed
_mm_pause does not require SSE2
Closes #705 .
1 parent 7711679 commit 12bdc2e

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

crates/core_arch/src/x86/sse2.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ use crate::{
1717
///
1818
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_pause)
1919
#[inline]
20-
#[target_feature(enable = "sse2")]
21-
#[cfg_attr(test, assert_instr(pause))]
20+
#[cfg_attr(
21+
all(test, target_feature = "sse2"),
22+
assert_instr(pause)
23+
)]
2224
#[stable(feature = "simd_x86", since = "1.27.0")]
2325
pub unsafe fn _mm_pause() {
26+
// note: `pause` is guaranteed to be interpreted as a `nop` by CPUs without
27+
// the SSE2 target-feature - therefore it does not require any target features
2428
pause()
2529
}
2630

@@ -3191,9 +3195,9 @@ mod tests {
31913195
use stdsimd_test::simd_test;
31923196
use test::black_box; // Used to inhibit constant-folding.
31933197

3194-
#[simd_test(enable = "sse2")]
3195-
unsafe fn test_mm_pause() {
3196-
_mm_pause();
3198+
#[test]
3199+
fn test_mm_pause() {
3200+
unsafe { _mm_pause() }
31973201
}
31983202

31993203
#[simd_test(enable = "sse2")]

crates/stdsimd-verify/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn arm_functions(input: TokenStream) -> TokenStream {
2323

2424
fn functions(input: TokenStream, dirs: &[&str]) -> TokenStream {
2525
let dir = Path::new(env!("CARGO_MANIFEST_DIR"));
26-
let root = dir.parent().unwrap();
26+
let root = dir.parent().expect("root-dir not found");
2727

2828
let mut files = Vec::new();
2929
for dir in dirs {
@@ -199,11 +199,11 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident {
199199
if path.segments.len() != 1 {
200200
panic!("unsupported path that needs name resolution")
201201
}
202-
match path.segments.first().unwrap().value().arguments {
202+
match path.segments.first().expect("segment not found").value().arguments {
203203
syn::PathArguments::None => {}
204204
_ => panic!("unsupported path that has path arguments"),
205205
}
206-
path.segments.first().unwrap().value().ident.clone()
206+
path.segments.first().expect("segment not found").value().ident.clone()
207207
}
208208

209209
fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) {
@@ -224,9 +224,9 @@ fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) {
224224

225225
let mut contents = String::new();
226226
File::open(&path)
227-
.unwrap()
227+
.expect(&format!("can't open file at path: {}", path.display()))
228228
.read_to_string(&mut contents)
229-
.unwrap();
229+
.expect("failed to read file to string");
230230

231231
files.push((
232232
syn::parse_str::<syn::File>(&contents).expect("failed to parse"),

crates/stdsimd-verify/tests/x86-intel.rs

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ fn matches(rust: &Function, intel: &Intrinsic) -> Result<(), String> {
254254
}
255255

256256
for cpuid in &intel.cpuid {
257+
// The pause intrinsic is in the SSE2 module, but it is backwards
258+
// compatible with CPUs without SSE2, and it therefore does not need the
259+
// target-feature attribute.
260+
if rust.name == "_mm_pause" {
261+
continue;
262+
}
257263
// this is needed by _xsave and probably some related intrinsics,
258264
// but let's just skip it for now.
259265
if *cpuid == "XSS" {

0 commit comments

Comments
 (0)