From 0f61afad5c2e440c683f211207f45e1d08b1eaaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Fri, 29 Sep 2023 16:34:21 +0200 Subject: [PATCH 1/4] Deprecate functions that use `_mm_getcsr` or `_mm_setcsr` --- crates/core_arch/src/x86/sse.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/core_arch/src/x86/sse.rs b/crates/core_arch/src/x86/sse.rs index c132d13876..d78d03056d 100644 --- a/crates/core_arch/src/x86/sse.rs +++ b/crates/core_arch/src/x86/sse.rs @@ -1618,6 +1618,10 @@ pub const _MM_FLUSH_ZERO_OFF: u32 = 0x0000; #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_getcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_GET_EXCEPTION_MASK() -> u32 { _mm_getcsr() & _MM_MASK_MASK } @@ -1629,6 +1633,10 @@ pub unsafe fn _MM_GET_EXCEPTION_MASK() -> u32 { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_getcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_GET_EXCEPTION_STATE() -> u32 { _mm_getcsr() & _MM_EXCEPT_MASK } @@ -1640,6 +1648,10 @@ pub unsafe fn _MM_GET_EXCEPTION_STATE() -> u32 { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_getcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_GET_FLUSH_ZERO_MODE() -> u32 { _mm_getcsr() & _MM_FLUSH_ZERO_MASK } @@ -1651,6 +1663,10 @@ pub unsafe fn _MM_GET_FLUSH_ZERO_MODE() -> u32 { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_getcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_GET_ROUNDING_MODE() -> u32 { _mm_getcsr() & _MM_ROUND_MASK } @@ -1662,6 +1678,10 @@ pub unsafe fn _MM_GET_ROUNDING_MODE() -> u32 { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_setcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_SET_EXCEPTION_MASK(x: u32) { _mm_setcsr((_mm_getcsr() & !_MM_MASK_MASK) | x) } @@ -1673,6 +1693,10 @@ pub unsafe fn _MM_SET_EXCEPTION_MASK(x: u32) { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_setcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_SET_EXCEPTION_STATE(x: u32) { _mm_setcsr((_mm_getcsr() & !_MM_EXCEPT_MASK) | x) } @@ -1684,6 +1708,10 @@ pub unsafe fn _MM_SET_EXCEPTION_STATE(x: u32) { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_setcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_SET_FLUSH_ZERO_MODE(x: u32) { let val = (_mm_getcsr() & !_MM_FLUSH_ZERO_MASK) | x; // println!("setting csr={:x}", val); @@ -1697,6 +1725,10 @@ pub unsafe fn _MM_SET_FLUSH_ZERO_MODE(x: u32) { #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] +#[deprecated( + since = "1.73.0", + note = "see `_mm_setcsr` documentation - use inline assembly instead" +)] pub unsafe fn _MM_SET_ROUNDING_MODE(x: u32) { _mm_setcsr((_mm_getcsr() & !_MM_ROUND_MASK) | x) } From 625cd4ea79a6f41cec32f460f86be266937b368d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Fri, 29 Sep 2023 16:37:31 +0200 Subject: [PATCH 2/4] Remove references to `_mm_getcsr` or `_mm_setcsr` in other function's docs --- crates/core_arch/src/x86/sse.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/core_arch/src/x86/sse.rs b/crates/core_arch/src/x86/sse.rs index d78d03056d..2e275b065c 100644 --- a/crates/core_arch/src/x86/sse.rs +++ b/crates/core_arch/src/x86/sse.rs @@ -790,8 +790,7 @@ pub unsafe fn _mm_ucomineq_ss(a: __m128, b: __m128) -> i32 { /// /// The result is rounded according to the current rounding mode. If the result /// cannot be represented as a 32 bit integer the result will be `0x8000_0000` -/// (`i32::MIN`) or an invalid operation floating point exception if -/// unmasked (see [`_mm_setcsr`](fn._mm_setcsr.html)). +/// (`i32::MIN`). /// /// This corresponds to the `CVTSS2SI` instruction (with 32 bit output). /// @@ -821,8 +820,7 @@ pub unsafe fn _mm_cvt_ss2si(a: __m128) -> i32 { /// /// The result is rounded always using truncation (round towards zero). If the /// result cannot be represented as a 32 bit integer the result will be -/// `0x8000_0000` (`i32::MIN`) or an invalid operation floating point -/// exception if unmasked (see [`_mm_setcsr`](fn._mm_setcsr.html)). +/// `0x8000_0000` (`i32::MIN`). /// /// This corresponds to the `CVTTSS2SI` instruction (with 32 bit output). /// From b010d65bcac46567d491ca5cf822370d787ac6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Fri, 29 Sep 2023 18:02:47 +0200 Subject: [PATCH 3/4] Add some `#[allow(deprecated)]` --- crates/assert-instr-macro/src/lib.rs | 11 +++++++++++ crates/core_arch/src/x86/sse.rs | 12 ++++++++++++ crates/core_arch/src/x86/sse41.rs | 2 ++ 3 files changed, 25 insertions(+) diff --git a/crates/assert-instr-macro/src/lib.rs b/crates/assert-instr-macro/src/lib.rs index 99e37c9105..dfda3b48bf 100644 --- a/crates/assert-instr-macro/src/lib.rs +++ b/crates/assert-instr-macro/src/lib.rs @@ -35,6 +35,15 @@ pub fn assert_instr( let instr = &invoc.instr; let name = &func.sig.ident; + let maybe_allow_deprecated = if func + .attrs + .iter() + .any(|attr| attr.path.is_ident("deprecated")) + { + quote! { #[allow(deprecated)] } + } else { + quote! {} + }; // Disable assert_instr for x86 targets compiled with avx enabled, which // causes LLVM to generate different intrinsics that the ones we are @@ -135,6 +144,7 @@ pub fn assert_instr( let to_test = if disable_dedup_guard { quote! { #attrs + #maybe_allow_deprecated #[no_mangle] #[inline(never)] pub unsafe extern #abi fn #shim_name(#(#inputs),*) #ret { @@ -147,6 +157,7 @@ pub fn assert_instr( const #shim_name_ptr : *const u8 = #shim_name_str.as_ptr(); #attrs + #maybe_allow_deprecated #[no_mangle] #[inline(never)] pub unsafe extern #abi fn #shim_name(#(#inputs),*) #ret { diff --git a/crates/core_arch/src/x86/sse.rs b/crates/core_arch/src/x86/sse.rs index 2e275b065c..2560b10b0b 100644 --- a/crates/core_arch/src/x86/sse.rs +++ b/crates/core_arch/src/x86/sse.rs @@ -1613,6 +1613,7 @@ pub const _MM_FLUSH_ZERO_OFF: u32 = 0x0000; /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_EXCEPTION_MASK) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1628,6 +1629,7 @@ pub unsafe fn _MM_GET_EXCEPTION_MASK() -> u32 { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_EXCEPTION_STATE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1643,6 +1645,7 @@ pub unsafe fn _MM_GET_EXCEPTION_STATE() -> u32 { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_FLUSH_ZERO_MODE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1658,6 +1661,7 @@ pub unsafe fn _MM_GET_FLUSH_ZERO_MODE() -> u32 { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_GET_ROUNDING_MODE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1673,6 +1677,7 @@ pub unsafe fn _MM_GET_ROUNDING_MODE() -> u32 { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_EXCEPTION_MASK) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1688,6 +1693,7 @@ pub unsafe fn _MM_SET_EXCEPTION_MASK(x: u32) { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_EXCEPTION_STATE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1703,6 +1709,7 @@ pub unsafe fn _MM_SET_EXCEPTION_STATE(x: u32) { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_FLUSH_ZERO_MODE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -1720,6 +1727,7 @@ pub unsafe fn _MM_SET_FLUSH_ZERO_MODE(x: u32) { /// /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_MM_SET_ROUNDING_MODE) #[inline] +#[allow(deprecated)] // Deprecated function implemented on top of deprecated function #[allow(non_snake_case)] #[target_feature(enable = "sse")] #[stable(feature = "simd_x86", since = "1.27.0")] @@ -2834,6 +2842,7 @@ mod tests { } } + #[allow(deprecated)] // FIXME: This test uses deprecated CSR access functions #[simd_test(enable = "sse")] unsafe fn test_mm_comieq_ss_vs_ucomieq_ss() { // If one of the arguments is a quiet NaN `comieq_ss` should signal an @@ -3258,6 +3267,7 @@ mod tests { _mm_sfence(); } + #[allow(deprecated)] // FIXME: This tests functions that are immediate UB #[simd_test(enable = "sse")] unsafe fn test_mm_getcsr_setcsr_1() { let saved_csr = _mm_getcsr(); @@ -3274,6 +3284,7 @@ mod tests { assert_eq_m128(r, exp); // first component is a denormalized f32 } + #[allow(deprecated)] // FIXME: This tests functions that are immediate UB #[simd_test(enable = "sse")] unsafe fn test_mm_getcsr_setcsr_2() { // Same as _mm_setcsr_1 test, but with opposite flag value. @@ -3292,6 +3303,7 @@ mod tests { assert_eq_m128(r, exp); // first component is a denormalized f32 } + #[allow(deprecated)] // FIXME: This tests functions that are immediate UB #[simd_test(enable = "sse")] unsafe fn test_mm_getcsr_setcsr_underflow() { _MM_SET_EXCEPTION_STATE(0); diff --git a/crates/core_arch/src/x86/sse41.rs b/crates/core_arch/src/x86/sse41.rs index 7ba86e5f79..a62beb6f68 100644 --- a/crates/core_arch/src/x86/sse41.rs +++ b/crates/core_arch/src/x86/sse41.rs @@ -1668,6 +1668,7 @@ mod tests { assert_eq_m128(r, e); } + #[allow(deprecated)] // FIXME: This test uses deprecated CSR access functions #[simd_test(enable = "sse4.1")] unsafe fn test_mm_round_sd() { let a = _mm_setr_pd(1.5, 3.5); @@ -1680,6 +1681,7 @@ mod tests { assert_eq_m128d(r, e); } + #[allow(deprecated)] // FIXME: This test uses deprecated CSR access functions #[simd_test(enable = "sse4.1")] unsafe fn test_mm_round_ss() { let a = _mm_setr_ps(1.5, 3.5, 7.5, 15.5); From 79b1483cc08ed1a3f47bbe8a86624a707990fc77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Sun, 1 Oct 2023 16:03:53 +0200 Subject: [PATCH 4/4] Explicitly disable SSE3 for x86_64 --- ci/run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/run.sh b/ci/run.sh index c6eeae6045..20cd4c5643 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -33,6 +33,11 @@ case ${TARGET} in i686-* | i586-*) export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static -Z plt=yes" ;; + # Some x86_64 targets enable by default more features beyond SSE2, + # which cause some instruction assertion checks to fail. + x86_64-*) + export RUSTFLAGS="${RUSTFLAGS} -C target-feature=-sse3" + ;; #Unoptimized build uses fast-isel which breaks with msa mips-* | mipsel-*) export RUSTFLAGS="${RUSTFLAGS} -C llvm-args=-fast-isel=false"