From 4dc3e35bb45f3a0efe1e9f0ccf2589ef3462bb3c Mon Sep 17 00:00:00 2001 From: zilmar Date: Thu, 4 Jan 2024 16:51:11 +1030 Subject: [PATCH] Core: Update CX86RecompilerOps::COP1_S_SQRT to work with fpu exceptions --- .../Recompiler/x86/x86RecompilerOps.cpp | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 6a6f8266e..04c138894 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -7856,11 +7856,33 @@ void CX86RecompilerOps::COP1_S_NEG() void CX86RecompilerOps::COP1_S_SQRT() { - CompileCop1Test(); - m_RegWorkingSet.FixRoundModel(CRegInfo::RoundDefault); - m_RegWorkingSet.Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - m_Assembler.fsqrt(); - m_RegWorkingSet.UnMap_FPR(m_Opcode.fd, true); + if (FpuExceptionInRecompiler()) + { + CompileInitFpuOperation(CRegInfo::RoundDefault); + if (m_RegWorkingSet.RegInStack(m_Opcode.fs, CRegInfo::FPU_Float)) + { + g_Notify->BreakPoint(__FILE__, __LINE__); + return; + } + asmjit::x86::Gp TempReg = m_RegWorkingSet.FPRValuePointer(m_Opcode.fs, CRegInfo::FPU_Float); + CompileCheckFPUInput32(TempReg); + m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(TempReg), false); + TempReg = m_RegWorkingSet.FPRValuePointer(m_Opcode.fs, CRegInfo::FPU_Float); + CompileCheckFPUInput32(TempReg); + m_RegWorkingSet.PrepareFPTopToBe(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); + m_Assembler.fsqrt(); + m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(TempReg), false); + CompileCheckFPUResult32(m_Opcode.fd); + m_RegWorkingSet.SetFPTopAs(m_Opcode.fd); + } + else + { + CompileCop1Test(); + m_RegWorkingSet.FixRoundModel(CRegInfo::RoundDefault); + m_RegWorkingSet.Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); + m_Assembler.fsqrt(); + m_RegWorkingSet.UnMap_FPR(m_Opcode.fd, true); + } } void CX86RecompilerOps::COP1_S_MOV()