Cranelift 128-bit atomics on AArch64: a Trifecta Tech walkthrough
Cranelift's Rust backend, rustc_codegen_cranelift, builds most Rust projects, but not the Rust standard library. Two patches are currently needed to compile it with Cranelift, because Cranelift does not yet support 128-bit atomics on all targets. The x86_64 backend has supported them since the end of 2024. AArch64 support was missing at the time, and an open issue asking for it has existed since mid-2025.
The post's author was tasked with adding that support to the AArch64 backend as one of their starter projects at Trifecta Tech, with the goal of finally getting rid of the standard-library patches. The post is a walkthrough of how that work goes, aimed at readers who already know atomic operations and memory orderings. It recommends Mara's book Rust Atomics and Locks as an introduction.
The author starts with the hardware. ARM's Architecture Reference Manual is a 124MB PDF with over 17,000 pages; the author refers to version M.d from September 2026. The base AArch64 instruction set has the pairs ldar/stlr (64-bit) and ldaxp/stlxp (128-bit) for atomic loads and stores, with acquire/release semantics. Four operations need implementing: load, store, compare-and-swap (CAS) and read-modify-write (RMW). Loads and stores are straightforward. CAS and RMW are harder, because the ARMv8.0 baseline has no single instruction for them. ARMv8.1 added the Large System Extensions (LSE) for 64-bit atomics, and ARMv9.3 added LSE128 with limited 128-bit support. Cranelift cannot rely on either, since they are not part of the target baseline. Better code could be generated when the features are enabled, but any 128-bit support at all needs the less optimal fallbacks.
There is a second constraint. Cranelift is written first and foremost for wasmtime, a WebAssembly runtime, and WebAssembly requires sequentially consistent ordering for atomic memory accesses. ARM atomic loads only have acquire semantics and stores only release semantics, so every operation the author implements has to be built to be sequentially consistent.
To see what to emit, the author looks at LLVM through Compiler Explorer, using -Ctarget-feature=-outline-atomics. That flag forces LLVM to inline the atomics; without it LLVM emits calls to helpers that check at run time whether LSE is available. LLVM's 128-bit add (add_u128) is a loop in four steps: an exclusive load with ldaxp, the computation (adds, adc), an exclusive store with stlxp, and a branch back with cbnz if the store failed. A store fails if another store hit the address in the meantime, and the retry loop gives sequential consistency. This is the common pattern for all RMW operations. LLVM's sequentially consistent 128-bit load (load_u128) is the same loop with no computation: it does ldaxp and then tries to store the loaded value straight back with stlxp, retrying on failure. Because both instructions use the ARM exclusive monitor, this establishes a single total modification order with other sequentially consistent atomics. The author's aim is for Cranelift to emit the same instructions as LLVM.
The rest of the post, as far as it goes, implements the 128-bit atomic load in cranelift/codegen/, inside the wasmtime monorepo. The other operations are described as quite similar, only needing slightly more complex instruction sequences. To find where atomics are wired up, the author searched the tree with fd atomic and found AArch64 filetests such as atomic_load.clif and atomic-rmw.clif. These tests give the function in CLIF (Cranelift's intermediate representation), then the expected VCode and disassembly. The 64-bit load expects a single ldar x0, [x0]. Adding an atomic_load.i128 function and running the filetest fails with: Unsupported feature: should be implemented in ISLE.
Searching src/isa/aarch64/ for atomic_load leads to lower.isle, around line 2385. A rule there rewrites atomic_load to load_acquire when the type is a valid atomic transaction. ISLE, short for Instruction Selection Lowering Expressions, is a LISP-flavored DSL for term rewriting. The load_acquire helper in inst.isle allocates a destination register and emits the MInst.LoadAcquire instruction, which handles 8, 16, 32 or 64 bits with one destination register. That cannot return a 128-bit value in general-purpose registers, which needs two.
So the author adds a new instruction, LoadAcquire128, with fields rt1 and rt2 (the lower and upper halves of the result), rn (the address), flags, and a scratch register. The scratch register holds the success status of the store in the exclusive load-store loop; its value before and after the instruction has no meaning. The author then begins a load_acquire_128 helper that allocates two 64-bit destination registers and a scratch register. The text available ends partway through that helper.
Key facts
- Two patches are currently needed to compile the Rust standard library with Cranelift, because Cranelift lacks 128-bit atomics on all targets; the post's work aims to remove them.
- x86_64 has supported 128-bit atomics in Cranelift since the end of 2024; AArch64 had an open issue since mid-2025.
- LSE (ARMv8.1) and LSE128 (ARMv9.3) are not in the target baseline, so Cranelift must use exclusive load/store loops (ldaxp/stlxp) as fallbacks.
- WebAssembly requires sequentially consistent atomics, so each operation must be sequentially consistent even though ARM loads are acquire-only and stores release-only.
- The author mirrors LLVM's output and adds a new LoadAcquire128 instruction with two destination registers and a scratch register for the 128-bit load.
Why it matters
The Rust standard library is described as perhaps the most prominent project rustc_codegen_cranelift cannot currently compile. Two patches stand in the way, and both exist because Cranelift lacks 128-bit atomics on all targets. Adding AArch64 support is the stated route to dropping them. The post also shows how a compiler backend squares ARM's acquire/release instructions with WebAssembly's demand for sequential consistency.
Who it affects
Mainly people who work on or use Cranelift, rustc_codegen_cranelift and wasmtime, and anyone who wants to build the Rust standard library with Cranelift on AArch64. Readers learning how Cranelift lowers instructions through ISLE also get a worked starting point.
How to use it
The post is a tutorial for contributors. It suggests finding where a feature is wired up by making it fail: add a CLIF filetest for atomic_load.i128 in the AArch64 filetests, run it with cargo run -p cranelift-tools -- test, and follow the error to the ISLE rules in lower.isle and inst.isle. It also recommends Compiler Explorer, with -Ctarget-feature=-outline-atomics, to see the inline assembly LLVM emits, and the ARM Architecture Reference Manual when defining new instructions.
How solid is it
This is a first-person engineering write-up from Trifecta Tech, and the examples (LLVM assembly, filetest output, ISLE snippets) are shown in the post. The available text is cut off partway through the 128-bit atomic load. The final code, the store, CAS and RMW implementations, any results and whether the patches were actually removed are not visible.
Risks and caveats
The fallbacks are less optimal than code that could use LSE or LSE128, which the baseline target cannot assume. The load implementation described, like LLVM's, uses a store-back loop, so it is more than a plain load. No performance numbers are given, and no merge status or release version for the work is stated. The author also says they skipped the ISLE introduction when starting, so the post covers only the parts of ISLE needed here.
“Ideally, we'll make Cranelift emit the same instructions as LLVM.”
— Trifecta Tech blog post on 128-bit atomics in Cranelift