From 44280dd58d790d530e3d71e6ba51f6750bb0aa38 Mon Sep 17 00:00:00 2001 From: GitHubProUser67 <127040195+GitHubProUser67@users.noreply.github.com> Date: Mon, 9 Jun 2025 21:32:35 +0200 Subject: [PATCH] [Soft-Float] - Fixes add/sub edge cases for denormals handling. This commit fixup a calculation mistake in add/sub when dealing with booth numbers that are denormals. --- pcsx2/PS2Float.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/pcsx2/PS2Float.cpp b/pcsx2/PS2Float.cpp index 590d10d360..840bafc98f 100644 --- a/pcsx2/PS2Float.cpp +++ b/pcsx2/PS2Float.cpp @@ -185,7 +185,14 @@ PS2Float PS2Float::Add(PS2Float addend) else if (!IsDenormalized() && addend.IsDenormalized()) return PS2Float(sign, Exponent(), Mantissa()); else if (IsDenormalized() && addend.IsDenormalized()) - return PS2Float(sign, 0, 0); + { + if (!Sign() || !addend.Sign()) + return PS2Float(false, 0, 0); + else if (Sign() && addend.Sign()) + return PS2Float(true, 0, 0); + else + Console.Error("Unhandled addition operation flags"); + } else Console.Error("Both numbers are not denormalized"); @@ -227,7 +234,14 @@ PS2Float PS2Float::Sub(PS2Float subtrahend) else if (!IsDenormalized() && subtrahend.IsDenormalized()) return PS2Float(sign, Exponent(), Mantissa()); else if (IsDenormalized() && subtrahend.IsDenormalized()) - return PS2Float(sign, 0, 0); + { + if (!Sign() || subtrahend.Sign()) + return PS2Float(false, 0, 0); + else if (Sign() && !subtrahend.Sign()) + return PS2Float(true, 0, 0); + else + Console.Error("Unhandled subtraction operation flags"); + } else Console.Error("Both numbers are not denormalized"); @@ -883,31 +897,11 @@ bool PS2Float::DetermineMultiplicationDivisionOperationSign(PS2Float a, PS2Float bool PS2Float::DetermineAdditionOperationSign(PS2Float a, PS2Float b) { - if (a.IsZero() && b.IsZero()) - { - if (!a.Sign() || !b.Sign()) - return false; - else if (a.Sign() && b.Sign()) - return true; - else - Console.Error("Unhandled addition operation flags"); - } - return a.CompareOperands(b) >= 0 ? a.Sign() : b.Sign(); } bool PS2Float::DetermineSubtractionOperationSign(PS2Float a, PS2Float b) { - if (a.IsZero() && b.IsZero()) - { - if (!a.Sign() || b.Sign()) - return false; - else if (a.Sign() && !b.Sign()) - return true; - else - Console.Error("Unhandled subtraction operation flags"); - } - return a.CompareOperands(b) >= 0 ? a.Sign() : !b.Sign(); }