| 1 |
// SPDX-License-Identifier: Apache-2.0 OR MIT |
| 2 |
// This file is @generated by target_spec.sh. |
| 3 |
// It is not intended for manual editing. |
| 4 |
|
| 5 |
#![allow(dead_code, unused_macros)] |
| 6 |
|
| 7 |
// On AArch64, the base register of memory-related instructions must be 64-bit. |
| 8 |
// Passing a 32-bit value to `in(reg)` on AArch64 results in the upper bits |
| 9 |
// having an undefined value, but to work correctly with ILP32 ABI, the upper |
| 10 |
// bits must be zero, which is handled here by casting to u64. Another way to |
| 11 |
// handle this is to pass it as a pointer and clear the upper bits inside asm, |
| 12 |
// but it is easier to overlook than cast, which can catch overlooks by |
| 13 |
// asm_sub_register lint. |
| 14 |
// See also https://github.com/ARM-software/abi-aa/blob/2025Q4/aapcs64/aapcs64.rst#pointers |
| 15 |
// |
| 16 |
// Except for x86_64, which can use 32-bit registers in the destination operand |
| 17 |
// (on x86_64, we use the ptr_modifier macro to handle this), we need to do the |
| 18 |
// same for ILP32 ABI on other 64-bit architectures. (At least, as far as I can |
| 19 |
// see from the assembly generated by LLVM, this is also required for MIPS64 N32 |
| 20 |
// ABI. I don't know about other similar ABIs, but in any case, this should be |
| 21 |
// a safe default for such ABIs). |
| 22 |
// |
| 23 |
// Known architectures that have such ABI are x86_64 (X32), AArch64 (ILP32), |
| 24 |
// mips64/mips64r6 (N32), riscv64 (RV64ILP32*), PowerPC64 (Lv2). (As of |
| 25 |
// 2026-03-22, only the former two are supported by rustc.) However, we list |
| 26 |
// all known 64-bit architectures because similar ABIs may exist or future added |
| 27 |
// for other architectures. |
| 28 |
#[cfg(all( |
| 29 |
target_pointer_width = "32", |
| 30 |
any( |
| 31 |
target_arch = "aarch64", |
| 32 |
target_arch = "amdgpu", |
| 33 |
target_arch = "arm64ec", |
| 34 |
target_arch = "bpf", |
| 35 |
target_arch = "loongarch64", |
| 36 |
target_arch = "mips64", |
| 37 |
target_arch = "mips64r6", |
| 38 |
target_arch = "nvptx64", |
| 39 |
target_arch = "powerpc64", |
| 40 |
target_arch = "riscv64", |
| 41 |
target_arch = "s390x", |
| 42 |
target_arch = "sparc64", |
| 43 |
target_arch = "wasm64", |
| 44 |
target_arch = "x86_64", |
| 45 |
), |
| 46 |
))] |
| 47 |
#[macro_use] |
| 48 |
mod imp { |
| 49 |
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] |
| 50 |
macro_rules! ptr_reg { |
| 51 |
($ptr:ident) => {{ |
| 52 |
let _: *const _ = $ptr; // ensure $ptr is a pointer (*mut _ or *const _) |
| 53 |
#[cfg(not(portable_atomic_no_asm_maybe_uninit))] |
| 54 |
#[allow(clippy::ptr_as_ptr)] |
| 55 |
{ |
| 56 |
// If we cast to u64 here, the provenance will be lost, |
| 57 |
// so we convert to MaybeUninit<u64> via zero extend helper. |
| 58 |
crate::utils::zero_extend64_ptr($ptr as *mut ()) |
| 59 |
} |
| 60 |
#[cfg(portable_atomic_no_asm_maybe_uninit)] |
| 61 |
{ |
| 62 |
// Use cast on old rustc because it does not support MaybeUninit |
| 63 |
// registers. This is still permissive-provenance compatible and |
| 64 |
// is sound. |
| 65 |
$ptr as u64 |
| 66 |
} |
| 67 |
}}; |
| 68 |
} |
| 69 |
pub(crate) type RegISize = i64; |
| 70 |
pub(crate) type RegSize = u64; |
| 71 |
} |
| 72 |
#[cfg(not(all( |
| 73 |
target_pointer_width = "32", |
| 74 |
any( |
| 75 |
target_arch = "aarch64", |
| 76 |
target_arch = "amdgpu", |
| 77 |
target_arch = "arm64ec", |
| 78 |
target_arch = "bpf", |
| 79 |
target_arch = "loongarch64", |
| 80 |
target_arch = "mips64", |
| 81 |
target_arch = "mips64r6", |
| 82 |
target_arch = "nvptx64", |
| 83 |
target_arch = "powerpc64", |
| 84 |
target_arch = "riscv64", |
| 85 |
target_arch = "s390x", |
| 86 |
target_arch = "sparc64", |
| 87 |
target_arch = "wasm64", |
| 88 |
target_arch = "x86_64", |
| 89 |
), |
| 90 |
)))] |
| 91 |
#[macro_use] |
| 92 |
mod imp { |
| 93 |
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] |
| 94 |
macro_rules! ptr_reg { |
| 95 |
($ptr:ident) => {{ |
| 96 |
let _: *const _ = $ptr; // ensure $ptr is a pointer (*mut _ or *const _) |
| 97 |
$ptr // cast is unnecessary here. |
| 98 |
}}; |
| 99 |
} |
| 100 |
pub(crate) type RegISize = isize; |
| 101 |
pub(crate) type RegSize = usize; |
| 102 |
} |
| 103 |
pub(crate) use self::imp::{RegISize, RegSize}; |
| 104 |
|
| 105 |
// Some 64-bit architectures have ABI with 32-bit pointer width (e.g., x86_64 X32 ABI, |
| 106 |
// AArch64 ILP32 ABI, MIPS64 N32 ABI). On those targets, AtomicU64 is available |
| 107 |
// and fast, so use it to implement normal sequence lock. |
| 108 |
// |
| 109 |
// See ptr_reg macro for the reason why all known 64-bit architectures are listed. |
| 110 |
// |
| 111 |
// Note: These macros are cfg_*!({ }), not cfg_*! { }. |
| 112 |
// An extra brace is used in input to make contents rustfmt-able. |
| 113 |
#[cfg(any( |
| 114 |
not(any(target_pointer_width = "16", target_pointer_width = "32")), // i.e., 64-bit or greater |
| 115 |
target_arch = "aarch64", |
| 116 |
target_arch = "amdgpu", |
| 117 |
target_arch = "arm64ec", |
| 118 |
target_arch = "bpf", |
| 119 |
target_arch = "loongarch64", |
| 120 |
target_arch = "mips64", |
| 121 |
target_arch = "mips64r6", |
| 122 |
target_arch = "nvptx64", |
| 123 |
target_arch = "powerpc64", |
| 124 |
target_arch = "riscv64", |
| 125 |
target_arch = "s390x", |
| 126 |
target_arch = "sparc64", |
| 127 |
target_arch = "wasm64", |
| 128 |
target_arch = "x86_64", |
| 129 |
))] |
| 130 |
#[macro_use] |
| 131 |
mod fast_atomic_64_macros { |
| 132 |
macro_rules! cfg_has_fast_atomic_64 { |
| 133 |
({$($tt:tt)*}) => { |
| 134 |
$($tt)* |
| 135 |
}; |
| 136 |
} |
| 137 |
macro_rules! cfg_no_fast_atomic_64 { |
| 138 |
({$($tt:tt)*}) => {}; |
| 139 |
} |
| 140 |
} |
| 141 |
#[cfg(not(any( |
| 142 |
not(any(target_pointer_width = "16", target_pointer_width = "32")), // i.e., 64-bit or greater |
| 143 |
target_arch = "aarch64", |
| 144 |
target_arch = "amdgpu", |
| 145 |
target_arch = "arm64ec", |
| 146 |
target_arch = "bpf", |
| 147 |
target_arch = "loongarch64", |
| 148 |
target_arch = "mips64", |
| 149 |
target_arch = "mips64r6", |
| 150 |
target_arch = "nvptx64", |
| 151 |
target_arch = "powerpc64", |
| 152 |
target_arch = "riscv64", |
| 153 |
target_arch = "s390x", |
| 154 |
target_arch = "sparc64", |
| 155 |
target_arch = "wasm64", |
| 156 |
target_arch = "x86_64", |
| 157 |
)))] |
| 158 |
#[macro_use] |
| 159 |
mod fast_atomic_64_macros { |
| 160 |
macro_rules! cfg_has_fast_atomic_64 { |
| 161 |
({$($tt:tt)*}) => {}; |
| 162 |
} |
| 163 |
macro_rules! cfg_no_fast_atomic_64 { |
| 164 |
({$($tt:tt)*}) => { |
| 165 |
$($tt)* |
| 166 |
}; |
| 167 |
} |
| 168 |
} |