From 09319a1e118c3885372c4e7ea07f4526630a111e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 21 Feb 2015 22:23:48 -0500 Subject: [PATCH 1/2] Interpreter: Rearrange ordered/unordered compares Comparing floating point numbers with == can trigger warnings (and have static analysis tools complain). So we make it the else case. This also more closely resembles the Gekko manual. --- .../Interpreter/Interpreter_FloatingPoint.cpp | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp index 31850a1c25..a469e3ccbb 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp @@ -22,19 +22,7 @@ void Interpreter::Helper_FloatCompareOrdered(UGeckoInstruction _inst, double fa, { int compareResult; - if (fa < fb) - { - compareResult = FPCC::FL; - } - else if (fa > fb) - { - compareResult = FPCC::FG; - } - else if (fa == fb) - { - compareResult = FPCC::FE; - } - else // NaN + if (IsNAN(fa) || IsNAN(fb)) { FPSCR.FX = 1; compareResult = FPCC::FU; @@ -51,6 +39,18 @@ void Interpreter::Helper_FloatCompareOrdered(UGeckoInstruction _inst, double fa, SetFPException(FPSCR_VXVC); } } + else if (fa < fb) + { + compareResult = FPCC::FL; + } + else if (fa > fb) + { + compareResult = FPCC::FG; + } + else // Equals + { + compareResult = FPCC::FE; + } FPSCR.FPRF = compareResult; SetCRField(_inst.CRFD, compareResult); @@ -60,7 +60,17 @@ void Interpreter::Helper_FloatCompareUnordered(UGeckoInstruction _inst, double f { int compareResult; - if (fa < fb) + if (IsNAN(fa) || IsNAN(fb)) + { + compareResult = FPCC::FU; + + if (IsSNAN(fa) || IsSNAN(fb)) + { + FPSCR.FX = 1; + SetFPException(FPSCR_VXSNAN); + } + } + else if (fa < fb) { compareResult = FPCC::FL; } @@ -68,19 +78,10 @@ void Interpreter::Helper_FloatCompareUnordered(UGeckoInstruction _inst, double f { compareResult = FPCC::FG; } - else if (fa == fb) + else // Equals { compareResult = FPCC::FE; } - else - { - compareResult = FPCC::FU; - if (IsSNAN(fa) || IsSNAN(fb)) - { - FPSCR.FX = 1; - SetFPException(FPSCR_VXSNAN); - } - } FPSCR.FPRF = compareResult; SetCRField(_inst.CRFD, compareResult); From bfa5dcc8913def1e1decf8e834cb64694ed0aa5d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 21 Feb 2015 22:56:22 -0500 Subject: [PATCH 2/2] Interpreter: Set the FPCC bits correctly for ordered/unordered FP compares Setting the whole FPRF is slightly incorrect, this should only modify the FPCC bits; the class bit should be preserved. --- .../PowerPC/Interpreter/Interpreter_FloatingPoint.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp index a469e3ccbb..26cb1edf7d 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter_FloatingPoint.cpp @@ -52,7 +52,9 @@ void Interpreter::Helper_FloatCompareOrdered(UGeckoInstruction _inst, double fa, compareResult = FPCC::FE; } - FPSCR.FPRF = compareResult; + // Clear and set the FPCC bits accordingly. + FPSCR.FPRF = (FPSCR.FPRF & ~0xF) | compareResult; + SetCRField(_inst.CRFD, compareResult); } @@ -83,7 +85,9 @@ void Interpreter::Helper_FloatCompareUnordered(UGeckoInstruction _inst, double f compareResult = FPCC::FE; } - FPSCR.FPRF = compareResult; + // Clear and set the FPCC bits accordingly. + FPSCR.FPRF = (FPSCR.FPRF & ~0xF) | compareResult; + SetCRField(_inst.CRFD, compareResult); }