Skip to content

Commit

Permalink
Enable accurate ADDi only on the VU block that needs it.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Dec 18, 2024
1 parent 62997ad commit 2d16426
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Source/ee/VuBasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions Source/ee/VuBasicBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CVuBasicBlock : public CBasicBlock
CVuBasicBlock(CMIPS&, uint32, uint32, BLOCK_CATEGORY);
virtual ~CVuBasicBlock() = default;

void AddBlockCompileHints(uint32);
bool IsLinkable() const;

protected:
Expand Down Expand Up @@ -45,4 +46,5 @@ class CVuBasicBlock : public CBasicBlock
static void EmitXgKick(CMipsJitter*);

bool m_isLinkable = true;
uint32 m_blockCompileHints = 0;
};
16 changes: 16 additions & 0 deletions Source/ee/VuExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<CVuBasicBlock>(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)
{
Expand Down
10 changes: 9 additions & 1 deletion Source/ee/VuExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ class CVuExecutor : public CGenericMipsExecutor<BlockLookupOneWay, 8>
protected:
typedef std::pair<uint128, uint32> CachedBlockKey;
typedef std::multimap<CachedBlockKey, BasicBlockPtr> 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;
};

0 comments on commit 2d16426

Please sign in to comment.