Skip to content

Rustc pull update #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c88c38b
Auto merge of #143641 - Kobzol:tool-target, r=jieyouxu
bors Jul 19, 2025
c94ed1e
Auto merge of #144154 - tgross35:update-builtins, r=tgross35
bors Jul 21, 2025
d125acf
Auto merge of #144205 - hkBst:flt2dec, r=workingjubilee
bors Jul 22, 2025
981ec71
Auto merge of #144222 - Kobzol:stdarch-push, r=folkertdev
bors Jul 22, 2025
0c8e067
Auto merge of #143897 - cjgillot:derive-walk, r=petrochenkov
bors Jul 23, 2025
196c053
Auto merge of #144233 - cjgillot:unsat-mir, r=oli-obk
bors Jul 23, 2025
36f02db
Auto merge of #144244 - jieyouxu:pr-full-ci, r=Kobzol
bors Jul 23, 2025
f1648f3
Auto merge of #144062 - bjorn3:lto_refactors2, r=davidtwco
bors Jul 24, 2025
c8401cc
Auto merge of #139597 - Kobzol:lint-skip, r=BoxyUwU
bors Jul 26, 2025
c7bc965
Auto merge of #143500 - compiler-errors:characterize-less, r=lcnr
bors Jul 26, 2025
f231c42
Auto merge of #144425 - nnethercote:avoid-new_adt-new_fn_def, r=compi…
bors Jul 27, 2025
f927473
Auto merge of #144434 - nnethercote:preintern-ty-bounds, r=compiler-e…
bors Jul 27, 2025
fe1b064
Auto merge of #144305 - ChrisDenton:win-free-disk-space, r=marcoieni
bors Jul 30, 2025
75ac146
compiler-builtins: plumb LSE support for aarch64 on linux
pmur Aug 4, 2025
d13b257
Rollup merge of #144705 - pmur:murp/aarch64-lse, r=Amanieu
tgross35 Aug 8, 2025
610309e
Rollup merge of #144857 - scrabsha:push-pwtyrnmqkrtr, r=jdonszelmann
tgross35 Aug 8, 2025
1a5aef4
Rollup merge of #144900 - Kivooeo:unsigned_signed_diff-stabilize, r=d…
tgross35 Aug 8, 2025
e0d7f95
Rollup merge of #144903 - Kivooeo:panic_handler-is-not-begin, r=m-ou-se
tgross35 Aug 8, 2025
10ab694
Rollup merge of #144974 - tgross35:update-builtins, r=tgross35
tgross35 Aug 8, 2025
db75b10
Rollup merge of #145007 - Kobzol:error-index, r=jieyouxu
tgross35 Aug 8, 2025
1bb3ac1
Rollup merge of #145018 - AlexanderPortland:rustc-public-hash, r=scot…
tgross35 Aug 8, 2025
7203189
Rollup merge of #145045 - Hywan:doc-library-iterator-by_ref, r=Guilla…
tgross35 Aug 8, 2025
45e6499
Rollup merge of #145046 - ulrichstark:master, r=tgross35
tgross35 Aug 8, 2025
e8ff6dc
Auto merge of #145074 - tgross35:rollup-0tillrm, r=tgross35
bors Aug 8, 2025
2f31646
Auto merge of #145077 - Zalathar:rollup-0k4194x, r=Zalathar
bors Aug 8, 2025
98d1580
Prepare for merging from rust-lang/rust
invalid-email-address Aug 9, 2025
dbe26bd
Merge ref 'ffb9d94dcf4a' from rust-lang/rust
invalid-email-address Aug 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 66 additions & 10 deletions compiler-builtins/src/aarch64_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
//! which is supported on the current CPU.
//! See <https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/making-the-most-of-the-arm-architecture-in-gcc-10#:~:text=out%20of%20line%20atomics> for more discussion.
//!
//! Currently we only support LL/SC, because LSE requires `getauxval` from libc in order to do runtime detection.
//! Use the `compiler-rt` intrinsics if you want LSE support.
//!
//! Ported from `aarch64/lse.S` in LLVM's compiler-rt.
//!
//! Generate functions for each of the following symbols:
Expand All @@ -24,7 +21,18 @@
//! We do something similar, but with macro arguments.
#![cfg_attr(feature = "c", allow(unused_macros))] // avoid putting the macros into a submodule

// We don't do runtime dispatch so we don't have to worry about the `__aarch64_have_lse_atomics` global ctor.
use core::sync::atomic::{AtomicU8, Ordering};

/// non-zero if the host supports LSE atomics.
static HAVE_LSE_ATOMICS: AtomicU8 = AtomicU8::new(0);

intrinsics! {
/// Call to enable LSE in outline atomic operations. The caller must verify
/// LSE operations are supported.
pub extern "C" fn __rust_enable_lse() {
HAVE_LSE_ATOMICS.store(1, Ordering::Relaxed);
}
}

/// Translate a byte size to a Rust type.
#[rustfmt::skip]
Expand All @@ -45,6 +53,7 @@ macro_rules! reg {
(2, $num:literal) => { concat!("w", $num) };
(4, $num:literal) => { concat!("w", $num) };
(8, $num:literal) => { concat!("x", $num) };
(16, $num:literal) => { concat!("x", $num) };
}

/// Given an atomic ordering, translate it to the acquire suffix for the lxdr aarch64 ASM instruction.
Expand Down Expand Up @@ -126,6 +135,41 @@ macro_rules! stxp {
};
}

// If supported, perform the requested LSE op and return, or fallthrough.
macro_rules! try_lse_op {
($op: literal, $ordering:ident, $bytes:tt, $($reg:literal,)* [ $mem:ident ] ) => {
concat!(
".arch_extension lse; ",
"adrp x16, {have_lse}; ",
"ldrb w16, [x16, :lo12:{have_lse}]; ",
"cbz w16, 8f; ",
// LSE_OP s(reg),* [$mem]
concat!(lse!($op, $ordering, $bytes), $( " ", reg!($bytes, $reg), ", " ,)* "[", stringify!($mem), "]; ",),
"ret; ",
"8:"
)
};
}

// Translate memory ordering to the LSE suffix
#[rustfmt::skip]
macro_rules! lse_mem_sfx {
(Relaxed) => { "" };
(Acquire) => { "a" };
(Release) => { "l" };
(AcqRel) => { "al" };
}

// Generate the aarch64 LSE operation for memory ordering and width
macro_rules! lse {
($op:literal, $order:ident, 16) => {
concat!($op, "p", lse_mem_sfx!($order))
};
($op:literal, $order:ident, $bytes:tt) => {
concat!($op, lse_mem_sfx!($order), size!($bytes))
};
}

/// See <https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicI8.html#method.compare_and_swap>.
macro_rules! compare_and_swap {
($ordering:ident, $bytes:tt, $name:ident) => {
Expand All @@ -137,7 +181,9 @@ macro_rules! compare_and_swap {
) -> int_ty!($bytes) {
// We can't use `AtomicI8::compare_and_swap`; we *are* compare_and_swap.
core::arch::naked_asm! {
// UXT s(tmp0), s(0)
// CAS s(0), s(1), [x2]; if LSE supported.
try_lse_op!("cas", $ordering, $bytes, 0, 1, [x2]),
// UXT s(tmp0), s(0)
concat!(uxt!($bytes), " ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
"0:",
// LDXR s(0), [x2]
Expand All @@ -150,6 +196,7 @@ macro_rules! compare_and_swap {
"cbnz w17, 0b",
"1:",
"ret",
have_lse = sym crate::aarch64_linux::HAVE_LSE_ATOMICS,
}
}
}
Expand All @@ -166,6 +213,8 @@ macro_rules! compare_and_swap_i128 {
expected: i128, desired: i128, ptr: *mut i128
) -> i128 {
core::arch::naked_asm! {
// CASP x0, x1, x2, x3, [x4]; if LSE supported.
try_lse_op!("cas", $ordering, 16, 0, 1, 2, 3, [x4]),
"mov x16, x0",
"mov x17, x1",
"0:",
Expand All @@ -179,6 +228,7 @@ macro_rules! compare_and_swap_i128 {
"cbnz w15, 0b",
"1:",
"ret",
have_lse = sym crate::aarch64_linux::HAVE_LSE_ATOMICS,
}
}
}
Expand All @@ -195,6 +245,8 @@ macro_rules! swap {
left: int_ty!($bytes), right_ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
core::arch::naked_asm! {
// SWP s(0), s(0), [x1]; if LSE supported.
try_lse_op!("swp", $ordering, $bytes, 0, 0, [x1]),
// mov s(tmp0), s(0)
concat!("mov ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
"0:",
Expand All @@ -204,6 +256,7 @@ macro_rules! swap {
concat!(stxr!($ordering, $bytes), " w17, ", reg!($bytes, 16), ", [x1]"),
"cbnz w17, 0b",
"ret",
have_lse = sym crate::aarch64_linux::HAVE_LSE_ATOMICS,
}
}
}
Expand All @@ -212,14 +265,16 @@ macro_rules! swap {

/// See (e.g.) <https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicI8.html#method.fetch_add>.
macro_rules! fetch_op {
($ordering:ident, $bytes:tt, $name:ident, $op:literal) => {
($ordering:ident, $bytes:tt, $name:ident, $op:literal, $lse_op:literal) => {
intrinsics! {
#[maybe_use_optimized_c_shim]
#[unsafe(naked)]
pub unsafe extern "C" fn $name (
val: int_ty!($bytes), ptr: *mut int_ty!($bytes)
) -> int_ty!($bytes) {
core::arch::naked_asm! {
// LSEOP s(0), s(0), [x1]; if LSE supported.
try_lse_op!($lse_op, $ordering, $bytes, 0, 0, [x1]),
// mov s(tmp0), s(0)
concat!("mov ", reg!($bytes, 16), ", ", reg!($bytes, 0)),
"0:",
Expand All @@ -231,6 +286,7 @@ macro_rules! fetch_op {
concat!(stxr!($ordering, $bytes), " w15, ", reg!($bytes, 17), ", [x1]"),
"cbnz w15, 0b",
"ret",
have_lse = sym crate::aarch64_linux::HAVE_LSE_ATOMICS,
}
}
}
Expand All @@ -240,25 +296,25 @@ macro_rules! fetch_op {
// We need a single macro to pass to `foreach_ldadd`.
macro_rules! add {
($ordering:ident, $bytes:tt, $name:ident) => {
fetch_op! { $ordering, $bytes, $name, "add" }
fetch_op! { $ordering, $bytes, $name, "add", "ldadd" }
};
}

macro_rules! and {
($ordering:ident, $bytes:tt, $name:ident) => {
fetch_op! { $ordering, $bytes, $name, "bic" }
fetch_op! { $ordering, $bytes, $name, "bic", "ldclr" }
};
}

macro_rules! xor {
($ordering:ident, $bytes:tt, $name:ident) => {
fetch_op! { $ordering, $bytes, $name, "eor" }
fetch_op! { $ordering, $bytes, $name, "eor", "ldeor" }
};
}

macro_rules! or {
($ordering:ident, $bytes:tt, $name:ident) => {
fetch_op! { $ordering, $bytes, $name, "orr" }
fetch_op! { $ordering, $bytes, $name, "orr", "ldset" }
};
}

Expand Down
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
82310651b93a594a3fd69015e1562186a080d94c
ffb9d94dcf4ade0d534842be3672d5e9f47e1333
Loading