Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 72 additions & 64 deletions psp/src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[no_mangle]
pub unsafe extern "C" fn fminf(x: f32, y: f32) -> f32 {
pub extern "C" fn fminf(x: f32, y: f32) -> f32 {
let out: f32;
if x.is_nan() && !y.is_nan() {
out = y;
Expand All @@ -8,28 +8,30 @@ pub unsafe extern "C" fn fminf(x: f32, y: f32) -> f32 {
} else if x.is_nan() && y.is_nan() {
out = core::f32::NAN;
} else {
vfpu_asm! (
"mfc1 {tmp1}, {x}",
"mfc1 {tmp2}, {y}",
"mtv {tmp1}, S000",
"mtv {tmp2}, S001",
"vmin.s S000, S000, S001",
"mfv {tmp1}, S000",
"mtc1 {tmp1}, {out}",
"nop",
x = in(freg) x,
y = in(freg) y,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
out = out(freg) out,
options(nostack, nomem),
);
unsafe {
vfpu_asm! (
"mfc1 {tmp1}, {x}",
"mfc1 {tmp2}, {y}",
"mtv {tmp1}, S000",
"mtv {tmp2}, S001",
"vmin.s S000, S000, S001",
"mfv {tmp1}, S000",
"mtc1 {tmp1}, {out}",
"nop",
x = in(freg) x,
y = in(freg) y,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
out = out(freg) out,
options(nostack, nomem),
);
}
}
out
}

#[no_mangle]
pub unsafe extern "C" fn fmaxf(x: f32, y: f32) -> f32 {
pub extern "C" fn fmaxf(x: f32, y: f32) -> f32 {
let out: f32;
if x.is_nan() && !y.is_nan() {
out = y;
Expand All @@ -38,63 +40,69 @@ pub unsafe extern "C" fn fmaxf(x: f32, y: f32) -> f32 {
} else if x.is_nan() && y.is_nan() {
out = core::f32::NAN;
} else {
vfpu_asm! (
"mfc1 {tmp1}, {x}",
"mfc1 {tmp2}, {y}",
"mtv {tmp1}, S000",
"mtv {tmp2}, S001",
"vmax.s S000, S000, S001",
"mfv {tmp1}, S000",
"mtc1 {tmp1}, {out}",
"nop",
x = in(freg) x,
y = in(freg) y,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
out = out(freg) out,
options(nostack, nomem),
);
unsafe {
vfpu_asm! (
"mfc1 {tmp1}, {x}",
"mfc1 {tmp2}, {y}",
"mtv {tmp1}, S000",
"mtv {tmp2}, S001",
"vmax.s S000, S000, S001",
"mfv {tmp1}, S000",
"mtc1 {tmp1}, {out}",
"nop",
x = in(freg) x,
y = in(freg) y,
tmp1 = out(reg) _,
tmp2 = out(reg) _,
out = out(freg) out,
options(nostack, nomem),
);
}
}
out
}

#[no_mangle]
pub unsafe extern "C" fn cosf(scalar: f32) -> f32 {
pub extern "C" fn cosf(scalar: f32) -> f32 {
let out: f32;
vfpu_asm! (
"mfc1 {tmp}, {scalar}",
"mtv {tmp}, S000",
"nop",
"vcst.s S001, VFPU_2_PI",
"vmul.s S000, S000, S001",
"vcos.s S000, S000",
"mfv {tmp}, S000",
"mtc1 {tmp}, {scalar}",
"nop",
scalar = inlateout(freg) scalar => out,
tmp = out(reg) _,
options(nostack, nomem),
);
unsafe {
vfpu_asm! (
"mfc1 {tmp}, {scalar}",
"mtv {tmp}, S000",
"nop",
"vcst.s S001, VFPU_2_PI",
"vmul.s S000, S000, S001",
"vcos.s S000, S000",
"mfv {tmp}, S000",
"mtc1 {tmp}, {scalar}",
"nop",
scalar = inlateout(freg) scalar => out,
tmp = out(reg) _,
options(nostack, nomem),
);
}
out
}

#[no_mangle]
pub unsafe extern "C" fn sinf(scalar: f32) -> f32 {
pub extern "C" fn sinf(scalar: f32) -> f32 {
let out: f32;
vfpu_asm! (
"mfc1 {tmp}, {scalar}",
"mtv {tmp}, S000",
"nop",
"vcst.s S001, VFPU_2_PI",
"vmul.s S000, S000, S001",
"vsin.s S000, S000",
"mfv {tmp}, S000",
"mtc1 {tmp}, {scalar}",
"nop",
scalar = inlateout(freg) scalar => out,
tmp = out(reg) _,
options(nostack, nomem),
);
unsafe {
vfpu_asm! (
"mfc1 {tmp}, {scalar}",
"mtv {tmp}, S000",
"nop",
"vcst.s S001, VFPU_2_PI",
"vmul.s S000, S000, S001",
"vsin.s S000, S000",
"mfv {tmp}, S000",
"mtc1 {tmp}, {scalar}",
"nop",
scalar = inlateout(freg) scalar => out,
tmp = out(reg) _,
options(nostack, nomem),
);
}
out
}
// borrowed from https://github.com/samcrow/cmsis_dsp.rs/blob/master/src/libm_c.rs
Expand Down