Skip to content

Commit 11dfa41

Browse files
committed
Remove CSR accessing tests as they are immediate UB
1 parent 211c94c commit 11dfa41

File tree

1 file changed

+4
-115
lines changed
  • crates/core_arch/src/x86

1 file changed

+4
-115
lines changed

Diff for: crates/core_arch/src/x86/sse.rs

+4-115
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ pub unsafe fn _MM_GET_ROUNDING_MODE() -> u32 {
17381738
note = "see `_mm_setcsr` documentation - use inline assembly instead"
17391739
)]
17401740
pub unsafe fn _MM_SET_EXCEPTION_MASK(x: u32) {
1741-
_mm_setcsr((_mm_getcsr() & !_MM_MASK_MASK) | x)
1741+
_mm_setcsr((_mm_getcsr() & !_MM_MASK_MASK) | (x & _MM_MASK_MASK))
17421742
}
17431743

17441744
/// See [`_mm_setcsr`](fn._mm_setcsr.html)
@@ -1754,7 +1754,7 @@ pub unsafe fn _MM_SET_EXCEPTION_MASK(x: u32) {
17541754
note = "see `_mm_setcsr` documentation - use inline assembly instead"
17551755
)]
17561756
pub unsafe fn _MM_SET_EXCEPTION_STATE(x: u32) {
1757-
_mm_setcsr((_mm_getcsr() & !_MM_EXCEPT_MASK) | x)
1757+
_mm_setcsr((_mm_getcsr() & !_MM_EXCEPT_MASK) | (x & _MM_EXCEPT_MASK))
17581758
}
17591759

17601760
/// See [`_mm_setcsr`](fn._mm_setcsr.html)
@@ -1770,9 +1770,7 @@ pub unsafe fn _MM_SET_EXCEPTION_STATE(x: u32) {
17701770
note = "see `_mm_setcsr` documentation - use inline assembly instead"
17711771
)]
17721772
pub unsafe fn _MM_SET_FLUSH_ZERO_MODE(x: u32) {
1773-
let val = (_mm_getcsr() & !_MM_FLUSH_ZERO_MASK) | x;
1774-
// println!("setting csr={:x}", val);
1775-
_mm_setcsr(val)
1773+
_mm_setcsr((_mm_getcsr() & !_MM_FLUSH_ZERO_MASK) | (x & _MM_FLUSH_ZERO_MASK))
17761774
}
17771775

17781776
/// See [`_mm_setcsr`](fn._mm_setcsr.html)
@@ -1788,7 +1786,7 @@ pub unsafe fn _MM_SET_FLUSH_ZERO_MODE(x: u32) {
17881786
note = "see `_mm_setcsr` documentation - use inline assembly instead"
17891787
)]
17901788
pub unsafe fn _MM_SET_ROUNDING_MODE(x: u32) {
1791-
_mm_setcsr((_mm_getcsr() & !_MM_ROUND_MASK) | x)
1789+
_mm_setcsr((_mm_getcsr() & !_MM_ROUND_MASK) | (x & _MM_ROUND_MASK))
17921790
}
17931791

17941792
/// See [`_mm_prefetch`](fn._mm_prefetch.html).
@@ -2901,57 +2899,6 @@ mod tests {
29012899
}
29022900
}
29032901

2904-
#[allow(deprecated)] // FIXME: This test uses deprecated CSR access functions
2905-
#[simd_test(enable = "sse")]
2906-
#[cfg_attr(miri, ignore)] // Uses _mm_setcsr, which is not supported by Miri
2907-
unsafe fn test_mm_comieq_ss_vs_ucomieq_ss() {
2908-
// If one of the arguments is a quiet NaN `comieq_ss` should signal an
2909-
// Invalid Operation Exception while `ucomieq_ss` should not.
2910-
let aa = &[3.0f32, NAN, 23.0, NAN];
2911-
let bb = &[3.0f32, 47.5, NAN, NAN];
2912-
2913-
let ee = &[1i32, 0, 0, 0];
2914-
let exc = &[0u32, 1, 1, 1]; // Should comieq_ss signal an exception?
2915-
2916-
for i in 0..4 {
2917-
let a = _mm_setr_ps(aa[i], 1.0, 2.0, 3.0);
2918-
let b = _mm_setr_ps(bb[i], 0.0, 2.0, 4.0);
2919-
2920-
_MM_SET_EXCEPTION_STATE(0);
2921-
let r1 = _mm_comieq_ss(*black_box(&a), b);
2922-
let s1 = _MM_GET_EXCEPTION_STATE();
2923-
2924-
_MM_SET_EXCEPTION_STATE(0);
2925-
let r2 = _mm_ucomieq_ss(*black_box(&a), b);
2926-
let s2 = _MM_GET_EXCEPTION_STATE();
2927-
2928-
assert_eq!(
2929-
ee[i], r1,
2930-
"_mm_comeq_ss({:?}, {:?}) = {}, expected: {} (i={})",
2931-
a, b, r1, ee[i], i
2932-
);
2933-
assert_eq!(
2934-
ee[i], r2,
2935-
"_mm_ucomeq_ss({:?}, {:?}) = {}, expected: {} (i={})",
2936-
a, b, r2, ee[i], i
2937-
);
2938-
assert_eq!(
2939-
s1,
2940-
exc[i] * _MM_EXCEPT_INVALID,
2941-
"_mm_comieq_ss() set exception flags: {} (i={})",
2942-
s1,
2943-
i
2944-
);
2945-
assert_eq!(
2946-
s2,
2947-
0, // ucomieq_ss should not signal an exception
2948-
"_mm_ucomieq_ss() set exception flags: {} (i={})",
2949-
s2,
2950-
i
2951-
);
2952-
}
2953-
}
2954-
29552902
#[simd_test(enable = "sse")]
29562903
unsafe fn test_mm_cvtss_si32() {
29572904
let inputs = &[42.0f32, -3.1, 4.0e10, 4.0e-20, NAN, 2147483500.1];
@@ -3320,64 +3267,6 @@ mod tests {
33203267
_mm_sfence();
33213268
}
33223269

3323-
#[allow(deprecated)] // FIXME: This tests functions that are immediate UB
3324-
#[simd_test(enable = "sse")]
3325-
#[cfg_attr(miri, ignore)] // Miri does not support accesing the CSR
3326-
unsafe fn test_mm_getcsr_setcsr_1() {
3327-
let saved_csr = _mm_getcsr();
3328-
3329-
let a = _mm_setr_ps(1.1e-36, 0.0, 0.0, 1.0);
3330-
let b = _mm_setr_ps(0.001, 0.0, 0.0, 1.0);
3331-
3332-
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
3333-
let r = _mm_mul_ps(*black_box(&a), *black_box(&b));
3334-
3335-
_mm_setcsr(saved_csr);
3336-
3337-
let exp = _mm_setr_ps(0.0, 0.0, 0.0, 1.0);
3338-
assert_eq_m128(r, exp); // first component is a denormalized f32
3339-
}
3340-
3341-
#[allow(deprecated)] // FIXME: This tests functions that are immediate UB
3342-
#[simd_test(enable = "sse")]
3343-
#[cfg_attr(miri, ignore)] // Miri does not support accesing the CSR
3344-
unsafe fn test_mm_getcsr_setcsr_2() {
3345-
// Same as _mm_setcsr_1 test, but with opposite flag value.
3346-
3347-
let saved_csr = _mm_getcsr();
3348-
3349-
let a = _mm_setr_ps(1.1e-36, 0.0, 0.0, 1.0);
3350-
let b = _mm_setr_ps(0.001, 0.0, 0.0, 1.0);
3351-
3352-
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
3353-
let r = _mm_mul_ps(*black_box(&a), *black_box(&b));
3354-
3355-
_mm_setcsr(saved_csr);
3356-
3357-
let exp = _mm_setr_ps(1.1e-39, 0.0, 0.0, 1.0);
3358-
assert_eq_m128(r, exp); // first component is a denormalized f32
3359-
}
3360-
3361-
#[allow(deprecated)] // FIXME: This tests functions that are immediate UB
3362-
#[simd_test(enable = "sse")]
3363-
#[cfg_attr(miri, ignore)] // Miri does not support accesing the CSR
3364-
unsafe fn test_mm_getcsr_setcsr_underflow() {
3365-
_MM_SET_EXCEPTION_STATE(0);
3366-
3367-
let a = _mm_setr_ps(1.1e-36, 0.0, 0.0, 1.0);
3368-
let b = _mm_setr_ps(1e-5, 0.0, 0.0, 1.0);
3369-
3370-
assert_eq!(_MM_GET_EXCEPTION_STATE(), 0); // just to be sure
3371-
3372-
let r = _mm_mul_ps(*black_box(&a), *black_box(&b));
3373-
3374-
let exp = _mm_setr_ps(1.1e-41, 0.0, 0.0, 1.0);
3375-
assert_eq_m128(r, exp);
3376-
3377-
let underflow = _MM_GET_EXCEPTION_STATE() & _MM_EXCEPT_UNDERFLOW != 0;
3378-
assert!(underflow);
3379-
}
3380-
33813270
#[simd_test(enable = "sse")]
33823271
unsafe fn test_MM_TRANSPOSE4_PS() {
33833272
let mut a = _mm_setr_ps(1.0, 2.0, 3.0, 4.0);

0 commit comments

Comments
 (0)