2021-02-01 01:54:09 +08:00
|
|
|
use core::f32::consts::PI;
|
2021-02-27 21:54:46 +08:00
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
use easybench::bench_env;
|
2021-02-27 21:54:46 +08:00
|
|
|
|
2021-02-27 22:02:16 +08:00
|
|
|
use dsp::{atan2, cossin, iir, iir_int, Lowpass, PLL, RPLL};
|
2021-02-01 01:54:09 +08:00
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn atan2_bench() {
|
2021-02-01 01:54:09 +08:00
|
|
|
let xi = (10 << 16) as i32;
|
|
|
|
let xf = xi as f32 / i32::MAX as f32;
|
|
|
|
|
|
|
|
let yi = (-26_328 << 16) as i32;
|
|
|
|
let yf = yi as f32 / i32::MAX as f32;
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
println!(
|
|
|
|
"atan2(yi, xi): {}",
|
|
|
|
bench_env((yi, xi), |(yi, xi)| atan2(*yi, *xi))
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"yf.atan2(xf): {}",
|
|
|
|
bench_env((yf, xf), |(yf, xf)| yf.atan2(*xf))
|
|
|
|
);
|
2021-02-01 01:54:09 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn cossin_bench() {
|
2021-02-01 01:54:09 +08:00
|
|
|
let zi = -0x7304_2531_i32;
|
|
|
|
let zf = zi as f32 / i32::MAX as f32 * PI;
|
2021-02-19 17:44:46 +08:00
|
|
|
println!("cossin(zi): {}", bench_env(zi, |zi| cossin(*zi)));
|
|
|
|
println!("zf.sin_cos(): {}", bench_env(zf, |zf| zf.sin_cos()));
|
2021-02-01 01:54:09 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn rpll_bench() {
|
2021-02-01 01:54:09 +08:00
|
|
|
let mut dut = RPLL::new(8);
|
2021-02-19 17:44:46 +08:00
|
|
|
println!(
|
|
|
|
"RPLL::update(Some(t), 21, 20): {}",
|
|
|
|
bench_env(Some(0x241), |x| dut.update(*x, 21, 20))
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"RPLL::update(Some(t), sf, sp): {}",
|
|
|
|
bench_env((Some(0x241), 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
|
|
|
|
);
|
2021-02-01 01:54:09 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn pll_bench() {
|
2021-02-01 01:54:09 +08:00
|
|
|
let mut dut = PLL::default();
|
2021-02-19 17:44:46 +08:00
|
|
|
println!(
|
|
|
|
"PLL::update(t, 12, 12): {}",
|
2021-06-04 01:24:25 +08:00
|
|
|
bench_env(Some(0x241), |x| dut.update(*x, 12, 12))
|
2021-02-19 17:44:46 +08:00
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"PLL::update(t, sf, sp): {}",
|
2021-06-04 01:24:25 +08:00
|
|
|
bench_env((Some(0x241), 21, 20), |(x, p, q)| dut.update(*x, *p, *q))
|
2021-02-19 17:44:46 +08:00
|
|
|
);
|
2021-02-01 01:54:09 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn iir_int_bench() {
|
2021-02-01 02:12:24 +08:00
|
|
|
let dut = iir_int::IIR::default();
|
2021-02-01 20:27:49 +08:00
|
|
|
let mut xy = iir_int::Vec5::default();
|
2021-02-19 17:44:46 +08:00
|
|
|
println!(
|
|
|
|
"int_iir::IIR::update(s, x): {}",
|
|
|
|
bench_env(0x2832, |x| dut.update(&mut xy, *x))
|
|
|
|
);
|
2021-02-01 02:12:24 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn iir_bench() {
|
2021-02-01 02:12:24 +08:00
|
|
|
let dut = iir::IIR::default();
|
2021-02-01 20:27:49 +08:00
|
|
|
let mut xy = iir::Vec5::default();
|
2021-02-19 17:44:46 +08:00
|
|
|
println!(
|
|
|
|
"int::IIR::update(s, x): {}",
|
2021-04-14 22:02:54 +08:00
|
|
|
bench_env(0.32241, |x| dut.update(&mut xy, *x, true))
|
2021-02-19 17:44:46 +08:00
|
|
|
);
|
2021-02-01 02:12:24 +08:00
|
|
|
}
|
|
|
|
|
2021-02-27 21:54:46 +08:00
|
|
|
fn lowpass_bench() {
|
2021-05-10 23:31:53 +08:00
|
|
|
let mut dut = Lowpass::<4>::default();
|
2021-02-27 21:54:46 +08:00
|
|
|
println!(
|
2021-05-10 23:31:53 +08:00
|
|
|
"Lowpass::<4>::update(x, k): {}",
|
2021-02-27 21:54:46 +08:00
|
|
|
bench_env((0x32421, 14), |(x, k)| dut.update(*x, *k))
|
|
|
|
);
|
|
|
|
println!(
|
2021-05-10 23:31:53 +08:00
|
|
|
"Lowpass::<4>::update(x, 14): {}",
|
2021-02-27 21:54:46 +08:00
|
|
|
bench_env(0x32421, |x| dut.update(*x, 14))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn main() {
|
|
|
|
atan2_bench();
|
|
|
|
cossin_bench();
|
|
|
|
rpll_bench();
|
|
|
|
pll_bench();
|
|
|
|
iir_int_bench();
|
|
|
|
iir_bench();
|
2021-02-27 21:54:46 +08:00
|
|
|
lowpass_bench();
|
2021-02-19 17:44:46 +08:00
|
|
|
}
|