From 1e4ab0412140c81a93336acdac6348d806c0df79 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 5 Dec 2024 11:06:42 +1030 Subject: [PATCH] Core: Fix up CX86RecompilerOps::SPECIAL_DSUB when rd == rt --- .../Recompiler/x86/x86RecompilerOps.cpp | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 805bb03d4..0b686889c 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -7019,38 +7019,35 @@ void CX86RecompilerOps::SPECIAL_DSUB() } else { - int source1 = m_Opcode.rd == m_Opcode.rt ? m_Opcode.rt : m_Opcode.rs; - int source2 = m_Opcode.rd == m_Opcode.rt ? m_Opcode.rs : m_Opcode.rt; + m_RegWorkingSet.ProtectGPR(m_Opcode.rs); + m_RegWorkingSet.ProtectGPR(m_Opcode.rt); + asmjit::x86::Gp RegLo = m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp RegHi = m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); - m_RegWorkingSet.ProtectGPR(source1); - m_RegWorkingSet.ProtectGPR(source2); - asmjit::x86::Gp RegLo = m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, source1, false, false); - asmjit::x86::Gp RegHi = m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, source1, true, false); - - if (m_RegWorkingSet.IsConst(source2)) + if (m_RegWorkingSet.IsConst(m_Opcode.rt)) { - m_Assembler.sub(RegLo, m_RegWorkingSet.GetMipsRegLo(source2)); - m_Assembler.sbb(RegHi, m_RegWorkingSet.GetMipsRegHi(source2)); + m_Assembler.sub(RegLo, m_RegWorkingSet.GetMipsRegLo(m_Opcode.rt)); + m_Assembler.sbb(RegHi, m_RegWorkingSet.GetMipsRegHi(m_Opcode.rt)); } - else if (m_RegWorkingSet.IsMapped(source2)) + else if (m_RegWorkingSet.IsMapped(m_Opcode.rt)) { - asmjit::x86::Gp HiReg = m_RegWorkingSet.Is64Bit(source2) ? m_RegWorkingSet.GetMipsRegMapHi(source2) : m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, source2, true, false); - m_Assembler.sub(RegLo, m_RegWorkingSet.GetMipsRegMapLo(source2)); + asmjit::x86::Gp HiReg = m_RegWorkingSet.Is64Bit(m_Opcode.rt) ? m_RegWorkingSet.GetMipsRegMapHi(m_Opcode.rt) : m_RegWorkingSet.Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); + m_Assembler.sub(RegLo, m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rt)); m_Assembler.sbb(RegHi, HiReg); } else { - m_Assembler.SubVariableFromX86reg(RegLo, &m_Reg.m_GPR[source2].W[0], CRegName::GPR_Lo[source2]); - m_Assembler.SbbVariableFromX86reg(RegHi, &m_Reg.m_GPR[source2].W[1], CRegName::GPR_Hi[source2]); + m_Assembler.SubVariableFromX86reg(RegLo, &m_Reg.m_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); + m_Assembler.SbbVariableFromX86reg(RegHi, &m_Reg.m_GPR[m_Opcode.rt].W[1], CRegName::GPR_Hi[m_Opcode.rt]); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); if (m_Opcode.rd != 0) { - m_RegWorkingSet.UnProtectGPR(source1); - m_RegWorkingSet.UnProtectGPR(source2); - m_RegWorkingSet.Map_GPR_64bit(m_Opcode.rd, source1); + m_RegWorkingSet.UnProtectGPR(m_Opcode.rs); + m_RegWorkingSet.UnProtectGPR(m_Opcode.rt); + m_RegWorkingSet.Map_GPR_64bit(m_Opcode.rd, m_Opcode.rs); m_Assembler.mov(m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rd), RegLo); m_Assembler.mov(m_RegWorkingSet.GetMipsRegMapHi(m_Opcode.rd), RegHi); }