Skip to content

Commit

Permalink
Remove old nightly-specific optimizations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
taiki-e committed Sep 24, 2023
1 parent 287ef3d commit dea4dbe
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 36 deletions.
15 changes: 5 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions src/imp/arm_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 3 additions & 1 deletion src/imp/atomic128/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/imp/core_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/imp/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
18 changes: 6 additions & 12 deletions src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 1 addition & 3 deletions src/imp/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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",
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit dea4dbe

Please sign in to comment.