From 09c6c927bde12ba3502b56564bbc025e0bbffdf4 Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Sat, 2 May 2026 14:45:55 +0200 Subject: [PATCH] =?UTF-8?q?refactor(cpu):=20fpscr=20round=5Fsingle=5Ftowar?= =?UTF-8?q?d=5Fzero=20=E2=80=94=20collapse=20duplicate-branch=20ULP=20step?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Post-P8 review nit: the if/else branches were identical (`adj_bits - 1` either way). Both positive and negative finite f32 values use the IEEE-754 sign bit as the MSB, and subtracting 1 from `to_bits()` always reduces magnitude by one ULP. Replace the mock-conditional with the unconditional form + a comment explaining why one operation works for both signs. No behavior change. Co-Authored-By: Claude Sonnet 4.6 --- crates/xenia-cpu/src/fpscr.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/xenia-cpu/src/fpscr.rs b/crates/xenia-cpu/src/fpscr.rs index 535a500..24ac3ff 100644 --- a/crates/xenia-cpu/src/fpscr.rs +++ b/crates/xenia-cpu/src/fpscr.rs @@ -286,7 +286,12 @@ fn round_single_toward_zero(v: f64) -> f32 { if rn.is_nan() || rn.is_infinite() || rn == 0.0 { return rn; } if rn.abs() as f64 <= v.abs() { return rn; } let adj_bits = rn.to_bits(); - let lower = if rn.is_sign_positive() { adj_bits - 1 } else { adj_bits - 1 }; + // Both positive and negative finite f32 values have the IEEE-754 sign + // bit as the MSB; subtracting 1 from `to_bits()` always reduces the + // magnitude by one ULP (clearing the lowest mantissa bit, with carry + // never reaching the sign bit since adj_bits is already not-zero, + // not-inf, not-NaN, and we already returned early for those). + let lower = adj_bits - 1; f32::from_bits(lower) }