diff options
author | 2020-08-31 21:08:05 +0000 | |
---|---|---|
committer | 2020-08-31 21:08:05 +0000 | |
commit | b05a24e6b31e039e059760a4245b378df008faf8 (patch) | |
tree | 50a7ce8ead7bb9ef1f34216e8934988572d442a8 /src/call_asm.rs | |
parent | 3260e397647b5ea4984e8c82cb537f2475da0f5d (diff) | |
parent | c27c8e5b063bd7058ba05dc3a9fa7886a1b1545c (diff) | |
download | cortex-m-b05a24e6b31e039e059760a4245b378df008faf8.tar.gz cortex-m-b05a24e6b31e039e059760a4245b378df008faf8.tar.zst cortex-m-b05a24e6b31e039e059760a4245b378df008faf8.zip |
Merge #262
262: Merge asm implementations r=therealprof a=jonas-schievink
This replaces the implementation of `inline-asm` with the file I wrote in #259 (and some fixes).
All functions that call assembly now do so via a `call_asm!` macro that either dispatches to a call to an `#[inline(always)]` function containing the inline `asm!`, or to the FFI shim. This makes all functions that call into asm significantly shorter.
The FFI shim is now also macro-generated, which makes it very small.
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Diffstat (limited to 'src/call_asm.rs')
-rw-r--r-- | src/call_asm.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/call_asm.rs b/src/call_asm.rs new file mode 100644 index 0000000..295277f --- /dev/null +++ b/src/call_asm.rs @@ -0,0 +1,24 @@ +/// An internal macro to invoke an assembly routine. +/// +/// Depending on whether the unstable `inline-asm` feature is enabled, this will either call into +/// the inline assembly implementation directly, or through the FFI shim (see `asm/lib.rs`). +macro_rules! call_asm { + ( $func:ident ( $($args:ident: $tys:ty),* ) $(-> $ret:ty)? ) => {{ + #[allow(unused_unsafe)] + unsafe { + match () { + #[cfg(feature = "inline-asm")] + () => crate::asm::inline::$func($($args),*), + + #[cfg(not(feature = "inline-asm"))] + () => { + extern "C" { + fn $func($($args: $tys),*) $(-> $ret)?; + } + + $func($($args),*) + }, + } + } + }}; +} |