Use @only-target in SSE and SSE2 tests too

It looks cleaner and makes it consistent with other X86 tests
This commit is contained in:
Eduardo Sánchez Muñoz 2024-09-17 20:33:30 +02:00
parent 62ccf6a434
commit 57f6563858
2 changed files with 1892 additions and 1916 deletions

View File

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

View File

@ -1,30 +1,28 @@
// We're testing x86 target specific features
//@only-target: x86_64 i686
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
use std::f64::NAN;
use std::mem::transmute;
fn main() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
assert!(is_x86_feature_detected!("sse2"));
unsafe {
tests::test_sse2();
}
test_sse2();
}
}
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod tests {
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
use std::f64::NAN;
use std::mem::transmute;
#[target_feature(enable = "sse2")]
unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
#[target_feature(enable = "sse2")]
unsafe fn _mm_setr_epi64x(a: i64, b: i64) -> __m128i {
_mm_set_epi64x(b, a)
}
}
#[target_feature(enable = "sse2")]
pub(super) unsafe fn test_sse2() {
#[target_feature(enable = "sse2")]
unsafe fn test_sse2() {
// Mostly copied from library/stdarch/crates/core_arch/src/x86{,_64}/sse2.rs
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);
assert_eq_m128i(r, e);
let a =
_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 a = _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 r = _mm_madd_epi16(a, b);
let e = _mm_setr_epi32(0x7FFE0002, i32::MIN, -0x7FFF0000, 0);
assert_eq_m128i(r, e);
@ -844,5 +840,4 @@ unsafe fn test_mm_movemask_pd() {
assert_eq!(r, 0b11);
}
test_mm_movemask_pd();
}
}