Skip to content

WIP: Rewrite AArch64 outlined atomic operations using asm! - #162830

Closed
pmur wants to merge 3 commits into
rust-lang:mainfrom
pmur:murp/aarch64-outline-asm
Closed

pmur wants to merge 3 commits into
rust-lang:mainfrom
pmur:murp/aarch64-outline-asm

Conversation

@pmur

@pmur pmur commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

I think this is what was suggested in rust-lang/compiler-builtins#1063, and maybe step towards resolving #151486.

The cas16 operations are the most complicated. This compiles into nearly identical machine code.

r? @taiki-e @tgross35

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 15, 2026
@rustbot

rustbot commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Error: Failed to set assignee to taiki-e: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@tgross35 tgross35 self-assigned this Sep 15, 2026
intrinsics! {
#[maybe_use_optimized_c_shim]
#[unsafe(naked)]
#[target_feature(enable = "lse")]

@folkertdev folkertdev Sep 15, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the record, as of recently, on LLVM 23, naked functions do actually support target features

But it looks like there are other reasons to prefer asm! here.

View changes since the review

@tgross35 tgross35 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, it's been on my todo list for a long time but I never got around to it. I know this is a WIP but when it's closer to done, could you post the before and after asm?

View changes since this review

intrinsics! {
#[maybe_use_optimized_c_shim]
#[unsafe(naked)]
#[target_feature(enable = "lse")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this enable lse before we know it's enabled? Since HAVE_LSE_ATOMICS hasn't been checked

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should use .arch_extension lse in the relevant block instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with making the change. Though, how would target_feature's behavior differ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, is that potentially gated by the active target configuration.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with making the change. Though, how would target_feature's behavior differ?

Not sure I'm understanding the question right but I believe that #[target_feature(enable = "lse")] can be thought of as saying "LSE is known to be enabled for this function, and it is unsound to call if that isn't the case". Since it means LLVM is allowed to use LSE for the whole function, whereas .arch_extension lse just keeps the assembler from rejecting LSE instructions in that single block without further requirements.

Probably not going to make a difference in codegen here but it's more accurate since HAVE_LSE_ATOMICS could be false.

@tgross35

Copy link
Copy Markdown
Member

Also when this is closer to ready it should ideally be filed against https://github.com/rust-lang/compiler-builtins, that testsuite still isn't run as part of r-l/r

The outlined atomics should follow the AAPCS64 calling conventions,
and allow usage of -Z branch-protection=bti.

We just need to be careful to avoid bad codegen. This generates
almost identical codegen with -C opt-level=1. Those differences
are entirely regalloc choices.
The in/inlateout register operands aren't entirely accurate (w vs x).
This annoys me, but it's the same register, and we cannot use a macro
inside that portion of asm!.
@pmur
pmur force-pushed the murp/aarch64-outline-asm branch from ddce59f to 982f137 Compare September 16, 2026 21:25
@pmur

pmur commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Moving this over to rust-lang/compiler-builtins#1321.

@pmur pmur closed this Sep 17, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 17, 2026
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) 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.

4 participants