From dea4dbed1c453295c1d041ada953d72da0b0a39d Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 24 Sep 2023 18:54:03 +0900 Subject: [PATCH] Remove old nightly-specific optimizations This only removes optimizations that are only used in old nightly. Most of them were only used in old nightly releases about 3 and a half to about 2 years ago. --- build.rs | 15 +++++---------- src/imp/arm_linux.rs | 4 +--- src/imp/atomic128/intrinsics.rs | 4 +++- src/imp/core_atomic.rs | 6 +++--- src/imp/fallback/mod.rs | 2 +- src/imp/mod.rs | 18 ++++++------------ src/imp/x86.rs | 4 +--- src/lib.rs | 3 +-- src/tests/mod.rs | 2 +- 9 files changed, 22 insertions(+), 36 deletions(-) diff --git a/build.rs b/build.rs index bd33b395..1eb05cfe 100644 --- a/build.rs +++ b/build.rs @@ -133,20 +133,16 @@ fn main() { println!("cargo:rustc-cfg=portable_atomic_llvm_16"); } if version.nightly { + // For Miri and ThreadSanitizer. // https://github.com/rust-lang/rust/pull/97423 merged in Rust 1.64 (nightly-2022-06-30). - if version.probe(64, 2022, 6, 29) { + if target_arch == "aarch64" && version.probe(64, 2022, 6, 29) { println!("cargo:rustc-cfg=portable_atomic_new_atomic_intrinsics"); } - // https://github.com/rust-lang/rust/pull/100911 (includes https://github.com/rust-lang/stdarch/pull/1315) merged in Rust 1.65 (nightly-2022-08-26). - if target_arch == "x86_64" && !version.probe(65, 2022, 8, 25) { - println!( - "cargo:rustc-cfg=portable_atomic_no_cmpxchg16b_intrinsic_stronger_failure_ordering" - ); - } // feature(isa_attribute) stabilized in Rust 1.67 (nightly-2022-11-06): https://github.com/rust-lang/rust/pull/102458 if target_arch == "arm" && !version.probe(67, 2022, 11, 5) { println!("cargo:rustc-cfg=portable_atomic_unstable_isa_attribute"); } + // For Miri and ThreadSanitizer. // https://github.com/rust-lang/rust/pull/109359 (includes https://github.com/rust-lang/stdarch/pull/1358) merged in Rust 1.70 (nightly-2023-03-24). if target_arch == "x86_64" && !version.probe(70, 2023, 3, 23) { println!("cargo:rustc-cfg=portable_atomic_unstable_cmpxchg16b_intrinsic"); @@ -176,8 +172,8 @@ fn main() { } } - let is_apple = - target_os == "macos" || target_os == "ios" || target_os == "tvos" || target_os == "watchos"; + let is_macos = target_os == "macos"; + let is_apple = is_macos || target_os == "ios" || target_os == "tvos" || target_os == "watchos"; match target_arch { "x86_64" => { // cmpxchg16b_target_feature stabilized in Rust 1.69 (nightly-2023-03-01): https://github.com/rust-lang/rust/pull/106774 @@ -221,7 +217,6 @@ fn main() { // aarch64 macOS always supports FEAT_LSE and FEAT_LSE2 because it is armv8.5-a: // https://github.com/llvm/llvm-project/blob/llvmorg-17.0.0-rc2/llvm/include/llvm/TargetParser/AArch64TargetParser.h#L494 - let is_macos = target_os == "macos"; let mut has_lse = is_macos; // FEAT_LSE2 doesn't imply FEAT_LSE. FEAT_LSE128 implies FEAT_LSE but not FEAT_LSE2. // As of rustc 1.70, target_feature "lse2"/"lse128"/"rcpc3" is not available on rustc side: diff --git a/src/imp/arm_linux.rs b/src/imp/arm_linux.rs index 9f3c24ed..e2559678 100644 --- a/src/imp/arm_linux.rs +++ b/src/imp/arm_linux.rs @@ -16,9 +16,7 @@ #[path = "fallback/outline_atomics.rs"] mod fallback; -#[cfg(not(portable_atomic_no_asm))] -use core::arch::asm; -use core::{cell::UnsafeCell, mem, sync::atomic::Ordering}; +use core::{arch::asm, cell::UnsafeCell, mem, sync::atomic::Ordering}; use crate::utils::{Pair, U64}; diff --git a/src/imp/atomic128/intrinsics.rs b/src/imp/atomic128/intrinsics.rs index 97caba10..dfa55bbe 100644 --- a/src/imp/atomic128/intrinsics.rs +++ b/src/imp/atomic128/intrinsics.rs @@ -134,7 +134,9 @@ unsafe fn atomic_compare_exchange( let prev = unsafe { core::arch::x86_64::cmpxchg16b(dst, old, new, success, failure) }; (prev, prev == old) } - #[cfg(portable_atomic_no_cmpxchg16b_intrinsic_stronger_failure_ordering)] + // The stronger failure ordering in cmpxchg16b_intrinsic is actually supported + // before stabilization, but we do not have a specific cfg for it. + #[cfg(portable_atomic_unstable_cmpxchg16b_intrinsic)] let success = crate::utils::upgrade_success_ordering(success, failure); #[cfg(target_feature = "cmpxchg16b")] // SAFETY: the caller must guarantee that `dst` is valid for both writes and diff --git a/src/imp/core_atomic.rs b/src/imp/core_atomic.rs index 5a331429..c7f713b5 100644 --- a/src/imp/core_atomic.rs +++ b/src/imp/core_atomic.rs @@ -140,7 +140,7 @@ macro_rules! atomic_int { #[cfg(not(all( any(target_arch = "x86", target_arch = "x86_64"), not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), )))] #[cfg_attr( portable_atomic_no_cfg_target_has_atomic, @@ -376,7 +376,7 @@ macro_rules! atomic_int { #[cfg(not(all( any(target_arch = "x86", target_arch = "x86_64"), not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), )))] #[inline] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces @@ -391,7 +391,7 @@ macro_rules! atomic_int { #[cfg(not(all( any(target_arch = "x86", target_arch = "x86_64"), not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), )))] #[inline] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces diff --git a/src/imp/fallback/mod.rs b/src/imp/fallback/mod.rs index 8a8e7686..001781b8 100644 --- a/src/imp/fallback/mod.rs +++ b/src/imp/fallback/mod.rs @@ -43,7 +43,7 @@ ), all( target_arch = "arm", - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), any(target_os = "linux", target_os = "android"), not(portable_atomic_no_outline_atomics), ), diff --git a/src/imp/mod.rs b/src/imp/mod.rs index e91d6000..cea71eb3 100644 --- a/src/imp/mod.rs +++ b/src/imp/mod.rs @@ -108,14 +108,8 @@ mod powerpc64; // s390x 128-bit atomics #[cfg(all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch))] // Use intrinsics.rs on Miri and Sanitizer that do not support inline assembly. -#[cfg_attr( - all(any(miri, portable_atomic_sanitize_thread), portable_atomic_new_atomic_intrinsics), - path = "atomic128/intrinsics.rs" -)] -#[cfg_attr( - not(all(any(miri, portable_atomic_sanitize_thread), portable_atomic_new_atomic_intrinsics)), - path = "atomic128/s390x.rs" -)] +#[cfg_attr(any(miri, portable_atomic_sanitize_thread), path = "atomic128/intrinsics.rs")] +#[cfg_attr(not(any(miri, portable_atomic_sanitize_thread)), path = "atomic128/s390x.rs")] mod s390x; // pre-v6 ARM Linux 64-bit atomics @@ -124,7 +118,7 @@ mod s390x; #[cfg(all( target_arch = "arm", not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), any(target_os = "linux", target_os = "android"), not(any(target_feature = "v6", portable_atomic_target_feature = "v6")), not(portable_atomic_no_outline_atomics), @@ -152,7 +146,7 @@ mod riscv; #[cfg(all( any(target_arch = "x86", target_arch = "x86_64"), not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), ))] mod x86; @@ -320,7 +314,7 @@ items! { #[cfg(not(all( target_arch = "arm", not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), any(target_os = "linux", target_os = "android"), not(any(target_feature = "v6", portable_atomic_target_feature = "v6")), not(portable_atomic_no_outline_atomics), @@ -387,7 +381,7 @@ items! { #[cfg(all( target_arch = "arm", not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), any(target_os = "linux", target_os = "android"), not(any(target_feature = "v6", portable_atomic_target_feature = "v6")), not(portable_atomic_no_outline_atomics), diff --git a/src/imp/x86.rs b/src/imp/x86.rs index 7c2cdeb0..56e9b158 100644 --- a/src/imp/x86.rs +++ b/src/imp/x86.rs @@ -14,9 +14,7 @@ // Generated asm: // - x86_64 https://godbolt.org/z/8fve4YP1G -#[cfg(not(portable_atomic_no_asm))] -use core::arch::asm; -use core::sync::atomic::Ordering; +use core::{arch::asm, sync::atomic::Ordering}; use super::core_atomic::{ AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU64, diff --git a/src/lib.rs b/src/lib.rs index 1cd67f74..23a0000c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,7 +260,7 @@ RUSTFLAGS="--cfg portable_atomic_no_outline_atomics" cargo ... // - cfg(target_has_atomic) // - #[target_feature(enable = "lse")] on AArch64 // - #[target_feature(enable = "cmpxchg16b")] on x86_64 -// - asm! on ARM, AArch64, RISC-V, x86, x86_64 +// - asm! on ARM, AArch64, RISC-V, x86_64 // - llvm_asm! on AVR (tier 3) and MSP430 (tier 3) // - #[instruction_set] on non-Linux pre-v6 ARM (tier 3) #![cfg_attr(portable_atomic_unstable_cfg_target_has_atomic, feature(cfg_target_has_atomic))] @@ -290,7 +290,6 @@ RUSTFLAGS="--cfg portable_atomic_no_outline_atomics" cargo ... target_arch = "arm", target_arch = "riscv32", target_arch = "riscv64", - target_arch = "x86", target_arch = "x86_64", ), ), diff --git a/src/tests/mod.rs b/src/tests/mod.rs index ba7ed479..e34aacea 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -84,7 +84,7 @@ fn test_is_lock_free() { feature = "fallback", target_arch = "arm", not(any(miri, portable_atomic_sanitize_thread)), - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + not(portable_atomic_no_asm), any(target_os = "linux", target_os = "android"), not(any(target_feature = "v6", portable_atomic_target_feature = "v6")), not(portable_atomic_no_outline_atomics),