Try   HackMD

Bridging ARM64 Inline Assembly

Problem statement

We have a huge repository of atomic operations backed by inline assembly code which resides in the vanilla C side. It is constructed with an elaborate macro infrastructure that has evolved over several years into various flavours of API or code expansion.

Today, the kernel crate invokes the atomic operations by materialising the macros and static inlines in rust/helpers, so that the kernel crate can link into.

Unfortunately this also comes with a foreseeable and observable comparative disadvantage in performance. One possible solution that has been floating around is to translate the inline assembly blocks, through compiler infrastructure, into Rust inline assembly, so that kernel crate can "inline" the atomics for a performance boost. This document is a proposal to realise the pre-requisites of this experiment and performance benchmarking on the Rust kernel modules.

Design principles

I would propose the following guidelines in search of solutions.

Least course of change on vanilla kernel C code

At this point, we should still view assembly snippets as the golden reference. We aim for minimal editing of these snippets.

Ease of maintanence

On the side of Rust ecosystem, we should strive for least amount of maintenance in tools.

Assumptions

No "crazy" use of inline assembly in the kernel

There is a repository of possible inline assembly features supported by Clang located at clang/test/CodeGen/AArch64/inline-asm.c.

However, we have done our survey on exact features that kernel rely on. We can assume we will only support those features.

Simple structure of a unit of inline assembly

As discovered in the survey, most inline assembly blocks have been enclosed in static inlines or statement like macros, aka. do-while style macros.

Proposed changes

Enhancement in libclang and clang-sys

Enhancement in