diff --git a/Cargo.toml b/Cargo.toml index 301956c..896eecf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ branch = "dma" [features] semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] bkpt = [ ] -nightly = ["cortex-m/inline-asm"] +nightly = ["cortex-m/inline-asm", "dsp/nightly"] [profile.dev] codegen-units = 1 diff --git a/dsp/Cargo.toml b/dsp/Cargo.toml index 625d0f0..c8ef52b 100644 --- a/dsp/Cargo.toml +++ b/dsp/Cargo.toml @@ -6,3 +6,6 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"], default-features = false } + +[features] +nightly = [] diff --git a/dsp/src/iir.rs b/dsp/src/iir.rs index 04d7c8e..e081556 100644 --- a/dsp/src/iir.rs +++ b/dsp/src/iir.rs @@ -24,6 +24,7 @@ fn copysign(x: f32, y: f32) -> f32 { } } +#[cfg(not(feature = "nightly"))] fn max(x: f32, y: f32) -> f32 { if x > y { x @@ -32,6 +33,7 @@ fn max(x: f32, y: f32) -> f32 { } } +#[cfg(not(feature = "nightly"))] fn min(x: f32, y: f32) -> f32 { if x < y { x @@ -40,6 +42,31 @@ fn min(x: f32, y: f32) -> f32 { } } +#[cfg(feature = "nightly")] +fn max(x: f32, y: f32) -> f32 { + let o: f32; + unsafe { + asm!("vmaxnm.f32 {}, {}, {}", + lateout(sreg) o, in(sreg) x, in(sreg) y, + options(pure, nomem, nostack, preserves_flags) + ); + } + o +} + +#[cfg(feature = "nightly")] +fn min(x: f32, y: f32) -> f32 { + let o: f32; + unsafe { + asm!("vminnm.f32 {}, {}, {}", + lateout(sreg) o, in(sreg) x, in(sreg) y, + options(pure, nomem, nostack, preserves_flags) + ); + } + o +} + + // Multiply-accumulate vectors `x` and `a`. // // A.k.a. dot product. diff --git a/dsp/src/lib.rs b/dsp/src/lib.rs index 3c44bbc..ac25d1e 100644 --- a/dsp/src/lib.rs +++ b/dsp/src/lib.rs @@ -1,3 +1,4 @@ #![no_std] +#![cfg_attr(feature = "nightly", feature(asm))] pub mod iir; diff --git a/src/main.rs b/src/main.rs index 3173158..15046b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,9 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { let gpiod = unsafe { &*hal::stm32::GPIOD::ptr() }; gpiod.odr.modify(|_, w| w.odr6().high().odr12().high()); // FP_LED_1, FP_LED_3 + #[cfg(feature = "nightly")] + core::intrinsics::abort(); + #[cfg(not(feature = "nightly"))] unsafe { core::intrinsics::abort(); }