From 2d164264122f8fbb90c9d7355fd4a3868fe9fe7b Mon Sep 17 00:00:00 2001 From: Jean-Philip Desjardins Date: Wed, 18 Dec 2024 13:53:07 -0500 Subject: [PATCH] Enable accurate ADDi only on the VU block that needs it. --- Source/ee/VuBasicBlock.cpp | 7 ++++++- Source/ee/VuBasicBlock.h | 2 ++ Source/ee/VuExecutor.cpp | 16 ++++++++++++++++ Source/ee/VuExecutor.h | 10 +++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Source/ee/VuBasicBlock.cpp b/Source/ee/VuBasicBlock.cpp index 69a8206e04..0a83cb6106 100644 --- a/Source/ee/VuBasicBlock.cpp +++ b/Source/ee/VuBasicBlock.cpp @@ -9,6 +9,11 @@ CVuBasicBlock::CVuBasicBlock(CMIPS& context, uint32 begin, uint32 end, BLOCK_CAT { } +void CVuBasicBlock::AddBlockCompileHints(uint32 compileHints) +{ + m_blockCompileHints |= compileHints; +} + bool CVuBasicBlock::IsLinkable() const { return m_isLinkable; @@ -168,7 +173,7 @@ void CVuBasicBlock::CompileRange(CMipsJitter* jitter) jitter->PullRel(offsetof(CMIPS, m_State.savedNextBlockIntRegVal)); } - uint32 compileHints = hints[instructionIndex]; + uint32 compileHints = hints[instructionIndex] | m_blockCompileHints; arch->SetRelativePipeTime(relativePipeTime, compileHints); arch->CompileInstruction(addressHi, jitter, &m_context, addressHi - m_begin); diff --git a/Source/ee/VuBasicBlock.h b/Source/ee/VuBasicBlock.h index 052b681690..3adb22d4ea 100644 --- a/Source/ee/VuBasicBlock.h +++ b/Source/ee/VuBasicBlock.h @@ -8,6 +8,7 @@ class CVuBasicBlock : public CBasicBlock CVuBasicBlock(CMIPS&, uint32, uint32, BLOCK_CATEGORY); virtual ~CVuBasicBlock() = default; + void AddBlockCompileHints(uint32); bool IsLinkable() const; protected: @@ -45,4 +46,5 @@ class CVuBasicBlock : public CBasicBlock static void EmitXgKick(CMipsJitter*); bool m_isLinkable = true; + uint32 m_blockCompileHints = 0; }; diff --git a/Source/ee/VuExecutor.cpp b/Source/ee/VuExecutor.cpp index bc0e55cdca..ed683aa758 100644 --- a/Source/ee/VuExecutor.cpp +++ b/Source/ee/VuExecutor.cpp @@ -3,6 +3,14 @@ #include "VUShared.h" #include "xxhash.h" +// clang-format off +const CVuExecutor::BLOCK_COMPILE_HINTS CVuExecutor::g_blockCompileHints[] = +{ + // Tri-Ace VU0 decompression code + { std::make_pair(uint128{0x3aa43f7c, 0xe932516c, 0x6786472d, 0xf5333e12}, 0x58U), VUShared::COMPILEHINT_USE_ACCURATE_ADDI }, +}; +// clang-format on + CVuExecutor::CVuExecutor(CMIPS& context, uint32 maxAddress) : CGenericMipsExecutor(context, maxAddress, BLOCK_CATEGORY_PS2_VU) { @@ -57,6 +65,14 @@ BasicBlockPtr CVuExecutor::BlockFactory(CMIPS& context, uint32 begin, uint32 end //Totally new block, build it from scratch auto result = std::make_shared(context, begin, end, m_blockCategory); + + auto blockCompileHintsIterator = std::find_if(std::begin(g_blockCompileHints), std::end(g_blockCompileHints), + [&](const auto& item) { return item.blockKey == blockKey; }); + if(blockCompileHintsIterator != std::end(g_blockCompileHints)) + { + result->AddBlockCompileHints(blockCompileHintsIterator->hints); + } + result->Compile(); if(!hasBreakpoint) { diff --git a/Source/ee/VuExecutor.h b/Source/ee/VuExecutor.h index 21318b1d93..e0e4b83c23 100644 --- a/Source/ee/VuExecutor.h +++ b/Source/ee/VuExecutor.h @@ -14,8 +14,16 @@ class CVuExecutor : public CGenericMipsExecutor protected: typedef std::pair CachedBlockKey; typedef std::multimap CachedBlockMap; - CachedBlockMap m_cachedBlocks; + + struct BLOCK_COMPILE_HINTS + { + CachedBlockKey blockKey; + uint32 hints; + }; BasicBlockPtr BlockFactory(CMIPS&, uint32, uint32) override; void PartitionFunction(uint32) override; + + static const BLOCK_COMPILE_HINTS g_blockCompileHints[]; + CachedBlockMap m_cachedBlocks; };