Auto merge of #3897 - eduardosm:sse-tests, r=RalfJung

Use `@only-target` in SSE and SSE2 tests too

It looks cleaner and makes it consistent with other X86 tests.

The huge diffs are mostly indentation changes.
This commit is contained in:
bors 2024-09-17 19:04:45 +00:00
commit 3d4d5e1c10
2 changed files with 1892 additions and 1916 deletions

View File

@ -1,16 +1,6 @@
fn main() { // We're testing x86 target specific features
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] //@only-target: x86_64 i686
{
assert!(is_x86_feature_detected!("sse"));
unsafe {
tests::test_sse();
}
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod tests {
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
use std::arch::x86::*; use std::arch::x86::*;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -18,6 +8,14 @@ mod tests {
use std::f32::NAN; use std::f32::NAN;
use std::mem::transmute; use std::mem::transmute;
fn main() {
assert!(is_x86_feature_detected!("sse"));
unsafe {
test_sse();
}
}
macro_rules! assert_approx_eq { macro_rules! assert_approx_eq {
($a:expr, $b:expr, $eps:expr) => {{ ($a:expr, $b:expr, $eps:expr) => {{
let (a, b) = (&$a, &$b); let (a, b) = (&$a, &$b);
@ -34,7 +32,7 @@ macro_rules! assert_approx_eq {
} }
#[target_feature(enable = "sse")] #[target_feature(enable = "sse")]
pub(super) unsafe fn test_sse() { unsafe fn test_sse() {
// Mostly copied from library/stdarch/crates/core_arch/src/x86{,_64}/sse.rs // Mostly copied from library/stdarch/crates/core_arch/src/x86{,_64}/sse.rs
#[target_feature(enable = "sse")] #[target_feature(enable = "sse")]
@ -939,11 +937,7 @@ unsafe fn test_mm_cvtss_si32() {
let x = _mm_setr_ps(inputs[i], 1.0, 3.0, 4.0); let x = _mm_setr_ps(inputs[i], 1.0, 3.0, 4.0);
let e = result[i]; let e = result[i];
let r = _mm_cvtss_si32(x); let r = _mm_cvtss_si32(x);
assert_eq!( assert_eq!(e, r, "TestCase #{} _mm_cvtss_si32({:?}) = {}, expected: {}", i, x, r, e);
e, r,
"TestCase #{} _mm_cvtss_si32({:?}) = {}, expected: {}",
i, x, r, e
);
} }
} }
test_mm_cvtss_si32(); test_mm_cvtss_si32();
@ -966,11 +960,7 @@ unsafe fn test_mm_cvttss_si32() {
let (xi, e) = inputs[i]; let (xi, e) = inputs[i];
let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0); let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0);
let r = _mm_cvttss_si32(x); let r = _mm_cvttss_si32(x);
assert_eq!( assert_eq!(e, r, "TestCase #{} _mm_cvttss_si32({:?}) = {}, expected: {}", i, x, r, e);
e, r,
"TestCase #{} _mm_cvttss_si32({:?}) = {}, expected: {}",
i, x, r, e
);
} }
} }
test_mm_cvttss_si32(); test_mm_cvttss_si32();
@ -1020,11 +1010,7 @@ unsafe fn test_mm_cvtss_si64() {
let (xi, e) = inputs[i]; let (xi, e) = inputs[i];
let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0); let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0);
let r = _mm_cvtss_si64(x); let r = _mm_cvtss_si64(x);
assert_eq!( assert_eq!(e, r, "TestCase #{} _mm_cvtss_si64({:?}) = {}, expected: {}", i, x, r, e);
e, r,
"TestCase #{} _mm_cvtss_si64({:?}) = {}, expected: {}",
i, x, r, e
);
} }
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -1052,11 +1038,7 @@ unsafe fn test_mm_cvttss_si64() {
let (xi, e) = inputs[i]; let (xi, e) = inputs[i];
let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0); let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0);
let r = _mm_cvttss_si64(x); let r = _mm_cvttss_si64(x);
assert_eq!( assert_eq!(e, r, "TestCase #{} _mm_cvttss_si64({:?}) = {}, expected: {}", i, x, r, e);
e, r,
"TestCase #{} _mm_cvttss_si64({:?}) = {}, expected: {}",
i, x, r, e
);
} }
} }
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -1104,4 +1086,3 @@ unsafe fn test_mm_movemask_ps() {
_mm_prefetch(&x, _MM_HINT_ET0); _mm_prefetch(&x, _MM_HINT_ET0);
_mm_prefetch(&x, _MM_HINT_ET1); _mm_prefetch(&x, _MM_HINT_ET1);
} }
}

View File

@ -1,16 +1,6 @@
fn main() { // We're testing x86 target specific features
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] //@only-target: x86_64 i686
{
assert!(is_x86_feature_detected!("sse2"));
unsafe {
tests::test_sse2();
}
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod tests {
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
use std::arch::x86::*; use std::arch::x86::*;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -18,13 +8,21 @@ mod tests {
use std::f64::NAN; use std::f64::NAN;
use std::mem::transmute; use std::mem::transmute;
fn main() {
assert!(is_x86_feature_detected!("sse2"));
unsafe {
test_sse2();
}
}
#[target_feature(enable = "sse2")] #[target_feature(enable = "sse2")]
unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i { unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
_mm_set_epi64x(b, a) _mm_set_epi64x(b, a)
} }
#[target_feature(enable = "sse2")] #[target_feature(enable = "sse2")]
pub(super) unsafe fn test_sse2() { unsafe fn test_sse2() {
// Mostly copied from library/stdarch/crates/core_arch/src/x86{,_64}/sse2.rs // Mostly copied from library/stdarch/crates/core_arch/src/x86{,_64}/sse2.rs
unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i { unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
@ -83,10 +81,8 @@ unsafe fn test_mm_madd_epi16() {
let e = _mm_setr_epi32(29, 81, 149, 233); let e = _mm_setr_epi32(29, 81, 149, 233);
assert_eq_m128i(r, e); assert_eq_m128i(r, e);
let a = let a = _mm_setr_epi16(i16::MAX, i16::MAX, i16::MIN, i16::MIN, i16::MIN, i16::MAX, 0, 0);
_mm_setr_epi16(i16::MAX, i16::MAX, i16::MIN, i16::MIN, i16::MIN, i16::MAX, 0, 0); let b = _mm_setr_epi16(i16::MAX, i16::MAX, i16::MIN, i16::MIN, i16::MAX, i16::MIN, 0, 0);
let b =
_mm_setr_epi16(i16::MAX, i16::MAX, i16::MIN, i16::MIN, i16::MAX, i16::MIN, 0, 0);
let r = _mm_madd_epi16(a, b); let r = _mm_madd_epi16(a, b);
let e = _mm_setr_epi32(0x7FFE0002, i32::MIN, -0x7FFF0000, 0); let e = _mm_setr_epi32(0x7FFE0002, i32::MIN, -0x7FFF0000, 0);
assert_eq_m128i(r, e); assert_eq_m128i(r, e);
@ -845,4 +841,3 @@ unsafe fn test_mm_movemask_pd() {
} }
test_mm_movemask_pd(); test_mm_movemask_pd();
} }
}