Skip to content

Commit

Permalink
Avoid copying code when hashing block.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Apr 29, 2024
1 parent bf706f8 commit 727ab79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Source/MemoryMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const CMemoryMap::MEMORYMAPELEMENT* CMemoryMap::GetWriteMap(uint32 address) cons
return GetMap(m_writeMap, address);
}

const CMemoryMap::MEMORYMAPELEMENT* CMemoryMap::GetInstructionMap(uint32 address) const
{
return GetMap(m_instructionMap, address);
}

void CMemoryMap::InsertMap(MemoryMapListType& memoryMap, uint32 start, uint32 end, void* pointer, unsigned char key)
{
MEMORYMAPELEMENT element;
Expand Down
1 change: 1 addition & 0 deletions Source/MemoryMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CMemoryMap
const MemoryMapListType& GetInstructionMaps();
const MEMORYMAPELEMENT* GetReadMap(uint32) const;
const MEMORYMAPELEMENT* GetWriteMap(uint32) const;
const MEMORYMAPELEMENT* GetInstructionMap(uint32) const;

protected:
static const MEMORYMAPELEMENT* GetMap(const MemoryMapListType&, uint32);
Expand Down
19 changes: 4 additions & 15 deletions Source/ee/VuExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@ BasicBlockPtr CVuExecutor::BlockFactory(CMIPS& context, uint32 begin, uint32 end
{
uint32 blockSize = ((end - begin) + 4) / 4;
uint32 blockSizeByte = blockSize * 4;
uint32* blockMemory = reinterpret_cast<uint32*>(alloca(blockSizeByte));
for(uint32 address = begin; address <= end; address += 8)
{
uint32 index = (address - begin) / 4;

uint32 addressLo = address + 0;
uint32 addressHi = address + 4;

uint32 opcodeLo = m_context.m_pMemoryMap->GetInstruction(addressLo);
uint32 opcodeHi = m_context.m_pMemoryMap->GetInstruction(addressHi);

assert((index + 0) < blockSize);
blockMemory[index + 0] = opcodeLo;
assert((index + 1) < blockSize);
blockMemory[index + 1] = opcodeHi;
}
auto map = m_context.m_pMemoryMap->GetInstructionMap(begin);
assert(m_context.m_pMemoryMap->GetInstructionMap(end) == map);
uint32 localBegin = begin - map->nStart;
auto blockMemory = reinterpret_cast<const uint32*>(reinterpret_cast<uint8*>(map->pPointer) + localBegin);

auto xxHash = XXH3_128bits(blockMemory, blockSizeByte);
uint128 hash;
Expand Down

0 comments on commit 727ab79

Please sign in to comment.