core: Support variety of atomic widths in width-agnostic functions
Before this change, the following functions and macros were annotated with `#[cfg(target_has_atomic = "8")]` or `#[cfg(target_has_atomic_load_store = "8")]`: * `atomic_int` * `strongest_failure_ordering` * `atomic_swap` * `atomic_add` * `atomic_sub` * `atomic_compare_exchange` * `atomic_compare_exchange_weak` * `atomic_and` * `atomic_nand` * `atomic_or` * `atomic_xor` * `atomic_max` * `atomic_min` * `atomic_umax` * `atomic_umin` However, none of those functions and macros actually depend on 8-bit width and they are needed for all atomic widths (16-bit, 32-bit, 64-bit etc.). Some targets might not support 8-bit atomics (i.e. BPF, if we would enable atomic CAS for it). This change fixes that by removing the `"8"` argument from annotations, which results in accepting the whole variety of widths. Fixes #106845 Fixes #106795 Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
This commit is contained in:
parent
1cd7dbfbf8
commit
474ea87943
@ -1861,7 +1861,8 @@ macro_rules! if_not_8_bit {
|
||||
($_:ident, $($tt:tt)*) => { $($tt)* };
|
||||
}
|
||||
|
||||
#[cfg(target_has_atomic_load_store = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic_load_store))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic_load_store = "8"))]
|
||||
macro_rules! atomic_int {
|
||||
($cfg_cas:meta,
|
||||
$cfg_align:meta,
|
||||
@ -2988,7 +2989,8 @@ macro_rules! atomic_int_ptr_sized {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
fn strongest_failure_ordering(order: Ordering) -> Ordering {
|
||||
match order {
|
||||
Release => Relaxed,
|
||||
@ -3030,7 +3032,8 @@ unsafe fn atomic_load<T: Copy>(dst: *const T, order: Ordering) -> T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_swap`.
|
||||
@ -3047,7 +3050,8 @@ unsafe fn atomic_swap<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// Returns the previous value (like __sync_fetch_and_add).
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_add<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_add`.
|
||||
@ -3064,7 +3068,8 @@ unsafe fn atomic_add<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// Returns the previous value (like __sync_fetch_and_sub).
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_sub`.
|
||||
@ -3080,7 +3085,8 @@ unsafe fn atomic_sub<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_compare_exchange<T: Copy>(
|
||||
dst: *mut T,
|
||||
@ -3115,7 +3121,8 @@ unsafe fn atomic_compare_exchange<T: Copy>(
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_compare_exchange_weak<T: Copy>(
|
||||
dst: *mut T,
|
||||
@ -3150,7 +3157,8 @@ unsafe fn atomic_compare_exchange_weak<T: Copy>(
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_and<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_and`
|
||||
@ -3166,7 +3174,8 @@ unsafe fn atomic_and<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_nand<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_nand`
|
||||
@ -3182,7 +3191,8 @@ unsafe fn atomic_nand<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_or<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_or`
|
||||
@ -3198,7 +3208,8 @@ unsafe fn atomic_or<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_xor`
|
||||
@ -3215,7 +3226,8 @@ unsafe fn atomic_xor<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// returns the max value (signed comparison)
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_max<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_max`
|
||||
@ -3232,7 +3244,8 @@ unsafe fn atomic_max<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// returns the min value (signed comparison)
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_min<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_min`
|
||||
@ -3249,7 +3262,8 @@ unsafe fn atomic_min<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// returns the max value (unsigned comparison)
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_umax<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_umax`
|
||||
@ -3266,7 +3280,8 @@ unsafe fn atomic_umax<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
|
||||
/// returns the min value (unsigned comparison)
|
||||
#[inline]
|
||||
#[cfg(target_has_atomic = "8")]
|
||||
#[cfg_attr(not(bootstrap), cfg(target_has_atomic))]
|
||||
#[cfg_attr(bootstrap, cfg(target_has_atomic = "8"))]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
unsafe fn atomic_umin<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
|
||||
// SAFETY: the caller must uphold the safety contract for `atomic_umin`
|
||||
|
Loading…
Reference in New Issue
Block a user