2021-02-01 01:54:09 +08:00
|
|
|
use core::f32::consts::PI;
|
2021-02-19 17:44:46 +08:00
|
|
|
use dsp::{atan2, cossin};
|
|
|
|
use dsp::{iir, iir_int};
|
2021-02-19 18:02:46 +08:00
|
|
|
use dsp::{PLL, RPLL};
|
2021-02-19 17:44:46 +08:00
|
|
|
use easybench::bench_env;
|
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): {}",
|
|
|
|
bench_env(0x241, |x| dut.update(*x, 12, 12))
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"PLL::update(t, sf, sp): {}",
|
|
|
|
bench_env((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 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): {}",
|
|
|
|
bench_env(0.32241, |x| dut.update(&mut xy, *x))
|
|
|
|
);
|
2021-02-01 02:12:24 +08:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:44:46 +08:00
|
|
|
fn main() {
|
|
|
|
atan2_bench();
|
|
|
|
cossin_bench();
|
|
|
|
rpll_bench();
|
|
|
|
pll_bench();
|
|
|
|
iir_int_bench();
|
|
|
|
iir_bench();
|
|
|
|
}
|