From fba1c4bc3b50cb739cffaf18bcf94c9daebd35e8 Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 19 Dec 2024 09:57:25 +1030 Subject: [PATCH] Core: Fix up bug in CX86RecompilerOps::SPECIAL_AND --- .../Recompiler/x86/x86RecompilerOps.cpp | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index a402c6656..7c8da1074 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -5622,11 +5622,26 @@ void CX86RecompilerOps::SPECIAL_AND() } else if (m_RegWorkingSet.Is64Bit(MappedReg)) { - uint32_t Value = m_RegWorkingSet.GetMipsRegLo(ConstReg); - if (Value != 0) + uint32_t HiValue = m_RegWorkingSet.IsSigned(ConstReg) ? m_RegWorkingSet.GetMipsRegLo_S(ConstReg) >> 31 : 0; + uint32_t LoValue = m_RegWorkingSet.GetMipsRegLo(ConstReg); + + if (m_RegWorkingSet.Is64Bit(ConstReg)) { - m_RegWorkingSet.Map_GPR_32bit(m_Opcode.rd, m_RegWorkingSet.IsSigned(ConstReg), MappedReg); - m_Assembler.and_(m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rd), Value); + HiValue = m_RegWorkingSet.GetMipsRegHi(ConstReg); + } + if (HiValue != 0 || LoValue != 0) + { + if ((HiValue == 0 && (LoValue & 0x80000000) == 0) && (HiValue == 0xFFFFFFFF && (LoValue & 0x80000000) == 0x80000000)) + { + m_RegWorkingSet.Map_GPR_32bit(m_Opcode.rd, true, MappedReg); + m_Assembler.and_(m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rd), LoValue); + } + else + { + m_RegWorkingSet.Map_GPR_64bit(m_Opcode.rd, MappedReg); + m_Assembler.and_(m_RegWorkingSet.GetMipsRegMapHi(m_Opcode.rd), HiValue); + m_Assembler.and_(m_RegWorkingSet.GetMipsRegMapLo(m_Opcode.rd), LoValue); + } } else {