Description
Triage(2018-08-21)
A pre-RFC discussing what should go in core::arch::arm
have been opened in #184
Update - 2018-07-27
Intrinsics like __NOP
are now available in core::arch::arm
. Path towards stabilization is being discussed in rust-lang/stdarch#518 (comment).
Help wanted
We are looking for someone / people to help us write an RFC on stabilization of the ARM Cortex intrinsics in core::arch::arm. Details in #63 (comment).
One of the features that ties embedded development to the nightly channel is the asm!
macro, and
by extension the global_asm!
macro.
In some cases it's possible to turn an unstable asm!
call into a stable FFI call that invokes some
subroutine that comes from a pre-compiled external assembly file. This alternative comes at the cost
of a function call overhead per asm!
invocation.
In other cases the function call overhead of the FFI call breaks the intended semantics of the
original asm!
call; this can be seen when reading registers like the Program Counter (PC) or the
Link Register (LR).
The asm!
feature is hard to stabilize because it's directly tied to LLVM; rustc
literally passes
the contents of asm!
invocations to LLVM's internal assembler. It's not possible to guarantee that
the syntax of LLVM assembly won't change across LLVM releases so stabilizing the asm!
feature in
its current form is not possible.
This ticket is about exploring making operations that require assembly available on the stable
channel. This proposal is not about stabilizing the asm!
macro itself.
The main idea is that everything that requires assembly and can be implemented as external assembly
files should use that approach. For everything that requires inlining the assembly operation the
proposal is that the core
crate will provide such functionality.
This idea is not unlike what's currently being done in stdsimd land: core::arch
provides
functions that are thin wrappers around unstable LLVM intrinsics that provide SIMD functionality.
Similarly core::asm
(module up for bikeshedding) would provide functionality that requires asm!
but in a stable fashion. Example below:
mod asm {
mod arm {
#[inline(always)]
#[stable]
pub fn pc() -> u32 {
let r;
unsafe { asm!("mov $0,R15" : "=r"(r) ::: "volatile") }
r
}
#[inline(always)]
#[stable]
pub fn lr() -> u32 {
let r;
unsafe { asm!("mov $0,R14" : "=r"(r) ::: "volatile") }
r
}
}
}
This way the functionality can be preserved across LLVM upgrades; the maintainers of the core
crate would update the implementation to match the current LLVM assembly syntax.
TODO (outdated)
- Come up with a list of assembly operations that are used in practice and that would need to be
provided incore::asm
.- I would appreciate some help making a Proof of Concept PR against
cortex-m
that moves
most of the assembly operations to external assembly files by enabling some Cargo feature. What can't be moved to assembly files would be a candidate for inclusion incore::asm
. - AVR
- MSP430
- RISCV
- I would appreciate some help making a Proof of Concept PR against
- The team will bring up this idea to the lang / compiler team during the Rust All Hands event.
cc @gnzlbg @nagisa could we get your thoughts on this? does this sound feasible, or does this sound
like a bad idea?
cc @dvc94ch @dylanmckay @pftbest could you help me identify assembly operations that require inline assemly on AVR, MSP430 and RICSV?