From 529f23d836a63cb5d224336dbb5cde2e81a9a82a Mon Sep 17 00:00:00 2001 From: joevt Date: Tue, 9 Apr 2024 01:07:48 -0700 Subject: [PATCH] poweropcodes: Fix abs. Making a negative value positive requires unary negate operator rather than binary and operator since negative numbers are stored using twos compliment. If ov is set then clear overflow when overflow doesn't happen. --- cpu/ppc/poweropcodes.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpu/ppc/poweropcodes.cpp b/cpu/ppc/poweropcodes.cpp index 0bcfedd..a5204d3 100644 --- a/cpu/ppc/poweropcodes.cpp +++ b/cpu/ppc/poweropcodes.cpp @@ -52,9 +52,10 @@ void dppc_interpreter::power_abs() { ppc_result_d = ppc_result_a; if (ov) ppc_state.spr[SPR::XER] |= XER::SO | XER::OV; - } else { - ppc_result_d = ppc_result_a & 0x7FFFFFFF; + ppc_result_d = (int32_t(ppc_result_a) < 0) ? -ppc_result_a : ppc_result_a; + if (ov) + ppc_state.spr[SPR::XER] &= ~XER::OV; } if (rec)