#![allow(unused_assignments)]
#![allow(asm_sub_register)]
use core::f32;
use core::f64;
use crate::Steal;
use pastey::paste;
pub struct Dcp {
_private: (),
}
impl Dcp {
#[inline]
pub fn init() -> Self {
Dcp { _private: () }
}
#[inline]
pub unsafe fn steal() -> Steal<Dcp> {
Steal(Dcp::init())
}
}
#[inline]
fn f64_to_pair(v: f64) -> (u32, u32) {
let bits = v.to_bits();
(bits as u32, (bits >> 32) as u32)
}
#[inline]
fn pair_to_f64(lo: u32, hi: u32) -> f64 {
f64::from_bits((hi as u64) << 32 | lo as u64)
}
impl Dcp {
#[inline]
pub fn fadd(&self, a: f32, b: f32) -> f32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #0", rx = in(reg) a_bits,
ry = in(reg) b_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fsub(&self, a: f32, b: f32) -> f32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #1", rx = in(reg) a_bits,
ry = in(reg) b_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fmul(&self, a: f32, b: f32) -> f32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "mrrc p4, #1, {t0}, {t1}, c1", "umull {t0}, {t1}, {t0}, {t1}", "mcrr p4, #10, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #2", rx = in(reg) a_bits,
ry = in(reg) b_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fxprod(&self, a: f32, b: f32) -> (u32, u32) {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "mrrc p4, #1, {t0}, {t1}, c1", "umull {t0}, {t1}, {t0}, {t1}", "mcrr p4, #3, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #5, {lo}, {hi}, c0", rx = in(reg) a_bits,
ry = in(reg) b_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
lo = out(reg) lo,
hi = out(reg) hi,
options(nomem, nostack),
);
}
(lo, hi)
}
#[inline]
pub fn fdiv(&self, a: f32, b: f32) -> f32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "mrrc p4, #2, {t0}, {t1}, c1", "umull {t1}, {t2}, {t0}, {t1}", "mvn {t2}, {t2}, lsl #2", "smmlar {t0}, {t2}, {t0}, {t0}", "smmulr {t2}, {t2}, {t2}", "smmlar {t0}, {t2}, {t0}, {t0}", "mrrc p4, #1, {t1}, {t2}, c1", "umull {t3}, {t0}, {t0}, {t1}", "orr {t0}, {t0}, {t0}, lsr #24", "bic {t0}, {t0}, {t0}, lsr #25", "bic {t0}, {t0}, #15", "mov {t2}, {t2}, lsr #7", "mul {t3}, {t0}, {t2}", "rsb {t3}, {t3}, {t1}, lsl #22", "sub {t0}, {t0}, {t3}, lsr #31", "mcrr p4, #11, {t0}, {t0}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #3", rx = in(reg) a_bits,
ry = in(reg) b_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fdiv_fast(&self, a: f32, b: f32) -> f32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "mrrc p4, #2, {t0}, {t1}, c1", "umull {t1}, {t2}, {t0}, {t1}", "mvn {t2}, {t2}, lsl #2", "smmlar {t0}, {t2}, {t0}, {t0}", "smmulr {t2}, {t2}, {t2}", "smmlar {t0}, {t2}, {t0}, {t0}", "mrrc p4, #1, {t1}, {t2}, c1", "umull {t0}, {t1}, {t0}, {t1}", "mcrr p4, #11, {t1}, {t1}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #3", rx = in(reg) a_bits,
ry = in(reg) b_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fsqrt(&self, a: f32) -> f32 {
let a_bits = a.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {rx}, c2", "cdp p4, #2, c0, c0, c1, #0", "mrrc p4, #4, {t2}, {t3}, c1", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "mov {t1}, {t1}, lsl #3", "sub {t1}, {t1}, #2147483648", "smmlsr {t2}, {t2}, {t1}, {t2}", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "movs {t0}, {t0}, lsr #28", "adc {t1}, {t0}, {t1}, lsl #4", "smmulr {t0}, {t1}, {t2}", "sub {t2}, {t2}, {t0}, asr #1", "umull {t0}, {t1}, {t2}, {t3}", "orr {t1}, {t1}, #63", "mov {t0}, {t1}, lsr #5", "mul {t0}, {t0}, {t0}", "rsb {t0}, {t0}, {t3}, lsl #18", "bic {t1}, {t1}, {t0}, lsr #26", "mcrr p4, #12, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #4", rx = in(reg) a_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fsqrt_fast(&self, a: f32) -> f32 {
let a_bits = a.to_bits();
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {rx}, c2", "cdp p4, #2, c0, c0, c1, #0", "mrrc p4, #4, {t2}, {t3}, c1", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "mov {t1}, {t1}, lsl #3", "sub {t1}, {t1}, #2147483648", "smmlsr {t2}, {t2}, {t1}, {t2}", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "movs {t0}, {t0}, lsr #28", "adc {t1}, {t0}, {t1}, lsl #4", "smmulr {t0}, {t1}, {t2}", "sub {t2}, {t2}, {t0}, asr #1", "umull {t0}, {t1}, {t2}, {t3}", "mcrr p4, #12, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #4", rx = in(reg) a_bits,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn fclassify(&self, a: f32) -> u32 {
let a_bits = a.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {rx}, c2", "mrc p4, #0, {rz}, c0, c0, #0", rx = in(reg) a_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
#[inline]
pub fn fcmp(&self, a: f32, b: f32) -> u32 {
let a_bits = a.to_bits();
let b_bits = b.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {ry}, c2", "cdp p4, #0, c0, c0, c1, #0", "mrc p4, #0, {rz}, c0, c0, #1", rx = in(reg) a_bits,
ry = in(reg) b_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
}
impl Dcp {
#[inline]
pub fn dadd(&self, a: f64, b: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #1, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn dsub(&self, a: f64, b: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #3, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn dmul(&self, a: f64, b: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let mut t4 = 0u32;
let mut t5 = 0u32;
let mut t6 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "mrrc p4, #0, {t0}, {t1}, c4", "mrrc p4, #0, {t2}, {t3}, c5", "umull {t4}, {t5}, {t0}, {t2}", "movs {t6}, #0", "umlal {t5}, {t6}, {t0}, {t3}", "umlal {t5}, {t6}, {t1}, {t2}", "mcrr p4, #2, {t4}, {t5}, c0", "movs {t4}, #0", "umlal {t6}, {t4}, {t1}, {t3}", "mcrr p4, #3, {t6}, {t4}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #5, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
t4 = inout(reg) t4,
t5 = inout(reg) t5,
t6 = inout(reg) t6,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn ddiv(&self, a: f64, b: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let mut t4 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "mrrc p4, #2, {t0}, {t1}, c1", "umull {t1}, {t2}, {t0}, {t1}", "mvn {t2}, {t2}, lsl #2", "smmlar {t0}, {t2}, {t0}, {t0}", "smmulr {t2}, {t2}, {t2}", "smmlar {t0}, {t2}, {t0}, {t0}", "sub {t4}, {t0}, {t0}, lsr #31", "mrrc p4, #0, {t2}, {t3}, c4", "smmulr {t1}, {t4}, {t3}", "mrrc p4, #1, {t2}, {t3}, c5", "umull {t2}, {t0}, {t1}, {t2}", "mla {t0}, {t1}, {t3}, {t0}", "mrrc p4, #4, {t2}, {t3}, c4", "sub {t0}, {t2}, {t0}", "smmulr {t2}, {t0}, {t4}", "mov {t3}, {t1}, lsr #4", "adds {t0}, {t2}, {t1}, lsl #28", "adc {t1}, {t3}, {t2}, asr #31", "orr {t0}, {t0}, {t1}, lsr #21", "bic {t0}, {t0}, {t1}, lsr #22", "bic {t0}, {t0}, #7", "mrrc p4, #7, {t2}, {t3}, c5", "umull {t3}, {t4}, {t0}, {t2}", "mrrc p4, #7, {t2}, {t3}, c5", "mla {t4}, {t0}, {t3}, {t4}", "mla {t4}, {t1}, {t2}, {t4}", "mrrc p4, #0, {t2}, {t3}, c4", "sub {t4}, {t4}, {t2}, lsl #18", "orr {t0}, {t0}, {t4}, lsr #29", "sub {t0}, {t0}, #1", "mcrr p4, #4, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #7, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
t4 = inout(reg) t4,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn ddiv_fast(&self, a: f64, b: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let mut t4 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "mrrc p4, #2, {t0}, {t1}, c1", "umull {t1}, {t2}, {t0}, {t1}", "mvn {t2}, {t2}, lsl #2", "smmlar {t0}, {t2}, {t0}, {t0}", "smmulr {t2}, {t2}, {t2}", "smmlar {t0}, {t2}, {t0}, {t0}", "sub {t4}, {t0}, {t0}, lsr #31", "mrrc p4, #0, {t2}, {t3}, c4", "smmulr {t1}, {t4}, {t3}", "mrrc p4, #1, {t2}, {t3}, c5", "umull {t2}, {t0}, {t1}, {t2}", "mla {t0}, {t1}, {t3}, {t0}", "mrrc p4, #4, {t2}, {t3}, c4", "sub {t0}, {t2}, {t0}", "smmulr {t2}, {t0}, {t4}", "mov {t3}, {t1}, lsr #4", "adds {t0}, {t2}, {t1}, lsl #28", "adc {t1}, {t3}, {t2}, asr #31", "mcrr p4, #4, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #7, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
t4 = inout(reg) t4,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn dsqrt(&self, a: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let mut t4 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "cdp p4, #2, c0, c0, c1, #0", "mrrc p4, #4, {t2}, {t3}, c1", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "mov {t1}, {t1}, lsl #3", "sub {t1}, {t1}, #2147483648", "smmlsr {t2}, {t2}, {t1}, {t2}", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "movs {t0}, {t0}, lsr #28", "adc {t1}, {t0}, {t1}, lsl #4", "smmulr {t0}, {t1}, {t2}", "sub {t2}, {t2}, {t0}, asr #1", "umull {t0}, {t1}, {t2}, {t3}", "mov {t1}, {t1}, lsr #1", "umull {t3}, {t0}, {t1}, {t1}", "mrrc p4, #6, {t0}, {t4}, c4", "sub {t3}, {t0}, {t3}", "smmulr {t3}, {t3}, {t2}", "add {t1}, {t1}, {t3}, asr #28", "mov {t3}, {t3}, lsl #4", "bic {t3}, {t3}, #255", "orr {t3}, {t3}, #128", "umull {t4}, {t2}, {t3}, {t3}", "mul {t4}, {t1}, {t1}", "umlal {t2}, {t4}, {t1}, {t3}", "umlal {t2}, {t4}, {t1}, {t3}", "sub {t4}, {t4}, {t0}", "orr {t3}, {t3}, {t4}, lsr #24", "sub {t3}, {t3}, #11", "mcrr p4, #5, {t3}, {t1}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #9, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
t4 = inout(reg) t4,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn dsqrt_fast(&self, a: f64) -> f64 {
let (a_lo, a_hi) = f64_to_pair(a);
let mut t0 = 0u32;
let mut t1 = 0u32;
let mut t2 = 0u32;
let mut t3 = 0u32;
let mut t4 = 0u32;
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "cdp p4, #2, c0, c0, c1, #0", "mrrc p4, #4, {t2}, {t3}, c1", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "mov {t1}, {t1}, lsl #3", "sub {t1}, {t1}, #2147483648", "smmlsr {t2}, {t2}, {t1}, {t2}", "umull {t0}, {t1}, {t2}, {t2}", "umull {t0}, {t1}, {t1}, {t3}", "movs {t0}, {t0}, lsr #28", "adc {t1}, {t0}, {t1}, lsl #4", "smmulr {t0}, {t1}, {t2}", "sub {t2}, {t2}, {t0}, asr #1", "umull {t0}, {t1}, {t2}, {t3}", "mov {t1}, {t1}, lsr #1", "umull {t3}, {t0}, {t1}, {t1}", "mrrc p4, #6, {t0}, {t4}, c4", "sub {t0}, {t0}, {t3}", "smmulr {t0}, {t0}, {t2}", "add {t1}, {t1}, {t0}, asr #28", "mov {t0}, {t0}, lsl #4", "mcrr p4, #5, {t0}, {t1}, c0", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #9, {rzl}, {rzh}, c0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
t0 = inout(reg) t0,
t1 = inout(reg) t1,
t2 = inout(reg) t2,
t3 = inout(reg) t3,
t4 = inout(reg) t4,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn dclassify(&self, a: f64) -> u32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mrc p4, #0, {rz}, c0, c0, #0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
#[inline]
pub fn dcmp(&self, a: f64, b: f64) -> u32 {
let (a_lo, a_hi) = f64_to_pair(a);
let (b_lo, b_hi) = f64_to_pair(b);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "mcrr p4, #1, {ryl}, {ryh}, c1", "cdp p4, #0, c0, c0, c1, #0", "mrc p4, #0, {rz}, c0, c0, #1", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
ryl = in(reg) b_lo,
ryh = in(reg) b_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
}
impl Dcp {
#[inline]
pub fn float2double(&self, a: f32) -> f64 {
let a_bits = a.to_bits();
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rx}, {rx}, c2", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #11, {rzl}, {rzh}, c0", rx = in(reg) a_bits,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn double2float(&self, a: f64) -> f32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #1, {rxl}, {rxh}, c0", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #5", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn int2float(&self, a: i32) -> f32 {
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #7, {rx}, {rx}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #1", rx = in(reg) a as u32,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn uint2float(&self, a: u32) -> f32 {
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #6, {rx}, {rx}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c2, #1", "mrc p4, #0, {rz}, c0, c2, #1", rx = in(reg) a,
rz = out(reg) result,
options(nomem, nostack),
);
}
f32::from_bits(result)
}
#[inline]
pub fn int2double(&self, a: i32) -> f64 {
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #7, {rx}, {rx}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #3, {rzl}, {rzh}, c0", rx = in(reg) a as u32,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn uint2double(&self, a: u32) -> f64 {
let lo: u32;
let hi: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #6, {rx}, {rx}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #1", "cdp p4, #8, c0, c0, c0, #1", "mrrc p4, #3, {rzl}, {rzh}, c0", rx = in(reg) a,
rzl = out(reg) lo,
rzh = out(reg) hi,
options(nomem, nostack),
);
}
pair_to_f64(lo, hi)
}
#[inline]
pub fn float2int(&self, a: f32) -> i32 {
let a_bits = a.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #9, {rx}, {rx}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #2", "mrc p4, #0, {rz}, c0, c3, #0", rx = in(reg) a_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result as i32
}
#[inline]
pub fn float2uint(&self, a: f32) -> u32 {
let a_bits = a.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #9, {rx}, {rx}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #2", "mrc p4, #0, {rz}, c0, c3, #1", rx = in(reg) a_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
#[inline]
pub fn double2int(&self, a: f64) -> i32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #8, {rxl}, {rxh}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #2", "mrc p4, #0, {rz}, c0, c3, #0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result as i32
}
#[inline]
pub fn double2uint(&self, a: f64) -> u32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #8, {rxl}, {rxh}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #2", "mrc p4, #0, {rz}, c0, c3, #1", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
#[inline]
pub fn float2int_r(&self, a: f32) -> i32 {
let a_bits = a.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #9, {rx}, {rx}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #3", "mrc p4, #0, {rz}, c0, c3, #0", rx = in(reg) a_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result as i32
}
#[inline]
pub fn float2uint_r(&self, a: f32) -> u32 {
let a_bits = a.to_bits();
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #9, {rx}, {rx}, c2", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #3", "mrc p4, #0, {rz}, c0, c3, #1", rx = in(reg) a_bits,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
#[inline]
pub fn double2int_r(&self, a: f64) -> i32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #8, {rxl}, {rxh}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #3", "mrc p4, #0, {rz}, c0, c3, #0", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result as i32
}
#[inline]
pub fn double2uint_r(&self, a: f64) -> u32 {
let (a_lo, a_hi) = f64_to_pair(a);
let result: u32;
unsafe {
core::arch::asm!(
"mcrr p4, #8, {rxl}, {rxh}, c0", "cdp p4, #0, c0, c0, c1, #0", "cdp p4, #1, c0, c0, c1, #0", "cdp p4, #8, c0, c0, c0, #3", "mrc p4, #0, {rz}, c0, c3, #1", rxl = in(reg) a_lo,
rxh = in(reg) a_hi,
rz = out(reg) result,
options(nomem, nostack),
);
}
result
}
}
mod cmp_bits {
pub(crate) const NAN: u32 = 1 << 28;
pub(crate) const GE: u32 = 1 << 29;
pub(crate) const EQUAL: u32 = 1 << 30;
}
macro_rules! impl_cmp {
($prefix:ident, $raw:ident, $ty:ty) => {
paste! {
impl Dcp {
#[doc = concat!("Test if `a == b` (false if either is NaN) for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_eq>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
(r & cmp_bits::EQUAL) != 0 && (r & cmp_bits::NAN) == 0
}
#[doc = concat!("Test if `a < b` (false if either is NaN) for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_lt>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
(r & cmp_bits::GE) == 0 && (r & cmp_bits::NAN) == 0
}
#[doc = concat!("Test if `a <= b` (false if either is NaN) for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_le>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
((r & cmp_bits::GE) == 0 || (r & cmp_bits::EQUAL) != 0) && (r & cmp_bits::NAN) == 0
}
#[doc = concat!("Test if `a > b` (false if either is NaN) for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_gt>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
(r & cmp_bits::GE) != 0 && (r & cmp_bits::EQUAL) == 0 && (r & cmp_bits::NAN) == 0
}
#[doc = concat!("Test if `a >= b` (false if either is NaN) for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_ge>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
(r & cmp_bits::GE) != 0 && (r & cmp_bits::NAN) == 0
}
#[doc = concat!("Test if either operand is NaN for ", stringify!($ty), ".")]
#[inline]
pub fn [<$prefix cmp_unordered>](&self, a: $ty, b: $ty) -> bool {
let r = self.$raw(a, b);
(r & cmp_bits::NAN) != 0
}
}
}
};
}
impl_cmp!(f, fcmp, f32);
impl_cmp!(d, dcmp, f64);