diff --git a/crates/xenia-cpu/src/interpreter.rs b/crates/xenia-cpu/src/interpreter.rs index 082e029..31d54f5 100644 --- a/crates/xenia-cpu/src/interpreter.rs +++ b/crates/xenia-cpu/src/interpreter.rs @@ -2429,25 +2429,13 @@ fn execute(ctx: &mut PpcContext, mem: &dyn MemoryAccess, instr: &DecodedInstr) - ctx.pc += 4; } PpcOpcode::vrfin | PpcOpcode::vrfin128 => { - // PPCBUG-432: ISA round-to-nearest-even, NOT Rust's round-half-away-from-zero. + // PPCBUG-432: ISA round-to-nearest-even, NOT Rust's `round()` + // (which is round-half-away-from-zero). let vb = if matches!(instr.opcode, PpcOpcode::vrfin128) { instr.vb128() } else { instr.rb() }; let vd = if matches!(instr.opcode, PpcOpcode::vrfin128) { instr.vd128() } else { instr.rd() }; let b = ctx.vr[vb].as_f32x4(); let mut r = [0f32; 4]; - for i in 0..4 { - let x = b[i]; - let t = x.trunc(); - let frac = (x - t).abs(); - r[i] = if frac > 0.5 { - t + if x >= 0.0 { 1.0 } else { -1.0 } - } else if frac < 0.5 { - t - } else { - // Tie — round to even. - let ti = t as i64; - if ti & 1 == 0 { t } else { t + if x >= 0.0 { 1.0 } else { -1.0 } } - }; - } + for i in 0..4 { r[i] = b[i].round_ties_even(); } ctx.vr[vd] = xenia_types::Vec128::from_f32x4_array(r); ctx.pc += 4; }