diff --git a/src/dynarmic/backend/arm64/emit_arm64_data_processing.cpp b/src/dynarmic/backend/arm64/emit_arm64_data_processing.cpp index ab048550..f5624a8d 100644 --- a/src/dynarmic/backend/arm64/emit_arm64_data_processing.cpp +++ b/src/dynarmic/backend/arm64/emit_arm64_data_processing.cpp @@ -493,9 +493,9 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst* RegAlloc::Realize(Rresult, Ra, flags); if (args[2].GetImmediateU1()) { - MaybeAddSubImm(code, ~imm, [&](const auto b) { sub ? code.ADDS(Rresult, *Ra, b) : code.SUBS(Rresult, *Ra, b); }); + MaybeAddSubImm(code, sub ? imm : ~imm, [&](const auto b) { code.SUBS(Rresult, *Ra, b); }); } else { - MaybeAddSubImm(code, imm, [&](const auto b) { sub ? code.SUBS(Rresult, *Ra, b) : code.ADDS(Rresult, *Ra, b); }); + MaybeAddSubImm(code, sub ? ~imm : imm, [&](const auto b) { code.ADDS(Rresult, *Ra, b); }); } } else { RegAlloc::Realize(Rresult, Ra); @@ -512,10 +512,19 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst* RegAlloc::Realize(Rresult, Ra, Rb, flags); if (args[2].GetImmediateU1()) { - code.MVN(Rscratch0(), Rb); - sub ? code.ADDS(Rresult, *Ra, Rscratch0()) : code.SUBS(Rresult, *Ra, Rscratch0()); + if (sub) { + code.SUBS(Rresult, *Ra, Rb); + } else { + code.MVN(Rscratch0(), Rb); + code.SUBS(Rresult, *Ra, Rscratch0()); + } } else { - sub ? code.SUBS(Rresult, *Ra, Rb) : code.ADDS(Rresult, *Ra, Rb); + if (sub) { + code.MVN(Rscratch0(), Rb); + code.ADDS(Rresult, *Ra, Rscratch0()); + } else { + code.ADDS(Rresult, *Ra, Rb); + } } } else { RegAlloc::Realize(Rresult, Ra, Rb); @@ -532,9 +541,9 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst* if (args[2].IsImmediate()) { if (args[2].GetImmediateU1()) { - MaybeAddSubImm(code, ~imm, [&](const auto b) { sub ? code.ADD(Rresult, *Ra, b) : code.SUB(Rresult, *Ra, b); }); + MaybeAddSubImm(code, sub ? imm : ~imm, [&](const auto b) { code.SUB(Rresult, *Ra, b); }); } else { - MaybeAddSubImm(code, imm, [&](const auto b) { sub ? code.SUB(Rresult, *Ra, b) : code.ADD(Rresult, *Ra, b); }); + MaybeAddSubImm(code, sub ? ~imm : imm, [&](const auto b) { code.ADD(Rresult, *Ra, b); }); } } else { code.MOV(Rscratch0(), imm); @@ -547,10 +556,19 @@ static void EmitAddSub(oaknut::CodeGenerator& code, EmitContext& ctx, IR::Inst* if (args[2].IsImmediate()) { if (args[2].GetImmediateU1()) { - code.MVN(Rscratch0(), Rb); - sub ? code.ADD(Rresult, *Ra, Rscratch0()) : code.SUB(Rresult, *Ra, Rscratch0()); + if (sub) { + code.SUB(Rresult, *Ra, Rb); + } else { + code.MVN(Rscratch0(), Rb); + code.SUB(Rresult, *Ra, Rscratch0()); + } } else { - sub ? code.SUB(Rresult, *Ra, Rb) : code.ADD(Rresult, *Ra, Rb); + if (sub) { + code.MVN(Rscratch0(), Rb); + code.ADD(Rresult, *Ra, Rscratch0()); + } else { + code.ADD(Rresult, *Ra, Rb); + } } } else { sub ? code.SBC(Rresult, Ra, Rb) : code.ADC(Rresult, Ra, Rb);