From 14119c86a42ad0b533be807354d67362e6a28279 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 15 Aug 2021 17:00:00 -0700 Subject: [PATCH] DSPInterpreter: Fix IsLess `IsLess` would incorrectly return true if both `SR_OVERFLOW` and `SR_SIGN` are set, as `(sr & SR_OVERFLOW) != (sr & SR_SIGN)` becomes `SR_OVERFLOW != SR_SIGN` which is true as the two masks are different. This broke in e651592ef56521f6db71f8a671fe8c20b948d338. This issue only affected the DSP LLE Interpreter, and not the DSP LLE JIT. I've also included a simple test case for this. `ax0.l` (on the top left) is set to 0 if the instruction following `IFL` does not execute and to 1 if it is executed. --- .../Core/Core/DSP/Interpreter/DSPInterpreter.cpp | 5 +---- Source/DSPSpy/tests/less_test.ds | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 Source/DSPSpy/tests/less_test.ds diff --git a/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp b/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp index ac490ae62e..5d8fd7e32b 100644 --- a/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp +++ b/Source/Core/Core/DSP/Interpreter/DSPInterpreter.cpp @@ -250,10 +250,7 @@ bool Interpreter::CheckCondition(u8 condition) const const auto IsCarry = [this] { return IsSRFlagSet(SR_CARRY); }; const auto IsOverflow = [this] { return IsSRFlagSet(SR_OVERFLOW); }; const auto IsOverS32 = [this] { return IsSRFlagSet(SR_OVER_S32); }; - const auto IsLess = [this] { - const auto& state = m_dsp_core.DSPState(); - return (state.r.sr & SR_OVERFLOW) != (state.r.sr & SR_SIGN); - }; + const auto IsLess = [this] { return IsSRFlagSet(SR_OVERFLOW) != IsSRFlagSet(SR_SIGN); }; const auto IsZero = [this] { return IsSRFlagSet(SR_ARITH_ZERO); }; const auto IsLogicZero = [this] { return IsSRFlagSet(SR_LOGIC_ZERO); }; const auto IsConditionA = [this] { diff --git a/Source/DSPSpy/tests/less_test.ds b/Source/DSPSpy/tests/less_test.ds new file mode 100644 index 0000000000..1b75eaecdd --- /dev/null +++ b/Source/DSPSpy/tests/less_test.ds @@ -0,0 +1,16 @@ +incdir "tests" +include "dsp_base.inc" + + CLR $acc0 + CLR $acc1 + LRI $ac0.h, #0x0050 + LRI $ac1.h, #0x0050 + ADD $acc0, $acc1 ; Causes acc0 to overflow, and thus also become negative + + LRI $AX0.L, #0x0000 + IFL + LRI $AX0.L, #0x0001 + CALL send_back + +; We're done, DO NOT DELETE THIS LINE + JMP end_of_test