Skip to content

Conversation

@tgross35
Copy link
Contributor

@tgross35 tgross35 commented Aug 5, 2025

The baseline Armv8.0 ISA doesn't have atomics instructions, but in
practice most hardware is at least Armv8.1-A (2014), which includes
single-instruction atomics as part of the LSE feature. As a performance
optimization for these cases, GCC and LLVM have the -moutline-atomics flag
to turn atomic operations into calls to symbols like __aarch64_cas1_acq.
These can do runtime feature detection and use the LSE instructions if
available, falling back to more portable load-exclusive/store-exclusive
loops.

Since the recent 3b50253 ("compiler-builtins: plumb LSE support
for aarch64 on linux") our builtins support this LSE optimization, and
since 6936bb9 ("Dynamically enable LSE for aarch64 rust provided
intrinsics"), std will set the flag as part of its startup code. The first
commit in this PR configures this to work on all platforms built with
outline-atomics, not just Linux.

Thus, enable outline-atomics by default on Android, OpenBSD, Windows,
and Fuchsia platforms that don't have LSE in the baseline. The feature is
already enabled on Linux. Platform-specific details are included in each
commit message.

The current implementation can still be accessed by setting
-Ctarget-feature=-outline-atomics. Setting -Ctarget-feature=+lse or
a relevant CPU will use the single-instruction atomics without the call
overhead. https://rust.godbolt.org/z/dsdrzszoe

Link: https://learn.arm.com/learning-paths/servers-and-cloud-computing/lse/intro/
Original Clang outline-atomics benchmarks: https://reviews.llvm.org/D91157#2435844

try-job: aarch64-msvc-*
try-job: arm-android
try-job: dist-android
try-job: dist-aarch64-llvm-mingw
try-job: dist-aarch64-msvc
try-job: dist-various-*
try-job: test-various

@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2025

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 5, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 5, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

@tgross35
Copy link
Contributor Author

tgross35 commented Aug 5, 2025

Whoops

r? @ghost

@tgross35 tgross35 marked this pull request as draft August 5, 2025 02:30
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 5, 2025
@tgross35

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Aug 5, 2025
[experiment] enable outline-atomics on more aarch64 platforms

try-job: arm-android
try-job: dist-android
try-job: dist-x86_64-freebsd
try-job: dist-aarch64-windows-gnullvm
try-job: dist-aarch64-apple
try-job: aarch64-msvc-1
try-job: aarch64-msvc-2
try-job: dist-aarch64-msvc
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@tgross35

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

rust-bors bot added a commit that referenced this pull request Aug 5, 2025
[experiment] enable outline-atomics on more aarch64 platforms

try-job: arm-android
try-job: dist-android
try-job: dist-x86_64-freebsd
try-job: dist-aarch64-windows-gnullvm
try-job: dist-aarch64-apple
try-job: aarch64-msvc-1
try-job: aarch64-msvc-2
try-job: dist-aarch64-msvc
@rust-bors

This comment was marked as outdated.

@bors

This comment was marked as outdated.

@tgross35 tgross35 force-pushed the more-outline-atomics branch from a25e101 to e20add7 Compare September 5, 2025 19:39
@tgross35 tgross35 changed the title [experiment] enable outline-atomics on more aarch64 platforms Enable outline-atomics by default on more aarch64 platforms Sep 5, 2025
@tgross35

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 5, 2025
Enable outline-atomics by default on more aarch64 platforms

try-job: aarch64-apple
try-job: aarch64-msvc-1
try-job: aarch64-msvc-2
try-job: arm-android
try-job: dist-android
try-job: dist-aarch64-windows-gnullvm
try-job: dist-aarch64-apple
try-job: dist-aarch64-msvc
try-job: dist-various
try-job: dist-x86_64-freebsd
@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment was marked as outdated.

Windows has a similar flag `/forceInterlockedFunctions`, which uses
names such as `_InterlockedAdd64_rel`.
Per LLVM commit c5e7e64 ("[AArch64][Clang][Linux] Enable
out-of-line atomics by default.") [1], Clang enables these on Android.
Thus, do the same in Rust.

[1]: llvm/llvm-project@c5e7e649d537067de
Clang has done this by default since LLVM commit 1a963d3 ("[Driver]
Make -moutline-atomics default for aarch64-fuchsia targets"), [1], so do
the same here.

[1]: llvm/llvm-project@1a963d3
Clang has recently started doing this, as of LLVM commit 5d774ec8d183
("[Driver] Enable outline atomics for OpenBSD/aarch64") [1]. Thus, do
the same here.

[1]: llvm/llvm-project@5d774ec
@tgross35
Copy link
Contributor Author

tgross35 commented Dec 4, 2025

@bors2 try

rust-bors bot added a commit that referenced this pull request Dec 4, 2025
Enable `outline-atomics` by default on more AArch64 platforms

try-job: aarch64-msvc-*
try-job: arm-android
try-job: dist-android
try-job: dist-aarch64-windows-gnullvm
try-job: dist-aarch64-msvc
try-job: dist-various-*
try-job: test-various
@rust-bors

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment was marked as outdated.

@tgross35
Copy link
Contributor Author

tgross35 commented Dec 4, 2025

Finally got a chance to circle back here. I split FreeBSD to a separate PR #149633, and dropped the Apple with an open issue #149634. For everything else here, the target maintainers have said this should be okay either on this PR or on Zulip.

@rustbot ready

@tgross35
Copy link
Contributor Author

tgross35 commented Dec 4, 2025

@bors2 try

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Dec 4, 2025
Enable `outline-atomics` by default on more AArch64 platforms

try-job: aarch64-msvc-*
try-job: arm-android
try-job: dist-android
try-job: dist-aarch64-llvm-mingw
try-job: dist-aarch64-msvc
try-job: dist-various-*
try-job: test-various
@rust-bors
Copy link

rust-bors bot commented Dec 4, 2025

☀️ Try build successful (CI)
Build commit: 73cd8c5 (73cd8c5953271a06db9935692296d56895fd742b, parent: 556beb9ec72360512d0294eb0855c92fb2c20c88)

@davidtwco
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 9, 2025

📌 Commit 66c150c has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 9, 2025
bors added a commit that referenced this pull request Dec 9, 2025
Rollup of 5 pull requests

Successful merges:

 - #144938 (Enable `outline-atomics` by default on more AArch64 platforms)
 - #146579 (Handle macro invocation in attribute during parse)
 - #149400 (unstable proc_macro tracked::* rename/restructure)
 - #149664 (attempt to fix unreachable code regression )
 - #149806 (Mirror `ubuntu:24.04` on ghcr)

Failed merges:

 - #149789 (Cleanup in the attribute parsers)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Dec 9, 2025
Rollup of 5 pull requests

Successful merges:

 - #144938 (Enable `outline-atomics` by default on more AArch64 platforms)
 - #146579 (Handle macro invocation in attribute during parse)
 - #149400 (unstable proc_macro tracked::* rename/restructure)
 - #149664 (attempt to fix unreachable code regression )
 - #149806 (Mirror `ubuntu:24.04` on ghcr)

Failed merges:

 - #149789 (Cleanup in the attribute parsers)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7637023 into rust-lang:main Dec 10, 2025
12 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 10, 2025
rust-timer added a commit that referenced this pull request Dec 10, 2025
Rollup merge of #144938 - tgross35:more-outline-atomics, r=davidtwco

Enable `outline-atomics` by default on more AArch64 platforms

The baseline Armv8.0 ISA doesn't have atomics instructions, but in
practice most hardware is at least Armv8.1-A (2014), which includes
single-instruction atomics as part of the LSE feature. As a performance
optimization for these cases, GCC and LLVM have the `-moutline-atomics` flag
to turn atomic operations into calls to symbols like `__aarch64_cas1_acq`.
These can do runtime feature detection and use the LSE instructions if
available, falling back to more portable load-exclusive/store-exclusive
loops.

Since the recent 3b50253 ("compiler-builtins: plumb LSE support
for aarch64 on linux") our builtins support this LSE optimization, and
since 6936bb9 ("Dynamically enable LSE for aarch64 rust provided
intrinsics"), std will set the flag as part of its startup code. The first
commit in this PR configures this to work on all platforms built with
`outline-atomics`, not just Linux.

Thus, enable `outline-atomics` by default on Android, OpenBSD, Windows,
and Fuchsia platforms that don't have LSE in the baseline. The feature is
already enabled on Linux. Platform-specific details are included in each
commit message.

The current implementation can still be accessed by setting
`-Ctarget-feature=-outline-atomics`. Setting `-Ctarget-feature=+lse` or
a relevant CPU will use the single-instruction atomics without the call
overhead. https://rust.godbolt.org/z/dsdrzszoe

Link: https://learn.arm.com/learning-paths/servers-and-cloud-computing/lse/intro/
Original Clang outline-atomics benchmarks: https://reviews.llvm.org/D91157#2435844

try-job: aarch64-msvc-*
try-job: arm-android
try-job: dist-android
try-job: dist-aarch64-llvm-mingw
try-job: dist-aarch64-msvc
try-job: dist-various-*
try-job: test-various
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Dec 11, 2025
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#144938 (Enable `outline-atomics` by default on more AArch64 platforms)
 - rust-lang/rust#146579 (Handle macro invocation in attribute during parse)
 - rust-lang/rust#149400 (unstable proc_macro tracked::* rename/restructure)
 - rust-lang/rust#149664 (attempt to fix unreachable code regression )
 - rust-lang/rust#149806 (Mirror `ubuntu:24.04` on ghcr)

Failed merges:

 - rust-lang/rust#149789 (Cleanup in the attribute parsers)

r? `@ghost`
`@rustbot` modify labels: rollup
@tgross35 tgross35 deleted the more-outline-atomics branch December 11, 2025 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants