rp: hook up softfloat rom intrinsics

rp-hal has done this very well already, so we'll just copy their entire
impl again. only div.rs needed some massaging because our sio access
works a little differently, everything else worked as is.
This commit is contained in:
pennae
2023-04-19 01:57:37 +02:00
parent a673b9aa29
commit fdd6e08ed6
11 changed files with 1108 additions and 3 deletions

View File

@ -1,6 +1,8 @@
[unstable]
build-std = ["core"]
build-std-features = ["panic_immediate_abort"]
# enabling these breaks the float tests during linking, with intrinsics
# duplicated between embassy-rp and compilter_builtins
#build-std = ["core"]
#build-std-features = ["panic_immediate_abort"]
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
#runner = "teleprobe client run --target rpi-pico --elf"

View File

@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] }
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl"] }
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics"] }
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
defmt = "0.3.0"

53
tests/rp/src/bin/float.rs Normal file
View File

@ -0,0 +1,53 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::pac;
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
embassy_rp::init(Default::default());
info!("Hello World!");
const PI_F: f32 = 3.1415926535f32;
const PI_D: f64 = 3.14159265358979323846f64;
unsafe {
pac::BUSCTRL
.perfsel(0)
.write(|r| r.set_perfsel(pac::busctrl::vals::Perfsel::ROM));
}
for i in 0..=360 {
let rad_f = (i as f32) * PI_F / 180.0;
info!(
"{}° float: {=f32} / {=f32} / {=f32} / {=f32}",
i,
rad_f,
rad_f - PI_F,
rad_f + PI_F,
rad_f % PI_F
);
let rad_d = (i as f64) * PI_D / 180.0;
info!(
"{}° double: {=f64} / {=f64} / {=f64} / {=f64}",
i,
rad_d,
rad_d - PI_D,
rad_d + PI_D,
rad_d % PI_D
);
Timer::after(Duration::from_millis(10)).await;
}
let rom_accesses = unsafe { pac::BUSCTRL.perfctr(0).read().perfctr() };
// every float operation used here uses at least 10 cycles
defmt::assert!(rom_accesses >= 360 * 12 * 10);
info!("Test OK");
cortex_m::asm::bkpt();
}