Skip to content

Commit

Permalink
Add cfg helper macro
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 1, 2023
1 parent 537a3c0 commit a4d656b
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 212 deletions.
38 changes: 3 additions & 35 deletions src/imp/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,38 +205,6 @@ macro_rules! atomic_float {

atomic_float!(AtomicF32, f32, AtomicU32, u32, 4);

#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
cfg(any(
all(
feature = "fallback",
any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
not(portable_atomic_no_atomic_64),
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
#[cfg_attr(
not(portable_atomic_no_cfg_target_has_atomic),
cfg(any(
all(
feature = "fallback",
any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
target_has_atomic = "64",
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
atomic_float!(AtomicF64, f64, AtomicU64, u64, 8);
cfg_atomic_64! {
atomic_float!(AtomicF64, f64, AtomicU64, u64, 8);
}
189 changes: 12 additions & 177 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4849,181 +4849,16 @@ atomic_int!(AtomicI32, i32, 4);
#[cfg(any(not(target_pointer_width = "16"), feature = "fallback"))]
atomic_int!(AtomicU32, u32, 4);

// cfg(any(target_has_atomic = "ptr", target_has_atomic_load_store = "64", all(feature = "fallback", portable_atomic_unsafe_assume_single_core)))
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
cfg(any(
all(
feature = "fallback",
any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
not(portable_atomic_no_atomic_64),
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
#[cfg_attr(
not(portable_atomic_no_cfg_target_has_atomic),
cfg(any(
all(
feature = "fallback",
any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
target_has_atomic = "64",
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
atomic_int!(AtomicI64, i64, 8);
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
cfg(any(
all(
feature = "fallback",
any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
not(portable_atomic_no_atomic_64),
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
#[cfg_attr(
not(portable_atomic_no_cfg_target_has_atomic),
cfg(any(
all(
feature = "fallback",
any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
target_has_atomic = "64",
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
atomic_int!(AtomicU64, u64, 8);
cfg_atomic_64! {
atomic_int!(AtomicI64, i64, 8);
}
cfg_atomic_64! {
atomic_int!(AtomicU64, u64, 8);
}

#[cfg_attr(
not(feature = "fallback"),
cfg(any(
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
target_arch = "aarch64",
),
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
any(
target_feature = "cmpxchg16b",
portable_atomic_target_feature = "cmpxchg16b",
all(
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
),
all(
portable_atomic_unstable_asm_experimental_arch,
any(
target_feature = "quadword-atomics",
portable_atomic_target_feature = "quadword-atomics",
),
target_arch = "powerpc64",
),
all(portable_atomic_unstable_asm_experimental_arch, target_arch = "s390x"),
))
)]
#[cfg_attr(
all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic),
cfg(any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
#[cfg_attr(
all(feature = "fallback", not(portable_atomic_no_cfg_target_has_atomic)),
cfg(any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
atomic_int!(AtomicI128, i128, 16);
#[cfg_attr(
not(feature = "fallback"),
cfg(any(
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
target_arch = "aarch64",
),
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
any(
target_feature = "cmpxchg16b",
portable_atomic_target_feature = "cmpxchg16b",
all(
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
),
all(
portable_atomic_unstable_asm_experimental_arch,
any(
target_feature = "quadword-atomics",
portable_atomic_target_feature = "quadword-atomics",
),
target_arch = "powerpc64",
),
all(portable_atomic_unstable_asm_experimental_arch, target_arch = "s390x"),
))
)]
#[cfg_attr(
all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic),
cfg(any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
#[cfg_attr(
all(feature = "fallback", not(portable_atomic_no_cfg_target_has_atomic)),
cfg(any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
atomic_int!(AtomicU128, u128, 16);
cfg_atomic_128! {
atomic_int!(AtomicI128, i128, 16);
}
cfg_atomic_128! {
atomic_int!(AtomicU128, u128, 16);
}
97 changes: 97 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,103 @@ macro_rules! bit_opts_fetch_impl {
};
}

macro_rules! cfg_atomic_64 {
($($tt:tt)*) => {
#[cfg_attr(
portable_atomic_no_cfg_target_has_atomic,
cfg(any(
all(
feature = "fallback",
any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
not(portable_atomic_no_atomic_64),
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
#[cfg_attr(
not(portable_atomic_no_cfg_target_has_atomic),
cfg(any(
all(
feature = "fallback",
any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
),
),
target_has_atomic = "64",
not(any(target_pointer_width = "16", target_pointer_width = "32")),
))
)]
$($tt)*
};
}
macro_rules! cfg_atomic_128 {
($($tt:tt)*) => {
#[cfg_attr(
not(feature = "fallback"),
cfg(any(
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
target_arch = "aarch64",
),
all(
any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
any(
target_feature = "cmpxchg16b",
portable_atomic_target_feature = "cmpxchg16b",
all(
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
),
all(
portable_atomic_unstable_asm_experimental_arch,
any(
target_feature = "quadword-atomics",
portable_atomic_target_feature = "quadword-atomics",
),
target_arch = "powerpc64",
),
all(portable_atomic_unstable_asm_experimental_arch, target_arch = "s390x"),
))
)]
#[cfg_attr(
all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic),
cfg(any(
not(portable_atomic_no_atomic_cas),
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
#[cfg_attr(
all(feature = "fallback", not(portable_atomic_no_cfg_target_has_atomic)),
cfg(any(
target_has_atomic = "ptr",
portable_atomic_unsafe_assume_single_core,
feature = "critical-section",
target_arch = "avr",
target_arch = "msp430",
))
)]
$($tt)*
};
}

// hthttps://github.com/rust-lang/rust/blob/1.68.0/library/core/src/sync/atomic.rs#L2992
#[allow(dead_code)]
#[inline]
Expand Down

0 comments on commit a4d656b

Please sign in to comment.