JitCache: Return a pointer in GetBlockFromStartAddress.

This commit is contained in:
degasus
2017-01-10 23:16:07 +01:00
parent f6ec96efbd
commit d3aa8c8080
3 changed files with 25 additions and 30 deletions

View File

@ -169,7 +169,7 @@ void JitBaseBlockCache::FinalizeBlock(int block_num, bool block_link, const u8*
JitRegister::Register(b.checkedEntry, b.codeSize, "JIT_PPC_%08x", b.physicalAddress); JitRegister::Register(b.checkedEntry, b.codeSize, "JIT_PPC_%08x", b.physicalAddress);
} }
int JitBaseBlockCache::GetBlockNumberFromStartAddress(u32 addr, u32 msr) JitBlock* JitBaseBlockCache::GetBlockFromStartAddress(u32 addr, u32 msr)
{ {
u32 translated_addr = addr; u32 translated_addr = addr;
if (UReg_MSR(msr).IR) if (UReg_MSR(msr).IR)
@ -177,23 +177,23 @@ int JitBaseBlockCache::GetBlockNumberFromStartAddress(u32 addr, u32 msr)
auto translated = PowerPC::JitCache_TranslateAddress(addr); auto translated = PowerPC::JitCache_TranslateAddress(addr);
if (!translated.valid) if (!translated.valid)
{ {
return -1; return nullptr;
} }
translated_addr = translated.address; translated_addr = translated.address;
} }
auto map_result = start_block_map.find(translated_addr); auto map_result = start_block_map.find(translated_addr);
if (map_result == start_block_map.end()) if (map_result == start_block_map.end())
return -1; return nullptr;
int block_num = map_result->second; int block_num = map_result->second;
const JitBlock& b = blocks[block_num]; JitBlock& b = blocks[block_num];
if (b.invalid) if (b.invalid)
return -1; return nullptr;
if (b.effectiveAddress != addr) if (b.effectiveAddress != addr)
return -1; return nullptr;
if (b.msrBits != (msr & JitBlock::JIT_CACHE_MSR_MASK)) if (b.msrBits != (msr & JitBlock::JIT_CACHE_MSR_MASK))
return -1; return nullptr;
return block_num; return &b;
} }
const u8* JitBaseBlockCache::Dispatch() const u8* JitBaseBlockCache::Dispatch()
@ -280,14 +280,11 @@ void JitBaseBlockCache::LinkBlockExits(JitBlock& b)
{ {
if (!e.linkStatus) if (!e.linkStatus)
{ {
int destinationBlock = GetBlockNumberFromStartAddress(e.exitAddress, b.msrBits); JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, b.msrBits);
if (destinationBlock != -1) if (destinationBlock && !destinationBlock->invalid)
{ {
if (!blocks[destinationBlock].invalid) WriteLinkBlock(e, destinationBlock);
{ e.linkStatus = true;
WriteLinkBlock(e, &blocks[destinationBlock]);
e.linkStatus = true;
}
} }
} }
} }
@ -357,15 +354,15 @@ void JitBaseBlockCache::DestroyBlock(JitBlock& b, bool invalidate)
void JitBaseBlockCache::MoveBlockIntoFastCache(u32 addr, u32 msr) void JitBaseBlockCache::MoveBlockIntoFastCache(u32 addr, u32 msr)
{ {
int block_num = GetBlockNumberFromStartAddress(addr, msr); JitBlock* block = GetBlockFromStartAddress(addr, msr);
if (block_num < 0) if (!block)
{ {
Jit(addr); Jit(addr);
} }
else else
{ {
FastLookupEntryForAddress(addr) = block_num; FastLookupEntryForAddress(addr) = static_cast<int>(block - &blocks[0]);
LinkBlock(blocks[block_num]); LinkBlock(*block);
} }
} }

View File

@ -136,7 +136,8 @@ public:
// Look for the block in the slow but accurate way. // Look for the block in the slow but accurate way.
// This function shall be used if FastLookupEntryForAddress() failed. // This function shall be used if FastLookupEntryForAddress() failed.
int GetBlockNumberFromStartAddress(u32 em_address, u32 msr); // This might return nullptr if there is no such block.
JitBlock* GetBlockFromStartAddress(u32 em_address, u32 msr);
// Get the normal entry for the block associated with the current program // Get the normal entry for the block associated with the current program
// counter. This will JIT code if necessary. (This is the reference // counter. This will JIT code if necessary. (This is the reference

View File

@ -168,34 +168,31 @@ int GetHostCode(u32* address, const u8** code, u32* code_size)
return 1; return 1;
} }
int block_num = g_jit->GetBlockCache()->GetBlockNumberFromStartAddress(*address, MSR); JitBlock* block = g_jit->GetBlockCache()->GetBlockFromStartAddress(*address, MSR);
if (block_num < 0) if (!block)
{ {
for (int i = 0; i < 500; i++) for (int i = 0; i < 500; i++)
{ {
block_num = g_jit->GetBlockCache()->GetBlockNumberFromStartAddress(*address - 4 * i, MSR); block = g_jit->GetBlockCache()->GetBlockFromStartAddress(*address - 4 * i, MSR);
if (block_num >= 0) if (block)
break; break;
} }
if (block_num >= 0) if (block)
{ {
JitBlock* block = g_jit->GetBlockCache()->GetBlock(block_num);
if (!(block->effectiveAddress <= *address && if (!(block->effectiveAddress <= *address &&
block->originalSize + block->effectiveAddress >= *address)) block->originalSize + block->effectiveAddress >= *address))
block_num = -1; block = nullptr;
} }
// Do not merge this "if" with the above - block_num changes inside it. // Do not merge this "if" with the above - block_num changes inside it.
if (block_num < 0) if (!block)
{ {
*code_size = 0; *code_size = 0;
return 2; return 2;
} }
} }
JitBlock* block = g_jit->GetBlockCache()->GetBlock(block_num);
*code = block->checkedEntry; *code = block->checkedEntry;
*code_size = block->codeSize; *code_size = block->codeSize;
*address = block->effectiveAddress; *address = block->effectiveAddress;