NewsCrawler.org

Implementing 128-bit atomics in Cranelift

The author describes adding 128-bit atomic operations to the AArch64 (64-bit ARM) backend of Cranelift. Cranelift is the code generator used by wasmtime, a WebAssembly runtime. The work is needed because rustc_codegen_cranelift still cannot compile the Rust standard library: two patches are required, since AArch64 lacks 128-bit atomics while x86_64 has supported them since the end of 2024.

On 64-bit ARM, the base instruction set has ldaxp and stlxp for 128-bit exclusive loads and stores, but compare-and-swap and read-modify-write need loops, because ARMv8.0 has no single instruction for them. The Large System Extensions (LSE[1]) from ARMv8.1 and LSE128 from ARMv9.3 are not part of the target baseline, so the author uses less optimal fallbacks. WebAssembly requires sequentially consistent ordering[2], so every operation must be implemented that way.

To see the target instruction sequences, the author compiles Rust snippets in Compiler Explorer with -Ctarget-feature=-outline-atomics, so LLVM inlines the operations instead of calling helper functions. The implementation starts with the 128-bit atomic load in Cranelift's test files, which are written in CLIF[3], Cranelift's intermediate representation. Running the existing test with a 128-bit atomic load produces an error, and that is where the author's work begins.

Read the original trifectatech.orgDiscussion

Discussion

One commenter asks why x86 needed a dedicated 128-bit instruction, given that using 128-bit compare-and-swap for simple reads already added overhead. Another asks about the current status of rustc_codegen_cranelift and whether its goal of fast builds with good-enough runtime performance has been reached, and a third says the ISLE change in Cranelift keeps paying off. One reader asks why the blog uses a font weight of 300, which they disable in the inspector each time.

Sources

Published: First seen: Читать по-русски

Open as a page