-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MIPS delay slot codegen issue #91442
Comments
@rustbot label: +O-mips |
@rustbot label: +A-codegen |
Simplified example: #![no_std]
#![no_main]
#![feature(bench_black_box)]
psp::module!("crash-test",1,0);
fn psp_main() {
let dx = core::hint::black_box(0.0);
let tdx = do_calc(dx);
psp::dprintln!("{}", tdx);
}
#[no_mangle]
#[inline(never)]
fn do_calc(dx: f32) -> f32 {
if dx == 0.0 {
core::f32::MAX
} else {
1.0 / dx
}
}
|
Nevermind, this appears to be a possible problem with the FPU of the PSP doing the comparison to 0, combined with my dodgy understanding of MIPS assembly. |
Followup: The real problem is that MIPS revs <=3 have delay slots for floating point comparison instructions, (such as c.eq.s), and LLVM does not appear to have accounted for this. Sources: |
I tried this code:
and compiled with the official tier 3 target, mipsel-sony-psp, the psp crate, and the cargo-psp crate. This should compile for any other mips target by renaming
psp_main
tomain
, removing#[no_main]
, removingpsp::enable_home_button
, removingpsp::module!
and replacingpsp::dprintln!
withprintln!
. I suspect the problem would be the same on other MIPS targets, PSP is MIPS2 ISA.I expected to see this happen: The if statement should prevent the case of divide by zero
Instead, this happened: The division instruction is scheduled in the delay slot of the jump (2b0), rendering the if statement useless. This leads to a floating point exception for dividing by zero.
Meta
rustc --version --verbose
:I used gdb for backtrace since I can't run RUST_BACKTRACE=1 on PSP.
Backtrace
The text was updated successfully, but these errors were encountered: