From 8e94b3086b0aca375c7de95b8f232134bde4e9ed Mon Sep 17 00:00:00 2001 From: zilmar Date: Wed, 23 Nov 2022 14:46:55 +1030 Subject: [PATCH] Core: Change recompiler to use asmjit --- Source/3rdParty/asmjit/asmjit.vcxproj | 31 +- Source/3rdParty/asmjit/asmjit.vcxproj.filters | 99 +- .../N64System/Recompiler/CodeBlock.cpp | 50 +- .../N64System/Recompiler/CodeBlock.h | 18 +- .../N64System/Recompiler/CodeSection.cpp | 37 +- .../N64System/Recompiler/CodeSection.h | 2 +- .../N64System/Recompiler/ExitInfo.cpp | 2 +- .../N64System/Recompiler/ExitInfo.h | 2 +- .../N64System/Recompiler/FunctionInfo.cpp | 1 - .../N64System/Recompiler/FunctionInfo.h | 5 - .../N64System/Recompiler/JumpInfo.cpp | 2 - .../N64System/Recompiler/JumpInfo.h | 4 +- .../N64System/Recompiler/LoopAnalysis.cpp | 8 +- .../N64System/Recompiler/Recompiler.cpp | 6 +- .../Recompiler/x86/x86RecompilerOps.cpp | 2675 ++++++----- .../Recompiler/x86/x86RecompilerOps.h | 4 +- .../N64System/Recompiler/x86/x86RegInfo.cpp | 152 +- .../N64System/Recompiler/x86/x86RegInfo.h | 26 +- .../N64System/Recompiler/x86/x86ops.cpp | 3924 +++-------------- .../N64System/Recompiler/x86/x86ops.h | 215 +- Source/Project64-core/Project64-core.vcxproj | 3 + 21 files changed, 2143 insertions(+), 5123 deletions(-) diff --git a/Source/3rdParty/asmjit/asmjit.vcxproj b/Source/3rdParty/asmjit/asmjit.vcxproj index c4e4a2145..bd59c0877 100644 --- a/Source/3rdParty/asmjit/asmjit.vcxproj +++ b/Source/3rdParty/asmjit/asmjit.vcxproj @@ -38,6 +38,24 @@ + + + + + + + + + + + + + + + + + + @@ -63,6 +81,7 @@ + @@ -99,7 +118,6 @@ - @@ -111,6 +129,17 @@ + + + + + + + + + + + diff --git a/Source/3rdParty/asmjit/asmjit.vcxproj.filters b/Source/3rdParty/asmjit/asmjit.vcxproj.filters index 15525b966..6ae8cefc8 100644 --- a/Source/3rdParty/asmjit/asmjit.vcxproj.filters +++ b/Source/3rdParty/asmjit/asmjit.vcxproj.filters @@ -25,6 +25,12 @@ {6b84aaac-0a23-40c3-a433-b295187c29f6} + + {c917aef2-cca5-40a8-96ce-44c52b0be104} + + + {1887f342-a4a7-4afc-a943-f43721792e81} + @@ -210,9 +216,6 @@ Header Files\x86 - - Header Files\x86 - Header Files\x86 @@ -240,6 +243,63 @@ Header Files\x86 + + Header Files\core + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + + + Header Files\arm + @@ -383,5 +443,38 @@ Source Files\x86 + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + + + Source Files\arm + \ No newline at end of file diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp index 638d7ce99..87bea087a 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.cpp @@ -13,16 +13,19 @@ extern "C" void __clear_cache_android(uint8_t * begin, uint8_t * end); #endif -CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation) : +CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter) : m_MMU(MMU), m_VAddrEnter(VAddrEnter), m_VAddrFirst(VAddrEnter), m_VAddrLast(VAddrEnter), - m_CompiledLocation(CompiledLocation), + m_CompiledLocation(nullptr), m_EnterSection(nullptr), m_RecompilerOps(nullptr), m_Test(1) { + m_Environment = asmjit::Environment::host(); + m_CodeHolder.init(m_Environment); + m_CodeHolder.setErrorHandler(this); #if defined(__arm__) || defined(_M_ARM) // Make sure function starts at an odd address so that the system knows it is in thumb mode if (((uint32_t)m_CompiledLocation % 2) == 0) @@ -50,7 +53,7 @@ CCodeBlock::CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * Compi m_Sections.push_back(baseSection); baseSection->AddParent(nullptr); - baseSection->m_CompiledLocation = (uint8_t *)-1; + baseSection->m_EnterLabel = asmjit::Label(1); baseSection->m_Cont.JumpPC = VAddrEnter; baseSection->m_Cont.FallThrough = true; baseSection->m_Cont.RegSet = baseSection->m_RegEnter; @@ -857,12 +860,6 @@ bool CCodeBlock::AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & bool CCodeBlock::Compile() { - Log("====== Code block ======"); - Log("Native entry point: %X", CompiledLocation()); - Log("Start of block: %X", VAddrEnter()); - Log("Number of sections: %d", NoOfSections()); - Log("====== Recompiled code ======"); - m_RecompilerOps->EnterCodeBlock(); if (g_System->bLinkBlocks()) { @@ -877,7 +874,6 @@ bool CCodeBlock::Compile() } } m_RecompilerOps->CompileExitCode(); - m_CompiledLocationEnd = *g_RecompPos; uint32_t BlockSize = (VAddrLast() - VAddrFirst()) + 4; uint8_t * BlockPtr = m_MMU.MemoryPtr(VAddrFirst(), BlockSize, true); @@ -887,12 +883,35 @@ bool CCodeBlock::Compile() return false; } MD5(BlockPtr, BlockSize).get_digest(m_Hash); -#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM)) - __clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocationEnd); -#endif return true; } +uint32_t CCodeBlock::Finilize(uint8_t * CompiledLocation) +{ + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string CodeLog = m_CodeLog; + m_CodeLog.clear(); + Log("====== Code block ======"); + Log("Native entry point: %X", CompiledLocation); + Log("Start of block: %X", VAddrEnter()); + Log("Number of sections: %d", NoOfSections()); + Log("====== Recompiled code ======"); + m_CodeLog += CodeLog; + } + + m_CompiledLocation = CompiledLocation; + m_CodeHolder.relocateToBase((uint64_t)m_CompiledLocation); + size_t codeSize = m_CodeHolder.codeSize(); + m_CodeHolder.copyFlattenedData(m_CompiledLocation, codeSize, asmjit::CopySectionFlags::kPadSectionBuffer); + *g_RecompPos += codeSize; + +#if defined(ANDROID) && (defined(__arm__) || defined(_M_ARM)) + __clear_cache((uint8_t *)((uint32_t)m_CompiledLocation & ~1), m_CompiledLocation + codeSize); +#endif + return codeSize; +} + uint32_t CCodeBlock::NextTest() { uint32_t next_test = m_Test; @@ -923,3 +942,8 @@ void CCodeBlock::Log(_Printf_format_string_ const char * Text, ...) #pragma warning(pop) va_end(args); } + +void CCodeBlock::handleError(asmjit::Error /*err*/, const char * /*message*/, asmjit::BaseEmitter * /*origin*/) +{ + g_Notify->BreakPoint(__FILE__, __LINE__); +} diff --git a/Source/Project64-core/N64System/Recompiler/CodeBlock.h b/Source/Project64-core/N64System/Recompiler/CodeBlock.h index 2f0bfe81f..2a4ce3c08 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeBlock.h +++ b/Source/Project64-core/N64System/Recompiler/CodeBlock.h @@ -9,14 +9,20 @@ class CMipsMemoryVM; -class CCodeBlock +class CCodeBlock : + public asmjit::ErrorHandler { public: - CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter, uint8_t * CompiledLocation); + CCodeBlock(CMipsMemoryVM & MMU, uint32_t VAddrEnter); ~CCodeBlock(); bool Compile(); + uint32_t Finilize(uint8_t * CompiledLocation); + asmjit::CodeHolder & CodeHolder(void) + { + return m_CodeHolder; + } uint32_t VAddrEnter() const { return m_VAddrEnter; @@ -33,10 +39,6 @@ public: { return m_CompiledLocation; } - uint8_t * CompiledLocationEnd() const - { - return m_CompiledLocationEnd; - } int32_t NoOfSections() const { return (int32_t)m_Sections.size() - 1; @@ -101,12 +103,14 @@ private: void LogSectionInfo(); bool SetSection(CCodeSection *& Section, CCodeSection * CurrentSection, uint32_t TargetPC, bool LinkAllowed, uint32_t CurrentPC); bool AnalyzeInstruction(uint32_t PC, uint32_t & TargetPC, uint32_t & ContinuePC, bool & LikelyBranch, bool & IncludeDelaySlot, bool & EndBlock, bool & PermLoop); + void handleError(asmjit::Error err, const char* message, asmjit::BaseEmitter* origin); + asmjit::Environment m_Environment; + asmjit::CodeHolder m_CodeHolder; uint32_t m_VAddrEnter; uint32_t m_VAddrFirst; uint32_t m_VAddrLast; uint8_t * m_CompiledLocation; - uint8_t * m_CompiledLocationEnd; typedef std::map SectionMap; typedef std::list SectionList; diff --git a/Source/Project64-core/N64System/Recompiler/CodeSection.cpp b/Source/Project64-core/N64System/Recompiler/CodeSection.cpp index 6a12928fa..92dcc355c 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeSection.cpp +++ b/Source/Project64-core/N64System/Recompiler/CodeSection.cpp @@ -24,7 +24,6 @@ CCodeSection::CCodeSection(CCodeBlock & CodeBlock, uint32_t EnterPC, uint32_t ID m_LinkAllowed(LinkAllowed), m_Test(0), m_Test2(0), - m_CompiledLocation(nullptr), m_InLoop(false), m_DelaySlot(false), m_RecompilerOps(CodeBlock.RecompilerOps()), @@ -48,7 +47,7 @@ void CCodeSection::GenerateSectionLinkage() for (i = 0; i < 2; i++) { - if (JumpInfo[i]->LinkLocation == nullptr && + if (!JumpInfo[i]->LinkLocation.isValid() && JumpInfo[i]->FallThrough == false) { JumpInfo[i]->TargetPC = (uint32_t)-1; @@ -75,7 +74,7 @@ void CCodeSection::GenerateSectionLinkage() { for (i = 0; i < 2; i++) { - if (JumpInfo[i]->LinkLocation == nullptr && JumpInfo[i]->FallThrough == false) + if (!JumpInfo[i]->LinkLocation.isValid() && JumpInfo[i]->FallThrough == false) { if (TargetSection[i]) { @@ -107,11 +106,11 @@ void CCodeSection::GenerateSectionLinkage() } else { - if (m_Cont.LinkLocation == nullptr && m_Cont.FallThrough == false) + if (!m_Cont.LinkLocation.isValid() && m_Cont.FallThrough == false) { m_ContinueSection = nullptr; } - if (m_Jump.LinkLocation == nullptr && m_Jump.FallThrough == false) + if (!m_Jump.LinkLocation.isValid() && m_Jump.FallThrough == false) { m_JumpSection = nullptr; } @@ -135,7 +134,7 @@ void CCodeSection::GenerateSectionLinkage() continue; } - if (TargetSection[i]->m_CompiledLocation != nullptr) + if (TargetSection[i]->m_EnterLabel.isValid()) { JumpInfo[i]->FallThrough = false; m_RecompilerOps->LinkJump(*JumpInfo[i], TargetSection[i]->m_SectionID); @@ -178,8 +177,7 @@ void CCodeSection::GenerateSectionLinkage() for (SECTION_LIST::iterator iter = TargetSection[i]->m_ParentSection.begin(); iter != TargetSection[i]->m_ParentSection.end(); iter++) { CCodeSection * Parent = *iter; - - if (Parent->m_CompiledLocation != nullptr) + if (Parent->m_EnterLabel.isValid()) { continue; } @@ -224,10 +222,9 @@ void CCodeSection::GenerateSectionLinkage() } } - //CodeLog("Section %d",m_SectionID); for (i = 0; i < 2; i++) { - if (JumpInfo[i]->LinkLocation == nullptr) + if (!JumpInfo[i]->LinkLocation.isValid()) { continue; } @@ -242,7 +239,7 @@ void CCodeSection::GenerateSectionLinkage() { g_Notify->BreakPoint(__FILE__, __LINE__); } - if (TargetSection[i]->m_CompiledLocation == nullptr) + if (!TargetSection[i]->m_EnterLabel.isValid()) { TargetSection[i]->GenerateNativeCode(m_CodeBlock.NextTest()); } @@ -304,7 +301,7 @@ bool CCodeSection::ParentContinue() for (SECTION_LIST::iterator iter = m_ParentSection.begin(); iter != m_ParentSection.end(); iter++) { CCodeSection * Parent = *iter; - if (Parent->m_CompiledLocation != nullptr) + if (Parent->m_EnterLabel.isValid()) { continue; } @@ -325,7 +322,7 @@ bool CCodeSection::ParentContinue() bool CCodeSection::GenerateNativeCode(uint32_t Test) { - if (m_CompiledLocation != nullptr) + if (m_EnterLabel.isValid()) { if (m_Test == Test) { @@ -347,7 +344,8 @@ bool CCodeSection::GenerateNativeCode(uint32_t Test) { return false; } - m_CompiledLocation = *g_RecompPos; + m_EnterLabel = m_RecompilerOps->Assembler().newLabel(); + m_RecompilerOps->Assembler().bind(m_EnterLabel); m_RecompilerOps->SetRegWorkingSet(m_RegEnter); m_RecompilerOps->SetCurrentPC(m_EnterPC); m_RecompilerOps->SetNextStepType(m_DelaySlot ? PIPELINE_STAGE_JUMP : PIPELINE_STAGE_NORMAL); @@ -988,19 +986,11 @@ void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection) CCodeSection * CodeSection = *iter; if (CodeSection->m_ContinueSection == this) { - if (CodeSection->m_CompiledLocation) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } CodeSection->m_ContinueSection = nullptr; } if (CodeSection->m_JumpSection == this) { - if (CodeSection->m_CompiledLocation) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } CodeSection->m_JumpSection = nullptr; } } @@ -1026,7 +1016,7 @@ void CCodeSection::UnlinkParent(CCodeSection * Parent, bool ContinueSection) bool CCodeSection::IsAllParentLoops(CCodeSection * Parent, bool IgnoreIfCompiled, uint32_t Test) { - if (IgnoreIfCompiled && Parent->m_CompiledLocation != nullptr) + if (IgnoreIfCompiled && Parent->m_EnterLabel.isValid()) { return true; } @@ -1103,7 +1093,6 @@ void CCodeSection::DisplaySectionInformation() { m_CodeBlock.Log("End PC: 0x%X", m_EndPC); } - m_CodeBlock.Log("CompiledLocation: 0x%X", m_CompiledLocation); if (g_System->bLinkBlocks() && !m_ParentSection.empty()) { stdstr ParentList; diff --git a/Source/Project64-core/N64System/Recompiler/CodeSection.h b/Source/Project64-core/N64System/Recompiler/CodeSection.h index 5456f72ec..bf92e387c 100644 --- a/Source/Project64-core/N64System/Recompiler/CodeSection.h +++ b/Source/Project64-core/N64System/Recompiler/CodeSection.h @@ -39,7 +39,7 @@ public: bool m_LinkAllowed; uint32_t m_Test; uint32_t m_Test2; - uint8_t * m_CompiledLocation; + asmjit::Label m_EnterLabel; bool m_InLoop; bool m_DelaySlot; CRecompilerOps *& m_RecompilerOps; diff --git a/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp b/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp index 031bae668..1c1fe9447 100644 --- a/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/ExitInfo.cpp @@ -6,7 +6,7 @@ CExitInfo::CExitInfo(CCodeBlock & CodeBlock) : ID(0), TargetPC(0), - JumpLoc(nullptr), ExitRegSet(CodeBlock, CodeBlock.RecompilerOps()->Assembler()) { + JumpLabel = CodeBlock.RecompilerOps()->Assembler().newLabel(); } diff --git a/Source/Project64-core/N64System/Recompiler/ExitInfo.h b/Source/Project64-core/N64System/Recompiler/ExitInfo.h index dbeafb788..870d11432 100644 --- a/Source/Project64-core/N64System/Recompiler/ExitInfo.h +++ b/Source/Project64-core/N64System/Recompiler/ExitInfo.h @@ -32,7 +32,7 @@ struct CExitInfo CRegInfo ExitRegSet; ExitReason Reason; PIPELINE_STAGE PipelineStage; - uint32_t * JumpLoc; // 32-bit jump + asmjit::Label JumpLabel; }; typedef std::list EXIT_LIST; diff --git a/Source/Project64-core/N64System/Recompiler/FunctionInfo.cpp b/Source/Project64-core/N64System/Recompiler/FunctionInfo.cpp index 8dce6549d..dbc14e253 100644 --- a/Source/Project64-core/N64System/Recompiler/FunctionInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/FunctionInfo.cpp @@ -7,7 +7,6 @@ CCompiledFunc::CCompiledFunc(const CCodeBlock & CodeBlock) : m_MaxPC(CodeBlock.VAddrLast()), m_Hash(CodeBlock.Hash()), m_Function((Func)CodeBlock.CompiledLocation()), - m_FunctionEnd(CodeBlock.CompiledLocationEnd()), m_Next(nullptr) { m_MemContents[0] = CodeBlock.MemContents(0); diff --git a/Source/Project64-core/N64System/Recompiler/FunctionInfo.h b/Source/Project64-core/N64System/Recompiler/FunctionInfo.h index 452561c99..a6a74d3c3 100644 --- a/Source/Project64-core/N64System/Recompiler/FunctionInfo.h +++ b/Source/Project64-core/N64System/Recompiler/FunctionInfo.h @@ -24,10 +24,6 @@ public: { return m_Function; } - const uint8_t * FunctionEnd() const - { - return m_FunctionEnd; - } const MD5Digest & Hash() const { return m_Hash; @@ -59,7 +55,6 @@ private: uint32_t m_EnterPC; uint32_t m_MinPC; uint32_t m_MaxPC; - uint8_t * m_FunctionEnd; MD5Digest m_Hash; Func m_Function; diff --git a/Source/Project64-core/N64System/Recompiler/JumpInfo.cpp b/Source/Project64-core/N64System/Recompiler/JumpInfo.cpp index c8f26d273..eb764fa89 100644 --- a/Source/Project64-core/N64System/Recompiler/JumpInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/JumpInfo.cpp @@ -10,8 +10,6 @@ CJumpInfo::CJumpInfo(CCodeBlock & CodeBlock) : TargetPC = (uint32_t)-1; JumpPC = (uint32_t)-1; BranchLabel = ""; - LinkLocation = nullptr; - LinkLocation2 = nullptr; FallThrough = false; PermLoop = false; DoneDelaySlot = false; diff --git a/Source/Project64-core/N64System/Recompiler/JumpInfo.h b/Source/Project64-core/N64System/Recompiler/JumpInfo.h index 594e97ff7..6d9990e1a 100644 --- a/Source/Project64-core/N64System/Recompiler/JumpInfo.h +++ b/Source/Project64-core/N64System/Recompiler/JumpInfo.h @@ -9,8 +9,8 @@ struct CJumpInfo uint32_t TargetPC; uint32_t JumpPC; std::string BranchLabel; - uint32_t * LinkLocation; - uint32_t * LinkLocation2; + asmjit::Label LinkLocation; + asmjit::Label LinkLocation2; bool FallThrough; bool PermLoop; bool DoneDelaySlot; diff --git a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp index 723809f82..49cf9eb0f 100644 --- a/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp +++ b/Source/Project64-core/N64System/Recompiler/LoopAnalysis.cpp @@ -76,7 +76,7 @@ bool LoopAnalysis::SetupEnterSection(CCodeSection * Section, bool & bChanged, bo return true; } - m_CodeBlock.Log("%s: Block EnterPC: %X Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, m_CodeBlock.VAddrEnter(), Section->m_SectionID, m_Test, Section->m_Test, Section->m_CompiledLocation); + m_CodeBlock.Log("%s: Block EnterPC: %X Section ID %d Test: %X Section Test: %X ", __FUNCTION__, m_CodeBlock.VAddrEnter(), Section->m_SectionID, m_Test, Section->m_Test); bool bFirstParent = true; CRegInfo RegEnter(m_CodeBlock, m_CodeBlock.RecompilerOps()->Assembler()); @@ -84,10 +84,10 @@ bool LoopAnalysis::SetupEnterSection(CCodeSection * Section, bool & bChanged, bo { CCodeSection * Parent = *iter; - m_CodeBlock.Log("%s: Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation); - if (Parent->m_Test != m_Test && (m_EnterSection != Section || Parent->m_CompiledLocation == nullptr) && Parent->m_InLoop) + m_CodeBlock.Log("%s: Parent Section ID %d Test: %X Section Test: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test); + if (Parent->m_Test != m_Test && (m_EnterSection != Section || !Parent->m_EnterLabel.isValid()) && Parent->m_InLoop) { - m_CodeBlock.Log("%s: Ignore Parent Section ID %d Test: %X Section Test: %X CompiledLocation: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test, Parent->m_CompiledLocation); + m_CodeBlock.Log("%s: Ignore Parent Section ID %d Test: %X Section Test: %X", __FUNCTION__, Parent->m_SectionID, m_Test, Parent->m_Test); bSkipedSection = true; continue; } diff --git a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp index 81b9ff0ec..00aecc6c3 100644 --- a/Source/Project64-core/N64System/Recompiler/Recompiler.cpp +++ b/Source/Project64-core/N64System/Recompiler/Recompiler.cpp @@ -374,7 +374,7 @@ CCompiledFunc * CRecompiler::CompileCode() CheckRecompMem(); WriteTrace(TraceRecompiler, TraceDebug, "Compile Block-Start: Program Counter: %X pAddr: %X", PROGRAM_COUNTER, pAddr); - CCodeBlock CodeBlock(m_MMU, PROGRAM_COUNTER, *g_RecompPos); + CCodeBlock CodeBlock(m_MMU, PROGRAM_COUNTER); if (!CodeBlock.Compile()) { return nullptr; @@ -385,6 +385,8 @@ CCompiledFunc * CRecompiler::CompileCode() ShowMemUsed(); } + uint32_t CodeLen = CodeBlock.Finilize(*g_RecompPos); + *g_RecompPos += CodeLen; LogCodeBlock(CodeBlock); CCompiledFunc * Func = new CCompiledFunc(CodeBlock); @@ -403,7 +405,7 @@ CCompiledFunc * CRecompiler::CompileCode() WriteTrace(TraceRecompiler, TraceDebug, "Info->Function() = %X", Func->Function()); std::string dumpline; uint32_t start_address = (uint32_t)(Func->Function()) & ~1; - for (uint8_t * ptr = (uint8_t *)start_address; ptr < CodeBlock.CompiledLocationEnd(); ptr++) + for (uint8_t * ptr = (uint8_t *)start_address, * ptr_end = ((uint8_t *)start_address) + CodeLen; ptr < ptr_end; ptr++) { if (dumpline.empty()) { diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp index 325907e95..ea85fdf4d 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.cpp @@ -213,7 +213,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) m_Assembler.MoveConstToX86reg(asmjit::x86::ecx, (uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); #else - m_Assembler.PushImm32((uint32_t)g_BaseSystem); + m_Assembler.push((uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); #endif @@ -233,7 +233,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) m_Assembler.MoveConstToX86reg(asmjit::x86::ecx, (uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); #else - m_Assembler.PushImm32((uint32_t)g_BaseSystem); + m_Assembler.push((uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); #endif @@ -262,7 +262,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) m_Assembler.MoveConstToX86reg(asmjit::x86::ecx, (uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); #else - m_Assembler.PushImm32((uint32_t)g_BaseSystem); + m_Assembler.push((uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); #endif @@ -283,7 +283,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) m_Assembler.MoveConstToX86reg(asmjit::x86::ecx, (uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); #else - m_Assembler.PushImm32((uint32_t)g_BaseSystem); + m_Assembler.push((uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); #endif @@ -299,7 +299,7 @@ void CX86RecompilerOps::PreCompileOpcode(void) m_Assembler.MoveConstToX86reg(asmjit::x86::ecx, (uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); #else - m_Assembler.PushImm32((uint32_t)g_BaseSystem); + m_Assembler.push((uint32_t)g_BaseSystem); m_Assembler.CallFunc(AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem"); m_Assembler.AddConstToX86Reg(asmjit::x86::esp, 4); #endif @@ -352,21 +352,21 @@ void CX86RecompilerOps::CompileReadTLBMiss(uint32_t VirtualAddress, const asmjit { m_Assembler.MoveConstToVariable(g_TLBLoadAddress, "TLBLoadAddress", VirtualAddress); m_Assembler.CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBReadMiss, false, &CX86Ops::JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBReadMiss, false, &CX86Ops::JeLabel); } void CX86RecompilerOps::CompileReadTLBMiss(const asmjit::x86::Gp & AddressReg, const asmjit::x86::Gp & LookUpReg) { m_Assembler.MoveX86regToVariable(g_TLBLoadAddress, "TLBLoadAddress", AddressReg); m_Assembler.CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBReadMiss, false, &CX86Ops::JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBReadMiss, false, &CX86Ops::JeLabel); } void CX86RecompilerOps::CompileWriteTLBMiss(const asmjit::x86::Gp & AddressReg, const asmjit::x86::Gp & LookUpReg) { m_Assembler.MoveX86regToVariable(&g_TLBStoreAddress, "g_TLBStoreAddress", AddressReg); m_Assembler.CompConstToX86reg(LookUpReg, (uint32_t)-1); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBWriteMiss, false, &CX86Ops::JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_TLBWriteMiss, false, &CX86Ops::JeLabel); } // Trap functions @@ -500,8 +500,8 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool { m_Section->m_Jump.BranchLabel = stdstr_f("Exit_%X_jump_%X", m_Section->m_EnterPC, m_Section->m_Jump.TargetPC); } - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_Section->m_Jump.DoneDelaySlot = false; m_Section->m_Cont.JumpPC = m_CompilePC; m_Section->m_Cont.TargetPC = m_CompilePC + 8; @@ -513,8 +513,8 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool { m_Section->m_Cont.BranchLabel = stdstr_f("Exit_%X_continue_%X", m_Section->m_EnterPC, m_Section->m_Cont.TargetPC); } - m_Section->m_Cont.LinkLocation = nullptr; - m_Section->m_Cont.LinkLocation2 = nullptr; + m_Section->m_Cont.LinkLocation = asmjit::Label(); + m_Section->m_Cont.LinkLocation2 = asmjit::Label(); m_Section->m_Cont.DoneDelaySlot = false; if (m_Section->m_Jump.TargetPC < m_Section->m_Cont.TargetPC) { @@ -551,14 +551,14 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool } if (!m_Section->m_Jump.FallThrough && !m_Section->m_Cont.FallThrough) { - if (m_Section->m_Jump.LinkLocation != nullptr) + if (m_Section->m_Jump.LinkLocation.isValid()) { m_CodeBlock.Log(""); m_CodeBlock.Log(" %s:", m_Section->m_Jump.BranchLabel.c_str()); LinkJump(m_Section->m_Jump); m_Section->m_Jump.FallThrough = true; } - else if (m_Section->m_Cont.LinkLocation != nullptr) + else if (m_Section->m_Cont.LinkLocation.isValid()) { m_CodeBlock.Log(""); m_CodeBlock.Log(" %s:", m_Section->m_Cont.BranchLabel.c_str()); @@ -568,10 +568,10 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool } if ((m_CompilePC & 0xFFC) == 0xFFC) { - uint8_t * DelayLinkLocation = nullptr; + asmjit::Label DelayLinkLocation; if (m_Section->m_Jump.FallThrough) { - if (m_Section->m_Jump.LinkLocation != nullptr || m_Section->m_Jump.LinkLocation2 != nullptr) + if (m_Section->m_Jump.LinkLocation.isValid() || m_Section->m_Jump.LinkLocation2.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -579,46 +579,45 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool } else if (m_Section->m_Cont.FallThrough) { - if (m_Section->m_Cont.LinkLocation != nullptr || m_Section->m_Cont.LinkLocation2 != nullptr) + if (m_Section->m_Cont.LinkLocation.isValid() || m_Section->m_Cont.LinkLocation2.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } m_Assembler.MoveConstToVariable(&g_System->m_JumpToLocation, "System::m_JumpToLocation", m_Section->m_Cont.TargetPC); } - if (m_Section->m_Jump.LinkLocation != nullptr || m_Section->m_Jump.LinkLocation2 != nullptr) + if (m_Section->m_Jump.LinkLocation.isValid() || m_Section->m_Jump.LinkLocation2.isValid()) { - m_Assembler.JmpLabel8("DoDelaySlot", 0); - if (DelayLinkLocation != nullptr) + if (DelayLinkLocation.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } - DelayLinkLocation = (uint8_t *)(*g_RecompPos - 1); + DelayLinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel("DoDelaySlot", DelayLinkLocation); m_CodeBlock.Log(" "); m_CodeBlock.Log(" %s:", m_Section->m_Jump.BranchLabel.c_str()); LinkJump(m_Section->m_Jump); m_Assembler.MoveConstToVariable(&g_System->m_JumpToLocation, "System::m_JumpToLocation", m_Section->m_Jump.TargetPC); } - if (m_Section->m_Cont.LinkLocation != nullptr || m_Section->m_Cont.LinkLocation2 != nullptr) + if (m_Section->m_Cont.LinkLocation.isValid() || m_Section->m_Cont.LinkLocation2.isValid()) { - m_Assembler.JmpLabel8("DoDelaySlot", 0); - if (DelayLinkLocation != nullptr) + if (DelayLinkLocation.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } - DelayLinkLocation = (uint8_t *)(*g_RecompPos - 1); + DelayLinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel("DoDelaySlot", DelayLinkLocation); m_CodeBlock.Log(" "); m_CodeBlock.Log(" %s:", m_Section->m_Cont.BranchLabel.c_str()); LinkJump(m_Section->m_Cont); m_Assembler.MoveConstToVariable(&g_System->m_JumpToLocation, "System::m_JumpToLocation", m_Section->m_Cont.TargetPC); } - if (DelayLinkLocation) + if (DelayLinkLocation.isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" DoDelaySlot:"); - m_Assembler.SetJump8(DelayLinkLocation, *g_RecompPos); + m_Assembler.bind(DelayLinkLocation); } OverflowDelaySlot(false); return; @@ -681,10 +680,10 @@ void CX86RecompilerOps::Compile_Branch(RecompilerBranchCompare CompareType, bool if (!JumpInfo->DoneDelaySlot) { FallInfo->FallThrough = false; - m_Assembler.JmpLabel32(FallInfo->BranchLabel.c_str(), 0); - FallInfo->LinkLocation = (uint32_t *)(*g_RecompPos - 4); + FallInfo->LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(FallInfo->BranchLabel.c_str(), FallInfo->LinkLocation); - if (JumpInfo->LinkLocation != nullptr) + if (JumpInfo->LinkLocation.isValid()) { m_CodeBlock.Log(" %s:", JumpInfo->BranchLabel.c_str()); LinkJump(*JumpInfo); @@ -787,11 +786,11 @@ void CX86RecompilerOps::Compile_BranchLikely(RecompilerBranchCompare CompareType } m_Section->m_Jump.FallThrough = true; - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_Section->m_Cont.FallThrough = false; - m_Section->m_Cont.LinkLocation = nullptr; - m_Section->m_Cont.LinkLocation2 = nullptr; + m_Section->m_Cont.LinkLocation = asmjit::Label(); + m_Section->m_Cont.LinkLocation2 = asmjit::Label(); if (Link) { UnMap_GPR(31, false); @@ -808,13 +807,13 @@ void CX86RecompilerOps::Compile_BranchLikely(RecompilerBranchCompare CompareType { if (m_Section->m_Cont.FallThrough) { - if (m_Section->m_Jump.LinkLocation != nullptr) + if (m_Section->m_Jump.LinkLocation.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } } - if (m_Section->m_Jump.LinkLocation != nullptr || m_Section->m_Jump.FallThrough) + if (m_Section->m_Jump.LinkLocation.isValid() || m_Section->m_Jump.FallThrough) { LinkJump(m_Section->m_Jump); @@ -848,7 +847,7 @@ void CX86RecompilerOps::Compile_BranchLikely(RecompilerBranchCompare CompareType { if (m_Section->m_Cont.FallThrough) { - if (m_Section->m_Jump.LinkLocation != nullptr) + if (m_Section->m_Jump.LinkLocation.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -873,7 +872,7 @@ void CX86RecompilerOps::Compile_BranchLikely(RecompilerBranchCompare CompareType void CX86RecompilerOps::BNE_Compare() { - uint8_t * Jump = nullptr; + asmjit::Label Jump; if (IsKnown(m_Opcode.rs) && IsKnown(m_Opcode.rt)) { @@ -900,61 +899,60 @@ void CX86RecompilerOps::BNE_Compare() ProtectGPR(m_Opcode.rt); if (Is64Bit(m_Opcode.rs) || Is64Bit(m_Opcode.rt)) { - m_Assembler.CompX86RegToX86Reg( + m_Assembler.cmp( Is32Bit(m_Opcode.rs) ? Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false) : GetMipsRegMapHi(m_Opcode.rs), Is32Bit(m_Opcode.rt) ? Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false) : GetMipsRegMapHi(m_Opcode.rt)); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } else { - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -983,34 +981,33 @@ void CX86RecompilerOps::BNE_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } m_Assembler.CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } else @@ -1018,20 +1015,20 @@ void CX86RecompilerOps::BNE_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -1076,13 +1073,13 @@ void CX86RecompilerOps::BNE_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } if (IsConst(KnownReg)) @@ -1095,41 +1092,41 @@ void CX86RecompilerOps::BNE_Compare() } if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); - if (Jump) + if (Jump.isValid()) { - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); if (g_System->b32BitCore()) { - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } } @@ -1143,13 +1140,13 @@ void CX86RecompilerOps::BNE_Compare() m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rs].W[1], CRegName::GPR_Hi[m_Opcode.rs]); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } @@ -1157,39 +1154,40 @@ void CX86RecompilerOps::BNE_Compare() m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs]); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - if (Jump) + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + if (Jump.isValid()) { - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); if (g_System->b32BitCore()) { - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); } } } @@ -1197,7 +1195,7 @@ void CX86RecompilerOps::BNE_Compare() void CX86RecompilerOps::BEQ_Compare() { - uint8_t * Jump = nullptr; + asmjit::Label Jump; if (IsKnown(m_Opcode.rs) && IsKnown(m_Opcode.rt)) { @@ -1225,60 +1223,59 @@ void CX86RecompilerOps::BEQ_Compare() ProtectGPR(m_Opcode.rs); ProtectGPR(m_Opcode.rt); - m_Assembler.CompX86RegToX86Reg( + m_Assembler.cmp( Is32Bit(m_Opcode.rs) ? Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false) : GetMipsRegMapHi(m_Opcode.rs), Is32Bit(m_Opcode.rt) ? Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false) : GetMipsRegMapHi(m_Opcode.rt)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else { - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -1307,34 +1304,33 @@ void CX86RecompilerOps::BEQ_Compare() } if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } m_Assembler.CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else @@ -1342,20 +1338,20 @@ void CX86RecompilerOps::BEQ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -1400,13 +1396,13 @@ void CX86RecompilerOps::BEQ_Compare() } if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } } if (IsConst(KnownReg)) @@ -1419,33 +1415,33 @@ void CX86RecompilerOps::BEQ_Compare() } if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - if (Jump) + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + if (Jump.isValid()) { - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else @@ -1457,52 +1453,53 @@ void CX86RecompilerOps::BEQ_Compare() m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rt].W[1], CRegName::GPR_Hi[m_Opcode.rt]); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("Continue", Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } } m_Assembler.CompX86regToVariable(Map_TempReg(Reg, m_Opcode.rs, false, false), &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - if (Jump) + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + if (Jump.isValid()) { - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -1543,20 +1540,20 @@ void CX86RecompilerOps::BGTZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JleLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JleLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else if (IsUnknown(m_Opcode.rs) && g_System->b32BitCore()) @@ -1564,25 +1561,25 @@ void CX86RecompilerOps::BGTZ_Compare() m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs], 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JleLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JleLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else { - uint8_t * Jump = nullptr; + asmjit::Label Jump; if (IsMapped(m_Opcode.rs)) { @@ -1594,24 +1591,24 @@ void CX86RecompilerOps::BGTZ_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JgLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + Jump = m_Assembler.newLabel(); + m_Assembler.JgLabel("Continue", Jump); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JlLabel8("Continue", 0); - Jump = *g_RecompPos - 1; - m_Assembler.JgLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + Jump = m_Assembler.newLabel(); + m_Assembler.JlLabel("Continue", Jump); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JgLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } if (IsMapped(m_Opcode.rs)) @@ -1624,24 +1621,22 @@ void CX86RecompilerOps::BGTZ_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Assembler.bind(Jump); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + m_Assembler.bind(Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } } } @@ -1697,25 +1692,25 @@ void CX86RecompilerOps::BLEZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JleLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else { - uint8_t * Jump = nullptr; + asmjit::Label Jump; if (IsMapped(m_Opcode.rs)) { @@ -1727,24 +1722,24 @@ void CX86RecompilerOps::BLEZ_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JlLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + Jump = m_Assembler.newLabel(); + m_Assembler.JlLabel("Continue", Jump); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgLabel8("Continue", 0); - Jump = *g_RecompPos - 1; - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + Jump = m_Assembler.newLabel(); + m_Assembler.JgLabel("Continue", Jump); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } if (IsMapped(m_Opcode.rs)) @@ -1757,89 +1752,86 @@ void CX86RecompilerOps::BLEZ_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Assembler.bind(Jump); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); + m_Assembler.bind(Jump); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32("BranchToJump", 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel("BranchToJump", m_Section->m_Jump.LinkLocation2); } } } else { - uint8_t * Jump = nullptr; + asmjit::Label Jump; if (!g_System->b32BitCore()) { m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[1], CRegName::GPR_Hi[m_Opcode.rs], 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JlLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + Jump = m_Assembler.newLabel(); + m_Assembler.JlLabel("Continue", Jump); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgLabel8("Continue", 0); - Jump = *g_RecompPos - 1; - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + Jump = m_Assembler.newLabel(); + m_Assembler.JgLabel("Continue", Jump); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs], 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); if (g_System->b32BitCore()) { - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); } - if (Jump) + if (Jump.isValid()) { - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - if (Jump) + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation2); + if (Jump.isValid()) { - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32("BranchToJump", 0); - m_Section->m_Jump.LinkLocation2 = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation2); + m_Section->m_Jump.LinkLocation2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel("BranchToJump", m_Section->m_Jump.LinkLocation2); } } else @@ -1847,20 +1839,20 @@ void CX86RecompilerOps::BLEZ_Compare() m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs], 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JleLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JleLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -1909,20 +1901,20 @@ void CX86RecompilerOps::BLTZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapHi(m_Opcode.rs), 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else if (IsSigned(m_Opcode.rs)) @@ -1930,20 +1922,20 @@ void CX86RecompilerOps::BLTZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), 0); if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JgeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else @@ -1964,20 +1956,20 @@ void CX86RecompilerOps::BLTZ_Compare() } if (m_Section->m_Jump.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else if (m_Section->m_Cont.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else { - m_Assembler.JlLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } } } @@ -2017,20 +2009,20 @@ void CX86RecompilerOps::BGEZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapHi(m_Opcode.rs), 0); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else if (IsSigned(m_Opcode.rs)) @@ -2038,20 +2030,20 @@ void CX86RecompilerOps::BGEZ_Compare() m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), 0); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } else @@ -2072,20 +2064,20 @@ void CX86RecompilerOps::BGEZ_Compare() } if (m_Section->m_Cont.FallThrough) { - m_Assembler.JgeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JgeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JlLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JlLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } } @@ -2095,20 +2087,20 @@ void CX86RecompilerOps::COP1_BCF_Compare() m_Assembler.TestVariable(&_FPCR[31], "_FPCR[31]", FPCSR_C); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JneLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } @@ -2117,20 +2109,20 @@ void CX86RecompilerOps::COP1_BCT_Compare() m_Assembler.TestVariable(&_FPCR[31], "_FPCR[31]", FPCSR_C); if (m_Section->m_Cont.FallThrough) { - m_Assembler.JneLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JneLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } else if (m_Section->m_Jump.FallThrough) { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); } else { - m_Assembler.JeLabel32(m_Section->m_Cont.BranchLabel.c_str(), 0); - m_Section->m_Cont.LinkLocation = (uint32_t *)(*g_RecompPos - 4); - m_Assembler.JmpLabel32(m_Section->m_Jump.BranchLabel.c_str(), 0); - m_Section->m_Jump.LinkLocation = (uint32_t *)(*g_RecompPos - 4); + m_Section->m_Cont.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JeLabel(m_Section->m_Cont.BranchLabel.c_str(), m_Section->m_Cont.LinkLocation); + m_Section->m_Jump.LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(m_Section->m_Jump.BranchLabel.c_str(), m_Section->m_Jump.LinkLocation); } } @@ -2157,8 +2149,8 @@ void CX86RecompilerOps::J() m_Section->m_Jump.BranchLabel = "ExitBlock"; } m_Section->m_Jump.FallThrough = true; - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_PipelineStage = PIPELINE_STAGE_DO_DELAY_SLOT; } else if (m_PipelineStage == PIPELINE_STAGE_DELAY_SLOT_DONE) @@ -2179,7 +2171,7 @@ void CX86RecompilerOps::JAL() { Map_GPR_32bit(31, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(31), _PROGRAM_COUNTER, "_PROGRAM_COUNTER"); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(31), 0xF0000000); + m_Assembler.and_(GetMipsRegMapLo(31), 0xF0000000); m_Assembler.AddConstToX86Reg(GetMipsRegMapLo(31), (m_CompilePC + 8) & ~0xF0000000); if ((m_CompilePC & 0xFFC) == 0xFFC) { @@ -2198,8 +2190,8 @@ void CX86RecompilerOps::JAL() m_Section->m_Jump.BranchLabel = "ExitBlock"; } m_Section->m_Jump.FallThrough = true; - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_PipelineStage = PIPELINE_STAGE_DO_DELAY_SLOT; } else if (m_PipelineStage == PIPELINE_STAGE_DELAY_SLOT_DONE) @@ -2213,9 +2205,9 @@ void CX86RecompilerOps::JAL() { m_RegWorkingSet.WriteBackRegisters(); - const asmjit::x86::Gp & PCReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp PCReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(PCReg, _PROGRAM_COUNTER, "_PROGRAM_COUNTER"); - m_Assembler.AndConstToX86Reg(PCReg, 0xF0000000); + m_Assembler.and_(PCReg, 0xF0000000); m_Assembler.AddConstToX86Reg(PCReg, (m_Opcode.target << 2)); m_Assembler.MoveX86regToVariable(_PROGRAM_COUNTER, "_PROGRAM_COUNTER", PCReg); @@ -2264,15 +2256,15 @@ void CX86RecompilerOps::ADDI() else { ProtectGPR(m_Opcode.rt); - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); m_Assembler.AddConstToX86Reg(Reg, (int16_t)m_Opcode.immediate); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); if (m_Opcode.rt != 0) { Map_GPR_32bit(m_Opcode.rt, true, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), Reg); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rt), Reg); } } if (g_System->bFastSP() && m_Opcode.rt == 29 && m_Opcode.rs != 29) @@ -2339,22 +2331,20 @@ void CX86RecompilerOps::SLTIU() { if (Is64Bit(m_Opcode.rs)) { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; m_Assembler.CompConstToX86reg(GetMipsRegMapHi(m_Opcode.rs), ((int16_t)m_Opcode.immediate >> 31)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), (int16_t)m_Opcode.immediate); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt), &m_BranchCompare, "m_BranchCompare"); } @@ -2375,15 +2365,12 @@ void CX86RecompilerOps::SLTIU() } else { - uint8_t * Jump = nullptr; - m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[1], CRegName::GPR_Hi[m_Opcode.rs], ((int16_t)m_Opcode.immediate >> 31)); - m_Assembler.JneLabel8("CompareSet", 0); - Jump = *g_RecompPos - 1; + asmjit::Label Jump = m_Assembler.newLabel(); + m_Assembler.JneLabel("CompareSet", Jump); m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs], (int16_t)m_Opcode.immediate); m_CodeBlock.Log(""); - m_CodeBlock.Log(" CompareSet:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt), &m_BranchCompare, "m_BranchCompare"); @@ -2409,32 +2396,25 @@ void CX86RecompilerOps::SLTI() { if (Is64Bit(m_Opcode.rs)) { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; m_Assembler.CompConstToX86reg(GetMipsRegMapHi(m_Opcode.rs), ((int16_t)m_Opcode.immediate >> 31)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), (int16_t)m_Opcode.immediate); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt), &m_BranchCompare, "m_BranchCompare"); } else { - /* m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs),(int16_t)m_Opcode.immediate); - m_Assembler.SetlVariable(&m_BranchCompare,"m_BranchCompare"); - Map_GPR_32bit(m_Opcode.rt, false, -1); - m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt),&m_BranchCompare,"m_BranchCompare"); - */ ProtectGPR(m_Opcode.rs); Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rs), (int16_t)m_Opcode.immediate); @@ -2446,8 +2426,8 @@ void CX86RecompilerOps::SLTI() } else { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rt)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), 1); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rt), 1); } } } @@ -2463,29 +2443,27 @@ void CX86RecompilerOps::SLTI() } else { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rt)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), 1); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rt), 1); } } else { - uint8_t * Jump[2] = {nullptr, nullptr}; + asmjit::Label Jump[2]; m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[1], CRegName::GPR_Hi[m_Opcode.rs], ((int16_t)m_Opcode.immediate >> 31)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rs].W[0], CRegName::GPR_Lo[m_Opcode.rs], (int16_t)m_Opcode.immediate); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - if (Jump[1]) + if (Jump[1].isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt), &m_BranchCompare, "m_BranchCompare"); @@ -2512,7 +2490,7 @@ void CX86RecompilerOps::ANDI() else if (m_Opcode.immediate != 0) { Map_GPR_32bit(m_Opcode.rt, false, m_Opcode.rs); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); } else { @@ -2529,7 +2507,7 @@ void CX86RecompilerOps::ORI() if (g_System->bFastSP() && m_Opcode.rs == 29 && m_Opcode.rt == 29) { - m_Assembler.OrConstToX86Reg(Map_MemoryStack(x86Reg_Unknown, true), m_Opcode.immediate); + m_Assembler.or_(Map_MemoryStack(x86Reg_Unknown, true), m_Opcode.immediate); } if (IsConst(m_Opcode.rs)) @@ -2560,7 +2538,7 @@ void CX86RecompilerOps::ORI() Map_GPR_32bit(m_Opcode.rt, IsSigned(m_Opcode.rs), m_Opcode.rs); } } - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); } else { @@ -2572,7 +2550,7 @@ void CX86RecompilerOps::ORI() { Map_GPR_64bit(m_Opcode.rt, m_Opcode.rs); } - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); } if (g_System->bFastSP() && m_Opcode.rt == 29 && m_Opcode.rs != 29) @@ -2616,7 +2594,7 @@ void CX86RecompilerOps::XORI() } if (m_Opcode.immediate != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rt), m_Opcode.immediate); } } } @@ -2630,7 +2608,7 @@ void CX86RecompilerOps::LUI() if (g_System->bFastSP() && m_Opcode.rt == 29) { - const asmjit::x86::Gp & Reg = Map_MemoryStack(x86Reg_Unknown, true, false); + asmjit::x86::Gp Reg = Map_MemoryStack(x86Reg_Unknown, true, false); uint32_t Address; m_MMU.VAddrToPAddr(((int16_t)m_Opcode.offset << 16), Address); @@ -2687,20 +2665,20 @@ void CX86RecompilerOps::DADDI() else { ProtectGPR(m_Opcode.rs); - const asmjit::x86::Gp & RegLo = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); - const asmjit::x86::Gp & RegHi = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp RegLo = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp RegHi = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); - m_Assembler.AddConstToX86Reg(RegLo, (uint32_t)imm, true); - m_Assembler.AdcConstToX86Reg(RegHi, (uint32_t)(imm >> 32)); + m_Assembler.add(RegLo, (uint32_t)imm); + m_Assembler.adc(RegHi, (uint32_t)(imm >> 32)); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); if (m_Opcode.rt != 0) { UnProtectGPR(m_Opcode.rs); Map_GPR_64bit(m_Opcode.rt, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), RegLo); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rt), RegHi); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rt), RegLo); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rt), RegHi); } } } @@ -2737,17 +2715,17 @@ void CX86RecompilerOps::DADDIU() else { ProtectGPR(m_Opcode.rs); - const asmjit::x86::Gp & RegLo = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); - const asmjit::x86::Gp & RegHi = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp RegLo = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp RegHi = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); - m_Assembler.AddConstToX86Reg(RegLo, (uint32_t)imm, true); - m_Assembler.AdcConstToX86Reg(RegHi, (uint32_t)(imm >> 32)); + m_Assembler.add(RegLo, (uint32_t)imm); + m_Assembler.adc(RegHi, (uint32_t)(imm >> 32)); if (m_Opcode.rt != 0) { UnProtectGPR(m_Opcode.rs); Map_GPR_64bit(m_Opcode.rt, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), RegLo); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rt), RegHi); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rt), RegLo); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rt), RegHi); } } } @@ -2765,7 +2743,7 @@ void CX86RecompilerOps::CACHE() case 16: m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("CRecompiler::Remove_Cache", CRecompiler::Remove_Cache); - m_Assembler.PushImm32("0x20", 0x20); + m_Assembler.push(0x20); if (IsConst(m_Opcode.base)) { uint32_t Address = GetMipsRegLo(m_Opcode.base) + (int16_t)m_Opcode.offset; @@ -2774,13 +2752,13 @@ void CX86RecompilerOps::CACHE() else if (IsMapped(m_Opcode.base)) { m_Assembler.AddConstToX86Reg(GetMipsRegMapLo(m_Opcode.base), (int16_t)m_Opcode.offset); - m_Assembler.Push(GetMipsRegMapLo(m_Opcode.base)); + m_Assembler.push(GetMipsRegMapLo(m_Opcode.base)); } else { m_Assembler.MoveVariableToX86reg(asmjit::x86::eax, &_GPR[m_Opcode.base].UW[0], CRegName::GPR_Lo[m_Opcode.base]); m_Assembler.AddConstToX86Reg(asmjit::x86::eax, (int16_t)m_Opcode.offset); - m_Assembler.Push(asmjit::x86::eax); + m_Assembler.push(asmjit::x86::eax); } m_Assembler.CallThis((uint32_t)g_Recompiler, AddressOf(&CRecompiler::ClearRecompCode_Virt), "CRecompiler::ClearRecompCode_Virt", 16); m_RegWorkingSet.AfterCallDirect(); @@ -2843,7 +2821,7 @@ void CX86RecompilerOps::LB_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA { if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileLoadMemoryValue(AddressReg, Reg, x86Reg_Unknown, 8, SignExtend); return; @@ -2924,22 +2902,22 @@ void CX86RecompilerOps::LB_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(((PAddr + 2) & ~0x3) & 0x1FFFFFFC); + m_Assembler.push(((PAddr + 2) & ~0x3) & 0x1FFFFFFC); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][0], "RomMemoryHandler::Read32", 16); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); uint8_t Shift = (((PAddr & 1) ^ 3) << 3); if (Shift == 0x10) { - m_Assembler.ShiftLeftSignImmed(Reg, 0x8); + m_Assembler.shl(Reg, 0x8); } if (SignExtend) { - m_Assembler.ShiftRightSignImmed(Reg, 0x18); + m_Assembler.sar(Reg, 0x18); } else { - m_Assembler.ShiftRightUnsignImmed(Reg, 0x18); + m_Assembler.shr(Reg, 0x18); } } else @@ -2962,7 +2940,7 @@ void CX86RecompilerOps::LH_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileLoadMemoryValue(AddressReg, Reg, x86Reg_Unknown, 16, SignExtend); } @@ -3009,17 +2987,17 @@ void CX86RecompilerOps::LH_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(((PAddr + 2) & ~0x3) & 0x1FFFFFFC); + m_Assembler.push(((PAddr + 2) & ~0x3) & 0x1FFFFFFC); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][0], "RomMemoryHandler::Read32", 16); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); if (SignExtend) { - m_Assembler.ShiftRightSignImmed(Reg, 16); + m_Assembler.sar(Reg, 16); } else { - m_Assembler.ShiftRightUnsignImmed(Reg, 16); + m_Assembler.shr(Reg, 16); } } else @@ -3105,32 +3083,32 @@ void CX86RecompilerOps::LWL() } Map_GPR_32bit(m_Opcode.rt, true, m_Opcode.rt); - const asmjit::x86::Gp & Value = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp Value = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(Value, (Address & ~3)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), R4300iOp::LWL_MASK[Offset]); - m_Assembler.ShiftLeftSignImmed(Value, (uint8_t)R4300iOp::LWL_SHIFT[Offset]); - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rt), R4300iOp::LWL_MASK[Offset]); + m_Assembler.shl(Value, (uint8_t)R4300iOp::LWL_SHIFT[Offset]); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rt), Value); } else { PreReadInstruction(); - const asmjit::x86::Gp & shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); + asmjit::x86::Gp shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); if (IsMapped(m_Opcode.rt)) { ProtectGPR(m_Opcode.rt); } - const asmjit::x86::Gp & AddressReg = BaseOffsetAddress(false); - const asmjit::x86::Gp & OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(OffsetReg, AddressReg); - m_Assembler.AndConstToX86Reg(OffsetReg, 3); - m_Assembler.AndConstToX86Reg(AddressReg, (uint32_t)~3); + asmjit::x86::Gp AddressReg = BaseOffsetAddress(false); + asmjit::x86::Gp OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(OffsetReg, AddressReg); + m_Assembler.and_(OffsetReg, 3); + m_Assembler.and_(AddressReg, (uint32_t)~3); TestReadBreakpoint(AddressReg, (uint32_t)x86TestReadBreakpoint32, "x86TestReadBreakpoint32"); CompileLoadMemoryValue(AddressReg, AddressReg, x86Reg_Unknown, 32, false); Map_GPR_32bit(m_Opcode.rt, true, m_Opcode.rt); m_Assembler.AndVariableDispToX86Reg(GetMipsRegMapLo(m_Opcode.rt), (void *)R4300iOp::LWL_MASK, "LWL_MASK", OffsetReg, CX86Ops::Multip_x4); m_Assembler.MoveVariableDispToX86Reg(shift, (void *)R4300iOp::LWL_SHIFT, "LWL_SHIFT", OffsetReg, CX86Ops::Multip_x4); - m_Assembler.ShiftLeftSign(AddressReg); - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), AddressReg); + m_Assembler.shl(AddressReg, asmjit::x86::cl); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rt), AddressReg); } } @@ -3146,7 +3124,7 @@ void CX86RecompilerOps::LW(bool ResultSigned, bool bRecordLLBit) if (!HaveReadBP() && m_Opcode.base == 29 && g_System->bFastSP()) { Map_GPR_32bit(m_Opcode.rt, ResultSigned, -1); - const asmjit::x86::Gp & TempReg1 = Map_MemoryStack(x86Reg_Unknown, true); + asmjit::x86::Gp TempReg1 = Map_MemoryStack(x86Reg_Unknown, true); m_Assembler.MoveVariableDispToX86Reg(GetMipsRegMapLo(m_Opcode.rt), (void *)((uint32_t)(int16_t)m_Opcode.offset), stdstr_f("%Xh", (int16_t)m_Opcode.offset).c_str(), TempReg1, CX86Ops::Multip_x1); if (bRecordLLBit) { @@ -3189,7 +3167,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(Reg), true); if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileLoadMemoryValue(AddressReg, Reg, x86Reg_Unknown, 32, true); } @@ -3244,7 +3222,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA default: m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)(g_MMU), AddressOf(&CMipsMemoryVM::LW_NonMemory), "CMipsMemoryVM::LW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); @@ -3255,7 +3233,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA case 0x04100000: m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)(g_MMU), AddressOf(&CMipsMemoryVM::LW_NonMemory), "CMipsMemoryVM::LW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); @@ -3281,7 +3259,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler)[0][0], "VideoInterfaceHandler::Read32", 16); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); @@ -3293,7 +3271,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler)[0][0], "AudioInterfaceHandler::Read32", 16); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); @@ -3399,7 +3377,7 @@ void CX86RecompilerOps::LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VA { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][0], "RomMemoryHandler::Read32", 16); m_RegWorkingSet.AfterCallDirect(); m_Assembler.MoveVariableToX86reg(Reg, &m_TempValue32, "m_TempValue32"); @@ -3485,32 +3463,32 @@ void CX86RecompilerOps::LWR() return; } Map_GPR_32bit(m_Opcode.rt, true, m_Opcode.rt); - const asmjit::x86::Gp & Value = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp Value = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(Value, (Address & ~3)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rt), R4300iOp::LWR_MASK[Offset]); - m_Assembler.ShiftRightUnsignImmed(Value, (uint8_t)R4300iOp::LWR_SHIFT[Offset]); - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rt), R4300iOp::LWR_MASK[Offset]); + m_Assembler.shr(Value, (uint8_t)R4300iOp::LWR_SHIFT[Offset]); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rt), Value); } else { PreReadInstruction(); - const asmjit::x86::Gp & shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); + asmjit::x86::Gp shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); if (IsMapped(m_Opcode.rt)) { ProtectGPR(m_Opcode.rt); } - const asmjit::x86::Gp & AddressReg = BaseOffsetAddress(false); - const asmjit::x86::Gp & OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(OffsetReg, AddressReg); - m_Assembler.AndConstToX86Reg(OffsetReg, 3); - m_Assembler.AndConstToX86Reg(AddressReg, (uint32_t)~3); + asmjit::x86::Gp AddressReg = BaseOffsetAddress(false); + asmjit::x86::Gp OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(OffsetReg, AddressReg); + m_Assembler.and_(OffsetReg, 3); + m_Assembler.and_(AddressReg, (uint32_t)~3); TestReadBreakpoint(AddressReg, (uint32_t)x86TestReadBreakpoint32, "x86TestReadBreakpoint32"); CompileLoadMemoryValue(AddressReg, AddressReg, x86Reg_Unknown, 32, false); Map_GPR_32bit(m_Opcode.rt, true, m_Opcode.rt); m_Assembler.AndVariableDispToX86Reg(GetMipsRegMapLo(m_Opcode.rt), (void *)R4300iOp::LWR_MASK, "LWR_MASK", OffsetReg, CX86Ops::Multip_x4); m_Assembler.MoveVariableDispToX86Reg(shift, (void *)R4300iOp::LWR_SHIFT, "LWR_SHIFT", OffsetReg, CX86Ops::Multip_x4); - m_Assembler.ShiftRightUnsign(AddressReg); - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rt), AddressReg); + m_Assembler.shr(AddressReg, asmjit::x86::cl); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rt), AddressReg); } } @@ -3617,40 +3595,39 @@ void CX86RecompilerOps::SWL() } uint32_t Offset = Address & 3; - const asmjit::x86::Gp & Value = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp Value = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(Value, (Address & ~3)); - m_Assembler.AndConstToX86Reg(Value, R4300iOp::SWL_MASK[Offset]); - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); - m_Assembler.ShiftRightUnsignImmed(TempReg1, (uint8_t)R4300iOp::SWL_SHIFT[Offset]); - m_Assembler.AddX86RegToX86Reg(Value, TempReg1); + m_Assembler.and_(Value, R4300iOp::SWL_MASK[Offset]); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + m_Assembler.shr(TempReg1, (uint8_t)R4300iOp::SWL_SHIFT[Offset]); + m_Assembler.add(Value, TempReg1); SW_Register(Value, (Address & ~3)); return; } PreWriteInstruction(); - const asmjit::x86::Gp & shift = Map_TempReg(asmjit::x86::ecx, -1, false, false), AddressReg = BaseOffsetAddress(false); + asmjit::x86::Gp shift = Map_TempReg(asmjit::x86::ecx, -1, false, false), AddressReg = BaseOffsetAddress(false); TestWriteBreakpoint(AddressReg, (uint32_t)x86TestWriteBreakpoint32, "x86TestWriteBreakpoint32"); - const asmjit::x86::Gp & TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); - const asmjit::x86::Gp & OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - const asmjit::x86::Gp & ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(TempReg2, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg2, 12); + asmjit::x86::Gp TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(TempReg2, AddressReg); + m_Assembler.shr(TempReg2, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg2, g_MMU->m_MemoryReadMap, "MMU->m_MemoryReadMap", TempReg2, CX86Ops::Multip_x4); m_Assembler.CompConstToX86reg(TempReg2, (uint32_t)-1); - m_Assembler.JneLabel8(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), 0); - uint8_t * JumpFound = (uint8_t *)(*g_RecompPos - 1); - m_Assembler.MoveX86RegToX86Reg(TempReg2, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg2, 12); + asmjit::Label JumpFound = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), JumpFound); + m_Assembler.mov(TempReg2, AddressReg); + m_Assembler.shr(TempReg2, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg2, g_MMU->m_TLB_ReadMap, "MMU->TLB_ReadMap", TempReg2, CX86Ops::Multip_x4); CompileReadTLBMiss(AddressReg, TempReg2); m_Assembler.AddConstToX86Reg(TempReg2, (uint32_t)m_MMU.Rdram()); m_CodeBlock.Log(""); - m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); - m_Assembler.SetJump8(JumpFound, *g_RecompPos); - m_Assembler.MoveX86RegToX86Reg(OffsetReg, AddressReg); - m_Assembler.AndConstToX86Reg(OffsetReg, 3); - m_Assembler.AndConstToX86Reg(AddressReg, (uint32_t)~3); - m_Assembler.MoveX86regPointerToX86reg(ValueReg, AddressReg, TempReg2); + m_Assembler.bind(JumpFound); + m_Assembler.mov(OffsetReg, AddressReg); + m_Assembler.and_(OffsetReg, 3); + m_Assembler.and_(AddressReg, (uint32_t)~3); + m_Assembler.mov(ValueReg, asmjit::x86::dword_ptr(AddressReg, TempReg2)); m_Assembler.AndVariableDispToX86Reg(ValueReg, (void *)R4300iOp::SWL_MASK, "R4300iOp::SWL_MASK", OffsetReg, CX86Ops::Multip_x4); if (!IsConst(m_Opcode.rt) || GetMipsRegLo(m_Opcode.rt) != 0) @@ -3662,14 +3639,14 @@ void CX86RecompilerOps::SWL() } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.MoveX86RegToX86Reg(OffsetReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(OffsetReg, GetMipsRegMapLo(m_Opcode.rt)); } else { m_Assembler.MoveVariableToX86reg(OffsetReg, &_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt]); } - m_Assembler.ShiftRightUnsign(OffsetReg); - m_Assembler.AddX86RegToX86Reg(ValueReg, OffsetReg); + m_Assembler.shr(OffsetReg, asmjit::x86::cl); + m_Assembler.add(ValueReg, OffsetReg); } CompileStoreMemoryValue(AddressReg, ValueReg, x86Reg_Unknown, 0, 32); @@ -3692,20 +3669,20 @@ void CX86RecompilerOps::SW(bool bCheckLLbit) { ProtectGPR(m_Opcode.rt); } - const asmjit::x86::Gp & TempReg1 = Map_MemoryStack(x86Reg_Unknown, true); + asmjit::x86::Gp TempReg1 = Map_MemoryStack(x86Reg_Unknown, true); if (IsConst(m_Opcode.rt)) { - m_Assembler.MoveConstToMemoryDisp(TempReg1, (uint32_t)((int16_t)m_Opcode.offset), GetMipsRegLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg1, (uint32_t)((int16_t)m_Opcode.offset)), GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.MoveX86regToMemory(TempReg1, (uint32_t)((int16_t)m_Opcode.offset), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg1, (uint32_t)((int16_t)m_Opcode.offset)), GetMipsRegMapLo(m_Opcode.rt)); } else { - const asmjit::x86::Gp & TempReg2 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); - m_Assembler.MoveX86regToMemory(TempReg1, (uint32_t)((int16_t)m_Opcode.offset), TempReg2); + asmjit::x86::Gp TempReg2 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg1, (uint32_t)((int16_t)m_Opcode.offset)), TempReg2); } } else @@ -3740,12 +3717,12 @@ void CX86RecompilerOps::SW(bool bCheckLLbit) } PreWriteInstruction(); - uint8_t * JumpLLBit = nullptr; + asmjit::Label JumpLLBit; if (bCheckLLbit) { m_Assembler.CompConstToVariable(_LLBit, "_LLBit", 1); - m_Assembler.JneLabel8("LLBit_Continue", 0); - JumpLLBit = *g_RecompPos - 1; + JumpLLBit = m_Assembler.newLabel(); + m_Assembler.JneLabel("LLBit_Continue", JumpLLBit); } asmjit::x86::Gp ValueReg; @@ -3760,9 +3737,8 @@ void CX86RecompilerOps::SW(bool bCheckLLbit) CompileStoreMemoryValue(x86Reg_Unknown, ValueReg, x86Reg_Unknown, GetMipsRegLo(m_Opcode.rt), 32); if (bCheckLLbit) { - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" LLBit_Continue:"); - m_Assembler.SetJump8(JumpLLBit, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(JumpLLBit); Map_GPR_32bit(m_Opcode.rt, false, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rt), _LLBit, "_LLBit"); } @@ -3781,42 +3757,41 @@ void CX86RecompilerOps::SWR() } uint32_t Offset = Address & 3; - const asmjit::x86::Gp & Value = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp Value = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(Value, (Address & ~3)); - m_Assembler.AndConstToX86Reg(Value, R4300iOp::SWR_MASK[Offset]); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); - m_Assembler.ShiftLeftSignImmed(TempReg, (uint8_t)R4300iOp::SWR_SHIFT[Offset]); - m_Assembler.AddX86RegToX86Reg(Value, TempReg); + m_Assembler.and_(Value, R4300iOp::SWR_MASK[Offset]); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + m_Assembler.shl(TempReg, (uint8_t)R4300iOp::SWR_SHIFT[Offset]); + m_Assembler.add(Value, TempReg); SW_Register(Value, (Address & ~3)); return; } PreWriteInstruction(); - const asmjit::x86::Gp & shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); - const asmjit::x86::Gp & AddressReg = BaseOffsetAddress(false); + asmjit::x86::Gp shift = Map_TempReg(asmjit::x86::ecx, -1, false, false); + asmjit::x86::Gp AddressReg = BaseOffsetAddress(false); TestWriteBreakpoint(AddressReg, (uint32_t)x86TestWriteBreakpoint32, "x86TestWriteBreakpoint32"); - const asmjit::x86::Gp & TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); - const asmjit::x86::Gp & OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - const asmjit::x86::Gp & ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(TempReg2, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg2, 12); + asmjit::x86::Gp TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp OffsetReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(TempReg2, AddressReg); + m_Assembler.shr(TempReg2, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg2, g_MMU->m_MemoryReadMap, "MMU->m_MemoryReadMap", TempReg2, CX86Ops::Multip_x4); m_Assembler.CompConstToX86reg(TempReg2, (uint32_t)-1); - m_Assembler.JneLabel8(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), 0); - uint8_t * JumpFound = (uint8_t *)(*g_RecompPos - 1); - m_Assembler.MoveX86RegToX86Reg(TempReg2, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg2, 12); + asmjit::Label JumpFound = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), JumpFound); + m_Assembler.mov(TempReg2, AddressReg); + m_Assembler.shr(TempReg2, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg2, g_MMU->m_TLB_ReadMap, "MMU->TLB_ReadMap", TempReg2, CX86Ops::Multip_x4); CompileReadTLBMiss(AddressReg, TempReg2); m_Assembler.AddConstToX86Reg(TempReg2, (uint32_t)m_MMU.Rdram()); m_CodeBlock.Log(""); - m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); - m_Assembler.SetJump8(JumpFound, *g_RecompPos); + m_Assembler.bind(JumpFound); - m_Assembler.MoveX86RegToX86Reg(OffsetReg, AddressReg); - m_Assembler.AndConstToX86Reg(OffsetReg, 3); - m_Assembler.AndConstToX86Reg(AddressReg, (uint32_t)~3); + m_Assembler.mov(OffsetReg, AddressReg); + m_Assembler.and_(OffsetReg, 3); + m_Assembler.and_(AddressReg, (uint32_t)~3); - m_Assembler.MoveX86regPointerToX86reg(ValueReg, AddressReg, TempReg2); + m_Assembler.mov(ValueReg, asmjit::x86::dword_ptr(AddressReg, TempReg2)); m_Assembler.AndVariableDispToX86Reg(ValueReg, (void *)R4300iOp::SWR_MASK, "R4300iOp::SWR_MASK", OffsetReg, CX86Ops::Multip_x4); if (!IsConst(m_Opcode.rt) || GetMipsRegLo(m_Opcode.rt) != 0) @@ -3828,14 +3803,14 @@ void CX86RecompilerOps::SWR() } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.MoveX86RegToX86Reg(OffsetReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(OffsetReg, GetMipsRegMapLo(m_Opcode.rt)); } else { m_Assembler.MoveVariableToX86reg(OffsetReg, &_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt]); } - m_Assembler.ShiftLeftSign(OffsetReg); - m_Assembler.AddX86RegToX86Reg(ValueReg, OffsetReg); + m_Assembler.shl(OffsetReg, asmjit::x86::cl); + m_Assembler.add(ValueReg, OffsetReg); } CompileStoreMemoryValue(AddressReg, ValueReg, x86Reg_Unknown, 0, 32); @@ -3908,20 +3883,20 @@ void CX86RecompilerOps::LWC1() FoundMemoryBreakpoint(); return; } - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(TempReg1, Address); - const asmjit::x86::Gp & TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg2, &_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86regToX86Pointer(TempReg2, TempReg1); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg2), TempReg1); return; } PreReadInstruction(); - const asmjit::x86::Gp & ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); CompileLoadMemoryValue(x86Reg_Unknown, ValueReg, x86Reg_Unknown, 32, false); - const asmjit::x86::Gp & FPR_SPtr = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp FPR_SPtr = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(FPR_SPtr, &_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86regToX86Pointer(FPR_SPtr, ValueReg); + m_Assembler.mov(asmjit::x86::dword_ptr(FPR_SPtr), ValueReg); } void CX86RecompilerOps::LDC1() @@ -3937,31 +3912,31 @@ void CX86RecompilerOps::LDC1() FoundMemoryBreakpoint(); return; } - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); LW_KnownAddress(TempReg1, Address); - const asmjit::x86::Gp & TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg2 = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg2, &_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); m_Assembler.AddConstToX86Reg(TempReg2, 4); - m_Assembler.MoveX86regToX86Pointer(TempReg2, TempReg1); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg2), TempReg1); LW_KnownAddress(TempReg1, Address + 4); m_Assembler.MoveVariableToX86reg(TempReg2, &_FPR_D[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86regToX86Pointer(TempReg2, TempReg1); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg2), TempReg1); } else { PreReadInstruction(); UnMap_FPR(m_Opcode.ft, true); - const asmjit::x86::Gp & ValueRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false), ValueRegLo = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false), ValueRegLo = Map_TempReg(x86Reg_Unknown, -1, false, false); CompileLoadMemoryValue(x86Reg_Unknown, ValueRegLo, ValueRegHi, 64, false); - const asmjit::x86::Gp & FPR_DPtr = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp FPR_DPtr = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(FPR_DPtr, &_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86regToX86Pointer(FPR_DPtr, ValueRegLo); + m_Assembler.mov(asmjit::x86::dword_ptr(FPR_DPtr), ValueRegLo); m_Assembler.AddConstToX86Reg(FPR_DPtr, 4); - m_Assembler.MoveX86regToX86Pointer(FPR_DPtr, ValueRegHi); + m_Assembler.mov(asmjit::x86::dword_ptr(FPR_DPtr), ValueRegHi); } } @@ -3975,7 +3950,7 @@ void CX86RecompilerOps::LD() if (!HaveReadBP() && m_Opcode.base == 29 && g_System->bFastSP()) { Map_GPR_64bit(m_Opcode.rt, -1); - const asmjit::x86::Gp & StackReg = Map_MemoryStack(x86Reg_Unknown, true); + asmjit::x86::Gp StackReg = Map_MemoryStack(x86Reg_Unknown, true); m_Assembler.MoveVariableDispToX86Reg(GetMipsRegMapHi(m_Opcode.rt), (void *)((uint32_t)(int16_t)m_Opcode.offset), stdstr_f("%Xh", (int16_t)m_Opcode.offset).c_str(), StackReg, CX86Ops::Multip_x1); m_Assembler.MoveVariableDispToX86Reg(GetMipsRegMapLo(m_Opcode.rt), (void *)((uint32_t)(int16_t)m_Opcode.offset + 4), stdstr_f("%Xh", (int16_t)m_Opcode.offset + 4).c_str(), StackReg, CX86Ops::Multip_x1); } @@ -4032,17 +4007,17 @@ void CX86RecompilerOps::SWC1() } UnMap_FPR(m_Opcode.ft, true); - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg1, &_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86PointerToX86reg(TempReg1, TempReg1); + m_Assembler.mov(TempReg1, asmjit::x86::dword_ptr(TempReg1)); SW_Register(TempReg1, Address); return; } PreWriteInstruction(); UnMap_FPR(m_Opcode.ft, true); - const asmjit::x86::Gp & ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(ValueReg, &_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86PointerToX86reg(ValueReg, ValueReg); + m_Assembler.mov(ValueReg, asmjit::x86::dword_ptr(ValueReg)); CompileStoreMemoryValue(x86Reg_Unknown, ValueReg, x86Reg_Unknown, 0, 32); } @@ -4060,25 +4035,25 @@ void CX86RecompilerOps::SDC1() return; } - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg1, (uint8_t *)&_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); m_Assembler.AddConstToX86Reg(TempReg1, 4); - m_Assembler.MoveX86PointerToX86reg(TempReg1, TempReg1); + m_Assembler.mov(TempReg1, asmjit::x86::dword_ptr(TempReg1)); SW_Register(TempReg1, Address); m_Assembler.MoveVariableToX86reg(TempReg1, &_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86PointerToX86reg(TempReg1, TempReg1); + m_Assembler.mov(TempReg1, asmjit::x86::dword_ptr(TempReg1)); SW_Register(TempReg1, Address + 4); return; } PreWriteInstruction(); UnMap_FPR(m_Opcode.ft, true); - const asmjit::x86::Gp & ValueRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false), ValueRegLo = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp ValueRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false), ValueRegLo = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(ValueRegHi, (uint8_t *)&_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); - m_Assembler.MoveX86RegToX86Reg(ValueRegLo, ValueRegHi); + m_Assembler.mov(ValueRegLo, ValueRegHi); m_Assembler.AddConstToX86Reg(ValueRegHi, 4); - m_Assembler.MoveX86PointerToX86reg(ValueRegHi, ValueRegHi); - m_Assembler.MoveX86PointerToX86reg(ValueRegLo, ValueRegLo); + m_Assembler.mov(ValueRegHi, asmjit::x86::dword_ptr(ValueRegHi)); + m_Assembler.mov(ValueRegLo, asmjit::x86::dword_ptr(ValueRegLo)); CompileStoreMemoryValue(x86Reg_Unknown, ValueRegLo, ValueRegHi, 0, 64); } @@ -4106,7 +4081,7 @@ void CX86RecompilerOps::SD() } else { - const asmjit::x86::Gp & TempReg1 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); + asmjit::x86::Gp TempReg1 = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); SW_Register(TempReg1, Address); SW_Register(Map_TempReg(TempReg1, m_Opcode.rt, false, false), Address + 4); } @@ -4170,29 +4145,21 @@ void CX86RecompilerOps::SPECIAL_SLL() Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); break; case 1: - ProtectGPR(m_Opcode.rt); - Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.LeaRegReg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt), 0, CX86Ops::Multip_x2); - break; case 2: - ProtectGPR(m_Opcode.rt); - Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.LeaRegReg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt), 0, CX86Ops::Multip_x4); - break; case 3: ProtectGPR(m_Opcode.rt); Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.LeaRegReg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt), 0, CX86Ops::Multip_x8); + m_Assembler.lea(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::ptr(0, GetMipsRegMapLo(m_Opcode.rt), m_Opcode.sa)); break; default: Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } else { Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } @@ -4215,7 +4182,7 @@ void CX86RecompilerOps::SPECIAL_SRL() return; } Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightUnsignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } void CX86RecompilerOps::SPECIAL_SRA() @@ -4237,7 +4204,7 @@ void CX86RecompilerOps::SPECIAL_SRA() return; } Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } void CX86RecompilerOps::SPECIAL_SLLV() @@ -4263,14 +4230,14 @@ void CX86RecompilerOps::SPECIAL_SLLV() else { Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); } return; } Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftLeftSign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); } void CX86RecompilerOps::SPECIAL_SRLV() @@ -4294,14 +4261,14 @@ void CX86RecompilerOps::SPECIAL_SRLV() return; } Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightUnsignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); return; } Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightUnsign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); } void CX86RecompilerOps::SPECIAL_SRAV() @@ -4326,13 +4293,13 @@ void CX86RecompilerOps::SPECIAL_SRAV() return; } Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)Shift); return; } Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rt); - m_Assembler.ShiftRightSign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); } void CX86RecompilerOps::SPECIAL_JR() @@ -4356,11 +4323,11 @@ void CX86RecompilerOps::SPECIAL_JR() } m_Section->m_Jump.FallThrough = false; - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_Section->m_Cont.FallThrough = false; - m_Section->m_Cont.LinkLocation = nullptr; - m_Section->m_Cont.LinkLocation2 = nullptr; + m_Section->m_Cont.LinkLocation = asmjit::Label(); + m_Section->m_Cont.LinkLocation2 = asmjit::Label(); R4300iOpcode DelaySlot; if (g_MMU->MemoryValue32(m_CompilePC + 4, DelaySlot.Value) && @@ -4458,11 +4425,11 @@ void CX86RecompilerOps::SPECIAL_JALR() } m_Section->m_Jump.FallThrough = false; - m_Section->m_Jump.LinkLocation = nullptr; - m_Section->m_Jump.LinkLocation2 = nullptr; + m_Section->m_Jump.LinkLocation = asmjit::Label(); + m_Section->m_Jump.LinkLocation2 = asmjit::Label(); m_Section->m_Cont.FallThrough = false; - m_Section->m_Cont.LinkLocation = nullptr; - m_Section->m_Cont.LinkLocation2 = nullptr; + m_Section->m_Cont.LinkLocation = asmjit::Label(); + m_Section->m_Cont.LinkLocation2 = asmjit::Label(); m_PipelineStage = PIPELINE_STAGE_DO_DELAY_SLOT; } @@ -4565,7 +4532,7 @@ void CX86RecompilerOps::SPECIAL_MTLO() } else { - const asmjit::x86::Gp & reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); m_Assembler.MoveX86regToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", reg); m_Assembler.MoveX86regToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", Map_TempReg(reg, m_Opcode.rs, false, false)); } @@ -4619,7 +4586,7 @@ void CX86RecompilerOps::SPECIAL_MTHI() } else { - const asmjit::x86::Gp & reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", reg); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", Map_TempReg(reg, m_Opcode.rs, false, false)); } @@ -4627,41 +4594,39 @@ void CX86RecompilerOps::SPECIAL_MTHI() void CX86RecompilerOps::SPECIAL_DSLLV() { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; if (m_Opcode.rd == 0) { return; } Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x3F); + m_Assembler.and_(asmjit::x86::ecx, 0x3F); Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); m_Assembler.CompConstToX86reg(asmjit::x86::ecx, 0x20); - m_Assembler.JaeLabel8("MORE32", 0); - Jump[0] = *g_RecompPos - 1; - m_Assembler.ShiftLeftDouble(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.ShiftLeftSign(GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JaeLabel("MORE32", Jump[0]); + m_Assembler.shld(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); // MORE32: m_CodeBlock.Log(""); - m_CodeBlock.Log(" MORE32:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.ShiftLeftSign(GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.bind(Jump[0]); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.shl(GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); // Continue: m_CodeBlock.Log(""); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } void CX86RecompilerOps::SPECIAL_DSRLV() { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; if (m_Opcode.rd == 0) { @@ -4699,78 +4664,74 @@ void CX86RecompilerOps::SPECIAL_DSRLV() Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); if ((Shift & 0x20) == 0x20) { - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.ShiftRightUnsign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); } else { - m_Assembler.ShiftRightDouble(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.ShiftRightUnsign(GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.shrd(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); + m_Assembler.shr(GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); } } else { Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x3F); + m_Assembler.and_(asmjit::x86::ecx, 0x3F); Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); m_Assembler.CompConstToX86reg(asmjit::x86::ecx, 0x20); - m_Assembler.JaeLabel8("MORE32", 0); - Jump[0] = *g_RecompPos - 1; - m_Assembler.ShiftRightDouble(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.ShiftRightUnsign(GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JaeLabel("MORE32", Jump[0]); + m_Assembler.shrd(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); + m_Assembler.shr(GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); // MORE32: m_CodeBlock.Log(""); - m_CodeBlock.Log(" MORE32:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.ShiftRightUnsign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.bind(Jump[0]); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); // Continue: m_CodeBlock.Log(""); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } } void CX86RecompilerOps::SPECIAL_DSRAV() { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; if (m_Opcode.rd == 0) { return; } Map_TempReg(asmjit::x86::ecx, m_Opcode.rs, false, false); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x3F); + m_Assembler.and_(asmjit::x86::ecx, 0x3F); Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); m_Assembler.CompConstToX86reg(asmjit::x86::ecx, 0x20); - m_Assembler.JaeLabel8("MORE32", 0); - Jump[0] = *g_RecompPos - 1; - m_Assembler.ShiftRightDouble(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.ShiftRightSign(GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JaeLabel("MORE32", Jump[0]); + m_Assembler.shrd(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); + m_Assembler.sar(GetMipsRegMapHi(m_Opcode.rd), asmjit::x86::cl); + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); // MORE32: m_CodeBlock.Log(""); - m_CodeBlock.Log(" MORE32:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); - m_Assembler.ShiftRightSignImmed(GetMipsRegMapHi(m_Opcode.rd), 0x1F); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.ShiftRightSign(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.bind(Jump[0]); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.sar(GetMipsRegMapHi(m_Opcode.rd), 0x1F); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), asmjit::x86::cl); // Continue: m_CodeBlock.Log(""); - m_CodeBlock.Log(" continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } void CX86RecompilerOps::SPECIAL_MULT() @@ -4780,12 +4741,12 @@ void CX86RecompilerOps::SPECIAL_MULT() m_RegWorkingSet.SetX86Protected(x86RegIndex_EDX, false); Map_TempReg(asmjit::x86::edx, m_Opcode.rt, false, false); - m_Assembler.imulX86reg(asmjit::x86::edx); + m_Assembler.imul(asmjit::x86::edx); m_Assembler.MoveX86regToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", asmjit::x86::edx); - m_Assembler.ShiftRightSignImmed(asmjit::x86::eax, 31); // Paired - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 31); + m_Assembler.sar(asmjit::x86::eax, 31); // Paired + m_Assembler.sar(asmjit::x86::edx, 31); m_Assembler.MoveX86regToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", asmjit::x86::edx); } @@ -4797,12 +4758,12 @@ void CX86RecompilerOps::SPECIAL_MULTU() m_RegWorkingSet.SetX86Protected(x86RegIndex_EDX, false); Map_TempReg(asmjit::x86::edx, m_Opcode.rt, false, false); - m_Assembler.MulX86reg(asmjit::x86::edx); + m_Assembler.mul(asmjit::x86::edx); m_Assembler.MoveX86regToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", asmjit::x86::edx); - m_Assembler.ShiftRightSignImmed(asmjit::x86::eax, 31); // Paired - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 31); + m_Assembler.sar(asmjit::x86::eax, 31); // Paired + m_Assembler.sar(asmjit::x86::edx, 31); m_Assembler.MoveX86regToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", asmjit::x86::edx); } @@ -4810,9 +4771,9 @@ void CX86RecompilerOps::SPECIAL_MULTU() void CX86RecompilerOps::SPECIAL_DIV() { asmjit::x86::Gp RegRs, RegRsHi, DivReg; - uint8_t * JumpNotDiv0 = nullptr; - uint8_t * JumpEnd = nullptr; - uint8_t * JumpEnd2 = nullptr; + asmjit::Label JumpNotDiv0; + asmjit::Label JumpEnd; + asmjit::Label JumpEnd2; if (IsConst(m_Opcode.rt) && GetMipsRegLo(m_Opcode.rt) == 0) { @@ -4827,20 +4788,18 @@ void CX86RecompilerOps::SPECIAL_DIV() { asmjit::x86::Gp Reg = IsMapped(m_Opcode.rs) ? GetMipsRegMapLo(m_Opcode.rs) : Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); m_Assembler.CompConstToX86reg(Reg, 0); - m_Assembler.JgeLabel8(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpPositive = *g_RecompPos - 1; + asmjit::Label JumpPositive = m_Assembler.newLabel(); + m_Assembler.JgeLabel(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0x00000001); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0x00000000); - m_Assembler.JmpLabel8(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpLoSet = *g_RecompPos - 1; + asmjit::Label JumpLoSet = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), JumpLoSet); m_CodeBlock.Log(""); - m_CodeBlock.Log(" RsPositive_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpPositive, *g_RecompPos); + m_Assembler.bind(JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); m_CodeBlock.Log(""); - m_CodeBlock.Log(" LoSet_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpLoSet, *g_RecompPos); + m_Assembler.bind(JumpLoSet); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", Reg); if (IsMapped(m_Opcode.rs)) { @@ -4848,7 +4807,7 @@ void CX86RecompilerOps::SPECIAL_DIV() } else { - m_Assembler.ShiftRightSignImmed(Reg, 31); + m_Assembler.sar(Reg, 31); } m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", Reg); } @@ -4879,17 +4838,16 @@ void CX86RecompilerOps::SPECIAL_DIV() if (!IsConst(m_Opcode.rs)) { m_Assembler.CompConstToX86reg(RegRs, 0x80000000); - m_Assembler.JneLabel8(stdstr_f("ValidDiv_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpValid = *g_RecompPos - 1; + asmjit::Label JumpValid = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("ValidDiv_%08X", m_CompilePC).c_str(), JumpValid); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0x80000000); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", 0x00000000); m_Assembler.MoveConstToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", 0x00000000); - m_Assembler.JmpLabel8(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), 0); - JumpEnd = *g_RecompPos - 1; + JumpEnd = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), JumpEnd); m_CodeBlock.Log(""); - m_CodeBlock.Log(" ValidDiv_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpValid, *g_RecompPos); + m_Assembler.bind(JumpValid); } } else @@ -4908,36 +4866,33 @@ void CX86RecompilerOps::SPECIAL_DIV() if (!IsConst(m_Opcode.rs)) { m_Assembler.CompConstToX86reg(DivReg, 0); - m_Assembler.JneLabel8(stdstr_f("NotDiv0_%08X", m_CompilePC).c_str(), 0); - JumpNotDiv0 = *g_RecompPos - 1; + JumpNotDiv0 = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("NotDiv0_%08X", m_CompilePC).c_str(), JumpNotDiv0); m_Assembler.CompConstToX86reg(RegRs, 0); - m_Assembler.JgeLabel8(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpPositive = *g_RecompPos - 1; + asmjit::Label JumpPositive = m_Assembler.newLabel(); + m_Assembler.JgeLabel(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0x00000001); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0x00000000); - m_Assembler.JmpLabel8(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpLoSet = *g_RecompPos - 1; + asmjit::Label JumpLoSet = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), JumpLoSet); m_CodeBlock.Log(""); - m_CodeBlock.Log(" RsPositive_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpPositive, *g_RecompPos); + m_Assembler.bind(JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); m_CodeBlock.Log(""); - m_CodeBlock.Log(" LoSet_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpLoSet, *g_RecompPos); + m_Assembler.bind(JumpLoSet); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", RegRs); if (!IsMapped(m_Opcode.rs)) { - m_Assembler.ShiftRightSignImmed(RegRsHi, 31); + m_Assembler.sar(RegRsHi, 31); } m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", RegRsHi); - m_Assembler.JmpLabel8(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), 0); - JumpEnd = *g_RecompPos - 1; + JumpEnd = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), JumpEnd); m_CodeBlock.Log(""); - m_CodeBlock.Log(" NotDiv0_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpNotDiv0, *g_RecompPos); + m_Assembler.bind(JumpNotDiv0); if (IsMapped(m_Opcode.rt)) { m_Assembler.CompConstToX86reg(GetMipsRegMapLo(m_Opcode.rt), (uint32_t)-1); @@ -4946,19 +4901,18 @@ void CX86RecompilerOps::SPECIAL_DIV() { m_Assembler.CompConstToVariable(&_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt], (uint32_t)-1); } - m_Assembler.JneLabel8(stdstr_f("ValidDiv0_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpValidDiv0 = *g_RecompPos - 1; + asmjit::Label JumpValidDiv0 = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("ValidDiv0_%08X", m_CompilePC).c_str(), JumpValidDiv0); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0x80000000); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", 0x00000000); m_Assembler.MoveConstToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", 0x00000000); - m_Assembler.JmpLabel8(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), 0); - JumpEnd2 = *g_RecompPos - 1; + JumpEnd2 = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("EndDiv_%08X", m_CompilePC).c_str(), JumpEnd2); m_CodeBlock.Log(""); - m_CodeBlock.Log(" ValidDiv0_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpValidDiv0, *g_RecompPos); + m_Assembler.bind(JumpValidDiv0); } } @@ -4974,36 +4928,35 @@ void CX86RecompilerOps::SPECIAL_DIV() } else { - m_Assembler.MoveX86RegToX86Reg(asmjit::x86::edx, asmjit::x86::eax); - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 31); + m_Assembler.mov(asmjit::x86::edx, asmjit::x86::eax); + m_Assembler.sar(asmjit::x86::edx, 31); } - m_Assembler.idivX86reg(DivReg); + m_Assembler.idiv(DivReg); m_Assembler.MoveX86regToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", asmjit::x86::edx); - m_Assembler.ShiftRightSignImmed(asmjit::x86::eax, 31); - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 31); + m_Assembler.sar(asmjit::x86::eax, 31); + m_Assembler.sar(asmjit::x86::edx, 31); m_Assembler.MoveX86regToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", asmjit::x86::edx); - if (JumpEnd != nullptr || JumpEnd2 != nullptr) + if (JumpEnd.isValid() || JumpEnd2.isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" EndDiv_%08X:", m_CompilePC); - if (JumpEnd != nullptr) + if (JumpEnd.isValid()) { - m_Assembler.SetJump8(JumpEnd, *g_RecompPos); + m_Assembler.bind(JumpEnd); } - if (JumpEnd2 != nullptr) + if (JumpEnd2.isValid()) { - m_Assembler.SetJump8(JumpEnd2, *g_RecompPos); + m_Assembler.bind(JumpEnd2); } } } void CX86RecompilerOps::SPECIAL_DIVU() { - uint8_t * JumpEndDivu = nullptr; + asmjit::Label JumpEndDivu; if (IsConst(m_Opcode.rt) && GetMipsRegLo(m_Opcode.rt) == 0) { if (IsConst(m_Opcode.rs)) @@ -5017,20 +4970,18 @@ void CX86RecompilerOps::SPECIAL_DIVU() { asmjit::x86::Gp RegRs = IsMapped(m_Opcode.rs) ? GetMipsRegMapLo(m_Opcode.rs) : Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); m_Assembler.CompConstToX86reg(RegRs, 0); - m_Assembler.JgeLabel8(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpPositive = *g_RecompPos - 1; + asmjit::Label JumpPositive = m_Assembler.newLabel(); + m_Assembler.JgeLabel(stdstr_f("RsPositive_%08X", m_CompilePC).c_str(), JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0x00000001); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0x00000000); - m_Assembler.JmpLabel8(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), 0); - uint8_t * JumpLoSet = *g_RecompPos - 1; + asmjit::Label JumpLoSet = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("LoSet_%08X", m_CompilePC).c_str(), JumpLoSet); m_CodeBlock.Log(""); - m_CodeBlock.Log(" RsPositive_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpPositive, *g_RecompPos); + m_Assembler.bind(JumpPositive); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); m_CodeBlock.Log(""); - m_CodeBlock.Log(" LoSet_%08X:", m_CompilePC); - m_Assembler.SetJump8(JumpLoSet, *g_RecompPos); + m_Assembler.bind(JumpLoSet); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", RegRs); if (IsMapped(m_Opcode.rs)) { @@ -5038,7 +4989,7 @@ void CX86RecompilerOps::SPECIAL_DIVU() } else { - m_Assembler.ShiftRightSignImmed(RegRs, 31); + m_Assembler.sar(RegRs, 31); } m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", RegRs); } @@ -5058,13 +5009,13 @@ void CX86RecompilerOps::SPECIAL_DIVU() m_RegWorkingSet.SetX86Protected(x86RegIndex_EAX, false); Map_TempReg(asmjit::x86::eax, m_Opcode.rs, false, false); - const asmjit::x86::Gp & DivReg = IsMapped(m_Opcode.rt) ? GetMipsRegMapLo(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + asmjit::x86::Gp DivReg = IsMapped(m_Opcode.rt) ? GetMipsRegMapLo(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); if (!IsConst(m_Opcode.rt)) { m_Assembler.CompConstToX86reg(DivReg, 0); - m_Assembler.JneLabel8("NoExcept", 0); - uint8_t * JumpNoExcept = *g_RecompPos - 1; + asmjit::Label JumpNoExcept = m_Assembler.newLabel(); + m_Assembler.JneLabel("NoExcept", JumpNoExcept); m_Assembler.MoveConstToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", 0xFFFFFFFF); m_Assembler.MoveConstToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", 0xFFFFFFFF); @@ -5072,30 +5023,28 @@ void CX86RecompilerOps::SPECIAL_DIVU() if (!IsMapped(m_Opcode.rs)) { RegRsHi = RegRsLo; - m_Assembler.ShiftRightSignImmed(RegRsHi, 31); + m_Assembler.sar(RegRsHi, 31); } m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", RegRsHi); - m_Assembler.JmpLabel8("EndDivu", 0); - JumpEndDivu = *g_RecompPos - 1; + JumpEndDivu = m_Assembler.newLabel(); + m_Assembler.JmpLabel("EndDivu", JumpEndDivu); m_CodeBlock.Log(""); - m_CodeBlock.Log(" NoExcept:"); - m_Assembler.SetJump8(JumpNoExcept, *g_RecompPos); + m_Assembler.bind(JumpNoExcept); } - m_Assembler.DivX86reg(DivReg); + m_Assembler.div(DivReg); m_Assembler.MoveX86regToVariable(&_RegLO->UW[0], "_RegLO->UW[0]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[0], "_RegHI->UW[0]", asmjit::x86::edx); - m_Assembler.ShiftRightSignImmed(asmjit::x86::eax, 31); - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 31); + m_Assembler.sar(asmjit::x86::eax, 31); + m_Assembler.sar(asmjit::x86::edx, 31); m_Assembler.MoveX86regToVariable(&_RegLO->UW[1], "_RegLO->UW[1]", asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_RegHI->UW[1], "_RegHI->UW[1]", asmjit::x86::edx); - if (JumpEndDivu != nullptr) + if (JumpEndDivu.isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" EndDivu:"); - m_Assembler.SetJump8(JumpEndDivu, *g_RecompPos); + m_Assembler.bind(JumpEndDivu); } } } @@ -5177,14 +5126,14 @@ void CX86RecompilerOps::SPECIAL_ADD() } ProtectGPR(m_Opcode.rd); - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, source1, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, source1, false, false); if (IsConst(source2)) { m_Assembler.AddConstToX86Reg(Reg, GetMipsRegLo(source2)); } else if (IsKnown(source2) && IsMapped(source2)) { - m_Assembler.AddX86RegToX86Reg(Reg, GetMipsRegMapLo(source2)); + m_Assembler.add(Reg, GetMipsRegMapLo(source2)); } else { @@ -5195,12 +5144,12 @@ void CX86RecompilerOps::SPECIAL_ADD() ResetMemoryStack(); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + 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) { Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Reg); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), Reg); } } @@ -5233,7 +5182,7 @@ void CX86RecompilerOps::SPECIAL_ADDU() } else if (IsKnown(source2) && IsMapped(source2)) { - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else { @@ -5272,26 +5221,26 @@ void CX86RecompilerOps::SPECIAL_SUB() else { ProtectGPR(m_Opcode.rd); - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); if (IsConst(m_Opcode.rt)) { - m_Assembler.SubConstFromX86Reg(Reg, GetMipsRegLo(m_Opcode.rt)); + m_Assembler.sub(Reg, GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.SubX86RegToX86Reg(Reg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.sub(Reg, GetMipsRegMapLo(m_Opcode.rt)); } else { m_Assembler.SubVariableFromX86reg(Reg, &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + 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) { Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Reg); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), Reg); } } if (g_System->bFastSP() && m_Opcode.rd == 29) @@ -5323,19 +5272,19 @@ void CX86RecompilerOps::SPECIAL_SUBU() { if (m_Opcode.rd == m_Opcode.rt) { - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rs); - m_Assembler.SubX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Reg); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), Reg); return; } Map_GPR_32bit(m_Opcode.rd, true, m_Opcode.rs); if (IsConst(m_Opcode.rt)) { - m_Assembler.SubConstFromX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegLo(m_Opcode.rt)); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.SubX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); } else { @@ -5391,34 +5340,34 @@ void CX86RecompilerOps::SPECIAL_AND() { bool Sign = (IsSigned(m_Opcode.rt) && IsSigned(m_Opcode.rs)); Map_GPR_32bit(m_Opcode.rd, Sign, source1); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else if (Is32Bit(source1) || Is32Bit(source2)) { if (IsUnsigned(Is32Bit(source1) ? source1 : source2)) { Map_GPR_32bit(m_Opcode.rd, false, source1); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else { Map_GPR_64bit(m_Opcode.rd, source1); if (Is32Bit(source2)) { - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); } else { - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); } - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } } else { Map_GPR_64bit(m_Opcode.rd, source1); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } } else @@ -5438,15 +5387,15 @@ void CX86RecompilerOps::SPECIAL_AND() { uint32_t Value = GetMipsRegLo(ConstReg); Map_GPR_32bit(m_Opcode.rd, false, MappedReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), Value); } } else { int64_t Value = GetMipsReg(ConstReg); Map_GPR_64bit(m_Opcode.rd, MappedReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), (uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), (uint32_t)(Value & 0xFFFFFFFF)); } } else if (Is64Bit(MappedReg)) @@ -5455,7 +5404,7 @@ void CX86RecompilerOps::SPECIAL_AND() if (Value != 0) { Map_GPR_32bit(m_Opcode.rd, IsSigned(ConstReg), MappedReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), Value); } else { @@ -5475,7 +5424,7 @@ void CX86RecompilerOps::SPECIAL_AND() if (Value != 0) { Map_GPR_32bit(m_Opcode.rd, Sign, MappedReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), Value); } else { @@ -5495,14 +5444,14 @@ void CX86RecompilerOps::SPECIAL_AND() { uint64_t Value = GetMipsReg(KnownReg); Map_GPR_64bit(m_Opcode.rd, UnknownReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), (uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), (uint32_t)(Value & 0xFFFFFFFF)); } else { uint32_t Value = GetMipsRegLo(KnownReg); Map_GPR_32bit(m_Opcode.rd, IsSigned(KnownReg), UnknownReg); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), Value); } } else @@ -5527,13 +5476,13 @@ void CX86RecompilerOps::SPECIAL_AND() if (Is64Bit(KnownReg)) { Map_GPR_64bit(m_Opcode.rd, UnknownReg); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(KnownReg)); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(KnownReg)); + m_Assembler.and_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(KnownReg)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(KnownReg)); } else { Map_GPR_32bit(m_Opcode.rd, IsSigned(KnownReg), UnknownReg); - m_Assembler.AndX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(KnownReg)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(KnownReg)); } } } @@ -5600,11 +5549,11 @@ void CX86RecompilerOps::SPECIAL_OR() Map_GPR_64bit(m_Opcode.rd, source1); if (Is64Bit(source2)) { - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); } else { - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); } } else @@ -5612,7 +5561,7 @@ void CX86RecompilerOps::SPECIAL_OR() ProtectGPR(source2); Map_GPR_32bit(m_Opcode.rd, true, source1); } - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else { @@ -5634,12 +5583,12 @@ void CX86RecompilerOps::SPECIAL_OR() Map_GPR_64bit(m_Opcode.rd, MappedReg); if ((Value >> 32) != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); } uint32_t dwValue = (uint32_t)(Value & 0xFFFFFFFF); if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } else @@ -5648,7 +5597,7 @@ void CX86RecompilerOps::SPECIAL_OR() Map_GPR_32bit(m_Opcode.rd, true, MappedReg); if (Value != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), Value); } } } @@ -5668,7 +5617,7 @@ void CX86RecompilerOps::SPECIAL_OR() Map_GPR_32bit(m_Opcode.rd, true, UnknownReg); if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } else @@ -5676,11 +5625,11 @@ void CX86RecompilerOps::SPECIAL_OR() Map_GPR_64bit(m_Opcode.rd, UnknownReg); if ((Value >> 32) != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); } if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } } @@ -5767,13 +5716,13 @@ void CX86RecompilerOps::SPECIAL_XOR() Map_GPR_64bit(m_Opcode.rd, source1); if (Is64Bit(source2)) { - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); } else if (IsSigned(source2)) { - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); } - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else { @@ -5785,7 +5734,7 @@ void CX86RecompilerOps::SPECIAL_XOR() { Map_GPR_32bit(m_Opcode.rd, IsSigned(m_Opcode.rt), source1); } - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } } else @@ -5802,11 +5751,11 @@ void CX86RecompilerOps::SPECIAL_XOR() Map_GPR_64bit(m_Opcode.rd, MappedReg); if (ConstHi != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), ConstHi); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), ConstHi); } if (ConstLo != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), ConstLo); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), ConstLo); } } else @@ -5822,7 +5771,7 @@ void CX86RecompilerOps::SPECIAL_XOR() } if (Value != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), Value); } } } @@ -5842,7 +5791,7 @@ void CX86RecompilerOps::SPECIAL_XOR() Map_GPR_64bit(m_Opcode.rd, UnknownReg); if ((Value >> 32) != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.xor_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); } } else @@ -5860,7 +5809,7 @@ void CX86RecompilerOps::SPECIAL_XOR() uint32_t dwValue = (uint32_t)(Value & 0xFFFFFFFF); if (dwValue != 0) { - m_Assembler.XorConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } else @@ -5936,11 +5885,11 @@ void CX86RecompilerOps::SPECIAL_NOR() Map_GPR_64bit(m_Opcode.rd, source1); if (Is64Bit(source2)) { - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapHi(source2)); } else { - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), Map_TempReg(x86Reg_Unknown, source2, true, false)); } } else @@ -5948,7 +5897,7 @@ void CX86RecompilerOps::SPECIAL_NOR() ProtectGPR(source2); Map_GPR_32bit(m_Opcode.rd, true, source1); } - m_Assembler.OrX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); } else { @@ -5970,12 +5919,12 @@ void CX86RecompilerOps::SPECIAL_NOR() Map_GPR_64bit(m_Opcode.rd, MappedReg); if ((Value >> 32) != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); } uint32_t dwValue = (uint32_t)(Value & 0xFFFFFFFF); if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } else @@ -5984,7 +5933,7 @@ void CX86RecompilerOps::SPECIAL_NOR() Map_GPR_32bit(m_Opcode.rd, true, MappedReg); if (Value != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), Value); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), Value); } } } @@ -6004,7 +5953,7 @@ void CX86RecompilerOps::SPECIAL_NOR() Map_GPR_32bit(m_Opcode.rd, true, UnknownReg); if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } else @@ -6012,11 +5961,11 @@ void CX86RecompilerOps::SPECIAL_NOR() Map_GPR_64bit(m_Opcode.rd, UnknownReg); if ((Value >> 32) != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); + m_Assembler.or_(GetMipsRegMapHi(m_Opcode.rd), (uint32_t)(Value >> 32)); } if (dwValue != 0) { - m_Assembler.OrConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), dwValue); + m_Assembler.or_(GetMipsRegMapLo(m_Opcode.rd), dwValue); } } } @@ -6054,9 +6003,9 @@ void CX86RecompilerOps::SPECIAL_NOR() { if (Is64Bit(m_Opcode.rd)) { - m_Assembler.NotX86Reg(GetMipsRegMapHi(m_Opcode.rd)); + m_Assembler.not_(GetMipsRegMapHi(m_Opcode.rd)); } - m_Assembler.NotX86Reg(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.not_(GetMipsRegMapLo(m_Opcode.rd)); } } @@ -6101,32 +6050,30 @@ void CX86RecompilerOps::SPECIAL_SLT() if ((Is64Bit(m_Opcode.rt) && Is64Bit(m_Opcode.rs)) || (!g_System->b32BitCore() && (Is64Bit(m_Opcode.rt) || Is64Bit(m_Opcode.rs)))) { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; - m_Assembler.CompX86RegToX86Reg( + m_Assembler.cmp( Is64Bit(m_Opcode.rs) ? GetMipsRegMapHi(m_Opcode.rs) : Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false), Is64Bit(m_Opcode.rt) ? GetMipsRegMapHi(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.bind(Jump[0]); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); } else { Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); if (GetMipsRegMapLo(m_Opcode.rd) != asmjit::x86::eax && GetMipsRegMapLo(m_Opcode.rd) != asmjit::x86::ebx) { @@ -6135,8 +6082,8 @@ void CX86RecompilerOps::SPECIAL_SLT() } else { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), 1); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), 1); } } } @@ -6148,13 +6095,13 @@ void CX86RecompilerOps::SPECIAL_SLT() ProtectGPR(MappedReg); if (Is64Bit(m_Opcode.rt) || Is64Bit(m_Opcode.rs)) { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; m_Assembler.CompConstToX86reg( Is64Bit(MappedReg) ? GetMipsRegMapHi(MappedReg) : Map_TempReg(x86Reg_Unknown, MappedReg, true, false), Is64Bit(ConstReg) ? GetMipsRegHi(ConstReg) : (GetMipsRegLo_S(ConstReg) >> 31)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); if (MappedReg == m_Opcode.rs) { m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); @@ -6163,12 +6110,11 @@ void CX86RecompilerOps::SPECIAL_SLT() { m_Assembler.SetgVariable(&m_BranchCompare, "m_BranchCompare"); } - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompConstToX86reg(GetMipsRegMapLo(MappedReg), GetMipsRegLo(ConstReg)); if (MappedReg == m_Opcode.rs) { @@ -6179,8 +6125,7 @@ void CX86RecompilerOps::SPECIAL_SLT() m_Assembler.SetaVariable(&m_BranchCompare, "m_BranchCompare"); } m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); } @@ -6206,13 +6151,13 @@ void CX86RecompilerOps::SPECIAL_SLT() { if (MappedReg == m_Opcode.rs) { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rd)); } else { - m_Assembler.Setg(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.setg(GetMipsRegMapLo(m_Opcode.rd)); } - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), 1); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), 1); } } } @@ -6221,7 +6166,7 @@ void CX86RecompilerOps::SPECIAL_SLT() { uint32_t KnownReg = IsKnown(m_Opcode.rt) ? m_Opcode.rt : m_Opcode.rs; uint32_t UnknownReg = IsKnown(m_Opcode.rt) ? m_Opcode.rs : m_Opcode.rt; - uint8_t * Jump[2]; + asmjit::Label Jump[2]; if (!g_System->b32BitCore()) { @@ -6248,8 +6193,8 @@ void CX86RecompilerOps::SPECIAL_SLT() m_Assembler.CompX86regToVariable(Map_TempReg(x86Reg_Unknown, KnownReg, true, false), &_GPR[UnknownReg].W[1], CRegName::GPR_Hi[UnknownReg]); } } - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); if (KnownReg == (IsConst(KnownReg) ? m_Opcode.rs : m_Opcode.rt)) { m_Assembler.SetgVariable(&m_BranchCompare, "m_BranchCompare"); @@ -6258,12 +6203,11 @@ void CX86RecompilerOps::SPECIAL_SLT() { m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); } - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); if (IsConst(KnownReg)) { m_Assembler.CompConstToVariable(&_GPR[UnknownReg].W[0], CRegName::GPR_Lo[UnknownReg], GetMipsRegLo(KnownReg)); @@ -6281,8 +6225,7 @@ void CX86RecompilerOps::SPECIAL_SLT() m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); } m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); } @@ -6320,19 +6263,19 @@ void CX86RecompilerOps::SPECIAL_SLT() { if (KnownReg == (bConstant ? m_Opcode.rs : m_Opcode.rt)) { - m_Assembler.Setg(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.setg(GetMipsRegMapLo(m_Opcode.rd)); } else { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rd)); } - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), 1); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), 1); } } } else if (g_System->b32BitCore()) { - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); Map_GPR_32bit(m_Opcode.rd, false, -1); m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); if (GetMipsRegMapLo(m_Opcode.rd) != asmjit::x86::eax && GetMipsRegMapLo(m_Opcode.rd) != asmjit::x86::ebx) @@ -6342,32 +6285,30 @@ void CX86RecompilerOps::SPECIAL_SLT() } else { - m_Assembler.Setl(GetMipsRegMapLo(m_Opcode.rd)); - m_Assembler.AndConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), 1); + m_Assembler.setl(GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.and_(GetMipsRegMapLo(m_Opcode.rd), 1); } } else { - uint8_t * Jump[2] = {nullptr, nullptr}; + asmjit::Label Jump[2]; - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rt].W[1], CRegName::GPR_Hi[m_Opcode.rt]); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetlVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompX86regToVariable(Map_TempReg(Reg, m_Opcode.rs, false, false), &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - if (Jump[1]) + if (Jump[1].isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); @@ -6415,31 +6356,29 @@ void CX86RecompilerOps::SPECIAL_SLTU() if ((Is64Bit(m_Opcode.rt) && Is64Bit(m_Opcode.rs)) || (!g_System->b32BitCore() && (Is64Bit(m_Opcode.rt) || Is64Bit(m_Opcode.rs)))) { - uint8_t * Jump[2]; + asmjit::Label Jump[2]; - m_Assembler.CompX86RegToX86Reg( + m_Assembler.cmp( Is64Bit(m_Opcode.rs) ? GetMipsRegMapHi(m_Opcode.rs) : Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false), Is64Bit(m_Opcode.rt) ? GetMipsRegMapHi(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false)); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.bind(Jump[0]); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); } else { - m_Assembler.CompX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.cmp(GetMipsRegMapLo(m_Opcode.rs), GetMipsRegMapLo(m_Opcode.rt)); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); @@ -6451,7 +6390,7 @@ void CX86RecompilerOps::SPECIAL_SLTU() { uint32_t ConstHi, ConstLo, ConstReg, MappedReg; asmjit::x86::Gp MappedRegHi, MappedRegLo; - uint8_t * Jump[2]; + asmjit::Label Jump[2]; ConstReg = IsConst(m_Opcode.rt) ? m_Opcode.rt : m_Opcode.rs; MappedReg = IsConst(m_Opcode.rt) ? m_Opcode.rs : m_Opcode.rt; @@ -6473,8 +6412,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.CompConstToX86reg(MappedRegHi, ConstHi); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); if (MappedReg == m_Opcode.rs) { m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); @@ -6483,12 +6422,11 @@ void CX86RecompilerOps::SPECIAL_SLTU() { m_Assembler.SetaVariable(&m_BranchCompare, "m_BranchCompare"); } - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompConstToX86reg(MappedRegLo, ConstLo); if (MappedReg == m_Opcode.rs) { @@ -6499,8 +6437,7 @@ void CX86RecompilerOps::SPECIAL_SLTU() m_Assembler.SetaVariable(&m_BranchCompare, "m_BranchCompare"); } m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); } @@ -6527,7 +6464,7 @@ void CX86RecompilerOps::SPECIAL_SLTU() { uint32_t KnownReg = IsKnown(m_Opcode.rt) ? m_Opcode.rt : m_Opcode.rs; uint32_t UnknownReg = IsKnown(m_Opcode.rt) ? m_Opcode.rs : m_Opcode.rt; - uint8_t * Jump[2] = {nullptr, nullptr}; + asmjit::Label Jump[2]; ProtectGPR(KnownReg); if (g_System->b32BitCore()) @@ -6577,8 +6514,8 @@ void CX86RecompilerOps::SPECIAL_SLTU() m_Assembler.CompX86regToVariable(Map_TempReg(x86Reg_Unknown, KnownReg, true, false), &_GPR[UnknownReg].W[1], CRegName::GPR_Hi[UnknownReg]); } } - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); if (KnownReg == (IsConst(KnownReg) ? m_Opcode.rs : m_Opcode.rt)) { @@ -6588,12 +6525,11 @@ void CX86RecompilerOps::SPECIAL_SLTU() { m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); } - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); if (IsConst(KnownReg)) { m_Assembler.CompConstToVariable(&_GPR[UnknownReg].W[0], CRegName::GPR_Lo[UnknownReg], GetMipsRegLo(KnownReg)); @@ -6610,11 +6546,10 @@ void CX86RecompilerOps::SPECIAL_SLTU() { m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); } - if (Jump[1]) + if (Jump[1].isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } } Map_GPR_32bit(m_Opcode.rd, true, -1); @@ -6622,7 +6557,7 @@ void CX86RecompilerOps::SPECIAL_SLTU() } else if (g_System->b32BitCore()) { - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, false, false); Map_GPR_32bit(m_Opcode.rd, false, -1); m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); @@ -6630,26 +6565,24 @@ void CX86RecompilerOps::SPECIAL_SLTU() } else { - uint8_t * Jump[2] = {nullptr, nullptr}; + asmjit::Label Jump[2]; - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rs, true, false); m_Assembler.CompX86regToVariable(Reg, &_GPR[m_Opcode.rt].W[1], CRegName::GPR_Hi[m_Opcode.rt]); - m_Assembler.JeLabel8("Low Compare", 0); - Jump[0] = *g_RecompPos - 1; + Jump[0] = m_Assembler.newLabel(); + m_Assembler.JeLabel("Low Compare", Jump[0]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - m_Assembler.JmpLabel8("Continue", 0); - Jump[1] = *g_RecompPos - 1; + Jump[1] = m_Assembler.newLabel(); + m_Assembler.JmpLabel("Continue", Jump[1]); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Low Compare:"); - m_Assembler.SetJump8(Jump[0], *g_RecompPos); + m_Assembler.bind(Jump[0]); m_Assembler.CompX86regToVariable(Map_TempReg(Reg, m_Opcode.rs, false, false), &_GPR[m_Opcode.rt].W[0], CRegName::GPR_Lo[m_Opcode.rt]); m_Assembler.SetbVariable(&m_BranchCompare, "m_BranchCompare"); - if (Jump[1]) + if (Jump[1].isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump[1], *g_RecompPos); + m_Assembler.bind(Jump[1]); } Map_GPR_32bit(m_Opcode.rd, true, -1); m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &m_BranchCompare, "m_BranchCompare"); @@ -6697,19 +6630,19 @@ void CX86RecompilerOps::SPECIAL_DADD() ProtectGPR(source1); ProtectGPR(source2); - const asmjit::x86::Gp & RegLo = Map_TempReg(x86Reg_Unknown, source1, false, false); - const asmjit::x86::Gp & RegHi = Map_TempReg(x86Reg_Unknown, source1, true, false); + asmjit::x86::Gp RegLo = Map_TempReg(x86Reg_Unknown, source1, false, false); + asmjit::x86::Gp RegHi = Map_TempReg(x86Reg_Unknown, source1, true, false); if (IsConst(source2)) { m_Assembler.AddConstToX86Reg(RegLo, GetMipsRegLo(source2)); - m_Assembler.AdcConstToX86Reg(RegHi, GetMipsRegHi(source2)); + m_Assembler.adc(RegHi, GetMipsRegHi(source2)); } else if (IsMapped(source2)) { - const asmjit::x86::Gp & HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); - m_Assembler.AddX86RegToX86Reg(RegLo, GetMipsRegMapLo(source2)); - m_Assembler.AdcX86RegToX86Reg(RegHi, HiReg); + asmjit::x86::Gp HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); + m_Assembler.add(RegLo, GetMipsRegMapLo(source2)); + m_Assembler.adc(RegHi, HiReg); } else { @@ -6717,15 +6650,15 @@ void CX86RecompilerOps::SPECIAL_DADD() m_Assembler.AdcVariableToX86reg(RegHi, &_GPR[source2].W[1], CRegName::GPR_Hi[source2]); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + 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) { UnProtectGPR(source1); UnProtectGPR(source2); Map_GPR_64bit(m_Opcode.rd, source1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), RegLo); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), RegHi); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), RegLo); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rd), RegHi); } } } @@ -6774,7 +6707,7 @@ void CX86RecompilerOps::SPECIAL_DADDU() m_Assembler.AddConstToX86Reg(GetMipsRegMapLo(m_Opcode.rd), LoReg); if (LoReg != 0) { - m_Assembler.AdcConstToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegHi(source2)); + m_Assembler.adc(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegHi(source2)); } else { @@ -6783,9 +6716,9 @@ void CX86RecompilerOps::SPECIAL_DADDU() } else if (IsMapped(source2)) { - const asmjit::x86::Gp & HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); - m_Assembler.AddX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); - m_Assembler.AdcX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), HiReg); + asmjit::x86::Gp HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); + m_Assembler.add(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(source2)); + m_Assembler.adc(GetMipsRegMapHi(m_Opcode.rd), HiReg); } else { @@ -6837,19 +6770,19 @@ void CX86RecompilerOps::SPECIAL_DSUB() ProtectGPR(source1); ProtectGPR(source2); - const asmjit::x86::Gp & RegLo = Map_TempReg(x86Reg_Unknown, source1, false, false); - const asmjit::x86::Gp & RegHi = Map_TempReg(x86Reg_Unknown, source1, true, false); + asmjit::x86::Gp RegLo = Map_TempReg(x86Reg_Unknown, source1, false, false); + asmjit::x86::Gp RegHi = Map_TempReg(x86Reg_Unknown, source1, true, false); if (IsConst(source2)) { - m_Assembler.SubConstFromX86Reg(RegLo, GetMipsRegLo(source2)); - m_Assembler.SbbConstFromX86Reg(RegHi, GetMipsRegHi(source2)); + m_Assembler.sub(RegLo, GetMipsRegLo(source2)); + m_Assembler.sbb(RegHi, GetMipsRegHi(source2)); } else if (IsMapped(source2)) { - const asmjit::x86::Gp & HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); - m_Assembler.SubX86RegToX86Reg(RegLo, GetMipsRegMapLo(source2)); - m_Assembler.SbbX86RegToX86Reg(RegHi, HiReg); + asmjit::x86::Gp HiReg = Is64Bit(source2) ? GetMipsRegMapHi(source2) : Map_TempReg(x86Reg_Unknown, source2, true, false); + m_Assembler.sub(RegLo, GetMipsRegMapLo(source2)); + m_Assembler.sbb(RegHi, HiReg); } else { @@ -6857,15 +6790,15 @@ void CX86RecompilerOps::SPECIAL_DSUB() m_Assembler.SbbVariableFromX86reg(RegHi, &_GPR[source2].W[1], CRegName::GPR_Hi[source2]); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_ExceptionOverflow, false, &CX86Ops::JoLabel32); + 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) { UnProtectGPR(source1); UnProtectGPR(source2); Map_GPR_64bit(m_Opcode.rd, source1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), RegLo); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), RegHi); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), RegLo); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rd), RegHi); } } } @@ -6904,11 +6837,11 @@ void CX86RecompilerOps::SPECIAL_DSUBU() { if (m_Opcode.rd == m_Opcode.rt) { - const asmjit::x86::Gp & HiReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); - const asmjit::x86::Gp & LoReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + asmjit::x86::Gp HiReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); + asmjit::x86::Gp LoReg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); Map_GPR_64bit(m_Opcode.rd, m_Opcode.rs); - m_Assembler.SubX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), LoReg); - m_Assembler.SbbX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), HiReg); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), LoReg); + m_Assembler.sbb(GetMipsRegMapHi(m_Opcode.rd), HiReg); return; } if (IsMapped(m_Opcode.rt)) @@ -6918,14 +6851,14 @@ void CX86RecompilerOps::SPECIAL_DSUBU() Map_GPR_64bit(m_Opcode.rd, m_Opcode.rs); if (IsConst(m_Opcode.rt)) { - m_Assembler.SubConstFromX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegLo(m_Opcode.rt)); - m_Assembler.SbbConstFromX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegHi(m_Opcode.rt)); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegLo(m_Opcode.rt)); + m_Assembler.sbb(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegHi(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - const asmjit::x86::Gp & HiReg = Is64Bit(m_Opcode.rt) ? GetMipsRegMapHi(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); - m_Assembler.SubX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); - m_Assembler.SbbX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), HiReg); + asmjit::x86::Gp HiReg = Is64Bit(m_Opcode.rt) ? GetMipsRegMapHi(m_Opcode.rt) : Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false); + m_Assembler.sub(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.sbb(GetMipsRegMapHi(m_Opcode.rd), HiReg); } else { @@ -6967,8 +6900,8 @@ void CX86RecompilerOps::SPECIAL_DSLL() } Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); - m_Assembler.ShiftLeftDoubleImmed(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shld(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shl(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } void CX86RecompilerOps::SPECIAL_DSRL() @@ -7001,8 +6934,8 @@ void CX86RecompilerOps::SPECIAL_DSRL() return; } Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); - m_Assembler.ShiftRightDoubleImmed(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); - m_Assembler.ShiftRightUnsignImmed(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shrd(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shr(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); } void CX86RecompilerOps::SPECIAL_DSRA() @@ -7037,8 +6970,8 @@ void CX86RecompilerOps::SPECIAL_DSRA() } Map_GPR_64bit(m_Opcode.rd, m_Opcode.rt); - m_Assembler.ShiftRightDoubleImmed(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); - m_Assembler.ShiftRightSignImmed(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shrd(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.sar(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); } void CX86RecompilerOps::SPECIAL_DSLL32() @@ -7075,20 +7008,20 @@ void CX86RecompilerOps::SPECIAL_DSLL32() Map_GPR_64bit(m_Opcode.rd, -1); if (m_Opcode.rt != m_Opcode.rd) { - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rt)); } else { m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", CX86Ops::x86_Name(GetMipsRegMapHi(m_Opcode.rt)), CX86Ops::x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); - const asmjit::x86::Gp & HiReg = GetMipsRegMapHi(m_Opcode.rt); + asmjit::x86::Gp HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); } if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shl(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); } - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); } else { @@ -7096,9 +7029,9 @@ void CX86RecompilerOps::SPECIAL_DSLL32() m_Assembler.MoveVariableToX86reg(GetMipsRegMapHi(m_Opcode.rd), &_GPR[m_Opcode.rt], CRegName::GPR_Hi[m_Opcode.rt]); if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftLeftSignImmed(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shl(GetMipsRegMapHi(m_Opcode.rd), (uint8_t)m_Opcode.sa); } - m_Assembler.XorX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); + m_Assembler.xor_(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapLo(m_Opcode.rd)); } } @@ -7122,7 +7055,7 @@ void CX86RecompilerOps::SPECIAL_DSRL32() if (m_Opcode.rt == m_Opcode.rd) { m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", CX86Ops::x86_Name(GetMipsRegMapHi(m_Opcode.rt)), CX86Ops::x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); - const asmjit::x86::Gp & HiReg = GetMipsRegMapHi(m_Opcode.rt); + asmjit::x86::Gp HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); Map_GPR_32bit(m_Opcode.rd, false, -1); @@ -7130,11 +7063,11 @@ void CX86RecompilerOps::SPECIAL_DSRL32() else { Map_GPR_32bit(m_Opcode.rd, false, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rt)); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rt)); } if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftRightUnsignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } else @@ -7148,7 +7081,7 @@ void CX86RecompilerOps::SPECIAL_DSRL32() m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &_GPR[m_Opcode.rt].UW[1], CRegName::GPR_Hi[m_Opcode.rt]); if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftRightUnsignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.shr(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } } @@ -7173,7 +7106,7 @@ void CX86RecompilerOps::SPECIAL_DSRA32() if (m_Opcode.rt == m_Opcode.rd) { m_CodeBlock.Log(" regcache: switch hi (%s) with lo (%s) for %s", CX86Ops::x86_Name(GetMipsRegMapHi(m_Opcode.rt)), CX86Ops::x86_Name(GetMipsRegMapLo(m_Opcode.rt)), CRegName::GPR[m_Opcode.rt]); - const asmjit::x86::Gp & HiReg = GetMipsRegMapHi(m_Opcode.rt); + asmjit::x86::Gp HiReg = GetMipsRegMapHi(m_Opcode.rt); m_RegWorkingSet.SetMipsRegMapHi(m_Opcode.rt, GetMipsRegMapLo(m_Opcode.rt)); m_RegWorkingSet.SetMipsRegMapLo(m_Opcode.rt, HiReg); Map_GPR_32bit(m_Opcode.rd, true, -1); @@ -7181,11 +7114,11 @@ void CX86RecompilerOps::SPECIAL_DSRA32() else { Map_GPR_32bit(m_Opcode.rd, true, -1); - m_Assembler.MoveX86RegToX86Reg(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rt)); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rd), GetMipsRegMapHi(m_Opcode.rt)); } if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftRightSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } else @@ -7199,7 +7132,7 @@ void CX86RecompilerOps::SPECIAL_DSRA32() m_Assembler.MoveVariableToX86reg(GetMipsRegMapLo(m_Opcode.rd), &_GPR[m_Opcode.rt].UW[1], CRegName::GPR_Lo[m_Opcode.rt]); if ((uint8_t)m_Opcode.sa != 0) { - m_Assembler.ShiftRightSignImmed(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); + m_Assembler.sar(GetMipsRegMapLo(m_Opcode.rd), (uint8_t)m_Opcode.sa); } } } @@ -7209,7 +7142,7 @@ void CX86RecompilerOps::COP0_MF() { Map_GPR_32bit(m_Opcode.rt, true, -1); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(m_Opcode.rd); + m_Assembler.push(m_Opcode.rd); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::Cop0_MF), "CRegisters::Cop0_MF", 8); m_Assembler.MoveX86regToVariable(&_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt], asmjit::x86::eax); m_RegWorkingSet.AfterCallDirect(); @@ -7220,7 +7153,7 @@ void CX86RecompilerOps::COP0_DMF() { Map_GPR_64bit(m_Opcode.rt, -1); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(m_Opcode.rd); + m_Assembler.push(m_Opcode.rd); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::Cop0_MF), "CRegisters::Cop0_MF", 8); m_Assembler.MoveX86regToVariable(&_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt], asmjit::x86::eax); m_Assembler.MoveX86regToVariable(&_GPR[m_Opcode.rt].UW[1], CRegName::GPR_Hi[m_Opcode.rt], asmjit::x86::edx); @@ -7238,26 +7171,26 @@ void CX86RecompilerOps::COP0_MT() m_RegWorkingSet.BeforeCallDirect(); if (IsConst(m_Opcode.rt)) { - m_Assembler.PushImm32(GetMipsRegLo_S(m_Opcode.rt) >> 31); - m_Assembler.PushImm32(GetMipsRegLo(m_Opcode.rt)); + m_Assembler.push(GetMipsRegLo_S(m_Opcode.rt) >> 31); + m_Assembler.push(GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - const asmjit::x86::Gp & HiReg = GetMipsRegMapLo(m_Opcode.rt) != asmjit::x86::edx ? asmjit::x86::edx : asmjit::x86::eax; - m_Assembler.MoveX86RegToX86Reg(HiReg, GetMipsRegMapLo(m_Opcode.rt)); - m_Assembler.ShiftRightSignImmed(HiReg, 0x1F); - m_Assembler.Push(HiReg); - m_Assembler.Push(GetMipsRegMapLo(m_Opcode.rt)); + asmjit::x86::Gp HiReg = GetMipsRegMapLo(m_Opcode.rt) != asmjit::x86::edx ? asmjit::x86::edx : asmjit::x86::eax; + m_Assembler.mov(HiReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.sar(HiReg, 0x1F); + m_Assembler.push(HiReg); + m_Assembler.push(GetMipsRegMapLo(m_Opcode.rt)); } else { m_Assembler.MoveVariableToX86reg(asmjit::x86::eax, &_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt]); - m_Assembler.MoveX86RegToX86Reg(asmjit::x86::edx, asmjit::x86::eax); - m_Assembler.ShiftRightSignImmed(asmjit::x86::edx, 0x1F); - m_Assembler.Push(asmjit::x86::edx); - m_Assembler.Push(asmjit::x86::eax); + m_Assembler.mov(asmjit::x86::edx, asmjit::x86::eax); + m_Assembler.sar(asmjit::x86::edx, 0x1F); + m_Assembler.push(asmjit::x86::edx); + m_Assembler.push(asmjit::x86::eax); } - m_Assembler.PushImm32(m_Opcode.rd); + m_Assembler.push(m_Opcode.rd); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::Cop0_MT), "CRegisters::Cop0_MT", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -7271,32 +7204,32 @@ void CX86RecompilerOps::COP0_DMT() m_RegWorkingSet.BeforeCallDirect(); if (IsConst(m_Opcode.rt)) { - m_Assembler.PushImm32(Is64Bit(m_Opcode.rt) ? GetMipsRegHi(m_Opcode.rt) : GetMipsRegLo_S(m_Opcode.rt) >> 31); - m_Assembler.PushImm32(GetMipsRegLo(m_Opcode.rt)); + m_Assembler.push(Is64Bit(m_Opcode.rt) ? GetMipsRegHi(m_Opcode.rt) : GetMipsRegLo_S(m_Opcode.rt) >> 31); + m_Assembler.push(GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { if (Is64Bit(m_Opcode.rt)) { - m_Assembler.Push(GetMipsRegMapHi(m_Opcode.rt)); + m_Assembler.push(GetMipsRegMapHi(m_Opcode.rt)); } else { - const asmjit::x86::Gp & HiReg = GetMipsRegMapLo(m_Opcode.rt) != asmjit::x86::edx ? asmjit::x86::edx : asmjit::x86::eax; - m_Assembler.MoveX86RegToX86Reg(HiReg, GetMipsRegMapLo(m_Opcode.rt)); - m_Assembler.ShiftRightSignImmed(HiReg, 0x1F); - m_Assembler.Push(HiReg); + asmjit::x86::Gp HiReg = GetMipsRegMapLo(m_Opcode.rt) != asmjit::x86::edx ? asmjit::x86::edx : asmjit::x86::eax; + m_Assembler.mov(HiReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.sar(HiReg, 0x1F); + m_Assembler.push(HiReg); } - m_Assembler.Push(GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.push(GetMipsRegMapLo(m_Opcode.rt)); } else { m_Assembler.MoveVariableToX86reg(asmjit::x86::eax, &_GPR[m_Opcode.rt].UW[0], CRegName::GPR_Lo[m_Opcode.rt]); m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &_GPR[m_Opcode.rt].UW[1], CRegName::GPR_Hi[m_Opcode.rt]); - m_Assembler.Push(asmjit::x86::edx); - m_Assembler.Push(asmjit::x86::eax); + m_Assembler.push(asmjit::x86::edx); + m_Assembler.push(asmjit::x86::eax); } - m_Assembler.PushImm32(m_Opcode.rd); + m_Assembler.push(m_Opcode.rd); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::Cop0_MT), "CRegisters::Cop0_MT", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -7314,8 +7247,8 @@ void CX86RecompilerOps::COP0_CO_TLBWI(void) m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("false", 0); m_Assembler.MoveVariableToX86reg(asmjit::x86::ecx, &g_Reg->INDEX_REGISTER, "INDEX_REGISTER"); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.Push(asmjit::x86::ecx); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.push(asmjit::x86::ecx); m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); m_RegWorkingSet.AfterCallDirect(); } @@ -7327,8 +7260,8 @@ void CX86RecompilerOps::COP0_CO_TLBWR(void) m_Assembler.CallThis((uint32_t)g_SystemTimer, AddressOf(&CSystemTimer::UpdateTimers), "CSystemTimer::UpdateTimers", 4); m_Assembler.PushImm32("true", true); m_Assembler.MoveVariableToX86reg(asmjit::x86::ecx, &g_Reg->RANDOM_REGISTER, "RANDOM_REGISTER"); - m_Assembler.AndConstToX86Reg(asmjit::x86::ecx, 0x1F); - m_Assembler.Push(asmjit::x86::ecx); + m_Assembler.and_(asmjit::x86::ecx, 0x1F); + m_Assembler.push(asmjit::x86::ecx); m_Assembler.CallThis((uint32_t)g_TLB, AddressOf(&CTLB::WriteEntry), "CTLB::WriteEntry", 12); m_RegWorkingSet.AfterCallDirect(); } @@ -7386,9 +7319,9 @@ void CX86RecompilerOps::COP1_MF() UnMap_FPR(m_Opcode.fs, true); Map_GPR_32bit(m_Opcode.rt, true, -1); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[m_Opcode.fs], stdstr_f("_FPR_S[%d]", m_Opcode.fs).c_str()); - m_Assembler.MoveX86PointerToX86reg(GetMipsRegMapLo(m_Opcode.rt), TempReg); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rt), asmjit::x86::dword_ptr(TempReg)); } void CX86RecompilerOps::COP1_DMF() @@ -7397,12 +7330,12 @@ void CX86RecompilerOps::COP1_DMF() UnMap_FPR(m_Opcode.fs, true); Map_GPR_64bit(m_Opcode.rt, -1); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[m_Opcode.fs], stdstr_f("_FPR_D[%d]", m_Opcode.fs).c_str()); m_Assembler.AddConstToX86Reg(TempReg, 4); - m_Assembler.MoveX86PointerToX86reg(GetMipsRegMapHi(m_Opcode.rt), TempReg); + m_Assembler.mov(GetMipsRegMapHi(m_Opcode.rt), asmjit::x86::dword_ptr(TempReg)); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[m_Opcode.fs], stdstr_f("_FPR_D[%d]", m_Opcode.fs).c_str()); - m_Assembler.MoveX86PointerToX86reg(GetMipsRegMapLo(m_Opcode.rt), TempReg); + m_Assembler.mov(GetMipsRegMapLo(m_Opcode.rt), asmjit::x86::dword_ptr(TempReg)); } void CX86RecompilerOps::COP1_CF() @@ -7431,20 +7364,20 @@ void CX86RecompilerOps::COP1_MT() } } UnMap_FPR(m_Opcode.fs, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[m_Opcode.fs], stdstr_f("_FPR_S[%d]", m_Opcode.fs).c_str()); if (IsConst(m_Opcode.rt)) { - m_Assembler.MoveConstToX86Pointer(TempReg, GetMipsRegLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegLo(m_Opcode.rt)); } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.MoveX86regToX86Pointer(TempReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegMapLo(m_Opcode.rt)); } else { - m_Assembler.MoveX86regToX86Pointer(TempReg, Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false)); } } @@ -7460,41 +7393,41 @@ void CX86RecompilerOps::COP1_DMT() } } UnMap_FPR(m_Opcode.fs, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[m_Opcode.fs], stdstr_f("_FPR_D[%d]", m_Opcode.fs).c_str()); if (IsConst(m_Opcode.rt)) { - m_Assembler.MoveConstToX86Pointer(TempReg, GetMipsRegLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegLo(m_Opcode.rt)); m_Assembler.AddConstToX86Reg(TempReg, 4); if (Is64Bit(m_Opcode.rt)) { - m_Assembler.MoveConstToX86Pointer(TempReg, GetMipsRegHi(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegHi(m_Opcode.rt)); } else { - m_Assembler.MoveConstToX86Pointer(TempReg, GetMipsRegLo_S(m_Opcode.rt) >> 31); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegLo_S(m_Opcode.rt) >> 31); } } else if (IsMapped(m_Opcode.rt)) { - m_Assembler.MoveX86regToX86Pointer(TempReg, GetMipsRegMapLo(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegMapLo(m_Opcode.rt)); m_Assembler.AddConstToX86Reg(TempReg, 4); if (Is64Bit(m_Opcode.rt)) { - m_Assembler.MoveX86regToX86Pointer(TempReg, GetMipsRegMapHi(m_Opcode.rt)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), GetMipsRegMapHi(m_Opcode.rt)); } else { - m_Assembler.MoveX86regToX86Pointer(TempReg, Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), Map_TempReg(x86Reg_Unknown, m_Opcode.rt, true, false)); } } else { - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); - m_Assembler.MoveX86regToX86Pointer(TempReg, Reg); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, m_Opcode.rt, false, false); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), Reg); m_Assembler.AddConstToX86Reg(TempReg, 4); - m_Assembler.MoveX86regToX86Pointer(TempReg, Map_TempReg(Reg, m_Opcode.rt, true, false)); + m_Assembler.mov(asmjit::x86::dword_ptr(TempReg), Map_TempReg(Reg, m_Opcode.rt, true, false)); } } @@ -7538,15 +7471,15 @@ void CX86RecompilerOps::COP1_S_ADD() Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Float); if (RegInStack(Reg2, CRegInfo::FPU_Float)) { - m_Assembler.fpuAddReg(StackPosition(Reg2)); + m_Assembler.fadd(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[Reg2], stdstr_f("_FPR_S[%d]", Reg2).c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Float); - m_Assembler.fpuAddDwordRegPointer(TempReg); + m_Assembler.fadd(asmjit::x86::dword_ptr(TempReg)); } UnMap_FPR(m_Opcode.fd, true); } @@ -7564,25 +7497,25 @@ void CX86RecompilerOps::COP1_S_SUB() UnMap_FPR(m_Opcode.fd, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.fpuSubDwordRegPointer(TempReg); + m_Assembler.fsub(asmjit::x86::dword_ptr(TempReg)); } else { Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Float); if (RegInStack(Reg2, CRegInfo::FPU_Float)) { - m_Assembler.fpuSubReg(StackPosition(Reg2)); + m_Assembler.fsub(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[Reg2], stdstr_f("_FPR_S[%d]", Reg2).c_str()); - m_Assembler.fpuSubDwordRegPointer(TempReg); + m_Assembler.fsub(asmjit::x86::dword_ptr(TempReg)); } } UnMap_FPR(m_Opcode.fd, true); @@ -7599,16 +7532,16 @@ void CX86RecompilerOps::COP1_S_MUL() Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Float); if (RegInStack(Reg2, CRegInfo::FPU_Float)) { - m_Assembler.fpuMulReg(StackPosition(Reg2)); + m_Assembler.fmul(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[Reg2], stdstr_f("_FPR_S[%d]", Reg2).c_str()); - m_Assembler.fpuMulDwordRegPointer(TempReg); + m_Assembler.fmul(asmjit::x86::dword_ptr(TempReg)); } UnMap_FPR(m_Opcode.fd, true); } @@ -7626,25 +7559,25 @@ void CX86RecompilerOps::COP1_S_DIV() UnMap_FPR(m_Opcode.fd, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[m_Opcode.ft], stdstr_f("_FPR_S[%d]", m_Opcode.ft).c_str()); - m_Assembler.fpuDivDwordRegPointer(TempReg); + m_Assembler.fdiv(asmjit::x86::dword_ptr(TempReg)); } else { Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Float); if (RegInStack(Reg2, CRegInfo::FPU_Float)) { - m_Assembler.fpuDivReg(StackPosition(Reg2)); + m_Assembler.fdiv(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[Reg2], stdstr_f("_FPR_S[%d]", Reg2).c_str()); - m_Assembler.fpuDivDwordRegPointer(TempReg); + m_Assembler.fdiv(asmjit::x86::dword_ptr(TempReg)); } } @@ -7656,7 +7589,7 @@ void CX86RecompilerOps::COP1_S_ABS() CompileCop1Test(); FixRoundModel(CRegInfo::RoundDefault); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - m_Assembler.fpuAbs(); + m_Assembler.fabs(); UnMap_FPR(m_Opcode.fd, true); } @@ -7665,7 +7598,7 @@ void CX86RecompilerOps::COP1_S_NEG() CompileCop1Test(); FixRoundModel(CRegInfo::RoundDefault); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - m_Assembler.fpuNeg(); + m_Assembler.fchs(); UnMap_FPR(m_Opcode.fd, true); } @@ -7674,7 +7607,7 @@ void CX86RecompilerOps::COP1_S_SQRT() CompileCop1Test(); FixRoundModel(CRegInfo::RoundDefault); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Float); - m_Assembler.fpuSqrt(); + m_Assembler.fsqrt(); UnMap_FPR(m_Opcode.fd, true); } @@ -7825,45 +7758,45 @@ void CX86RecompilerOps::COP1_S_CMP() Map_TempReg(asmjit::x86::eax, 0, false, false); if (RegInStack(Reg2, CRegInfo::FPU_Float)) { - m_Assembler.fpuComReg(StackPosition(Reg2), false); + m_Assembler.fcom(StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); Load_FPR_ToTop(Reg1, Reg1, CRegInfo::FPU_Float); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_S[Reg2], stdstr_f("_FPR_S[%d]", Reg2).c_str()); - m_Assembler.fpuComDwordRegPointer(TempReg, false); + m_Assembler.fcom(asmjit::x86::dword_ptr(TempReg)); } m_Assembler.AndConstToVariable(&_FPCR[31], "_FPCR[31]", (uint32_t)~FPCSR_C); - m_Assembler.fpuStoreStatus(); - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, 0, false, true); - m_Assembler.TestConstToX86Reg(asmjit::x86::eax, cmp); - m_Assembler.Setnz(Reg); + m_Assembler.fnstsw(asmjit::x86::ax); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, 0, false, true); + m_Assembler.test(asmjit::x86::eax, cmp); + m_Assembler.setnz(Reg); if (cmp != 0) { - m_Assembler.TestConstToX86Reg(asmjit::x86::eax, cmp); - m_Assembler.Setnz(Reg); + m_Assembler.test(asmjit::x86::eax, cmp); + m_Assembler.setnz(Reg); if ((m_Opcode.funct & 1) != 0) { - const asmjit::x86::Gp & _86RegReg2 = Map_TempReg(x86Reg_Unknown, 0, false, true); - m_Assembler.AndConstToX86Reg(asmjit::x86::eax, 0x4300); + asmjit::x86::Gp _86RegReg2 = Map_TempReg(x86Reg_Unknown, 0, false, true); + m_Assembler.and_(asmjit::x86::eax, 0x4300); m_Assembler.CompConstToX86reg(asmjit::x86::eax, 0x4300); - m_Assembler.Setz(_86RegReg2); + m_Assembler.setz(_86RegReg2); - m_Assembler.OrX86RegToX86Reg(Reg, _86RegReg2); + m_Assembler.or_(Reg, _86RegReg2); } } else if ((m_Opcode.funct & 1) != 0) { - m_Assembler.AndConstToX86Reg(asmjit::x86::eax, 0x4300); + m_Assembler.and_(asmjit::x86::eax, 0x4300); m_Assembler.CompConstToX86reg(asmjit::x86::eax, 0x4300); - m_Assembler.Setz(Reg); + m_Assembler.setz(Reg); } - m_Assembler.ShiftLeftSignImmed(Reg, 23); + m_Assembler.shl(Reg, 23); m_Assembler.OrX86RegToVariable(&_FPCR[31], "_FPCR[31]", Reg); } @@ -7878,15 +7811,15 @@ void CX86RecompilerOps::COP1_D_ADD() Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Double); if (RegInStack(Reg2, CRegInfo::FPU_Double)) { - m_Assembler.fpuAddReg(StackPosition(Reg2)); + m_Assembler.fadd(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[Reg2], stdstr_f("_FPR_D[%d]", Reg2).c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Double); - m_Assembler.fpuAddQwordRegPointer(TempReg); + m_Assembler.fadd(asmjit::x86::qword_ptr(TempReg)); } } @@ -7900,26 +7833,26 @@ void CX86RecompilerOps::COP1_D_SUB() if (m_Opcode.fd == m_Opcode.ft) { UnMap_FPR(m_Opcode.fd, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Double); - m_Assembler.fpuSubQwordRegPointer(TempReg); + m_Assembler.fsub(asmjit::x86::qword_ptr(TempReg)); } else { Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Double); if (RegInStack(Reg2, CRegInfo::FPU_Double)) { - m_Assembler.fpuSubReg(StackPosition(Reg2)); + m_Assembler.fsub(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[Reg2], stdstr_f("_FPR_D[%d]", Reg2).c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Double); - m_Assembler.fpuSubQwordRegPointer(TempReg); + m_Assembler.fsub(asmjit::x86::qword_ptr(TempReg)); } } } @@ -7935,15 +7868,15 @@ void CX86RecompilerOps::COP1_D_MUL() Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Double); if (RegInStack(Reg2, CRegInfo::FPU_Double)) { - m_Assembler.fpuMulReg(StackPosition(Reg2)); + m_Assembler.fmul(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Double); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[Reg2], stdstr_f("_FPR_D[%d]", Reg2).c_str()); - m_Assembler.fpuMulQwordRegPointer(TempReg); + m_Assembler.fmul(asmjit::x86::qword_ptr(TempReg)); } } @@ -7957,25 +7890,25 @@ void CX86RecompilerOps::COP1_D_DIV() if (m_Opcode.fd == m_Opcode.ft) { UnMap_FPR(m_Opcode.fd, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[m_Opcode.ft], stdstr_f("_FPR_D[%d]", m_Opcode.ft).c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Double); - m_Assembler.fpuDivQwordRegPointer(TempReg); + m_Assembler.fdiv(asmjit::x86::qword_ptr(TempReg)); } else { Load_FPR_ToTop(m_Opcode.fd, Reg1, CRegInfo::FPU_Double); if (RegInStack(Reg2, CRegInfo::FPU_Double)) { - m_Assembler.fpuDivReg(StackPosition(Reg2)); + m_Assembler.fdiv(asmjit::x86::st0, StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[Reg2], stdstr_f("_FPR_D[%d]").c_str()); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fd, CRegInfo::FPU_Double); - m_Assembler.fpuDivQwordRegPointer(TempReg); + m_Assembler.fdiv(asmjit::x86::qword_ptr(TempReg)); } } } @@ -7984,21 +7917,21 @@ void CX86RecompilerOps::COP1_D_ABS() { CompileCop1Test(); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Double); - m_Assembler.fpuAbs(); + m_Assembler.fabs(); } void CX86RecompilerOps::COP1_D_NEG() { CompileCop1Test(); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Double); - m_Assembler.fpuNeg(); + m_Assembler.fchs(); } void CX86RecompilerOps::COP1_D_SQRT() { CompileCop1Test(); Load_FPR_ToTop(m_Opcode.fd, m_Opcode.fs, CRegInfo::FPU_Double); - m_Assembler.fpuSqrt(); + m_Assembler.fsqrt(); } void CX86RecompilerOps::COP1_D_MOV() @@ -8191,43 +8124,43 @@ void CX86RecompilerOps::COP1_D_CMP() Map_TempReg(asmjit::x86::eax, 0, false, false); if (RegInStack(Reg2, CRegInfo::FPU_Double)) { - m_Assembler.fpuComReg(StackPosition(Reg2), false); + m_Assembler.fcom(StackPosition(Reg2)); } else { UnMap_FPR(Reg2, true); - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(TempReg, (uint8_t *)&_FPR_D[Reg2], stdstr_f("_FPR_D[%d]", Reg2).c_str()); Load_FPR_ToTop(Reg1, Reg1, CRegInfo::FPU_Double); - m_Assembler.fpuComQwordRegPointer(TempReg, false); + m_Assembler.fcom(asmjit::x86::qword_ptr(TempReg)); } m_Assembler.AndConstToVariable(&_FPCR[31], "_FPCR[31]", (uint32_t)~FPCSR_C); - m_Assembler.fpuStoreStatus(); - const asmjit::x86::Gp & Reg = Map_TempReg(x86Reg_Unknown, 0, false, true); - m_Assembler.TestConstToX86Reg(asmjit::x86::eax, cmp); - m_Assembler.Setnz(Reg); + m_Assembler.fnstsw(asmjit::x86::ax); + asmjit::x86::Gp Reg = Map_TempReg(x86Reg_Unknown, 0, false, true); + m_Assembler.test(asmjit::x86::eax, cmp); + m_Assembler.setnz(Reg); if (cmp != 0) { - m_Assembler.TestConstToX86Reg(asmjit::x86::eax, cmp); - m_Assembler.Setnz(Reg); + m_Assembler.test(asmjit::x86::eax, cmp); + m_Assembler.setnz(Reg); if ((m_Opcode.funct & 1) != 0) { - const asmjit::x86::Gp & _86RegReg2 = Map_TempReg(x86Reg_Unknown, 0, false, true); - m_Assembler.AndConstToX86Reg(asmjit::x86::eax, 0x4300); + asmjit::x86::Gp _86RegReg2 = Map_TempReg(x86Reg_Unknown, 0, false, true); + m_Assembler.and_(asmjit::x86::eax, 0x4300); m_Assembler.CompConstToX86reg(asmjit::x86::eax, 0x4300); - m_Assembler.Setz(_86RegReg2); + m_Assembler.setz(_86RegReg2); - m_Assembler.OrX86RegToX86Reg(Reg, _86RegReg2); + m_Assembler.or_(Reg, _86RegReg2); } } else if ((m_Opcode.funct & 1) != 0) { - m_Assembler.AndConstToX86Reg(asmjit::x86::eax, 0x4300); + m_Assembler.and_(asmjit::x86::eax, 0x4300); m_Assembler.CompConstToX86reg(asmjit::x86::eax, 0x4300); - m_Assembler.Setz(Reg); + m_Assembler.setz(Reg); } - m_Assembler.ShiftLeftSignImmed(Reg, 23); + m_Assembler.shl(Reg, 23); m_Assembler.OrX86RegToVariable(&_FPCR[31], "_FPCR[31]", Reg); } @@ -8289,7 +8222,7 @@ void CX86RecompilerOps::UnknownOpcode() m_Assembler.MoveConstToVariable(&R4300iOp::m_Opcode.Value, "R4300iOp::m_Opcode.Value", m_Opcode.Value); m_Assembler.CallFunc((uint32_t)R4300iOp::UnknownOpcode, "R4300iOp::UnknownOpcode"); - m_Assembler.Ret(); + m_Assembler.ret(); if (m_PipelineStage == PIPELINE_STAGE_NORMAL) { m_PipelineStage = PIPELINE_STAGE_END_BLOCK; @@ -8343,13 +8276,12 @@ void CX86RecompilerOps::TestBreakpoint(const asmjit::x86::Gp & AddressReg, uint3 m_Assembler.CallFunc(FunctAddress, FunctName); m_RegWorkingSet.AfterCallDirect(); m_Assembler.CompConstToVariable(&memory_breakpoint_found, "memory_breakpoint_found", 0); - m_Assembler.JeLabel8("NoBreakPoint", 0); - uint8_t * Jump = *g_RecompPos - 1; + asmjit::Label Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("NoBreakPoint", Jump); m_Assembler.MoveConstToVariable(&memory_breakpoint_found, "memory_breakpoint_found", 0); ExitCodeBlock(); - m_CodeBlock.Log(" "); - m_CodeBlock.Log(" NoBreakPoint:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_CodeBlock.Log(""); + m_Assembler.bind(Jump); } void CX86RecompilerOps::TestWriteBreakpoint(const asmjit::x86::Gp & AddressReg, uint32_t FunctAddress, const char * FunctName) @@ -8373,11 +8305,11 @@ void CX86RecompilerOps::TestReadBreakpoint(const asmjit::x86::Gp & AddressReg, u void CX86RecompilerOps::EnterCodeBlock() { #ifdef _DEBUG - m_Assembler.Push(asmjit::x86::esi); + m_Assembler.push(asmjit::x86::esi); #else - m_Assembler.Push(asmjit::x86::edi); - m_Assembler.Push(asmjit::x86::esi); - m_Assembler.Push(asmjit::x86::ebx); + m_Assembler.push(asmjit::x86::edi); + m_Assembler.push(asmjit::x86::esi); + m_Assembler.push(asmjit::x86::ebx); #endif } @@ -8388,13 +8320,13 @@ void CX86RecompilerOps::ExitCodeBlock() m_Assembler.CallThis((uint32_t)g_BaseSystem, AddressOf(&CN64System::SyncSystem), "CN64System::SyncSystem", 4); } #ifdef _DEBUG - m_Assembler.Pop(asmjit::x86::esi); + m_Assembler.pop(asmjit::x86::esi); #else - m_Assembler.Pop(asmjit::x86::ebx); - m_Assembler.Pop(asmjit::x86::esi); - m_Assembler.Pop(asmjit::x86::edi); + m_Assembler.pop(asmjit::x86::ebx); + m_Assembler.pop(asmjit::x86::esi); + m_Assembler.pop(asmjit::x86::edi); #endif - m_Assembler.Ret(); + m_Assembler.ret(); } void CX86RecompilerOps::CompileExitCode() @@ -8402,8 +8334,7 @@ void CX86RecompilerOps::CompileExitCode() for (EXIT_LIST::iterator ExitIter = m_ExitInfo.begin(); ExitIter != m_ExitInfo.end(); ExitIter++) { m_CodeBlock.Log(""); - m_CodeBlock.Log(" $%s", ExitIter->Name.c_str()); - m_Assembler.SetJump32(ExitIter->JumpLoc, (uint32_t *)*g_RecompPos); + m_Assembler.bind(ExitIter->JumpLabel); m_PipelineStage = ExitIter->PipelineStage; CompileExit((uint32_t)-1, ExitIter->TargetPC, ExitIter->ExitRegSet, ExitIter->Reason, true, nullptr); } @@ -8419,7 +8350,7 @@ void CX86RecompilerOps::CompileCop1Test() m_Assembler.TestVariable(&g_Reg->STATUS_REGISTER, "STATUS_REGISTER", STATUS_CU1); CRegInfo ExitRegSet = m_RegWorkingSet; ExitRegSet.SetBlockCycleCount(ExitRegSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, ExitRegSet, ExitReason_COP1Unuseable, false, &CX86Ops::JeLabel32); + CompileExit(m_CompilePC, m_CompilePC, ExitRegSet, ExitReason_COP1Unuseable, false, &CX86Ops::JeLabel); m_RegWorkingSet.SetFpuBeenUsed(true); } @@ -8465,17 +8396,17 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) { m_RegWorkingSet.SetRoundingModel(CRegInfo::RoundUnknown); } - const asmjit::x86::Gp & MemStackReg = Get_MemoryStack(); - const asmjit::x86::Gp & TargetStackReg = SyncTo.Get_MemoryStack(); + asmjit::x86::Gp MemStackReg = Get_MemoryStack(); + asmjit::x86::Gp TargetStackReg = SyncTo.Get_MemoryStack(); //m_CodeBlock.Log("MemoryStack for Original State = %s",MemStackReg > 0?CX86Ops::x86_Name(MemStackReg):"Not Mapped"); if (MemStackReg != TargetStackReg) { - if (TargetStackReg == x86Reg_Unknown) + if (!TargetStackReg.isValid()) { UnMap_X86reg(MemStackReg); } - else if (MemStackReg == x86Reg_Unknown) + else if (!MemStackReg.isValid()) { UnMap_X86reg(TargetStackReg); m_CodeBlock.Log(" regcache: allocate %s as memory stack", CX86Ops::x86_Name(TargetStackReg)); @@ -8488,7 +8419,7 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) m_CodeBlock.Log(" regcache: change allocation of memory stack from %s to %s", CX86Ops::x86_Name(MemStackReg), CX86Ops::x86_Name(TargetStackReg)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(TargetStackReg), CRegInfo::Stack_Mapped); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(MemStackReg), CRegInfo::NotMapped); - m_Assembler.MoveX86RegToX86Reg(TargetStackReg, MemStackReg); + m_Assembler.mov(TargetStackReg, MemStackReg); } } @@ -8540,8 +8471,8 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) case CRegInfo::STATE_UNKNOWN: UnMap_GPR(i, true); break; case CRegInfo::STATE_MAPPED_64: { - const asmjit::x86::Gp & Reg = SyncTo.GetMipsRegMapLo(i); - const asmjit::x86::Gp & x86RegHi = SyncTo.GetMipsRegMapHi(i); + asmjit::x86::Gp Reg = SyncTo.GetMipsRegMapLo(i); + asmjit::x86::Gp x86RegHi = SyncTo.GetMipsRegMapHi(i); UnMap_X86reg(Reg); UnMap_X86reg(x86RegHi); switch (GetMipsRegState(i)) @@ -8551,20 +8482,20 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) m_Assembler.MoveVariableToX86reg(x86RegHi, &_GPR[i].UW[1], CRegName::GPR_Hi[i]); break; case CRegInfo::STATE_MAPPED_64: - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); - m_Assembler.MoveX86RegToX86Reg(x86RegHi, GetMipsRegMapHi(i)); + m_Assembler.mov(x86RegHi, GetMipsRegMapHi(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapHi(i)), CRegInfo::NotMapped); break; case CRegInfo::STATE_MAPPED_32_SIGN: - m_Assembler.MoveX86RegToX86Reg(x86RegHi, GetMipsRegMapLo(i)); - m_Assembler.ShiftRightSignImmed(x86RegHi, 31); - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(x86RegHi, GetMipsRegMapLo(i)); + m_Assembler.sar(x86RegHi, 31); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); break; case CRegInfo::STATE_MAPPED_32_ZERO: - m_Assembler.XorX86RegToX86Reg(x86RegHi, x86RegHi); - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.xor_(x86RegHi, x86RegHi); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); break; case CRegInfo::STATE_CONST_64: @@ -8591,25 +8522,25 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) } case CRegInfo::STATE_MAPPED_32_SIGN: { - const asmjit::x86::Gp & Reg = SyncTo.GetMipsRegMapLo(i); + asmjit::x86::Gp Reg = SyncTo.GetMipsRegMapLo(i); UnMap_X86reg(Reg); switch (GetMipsRegState(i)) { case CRegInfo::STATE_UNKNOWN: m_Assembler.MoveVariableToX86reg(Reg, &_GPR[i].UW[0], CRegName::GPR_Lo[i]); break; case CRegInfo::STATE_CONST_32_SIGN: m_Assembler.MoveConstToX86reg(Reg, GetMipsRegLo(i)); break; case CRegInfo::STATE_MAPPED_32_SIGN: - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); break; case CRegInfo::STATE_MAPPED_32_ZERO: if (GetMipsRegMapLo(i) != Reg) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); } break; case CRegInfo::STATE_MAPPED_64: - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapHi(i)), CRegInfo::NotMapped); break; @@ -8627,7 +8558,7 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) } case CRegInfo::STATE_MAPPED_32_ZERO: { - const asmjit::x86::Gp & Reg = SyncTo.GetMipsRegMapLo(i); + asmjit::x86::Gp Reg = SyncTo.GetMipsRegMapLo(i); UnMap_X86reg(Reg); switch (GetMipsRegState(i)) { @@ -8636,13 +8567,13 @@ void CX86RecompilerOps::SyncRegState(const CRegInfo & SyncTo) m_Assembler.MoveVariableToX86reg(Reg, &_GPR[i].UW[0], CRegName::GPR_Lo[i]); break; case CRegInfo::STATE_MAPPED_32_ZERO: - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); break; case CRegInfo::STATE_MAPPED_32_SIGN: if (g_System->b32BitCore()) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(i)); + m_Assembler.mov(Reg, GetMipsRegMapLo(i)); m_RegWorkingSet.SetX86Mapped(GetIndexFromX86Reg(GetMipsRegMapLo(i)), CRegInfo::NotMapped); } else @@ -8690,16 +8621,7 @@ void CX86RecompilerOps::SetRegWorkingSet(const CRegInfo & RegInfo) bool CX86RecompilerOps::InheritParentInfo() { - if (m_Section->m_CompiledLocation == nullptr) - { - m_Section->m_CompiledLocation = *g_RecompPos; - m_Section->DisplaySectionInformation(); - m_Section->m_CompiledLocation = nullptr; - } - else - { - m_Section->DisplaySectionInformation(); - } + m_Section->DisplaySectionInformation(); if (m_Section->m_ParentSection.empty()) { @@ -8710,7 +8632,7 @@ bool CX86RecompilerOps::InheritParentInfo() if (m_Section->m_ParentSection.size() == 1) { CCodeSection * Parent = *(m_Section->m_ParentSection.begin()); - if (Parent->m_CompiledLocation == nullptr) + if (!Parent->m_EnterLabel.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } @@ -8730,7 +8652,7 @@ bool CX86RecompilerOps::InheritParentInfo() CCodeSection * Parent = *iter; BLOCK_PARENT BlockParent; - if (Parent->m_CompiledLocation == nullptr) + if (!Parent->m_EnterLabel.isValid()) { continue; } @@ -8763,7 +8685,7 @@ bool CX86RecompilerOps::InheritParentInfo() CCodeSection * Parent = *iter; BLOCK_PARENT BlockParent; - if (Parent->m_CompiledLocation != nullptr) + if (Parent->m_EnterLabel.isValid()) { continue; } @@ -8858,7 +8780,7 @@ bool CX86RecompilerOps::InheritParentInfo() continue; } Parent = ParentList[i].Parent; - if (Parent->m_CompiledLocation == nullptr) + if (!Parent->m_EnterLabel.isValid()) { continue; } @@ -8879,11 +8801,11 @@ bool CX86RecompilerOps::InheritParentInfo() break; } } - if (MemoryStackPos == x86Reg_Unknown) + if (!MemoryStackPos.isValid()) { // If the memory stack position is not mapped then unmap it - const asmjit::x86::Gp & MemStackReg = Get_MemoryStack(); - if (MemStackReg != x86Reg_Unknown) + asmjit::x86::Gp MemStackReg = Get_MemoryStack(); + if (MemStackReg.isValid()) { UnMap_X86reg(MemStackReg); } @@ -9080,25 +9002,24 @@ bool CX86RecompilerOps::InheritParentInfo() } Parent = ParentList[CurrentParent].Parent; JumpInfo = ParentList[CurrentParent].JumpInfo; - m_Assembler.JmpLabel32(Label.c_str(), 0); - JumpInfo->LinkLocation = (uint32_t *)(*g_RecompPos - 4); - JumpInfo->LinkLocation2 = nullptr; + JumpInfo->LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(Label.c_str(), JumpInfo->LinkLocation); + JumpInfo->LinkLocation2 = asmjit::Label(); CurrentParent = i; Parent = ParentList[CurrentParent].Parent; JumpInfo = ParentList[CurrentParent].JumpInfo; m_CodeBlock.Log(" Section_%d (from %d):", m_Section->m_SectionID, Parent->m_SectionID); - if (JumpInfo->LinkLocation != nullptr) + if (JumpInfo->LinkLocation.isValid()) { - m_Assembler.SetJump32(JumpInfo->LinkLocation, (uint32_t *)*g_RecompPos); - JumpInfo->LinkLocation = nullptr; - if (JumpInfo->LinkLocation2 != nullptr) + m_Assembler.bind(JumpInfo->LinkLocation); + JumpInfo->LinkLocation = asmjit::Label(); + if (JumpInfo->LinkLocation2.isValid()) { - m_Assembler.SetJump32(JumpInfo->LinkLocation2, (uint32_t *)*g_RecompPos); - JumpInfo->LinkLocation2 = nullptr; + m_Assembler.bind(JumpInfo->LinkLocation2); + JumpInfo->LinkLocation2 = asmjit::Label(); } } - m_RegWorkingSet = JumpInfo->RegSet; if (m_Section->m_EnterPC < JumpInfo->JumpPC) { @@ -9128,41 +9049,27 @@ bool CX86RecompilerOps::InheritParentInfo() void CX86RecompilerOps::LinkJump(CJumpInfo & JumpInfo, uint32_t SectionID, uint32_t FromSectionID) { - if (JumpInfo.LinkLocation != nullptr) + if (JumpInfo.LinkLocation.isValid()) { - if (SectionID != -1) + m_Assembler.bind(JumpInfo.LinkLocation); + JumpInfo.LinkLocation = asmjit::Label(); + if (JumpInfo.LinkLocation2.isValid()) { - if (FromSectionID != -1) - { - m_CodeBlock.Log(" Section_%d (from %d):", SectionID, FromSectionID); - } - else - { - m_CodeBlock.Log(" Section_%d:", SectionID); - } - } - m_Assembler.SetJump32(JumpInfo.LinkLocation, (uint32_t *)*g_RecompPos); - JumpInfo.LinkLocation = nullptr; - if (JumpInfo.LinkLocation2 != nullptr) - { - m_Assembler.SetJump32(JumpInfo.LinkLocation2, (uint32_t *)*g_RecompPos); - JumpInfo.LinkLocation2 = nullptr; + m_Assembler.bind(JumpInfo.LinkLocation2); + JumpInfo.LinkLocation2 = asmjit::Label(); } } } void CX86RecompilerOps::JumpToSection(CCodeSection * Section) { - char Label[100]; - sprintf(Label, "Section_%d", Section->m_SectionID); - m_Assembler.JmpLabel32(Label, 0); - m_Assembler.SetJump32(((uint32_t *)*g_RecompPos) - 1, (uint32_t *)(Section->m_CompiledLocation)); + m_Assembler.JmpLabel(stdstr_f("Section_%d", Section->m_SectionID).c_str(), Section->m_EnterLabel); } void CX86RecompilerOps::JumpToUnknown(CJumpInfo * JumpInfo) { - m_Assembler.JmpLabel32(JumpInfo->BranchLabel.c_str(), 0); - JumpInfo->LinkLocation = (uint32_t *)(*g_RecompPos - 4); + JumpInfo->LinkLocation = m_Assembler.newLabel(); + m_Assembler.JmpLabel(JumpInfo->BranchLabel.c_str(), JumpInfo->LinkLocation); } void CX86RecompilerOps::SetCurrentPC(uint32_t ProgramCounter) @@ -9213,7 +9120,8 @@ void CX86RecompilerOps::UpdateSyncCPU(CRegInfo & RegSet, uint32_t Cycles) return; } - m_Assembler.WriteX86Comment("Updating sync CPU"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" // Updating sync CPU"); RegSet.BeforeCallDirect(); m_Assembler.PushImm32(stdstr_f("%d", Cycles).c_str(), Cycles); m_Assembler.PushImm32("g_SyncSystem", (uint32_t)g_SyncSystem); @@ -9226,7 +9134,8 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool if (RegSet.GetBlockCycleCount() != 0) { UpdateSyncCPU(RegSet, RegSet.GetBlockCycleCount()); - m_Assembler.WriteX86Comment("Update counter"); + m_CodeBlock.Log(""); + m_CodeBlock.Log(" // Update counter"); m_Assembler.SubConstFromVariable(RegSet.GetBlockCycleCount(), g_NextTimer, "g_NextTimer"); // Updates compare flag if (ClearValues) { @@ -9240,15 +9149,14 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool if (CheckTimer) { - m_Assembler.JnsLabel8("Continue_From_Timer_Test", 0); - uint8_t * Jump = *g_RecompPos - 1; + asmjit::Label Jump = m_Assembler.newLabel(); + m_Assembler.JnsLabel("Continue_From_Timer_Test", Jump); RegSet.BeforeCallDirect(); m_Assembler.CallThis((uint32_t)g_SystemTimer, AddressOf(&CSystemTimer::TimerDone), "CSystemTimer::TimerDone", 4); RegSet.AfterCallDirect(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" $Continue_From_Timer_Test:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } if ((UpdateTimer || CGameSettings::OverClockModifier() != 1) && g_SyncSystem) @@ -9262,8 +9170,8 @@ void CX86RecompilerOps::UpdateCounters(CRegInfo & RegSet, bool CheckTimer, bool void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & RegSet) { m_Assembler.CompConstToVariable((void *)&g_SystemEvents->DoSomething(), "g_SystemEvents->DoSomething()", 0); - m_Assembler.JeLabel32("Continue_From_Interrupt_Test", 0); - uint32_t * Jump = (uint32_t *)(*g_RecompPos - 4); + asmjit::Label Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("Continue_From_Interrupt_Test", Jump); if (TargetPC != (uint32_t)-1) { m_Assembler.MoveConstToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", TargetPC); @@ -9274,8 +9182,7 @@ void CX86RecompilerOps::CompileSystemCheck(uint32_t TargetPC, const CRegInfo & R m_Assembler.CallThis((uint32_t)g_SystemEvents, AddressOf(&CSystemEvents::ExecuteEvents), "CSystemEvents::ExecuteEvents", 4); ExitCodeBlock(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" $Continue_From_Interrupt_Test:"); - m_Assembler.SetJump32(Jump, (uint32_t *)*g_RecompPos); + m_Assembler.bind(Jump); } void CX86RecompilerOps::CompileExecuteBP(void) @@ -9359,7 +9266,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo CompileExit(JumpPC, TargetPC, ExitRegSet, reason, true, nullptr); } -void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason reason, bool CompileNow, void (CX86Ops::*x86Jmp)(const char * Label, uint32_t Value)) +void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason reason, bool CompileNow, void (CX86Ops::*x86Jmp)(const char * LabelName, asmjit::Label & JumpLabel)) { if (!CompileNow) { @@ -9368,16 +9275,15 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo g_Notify->BreakPoint(__FILE__, __LINE__); return; } - stdstr_f ExitName("Exit_%08X_%d", JumpPC, m_ExitInfo.size()); - (m_Assembler.*x86Jmp)(ExitName.c_str(), 0); CExitInfo ExitInfo(m_CodeBlock); + stdstr_f ExitName("Exit_%08X_%d", JumpPC, m_ExitInfo.size()); + (m_Assembler.*x86Jmp)(ExitName.c_str(), ExitInfo.JumpLabel); ExitInfo.ID = m_ExitInfo.size(); ExitInfo.Name = ExitName; ExitInfo.TargetPC = TargetPC; ExitInfo.ExitRegSet = ExitRegSet; ExitInfo.Reason = reason; ExitInfo.PipelineStage = m_PipelineStage; - ExitInfo.JumpLoc = (uint32_t *)(*g_RecompPos - 4); m_ExitInfo.push_back(ExitInfo); return; } @@ -9434,7 +9340,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo ExitCodeBlock(); break; case ExitReason_COP1Unuseable: - m_Assembler.PushImm32("1", 1); + m_Assembler.push(1); m_Assembler.PushImm32(InDelaySlot ? "true" : "false", InDelaySlot); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::DoCopUnusableException), "CRegisters::DoCopUnusableException", 12); ExitCodeBlock(); @@ -9445,7 +9351,7 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo break; case ExitReason_TLBReadMiss: m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, g_TLBLoadAddress, "g_TLBLoadAddress"); - m_Assembler.Push(asmjit::x86::edx); + m_Assembler.push(asmjit::x86::edx); m_Assembler.PushImm32(InDelaySlot ? "true" : "false", InDelaySlot); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::DoTLBReadMiss), "CRegisters::DoTLBReadMiss", 12); ExitCodeBlock(); @@ -9460,22 +9366,22 @@ void CX86RecompilerOps::CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo ExitCodeBlock(); break; case ExitReason_AddressErrorExceptionRead32: - m_Assembler.PushImm32("1", 1); + m_Assembler.push(1); m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &m_TempValue32, "TempValue32"); - m_Assembler.MoveX86RegToX86Reg(asmjit::x86::eax, asmjit::x86::edx); - m_Assembler.ShiftRightSignImmed(asmjit::x86::eax, 31); - m_Assembler.Push(asmjit::x86::eax); - m_Assembler.Push(asmjit::x86::edx); + m_Assembler.mov(asmjit::x86::eax, asmjit::x86::edx); + m_Assembler.sar(asmjit::x86::eax, 31); + m_Assembler.push(asmjit::x86::eax); + m_Assembler.push(asmjit::x86::edx); m_Assembler.PushImm32(InDelaySlot ? "true" : "false", InDelaySlot); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::DoAddressError), "CRegisters::DoAddressError", 12); ExitCodeBlock(); break; case ExitReason_AddressErrorExceptionRead64: - m_Assembler.PushImm32("1", 1); + m_Assembler.push(1); m_Assembler.MoveVariableToX86reg(asmjit::x86::edx, &m_TempValue64, "TempValue64"); m_Assembler.MoveVariableToX86reg(asmjit::x86::eax, &m_TempValue64 + 4, "TempValue64+4"); - m_Assembler.Push(asmjit::x86::eax); - m_Assembler.Push(asmjit::x86::edx); + m_Assembler.push(asmjit::x86::eax); + m_Assembler.push(asmjit::x86::edx); m_Assembler.PushImm32(InDelaySlot ? "true" : "false", InDelaySlot); m_Assembler.CallThis((uint32_t)g_Reg, AddressOf(&CRegisters::DoAddressError), "CRegisters::DoAddressError", 12); ExitCodeBlock(); @@ -9501,7 +9407,7 @@ asmjit::x86::Gp CX86RecompilerOps::BaseOffsetAddress(bool UseBaseRegister) bool UnProtect = m_RegWorkingSet.GetX86Protected(GetIndexFromX86Reg(GetMipsRegMapLo(m_Opcode.base))); ProtectGPR(m_Opcode.base); AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.LeaSourceAndOffset(AddressReg, GetMipsRegMapLo(m_Opcode.base), (int16_t)m_Opcode.offset); + m_Assembler.lea(AddressReg, asmjit::x86::ptr(GetMipsRegMapLo(m_Opcode.base), (int16_t)m_Opcode.offset)); if (!UnProtect) { UnProtectGPR(m_Opcode.base); @@ -9526,9 +9432,9 @@ asmjit::x86::Gp CX86RecompilerOps::BaseOffsetAddress(bool UseBaseRegister) if (!b32BitCore() && ((IsKnown(m_Opcode.base) && Is64Bit(m_Opcode.base)) || IsUnknown(m_Opcode.base))) { m_Assembler.MoveX86regToVariable(&m_TempValue64, "TempValue64", AddressReg); - const asmjit::x86::Gp & AddressRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(AddressRegHi, AddressReg); - m_Assembler.ShiftRightSignImmed(AddressRegHi, 31); + asmjit::x86::Gp AddressRegHi = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(AddressRegHi, AddressReg); + m_Assembler.sar(AddressRegHi, 31); if (IsConst(m_Opcode.base)) { @@ -9538,18 +9444,18 @@ asmjit::x86::Gp CX86RecompilerOps::BaseOffsetAddress(bool UseBaseRegister) else if (IsMapped(m_Opcode.base)) { m_Assembler.MoveX86regToVariable(&m_TempValue64 + 4, "TempValue64 + 4", GetMipsRegMapHi(m_Opcode.base)); - m_Assembler.CompX86RegToX86Reg(AddressRegHi, GetMipsRegMapHi(m_Opcode.base)); + m_Assembler.cmp(AddressRegHi, GetMipsRegMapHi(m_Opcode.base)); } else { - const asmjit::x86::Gp & AddressMemoryHi = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressMemoryHi = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(AddressMemoryHi, &_GPR[m_Opcode.base].W[1], CRegName::GPR_Hi[m_Opcode.base]); m_Assembler.MoveX86regToVariable(&m_TempValue64 + 4, "TempValue64 + 4", AddressMemoryHi); - m_Assembler.CompX86RegToX86Reg(AddressRegHi, AddressMemoryHi); + m_Assembler.cmp(AddressRegHi, AddressMemoryHi); m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(AddressMemoryHi), false); } m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead64, false, &CX86Ops::JneLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead64, false, &CX86Ops::JneLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(AddressRegHi), false); } @@ -9558,8 +9464,8 @@ asmjit::x86::Gp CX86RecompilerOps::BaseOffsetAddress(bool UseBaseRegister) void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmjit::x86::Gp ValueReg, const asmjit::x86::Gp & ValueRegHi, uint8_t ValueSize, bool SignExtend) { - bool UnprotectAddressReg = AddressReg == x86Reg_Unknown; - if (AddressReg == x86Reg_Unknown) + bool UnprotectAddressReg = !AddressReg.isValid(); + if (UnprotectAddressReg) { if (ValueSize == 8) { @@ -9587,30 +9493,30 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji } } - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); if (ValueSize == 16) { m_Assembler.MoveX86regToVariable(&m_TempValue32, "TempValue32", AddressReg); - m_Assembler.TestConstToX86Reg(AddressReg, 1); + m_Assembler.test(AddressReg, 1); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead32, false, &CX86Ops::JneLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead32, false, &CX86Ops::JneLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); } else if (ValueSize == 32) { m_Assembler.MoveX86regToVariable(&m_TempValue32, "TempValue32", AddressReg); - m_Assembler.TestConstToX86Reg(AddressReg, 3); + m_Assembler.test(AddressReg, 3); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() + g_System->CountPerOp()); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead32, false, &CX86Ops::JneLabel32); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_AddressErrorExceptionRead32, false, &CX86Ops::JneLabel); m_RegWorkingSet.SetBlockCycleCount(m_RegWorkingSet.GetBlockCycleCount() - g_System->CountPerOp()); } - m_Assembler.MoveX86RegToX86Reg(TempReg, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg, 12); + m_Assembler.mov(TempReg, AddressReg); + m_Assembler.shr(TempReg, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg, g_MMU->m_MemoryReadMap, "MMU->m_MemoryReadMap", TempReg, CX86Ops::Multip_x4); m_Assembler.CompConstToX86reg(TempReg, (uint32_t)-1); - m_Assembler.JneLabel8(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), 0); - uint8_t * JumpFound = (uint8_t *)(*g_RecompPos - 1); + asmjit::Label JumpFound = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("MemoryReadMap_%X_Found", m_CompilePC).c_str(), JumpFound); uint32_t OpsExecuted = m_RegWorkingSet.GetBlockCycleCount(); if (OpsExecuted != 0) { @@ -9622,39 +9528,39 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)(&m_MMU), AddressOf(&CMipsMemoryVM::LW_NonMemory), "CMipsMemoryVM::LW_NonMemory", 12); - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); m_Assembler.MoveConstToX86reg(TempReg, (uint32_t)&m_TempValue32); - m_Assembler.SubX86RegToX86Reg(TempReg, AddressReg); + m_Assembler.sub(TempReg, AddressReg); } else if (ValueSize == 16) { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)(&m_MMU), AddressOf(&CMipsMemoryVM::LH_NonMemory), "CMipsMemoryVM::LH_NonMemory", 12); - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); m_Assembler.MoveConstToX86reg(TempReg, (uint32_t)&m_TempValue32); - m_Assembler.SubX86RegToX86Reg(TempReg, AddressReg); - m_Assembler.XorConstToX86Reg(AddressReg, 2); + m_Assembler.sub(TempReg, AddressReg); + m_Assembler.xor_(AddressReg, 2); } else if (ValueSize == 8) { m_RegWorkingSet.BeforeCallDirect(); m_Assembler.PushImm32("m_TempValue32", (uint32_t)&m_TempValue32); - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)&m_MMU, AddressOf(&CMipsMemoryVM::LB_NonMemory), "CMipsMemoryVM::LB_NonMemory", 12); - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); + CompileExit((uint32_t)-1, (uint32_t)-1, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); m_Assembler.MoveConstToX86reg(TempReg, (uint32_t)&m_TempValue32); - m_Assembler.SubX86RegToX86Reg(TempReg, AddressReg); - m_Assembler.XorConstToX86Reg(AddressReg, 3); + m_Assembler.sub(TempReg, AddressReg); + m_Assembler.xor_(AddressReg, 3); } else { @@ -9665,29 +9571,28 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji m_Assembler.AddConstToVariable(g_NextTimer, "g_NextTimer", OpsExecuted); } m_CodeBlock.Log(""); - m_CodeBlock.Log(stdstr_f(" MemoryReadMap_%X_Found:", m_CompilePC).c_str()); - m_Assembler.SetJump8(JumpFound, *g_RecompPos); + m_Assembler.bind(JumpFound); if (ValueSize == 8) { - m_Assembler.XorConstToX86Reg(AddressReg, 3); - if (ValueReg == x86Reg_Unknown) + m_Assembler.xor_(AddressReg, 3); + if (!ValueReg.isValid()) { g_Notify->BreakPoint(__FILE__, __LINE__); } else if (SignExtend) { - m_Assembler.MoveSxByteX86regPointerToX86reg(ValueReg, AddressReg, TempReg); + m_Assembler.movsx(ValueReg, asmjit::x86::byte_ptr(AddressReg, TempReg)); } else { - m_Assembler.MoveZxByteX86regPointerToX86reg(ValueReg, AddressReg, TempReg); + m_Assembler.movzx(ValueReg, asmjit::x86::byte_ptr(AddressReg, TempReg)); } } else if (ValueSize == 16) { - m_Assembler.XorConstToX86Reg(AddressReg, 2); - if (ValueReg == x86Reg_Unknown) + m_Assembler.xor_(AddressReg, 2); + if (!ValueReg.isValid()) { Map_GPR_32bit(m_Opcode.rt, SignExtend, -1); ValueReg = GetMipsRegMapLo(m_Opcode.rt); @@ -9695,24 +9600,24 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji if (SignExtend) { - m_Assembler.MoveSxHalfX86regPointerToX86reg(ValueReg, AddressReg, TempReg); + m_Assembler.movsx(ValueReg, asmjit::x86::word_ptr(AddressReg, TempReg)); } else { - m_Assembler.MoveZxHalfX86regPointerToX86reg(ValueReg, AddressReg, TempReg); + m_Assembler.movzx(ValueReg, asmjit::x86::word_ptr(AddressReg, TempReg)); } } else if (ValueSize == 32) { - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { Map_GPR_32bit(m_Opcode.rt, true, -1); ValueReg = GetMipsRegMapLo(m_Opcode.rt); } - if (ValueReg != x86Reg_Unknown) + if (ValueReg.isValid()) { - m_Assembler.MoveX86regPointerToX86reg(ValueReg, AddressReg, TempReg); + m_Assembler.mov(ValueReg, asmjit::x86::dword_ptr(AddressReg, TempReg)); } else { @@ -9721,10 +9626,10 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji } else if (ValueSize == 64) { - if (ValueReg != x86Reg_Unknown) + if (ValueReg.isValid()) { - m_Assembler.MoveX86regPointerToX86reg(ValueRegHi, AddressReg, TempReg); - m_Assembler.MoveX86regPointerToX86regDisp8(ValueReg, AddressReg, TempReg, 4); + m_Assembler.mov(ValueRegHi, asmjit::x86::dword_ptr(AddressReg, TempReg)); + m_Assembler.mov(ValueReg, asmjit::x86::dword_ptr(AddressReg, TempReg, 0, 4)); } else { @@ -9744,9 +9649,9 @@ void CX86RecompilerOps::CompileLoadMemoryValue(asmjit::x86::Gp AddressReg, asmji void CX86RecompilerOps::CompileStoreMemoryValue(asmjit::x86::Gp AddressReg, asmjit::x86::Gp ValueReg, const asmjit::x86::Gp & ValueRegHi, uint64_t Value, uint8_t ValueSize) { - uint8_t * MemoryWriteDone = nullptr; + asmjit::Label MemoryWriteDone; - if (AddressReg == x86Reg_Unknown) + if (!AddressReg.isValid()) { AddressReg = BaseOffsetAddress(ValueSize == 32); if (ValueSize == 8) @@ -9770,13 +9675,13 @@ void CX86RecompilerOps::CompileStoreMemoryValue(asmjit::x86::Gp AddressReg, asmj g_Notify->BreakPoint(__FILE__, __LINE__); } } - const asmjit::x86::Gp & TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); - m_Assembler.MoveX86RegToX86Reg(TempReg, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg, 12); + asmjit::x86::Gp TempReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + m_Assembler.mov(TempReg, AddressReg); + m_Assembler.shr(TempReg, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg, g_MMU->m_MemoryWriteMap, "MMU->m_MemoryWriteMap", TempReg, CX86Ops::Multip_x4); m_Assembler.CompConstToX86reg(TempReg, (uint32_t)-1); - m_Assembler.JneLabel8(stdstr_f("MemoryWriteMap_%X_Found", m_CompilePC).c_str(), 0); - uint8_t * JumpFound = (uint8_t *)(*g_RecompPos - 1); + asmjit::Label JumpFound = m_Assembler.newLabel(); + m_Assembler.JneLabel(stdstr_f("MemoryWriteMap_%X_Found", m_CompilePC).c_str(), JumpFound); m_Assembler.MoveConstToVariable(&g_Reg->m_PROGRAM_COUNTER, "PROGRAM_COUNTER", m_CompilePC); m_Assembler.MoveConstToVariable(&g_System->m_PipelineStage, "g_System->m_PipelineStage", m_PipelineStage); @@ -9788,120 +9693,119 @@ void CX86RecompilerOps::CompileStoreMemoryValue(asmjit::x86::Gp AddressReg, asmj if (ValueSize == 8) { m_RegWorkingSet.BeforeCallDirect(); - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.PushImm32((uint32_t)Value); + m_Assembler.push((uint32_t)Value); } else { - m_Assembler.Push(ValueReg); + m_Assembler.push(ValueReg); } - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)&m_MMU, AddressOf(&CMipsMemoryVM::SB_NonMemory), "CMipsMemoryVM::SB_NonMemory", 12); if (OpsExecuted != 0) { m_Assembler.AddConstToVariable(g_NextTimer, "g_NextTimer", OpsExecuted); } - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); - m_Assembler.JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); - MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); + MemoryWriteDone = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), MemoryWriteDone); } else if (ValueSize == 16) { m_RegWorkingSet.BeforeCallDirect(); - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.PushImm32((uint32_t)(Value & 0xFFFF)); + m_Assembler.push((uint32_t)(Value & 0xFFFF)); } else { - m_Assembler.Push(ValueReg); + m_Assembler.push(ValueReg); } - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)&m_MMU, AddressOf(&CMipsMemoryVM::SH_NonMemory), "CMipsMemoryVM::SH_NonMemory", 12); if (OpsExecuted != 0) { m_Assembler.AddConstToVariable(g_NextTimer, "g_NextTimer", OpsExecuted); } - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); - m_Assembler.JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); - MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); + MemoryWriteDone = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), MemoryWriteDone); } else if (ValueSize == 32) { m_RegWorkingSet.BeforeCallDirect(); - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.PushImm32((uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.push((uint32_t)(Value & 0xFFFFFFFF)); } else { - m_Assembler.Push(ValueReg); + m_Assembler.push(ValueReg); } - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)&m_MMU, AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 12); if (OpsExecuted != 0) { m_Assembler.AddConstToVariable(g_NextTimer, "g_NextTimer", OpsExecuted); } - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); - m_Assembler.JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); - MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); + MemoryWriteDone = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), MemoryWriteDone); } else if (ValueSize == 64) { m_RegWorkingSet.BeforeCallDirect(); - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.PushImm32((uint32_t)(Value & 0xFFFFFFFF)); - m_Assembler.PushImm32((uint32_t)((Value >> 32) & 0xFFFFFFFF)); + m_Assembler.push((uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.push((uint32_t)((Value >> 32) & 0xFFFFFFFF)); } else { - m_Assembler.Push(ValueReg); - m_Assembler.Push(ValueRegHi); + m_Assembler.push(ValueReg); + m_Assembler.push(ValueRegHi); } - m_Assembler.Push(AddressReg); + m_Assembler.push(AddressReg); m_Assembler.CallThis((uint32_t)&m_MMU, AddressOf(&CMipsMemoryVM::SD_NonMemory), "CMipsMemoryVM::SD_NonMemory", 12); if (OpsExecuted != 0) { m_Assembler.AddConstToVariable(g_NextTimer, "g_NextTimer", OpsExecuted); } - m_Assembler.TestX86ByteRegToX86Reg(asmjit::x86::al, asmjit::x86::al); + m_Assembler.test(asmjit::x86::al, asmjit::x86::al); m_RegWorkingSet.AfterCallDirect(); - CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel32); - m_Assembler.JmpLabel8(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), 0); - MemoryWriteDone = (uint8_t *)(*g_RecompPos - 1); + CompileExit(m_CompilePC, m_CompilePC, m_RegWorkingSet, ExitReason_NormalNoSysCheck, false, &CX86Ops::JeLabel); + MemoryWriteDone = m_Assembler.newLabel(); + m_Assembler.JmpLabel(stdstr_f("MemoryWrite_%X_Done:", m_CompilePC).c_str(), MemoryWriteDone); } else { m_Assembler.X86BreakPoint(__FILE__, __LINE__); - m_Assembler.MoveX86RegToX86Reg(TempReg, AddressReg); - m_Assembler.ShiftRightUnsignImmed(TempReg, 12); + m_Assembler.mov(TempReg, AddressReg); + m_Assembler.shr(TempReg, 12); m_Assembler.MoveVariableDispToX86Reg(TempReg, g_MMU->m_TLB_WriteMap, "MMU->TLB_WriteMap", TempReg, CX86Ops::Multip_x4); CompileWriteTLBMiss(AddressReg, TempReg); m_Assembler.AddConstToX86Reg(TempReg, (uint32_t)m_MMU.Rdram()); } m_CodeBlock.Log(""); - m_CodeBlock.Log(stdstr_f(" MemoryWriteMap_%X_Found:", m_CompilePC).c_str()); - m_Assembler.SetJump8(JumpFound, *g_RecompPos); + m_Assembler.bind(JumpFound); if (ValueSize == 8) { - m_Assembler.XorConstToX86Reg(AddressReg, 3); - if (ValueReg == x86Reg_Unknown) + m_Assembler.xor_(AddressReg, 3); + if (!ValueReg.isValid()) { - m_Assembler.MoveConstByteToX86regPointer(AddressReg, TempReg, (uint8_t)(Value & 0xFF)); + m_Assembler.mov(asmjit::x86::byte_ptr(AddressReg, TempReg), (uint8_t)(Value & 0xFF)); } else if (m_Assembler.Is8BitReg(ValueReg)) { - m_Assembler.MoveX86regByteToX86regPointer(AddressReg, TempReg, ValueReg); + m_Assembler.mov(asmjit::x86::byte_ptr(AddressReg, TempReg), ValueReg.r8Lo()); } else { @@ -9910,40 +9814,40 @@ void CX86RecompilerOps::CompileStoreMemoryValue(asmjit::x86::Gp AddressReg, asmj } else if (ValueSize == 16) { - m_Assembler.XorConstToX86Reg(AddressReg, 2); - if (ValueReg == x86Reg_Unknown) + m_Assembler.xor_(AddressReg, 2); + if (!ValueReg.isValid()) { - m_Assembler.MoveConstHalfToX86regPointer(AddressReg, TempReg, (uint16_t)(Value & 0xFFFF)); + m_Assembler.mov(asmjit::x86::word_ptr(AddressReg, TempReg), (uint16_t)(Value & 0xFFFF)); } else { - m_Assembler.MoveX86regHalfToX86regPointer(AddressReg, TempReg, ValueReg); + m_Assembler.mov(asmjit::x86::word_ptr(AddressReg, TempReg), ValueReg.r16()); } } else if (ValueSize == 32) { - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.MoveConstToX86regPointer(AddressReg, TempReg, (uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), (uint32_t)(Value & 0xFFFFFFFF)); } else { - m_Assembler.MoveX86regToX86regPointer(AddressReg, TempReg, ValueReg ); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), ValueReg ); } } else if (ValueSize == 64) { - if (ValueReg == x86Reg_Unknown) + if (!ValueReg.isValid()) { - m_Assembler.MoveConstToX86regPointer(AddressReg, TempReg, (uint32_t)(Value >> 32)); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), (uint32_t)(Value >> 32)); m_Assembler.AddConstToX86Reg(AddressReg, 4); - m_Assembler.MoveConstToX86regPointer(AddressReg, TempReg, (uint32_t)(Value & 0xFFFFFFFF)); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), (uint32_t)(Value & 0xFFFFFFFF)); } else { - m_Assembler.MoveX86regToX86regPointer(AddressReg, TempReg, ValueRegHi); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), ValueRegHi); m_Assembler.AddConstToX86Reg(AddressReg, 4); - m_Assembler.MoveX86regToX86regPointer(AddressReg, TempReg, ValueReg); + m_Assembler.mov(asmjit::x86::dword_ptr(AddressReg, TempReg), ValueReg); } } else @@ -9951,11 +9855,10 @@ void CX86RecompilerOps::CompileStoreMemoryValue(asmjit::x86::Gp AddressReg, asmj g_Notify->BreakPoint(__FILE__, __LINE__); } - if (MemoryWriteDone != nullptr) + if (MemoryWriteDone.isValid()) { m_CodeBlock.Log(""); - m_CodeBlock.Log(stdstr_f(" MemoryWrite_%X_Done:", m_CompilePC).c_str()); - m_Assembler.SetJump8(MemoryWriteDone, *g_RecompPos); + m_Assembler.bind(MemoryWriteDone); } } @@ -9963,7 +9866,7 @@ void CX86RecompilerOps::SB_Const(uint32_t Value, uint32_t VAddr) { if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, Value, 8); return; @@ -9992,7 +9895,7 @@ void CX86RecompilerOps::SB_Const(uint32_t Value, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, Value, 8); } @@ -10022,9 +9925,9 @@ void CX86RecompilerOps::SB_Const(uint32_t Value, uint32_t VAddr) if (PAddr >= 0x10000000 && PAddr < 0x13F00000) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value << ((3 - (PAddr & 3)) * 8)); - m_Assembler.PushImm32(PAddr); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value << ((3 - (PAddr & 3)) * 8)); + m_Assembler.push(PAddr); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -10040,7 +9943,7 @@ void CX86RecompilerOps::SB_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(Reg), true); - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 8); return; @@ -10069,7 +9972,7 @@ void CX86RecompilerOps::SB_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 8); } @@ -10090,7 +9993,7 @@ void CX86RecompilerOps::SH_Const(uint32_t Value, uint32_t VAddr) { if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, (uint16_t)Value, 16); return; @@ -10119,7 +10022,7 @@ void CX86RecompilerOps::SH_Const(uint32_t Value, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, (uint16_t)Value, 16); } @@ -10132,9 +10035,9 @@ void CX86RecompilerOps::SH_Const(uint32_t Value, uint32_t VAddr) if (PAddr >= 0x10000000 && PAddr < 0x13F00000) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value << ((2 - (PAddr & 2)) * 8)); - m_Assembler.PushImm32(PAddr); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value << ((2 - (PAddr & 2)) * 8)); + m_Assembler.push(PAddr); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -10151,7 +10054,7 @@ void CX86RecompilerOps::SH_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) { m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(Reg), true); - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 16); } @@ -10172,7 +10075,7 @@ void CX86RecompilerOps::SH_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 16); } @@ -10201,11 +10104,11 @@ void CX86RecompilerOps::SH_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) { - uint8_t * Jump; + asmjit::Label Jump; if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, Value, 32); return; @@ -10234,7 +10137,7 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, x86Reg_Unknown, x86Reg_Unknown, Value, 32); } @@ -10287,9 +10190,9 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) case 0x04040008: case 0x0404000C: m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_SPRegistersHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_SPRegistersHandler)[0][1], "SPRegistersHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10297,8 +10200,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(Value); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)g_MMU, AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); break; @@ -10317,8 +10220,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) { case 0x0410000C: m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(Value); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)g_MMU, AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); break; @@ -10454,9 +10357,9 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler)[0][1], "VideoInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -10468,15 +10371,14 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) if (g_Plugins->Gfx()->ViStatusChanged != nullptr) { m_Assembler.CompConstToVariable(&g_Reg->VI_STATUS_REG, "VI_STATUS_REG", Value); - m_Assembler.JeLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("Continue", Jump); m_Assembler.MoveConstToVariable(&g_Reg->VI_STATUS_REG, "VI_STATUS_REG", Value); m_RegWorkingSet.BeforeCallDirect(); m_Assembler.CallFunc((uint32_t)g_Plugins->Gfx()->ViStatusChanged, "ViStatusChanged"); m_RegWorkingSet.AfterCallDirect(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } break; case 0x04400004: m_Assembler.MoveConstToVariable(&g_Reg->VI_ORIGIN_REG, "VI_ORIGIN_REG", (Value & 0xFFFFFF)); break; @@ -10484,15 +10386,14 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) if (g_Plugins->Gfx()->ViWidthChanged != nullptr) { m_Assembler.CompConstToVariable(&g_Reg->VI_WIDTH_REG, "VI_WIDTH_REG", Value); - m_Assembler.JeLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("Continue", Jump); m_Assembler.MoveConstToVariable(&g_Reg->VI_WIDTH_REG, "VI_WIDTH_REG", Value); m_RegWorkingSet.BeforeCallDirect(); m_Assembler.CallFunc((uint32_t)g_Plugins->Gfx()->ViWidthChanged, "ViWidthChanged"); m_RegWorkingSet.AfterCallDirect(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } break; case 0x0440000C: m_Assembler.MoveConstToVariable(&g_Reg->VI_INTR_REG, "VI_INTR_REG", Value); break; @@ -10523,9 +10424,9 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler)[0][1], "AudioInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10542,9 +10443,9 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); } m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_PeripheralInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_PeripheralInterfaceHandler)[0][1], "PeripheralInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10633,8 +10534,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(Value); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)g_MMU, AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 4); m_RegWorkingSet.AfterCallDirect(); break; @@ -10643,9 +10544,9 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) if (PAddr >= 0x10000000 && PAddr < 0x13F00000) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Value); + m_Assembler.push(PAddr); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -10658,8 +10559,8 @@ void CX86RecompilerOps::SW_Const(uint32_t Value, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, true); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(Value); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(Value); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)(g_MMU), AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); } @@ -10671,7 +10572,7 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) if (VAddr < 0x80000000 || VAddr >= 0xC0000000) { m_RegWorkingSet.SetX86Protected(GetIndexFromX86Reg(Reg), true); - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 32); return; @@ -10702,7 +10603,7 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x00700000: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 32); } @@ -10720,9 +10621,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x04040008: case 0x0404000C: m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_SPRegistersHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_SPRegistersHandler)[0][1], "SPRegistersHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10741,7 +10642,7 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) default: if (CGameSettings::bSMM_StoreInstruc()) { - const asmjit::x86::Gp & AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); + asmjit::x86::Gp AddressReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveConstToX86reg(AddressReg, VAddr); CompileStoreMemoryValue(AddressReg, Reg, x86Reg_Unknown, 0, 32); } @@ -10769,8 +10670,8 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); } m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr | 0xA0000000); + m_Assembler.push(Reg); + m_Assembler.push(PAddr | 0xA0000000); m_Assembler.CallThis((uint32_t)(g_MMU), AddressOf(&CMipsMemoryVM::SW_NonMemory), "CMipsMemoryVM::SW_NonMemory", 12); m_RegWorkingSet.AfterCallDirect(); break; @@ -10779,9 +10680,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) { case 0x04300000: m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_MIPSInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_MIPSInterfaceHandler)[0][1], "MIPSInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10805,9 +10706,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true, false); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_VideoInterfaceHandler)[0][1], "VideoInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } @@ -10818,17 +10719,16 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x04400000: if (g_Plugins->Gfx()->ViStatusChanged != nullptr) { - uint8_t * Jump; + asmjit::Label Jump; m_Assembler.CompX86regToVariable(Reg, &g_Reg->VI_STATUS_REG, "VI_STATUS_REG"); - m_Assembler.JeLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("Continue", Jump); m_Assembler.MoveX86regToVariable(&g_Reg->VI_STATUS_REG, "VI_STATUS_REG", Reg); m_RegWorkingSet.BeforeCallDirect(); m_Assembler.CallFunc((uint32_t)g_Plugins->Gfx()->ViStatusChanged, "ViStatusChanged"); m_RegWorkingSet.AfterCallDirect(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } break; case 0x04400004: @@ -10838,17 +10738,16 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) case 0x04400008: if (g_Plugins->Gfx()->ViWidthChanged != nullptr) { - uint8_t * Jump; + asmjit::Label Jump; m_Assembler.CompX86regToVariable(Reg, &g_Reg->VI_WIDTH_REG, "VI_WIDTH_REG"); - m_Assembler.JeLabel8("Continue", 0); - Jump = *g_RecompPos - 1; + Jump = m_Assembler.newLabel(); + m_Assembler.JeLabel("Continue", Jump); m_Assembler.MoveX86regToVariable(&g_Reg->VI_WIDTH_REG, "VI_WIDTH_REG", Reg); m_RegWorkingSet.BeforeCallDirect(); m_Assembler.CallFunc((uint32_t)g_Plugins->Gfx()->ViWidthChanged, "ViWidthChanged"); m_RegWorkingSet.AfterCallDirect(); m_CodeBlock.Log(""); - m_CodeBlock.Log(" Continue:"); - m_Assembler.SetJump8(Jump, *g_RecompPos); + m_Assembler.bind(Jump); } break; case 0x0440000C: m_Assembler.MoveX86regToVariable(&g_Reg->VI_INTR_REG, "VI_INTR_REG", Reg); break; @@ -10880,9 +10779,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true); m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_AudioInterfaceHandler)[0][1], "AudioInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -10899,9 +10798,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) UpdateCounters(m_RegWorkingSet, false, true); } m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_PeripheralInterfaceHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_PeripheralInterfaceHandler)[0][1], "PeripheralInterfaceHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -11029,9 +10928,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) } case 0x13F00000: m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr & 0x1FFFFFFF); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr & 0x1FFFFFFF); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_ISViewerHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_ISViewerHandler)[0][1], "ISViewerHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); break; @@ -11043,9 +10942,9 @@ void CX86RecompilerOps::SW_Register(const asmjit::x86::Gp & Reg, uint32_t VAddr) if (PAddr >= 0x10000000 && PAddr < 0x13F00000) { m_RegWorkingSet.BeforeCallDirect(); - m_Assembler.PushImm32(0xFFFFFFFF); - m_Assembler.Push(Reg); - m_Assembler.PushImm32(PAddr); + m_Assembler.push(0xFFFFFFFF); + m_Assembler.push(Reg); + m_Assembler.push(PAddr); m_Assembler.CallThis((uint32_t)(MemoryHandler *)&g_MMU->m_RomMemoryHandler, (uint32_t)((long **)(MemoryHandler *)&g_MMU->m_RomMemoryHandler)[0][1], "RomMemoryHandler::Write32", 16); m_RegWorkingSet.AfterCallDirect(); } diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h index a3426836a..ed6901f24 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RecompilerOps.h @@ -350,7 +350,7 @@ public: { return m_RegWorkingSet.RegInStack(Reg, Format); } - CX86Ops::x86FpuValues StackPosition(int32_t Reg) + const asmjit::x86::St & StackPosition(int32_t Reg) { return m_RegWorkingSet.StackPosition(Reg); } @@ -441,7 +441,7 @@ private: void LW_KnownAddress(const asmjit::x86::Gp & Reg, uint32_t VAddr); void LW(bool ResultSigned, bool bRecordLLBit); void SW(bool bCheckLLbit); - void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason Reason, bool CompileNow, void (CX86Ops::*x86Jmp)(const char * Label, uint32_t Value)); + void CompileExit(uint32_t JumpPC, uint32_t TargetPC, CRegInfo & ExitRegSet, ExitReason Reason, bool CompileNow, void (CX86Ops::*x86Jmp)(const char * LabelName, asmjit::Label & JumpLabel)); void ResetMemoryStack(); EXIT_LIST m_ExitInfo; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp index 6ec89ae4d..baaa4e0bd 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.cpp @@ -45,6 +45,37 @@ asmjit::x86::Gp GetX86RegFromIndex(x86RegIndex Index) return x86Reg_Unknown; } +x86RegFpuIndex GetIndexFromX86FpuReg(const asmjit::x86::St & Reg) +{ + if (Reg == asmjit::x86::st0) { return x86RegFpuIndex_ST0; } + if (Reg == asmjit::x86::st1) { return x86RegFpuIndex_ST1; } + if (Reg == asmjit::x86::st2) { return x86RegFpuIndex_ST2; } + if (Reg == asmjit::x86::st3) { return x86RegFpuIndex_ST3; } + if (Reg == asmjit::x86::st4) { return x86RegFpuIndex_ST4; } + if (Reg == asmjit::x86::st5) { return x86RegFpuIndex_ST5; } + if (Reg == asmjit::x86::st6) { return x86RegFpuIndex_ST6; } + if (Reg == asmjit::x86::st7) { return x86RegFpuIndex_ST7; } + g_Notify->BreakPoint(__FILE__, __LINE__); + return x86RegFpuIndex_ST0; +} + +asmjit::x86::St GetX86FpuRegFromIndex(x86RegFpuIndex Index) +{ + switch (Index) + { + case x86RegFpuIndex_ST0: return asmjit::x86::st0; + case x86RegFpuIndex_ST1: return asmjit::x86::st1; + case x86RegFpuIndex_ST2: return asmjit::x86::st2; + case x86RegFpuIndex_ST3: return asmjit::x86::st3; + case x86RegFpuIndex_ST4: return asmjit::x86::st4; + case x86RegFpuIndex_ST5: return asmjit::x86::st5; + case x86RegFpuIndex_ST6: return asmjit::x86::st6; + case x86RegFpuIndex_ST7: return asmjit::x86::st7; + } + g_Notify->BreakPoint(__FILE__, __LINE__); + return asmjit::x86::St(); +} + CX86RegInfo::CX86RegInfo(CCodeBlock & CodeBlock, CX86Ops & Assembler) : m_CodeBlock(CodeBlock), m_Assembler(Assembler), @@ -62,7 +93,7 @@ CX86RegInfo::CX86RegInfo(CCodeBlock & CodeBlock, CX86Ops & Assembler) : m_x86reg_Protected[i] = false; m_x86reg_MapOrder[i] = 0; } - for (int32_t i = 0, n = sizeof(m_x86fpu_MappedTo) / sizeof(m_x86fpu_MappedTo[0]); i < n; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { m_x86fpu_MappedTo[i] = -1; m_x86fpu_State[i] = FPU_Unknown; @@ -137,7 +168,7 @@ bool CX86RegInfo::operator==(const CX86RegInfo & right) const return false; } - for (count = 0; count < 8; count++) + for (count = 0; count < x86RegFpuIndex_Size; count++) { if (m_x86fpu_MappedTo[count] != right.m_x86fpu_MappedTo[count]) { @@ -181,7 +212,7 @@ void CX86RegInfo::BeforeCallDirect(void) } m_InBeforeCallDirect = true; UnMap_AllFPRs(); - m_Assembler.Pushad(); + m_Assembler.pushad(); } void CX86RegInfo::AfterCallDirect(void) @@ -191,7 +222,7 @@ void CX86RegInfo::AfterCallDirect(void) g_Notify->BreakPoint(__FILE__, __LINE__); } m_InBeforeCallDirect = false; - m_Assembler.Popad(); + m_Assembler.popad(); SetRoundingModel(CRegInfo::RoundUnknown); } @@ -207,7 +238,7 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod) m_Assembler.fpuStoreControl(&m_fpuControl, "m_fpuControl"); asmjit::x86::Gp reg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(reg, &m_fpuControl, "m_fpuControl"); - m_Assembler.AndConstToX86Reg(reg, 0xF3FF); + m_Assembler.and_(reg, 0xF3FF); if (RoundMethod == RoundDefault) { @@ -224,12 +255,12 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod) m_Assembler.MoveVariableToX86reg(RoundReg, &g_Reg->m_RoundingModel, "m_RoundingModel"); m_Assembler.MoveVariableDispToX86Reg(RoundReg, (void *)&msRound[0], "msRound", RoundReg, CX86Ops::Multip_x4); - m_Assembler.ShiftLeftSignImmed(RoundReg, 2); - m_Assembler.OrX86RegToX86Reg(reg, RoundReg); + m_Assembler.shl(RoundReg, 2); + m_Assembler.or_(reg, RoundReg); #else asmjit::x86::Gp RoundReg = Map_TempReg(x86Reg_Unknown, -1, false, false); m_Assembler.MoveVariableToX86reg(RoundReg, _RoundingModel, "_RoundingModel"); - m_Assembler.OrX86RegToX86Reg(reg, RoundReg); + m_Assembler.or_(reg, RoundReg); #endif SetX86Protected(GetIndexFromX86Reg(RoundReg), false); } @@ -237,10 +268,10 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod) { switch (RoundMethod) { - case RoundTruncate: m_Assembler.OrConstToX86Reg(reg, 0x0C00); break; - case RoundNearest: m_Assembler.OrConstToX86Reg(reg, 0x0000); break; - case RoundDown: m_Assembler.OrConstToX86Reg(reg, 0x0400); break; - case RoundUp: m_Assembler.OrConstToX86Reg(reg, 0x0800); break; + case RoundTruncate: m_Assembler.or_(reg, 0x0C00); break; + case RoundNearest: m_Assembler.or_(reg, 0x0000); break; + case RoundDown: m_Assembler.or_(reg, 0x0400); break; + case RoundUp: m_Assembler.or_(reg, 0x0800); break; default: g_Notify->DisplayError("Unknown rounding model"); } @@ -253,7 +284,7 @@ void CX86RegInfo::FixRoundModel(FPU_ROUND RoundMethod) void CX86RegInfo::ChangeFPURegFormat(int32_t Reg, FPU_STATE OldFormat, FPU_STATE NewFormat, FPU_ROUND RoundingModel) { - for (uint32_t i = 0; i < 8; i++) + for (uint32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] != Reg) { @@ -308,7 +339,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma { if ((Reg & 1) != 0) { - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] == (Reg - 1)) { @@ -322,7 +353,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma } if ((RegToLoad & 1) != 0) { - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] == (RegToLoad - 1)) { @@ -339,7 +370,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma if (Reg == RegToLoad) { // If different format then unmap original register from stack - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] != Reg) { @@ -355,7 +386,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma else { // If different format then unmap original register from stack - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] != Reg) { @@ -388,14 +419,14 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma } else { - CX86Ops::x86FpuValues RegPos = CX86Ops::x86_ST_Unknown; - for (uint32_t z = 0; z < 8; z++) + int32_t RegPos = -1; + for (uint32_t z = 0; z < x86RegFpuIndex_Size; z++) { if (m_x86fpu_MappedTo[z] != Reg) { continue; } - RegPos = (CX86Ops::x86FpuValues)z; + RegPos = z; break; } @@ -403,7 +434,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma { return; } - CX86Ops::x86FpuValues StackPos = StackPosition(Reg); + asmjit::x86::St StackPos = StackPosition(Reg); FpuRoundingModel(RegPos) = FpuRoundingModel(StackTopPos()); m_x86fpu_MappedTo[RegPos] = m_x86fpu_MappedTo[StackTopPos()]; @@ -412,7 +443,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma m_CodeBlock.Log(" regcache: allocate ST(%d) to %s", StackPos, CRegName::FPR[m_x86fpu_MappedTo[RegPos]]); m_CodeBlock.Log(" regcache: allocate ST(0) to %s", CRegName::FPR[Reg]); - m_Assembler.fpuExchange(StackPos); + m_Assembler.fxch(StackPos); FpuRoundingModel(StackTopPos()) = RoundDefault; m_x86fpu_MappedTo[StackTopPos()] = Reg; @@ -423,7 +454,7 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma else { UnMap_FPR(m_x86fpu_MappedTo[(StackTopPos() - 1) & 7], true); - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] == RegToLoad) { @@ -465,16 +496,27 @@ void CX86RegInfo::Load_FPR_ToTop(int32_t Reg, int32_t RegToLoad, FPU_STATE Forma } } -CX86Ops::x86FpuValues CX86RegInfo::StackPosition(int32_t Reg) +const asmjit::x86::St & CX86RegInfo::StackPosition(int32_t Reg) { - for (int32_t i = 0; i < 8; i++) + static const asmjit::x86::St StRegs[] = + { + asmjit::x86::st0, + asmjit::x86::st1, + asmjit::x86::st2, + asmjit::x86::st3, + asmjit::x86::st4, + asmjit::x86::st5, + asmjit::x86::st6, + asmjit::x86::st7, + }; + for (int32_t i = 0, n = sizeof(StRegs) / sizeof(StRegs[0]); i < n; i++) { if (m_x86fpu_MappedTo[i] == Reg) { - return (CX86Ops::x86FpuValues)((i - StackTopPos()) & 7); + return StRegs[((i - StackTopPos()) & 7)]; } } - return CX86Ops::x86_ST_Unknown; + return asmjit::x86::St(); } asmjit::x86::Gp CX86RegInfo::FreeX86Reg() @@ -699,7 +741,7 @@ asmjit::x86::Gp CX86RegInfo::Map_MemoryStack(asmjit::x86::Gp Reg, bool bMapRegis m_CodeBlock.Log(" regcache: change allocation of memory stack from %s to %s", CX86Ops::x86_Name(CurrentMap), CX86Ops::x86_Name(Reg)); SetX86Mapped(GetIndexFromX86Reg(Reg), CX86RegInfo::Stack_Mapped); SetX86Mapped(GetIndexFromX86Reg(CurrentMap), CX86RegInfo::NotMapped); - m_Assembler.MoveX86RegToX86Reg(Reg, CurrentMap); + m_Assembler.mov(Reg, CurrentMap); } else { @@ -769,7 +811,7 @@ void CX86RegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg { if (MipsReg != MipsRegToLoad) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(MipsRegToLoad)); + m_Assembler.mov(Reg, GetMipsRegMapLo(MipsRegToLoad)); } } else @@ -779,7 +821,7 @@ void CX86RegInfo::Map_GPR_32bit(int32_t MipsReg, bool SignValue, int32_t MipsReg } else if (MipsRegToLoad == 0) { - m_Assembler.XorX86RegToX86Reg(Reg, Reg); + m_Assembler.xor_(Reg, Reg); } SetX86Mapped(RegIndex, GPR_Mapped); SetX86Protected(RegIndex, true); @@ -870,24 +912,24 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad) { if (IsSigned(MipsRegToLoad)) { - m_Assembler.MoveX86RegToX86Reg(x86Hi, GetMipsRegMapLo(MipsRegToLoad)); - m_Assembler.ShiftRightSignImmed(x86Hi, 31); + m_Assembler.mov(x86Hi, GetMipsRegMapLo(MipsRegToLoad)); + m_Assembler.sar(x86Hi, 31); } else { - m_Assembler.XorX86RegToX86Reg(x86Hi, x86Hi); + m_Assembler.xor_(x86Hi, x86Hi); } if (MipsReg != MipsRegToLoad) { - m_Assembler.MoveX86RegToX86Reg(x86lo, GetMipsRegMapLo(MipsRegToLoad)); + m_Assembler.mov(x86lo, GetMipsRegMapLo(MipsRegToLoad)); } } else { if (MipsReg != MipsRegToLoad) { - m_Assembler.MoveX86RegToX86Reg(x86Hi, GetMipsRegMapHi(MipsRegToLoad)); - m_Assembler.MoveX86RegToX86Reg(x86lo, GetMipsRegMapLo(MipsRegToLoad)); + m_Assembler.mov(x86Hi, GetMipsRegMapHi(MipsRegToLoad)); + m_Assembler.mov(x86lo, GetMipsRegMapLo(MipsRegToLoad)); } } } @@ -914,8 +956,8 @@ void CX86RegInfo::Map_GPR_64bit(int32_t MipsReg, int32_t MipsRegToLoad) } else if (MipsRegToLoad == 0) { - m_Assembler.XorX86RegToX86Reg(x86Hi, x86Hi); - m_Assembler.XorX86RegToX86Reg(x86lo, x86lo); + m_Assembler.xor_(x86Hi, x86Hi); + m_Assembler.xor_(x86lo, x86lo); } SetX86Mapped(GetIndexFromX86Reg(x86Hi), GPR_Mapped); SetX86Mapped(GetIndexFromX86Reg(x86lo), GPR_Mapped); @@ -1030,7 +1072,7 @@ asmjit::x86::Gp CX86RegInfo::Map_TempReg(asmjit::x86::Gp Reg, int32_t MipsReg, b SetX86Mapped(GetIndexFromX86Reg(NewReg), GPR_Mapped); SetX86MapOrder(GetIndexFromX86Reg(NewReg), GetX86MapOrder(GetIndexFromX86Reg(Reg))); SetMipsRegMapLo(i, NewReg); - m_Assembler.MoveX86RegToX86Reg(NewReg, Reg); + m_Assembler.mov(NewReg, Reg); if (MipsReg == (int32_t)i && !LoadHiWord) { MipsReg = -1; @@ -1048,7 +1090,7 @@ asmjit::x86::Gp CX86RegInfo::Map_TempReg(asmjit::x86::Gp Reg, int32_t MipsReg, b SetX86Mapped(GetIndexFromX86Reg(NewReg), GPR_Mapped); SetX86MapOrder(GetIndexFromX86Reg(NewReg), GetX86MapOrder(GetIndexFromX86Reg(Reg))); SetMipsRegMapHi(i, NewReg); - m_Assembler.MoveX86RegToX86Reg(NewReg, Reg); + m_Assembler.mov(NewReg, Reg); if (MipsReg == (int32_t)i && LoadHiWord) { MipsReg = -1; @@ -1075,12 +1117,12 @@ asmjit::x86::Gp CX86RegInfo::Map_TempReg(asmjit::x86::Gp Reg, int32_t MipsReg, b { if (Is64Bit(MipsReg)) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapHi(MipsReg)); + m_Assembler.mov(Reg, GetMipsRegMapHi(MipsReg)); } else if (IsSigned(MipsReg)) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(MipsReg)); - m_Assembler.ShiftRightSignImmed(Reg, 31); + m_Assembler.mov(Reg, GetMipsRegMapLo(MipsReg)); + m_Assembler.sar(Reg, 31); } else { @@ -1107,7 +1149,7 @@ asmjit::x86::Gp CX86RegInfo::Map_TempReg(asmjit::x86::Gp Reg, int32_t MipsReg, b } else if (IsMapped(MipsReg)) { - m_Assembler.MoveX86RegToX86Reg(Reg, GetMipsRegMapLo(MipsReg)); + m_Assembler.mov(Reg, GetMipsRegMapLo(MipsReg)); } else { @@ -1166,7 +1208,7 @@ void CX86RegInfo::ResetX86Protection() bool CX86RegInfo::RegInStack(int32_t Reg, FPU_STATE Format) { - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] == Reg) { @@ -1192,7 +1234,7 @@ void CX86RegInfo::UnMap_AllFPRs() } // See if any more registers mapped int32_t StartPos = StackTopPos(); - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[(StartPos + i) & 7] != -1) { @@ -1213,7 +1255,7 @@ void CX86RegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue) { return; } - for (int32_t i = 0; i < 8; i++) + for (int32_t i = 0; i < x86RegFpuIndex_Size; i++) { if (m_x86fpu_MappedTo[i] != Reg) { @@ -1244,7 +1286,7 @@ void CX86RegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue) m_x86fpu_MappedTo[i] = MappedTo; m_x86fpu_State[i] = RegState; m_x86fpu_StateChanged[i] = Changed; - m_Assembler.fpuExchange((CX86Ops::x86FpuValues)((i - StackTopPos()) & 7)); + m_Assembler.fxch(GetX86FpuRegFromIndex((x86RegFpuIndex)((i - StackTopPos()) & 7))); } } @@ -1284,7 +1326,7 @@ void CX86RegInfo::UnMap_FPR(int32_t Reg, bool WriteBackValue) } else { - m_Assembler.fpuFree((CX86Ops::x86FpuValues)((i - StackTopPos()) & 7)); + m_Assembler.ffree(GetX86FpuRegFromIndex((x86RegFpuIndex)((i - StackTopPos()) & 7))); FpuRoundingModel(i) = RoundDefault; m_x86fpu_MappedTo[i] = -1; m_x86fpu_State[i] = FPU_Unknown; @@ -1364,7 +1406,7 @@ void CX86RegInfo::UnMap_GPR(uint32_t Reg, bool WriteBackValue) { if (IsSigned(Reg)) { - m_Assembler.ShiftRightSignImmed(GetMipsRegMapLo(Reg), 31); + m_Assembler.sar(GetMipsRegMapLo(Reg), 31); m_Assembler.MoveX86regToVariable(&_GPR[Reg].UW[1], CRegName::GPR_Hi[Reg], GetMipsRegMapLo(Reg)); } else @@ -1510,7 +1552,7 @@ void CX86RegInfo::WriteBackRegisters() { if (!bEdiZero && (!GetMipsRegLo(count) || !(GetMipsRegLo(count) & 0x80000000))) { - m_Assembler.XorX86RegToX86Reg(asmjit::x86::edi, asmjit::x86::edi); + m_Assembler.xor_(asmjit::x86::edi, asmjit::x86::edi); bEdiZero = true; } if (!bEsiSign && (GetMipsRegLo(count) & 0x80000000)) @@ -1534,7 +1576,7 @@ void CX86RegInfo::WriteBackRegisters() { if (!bEdiZero) { - m_Assembler.XorX86RegToX86Reg(asmjit::x86::edi, asmjit::x86::edi); + m_Assembler.xor_(asmjit::x86::edi, asmjit::x86::edi); bEdiZero = true; } } @@ -1564,7 +1606,7 @@ void CX86RegInfo::WriteBackRegisters() { if (!bEdiZero) { - m_Assembler.XorX86RegToX86Reg(asmjit::x86::edi, asmjit::x86::edi); + m_Assembler.xor_(asmjit::x86::edi, asmjit::x86::edi); bEdiZero = true; } m_Assembler.MoveX86regToVariable(&_GPR[count].UW[1], CRegName::GPR_Hi[count], asmjit::x86::edi); @@ -1576,7 +1618,7 @@ void CX86RegInfo::WriteBackRegisters() { if (!bEdiZero) { - m_Assembler.XorX86RegToX86Reg(asmjit::x86::edi, asmjit::x86::edi); + m_Assembler.xor_(asmjit::x86::edi, asmjit::x86::edi); bEdiZero = true; } } @@ -1591,7 +1633,7 @@ void CX86RegInfo::WriteBackRegisters() case CX86RegInfo::STATE_CONST_64: if (GetMipsRegLo(count) == 0 || GetMipsRegHi(count) == 0) { - m_Assembler.XorX86RegToX86Reg(asmjit::x86::edi, asmjit::x86::edi); + m_Assembler.xor_(asmjit::x86::edi, asmjit::x86::edi); bEdiZero = true; } if (GetMipsRegLo(count) == 0xFFFFFFFF || GetMipsRegHi(count) == 0xFFFFFFFF) diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h index 30109b763..b28905dd6 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86RegInfo.h @@ -23,6 +23,22 @@ enum x86RegIndex x86RegIndex GetIndexFromX86Reg(const asmjit::x86::Gp & Reg); asmjit::x86::Gp GetX86RegFromIndex(x86RegIndex Index); +enum x86RegFpuIndex +{ + x86RegFpuIndex_ST0, + x86RegFpuIndex_ST1, + x86RegFpuIndex_ST2, + x86RegFpuIndex_ST3, + x86RegFpuIndex_ST4, + x86RegFpuIndex_ST5, + x86RegFpuIndex_ST6, + x86RegFpuIndex_ST7, + x86RegFpuIndex_Size, +}; + +x86RegFpuIndex GetIndexFromX86FpuReg(const asmjit::x86::St & Reg); +asmjit::x86::St GetX86FpuRegFromIndex(x86RegFpuIndex Index); + class CX86RegInfo : public CRegBase, private CDebugSettings, @@ -68,7 +84,7 @@ public: bool RegInStack(int32_t Reg, FPU_STATE Format); void UnMap_AllFPRs(); void UnMap_FPR(int32_t Reg, bool WriteBackValue); - CX86Ops::x86FpuValues StackPosition(int32_t Reg); + const asmjit::x86::St & StackPosition(int32_t Reg); asmjit::x86::Gp FreeX86Reg(); asmjit::x86::Gp Free8BitX86Reg(); @@ -163,10 +179,10 @@ private: // FPU int32_t m_Stack_TopPos; - int32_t m_x86fpu_MappedTo[8]; - FPU_STATE m_x86fpu_State[8]; - bool m_x86fpu_StateChanged[8]; - FPU_ROUND m_x86fpu_RoundingModel[8]; + int32_t m_x86fpu_MappedTo[x86RegFpuIndex_Size]; + FPU_STATE m_x86fpu_State[x86RegFpuIndex_Size]; + bool m_x86fpu_StateChanged[x86RegFpuIndex_Size]; + FPU_ROUND m_x86fpu_RoundingModel[x86RegFpuIndex_Size]; static uint32_t m_fpuControl; bool m_InBeforeCallDirect; diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp b/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp index 5fc0a8ee1..e51c69f95 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp +++ b/Source/Project64-core/N64System/Recompiler/x86/x86ops.cpp @@ -6,163 +6,124 @@ #include #include -char CX86Ops::m_fpupop[2][2] = { - "", - "p", -}; - CX86Ops::CX86Ops(CCodeBlock & CodeBlock) : + asmjit::x86::Assembler(&CodeBlock.CodeHolder()), m_CodeBlock(CodeBlock) { -} - -// Logging functions -void CX86Ops::WriteX86Comment(const char * Comment) -{ - CodeLog(""); - CodeLog(" // %s", Comment); -} - -void CX86Ops::WriteX86Label(const char * Label) -{ - CodeLog(""); - CodeLog(" %s:", Label); -} - -void CX86Ops::AdcConstToVariable(void * Variable, const char * VariableName, uint8_t Constant) -{ - CodeLog(" adc dword ptr [%s], %Xh", VariableName, Constant); - AddCode16(0x1583); - AddCode32((uint32_t)Variable); - AddCode8(Constant); -} - -void CX86Ops::AdcConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" adc %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - AddCode16((uint16_t)(0xD081 + (RegValue(Reg) * 0x100))); - AddCode32(Const); - } - else - { - AddCode16((uint16_t)(0xD083 + (RegValue(Reg) * 0x100))); - AddCode8((uint8_t)Const); - } + setLogger(this); + setErrorHandler(&CodeBlock); + addFlags(asmjit::FormatFlags::kHexOffsets); + addFlags(asmjit::FormatFlags::kHexImms); + addFlags(asmjit::FormatFlags::kExplainImms); } void CX86Ops::AdcVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" adc %s, dword ptr [%s]", x86_Name(Reg), VariableName); - AddCode16((uint16_t)(0x0513 + (RegValue(Reg) * 0x800))); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::AdcX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - CodeLog(" adc %s, %s", x86_Name(Destination), x86_Name(Source)); - AddCode16((uint16_t)(0xC013 + (RegValue(Source) * 0x100) + (RegValue(Destination) * 0x800))); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + adc(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + adc(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + } } void CX86Ops::AddConstToVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" add dword ptr [%s], 0x%X", VariableName, Const); - AddCode16(0x0581); - AddCode32((uint32_t)Variable); - AddCode32(Const); -} - -void CX86Ops::AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const, bool NeedCarry) -{ - if (Const == 0) + if (CDebugSettings::bRecordRecompilerAsm()) { - } - else if (Const == 1 && !NeedCarry) - { - IncX86reg(Reg); - } - else if (Const == 0xFFFFFFFF && !NeedCarry) - { - DecX86reg(Reg); - } - else if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - CodeLog(" add %s, %Xh", x86_Name(Reg), Const); - AddCode16((uint16_t)(0xC081 + (RegValue(Reg) * 0x100))); - AddCode32(Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + add(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } else { - CodeLog(" add %s, %Xh", x86_Name(Reg), Const); - AddCode16((uint16_t)(0xC083 + (RegValue(Reg) * 0x100))); - AddCode8((uint8_t)Const); + add(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + } +} + +void CX86Ops::AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) +{ + if (Const != 0) + { + if (Const == 1) + { + inc(Reg); + } + else if (Const == 0xFFFFFFFF) + { + dec(Reg); + } + else + { + add(Reg, Const); + } } } void CX86Ops::AddVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" add %s, dword ptr [%s]", x86_Name(Reg), VariableName); - AddCode16((uint16_t)(0x0503 + (RegValue(Reg) * 0x800))); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::AddX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) -{ - CodeLog(" add dword ptr [%s], %s", VariableName, x86_Name(Reg)); - AddCode16((uint16_t)(0x0501 + (RegValue(Reg) * 0x800))); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::AddX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - CodeLog(" add %s, %s", x86_Name(Destination), x86_Name(Source)); - AddCode16((uint16_t)(0xC003 + (RegValue(Source) * 0x100) + (RegValue(Destination) * 0x800))); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + add(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + add(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + } } void CX86Ops::AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" and dword ptr [%s], 0x%X", VariableName, Const); - AddCode16(0x2581); - AddCode32((uint32_t)Variable); - AddCode32(Const); -} - -void CX86Ops::AndConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" and %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) + if (CDebugSettings::bRecordRecompilerAsm()) { - AddCode16((uint16_t)(0xE081 + (RegValue(Reg) * 0x100))); - AddCode32(Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + and_(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } else { - AddCode16((uint16_t)(0xE083 + (RegValue(Reg) * 0x100))); - AddCode8((uint8_t)Const); + and_(asmjit::x86::dword_ptr((uint64_t)Variable), Const); } } void CX86Ops::AndVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiply) { - CodeLog(" and %s, dword ptr [%s+%s*%i]", x86_Name(Reg), VariableName, x86_Name(AddrReg), Multiply); - - AddCode16((uint16_t)(0x0423 + (RegValue(Reg) * 0x800))); - AddCode8((uint8_t)(0x05 + CalcMultiplyCode(Multiply) + (RegValue(AddrReg) * 0x8))); - AddCode32((uint32_t)(Variable)); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiply >> 1)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiply >> 1)); + } } void CX86Ops::AndVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" and %s, dword ptr [%s]", x86_Name(Reg), VariableName); - AddCode16((uint16_t)(0x0523 + (RegValue(Reg) * 0x800))); - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::AndX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - CodeLog(" and %s, %s", x86_Name(Destination), x86_Name(Source)); - AddCode16((uint16_t)(0xC021 + (RegValue(Destination) * 0x100) + (RegValue(Source) * 0x800))); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + and_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + } } void CX86Ops::BreakPointNotification(const char * FileName, int32_t LineNumber) @@ -172,31 +133,38 @@ void CX86Ops::BreakPointNotification(const char * FileName, int32_t LineNumber) void CX86Ops::X86HardBreakPoint() { - CodeLog(" int 3"); - AddCode8(0xCC); + int3(); } void CX86Ops::X86BreakPoint(const char * FileName, int32_t LineNumber) { - Pushad(); + pushad(); PushImm32(stdstr_f("%d", LineNumber).c_str(), LineNumber); PushImm32(FileName, (uint32_t)FileName); CallFunc((uint32_t)BreakPointNotification, "BreakPointNotification"); AddConstToX86Reg(asmjit::x86::esp, 8); - Popad(); + popad(); } void CX86Ops::CallFunc(uint32_t FunctPtr, const char * FunctName) { - CodeLog(" call offset %s", FunctName); - AddCode8(0xE8); - AddCode32(FunctPtr - (uint32_t)*g_RecompPos - 4); + if (CDebugSettings::bRecordRecompilerAsm()) + { + stdstr_f SymbolKey("0x%X", FunctPtr); + AddSymbol(SymbolKey.c_str(), FunctName); + call((uint64_t)FunctPtr); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + call(asmjit::x86::dword_ptr((uint64_t)FunctPtr)); + } } #ifdef _MSC_VER void CX86Ops::CallThis(uint32_t ThisPtr, uint32_t FunctPtr, char * FunctName, uint32_t /*StackSize*/) { - MoveConstToX86reg(asmjit::x86::ecx, ThisPtr); + mov(asmjit::x86::ecx, ThisPtr); CallFunc(FunctPtr, FunctName); } #else @@ -210,3515 +178,684 @@ void CX86Ops::CallThis(uint32_t ThisPtr, uint32_t FunctPtr, char * FunctName, ui void CX86Ops::CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" cmp dword ptr [%s], 0x%X", VariableName, Const); - AddCode16(0x3D81); - AddCode32((uint32_t)Variable); - AddCode32(Const); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + cmp(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + cmp(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + } } void CX86Ops::CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const) { if (Const == 0) { - OrX86RegToX86Reg(Reg, Reg); + or_(Reg, Reg); } else { - CodeLog(" cmp %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - AddCode16((uint16_t)(0xF881 + (RegValue(Reg) * 0x100))); - AddCode32(Const); - } - else - { - AddCode16((uint16_t)(0xF883 + (RegValue(Reg) * 0x100))); - AddCode8((uint8_t)Const); - } - } -} - -void CX86Ops::CompConstToX86regPointer(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - CodeLog(" cmp dword ptr [%s], %Xh", x86_Name(Reg), Const); - AddCode16((uint16_t)(0x3881 + (RegValue(Reg) * 0x100))); - AddCode32(Const); - } - else - { - CodeLog(" cmp byte ptr [%s], %Xh", x86_Name(Reg), Const); - AddCode16((uint16_t)(0x3883 + (RegValue(Reg) * 0x100))); - AddCode8((uint8_t)Const); + cmp(Reg, Const); } } void CX86Ops::CompX86regToVariable(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" cmp %s, dword ptr [%s]", x86_Name(Reg), VariableName); - AddCode16((uint16_t)(0x053B + (RegValue(Reg) * 0x800))); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::CompX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - - CodeLog(" cmp %s, %s", x86_Name(Destination), x86_Name(Source)); - - switch (RegValue(Source)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: x86Command = 0x003B; break; - case x86_EBX: x86Command = 0x033B; break; - case x86_ECX: x86Command = 0x013B; break; - case x86_EDX: x86Command = 0x023B; break; - case x86_ESI: x86Command = 0x063B; break; - case x86_EDI: x86Command = 0x073B; break; - case x86_ESP: x86Command = 0x043B; break; - case x86_EBP: x86Command = 0x053B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - } - AddCode16(x86Command); -} - -void CX86Ops::DecX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" dec %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xC8FF); break; - case x86_EBX: AddCode16(0xCBFF); break; - case x86_ECX: AddCode16(0xC9FF); break; - case x86_EDX: AddCode16(0xCAFF); break; - case x86_ESI: AddCode16(0xCEFF); break; - case x86_EDI: AddCode16(0xCFFF); break; - case x86_ESP: AddCode8(0x4C); break; - case x86_EBP: AddCode8(0x4D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::DivX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" div %s", x86_Name(Reg)); - switch (RegValue(Reg)) - { - case x86_EBX: AddCode16(0xf3F7); break; - case x86_ECX: AddCode16(0xf1F7); break; - case x86_EDX: AddCode16(0xf2F7); break; - case x86_ESI: AddCode16(0xf6F7); break; - case x86_EDI: AddCode16(0xf7F7); break; - case x86_ESP: AddCode16(0xf4F7); break; - case x86_EBP: AddCode16(0xf5F7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::idivX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" idiv %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EBX: AddCode16(0xfbF7); break; - case x86_ECX: AddCode16(0xf9F7); break; - case x86_EDX: AddCode16(0xfaF7); break; - case x86_ESI: AddCode16(0xfeF7); break; - case x86_EDI: AddCode16(0xffF7); break; - case x86_ESP: AddCode16(0xfcF7); break; - case x86_EBP: AddCode16(0xfdF7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::imulX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" imul %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE8F7); break; - case x86_EBX: AddCode16(0xEBF7); break; - case x86_ECX: AddCode16(0xE9F7); break; - case x86_EDX: AddCode16(0xEAF7); break; - case x86_ESI: AddCode16(0xEEF7); break; - case x86_EDI: AddCode16(0xEFF7); break; - case x86_ESP: AddCode16(0xECF7); break; - case x86_EBP: AddCode16(0xEDF7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::IncX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" inc %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xC0FF); break; - case x86_EBX: AddCode16(0xC3FF); break; - case x86_ECX: AddCode16(0xC1FF); break; - case x86_EDX: AddCode16(0xC2FF); break; - case x86_ESI: AddCode16(0xC6FF); break; - case x86_EDI: AddCode16(0xC7FF); break; - case x86_ESP: AddCode8(0x44); break; - case x86_EBP: AddCode8(0x45); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::JaeLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jae $%s", Label); - AddCode8(0x73); - AddCode8(Value); -} - -void CX86Ops::JaeLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jae $%s", Label); - AddCode16(0x830F); - AddCode32(Value); -} - -void CX86Ops::JaLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" ja $%s", Label); - AddCode8(0x77); - AddCode8(Value); -} - -void CX86Ops::JaLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" ja $%s", Label); - AddCode16(0x870F); - AddCode32(Value); -} - -void CX86Ops::JbLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jb $%s", Label); - AddCode8(0x72); - AddCode8(Value); -} - -void CX86Ops::JbLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jb $%s", Label); - AddCode16(0x820F); - AddCode32(Value); -} - -void CX86Ops::JecxzLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jecxz $%s", Label); - AddCode8(0xE3); - AddCode8(Value); -} - -void CX86Ops::JeLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" je $%s", Label); - AddCode8(0x74); - AddCode8(Value); -} - -void CX86Ops::JeLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" je $%s", Label); - AddCode16(0x840F); - AddCode32(Value); -} - -void CX86Ops::JgeLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jge $%s", Label); - AddCode8(0x7D); - AddCode8(Value); -} - -void CX86Ops::JgeLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jge $%s", Label); - AddCode16(0x8D0F); - AddCode32(Value); -} - -void CX86Ops::JgLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jg $%s", Label); - AddCode8(0x7F); - AddCode8(Value); -} - -void CX86Ops::JgLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jg $%s", Label); - AddCode16(0x8F0F); - AddCode32(Value); -} - -void CX86Ops::JleLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jle $%s", Label); - AddCode8(0x7E); - AddCode8(Value); -} - -void CX86Ops::JleLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jle $%s", Label); - AddCode16(0x8E0F); - AddCode32(Value); -} - -void CX86Ops::JlLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jl $%s", Label); - AddCode8(0x7C); - AddCode8(Value); -} - -void CX86Ops::JlLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jl $%s", Label); - AddCode16(0x8C0F); - AddCode32(Value); -} - -void CX86Ops::JmpDirectReg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" jmp %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE0ff); break; - case x86_EBX: AddCode16(0xE3ff); break; - case x86_ECX: AddCode16(0xE1ff); break; - case x86_EDX: AddCode16(0xE2ff); break; - case x86_ESI: AddCode16(0xE6ff); break; - case x86_EDI: AddCode16(0xE7ff); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::JmpIndirectLabel32(const char * Label, uint32_t location) -{ - CodeLog(" jmp dword ptr [%s]", Label); - AddCode16(0x25ff); - AddCode32(location); -} - -void CX86Ops::JmpIndirectReg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" jmp dword ptr [%s]", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0x20ff); break; - case x86_EBX: AddCode16(0x23ff); break; - case x86_ECX: AddCode16(0x21ff); break; - case x86_EDX: AddCode16(0x22ff); break; - case x86_ESI: AddCode16(0x26ff); break; - case x86_EDI: AddCode16(0x27ff); break; - case x86_ESP: - AddCode8(0xff); - AddCode16(0x2434); - // g_Notify->BreakPoint(__FILEW__,__LINE__); - break; - case x86_EBP: - AddCode8(0xff); - AddCode16(0x0065); - // g_Notify->BreakPoint(__FILEW__,__LINE__); - break; - } -} - -void CX86Ops::JmpLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jmp $%s", Label); - AddCode8(0xEB); - AddCode8(Value); -} - -void CX86Ops::JmpLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jmp $%s", Label); - AddCode8(0xE9); - AddCode32(Value); -} - -void CX86Ops::JneLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jne $%s", Label); - AddCode8(0x75); - AddCode8(Value); -} - -void CX86Ops::JneLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jne $%s", Label); - AddCode16(0x850F); - AddCode32(Value); -} - -void CX86Ops::JnsLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jns $%s", Label); - AddCode8(0x79); - AddCode8(Value); -} - -void CX86Ops::JnsLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jns $%s", Label); - AddCode16(0x890F); - AddCode32(Value); -} - -void CX86Ops::JnzLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jnz $%s", Label); - AddCode8(0x75); - AddCode8(Value); -} - -void CX86Ops::JnzLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jnz $%s", Label); - AddCode16(0x850F); - AddCode32(Value); -} - -void CX86Ops::JsLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" js $%s", Label); - AddCode16(0x880F); - AddCode32(Value); -} - -void CX86Ops::JoLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jo $%s", Label); - AddCode16(0x800F); - AddCode32(Value); -} - -void CX86Ops::JzLabel8(const char * Label, uint8_t Value) -{ - CodeLog(" jz $%s", Label); - AddCode8(0x74); - AddCode8(Value); -} - -void CX86Ops::JzLabel32(const char * Label, uint32_t Value) -{ - CodeLog(" jz $%s", Label); - AddCode16(0x840F); - AddCode32(Value); -} - -void CX86Ops::LeaRegReg(const asmjit::x86::Gp & RegDest, const asmjit::x86::Gp & RegSrc, uint32_t Const, Multipler multiplier) -{ - if (Const != 0) - { - CodeLog(" lea %s, [%s*%i+%X]", x86_Name(RegDest), x86_Name(RegSrc), multiplier, Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + cmp(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } else { - CodeLog(" lea %s, [%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), multiplier); + cmp(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); } - - AddCode8(0x8D); - AddCode8((uint8_t)(0x04 + (RegValue(RegDest) * 8))); - AddCode8((uint8_t)(0x05 + (RegValue(RegSrc) * 8) + CalcMultiplyCode(multiplier))); - AddCode32(Const); } -void CX86Ops::LeaRegReg2(const asmjit::x86::Gp & RegDest, const asmjit::x86::Gp & RegSrc, const asmjit::x86::Gp & RegSrc2, Multipler multiplier) +void CX86Ops::JaeLabel(const char * LabelName, asmjit::Label & JumpLabel) { - CodeLog(" lea %s, [%s+%s*%i]", x86_Name(RegDest), x86_Name(RegSrc), x86_Name(RegSrc2), multiplier); - - if (RegSrc2 == asmjit::x86::esp || RegSrc2 == asmjit::x86::ebp) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - return; - } - AddCode8(0x8D); - AddCode8((uint8_t)(0x04 + (RegValue(RegDest) * 0x8))); - AddCode8((uint8_t)(0x05 + (RegValue(RegSrc) * 0x8) + RegValue(RegSrc2) + CalcMultiplyCode(multiplier))); + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jae(JumpLabel); } -void CX86Ops::LeaSourceAndOffset(const asmjit::x86::Gp & x86DestReg, const asmjit::x86::Gp & x86SourceReg, int32_t offset) +void CX86Ops::JaLabel(const char * LabelName, asmjit::Label & JumpLabel) { - uint16_t x86Command = 0; + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + ja(JumpLabel); +} - CodeLog(" lea %s, [%s + %0Xh]", x86_Name(x86DestReg), x86_Name(x86SourceReg), offset); +void CX86Ops::JbLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jb(JumpLabel); +} - // if ((offset & 0xFFFFFF80) != 0 && (offset & 0xFFFFFF80) != 0xFFFFFF80) { - if (1) - { - switch (RegValue(x86DestReg)) - { - case x86_EAX: x86Command = 0x808D; break; - case x86_EBX: x86Command = 0x988D; break; - case x86_ECX: x86Command = 0x888D; break; - case x86_EDX: x86Command = 0x908D; break; - case x86_ESI: x86Command = 0xB08D; break; - case x86_EDI: x86Command = 0xB88D; break; - case x86_ESP: x86Command = 0xA08D; break; - case x86_EBP: x86Command = 0xA88D; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(x86SourceReg)) - { - case x86_EAX: x86Command += 0x0000; break; - case x86_EBX: x86Command += 0x0300; break; - case x86_ECX: x86Command += 0x0100; break; - case x86_EDX: x86Command += 0x0200; break; - case x86_ESI: x86Command += 0x0600; break; - case x86_EDI: x86Command += 0x0700; break; - case x86_ESP: x86Command += 0x0400; break; - case x86_EBP: x86Command += 0x0500; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); - AddCode32(offset); - } - else - { - switch (RegValue(x86DestReg)) - { - case x86_EAX: x86Command = 0x408D; break; - case x86_EBX: x86Command = 0x588D; break; - case x86_ECX: x86Command = 0x488D; break; - case x86_EDX: x86Command = 0x508D; break; - case x86_ESI: x86Command = 0x708D; break; - case x86_EDI: x86Command = 0x788D; break; - case x86_ESP: x86Command = 0x608D; break; - case x86_EBP: x86Command = 0x688D; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(x86SourceReg)) - { - case x86_EAX: x86Command += 0x0000; break; - case x86_EBX: x86Command += 0x0300; break; - case x86_ECX: x86Command += 0x0100; break; - case x86_EDX: x86Command += 0x0200; break; - case x86_ESI: x86Command += 0x0600; break; - case x86_EDI: x86Command += 0x0700; break; - case x86_ESP: x86Command += 0x0400; break; - case x86_EBP: x86Command += 0x0500; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); - AddCode8((uint8_t)offset); - } +void CX86Ops::JecxzLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jecxz(JumpLabel); +} + +void CX86Ops::JeLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + je(JumpLabel); +} + +void CX86Ops::JgeLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jge(JumpLabel); +} + +void CX86Ops::JgLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jg(JumpLabel); +} + +void CX86Ops::JleLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jle(JumpLabel); +} + +void CX86Ops::JlLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jl(JumpLabel); +} + +void CX86Ops::JmpLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jmp(JumpLabel); +} + +void CX86Ops::JneLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jne(JumpLabel); +} + +void CX86Ops::JnsLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jns(JumpLabel); +} + +void CX86Ops::JnzLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jnz(JumpLabel); +} + +void CX86Ops::JsLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + js(JumpLabel); +} + +void CX86Ops::JoLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jo(JumpLabel); +} + +void CX86Ops::JzLabel(const char * LabelName, asmjit::Label & JumpLabel) +{ + AddSymbol(stdstr_f("L%d", JumpLabel.id()).c_str(), LabelName); + jz(JumpLabel); } void CX86Ops::MoveConstByteToVariable(void * Variable, const char * VariableName, uint8_t Const) { - CodeLog(" mov byte ptr [%s], %Xh", VariableName, Const); - AddCode16(0x05C6); - AddCode32((uint32_t)Variable); - AddCode8(Const); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::byte_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + mov(asmjit::x86::byte_ptr((uint64_t)Variable), Const); + } } void CX86Ops::MoveConstHalfToVariable(void * Variable, const char * VariableName, uint16_t Const) { - CodeLog(" mov word ptr [%s], %Xh", VariableName, Const); - AddCode8(0x66); - AddCode16(0x05C7); - AddCode32((uint32_t)Variable); - AddCode16(Const); -} - -void CX86Ops::MoveConstHalfToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint16_t Const) -{ - uint8_t Param = 0; - - CodeLog(" mov word ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); - - AddCode8(0x66); - AddCode16(0x04C7); - - switch (RegValue(AddrReg1)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::word_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } - - switch (RegValue(AddrReg2)) + else { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + mov(asmjit::x86::word_ptr((uint64_t)Variable), Const); } - AddCode8(Param); - AddCode16(Const); -} - -void CX86Ops::MoveConstToMemoryDisp(const asmjit::x86::Gp & AddrReg, uint32_t Disp, uint32_t Const) -{ - CodeLog(" mov dword ptr [%s+%Xh], %Xh", x86_Name(AddrReg), Disp, Const); - switch (RegValue(AddrReg)) - { - case x86_EAX: AddCode16(0x80C7); break; - case x86_EBX: AddCode16(0x83C7); break; - case x86_ECX: AddCode16(0x81C7); break; - case x86_EDX: AddCode16(0x82C7); break; - case x86_ESI: AddCode16(0x86C7); break; - case x86_EDI: AddCode16(0x87C7); break; - case x86_ESP: AddCode16(0x84C7); break; - case x86_EBP: AddCode16(0x85C7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Disp); - AddCode32(Const); } void CX86Ops::MoveConstToVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" mov dword ptr [%s], %Xh", VariableName, Const); - AddCode16(0x05C7); - AddCode32((uint32_t)Variable); - AddCode32(Const); -} - -void CX86Ops::MoveConstToX86Pointer(const asmjit::x86::Gp & X86Pointer, uint32_t Const) -{ - CodeLog(" mov dword ptr [%s], %Xh", x86_Name(X86Pointer), Const); - AddCode16((uint16_t)(0x00C7 + (RegValue(X86Pointer) * 0x100))); - AddCode32(Const); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + mov(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + } } void CX86Ops::MoveConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const) { if (Const == 0) { - XorX86RegToX86Reg(Reg, Reg); + xor_(Reg, Reg); } else { - CodeLog(" mov %s, %Xh", x86_Name(Reg), Const); - AddCode16((uint16_t)(0xC0C7 + (RegValue(Reg) * 0x100))); - AddCode32(Const); + mov(Reg, Const); } } -void CX86Ops::MoveConstByteToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint8_t Const) -{ - uint8_t Param = 0; - - CodeLog(" mov byte ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); - - AddCode16(0x04C6); - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); - AddCode8(Const); -} - -void CX86Ops::MoveConstToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint32_t Const) -{ - uint8_t Param = 0; - - CodeLog(" mov dword ptr [%s+%s],%Xh", x86_Name(AddrReg1), x86_Name(AddrReg2), Const); - - AddCode16(0x04C7); - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); - AddCode32(Const); -} - -void CX86Ops::MoveSxByteX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2) -{ - uint8_t Param = 0; - - CodeLog(" movsx %s, byte ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - AddCode16(0xBE0F); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x04); break; - case x86_EBX: AddCode8(0x1C); break; - case x86_ECX: AddCode8(0x0C); break; - case x86_EDX: AddCode8(0x14); break; - case x86_ESI: AddCode8(0x34); break; - case x86_EDI: AddCode8(0x3C); break; - case x86_ESP: AddCode8(0x24); break; - case x86_EBP: AddCode8(0x2C); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - -void CX86Ops::MoveSxHalfX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2) -{ - uint8_t Param = 0; - - CodeLog(" movsx %s, word ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - AddCode16(0xBF0F); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x04); break; - case x86_EBX: AddCode8(0x1C); break; - case x86_ECX: AddCode8(0x0C); break; - case x86_EDX: AddCode8(0x14); break; - case x86_ESI: AddCode8(0x34); break; - case x86_EDI: AddCode8(0x3C); break; - case x86_ESP: AddCode8(0x24); break; - case x86_EBP: AddCode8(0x2C); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - void CX86Ops::MoveSxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" movsx %s, byte ptr [%s]", x86_Name(Reg), VariableName); - - AddCode16(0xbe0f); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0x05); break; - case x86_EBX: AddCode8(0x1D); break; - case x86_ECX: AddCode8(0x0D); break; - case x86_EDX: AddCode8(0x15); break; - case x86_ESI: AddCode8(0x35); break; - case x86_EDI: AddCode8(0x3D); break; - case x86_ESP: AddCode8(0x25); break; - case x86_EBP: AddCode8(0x2D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + movsx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + movsx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable)); } - AddCode32((uint32_t)Variable); } void CX86Ops::MoveSxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" movsx %s, word ptr [%s]", x86_Name(Reg), VariableName); - - AddCode16(0xbf0f); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0x05); break; - case x86_EBX: AddCode8(0x1D); break; - case x86_ECX: AddCode8(0x0D); break; - case x86_EDX: AddCode8(0x15); break; - case x86_ESI: AddCode8(0x35); break; - case x86_EDI: AddCode8(0x3D); break; - case x86_ESP: AddCode8(0x25); break; - case x86_EBP: AddCode8(0x2D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + movsx(Reg, asmjit::x86::word_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + movsx(Reg, asmjit::x86::word_ptr((uint64_t)Variable)); } - AddCode32((uint32_t)Variable); } void CX86Ops::MoveVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" mov %s, dword ptr [%s]", x86_Name(Reg), VariableName); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x058B); break; - case x86_EBX: AddCode16(0x1D8B); break; - case x86_ECX: AddCode16(0x0D8B); break; - case x86_EDX: AddCode16(0x158B); break; - case x86_ESI: AddCode16(0x358B); break; - case x86_EDI: AddCode16(0x3D8B); break; - case x86_ESP: AddCode16(0x258B); break; - case x86_EBP: AddCode16(0x2D8B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); } - AddCode32((uint32_t)Variable); } void CX86Ops::MoveVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiplier) { - CodeLog(" mov %s, dword ptr [%s+%s*%i]", x86_Name(Reg), VariableName, x86_Name(AddrReg), Multiplier); - - AddCode8(0x8B); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0x04); break; - case x86_EBX: AddCode8(0x1C); break; - case x86_ECX: AddCode8(0x0C); break; - case x86_EDX: AddCode8(0x14); break; - case x86_ESI: AddCode8(0x34); break; - case x86_EDI: AddCode8(0x3C); break; - case x86_ESP: AddCode8(0x24); break; - case x86_EBP: AddCode8(0x2C); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiplier >> 1)); + RemoveSymbol(SymbolKey.c_str()); } - - // Put in shifter 2(01), 4(10), 8(11) - uint8_t x = CalcMultiplyCode(Multiplier); - - // Format xx|000000 - switch (RegValue(AddrReg)) + else { - case x86_EAX: AddCode8((uint8_t)(0x05 | x)); break; - case x86_EBX: AddCode8((uint8_t)(0x1D | x)); break; - case x86_ECX: AddCode8((uint8_t)(0x0D | x)); break; - case x86_EDX: AddCode8((uint8_t)(0x15 | x)); break; - case x86_ESI: AddCode8((uint8_t)(0x35 | x)); break; - case x86_EDI: AddCode8((uint8_t)(0x3D | x)); break; - case x86_ESP: AddCode8((uint8_t)(0x25 | x)); break; - case x86_EBP: AddCode8((uint8_t)(0x2D | x)); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + mov(Reg, asmjit::x86::dword_ptr((uint64_t)Variable, AddrReg, Multiplier >> 1)); } - - AddCode32((uint32_t)Variable); } void CX86Ops::MoveX86regByteToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) { - CodeLog(" mov byte ptr [%s], %s", VariableName, x86_ByteName(Reg)); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x0588); break; - case x86_EBX: AddCode16(0x1D88); break; - case x86_ECX: AddCode16(0x0D88); break; - case x86_EDX: AddCode16(0x1588); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::byte_ptr((uint64_t)(Variable)), Reg.r8()); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)Variable); -} - -void CX86Ops::MoveX86regByteToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg) -{ - uint8_t Param = 0; - - CodeLog(" mov byte ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_ByteName(Reg)); - - switch (RegValue(Reg)) + else { - case x86_EAX: AddCode16(0x0488); break; - case x86_EBX: AddCode16(0x1C88); break; - case x86_ECX: AddCode16(0x0C88); break; - case x86_EDX: AddCode16(0x1488); break; - case x86_ESI: AddCode16(0x3488); break; - case x86_EDI: AddCode16(0x3C88); break; - case x86_ESP: AddCode16(0x2488); break; - case x86_EBP: AddCode16(0x2C88); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + mov(asmjit::x86::byte_ptr((uint64_t)(Variable)), Reg.r8()); } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); } void CX86Ops::MoveX86regHalfToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) { - CodeLog(" mov word ptr [%s], %s", VariableName, x86_HalfName(Reg)); - AddCode8(0x66); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x0589); break; - case x86_EBX: AddCode16(0x1D89); break; - case x86_ECX: AddCode16(0x0D89); break; - case x86_EDX: AddCode16(0x1589); break; - case x86_ESI: AddCode16(0x3589); break; - case x86_EDI: AddCode16(0x3D89); break; - case x86_ESP: AddCode16(0x2589); break; - case x86_EBP: AddCode16(0x2D89); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::word_ptr((uint64_t)(Variable)), Reg.r16()); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)Variable); -} - -void CX86Ops::MoveX86regHalfToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg) -{ - uint8_t Param = 0; - - CodeLog(" mov word ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_HalfName(Reg)); - - AddCode8(0x66); - switch (RegValue(Reg)) + else { - case x86_EAX: AddCode16(0x0489); break; - case x86_EBX: AddCode16(0x1C89); break; - case x86_ECX: AddCode16(0x0C89); break; - case x86_EDX: AddCode16(0x1489); break; - case x86_ESI: AddCode16(0x3489); break; - case x86_EDI: AddCode16(0x3C89); break; - case x86_ESP: AddCode16(0x2489); break; - case x86_EBP: AddCode16(0x2C89); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + mov(asmjit::x86::word_ptr((uint64_t)(Variable)), Reg.r16()); } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - -void CX86Ops::MoveX86PointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & X86Pointer) -{ - uint16_t x86Command = 0; - - CodeLog(" mov %s, dword ptr [%s]", x86_Name(Reg), x86_Name(X86Pointer)); - - switch (RegValue(X86Pointer)) - { - case x86_EAX: x86Command = 0x008B; break; - case x86_EBX: x86Command = 0x038B; break; - case x86_ECX: x86Command = 0x018B; break; - case x86_EDX: x86Command = 0x028B; break; - case x86_ESI: x86Command = 0x068B; break; - case x86_EDI: x86Command = 0x078B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Reg)) - { - case x86_EAX: x86Command += 0x0000; break; - case x86_EBX: x86Command += 0x1800; break; - case x86_ECX: x86Command += 0x0800; break; - case x86_EDX: x86Command += 0x1000; break; - case x86_ESI: x86Command += 0x3000; break; - case x86_EDI: x86Command += 0x3800; break; - case x86_ESP: x86Command += 0x2000; break; - case x86_EBP: x86Command += 0x2800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::MoveX86PointerToX86regDisp(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & X86Pointer, uint8_t Disp) -{ - uint16_t x86Command = 0; - - CodeLog(" mov %s, dword ptr [%s] + %d", x86_Name(Reg), x86_Name(X86Pointer), Disp); - - switch (RegValue(X86Pointer)) - { - case x86_EAX: x86Command = 0x408B; break; - case x86_EBX: x86Command = 0x438B; break; - case x86_ECX: x86Command = 0x418B; break; - case x86_EDX: x86Command = 0x428B; break; - case x86_ESI: x86Command = 0x468B; break; - case x86_EDI: x86Command = 0x478B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Reg)) - { - case x86_EAX: x86Command += 0x0000; break; - case x86_EBX: x86Command += 0x1800; break; - case x86_ECX: x86Command += 0x0800; break; - case x86_EDX: x86Command += 0x1000; break; - case x86_ESI: x86Command += 0x3000; break; - case x86_EDI: x86Command += 0x3800; break; - case x86_ESP: x86Command += 0x2000; break; - case x86_EBP: x86Command += 0x2800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); - AddCode8(Disp); -} - -void CX86Ops::MoveX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2) -{ - uint8_t Param = 0; - - CodeLog(" mov %s, dword ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0x048B); break; - case x86_EBX: AddCode16(0x1C8B); break; - case x86_ECX: AddCode16(0x0C8B); break; - case x86_EDX: AddCode16(0x148B); break; - case x86_ESI: AddCode16(0x348B); break; - case x86_EDI: AddCode16(0x3C8B); break; - case x86_ESP: AddCode16(0x248B); break; - case x86_EBP: AddCode16(0x2C8B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - -void CX86Ops::MoveX86regPointerToX86regDisp8(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint8_t offset) -{ - uint8_t Param = 0; - - CodeLog(" mov %s, dword ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0x448B); break; - case x86_EBX: AddCode16(0x5C8B); break; - case x86_ECX: AddCode16(0x4C8B); break; - case x86_EDX: AddCode16(0x548B); break; - case x86_ESI: AddCode16(0x748B); break; - case x86_EDI: AddCode16(0x7C8B); break; - case x86_ESP: AddCode16(0x648B); break; - case x86_EBP: AddCode16(0x6C8B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); - AddCode8(offset); -} - -void CX86Ops::MoveX86regToMemory(const asmjit::x86::Gp & AddrReg, uint32_t Disp, const asmjit::x86::Gp & Reg) -{ - uint16_t x86Command = 0; - - CodeLog(" mov dword ptr [%s+%X], %s", x86_Name(AddrReg), Disp, x86_Name(Reg)); - switch (RegValue(AddrReg)) - { - case x86_EAX: x86Command = 0x0089; break; - case x86_EBX: x86Command = 0x0389; break; - case x86_ECX: x86Command = 0x0189; break; - case x86_EDX: x86Command = 0x0289; break; - case x86_ESI: x86Command = 0x0689; break; - case x86_EDI: x86Command = 0x0789; break; - case x86_ESP: x86Command = 0x0489; break; - case x86_EBP: x86Command = 0x0589; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Reg)) - { - case x86_EAX: x86Command += 0x8000; break; - case x86_EBX: x86Command += 0x9800; break; - case x86_ECX: x86Command += 0x8800; break; - case x86_EDX: x86Command += 0x9000; break; - case x86_ESI: x86Command += 0xB000; break; - case x86_EDI: x86Command += 0xB800; break; - case x86_ESP: x86Command += 0xA000; break; - case x86_EBP: x86Command += 0xA800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); - AddCode32(Disp); } void CX86Ops::MoveX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) { - CodeLog(" mov dword ptr [%s], %s", VariableName, x86_Name(Reg)); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x0589); break; - case x86_EBX: AddCode16(0x1D89); break; - case x86_ECX: AddCode16(0x0D89); break; - case x86_EDX: AddCode16(0x1589); break; - case x86_ESI: AddCode16(0x3589); break; - case x86_EDI: AddCode16(0x3D89); break; - case x86_ESP: AddCode16(0x2589); break; - case x86_EBP: AddCode16(0x2D89); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + mov(asmjit::x86::dword_ptr((uint64_t)(Variable)), Reg); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::MoveX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - - if (Source == Destination) + else { - return; + mov(asmjit::x86::dword_ptr((uint64_t)(Variable)), Reg); } - CodeLog(" mov %s, %s", x86_Name(Destination), x86_Name(Source)); - - switch (RegValue(Destination)) - { - case x86_EAX: x86Command = 0x0089; break; - case x86_EBX: x86Command = 0x0389; break; - case x86_ECX: x86Command = 0x0189; break; - case x86_EDX: x86Command = 0x0289; break; - case x86_ESI: x86Command = 0x0689; break; - case x86_EDI: x86Command = 0x0789; break; - case x86_ESP: x86Command = 0x0489; break; - case x86_EBP: x86Command = 0x0589; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Source)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::MoveX86regToX86Pointer(const asmjit::x86::Gp & X86Pointer, const asmjit::x86::Gp & Reg) -{ - uint16_t x86Command = 0; - - CodeLog(" mov dword ptr [%s], %s", x86_Name(X86Pointer), x86_Name(Reg)); - - switch (RegValue(X86Pointer)) - { - case x86_EAX: x86Command = 0x0089; break; - case x86_EBX: x86Command = 0x0389; break; - case x86_ECX: x86Command = 0x0189; break; - case x86_EDX: x86Command = 0x0289; break; - case x86_ESI: x86Command = 0x0689; break; - case x86_EDI: x86Command = 0x0789; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Reg)) - { - case x86_EAX: x86Command += 0x0000; break; - case x86_EBX: x86Command += 0x1800; break; - case x86_ECX: x86Command += 0x0800; break; - case x86_EDX: x86Command += 0x1000; break; - case x86_ESI: x86Command += 0x3000; break; - case x86_EDI: x86Command += 0x3800; break; - case x86_ESP: x86Command += 0x2000; break; - case x86_EBP: x86Command += 0x2800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::MoveX86regToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg) -{ - uint8_t Param = 0; - - CodeLog(" mov dword ptr [%s+%s],%s", x86_Name(AddrReg1), x86_Name(AddrReg2), x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0x0489); break; - case x86_EBX: AddCode16(0x1C89); break; - case x86_ECX: AddCode16(0x0C89); break; - case x86_EDX: AddCode16(0x1489); break; - case x86_ESI: AddCode16(0x3489); break; - case x86_EDI: AddCode16(0x3C89); break; - case x86_ESP: AddCode16(0x2489); break; - case x86_EBP: AddCode16(0x2C89); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - -void CX86Ops::MoveZxByteX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2) -{ - uint8_t Param = 0; - - CodeLog(" movzx %s, byte ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - AddCode16(0xB60F); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x04); break; - case x86_EBX: AddCode8(0x1C); break; - case x86_ECX: AddCode8(0x0C); break; - case x86_EDX: AddCode8(0x14); break; - case x86_ESI: AddCode8(0x34); break; - case x86_EDI: AddCode8(0x3C); break; - case x86_ESP: AddCode8(0x24); break; - case x86_EBP: AddCode8(0x2C); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); -} - -void CX86Ops::MoveZxHalfX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2) -{ - uint8_t Param = 0; - - CodeLog(" movzx %s, word ptr [%s+%s]", x86_Name(Reg), x86_Name(AddrReg1), x86_Name(AddrReg2)); - - AddCode16(0xB70F); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x04); break; - case x86_EBX: AddCode8(0x1C); break; - case x86_ECX: AddCode8(0x0C); break; - case x86_EDX: AddCode8(0x14); break; - case x86_ESI: AddCode8(0x34); break; - case x86_EDI: AddCode8(0x3C); break; - case x86_ESP: AddCode8(0x24); break; - case x86_EBP: AddCode8(0x2C); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg1)) - { - case x86_EAX: Param = 0x00; break; - case x86_EBX: Param = 0x03; break; - case x86_ECX: Param = 0x01; break; - case x86_EDX: Param = 0x02; break; - case x86_ESI: Param = 0x06; break; - case x86_EDI: Param = 0x07; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(AddrReg2)) - { - case x86_EAX: Param += 0x00; break; - case x86_EBX: Param += 0x18; break; - case x86_ECX: Param += 0x08; break; - case x86_EDX: Param += 0x10; break; - case x86_ESI: Param += 0x30; break; - case x86_EDI: Param += 0x38; break; - case x86_ESP: Param += 0x20; break; - case x86_EBP: Param += 0x28; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Param); } void CX86Ops::MoveZxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" movzx %s, byte ptr [%s]", x86_Name(Reg), VariableName); - - AddCode16(0xb60f); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0x05); break; - case x86_EBX: AddCode8(0x1D); break; - case x86_ECX: AddCode8(0x0D); break; - case x86_EDX: AddCode8(0x15); break; - case x86_ESI: AddCode8(0x35); break; - case x86_EDI: AddCode8(0x3D); break; - case x86_ESP: AddCode8(0x25); break; - case x86_EBP: AddCode8(0x2D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + movzx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + movzx(Reg, asmjit::x86::byte_ptr((uint64_t)Variable)); } - AddCode32((uint32_t)(Variable)); } void CX86Ops::MoveZxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" movzx %s, word ptr [%s]", x86_Name(Reg), VariableName); - - AddCode16(0xb70f); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0x05); break; - case x86_EBX: AddCode8(0x1D); break; - case x86_ECX: AddCode8(0x0D); break; - case x86_EDX: AddCode8(0x15); break; - case x86_ESI: AddCode8(0x35); break; - case x86_EDI: AddCode8(0x3D); break; - case x86_ESP: AddCode8(0x25); break; - case x86_EBP: AddCode8(0x2D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + movzx(Reg, asmjit::x86::word_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::MulX86reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" mul %s", x86_Name(Reg)); - switch (RegValue(Reg)) + else { - case x86_EAX: AddCode16(0xE0F7); break; - case x86_EBX: AddCode16(0xE3F7); break; - case x86_ECX: AddCode16(0xE1F7); break; - case x86_EDX: AddCode16(0xE2F7); break; - case x86_ESI: AddCode16(0xE6F7); break; - case x86_EDI: AddCode16(0xE7F7); break; - case x86_ESP: AddCode16(0xE4F7); break; - case x86_EBP: AddCode16(0xE5F7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::NotX86Reg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" not %s", x86_Name(Reg)); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xD0F7); break; - case x86_EBX: AddCode16(0xD3F7); break; - case x86_ECX: AddCode16(0xD1F7); break; - case x86_EDX: AddCode16(0xD2F7); break; - case x86_ESI: AddCode16(0xD6F7); break; - case x86_EDI: AddCode16(0xD7F7); break; - case x86_ESP: AddCode16(0xD4F7); break; - case x86_EBP: AddCode16(0xD5F7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + movzx(Reg, asmjit::x86::word_ptr((uint64_t)Variable)); } } void CX86Ops::OrConstToVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" or dword ptr [%s], 0x%X", VariableName, Const); - AddCode16(0x0D81); - AddCode32((uint32_t)(Variable)); - AddCode32(Const); -} - -void CX86Ops::OrConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - if (Const == 0) + if (CDebugSettings::bRecordRecompilerAsm()) { - return; - } - CodeLog(" or %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xC881); break; - case x86_EBX: AddCode16(0xCB81); break; - case x86_ECX: AddCode16(0xC981); break; - case x86_EDX: AddCode16(0xCA81); break; - case x86_ESI: AddCode16(0xCE81); break; - case x86_EDI: AddCode16(0xCF81); break; - case x86_ESP: AddCode16(0xCC81); break; - case x86_EBP: AddCode16(0xCD81); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Const); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + or_(asmjit::x86::word_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } else { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xC883); break; - case x86_EBX: AddCode16(0xCB83); break; - case x86_ECX: AddCode16(0xC983); break; - case x86_EDX: AddCode16(0xCA83); break; - case x86_ESI: AddCode16(0xCE83); break; - case x86_EDI: AddCode16(0xCF83); break; - case x86_ESP: AddCode16(0xCC83); break; - case x86_EBP: AddCode16(0xCD83); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8((uint8_t)Const); + or_(asmjit::x86::word_ptr((uint64_t)Variable), Const); } } void CX86Ops::OrVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" or %s, dword ptr [%s]", x86_Name(Reg), VariableName); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x050B); break; - case x86_EBX: AddCode16(0x1D0B); break; - case x86_ECX: AddCode16(0x0D0B); break; - case x86_EDX: AddCode16(0x150B); break; - case x86_ESI: AddCode16(0x350B); break; - case x86_EDI: AddCode16(0x3D0B); break; - case x86_ESP: AddCode16(0x250B); break; - case x86_EBP: AddCode16(0x2D0B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + or_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + or_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); } - AddCode32((uint32_t)(Variable)); } void CX86Ops::OrX86RegToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg) { - CodeLog(" or dword ptr [%s], %s", VariableName, x86_Name(Reg)); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x0509); break; - case x86_EBX: AddCode16(0x1D09); break; - case x86_ECX: AddCode16(0x0D09); break; - case x86_EDX: AddCode16(0x1509); break; - case x86_ESI: AddCode16(0x3509); break; - case x86_EDI: AddCode16(0x3D09); break; - case x86_ESP: AddCode16(0x2509); break; - case x86_EBP: AddCode16(0x2D09); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::OrX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - - CodeLog(" or %s, %s", x86_Name(Destination), x86_Name(Source)); - switch (RegValue(Source)) - { - case x86_EAX: x86Command = 0x000B; break; - case x86_EBX: x86Command = 0x030B; break; - case x86_ECX: x86Command = 0x010B; break; - case x86_EDX: x86Command = 0x020B; break; - case x86_ESI: x86Command = 0x060B; break; - case x86_EDI: x86Command = 0x070B; break; - case x86_ESP: x86Command = 0x040B; break; - case x86_EBP: x86Command = 0x050B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::Popad(void) -{ - CodeLog(" popad"); - AddCode8(0x61); -} - -void CX86Ops::Pushad(void) -{ - CodeLog(" pushad"); - AddCode8(0x60); -} - -void CX86Ops::Push(const asmjit::x86::Gp & Reg) -{ - CodeLog(" push %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x50); break; - case x86_EBX: AddCode8(0x53); break; - case x86_ECX: AddCode8(0x51); break; - case x86_EDX: AddCode8(0x52); break; - case x86_ESI: AddCode8(0x56); break; - case x86_EDI: AddCode8(0x57); break; - case x86_ESP: AddCode8(0x54); break; - case x86_EBP: AddCode8(0x55); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::Pop(const asmjit::x86::Gp & Reg) -{ - CodeLog(" pop %s", x86_Name(Reg)); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0x58); break; - case x86_EBX: AddCode8(0x5B); break; - case x86_ECX: AddCode8(0x59); break; - case x86_EDX: AddCode8(0x5A); break; - case x86_ESI: AddCode8(0x5E); break; - case x86_EDI: AddCode8(0x5F); break; - case x86_ESP: AddCode8(0x5C); break; - case x86_EBP: AddCode8(0x5D); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::PushImm32(uint32_t Value) -{ - if ((Value & 0xFFFFF000) != 0) - { - PushImm32(stdstr_f("0x%X", Value).c_str(), Value); + stdstr_f SymbolKey("0x%X", Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + or_(asmjit::x86::dword_ptr((uint64_t)Variable), Reg); + RemoveSymbol(SymbolKey.c_str()); } else { - PushImm32(stdstr_f("%d", Value).c_str(), Value); + or_(asmjit::x86::dword_ptr((uint64_t)Variable), Reg); } } void CX86Ops::PushImm32(const char * String, uint32_t Value) { - CodeLog(" push %s", String); - AddCode8(0x68); - AddCode32(Value); -} - -void CX86Ops::Ret(void) -{ - CodeLog(" ret"); - AddCode8(0xC3); -} - -void CX86Ops::Seta(const asmjit::x86::Gp & Reg) -{ - CodeLog(" seta %s", x86_ByteName(Reg)); - AddCode16(0x970F); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + stdstr_f SymbolKey("0x%X", Value); + AddSymbol(SymbolKey.c_str(), String); + push(Value); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + push(Value); } } void CX86Ops::SetaVariable(void * Variable, const char * VariableName) { - CodeLog(" seta byte ptr [%s]", VariableName); - AddCode16(0x970F); - AddCode8(0x05); - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::Setae(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setae %s", x86_ByteName(Reg)); - AddCode16(0x930F); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + seta(asmjit::x86::byte_ptr((uint32_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } -} - -void CX86Ops::Setb(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setb %s", x86_ByteName(Reg)); - AddCode16(0x920F); - switch (RegValue(Reg)) + else { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + seta(asmjit::x86::byte_ptr((uint32_t)Variable)); } } void CX86Ops::SetbVariable(void * Variable, const char * VariableName) { - CodeLog(" setb byte ptr [%s]", VariableName); - AddCode16(0x920F); - AddCode8(0x05); - AddCode32((uint32_t)(Variable)); -} - -void CX86Ops::Setg(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setg %s", x86_ByteName(Reg)); - AddCode16(0x9F0F); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + setb(asmjit::x86::byte_ptr((uint32_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + setb(asmjit::x86::byte_ptr((uint32_t)Variable)); } } void CX86Ops::SetgVariable(void * Variable, const char * VariableName) { - CodeLog(" setg byte ptr [%s]", VariableName); - AddCode16(0x9F0F); - AddCode8(0x05); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::Setl(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setl %s", x86_ByteName(Reg)); - AddCode16(0x9C0F); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + setg(asmjit::x86::byte_ptr((uint32_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + setg(asmjit::x86::byte_ptr((uint32_t)Variable)); } } void CX86Ops::SetlVariable(void * Variable, const char * VariableName) { - CodeLog(" setl byte ptr [%s]", VariableName); - AddCode16(0x9C0F); - AddCode8(0x05); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::Setz(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setz %s", x86_ByteName(Reg)); - AddCode16(0x940F); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::Setnz(const asmjit::x86::Gp & Reg) -{ - CodeLog(" setnz %s", x86_ByteName(Reg)); - AddCode16(0x950F); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0xC0); break; - case x86_EBX: AddCode8(0xC3); break; - case x86_ECX: AddCode8(0xC1); break; - case x86_EDX: AddCode8(0xC2); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::ShiftLeftDouble(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint8_t s = 0xC0; - - CodeLog(" shld %s, %s, cl", x86_Name(Destination), x86_Name(Source)); - AddCode16(0xA50F); - - switch (RegValue(Destination)) - { - case x86_EAX: s |= 0x00; break; - case x86_EBX: s |= 0x03; break; - case x86_ECX: s |= 0x01; break; - case x86_EDX: s |= 0x02; break; - case x86_ESI: s |= 0x06; break; - case x86_EDI: s |= 0x07; break; - case x86_ESP: s |= 0x04; break; - case x86_EBP: s |= 0x05; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Source)) - { - case x86_EAX: s |= 0x00 << 3; break; - case x86_EBX: s |= 0x03 << 3; break; - case x86_ECX: s |= 0x01 << 3; break; - case x86_EDX: s |= 0x02 << 3; break; - case x86_ESI: s |= 0x06 << 3; break; - case x86_EDI: s |= 0x07 << 3; break; - case x86_ESP: s |= 0x04 << 3; break; - case x86_EBP: s |= 0x05 << 3; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(s); -} - -void CX86Ops::ShiftLeftDoubleImmed(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source, uint8_t Immediate) -{ - uint8_t s = 0xC0; - - CodeLog(" shld %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); - AddCode16(0xA40F); - - switch (RegValue(Destination)) - { - case x86_EAX: s |= 0x00; break; - case x86_EBX: s |= 0x03; break; - case x86_ECX: s |= 0x01; break; - case x86_EDX: s |= 0x02; break; - case x86_ESI: s |= 0x06; break; - case x86_EDI: s |= 0x07; break; - case x86_ESP: s |= 0x04; break; - case x86_EBP: s |= 0x05; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Source)) - { - case x86_EAX: s |= 0x00 << 3; break; - case x86_EBX: s |= 0x03 << 3; break; - case x86_ECX: s |= 0x01 << 3; break; - case x86_EDX: s |= 0x02 << 3; break; - case x86_ESI: s |= 0x06 << 3; break; - case x86_EDI: s |= 0x07 << 3; break; - case x86_ESP: s |= 0x04 << 3; break; - case x86_EBP: s |= 0x05 << 3; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(s); - AddCode8(Immediate); -} - -void CX86Ops::ShiftLeftSign(const asmjit::x86::Gp & Reg) -{ - CodeLog(" shl %s, cl", x86_Name(Reg)); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE0D3); break; - case x86_EBX: AddCode16(0xE3D3); break; - case x86_ECX: AddCode16(0xE1D3); break; - case x86_EDX: AddCode16(0xE2D3); break; - case x86_ESI: AddCode16(0xE6D3); break; - case x86_EDI: AddCode16(0xE7D3); break; - case x86_ESP: AddCode16(0xE4D3); break; - case x86_EBP: AddCode16(0xE5D3); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::ShiftLeftSignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate) -{ - CodeLog(" shl %s, %Xh", x86_Name(Reg), Immediate); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE0C1); break; - case x86_EBX: AddCode16(0xE3C1); break; - case x86_ECX: AddCode16(0xE1C1); break; - case x86_EDX: AddCode16(0xE2C1); break; - case x86_ESI: AddCode16(0xE6C1); break; - case x86_EDI: AddCode16(0xE7C1); break; - case x86_ESP: AddCode16(0xE4C1); break; - case x86_EBP: AddCode16(0xE5C1); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Immediate); -} - -void CX86Ops::ShiftRightSign(const asmjit::x86::Gp & Reg) -{ - CodeLog(" sar %s, cl", x86_Name(Reg)); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xF8D3); break; - case x86_EBX: AddCode16(0xFBD3); break; - case x86_ECX: AddCode16(0xF9D3); break; - case x86_EDX: AddCode16(0xFAD3); break; - case x86_ESI: AddCode16(0xFED3); break; - case x86_EDI: AddCode16(0xFFD3); break; - case x86_ESP: AddCode16(0xFCD3); break; - case x86_EBP: AddCode16(0xFDD3); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::ShiftRightSignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate) -{ - CodeLog(" sar %s, %Xh", x86_Name(Reg), Immediate); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xF8C1); break; - case x86_EBX: AddCode16(0xFBC1); break; - case x86_ECX: AddCode16(0xF9C1); break; - case x86_EDX: AddCode16(0xFAC1); break; - case x86_ESI: AddCode16(0xFEC1); break; - case x86_EDI: AddCode16(0xFFC1); break; - case x86_ESP: AddCode16(0xFCC1); break; - case x86_EBP: AddCode16(0xFDC1); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Immediate); -} - -void CX86Ops::ShiftRightUnsign(const asmjit::x86::Gp & Reg) -{ - CodeLog(" shr %s, cl", x86_Name(Reg)); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE8D3); break; - case x86_EBX: AddCode16(0xEBD3); break; - case x86_ECX: AddCode16(0xE9D3); break; - case x86_EDX: AddCode16(0xEAD3); break; - case x86_ESI: AddCode16(0xEED3); break; - case x86_EDI: AddCode16(0xEFD3); break; - case x86_ESP: AddCode16(0xECD3); break; - case x86_EBP: AddCode16(0xEDD3); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::ShiftRightDouble(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint8_t s = 0xC0; - - CodeLog(" shrd %s, %s, cl", x86_Name(Destination), x86_Name(Source)); - AddCode16(0xAD0F); - - switch (RegValue(Destination)) - { - case x86_EAX: s |= 0x00; break; - case x86_EBX: s |= 0x03; break; - case x86_ECX: s |= 0x01; break; - case x86_EDX: s |= 0x02; break; - case x86_ESI: s |= 0x06; break; - case x86_EDI: s |= 0x07; break; - case x86_ESP: s |= 0x04; break; - case x86_EBP: s |= 0x05; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Source)) - { - case x86_EAX: s |= 0x00 << 3; break; - case x86_EBX: s |= 0x03 << 3; break; - case x86_ECX: s |= 0x01 << 3; break; - case x86_EDX: s |= 0x02 << 3; break; - case x86_ESI: s |= 0x06 << 3; break; - case x86_EDI: s |= 0x07 << 3; break; - case x86_ESP: s |= 0x04 << 3; break; - case x86_EBP: s |= 0x05 << 3; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(s); -} - -void CX86Ops::ShiftRightDoubleImmed(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source, uint8_t Immediate) -{ - uint8_t s = 0xC0; - - CodeLog(" shrd %s, %s, %Xh", x86_Name(Destination), x86_Name(Source), Immediate); - AddCode16(0xAC0F); - - switch (RegValue(Destination)) - { - case x86_EAX: s |= 0x00; break; - case x86_EBX: s |= 0x03; break; - case x86_ECX: s |= 0x01; break; - case x86_EDX: s |= 0x02; break; - case x86_ESI: s |= 0x06; break; - case x86_EDI: s |= 0x07; break; - case x86_ESP: s |= 0x04; break; - case x86_EBP: s |= 0x05; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - switch (RegValue(Source)) - { - case x86_EAX: s |= 0x00 << 3; break; - case x86_EBX: s |= 0x03 << 3; break; - case x86_ECX: s |= 0x01 << 3; break; - case x86_EDX: s |= 0x02 << 3; break; - case x86_ESI: s |= 0x06 << 3; break; - case x86_EDI: s |= 0x07 << 3; break; - case x86_ESP: s |= 0x04 << 3; break; - case x86_EBP: s |= 0x05 << 3; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(s); - AddCode8(Immediate); -} - -void CX86Ops::ShiftRightUnsignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate) -{ - CodeLog(" shr %s, %Xh", x86_Name(Reg), Immediate); - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE8C1); break; - case x86_EBX: AddCode16(0xEBC1); break; - case x86_ECX: AddCode16(0xE9C1); break; - case x86_EDX: AddCode16(0xEAC1); break; - case x86_ESI: AddCode16(0xEEC1); break; - case x86_EDI: AddCode16(0xEFC1); break; - case x86_ESP: AddCode16(0xECC1); break; - case x86_EBP: AddCode16(0xEDC1); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8(Immediate); -} - -void CX86Ops::SbbConstFromX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" sbb %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xD881); break; - case x86_EBX: AddCode16(0xDB81); break; - case x86_ECX: AddCode16(0xD981); break; - case x86_EDX: AddCode16(0xDA81); break; - case x86_ESI: AddCode16(0xDE81); break; - case x86_EDI: AddCode16(0xDF81); break; - case x86_ESP: AddCode16(0xDC81); break; - case x86_EBP: AddCode16(0xDD81); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + setl(asmjit::x86::byte_ptr((uint32_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } else { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xD883); break; - case x86_EBX: AddCode16(0xDB83); break; - case x86_ECX: AddCode16(0xD983); break; - case x86_EDX: AddCode16(0xDA83); break; - case x86_ESI: AddCode16(0xDE83); break; - case x86_EDI: AddCode16(0xDF83); break; - case x86_ESP: AddCode16(0xDC83); break; - case x86_EBP: AddCode16(0xDD83); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8((uint8_t)Const); + setl(asmjit::x86::byte_ptr((uint32_t)Variable)); } } void CX86Ops::SbbVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" sbb %s, dword ptr [%s]", x86_Name(Reg), VariableName); - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x051B); break; - case x86_EBX: AddCode16(0x1D1B); break; - case x86_ECX: AddCode16(0x0D1B); break; - case x86_EDX: AddCode16(0x151B); break; - case x86_ESI: AddCode16(0x351B); break; - case x86_EDI: AddCode16(0x3D1B); break; - case x86_ESP: AddCode16(0x251B); break; - case x86_EBP: AddCode16(0x2D1B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + sbb(Reg, asmjit::x86::dword_ptr((uint32_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)Variable); -} - -void CX86Ops::SbbX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - CodeLog(" sbb %s, %s", x86_Name(Destination), x86_Name(Source)); - switch (RegValue(Source)) + else { - case x86_EAX: x86Command = 0x001B; break; - case x86_EBX: x86Command = 0x031B; break; - case x86_ECX: x86Command = 0x011B; break; - case x86_EDX: x86Command = 0x021B; break; - case x86_ESI: x86Command = 0x061B; break; - case x86_EDI: x86Command = 0x071B; break; - case x86_ESP: x86Command = 0x041B; break; - case x86_EBP: x86Command = 0x051B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + sbb(Reg, asmjit::x86::dword_ptr((uint32_t)Variable)); } - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); } void CX86Ops::SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName) { - CodeLog(" sub dword ptr [%s], 0x%X", VariableName, Const); - - AddCode16(0x2D81); - AddCode32((uint32_t)Variable); - AddCode32(Const); -} - -void CX86Ops::SubConstFromX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" sub %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) + if (CDebugSettings::bRecordRecompilerAsm()) { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE881); break; - case x86_EBX: AddCode16(0xEB81); break; - case x86_ECX: AddCode16(0xE981); break; - case x86_EDX: AddCode16(0xEA81); break; - case x86_ESI: AddCode16(0xEE81); break; - case x86_EDI: AddCode16(0xEF81); break; - case x86_ESP: AddCode16(0xEC81); break; - case x86_EBP: AddCode16(0xED81); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + sub(asmjit::x86::dword_ptr((uint32_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } else { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xE883); break; - case x86_EBX: AddCode16(0xEB83); break; - case x86_ECX: AddCode16(0xE983); break; - case x86_EDX: AddCode16(0xEA83); break; - case x86_ESI: AddCode16(0xEE83); break; - case x86_EDI: AddCode16(0xEF83); break; - case x86_ESP: AddCode16(0xEC83); break; - case x86_EBP: AddCode16(0xED83); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8((uint8_t)Const); + sub(asmjit::x86::dword_ptr((uint32_t)Variable), Const); } } void CX86Ops::SubVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" sub %s, dword ptr [%s]", x86_Name(Reg), VariableName); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x052B); break; - case x86_EBX: AddCode16(0x1D2B); break; - case x86_ECX: AddCode16(0x0D2B); break; - case x86_EDX: AddCode16(0x152B); break; - case x86_ESI: AddCode16(0x352B); break; - case x86_EDI: AddCode16(0x3D2B); break; - case x86_ESP: AddCode16(0x252B); break; - case x86_EBP: AddCode16(0x2D2B); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + sub(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)Variable); -} - -void CX86Ops::SubX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - CodeLog(" sub %s, %s", x86_Name(Destination), x86_Name(Source)); - - switch (RegValue(Source)) + else { - case x86_EAX: x86Command = 0x002B; break; - case x86_EBX: x86Command = 0x032B; break; - case x86_ECX: x86Command = 0x012B; break; - case x86_EDX: x86Command = 0x022B; break; - case x86_ESI: x86Command = 0x062B; break; - case x86_EDI: x86Command = 0x072B; break; - case x86_ESP: x86Command = 0x042B; break; - case x86_EBP: x86Command = 0x052B; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + sub(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); } - - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::TestConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" test %s, 0x%X", x86_Name(Reg), Const); - - switch (RegValue(Reg)) - { - case x86_EAX: AddCode8(0xA9); break; - case x86_EBX: AddCode16(0xC3F7); break; - case x86_ECX: AddCode16(0xC1F7); break; - case x86_EDX: AddCode16(0xC2F7); break; - case x86_ESI: AddCode16(0xC6F7); break; - case x86_EDI: AddCode16(0xC7F7); break; - case x86_ESP: AddCode16(0xC4F7); break; - case x86_EBP: AddCode16(0xC5F7); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Const); } void CX86Ops::TestVariable(void * Variable, const char * VariableName, uint32_t Const) { - CodeLog(" test dword ptr ds:[%s], 0x%X", VariableName, Const); - AddCode16(0x05F7); - AddCode32((uint32_t)Variable); - AddCode32(Const); -} - -void CX86Ops::TestX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - CodeLog(" test %s, %s", x86_Name(Destination), x86_Name(Source)); - switch (RegValue(Source)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: x86Command = 0x0085; break; - case x86_EBX: x86Command = 0x0385; break; - case x86_ECX: x86Command = 0x0185; break; - case x86_EDX: x86Command = 0x0285; break; - case x86_ESI: x86Command = 0x0685; break; - case x86_EDI: x86Command = 0x0785; break; - case x86_ESP: x86Command = 0x0485; break; - case x86_EBP: x86Command = 0x0585; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::TestX86ByteRegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source) -{ - uint16_t x86Command = 0; - CodeLog(" test %s, %s", x86_ByteName(Destination), x86_ByteName(Source)); - switch (RegValue(Source)) - { - case x86_AL: x86Command = 0x0084; break; - case x86_BL: x86Command = 0x0384; break; - case x86_CL: x86Command = 0x0184; break; - case x86_DL: x86Command = 0x0284; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Destination)) - { - case x86_AL: x86Command += 0xC000; break; - case x86_BL: x86Command += 0xD800; break; - case x86_CL: x86Command += 0xC800; break; - case x86_DL: x86Command += 0xD000; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - -void CX86Ops::XorConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const) -{ - CodeLog(" xor %s, %Xh", x86_Name(Reg), Const); - if ((Const & 0xFFFFFF80) != 0 && (Const & 0xFFFFFF80) != 0xFFFFFF80) - { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xF081); break; - case x86_EBX: AddCode16(0xF381); break; - case x86_ECX: AddCode16(0xF181); break; - case x86_EDX: AddCode16(0xF281); break; - case x86_ESI: AddCode16(0xF681); break; - case x86_EDI: AddCode16(0xF781); break; - case x86_ESP: AddCode16(0xF481); break; - case x86_EBP: AddCode16(0xF581); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32(Const); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + test(asmjit::x86::dword_ptr((uint64_t)Variable), Const); + RemoveSymbol(SymbolKey.c_str()); } else { - switch (RegValue(Reg)) - { - case x86_EAX: AddCode16(0xF083); break; - case x86_EBX: AddCode16(0xF383); break; - case x86_ECX: AddCode16(0xF183); break; - case x86_EDX: AddCode16(0xF283); break; - case x86_ESI: AddCode16(0xF683); break; - case x86_EDI: AddCode16(0xF783); break; - case x86_ESP: AddCode16(0xF483); break; - case x86_EBP: AddCode16(0xF583); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode8((uint8_t)Const); + test(asmjit::x86::dword_ptr((uint64_t)Variable), Const); } } -void CX86Ops::XorX86RegToX86Reg(const asmjit::x86::Gp & Source, const asmjit::x86::Gp & Destination) -{ - uint16_t x86Command = 0; - - CodeLog(" xor %s, %s", x86_Name(Source), x86_Name(Destination)); - - switch (RegValue(Source)) - { - case x86_EAX: x86Command = 0x0031; break; - case x86_EBX: x86Command = 0x0331; break; - case x86_ECX: x86Command = 0x0131; break; - case x86_EDX: x86Command = 0x0231; break; - case x86_ESI: x86Command = 0x0631; break; - case x86_EDI: x86Command = 0x0731; break; - case x86_ESP: x86Command = 0x0431; break; - case x86_EBP: x86Command = 0x0531; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - switch (RegValue(Destination)) - { - case x86_EAX: x86Command += 0xC000; break; - case x86_EBX: x86Command += 0xD800; break; - case x86_ECX: x86Command += 0xC800; break; - case x86_EDX: x86Command += 0xD000; break; - case x86_ESI: x86Command += 0xF000; break; - case x86_EDI: x86Command += 0xF800; break; - case x86_ESP: x86Command += 0xE000; break; - case x86_EBP: x86Command += 0xE800; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode16(x86Command); -} - void CX86Ops::XorVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName) { - CodeLog(" Xor %s, dword ptr [%s]", x86_Name(Reg), VariableName); - - switch (RegValue(Reg)) + if (CDebugSettings::bRecordRecompilerAsm()) { - case x86_EAX: AddCode16(0x0533); break; - case x86_EBX: AddCode16(0x1D33); break; - case x86_ECX: AddCode16(0x0D33); break; - case x86_EDX: AddCode16(0x1533); break; - case x86_ESI: AddCode16(0x3533); break; - case x86_EDI: AddCode16(0x3D33); break; - case x86_ESP: AddCode16(0x2533); break; - case x86_EBP: AddCode16(0x2D33); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + xor_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); } - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuAbs(void) -{ - CodeLog(" fabs ST(0)"); - AddCode16(0xE1D9); -} - -void CX86Ops::fpuAddDword(void * Variable, const char * VariableName) -{ - CodeLog(" fadd ST(0), dword ptr [%s]", VariableName); - AddCode16(0x05D8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuAddDwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fadd ST(0), dword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) + else { - case x86_EAX: AddCode16(0x00D8); break; - case x86_EBX: AddCode16(0x03D8); break; - case x86_ECX: AddCode16(0x01D8); break; - case x86_EDX: AddCode16(0x02D8); break; - case x86_ESI: AddCode16(0x06D8); break; - case x86_EDI: AddCode16(0x07D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; + xor_(Reg, asmjit::x86::dword_ptr((uint64_t)Variable)); } } -void CX86Ops::fpuAddQword(void * Variable, const char * VariableName) -{ - CodeLog(" fadd ST(0), qword ptr [%s]", VariableName); - AddCode16(0x05DC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuAddQwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fadd ST(0), qword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x00DC); break; - case x86_EBX: AddCode16(0x03DC); break; - case x86_ECX: AddCode16(0x01DC); break; - case x86_EDX: AddCode16(0x02DC); break; - case x86_ESI: AddCode16(0x06DC); break; - case x86_EDI: AddCode16(0x07DC); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuAddReg(x86FpuValues x86reg) -{ - CodeLog(" fadd ST(0), %s", fpu_Name(x86reg)); - switch (x86reg) - { - case x86_ST0: AddCode16(0xC0D8); break; - case x86_ST1: AddCode16(0xC1D8); break; - case x86_ST2: AddCode16(0xC2D8); break; - case x86_ST3: AddCode16(0xC3D8); break; - case x86_ST4: AddCode16(0xC4D8); break; - case x86_ST5: AddCode16(0xC5D8); break; - case x86_ST6: AddCode16(0xC6D8); break; - case x86_ST7: AddCode16(0xC7D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuAddRegPop(int32_t & StackPos, x86FpuValues Reg) -{ - CodeLog(" faddp ST(0), %s", fpu_Name(Reg)); - StackPos = (StackPos + 1) & 7; - switch (Reg) - { - case x86_ST0: AddCode16(0xC0DE); break; - case x86_ST1: AddCode16(0xC1DE); break; - case x86_ST2: AddCode16(0xC2DE); break; - case x86_ST3: AddCode16(0xC3DE); break; - case x86_ST4: AddCode16(0xC4DE); break; - case x86_ST5: AddCode16(0xC5DE); break; - case x86_ST6: AddCode16(0xC6DE); break; - case x86_ST7: AddCode16(0xC7DE); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuComDword(void * Variable, const char * VariableName, bool Pop) -{ - CodeLog(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], VariableName); - AddCode16(Pop ? 0x1DD8 : 0x15D8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuComDwordRegPointer(const asmjit::x86::Gp & x86Pointer, bool Pop) -{ - uint16_t x86Command; - - CodeLog(" fcom%s ST(0), dword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: x86Command = 0x10D8; break; - case x86_EBX: x86Command = 0x13D8; break; - case x86_ECX: x86Command = 0x11D8; break; - case x86_EDX: x86Command = 0x12D8; break; - case x86_ESI: x86Command = 0x16D8; break; - case x86_EDI: x86Command = 0x17D8; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - if (Pop) - { - x86Command |= 0x0800; - } - - AddCode16(x86Command); -} - -void CX86Ops::fpuComQword(void * Variable, const char * VariableName, bool Pop) -{ - CodeLog(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], VariableName); - AddCode16(Pop ? 0x1DDC : 0x15DC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuComQwordRegPointer(const asmjit::x86::Gp & x86Pointer, bool Pop) -{ - uint16_t x86Command; - - CodeLog(" fcom%s ST(0), qword ptr [%s]", m_fpupop[Pop], x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: x86Command = 0x10DC; break; - case x86_EBX: x86Command = 0x13DC; break; - case x86_ECX: x86Command = 0x11DC; break; - case x86_EDX: x86Command = 0x12DC; break; - case x86_ESI: x86Command = 0x16DC; break; - case x86_EDI: x86Command = 0x17DC; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - if (Pop) - { - x86Command |= 0x0800; - } - - AddCode16(x86Command); -} - -void CX86Ops::fpuComReg(x86FpuValues x86reg, bool Pop) -{ - int s = Pop ? 0x0800 : 0x0000; - CodeLog(" fcom%s ST(0), %s", m_fpupop[Pop], fpu_Name(x86reg)); - - switch (x86reg) - { - case x86_ST0: AddCode16((uint16_t)(0xD0D8 | s)); break; - case x86_ST1: AddCode16((uint16_t)(0xD1D8 | s)); break; - case x86_ST2: AddCode16((uint16_t)(0xD2D8 | s)); break; - case x86_ST3: AddCode16((uint16_t)(0xD3D8 | s)); break; - case x86_ST4: AddCode16((uint16_t)(0xD4D8 | s)); break; - case x86_ST5: AddCode16((uint16_t)(0xD5D8 | s)); break; - case x86_ST6: AddCode16((uint16_t)(0xD6D8 | s)); break; - case x86_ST7: AddCode16((uint16_t)(0xD7D8 | s)); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuDivDword(void * Variable, const char * VariableName) -{ - CodeLog(" fdiv ST(0), dword ptr [%s]", VariableName); - AddCode16(0x35D8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuDivDwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fdiv ST(0), dword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x30D8); break; - case x86_EBX: AddCode16(0x33D8); break; - case x86_ECX: AddCode16(0x31D8); break; - case x86_EDX: AddCode16(0x32D8); break; - case x86_ESI: AddCode16(0x36D8); break; - case x86_EDI: AddCode16(0x37D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuDivQword(void * Variable, const char * VariableName) -{ - CodeLog(" fdiv ST(0), qword ptr [%s]", VariableName); - AddCode16(0x35DC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuDivQwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fdiv ST(0), qword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x30DC); break; - case x86_EBX: AddCode16(0x33DC); break; - case x86_ECX: AddCode16(0x31DC); break; - case x86_EDX: AddCode16(0x32DC); break; - case x86_ESI: AddCode16(0x36DC); break; - case x86_EDI: AddCode16(0x37DC); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuDivReg(x86FpuValues Reg) -{ - CodeLog(" fdiv ST(0), %s", fpu_Name(Reg)); - switch (Reg) - { - case x86_ST0: AddCode16(0xF0D8); break; - case x86_ST1: AddCode16(0xF1D8); break; - case x86_ST2: AddCode16(0xF2D8); break; - case x86_ST3: AddCode16(0xF3D8); break; - case x86_ST4: AddCode16(0xF4D8); break; - case x86_ST5: AddCode16(0xF5D8); break; - case x86_ST6: AddCode16(0xF6D8); break; - case x86_ST7: AddCode16(0xF7D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuDivRegPop(x86FpuValues Reg) -{ - CodeLog(" fdivp ST(0), %s", fpu_Name(Reg)); - switch (Reg) - { - case x86_ST0: AddCode16(0xF8DE); break; - case x86_ST1: AddCode16(0xF9DE); break; - case x86_ST2: AddCode16(0xFADE); break; - case x86_ST3: AddCode16(0xFBDE); break; - case x86_ST4: AddCode16(0xFCDE); break; - case x86_ST5: AddCode16(0xFDDE); break; - case x86_ST6: AddCode16(0xFEDE); break; - case x86_ST7: AddCode16(0xFFDE); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuExchange(x86FpuValues Reg) -{ - CodeLog(" fxch ST(0), %s", fpu_Name(Reg)); - switch (Reg) - { - case x86_ST0: AddCode16(0xC8D9); break; - case x86_ST1: AddCode16(0xC9D9); break; - case x86_ST2: AddCode16(0xCAD9); break; - case x86_ST3: AddCode16(0xCBD9); break; - case x86_ST4: AddCode16(0xCCD9); break; - case x86_ST5: AddCode16(0xCDD9); break; - case x86_ST6: AddCode16(0xCED9); break; - case x86_ST7: AddCode16(0xCFD9); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuFree(x86FpuValues Reg) -{ - CodeLog(" ffree %s", fpu_Name(Reg)); - switch (Reg) - { - case x86_ST0: AddCode16(0xC0DD); break; - case x86_ST1: AddCode16(0xC1DD); break; - case x86_ST2: AddCode16(0xC2DD); break; - case x86_ST3: AddCode16(0xC3DD); break; - case x86_ST4: AddCode16(0xC4DD); break; - case x86_ST5: AddCode16(0xC5DD); break; - case x86_ST6: AddCode16(0xC6DD); break; - case x86_ST7: AddCode16(0xC7DD); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuDecStack(int32_t & StackPos) -{ - CodeLog(" fdecstp"); - StackPos = (StackPos - 1) & 7; - AddCode16(0xF6D9); -} - void CX86Ops::fpuIncStack(int32_t & StackPos) { - CodeLog(" fincstp"); StackPos = (StackPos + 1) & 7; - AddCode16(0xF7D9); + fincstp(); } void CX86Ops::fpuLoadControl(void * Variable, const char * VariableName) { - CodeLog(" fldcw [%s]", VariableName); - AddCode16(0x2DD9); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuLoadDword(int32_t & StackPos, void * Variable, const char * VariableName) -{ - CodeLog(" fld dword ptr [%s]", VariableName); - StackPos = (StackPos - 1) & 7; - AddCode16(0x05D9); - AddCode32((uint32_t)Variable); + if (CDebugSettings::bRecordRecompilerAsm()) + { + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + fldcw(asmjit::x86::ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + fldcw(asmjit::x86::ptr((uint64_t)Variable)); + } } void CX86Ops::fpuLoadDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg) { - CodeLog(" fld dword ptr [%s]", x86_Name(x86reg)); + fld(asmjit::x86::dword_ptr(x86reg)); StackPos = (StackPos - 1) & 7; - AddCode8(0xD9); - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode8(0x00); break; - case x86_EBX: AddCode8(0x03); break; - case x86_ECX: AddCode8(0x01); break; - case x86_EDX: AddCode8(0x02); break; - case x86_ESI: AddCode8(0x06); break; - case x86_EDI: AddCode8(0x07); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::fpuLoadDwordFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & x86reg) -{ - CodeLog(" fld dword ptr [%s+N64mem]", x86_Name(x86reg)); - StackPos = (StackPos - 1) & 7; - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode16(0x80D9); break; - case x86_EBX: AddCode16(0x83D9); break; - case x86_ECX: AddCode16(0x81D9); break; - case x86_EDX: AddCode16(0x82D9); break; - case x86_ESI: AddCode16(0x86D9); break; - case x86_EDI: AddCode16(0x87D9); break; - case x86_EBP: AddCode16(0x85D9); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32((uint32_t)g_MMU->Rdram()); -} - -void CX86Ops::fpuLoadInt32bFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & x86reg) -{ - CodeLog(" fild dword ptr [%s+N64mem]", x86_Name(x86reg)); - StackPos = (StackPos - 1) & 7; - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode16(0x80DB); break; - case x86_EBX: AddCode16(0x83DB); break; - case x86_ECX: AddCode16(0x81DB); break; - case x86_EDX: AddCode16(0x82DB); break; - case x86_ESI: AddCode16(0x86DB); break; - case x86_EDI: AddCode16(0x87DB); break; - case x86_EBP: AddCode16(0x85DB); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32((uint32_t)g_MMU->Rdram()); -} - -void CX86Ops::fpuLoadIntegerDword(int32_t & StackPos, void * Variable, const char * VariableName) -{ - CodeLog(" fild dword ptr [%s]", VariableName); - StackPos = (StackPos - 1) & 7; - AddCode16(0x05DB); - AddCode32((uint32_t)Variable); } void CX86Ops::fpuLoadIntegerDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg) { - CodeLog(" fild dword ptr [%s]", x86_Name(x86reg)); + fild(asmjit::x86::dword_ptr(x86reg)); StackPos = (StackPos - 1) & 7; - AddCode8(0xDB); - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode8(0x00); break; - case x86_EBX: AddCode8(0x03); break; - case x86_ECX: AddCode8(0x01); break; - case x86_EDX: AddCode8(0x02); break; - case x86_ESI: AddCode8(0x06); break; - case x86_EDI: AddCode8(0x07); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::fpuLoadIntegerQword(int32_t & StackPos, void * Variable, const char * VariableName) -{ - CodeLog(" fild qword ptr [%s]", VariableName); - StackPos = (StackPos - 1) & 7; - AddCode16(0x2DDF); - AddCode32((uint32_t)Variable); } void CX86Ops::fpuLoadIntegerQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg) { - CodeLog(" fild qword ptr [%s]", x86_Name(x86reg)); + fild(asmjit::x86::qword_ptr(x86reg)); StackPos = (StackPos - 1) & 7; - AddCode8(0xDF); - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode8(0x28); break; - case x86_EBX: AddCode8(0x2B); break; - case x86_ECX: AddCode8(0x29); break; - case x86_EDX: AddCode8(0x2A); break; - case x86_ESI: AddCode8(0x2E); break; - case x86_EDI: AddCode8(0x2F); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } } -void CX86Ops::fpuLoadQword(int32_t & StackPos, void * Variable, const char * VariableName) +void CX86Ops::fpuLoadQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg) { - CodeLog(" fld qword ptr [%s]", VariableName); StackPos = (StackPos - 1) & 7; - AddCode16(0x05DD); - AddCode32((uint32_t)Variable); + fld(asmjit::x86::qword_ptr(Reg)); } -void CX86Ops::fpuLoadQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg) +void CX86Ops::fpuLoadReg(int32_t & StackPos, const asmjit::x86::St & Reg) { - CodeLog(" fld qword ptr [%s]", x86_Name(x86reg)); StackPos = (StackPos - 1) & 7; - AddCode8(0xDD); - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode8(0x00); break; - case x86_EBX: AddCode8(0x03); break; - case x86_ECX: AddCode8(0x01); break; - case x86_EDX: AddCode8(0x02); break; - case x86_ESI: AddCode8(0x06); break; - case x86_EDI: AddCode8(0x07); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::fpuLoadQwordFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & x86reg) -{ - CodeLog(" fld qword ptr [%s+N64mem]", x86_Name(x86reg)); - StackPos = (StackPos - 1) & 7; - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode16(0x80DD); break; - case x86_EBX: AddCode16(0x83DD); break; - case x86_ECX: AddCode16(0x81DD); break; - case x86_EDX: AddCode16(0x82DD); break; - case x86_ESI: AddCode16(0x86DD); break; - case x86_EDI: AddCode16(0x87DD); break; - case x86_EBP: AddCode16(0x85DD); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - AddCode32((uint32_t)g_MMU->Rdram()); -} - -void CX86Ops::fpuLoadReg(int32_t & StackPos, x86FpuValues Reg) -{ - CodeLog(" fld ST(0), %s", fpu_Name(Reg)); - StackPos = (StackPos - 1) & 7; - switch (Reg) - { - case x86_ST0: AddCode16(0xC0D9); break; - case x86_ST1: AddCode16(0xC1D9); break; - case x86_ST2: AddCode16(0xC2D9); break; - case x86_ST3: AddCode16(0xC3D9); break; - case x86_ST4: AddCode16(0xC4D9); break; - case x86_ST5: AddCode16(0xC5D9); break; - case x86_ST6: AddCode16(0xC6D9); break; - case x86_ST7: AddCode16(0xC7D9); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuMulDword(void * Variable, const char * VariableName) -{ - CodeLog(" fmul ST(0), dword ptr [%s]", VariableName); - AddCode16(0x0DD8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuMulDwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fmul ST(0), dword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x08D8); break; - case x86_EBX: AddCode16(0x0BD8); break; - case x86_ECX: AddCode16(0x09D8); break; - case x86_EDX: AddCode16(0x0AD8); break; - case x86_ESI: AddCode16(0x0ED8); break; - case x86_EDI: AddCode16(0x0FD8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuMulQword(void * Variable, const char * VariableName) -{ - CodeLog(" fmul ST(0), qword ptr [%s]", VariableName); - AddCode16(0x0DDC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuMulQwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fmul ST(0), qword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x08DC); break; - case x86_EBX: AddCode16(0x0BDC); break; - case x86_ECX: AddCode16(0x09DC); break; - case x86_EDX: AddCode16(0x0ADC); break; - case x86_ESI: AddCode16(0x0EDC); break; - case x86_EDI: AddCode16(0x0FDC); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuMulReg(x86FpuValues x86reg) -{ - CodeLog(" fmul ST(0), %s", fpu_Name(x86reg)); - switch (x86reg) - { - case x86_ST0: AddCode16(0xC8D8); break; - case x86_ST1: AddCode16(0xC9D8); break; - case x86_ST2: AddCode16(0xCAD8); break; - case x86_ST3: AddCode16(0xCBD8); break; - case x86_ST4: AddCode16(0xCCD8); break; - case x86_ST5: AddCode16(0xCDD8); break; - case x86_ST6: AddCode16(0xCED8); break; - case x86_ST7: AddCode16(0xCFD8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuMulRegPop(x86FpuValues x86reg) -{ - CodeLog(" fmulp ST(0), %s", fpu_Name(x86reg)); - switch (x86reg) - { - case x86_ST0: AddCode16(0xC8DE); break; - case x86_ST1: AddCode16(0xC9DE); break; - case x86_ST2: AddCode16(0xCADE); break; - case x86_ST3: AddCode16(0xCBDE); break; - case x86_ST4: AddCode16(0xCCDE); break; - case x86_ST5: AddCode16(0xCDDE); break; - case x86_ST6: AddCode16(0xCEDE); break; - case x86_ST7: AddCode16(0xCFDE); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuNeg(void) -{ - CodeLog(" fchs ST(0)"); - AddCode16(0xE0D9); -} - -void CX86Ops::fpuRound(void) -{ - CodeLog(" frndint ST(0)"); - AddCode16(0xFCD9); -} - -void CX86Ops::fpuSqrt(void) -{ - CodeLog(" fsqrt ST(0)"); - AddCode16(0xFAD9); + fld(Reg); } void CX86Ops::fpuStoreControl(void * Variable, const char * VariableName) { - CodeLog(" fnstcw [%s]", VariableName); - AddCode16(0x3DD9); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuStoreDword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop) -{ - CodeLog(" fst%s dword ptr [%s]", m_fpupop[pop], VariableName); - - if (pop) + if (CDebugSettings::bRecordRecompilerAsm()) { - StackPos = (StackPos + 1) & 7; + std::string SymbolKey = VariableSymbol(Variable); + AddSymbol(SymbolKey.c_str(), VariableName); + fnstcw(asmjit::x86::ptr((uint64_t)Variable)); + RemoveSymbol(SymbolKey.c_str()); + } + else + { + fnstcw(asmjit::x86::ptr((uint64_t)Variable)); } - - AddCode16(pop ? 0x1DD9 : 0x15D9); - AddCode32((uint32_t)Variable); } void CX86Ops::fpuStoreDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop) { - uint8_t Command = 0; - - CodeLog(" fst%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); - if (pop) { + fstp(asmjit::x86::dword_ptr(x86reg)); StackPos = (StackPos + 1) & 7; } - - AddCode8(0xD9); - - switch (RegValue(x86reg)) + else { - case x86_EAX: Command = 0x10; break; - case x86_EBX: Command = 0x13; break; - case x86_ECX: Command = 0x11; break; - case x86_EDX: Command = 0x12; break; - case x86_ESI: Command = 0x16; break; - case x86_EDI: Command = 0x17; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + fst(asmjit::x86::dword_ptr(x86reg)); } - - AddCode8(pop ? (Command + 0x8) : Command); -} - -void CX86Ops::fpuStoreDwordToN64Mem(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool Pop) -{ - int s = Pop ? 0x0800 : 0; - - CodeLog(" fst%s dword ptr [%s+N64mem]", m_fpupop[Pop], x86_Name(x86reg)); - - if (Pop) - { - StackPos = (StackPos + 1) & 7; - } - - switch (RegValue(x86reg)) - { - case x86_EAX: AddCode16((uint16_t)(0x90D9 | s)); break; - case x86_EBX: AddCode16((uint16_t)(0x93D9 | s)); break; - case x86_ECX: AddCode16((uint16_t)(0x91D9 | s)); break; - case x86_EDX: AddCode16((uint16_t)(0x92D9 | s)); break; - case x86_ESI: AddCode16((uint16_t)(0x96D9 | s)); break; - case x86_EDI: AddCode16((uint16_t)(0x97D9 | s)); break; - case x86_EBP: AddCode16((uint16_t)(0x95D9 | s)); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode32((uint32_t)g_MMU->Rdram()); -} - -void CX86Ops::fpuStoreIntegerDword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop) -{ - CodeLog(" fist%s dword ptr [%s]", m_fpupop[pop], VariableName); - - if (pop) - { - StackPos = (StackPos + 1) & 7; - } - AddCode16(pop ? 0x1DDB : 0x15DB); - AddCode32((uint32_t)Variable); } void CX86Ops::fpuStoreIntegerDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop) { - uint8_t Command = 0; - - CodeLog(" fist%s dword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); + if (pop) + { + fistp(asmjit::x86::dword_ptr(x86reg)); + StackPos = (StackPos + 1) & 7; + } + else + { + fist(asmjit::x86::dword_ptr(x86reg)); + } +} +void CX86Ops::fpuStoreIntegerQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop) +{ if (pop) { StackPos = (StackPos + 1) & 7; + fistp(asmjit::x86::qword_ptr(Reg)); } - - AddCode8(0xDB); - - switch (RegValue(x86reg)) + else { - case x86_EAX: Command = 0x10; break; - case x86_EBX: Command = 0x13; break; - case x86_ECX: Command = 0x11; break; - case x86_EDX: Command = 0x12; break; - case x86_ESI: Command = 0x16; break; - case x86_EDI: Command = 0x17; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + fist(asmjit::x86::qword_ptr(Reg)); } - - AddCode8(pop ? (Command + 0x8) : Command); } -void CX86Ops::fpuStoreIntegerQword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop) +void CX86Ops::fpuStoreQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop) { - CodeLog(" fist%s qword ptr [%s]", m_fpupop[pop], VariableName); - if (pop) { + fstp(asmjit::x86::qword_ptr(Reg)); StackPos = (StackPos + 1) & 7; } - - AddCode16(pop ? 0x3DDF : 0x35DF); - AddCode32((uint32_t)Variable); - - if (!pop) + else { - X86BreakPoint(__FILE__, __LINE__); - } -} - -void CX86Ops::fpuStoreIntegerQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop) -{ - uint8_t Command = 0; - - CodeLog(" fist%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); - - if (pop) - { - StackPos = (StackPos + 1) & 7; - } - - AddCode8(0xDF); - - switch (RegValue(x86reg)) - { - case x86_EAX: Command = 0x30; break; - case x86_EBX: Command = 0x33; break; - case x86_ECX: Command = 0x31; break; - case x86_EDX: Command = 0x32; break; - case x86_ESI: Command = 0x36; break; - case x86_EDI: Command = 0x37; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(pop ? (Command + 0x8) : Command); -} - -void CX86Ops::fpuStoreQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & x86reg, bool pop) -{ - uint8_t Command = 0; - - CodeLog(" fst%s qword ptr [%s]", m_fpupop[pop], x86_Name(x86reg)); - - if (pop) - { - StackPos = (StackPos + 1) & 7; - } - - AddCode8(0xDD); - - switch (RegValue(x86reg)) - { - case x86_EAX: Command = 0x10; break; - case x86_EBX: Command = 0x13; break; - case x86_ECX: Command = 0x11; break; - case x86_EDX: Command = 0x12; break; - case x86_ESI: Command = 0x16; break; - case x86_EDI: Command = 0x17; break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - } - - AddCode8(pop ? (Command + 0x8) : Command); -} - -void CX86Ops::fpuStoreStatus(void) -{ - CodeLog(" fnstsw ax"); - AddCode16(0xE0DF); -} - -void CX86Ops::fpuSubDword(void * Variable, const char * VariableName) -{ - CodeLog(" fsub ST(0), dword ptr [%s]", VariableName); - AddCode16(0x25D8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuSubDwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fsub ST(0), dword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x20D8); break; - case x86_EBX: AddCode16(0x23D8); break; - case x86_ECX: AddCode16(0x21D8); break; - case x86_EDX: AddCode16(0x22D8); break; - case x86_ESI: AddCode16(0x26D8); break; - case x86_EDI: AddCode16(0x27D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuSubDwordReverse(void * Variable, const char * VariableName) -{ - CodeLog(" fsubr ST(0), dword ptr [%s]", VariableName); - AddCode16(0x2DD8); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuSubQword(void * Variable, const char * VariableName) -{ - CodeLog(" fsub ST(0), qword ptr [%s]", VariableName); - AddCode16(0x25DC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuSubQwordRegPointer(const asmjit::x86::Gp & x86Pointer) -{ - CodeLog(" fsub ST(0), qword ptr [%s]", x86_Name(x86Pointer)); - switch (RegValue(x86Pointer)) - { - case x86_EAX: AddCode16(0x20DC); break; - case x86_EBX: AddCode16(0x23DC); break; - case x86_ECX: AddCode16(0x21DC); break; - case x86_EDX: AddCode16(0x22DC); break; - case x86_ESI: AddCode16(0x26DC); break; - case x86_EDI: AddCode16(0x27DC); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuSubQwordReverse(void * Variable, const char * VariableName) -{ - CodeLog(" fsubr ST(0), qword ptr [%s]", VariableName); - AddCode16(0x2DDC); - AddCode32((uint32_t)Variable); -} - -void CX86Ops::fpuSubReg(x86FpuValues x86reg) -{ - CodeLog(" fsub ST(0), %s", fpu_Name(x86reg)); - switch (x86reg) - { - case x86_ST0: AddCode16(0xE0D8); break; - case x86_ST1: AddCode16(0xE1D8); break; - case x86_ST2: AddCode16(0xE2D8); break; - case x86_ST3: AddCode16(0xE3D8); break; - case x86_ST4: AddCode16(0xE4D8); break; - case x86_ST5: AddCode16(0xE5D8); break; - case x86_ST6: AddCode16(0xE6D8); break; - case x86_ST7: AddCode16(0xE7D8); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; - } -} - -void CX86Ops::fpuSubRegPop(x86FpuValues x86reg) -{ - CodeLog(" fsubp ST(0), %s", fpu_Name(x86reg)); - switch (x86reg) - { - case x86_ST0: AddCode16(0xE8DE); break; - case x86_ST1: AddCode16(0xE9DE); break; - case x86_ST2: AddCode16(0xEADE); break; - case x86_ST3: AddCode16(0xEBDE); break; - case x86_ST4: AddCode16(0xECDE); break; - case x86_ST5: AddCode16(0xEDDE); break; - case x86_ST6: AddCode16(0xEEDE); break; - case x86_ST7: AddCode16(0xEFDE); break; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); - break; + fst(asmjit::x86::qword_ptr(Reg)); } } const char * CX86Ops::x86_Name(const asmjit::x86::Gp & Reg) { - switch (RegValue(Reg)) + if (Reg == asmjit::x86::eax) { - case x86_EAX: return "eax"; - case x86_EBX: return "ebx"; - case x86_ECX: return "ecx"; - case x86_EDX: return "edx"; - case x86_ESI: return "esi"; - case x86_EDI: return "edi"; - case x86_EBP: return "ebp"; - case x86_ESP: return "esp"; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + return "eax"; } - return "???"; -} - -const char * CX86Ops::x86_ByteName(const asmjit::x86::Gp & Reg) -{ - switch (RegValue(Reg)) + if (Reg == asmjit::x86::ebx) { - case x86_AL: return "al"; - case x86_BL: return "bl"; - case x86_CL: return "cl"; - case x86_DL: return "dl"; - case x86_AH: return "ah"; - case x86_BH: return "bh"; - case x86_CH: return "ch"; - case x86_DH: return "dh"; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + return "ebx"; } - return "???"; -} - -const char * CX86Ops::x86_HalfName(const asmjit::x86::Gp & Reg) -{ - switch (RegValue(Reg)) + if (Reg == asmjit::x86::ecx) { - case x86_EAX: return "ax"; - case x86_EBX: return "bx"; - case x86_ECX: return "cx"; - case x86_EDX: return "dx"; - case x86_ESI: return "si"; - case x86_EDI: return "di"; - case x86_EBP: return "bp"; - case x86_ESP: return "sp"; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + return "ecx"; } - return "???"; -} - -const char * CX86Ops::fpu_Name(x86FpuValues Reg) -{ - switch (Reg) + if (Reg == asmjit::x86::edx) { - case x86_ST0: return "ST(0)"; - case x86_ST1: return "ST(1)"; - case x86_ST2: return "ST(2)"; - case x86_ST3: return "ST(3)"; - case x86_ST4: return "ST(4)"; - case x86_ST5: return "ST(5)"; - case x86_ST6: return "ST(6)"; - case x86_ST7: return "ST(7)"; - default: - g_Notify->BreakPoint(__FILE__, __LINE__); + return "edx"; } + if (Reg == asmjit::x86::esi) + { + return "esi"; + } + if (Reg == asmjit::x86::edi) + { + return "edi"; + } + if (Reg == asmjit::x86::ebp) + { + return "ebp"; + } + if (Reg == asmjit::x86::esp) + { + return "esp"; + } + g_Notify->BreakPoint(__FILE__, __LINE__); return "???"; } @@ -3730,37 +867,6 @@ bool CX86Ops::Is8BitReg(const asmjit::x86::Gp & Reg) (Reg == asmjit::x86::edx); } -uint8_t CX86Ops::CalcMultiplyCode(Multipler Multiply) -{ - switch (Multiply) - { - case Multip_x2: return 0x40; - case Multip_x4: return 0x80; - case Multip_x8: return 0xC0; - default: return 0; - } -} - -void CX86Ops::SetJump32(uint32_t * Loc, uint32_t * JumpLoc) -{ - *Loc = (uint32_t)(((uint32_t)JumpLoc) - (((uint32_t)(Loc)) + 4)); -} - -void CX86Ops::SetJump8(uint8_t * Loc, uint8_t * JumpLoc) -{ - if (Loc == nullptr || JumpLoc == nullptr) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - return; - } - uint32_t diffrence = (uint32_t)(((uint32_t)JumpLoc) - (((uint32_t)(Loc)) + 1)); - if (diffrence > 255) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } - *Loc = (uint8_t)diffrence; -} - uint32_t CX86Ops::GetAddressOf(int value, ...) { void * Address; @@ -3773,42 +879,6 @@ uint32_t CX86Ops::GetAddressOf(int value, ...) return (uint32_t)Address; } -void CX86Ops::AddCode8(uint8_t value) -{ -#ifdef _DEBUG - if (g_RecompPos == nullptr) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } -#endif - (*((uint8_t *)(*g_RecompPos)) = (uint8_t)(value)); - *g_RecompPos += 1; -} - -void CX86Ops::AddCode16(uint16_t value) -{ -#ifdef _DEBUG - if (g_RecompPos == nullptr) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } -#endif - (*((uint16_t *)(*g_RecompPos)) = (uint16_t)(value)); - *g_RecompPos += 2; -} - -void CX86Ops::AddCode32(uint32_t value) -{ -#ifdef _DEBUG - if (g_RecompPos == nullptr) - { - g_Notify->BreakPoint(__FILE__, __LINE__); - } -#endif - (*((uint32_t *)(*g_RecompPos)) = (uint32_t)(value)); - *g_RecompPos += 4; -} - CX86Ops::x86Reg CX86Ops::RegValue(const asmjit::x86::Gp & Reg) { if (Reg == asmjit::x86::eax) @@ -3879,27 +949,39 @@ CX86Ops::x86Reg CX86Ops::RegValue(const asmjit::x86::Gp & Reg) return x86_EAX; } -void CX86Ops::CodeLog(_Printf_format_string_ const char * Text, ...) +asmjit::Error CX86Ops::_log(const char* data, size_t size) noexcept { - if (!CDebugSettings::bRecordRecompilerAsm()) + stdstr AsmjitLog(std::string(data, size)); + AsmjitLog.Trim("\n"); + for (SymbolMap::const_iterator itr = m_Symbols.begin(); itr != m_Symbols.end(); itr++) { - return; + AsmjitLog.Replace(itr->first, itr->second); } + m_CodeBlock.Log(" %s", AsmjitLog.c_str()); + return asmjit::kErrorOk; +} - va_list args; - va_start(args, Text); -#pragma warning(push) -#pragma warning(disable : 4996) - size_t nlen = _vscprintf(Text, args) + 1; - char * buffer = (char *)alloca(nlen * sizeof(char)); - buffer[nlen - 1] = 0; - if (buffer != nullptr) +void CX86Ops::AddSymbol(const char * SymbolKey, const char * SymbolValue) +{ + m_Symbols.emplace(std::make_pair(SymbolKey, SymbolValue)); +} + +void CX86Ops::RemoveSymbol(const char * SymbolKey) +{ + SymbolMap::iterator itr = m_Symbols.find(SymbolKey); + if (itr != m_Symbols.end()) { - vsprintf(buffer, Text, args); - m_CodeBlock.Log(buffer); + m_Symbols.erase(itr); } -#pragma warning(pop) - va_end(args); +} + +std::string CX86Ops::VariableSymbol(void * Variable) const +{ + if (int64_t(Variable) < 0) + { + return stdstr_f("-0x%0X", (uint32_t)(~(int64_t(Variable)) + 1)); + } + return stdstr_f("0x%X", (uint32_t)Variable); } #endif diff --git a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h index 7d4505331..307497231 100644 --- a/Source/Project64-core/N64System/Recompiler/x86/x86ops.h +++ b/Source/Project64-core/N64System/Recompiler/x86/x86ops.h @@ -1,6 +1,8 @@ #pragma once #if defined(__i386__) || defined(_M_IX86) #include +#include +#include #if !defined(_MSC_VER) && !defined(_Printf_format_string_) #define _Printf_format_string_ @@ -10,21 +12,11 @@ class CCodeBlock; static constexpr asmjit::x86::Gp x86Reg_Unknown = asmjit::x86::Gp(); -class CX86Ops +class CX86Ops : + public asmjit::x86::Assembler, + public asmjit::Logger { public: - enum x86FpuValues - { - x86_ST_Unknown = -1, - x86_ST0 = 0, - x86_ST1 = 1, - x86_ST2 = 2, - x86_ST3 = 3, - x86_ST4 = 4, - x86_ST5 = 5, - x86_ST6 = 6, - x86_ST7 = 7 - }; enum Multipler { @@ -35,231 +27,82 @@ public: }; static const char * x86_Name(const asmjit::x86::Gp & Reg); - static const char * x86_ByteName(const asmjit::x86::Gp & Reg); - static const char * x86_HalfName(const asmjit::x86::Gp & Reg); - static const char * fpu_Name(x86FpuValues Reg); CX86Ops(CCodeBlock & CodeBlock); - // Logging functions - void WriteX86Comment(const char * Comment); - void WriteX86Label(const char * Label); - - void AdcConstToVariable(void * Variable, const char * VariableName, uint8_t Constant); - void AdcConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void AdcVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void AdcX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); void AddConstToVariable(void * Variable, const char * VariableName, uint32_t Const); - void AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const, bool NeedCarry = false); + void AddConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void AddVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void AddX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg); - void AddX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); void AndConstToVariable(void * Variable, const char * VariableName, uint32_t Const); - void AndConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void AndVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void AndVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiply); - void AndX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); void X86HardBreakPoint(); void X86BreakPoint(const char * FileName, int32_t LineNumber); void CallFunc(uint32_t FunctPtr, const char * FunctName); void CallThis(uint32_t ThisPtr, uint32_t FunctPtr, char * FunctName, uint32_t StackSize); void CompConstToVariable(void * Variable, const char * VariableName, uint32_t Const); void CompConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const); - void CompConstToX86regPointer(const asmjit::x86::Gp & Reg, uint32_t Const); void CompX86regToVariable(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void CompX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void DecX86reg(const asmjit::x86::Gp & Reg); - void DivX86reg(const asmjit::x86::Gp & Reg); - void idivX86reg(const asmjit::x86::Gp & Reg); - void imulX86reg(const asmjit::x86::Gp & Reg); - void IncX86reg(const asmjit::x86::Gp & Reg); - void JaeLabel8(const char * Label, uint8_t Value); - void JaeLabel32(const char * Label, uint32_t Value); - void JaLabel8(const char * Label, uint8_t Value); - void JaLabel32(const char * Label, uint32_t Value); - void JbLabel8(const char * Label, uint8_t Value); - void JbLabel32(const char * Label, uint32_t Value); - void JecxzLabel8(const char * Label, uint8_t Value); - void JeLabel8(const char * Label, uint8_t Value); - void JeLabel32(const char * Label, uint32_t Value); - void JgeLabel8(const char * Label, uint8_t Value); - void JgeLabel32(const char * Label, uint32_t Value); - void JgLabel8(const char * Label, uint8_t Value); - void JgLabel32(const char * Label, uint32_t Value); - void JleLabel8(const char * Label, uint8_t Value); - void JleLabel32(const char * Label, uint32_t Value); - void JlLabel8(const char * Label, uint8_t Value); - void JlLabel32(const char * Label, uint32_t Value); - void JmpDirectReg(const asmjit::x86::Gp & Reg); - void JmpIndirectLabel32(const char * Label, uint32_t location); - void JmpIndirectReg(const asmjit::x86::Gp & Reg); - void JmpLabel8(const char * Label, uint8_t Value); - void JmpLabel32(const char * Label, uint32_t Value); - void JneLabel8(const char * Label, uint8_t Value); - void JneLabel32(const char * Label, uint32_t Value); - void JnsLabel8(const char * Label, uint8_t Value); - void JnsLabel32(const char * Label, uint32_t Value); - void JnzLabel8(const char * Label, uint8_t Value); - void JnzLabel32(const char * Label, uint32_t Value); - void JoLabel32(const char * Label, uint32_t Value); - void JsLabel32(const char * Label, uint32_t Value); - void JzLabel8(const char * Label, uint8_t Value); - void JzLabel32(const char * Label, uint32_t Value); - void LeaRegReg(const asmjit::x86::Gp & RegDest, const asmjit::x86::Gp & RegSrc, uint32_t Const, Multipler multiplier); - void LeaRegReg2(const asmjit::x86::Gp & RegDest, const asmjit::x86::Gp & RegSrc, const asmjit::x86::Gp & RegSrc2, Multipler multiplier); - void LeaSourceAndOffset(const asmjit::x86::Gp & x86DestReg, const asmjit::x86::Gp & x86SourceReg, int32_t offset); + void JaeLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JaLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JbLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JecxzLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JeLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JgeLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JgLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JleLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JlLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JmpLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JneLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JnsLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JnzLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JoLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JsLabel(const char * LabelName, asmjit::Label & JumpLabel); + void JzLabel(const char * LabelName, asmjit::Label & JumpLabel); void MoveConstByteToVariable(void * Variable, const char * VariableName, uint8_t Const); - void MoveConstByteToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint8_t Const); void MoveConstHalfToVariable(void * Variable, const char * VariableName, uint16_t Const); - void MoveConstHalfToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint16_t Const); - void MoveConstToMemoryDisp(const asmjit::x86::Gp & AddrReg, uint32_t Disp, uint32_t Const); void MoveConstToVariable(void * Variable, const char * VariableName, uint32_t Const); - void MoveConstToX86Pointer(const asmjit::x86::Gp & X86Pointer, uint32_t Const); void MoveConstToX86reg(const asmjit::x86::Gp & Reg, uint32_t Const); - void MoveConstToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint32_t Const); - void MoveSxByteX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2); - void MoveSxHalfX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2); void MoveSxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void MoveSxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void MoveVariableDispToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName, const asmjit::x86::Gp & AddrReg, Multipler Multiplier); void MoveVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void MoveX86PointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & X86Pointer); - void MoveX86PointerToX86regDisp(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & X86Pointer, uint8_t Disp); void MoveX86regByteToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg); - void MoveX86regByteToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg); void MoveX86regHalfToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg); - void MoveX86regHalfToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg); - void MoveX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2); - void MoveX86regPointerToX86regDisp8(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, uint8_t offset); - void MoveX86regToMemory(const asmjit::x86::Gp & AddrReg, uint32_t Disp, const asmjit::x86::Gp & Reg); void MoveX86regToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg); - void MoveX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void MoveX86regToX86Pointer(const asmjit::x86::Gp & X86Pointer, const asmjit::x86::Gp & Reg); - void MoveX86regToX86regPointer(const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2, const asmjit::x86::Gp & Reg); - void MoveZxByteX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2); - void MoveZxHalfX86regPointerToX86reg(const asmjit::x86::Gp & Reg, const asmjit::x86::Gp & AddrReg1, const asmjit::x86::Gp & AddrReg2); void MoveZxVariableToX86regByte(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void MoveZxVariableToX86regHalf(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void MulX86reg(const asmjit::x86::Gp & Reg); - void NotX86Reg(const asmjit::x86::Gp & Reg); void OrConstToVariable(void * Variable, const char * VariableName, uint32_t Const); - void OrConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void OrVariableToX86Reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); void OrX86RegToVariable(void * Variable, const char * VariableName, const asmjit::x86::Gp & Reg); - void OrX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void Push(const asmjit::x86::Gp & Reg); - void Pushad(); - void PushImm32(uint32_t Value); void PushImm32(const char * String, uint32_t Value); - void Pop(const asmjit::x86::Gp & Reg); - void Popad(); - void Ret(); - void Seta(const asmjit::x86::Gp & Reg); - void Setae(const asmjit::x86::Gp & Reg); void SetaVariable(void * Variable, const char * VariableName); - void Setb(const asmjit::x86::Gp & Reg); void SetbVariable(void * Variable, const char * VariableName); - void Setg(const asmjit::x86::Gp & Reg); void SetgVariable(void * Variable, const char * VariableName); - void Setl(const asmjit::x86::Gp & Reg); void SetlVariable(void * Variable, const char * VariableName); - void Setz(const asmjit::x86::Gp & Reg); - void Setnz(const asmjit::x86::Gp & Reg); - void ShiftLeftDouble(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void ShiftLeftDoubleImmed(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source, uint8_t Immediate); - void ShiftLeftSign(const asmjit::x86::Gp & Reg); - void ShiftLeftSignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate); - void ShiftRightDouble(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void ShiftRightDoubleImmed(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source, uint8_t Immediate); - void ShiftRightSign(const asmjit::x86::Gp & Reg); - void ShiftRightSignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate); - void ShiftRightUnsign(const asmjit::x86::Gp & Reg); - void ShiftRightUnsignImmed(const asmjit::x86::Gp & Reg, uint8_t Immediate); - void SbbConstFromX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void SbbVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void SbbX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); void SubConstFromVariable(uint32_t Const, void * Variable, const char * VariableName); - void SubConstFromX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void SubVariableFromX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void SubX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void TestConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); void TestVariable(void * Variable, const char * VariableName, uint32_t Const); - void TestX86RegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void TestX86ByteRegToX86Reg(const asmjit::x86::Gp & Destination, const asmjit::x86::Gp & Source); - void XorConstToX86Reg(const asmjit::x86::Gp & Reg, uint32_t Const); - void XorX86RegToX86Reg(const asmjit::x86::Gp & Source, const asmjit::x86::Gp & Destination); void XorVariableToX86reg(const asmjit::x86::Gp & Reg, void * Variable, const char * VariableName); - void fpuAbs(); - void fpuAddDword(void * Variable, const char * VariableName); - void fpuAddDwordRegPointer(const asmjit::x86::Gp & x86Pointer); - void fpuAddQword(void * Variable, const char * VariableName); - void fpuAddQwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuAddReg(x86FpuValues Reg); - void fpuAddRegPop(int32_t & StackPos, x86FpuValues Reg); - void fpuComDword(void * Variable, const char * VariableName, bool Pop); - void fpuComDwordRegPointer(const asmjit::x86::Gp & X86Pointer, bool Pop); - void fpuComQword(void * Variable, const char * VariableName, bool Pop); - void fpuComQwordRegPointer(const asmjit::x86::Gp & X86Pointer, bool Pop); - void fpuComReg(x86FpuValues Reg, bool Pop); - void fpuDivDword(void * Variable, const char * VariableName); - void fpuDivDwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuDivQword(void * Variable, const char * VariableName); - void fpuDivQwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuDivReg(x86FpuValues Reg); - void fpuDivRegPop(x86FpuValues Reg); - void fpuExchange(x86FpuValues Reg); - void fpuFree(x86FpuValues Reg); - void fpuDecStack(int32_t & StackPos); void fpuIncStack(int32_t & StackPos); void fpuLoadControl(void * Variable, const char * VariableName); - void fpuLoadDword(int32_t & StackPos, void * Variable, const char * VariableName); void fpuLoadDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadDwordFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadInt32bFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadIntegerDword(int32_t & StackPos, void * Variable, const char * VariableName); void fpuLoadIntegerDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadIntegerQword(int32_t & StackPos, void * Variable, const char * VariableName); void fpuLoadIntegerQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadQword(int32_t & StackPos, void * Variable, const char * VariableName); void fpuLoadQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadQwordFromN64Mem(int32_t & StackPos, const asmjit::x86::Gp & Reg); - void fpuLoadReg(int32_t & StackPos, x86FpuValues Reg); - void fpuMulDword(void * Variable, const char * VariableName); - void fpuMulDwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuMulQword(void * Variable, const char * VariableName); - void fpuMulQwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuMulReg(x86FpuValues Reg); - void fpuMulRegPop(x86FpuValues Reg); - void fpuNeg(); - void fpuRound(); - void fpuSqrt(); + void fpuLoadReg(int32_t & StackPos, const asmjit::x86::St & Reg); void fpuStoreControl(void * Variable, const char * VariableName); - void fpuStoreDword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop); - void fpuStoreDwordToN64Mem(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool Pop); - void fpuStoreIntegerDword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreIntegerDwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop); - void fpuStoreIntegerQword(int32_t & StackPos, void * Variable, const char * VariableName, bool pop); void fpuStoreIntegerQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop); void fpuStoreQwordFromX86Reg(int32_t & StackPos, const asmjit::x86::Gp & Reg, bool pop); - void fpuStoreStatus(); - void fpuSubDword(void * Variable, const char * VariableName); - void fpuSubDwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuSubDwordReverse(void * Variable, const char * VariableName); - void fpuSubQword(void * Variable, const char * VariableName); - void fpuSubQwordRegPointer(const asmjit::x86::Gp & X86Pointer); - void fpuSubQwordReverse(void * Variable, const char * VariableName); - void fpuSubReg(x86FpuValues Reg); - void fpuSubRegPop(x86FpuValues Reg); static bool Is8BitReg(const asmjit::x86::Gp & Reg); - static uint8_t CalcMultiplyCode(Multipler Multiply); static uint32_t GetAddressOf(int32_t value, ...); - void SetJump32(uint32_t * Loc, uint32_t * JumpLoc); - void SetJump8(uint8_t * Loc, uint8_t * JumpLoc); - private: CX86Ops(void); CX86Ops(const CX86Ops &); @@ -287,14 +130,16 @@ private: }; static x86Reg RegValue(const asmjit::x86::Gp & Reg); - void CodeLog(_Printf_format_string_ const char * Text, ...); + asmjit::Error _log(const char* data, size_t size) noexcept; + void AddSymbol(const char * SymbolKey, const char * SymbolValue); + void RemoveSymbol(const char * SymbolKey); + std::string VariableSymbol(void * Variable) const; static void BreakPointNotification(const char * FileName, int32_t LineNumber); - static char m_fpupop[2][2]; - void AddCode8(uint8_t value); - void AddCode16(uint16_t value); - void AddCode32(uint32_t value); + typedef std::map SymbolMap; + + SymbolMap m_Symbols; CCodeBlock & m_CodeBlock; }; diff --git a/Source/Project64-core/Project64-core.vcxproj b/Source/Project64-core/Project64-core.vcxproj index 9083f3415..3a93a7b1e 100644 --- a/Source/Project64-core/Project64-core.vcxproj +++ b/Source/Project64-core/Project64-core.vcxproj @@ -288,6 +288,9 @@ + + {a72c9f08-ebb4-443d-9982-da21ae8b367d} + {731bd205-2826-4631-b7af-117658e88dbc}