diff --git a/src/cfgs.rs b/src/cfgs.rs new file mode 100644 index 00000000..6dc6c47e --- /dev/null +++ b/src/cfgs.rs @@ -0,0 +1,408 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#[cfg(not(all( + portable_atomic_no_atomic_load_store, + not(any( + target_arch = "avr", + target_arch = "msp430", + target_arch = "riscv32", + target_arch = "riscv64", + feature = "critical-section", + )), +)))] +#[macro_use] +mod atomic_8_16_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_8 { + ($($tt:tt)*) => { + $($tt)* + }; + } + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_16 { + ($($tt:tt)*) => { + $($tt)* + }; + } +} +#[cfg(all( + portable_atomic_no_atomic_load_store, + not(any( + target_arch = "avr", + target_arch = "msp430", + target_arch = "riscv32", + target_arch = "riscv64", + feature = "critical-section", + )), +))] +#[macro_use] +mod atomic_8_16_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_8 { + ($($tt:tt)*) => {}; + } + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_16 { + ($($tt:tt)*) => {}; + } +} + +#[cfg(all( + any(not(target_pointer_width = "16"), feature = "fallback"), + not(all( + portable_atomic_no_atomic_load_store, + not(any( + target_arch = "avr", + target_arch = "msp430", + target_arch = "riscv32", + target_arch = "riscv64", + feature = "critical-section", + )), + )), +))] +#[macro_use] +mod atomic_32_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_32 { + ($($tt:tt)*) => { + $($tt)* + }; + } +} +#[cfg(not(all( + any(not(target_pointer_width = "16"), feature = "fallback"), + not(all( + portable_atomic_no_atomic_load_store, + not(any( + target_arch = "avr", + target_arch = "msp430", + target_arch = "riscv32", + target_arch = "riscv64", + feature = "critical-section", + )), + )), +)))] +#[macro_use] +mod atomic_32_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_32 { + ($($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")), + )) +)] +#[macro_use] +mod atomic_64_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_64 { + ($($tt:tt)*) => { + $($tt)* + }; + } +} +#[cfg_attr( + portable_atomic_no_cfg_target_has_atomic, + cfg(not(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(not(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")), + ))) +)] +#[macro_use] +mod atomic_64_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_64 { + ($($tt:tt)*) => {}; + } +} + +#[cfg_attr( + not(feature = "fallback"), + cfg(any( + all( + target_arch = "aarch64", + any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + ), + all( + target_arch = "x86_64", + any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + any( + target_feature = "cmpxchg16b", + portable_atomic_target_feature = "cmpxchg16b", + all( + feature = "fallback", + not(portable_atomic_no_cmpxchg16b_target_feature), + not(portable_atomic_no_outline_atomics), + not(any(target_env = "sgx", miri)), + ), + ), + ), + all( + target_arch = "powerpc64", + portable_atomic_unstable_asm_experimental_arch, + any( + target_feature = "quadword-atomics", + portable_atomic_target_feature = "quadword-atomics", + all( + feature = "fallback", + not(portable_atomic_no_outline_atomics), + portable_atomic_outline_atomics, // TODO(powerpc64): currently disabled by default + any( + all( + target_os = "linux", + any( + target_env = "gnu", + all( + any(target_env = "musl", target_env = "ohos"), + not(target_feature = "crt-static"), + ), + portable_atomic_outline_atomics, + ), + ), + target_os = "android", + target_os = "freebsd", + ), + not(any(miri, portable_atomic_sanitize_thread)), + ), + ), + ), + all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch), + )) +)] +#[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", + )) +)] +#[macro_use] +mod atomic_128_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_128 { + ($($tt:tt)*) => { + $($tt)* + }; + } +} +#[cfg_attr( + not(feature = "fallback"), + cfg(not(any( + all( + target_arch = "aarch64", + any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + ), + all( + target_arch = "x86_64", + any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), + any( + target_feature = "cmpxchg16b", + portable_atomic_target_feature = "cmpxchg16b", + all( + feature = "fallback", + not(portable_atomic_no_cmpxchg16b_target_feature), + not(portable_atomic_no_outline_atomics), + not(any(target_env = "sgx", miri)), + ), + ), + ), + all( + target_arch = "powerpc64", + portable_atomic_unstable_asm_experimental_arch, + any( + target_feature = "quadword-atomics", + portable_atomic_target_feature = "quadword-atomics", + all( + feature = "fallback", + not(portable_atomic_no_outline_atomics), + portable_atomic_outline_atomics, // TODO(powerpc64): currently disabled by default + any( + all( + target_os = "linux", + any( + target_env = "gnu", + all( + any(target_env = "musl", target_env = "ohos"), + not(target_feature = "crt-static"), + ), + portable_atomic_outline_atomics, + ), + ), + target_os = "android", + target_os = "freebsd", + ), + not(any(miri, portable_atomic_sanitize_thread)), + ), + ), + ), + all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch), + ))) +)] +#[cfg_attr( + all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic), + cfg(not(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(not(any( + target_has_atomic = "ptr", + portable_atomic_unsafe_assume_single_core, + feature = "critical-section", + target_arch = "avr", + target_arch = "msp430", + ))) +)] +#[macro_use] +mod atomic_128_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_128 { + ($($tt:tt)*) => {}; + } +} + +#[cfg_attr( + 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( + 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", + )) +)] +#[macro_use] +mod atomic_cas_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_cas { + ($($tt:tt)*) => { + $($tt)* + }; + } +} +#[cfg_attr( + portable_atomic_no_cfg_target_has_atomic, + cfg(not(any( + not(portable_atomic_no_atomic_cas), + portable_atomic_unsafe_assume_single_core, + feature = "critical-section", + target_arch = "avr", + target_arch = "msp430", + ))) +)] +#[cfg_attr( + not(portable_atomic_no_cfg_target_has_atomic), + cfg(not(any( + target_has_atomic = "ptr", + portable_atomic_unsafe_assume_single_core, + feature = "critical-section", + target_arch = "avr", + target_arch = "msp430", + ))) +)] +#[macro_use] +mod atomic_cas_macros { + #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) + #[macro_export] + macro_rules! cfg_has_atomic_cas { + ($($tt:tt)*) => {}; + } +} diff --git a/src/lib.rs b/src/lib.rs index 9492bb43..3268ba1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -439,6 +439,21 @@ compile_error!( #[cfg(any(test, feature = "std"))] extern crate std; +#[macro_use] +mod cfgs; +#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) +#[cfg(target_pointer_width = "128")] +pub use cfg_has_atomic_128 as cfg_has_atomic_ptr; +#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) +#[cfg(target_pointer_width = "16")] +pub use cfg_has_atomic_16 as cfg_has_atomic_ptr; +#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) +#[cfg(target_pointer_width = "32")] +pub use cfg_has_atomic_32 as cfg_has_atomic_ptr; +#[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) +#[cfg(target_pointer_width = "64")] +pub use cfg_has_atomic_64 as cfg_has_atomic_ptr; + #[macro_use] mod utils; diff --git a/src/utils.rs b/src/utils.rs index 102edbef..f73e7943 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -246,454 +246,6 @@ macro_rules! items { }; } -#[cfg(not(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "bpf", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), -)))] -#[macro_use] -mod atomic_ptr_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_ptr { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "bpf", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), -))] -#[macro_use] -mod atomic_ptr_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_ptr { - ($($tt:tt)*) => {}; - } -} - -#[cfg(not(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), -)))] -#[macro_use] -mod atomic_8_16_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_8 { - ($($tt:tt)*) => { - $($tt)* - }; - } - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_16 { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), -))] -#[macro_use] -mod atomic_8_16_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_8 { - ($($tt:tt)*) => {}; - } - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_16 { - ($($tt:tt)*) => {}; - } -} - -#[cfg(all( - any(not(target_pointer_width = "16"), feature = "fallback"), - not(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), - )), -))] -#[macro_use] -mod atomic_32_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_32 { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg(not(all( - any(not(target_pointer_width = "16"), feature = "fallback"), - not(all( - portable_atomic_no_atomic_load_store, - not(any( - target_arch = "avr", - target_arch = "msp430", - target_arch = "riscv32", - target_arch = "riscv64", - feature = "critical-section", - )), - )), -)))] -#[macro_use] -mod atomic_32_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_32 { - ($($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")), - )) -)] -#[macro_use] -mod atomic_64_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_64 { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg_attr( - portable_atomic_no_cfg_target_has_atomic, - cfg(not(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(not(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")), - ))) -)] -#[macro_use] -mod atomic_64_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_64 { - ($($tt:tt)*) => {}; - } -} - -#[cfg_attr( - not(feature = "fallback"), - cfg(any( - all( - target_arch = "aarch64", - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), - ), - all( - target_arch = "x86_64", - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), - any( - target_feature = "cmpxchg16b", - portable_atomic_target_feature = "cmpxchg16b", - all( - feature = "fallback", - not(portable_atomic_no_cmpxchg16b_target_feature), - not(portable_atomic_no_outline_atomics), - not(any(target_env = "sgx", miri)), - ), - ), - ), - all( - target_arch = "powerpc64", - portable_atomic_unstable_asm_experimental_arch, - any( - target_feature = "quadword-atomics", - portable_atomic_target_feature = "quadword-atomics", - all( - feature = "fallback", - not(portable_atomic_no_outline_atomics), - portable_atomic_outline_atomics, // TODO(powerpc64): currently disabled by default - any( - all( - target_os = "linux", - any( - target_env = "gnu", - all( - any(target_env = "musl", target_env = "ohos"), - not(target_feature = "crt-static"), - ), - portable_atomic_outline_atomics, - ), - ), - target_os = "android", - target_os = "freebsd", - ), - not(any(miri, portable_atomic_sanitize_thread)), - ), - ), - ), - all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch), - )) -)] -#[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", - )) -)] -#[macro_use] -mod atomic_128_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_128 { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg_attr( - not(feature = "fallback"), - cfg(not(any( - all( - target_arch = "aarch64", - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), - ), - all( - target_arch = "x86_64", - any(not(portable_atomic_no_asm), portable_atomic_unstable_asm), - any( - target_feature = "cmpxchg16b", - portable_atomic_target_feature = "cmpxchg16b", - all( - feature = "fallback", - not(portable_atomic_no_cmpxchg16b_target_feature), - not(portable_atomic_no_outline_atomics), - not(any(target_env = "sgx", miri)), - ), - ), - ), - all( - target_arch = "powerpc64", - portable_atomic_unstable_asm_experimental_arch, - any( - target_feature = "quadword-atomics", - portable_atomic_target_feature = "quadword-atomics", - all( - feature = "fallback", - not(portable_atomic_no_outline_atomics), - portable_atomic_outline_atomics, // TODO(powerpc64): currently disabled by default - any( - all( - target_os = "linux", - any( - target_env = "gnu", - all( - any(target_env = "musl", target_env = "ohos"), - not(target_feature = "crt-static"), - ), - portable_atomic_outline_atomics, - ), - ), - target_os = "android", - target_os = "freebsd", - ), - not(any(miri, portable_atomic_sanitize_thread)), - ), - ), - ), - all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch), - ))) -)] -#[cfg_attr( - all(feature = "fallback", portable_atomic_no_cfg_target_has_atomic), - cfg(not(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(not(any( - target_has_atomic = "ptr", - portable_atomic_unsafe_assume_single_core, - feature = "critical-section", - target_arch = "avr", - target_arch = "msp430", - ))) -)] -#[macro_use] -mod atomic_128_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_128 { - ($($tt:tt)*) => {}; - } -} - -#[cfg_attr( - 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( - 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", - )) -)] -#[macro_use] -mod atomic_cas_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_cas { - ($($tt:tt)*) => { - $($tt)* - }; - } -} -#[cfg_attr( - portable_atomic_no_cfg_target_has_atomic, - cfg(not(any( - not(portable_atomic_no_atomic_cas), - portable_atomic_unsafe_assume_single_core, - feature = "critical-section", - target_arch = "avr", - target_arch = "msp430", - ))) -)] -#[cfg_attr( - not(portable_atomic_no_cfg_target_has_atomic), - cfg(not(any( - target_has_atomic = "ptr", - portable_atomic_unsafe_assume_single_core, - feature = "critical-section", - target_arch = "avr", - target_arch = "msp430", - ))) -)] -#[macro_use] -mod atomic_cas_macros { - #[doc(hidden)] // Not public API. (please submit an issue if you want this to be public API) - #[macro_export] - macro_rules! cfg_has_atomic_cas { - ($($tt:tt)*) => {}; - } -} - // https://github.com/rust-lang/rust/blob/1.70.0/library/core/src/sync/atomic.rs#L3155 #[inline] #[cfg_attr(all(debug_assertions, not(portable_atomic_no_track_caller)), track_caller)]