From ccb8c44a5a43bdd080440722daa6d86a5c1ec7e6 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 22:36:07 +0100 Subject: [PATCH 01/14] JitCache: Use a pointer in LinkBlockExits. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 11 +++++------ Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 265bef38d9..9ef3e7786e 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -269,9 +269,8 @@ void JitBaseBlockCache::WriteDestroyBlock(const JitBlock& block) // Can be faster by doing a queue for blocks to link up, and only process those // Should probably be done -void JitBaseBlockCache::LinkBlockExits(int i) +void JitBaseBlockCache::LinkBlockExits(JitBlock& b) { - JitBlock& b = blocks[i]; if (b.invalid) { // This block is dead. Don't relink it. @@ -296,15 +295,15 @@ void JitBaseBlockCache::LinkBlockExits(int i) void JitBaseBlockCache::LinkBlock(int i) { - LinkBlockExits(i); - const JitBlock& b = blocks[i]; + JitBlock& b = blocks[i]; + LinkBlockExits(b); auto ppp = links_to.equal_range(b.effectiveAddress); for (auto iter = ppp.first; iter != ppp.second; ++iter) { - const JitBlock& b2 = blocks[iter->second]; + JitBlock& b2 = blocks[iter->second]; if (b.msrBits == b2.msrBits) - LinkBlockExits(iter->second); + LinkBlockExits(b2); } } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 0b1f23482e..b3d7527e3c 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -155,7 +155,7 @@ private: virtual void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) = 0; virtual void WriteDestroyBlock(const JitBlock& block); - void LinkBlockExits(int i); + void LinkBlockExits(JitBlock& b); void LinkBlock(int i); void UnlinkBlock(int i); void DestroyBlock(int block_num, bool invalidate); From eb390f30209fc26b91605620136df027a2264f24 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 22:40:27 +0100 Subject: [PATCH 02/14] JitCache: Use a pointer in LinkBlock. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 7 +++---- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 9ef3e7786e..462708a191 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -163,7 +163,7 @@ void JitBaseBlockCache::FinalizeBlock(int block_num, bool block_link, const u8* links_to.emplace(e.exitAddress, block_num); } - LinkBlock(block_num); + LinkBlock(b); } JitRegister::Register(b.checkedEntry, b.codeSize, "JIT_PPC_%08x", b.physicalAddress); @@ -293,9 +293,8 @@ void JitBaseBlockCache::LinkBlockExits(JitBlock& b) } } -void JitBaseBlockCache::LinkBlock(int i) +void JitBaseBlockCache::LinkBlock(JitBlock& b) { - JitBlock& b = blocks[i]; LinkBlockExits(b); auto ppp = links_to.equal_range(b.effectiveAddress); @@ -373,7 +372,7 @@ void JitBaseBlockCache::MoveBlockIntoFastCache(u32 addr, u32 msr) else { FastLookupEntryForAddress(addr) = block_num; - LinkBlock(block_num); + LinkBlock(blocks[block_num]); } } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index b3d7527e3c..d2240e02fd 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -156,7 +156,7 @@ private: virtual void WriteDestroyBlock(const JitBlock& block); void LinkBlockExits(JitBlock& b); - void LinkBlock(int i); + void LinkBlock(JitBlock& b); void UnlinkBlock(int i); void DestroyBlock(int block_num, bool invalidate); From 68c85d32f71b3b8941b6269d7625d03152dcefb7 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 22:42:54 +0100 Subject: [PATCH 03/14] JitCache: Use a pointer in UnlinkBlock. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 5 ++--- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 462708a191..58586fa23c 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -306,9 +306,8 @@ void JitBaseBlockCache::LinkBlock(JitBlock& b) } } -void JitBaseBlockCache::UnlinkBlock(int i) +void JitBaseBlockCache::UnlinkBlock(const JitBlock& b) { - JitBlock& b = blocks[i]; auto ppp = links_to.equal_range(b.effectiveAddress); for (auto iter = ppp.first; iter != ppp.second; ++iter) @@ -346,7 +345,7 @@ void JitBaseBlockCache::DestroyBlock(int block_num, bool invalidate) start_block_map.erase(b.physicalAddress); FastLookupEntryForAddress(b.effectiveAddress) = 0; - UnlinkBlock(block_num); + UnlinkBlock(b); // Delete linking addresses auto it = links_to.equal_range(b.effectiveAddress); diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index d2240e02fd..e47723eb2f 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -157,7 +157,7 @@ private: void LinkBlockExits(JitBlock& b); void LinkBlock(JitBlock& b); - void UnlinkBlock(int i); + void UnlinkBlock(const JitBlock& b); void DestroyBlock(int block_num, bool invalidate); void MoveBlockIntoFastCache(u32 em_address, u32 msr); From f6ec96efbd46dc3922dc6ac0e9ae4d703f17d00e Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 23:08:11 +0100 Subject: [PATCH 04/14] JitCache: Use a pointer in DestroyBlock. --- .../Core/Core/PowerPC/JitCommon/JitCache.cpp | 20 +++++++------------ Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 58586fa23c..35c907169c 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -71,7 +71,7 @@ void JitBaseBlockCache::Clear() m_jit.js.pairedQuantizeAddresses.clear(); for (int i = 1; i < num_blocks; i++) { - DestroyBlock(i, false); + DestroyBlock(blocks[i], false); } links_to.clear(); block_map.clear(); @@ -141,10 +141,10 @@ void JitBaseBlockCache::FinalizeBlock(int block_num, bool block_link, const u8* // is called both with DR/IR enabled or disabled. WARN_LOG(DYNA_REC, "Invalidating compiled block at same address %08x", b.physicalAddress); int old_block_num = start_block_map[b.physicalAddress]; - const JitBlock& old_b = blocks[old_block_num]; + JitBlock& old_b = blocks[old_block_num]; block_map.erase( std::make_pair(old_b.physicalAddress + 4 * old_b.originalSize - 1, old_b.physicalAddress)); - DestroyBlock(old_block_num, true); + DestroyBlock(old_b, true); } start_block_map[b.physicalAddress] = block_num; FastLookupEntryForAddress(b.effectiveAddress) = block_num; @@ -235,7 +235,7 @@ void JitBaseBlockCache::InvalidateICache(u32 address, const u32 length, bool for auto it = block_map.lower_bound(std::make_pair(pAddr, 0)); while (it != block_map.end() && it->first.second < pAddr + length) { - DestroyBlock(it->second, true); + DestroyBlock(blocks[it->second], true); it = block_map.erase(it); } @@ -327,18 +327,12 @@ void JitBaseBlockCache::UnlinkBlock(const JitBlock& b) } } -void JitBaseBlockCache::DestroyBlock(int block_num, bool invalidate) +void JitBaseBlockCache::DestroyBlock(JitBlock& b, bool invalidate) { - if (block_num < 0 || block_num >= num_blocks) - { - PanicAlert("DestroyBlock: Invalid block number %d", block_num); - return; - } - JitBlock& b = blocks[block_num]; if (b.invalid) { if (invalidate) - PanicAlert("Invalidating invalid block %d", block_num); + PanicAlert("Invalidating invalid block %p", &b); return; } b.invalid = true; @@ -351,7 +345,7 @@ void JitBaseBlockCache::DestroyBlock(int block_num, bool invalidate) auto it = links_to.equal_range(b.effectiveAddress); while (it.first != it.second) { - if (it.first->second == block_num) + if (it.first->second == &b - &blocks[0]) it.first = links_to.erase(it.first); else it.first++; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index e47723eb2f..c2bb5f6e43 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -158,7 +158,7 @@ private: void LinkBlockExits(JitBlock& b); void LinkBlock(JitBlock& b); void UnlinkBlock(const JitBlock& b); - void DestroyBlock(int block_num, bool invalidate); + void DestroyBlock(JitBlock& b, bool invalidate); void MoveBlockIntoFastCache(u32 em_address, u32 msr); From d3aa8c808035b336755dce4b99cd6e52730f37e0 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 23:16:07 +0100 Subject: [PATCH 05/14] JitCache: Return a pointer in GetBlockFromStartAddress. --- .../Core/Core/PowerPC/JitCommon/JitCache.cpp | 35 +++++++++---------- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 3 +- Source/Core/Core/PowerPC/JitInterface.cpp | 17 ++++----- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 35c907169c..1a1fe03556 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -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); } -int JitBaseBlockCache::GetBlockNumberFromStartAddress(u32 addr, u32 msr) +JitBlock* JitBaseBlockCache::GetBlockFromStartAddress(u32 addr, u32 msr) { u32 translated_addr = addr; if (UReg_MSR(msr).IR) @@ -177,23 +177,23 @@ int JitBaseBlockCache::GetBlockNumberFromStartAddress(u32 addr, u32 msr) auto translated = PowerPC::JitCache_TranslateAddress(addr); if (!translated.valid) { - return -1; + return nullptr; } translated_addr = translated.address; } auto map_result = start_block_map.find(translated_addr); if (map_result == start_block_map.end()) - return -1; + return nullptr; int block_num = map_result->second; - const JitBlock& b = blocks[block_num]; + JitBlock& b = blocks[block_num]; if (b.invalid) - return -1; + return nullptr; if (b.effectiveAddress != addr) - return -1; + return nullptr; if (b.msrBits != (msr & JitBlock::JIT_CACHE_MSR_MASK)) - return -1; - return block_num; + return nullptr; + return &b; } const u8* JitBaseBlockCache::Dispatch() @@ -280,14 +280,11 @@ void JitBaseBlockCache::LinkBlockExits(JitBlock& b) { if (!e.linkStatus) { - int destinationBlock = GetBlockNumberFromStartAddress(e.exitAddress, b.msrBits); - if (destinationBlock != -1) + JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, b.msrBits); + if (destinationBlock && !destinationBlock->invalid) { - if (!blocks[destinationBlock].invalid) - { - WriteLinkBlock(e, &blocks[destinationBlock]); - e.linkStatus = true; - } + WriteLinkBlock(e, destinationBlock); + e.linkStatus = true; } } } @@ -357,15 +354,15 @@ void JitBaseBlockCache::DestroyBlock(JitBlock& b, bool invalidate) void JitBaseBlockCache::MoveBlockIntoFastCache(u32 addr, u32 msr) { - int block_num = GetBlockNumberFromStartAddress(addr, msr); - if (block_num < 0) + JitBlock* block = GetBlockFromStartAddress(addr, msr); + if (!block) { Jit(addr); } else { - FastLookupEntryForAddress(addr) = block_num; - LinkBlock(blocks[block_num]); + FastLookupEntryForAddress(addr) = static_cast(block - &blocks[0]); + LinkBlock(*block); } } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index c2bb5f6e43..a79ce53c9f 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -136,7 +136,8 @@ public: // Look for the block in the slow but accurate way. // 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 // counter. This will JIT code if necessary. (This is the reference diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index d02377264c..790a377dc1 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -168,34 +168,31 @@ int GetHostCode(u32* address, const u8** code, u32* code_size) return 1; } - int block_num = g_jit->GetBlockCache()->GetBlockNumberFromStartAddress(*address, MSR); - if (block_num < 0) + JitBlock* block = g_jit->GetBlockCache()->GetBlockFromStartAddress(*address, MSR); + if (!block) { for (int i = 0; i < 500; i++) { - block_num = g_jit->GetBlockCache()->GetBlockNumberFromStartAddress(*address - 4 * i, MSR); - if (block_num >= 0) + block = g_jit->GetBlockCache()->GetBlockFromStartAddress(*address - 4 * i, MSR); + if (block) break; } - if (block_num >= 0) + if (block) { - JitBlock* block = g_jit->GetBlockCache()->GetBlock(block_num); if (!(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. - if (block_num < 0) + if (!block) { *code_size = 0; return 2; } } - JitBlock* block = g_jit->GetBlockCache()->GetBlock(block_num); - *code = block->checkedEntry; *code_size = block->codeSize; *address = block->effectiveAddress; From f14cebf079fc77b47d6e4ed127fe9adf57206ae2 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 23:24:24 +0100 Subject: [PATCH 06/14] JitCache: Use a pointer in FinalizeBlock. --- .../Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp | 2 +- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 2 +- Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp | 2 +- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 2 +- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 4 ++-- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index 44bf711e90..7fe68c3c21 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -212,7 +212,7 @@ void CachedInterpreter::Jit(u32 address) b->codeSize = (u32)(GetCodePtr() - b->checkedEntry); b->originalSize = code_block.m_num_instructions; - m_block_cache.FinalizeBlock(block_num, jo.enableBlocklink, b->checkedEntry); + m_block_cache.FinalizeBlock(*b, jo.enableBlocklink, b->checkedEntry); } void CachedInterpreter::ClearCache() diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index a96078302e..cb000b93ff 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -591,7 +591,7 @@ void Jit64::Jit(u32 em_address) int block_num = blocks.AllocateBlock(em_address); JitBlock* b = blocks.GetBlock(block_num); - blocks.FinalizeBlock(block_num, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); + blocks.FinalizeBlock(*b, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); } const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC) diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index 988d8321fd..99bd811c2f 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -509,7 +509,7 @@ void JitIL::Jit(u32 em_address) int block_num = blocks.AllocateBlock(em_address); JitBlock* b = blocks.GetBlock(block_num); - blocks.FinalizeBlock(block_num, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); + blocks.FinalizeBlock(*b, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); } const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC) diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index 5ee45e5613..a1139f0c24 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -401,7 +401,7 @@ void JitArm64::Jit(u32) int block_num = blocks.AllocateBlock(em_address); JitBlock* b = blocks.GetBlock(block_num); const u8* BlockPtr = DoJit(em_address, &code_buffer, b, nextPC); - blocks.FinalizeBlock(block_num, jo.enableBlocklink, BlockPtr); + blocks.FinalizeBlock(*b, jo.enableBlocklink, BlockPtr); } const u8* JitArm64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBlock* b, u32 nextPC) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 1a1fe03556..869ebb4374 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -131,9 +131,8 @@ int JitBaseBlockCache::AllocateBlock(u32 em_address) return num_blocks - 1; } -void JitBaseBlockCache::FinalizeBlock(int block_num, bool block_link, const u8* code_ptr) +void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr) { - JitBlock& b = blocks[block_num]; if (start_block_map.count(b.physicalAddress)) { // We already have a block at this address; invalidate the old block. @@ -146,6 +145,7 @@ void JitBaseBlockCache::FinalizeBlock(int block_num, bool block_link, const u8* std::make_pair(old_b.physicalAddress + 4 * old_b.originalSize - 1, old_b.physicalAddress)); DestroyBlock(old_b, true); } + const int block_num = static_cast(&b - &blocks[0]); start_block_map[b.physicalAddress] = block_num; FastLookupEntryForAddress(b.effectiveAddress) = block_num; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index a79ce53c9f..446aaa70e6 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -132,7 +132,7 @@ public: int* GetICache(); int AllocateBlock(u32 em_address); - void FinalizeBlock(int block_num, bool block_link, const u8* code_ptr); + void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); // Look for the block in the slow but accurate way. // This function shall be used if FastLookupEntryForAddress() failed. From 2d5288dc1025ec0e582090b5c1efc326635eb708 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 23:28:44 +0100 Subject: [PATCH 07/14] JitCache: Return a pointer in AllocateBlock. --- .../Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp | 3 +-- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 3 +-- Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp | 3 +-- Source/Core/Core/PowerPC/JitArm64/Jit.cpp | 3 +-- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 4 ++-- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp index 7fe68c3c21..39006acf01 100644 --- a/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp +++ b/Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp @@ -140,8 +140,7 @@ void CachedInterpreter::Jit(u32 address) return; } - int block_num = m_block_cache.AllocateBlock(PC); - JitBlock* b = m_block_cache.GetBlock(block_num); + JitBlock* b = m_block_cache.AllocateBlock(PC); js.blockStart = PC; js.firstFPInstructionFound = false; diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index cb000b93ff..580bab2577 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -589,8 +589,7 @@ void Jit64::Jit(u32 em_address) return; } - int block_num = blocks.AllocateBlock(em_address); - JitBlock* b = blocks.GetBlock(block_num); + JitBlock* b = blocks.AllocateBlock(em_address); blocks.FinalizeBlock(*b, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); } diff --git a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp index 99bd811c2f..85c8b12cc0 100644 --- a/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp +++ b/Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp @@ -507,8 +507,7 @@ void JitIL::Jit(u32 em_address) return; } - int block_num = blocks.AllocateBlock(em_address); - JitBlock* b = blocks.GetBlock(block_num); + JitBlock* b = blocks.AllocateBlock(em_address); blocks.FinalizeBlock(*b, jo.enableBlocklink, DoJit(em_address, &code_buffer, b, nextPC)); } diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp index a1139f0c24..a424166574 100644 --- a/Source/Core/Core/PowerPC/JitArm64/Jit.cpp +++ b/Source/Core/Core/PowerPC/JitArm64/Jit.cpp @@ -398,8 +398,7 @@ void JitArm64::Jit(u32) return; } - int block_num = blocks.AllocateBlock(em_address); - JitBlock* b = blocks.GetBlock(block_num); + JitBlock* b = blocks.AllocateBlock(em_address); const u8* BlockPtr = DoJit(em_address, &code_buffer, b, nextPC); blocks.FinalizeBlock(*b, jo.enableBlocklink, BlockPtr); } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 869ebb4374..944051d2ac 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -119,7 +119,7 @@ int* JitBaseBlockCache::GetICache() return iCache.data(); } -int JitBaseBlockCache::AllocateBlock(u32 em_address) +JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address) { JitBlock& b = blocks[num_blocks]; b.invalid = false; @@ -128,7 +128,7 @@ int JitBaseBlockCache::AllocateBlock(u32 em_address) b.msrBits = MSR & JitBlock::JIT_CACHE_MSR_MASK; b.linkData.clear(); num_blocks++; // commit the current block - return num_blocks - 1; + return &b; } void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 446aaa70e6..b44572e2b4 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -131,7 +131,7 @@ public: int GetNumBlocks() const; int* GetICache(); - int AllocateBlock(u32 em_address); + JitBlock* AllocateBlock(u32 em_address); void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); // Look for the block in the slow but accurate way. From 74a27d97424dabedee950a2a85a827936caea653 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 10 Jan 2017 23:34:57 +0100 Subject: [PATCH 08/14] JitCache: Use a pointer in start_block_map. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 8 +++----- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 944051d2ac..ded0c003a7 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -139,14 +139,13 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* co // This should be very rare. This will only happen if the same block // is called both with DR/IR enabled or disabled. WARN_LOG(DYNA_REC, "Invalidating compiled block at same address %08x", b.physicalAddress); - int old_block_num = start_block_map[b.physicalAddress]; - JitBlock& old_b = blocks[old_block_num]; + JitBlock& old_b = *start_block_map[b.physicalAddress]; block_map.erase( std::make_pair(old_b.physicalAddress + 4 * old_b.originalSize - 1, old_b.physicalAddress)); DestroyBlock(old_b, true); } const int block_num = static_cast(&b - &blocks[0]); - start_block_map[b.physicalAddress] = block_num; + start_block_map[b.physicalAddress] = &b; FastLookupEntryForAddress(b.effectiveAddress) = block_num; u32 pAddr = b.physicalAddress; @@ -185,8 +184,7 @@ JitBlock* JitBaseBlockCache::GetBlockFromStartAddress(u32 addr, u32 msr) auto map_result = start_block_map.find(translated_addr); if (map_result == start_block_map.end()) return nullptr; - int block_num = map_result->second; - JitBlock& b = blocks[block_num]; + JitBlock& b = *map_result->second; if (b.invalid) return nullptr; if (b.effectiveAddress != addr) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index b44572e2b4..b048c92f7a 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -182,7 +182,7 @@ private: // Map indexed by the physical address of the entry point. // This is used to query the block based on the current PC in a slow way. // TODO: This is redundant with block_map, and both should be a multimap. - std::map start_block_map; // start_addr -> number + std::map start_block_map; // start_addr -> block // This bitsets shows which cachelines overlap with any blocks. // It is used to provide a fast way to query if no icache invalidation is needed. From 928ccbef532d3972ad87fe16246d6c6753cbf1ad Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 11 Jan 2017 20:03:35 +0100 Subject: [PATCH 09/14] JitCache: Use a pointer in block_map. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 4 ++-- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index ded0c003a7..59a4d8314d 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -153,7 +153,7 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* co for (u32 block = pAddr / 32; block <= (pAddr + (b.originalSize - 1) * 4) / 32; ++block) valid_block.Set(block); - block_map[std::make_pair(pAddr + 4 * b.originalSize - 1, pAddr)] = block_num; + block_map[std::make_pair(pAddr + 4 * b.originalSize - 1, pAddr)] = &b; if (block_link) { @@ -233,7 +233,7 @@ void JitBaseBlockCache::InvalidateICache(u32 address, const u32 length, bool for auto it = block_map.lower_bound(std::make_pair(pAddr, 0)); while (it != block_map.end() && it->first.second < pAddr + length) { - DestroyBlock(blocks[it->second], true); + DestroyBlock(*it->second, true); it = block_map.erase(it); } diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index b048c92f7a..0be888eb49 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -177,7 +177,7 @@ private: // Map indexed by the physical memory location. // It is used to invalidate blocks based on memory location. - std::map, u32> block_map; // (end_addr, start_addr) -> number + std::map, JitBlock*> block_map; // (end_addr, start_addr) -> block // Map indexed by the physical address of the entry point. // This is used to query the block based on the current PC in a slow way. From ca026b58ab666ecc4fe814c1370fc0a1032f9337 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 11 Jan 2017 20:08:45 +0100 Subject: [PATCH 10/14] JitCache: Use a pointer in links_to. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 8 ++++---- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 59a4d8314d..ad15d0f449 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -159,7 +159,7 @@ void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* co { for (const auto& e : b.linkData) { - links_to.emplace(e.exitAddress, block_num); + links_to.emplace(e.exitAddress, &b); } LinkBlock(b); @@ -295,7 +295,7 @@ void JitBaseBlockCache::LinkBlock(JitBlock& b) for (auto iter = ppp.first; iter != ppp.second; ++iter) { - JitBlock& b2 = blocks[iter->second]; + JitBlock& b2 = *iter->second; if (b.msrBits == b2.msrBits) LinkBlockExits(b2); } @@ -307,7 +307,7 @@ void JitBaseBlockCache::UnlinkBlock(const JitBlock& b) for (auto iter = ppp.first; iter != ppp.second; ++iter) { - JitBlock& sourceBlock = blocks[iter->second]; + JitBlock& sourceBlock = *iter->second; if (sourceBlock.msrBits != b.msrBits) continue; @@ -340,7 +340,7 @@ void JitBaseBlockCache::DestroyBlock(JitBlock& b, bool invalidate) auto it = links_to.equal_range(b.effectiveAddress); while (it.first != it.second) { - if (it.first->second == &b - &blocks[0]) + if (it.first->second == &b) it.first = links_to.erase(it.first); else it.first++; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 0be888eb49..8c4bc04e2e 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -173,7 +173,7 @@ private: // links_to hold all exit points of all valid blocks in a reverse way. // It is used to query all blocks which links to an address. - std::multimap links_to; // destination_PC -> number + std::multimap links_to; // destination_PC -> number // Map indexed by the physical memory location. // It is used to invalidate blocks based on memory location. From 7e850361fbe4463dbfa433f09315ebfc5f6405bb Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 11 Jan 2017 20:24:13 +0100 Subject: [PATCH 11/14] JitCache: Add a helper function to iterate over all blocks. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 6 ++++++ Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 ++ Source/Core/Core/PowerPC/JitInterface.cpp | 17 +++++++---------- Source/Core/Core/PowerPC/Profiler.h | 5 ++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index ad15d0f449..1f825fa9ec 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -119,6 +119,12 @@ int* JitBaseBlockCache::GetICache() return iCache.data(); } +void JitBaseBlockCache::RunOnBlocks(std::function f) +{ + for (int i = 0; i < num_blocks; i++) + f(blocks[i]); +} + JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address) { JitBlock& b = blocks[num_blocks]; diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 8c4bc04e2e..781fb596f4 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -130,6 +131,7 @@ public: JitBlock* GetBlocks(); int GetNumBlocks() const; int* GetICache(); + void RunOnBlocks(std::function f); JitBlock* AllocateBlock(u32 em_address); void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); diff --git a/Source/Core/Core/PowerPC/JitInterface.cpp b/Source/Core/Core/PowerPC/JitInterface.cpp index 790a377dc1..a342f7a6d7 100644 --- a/Source/Core/Core/PowerPC/JitInterface.cpp +++ b/Source/Core/Core/PowerPC/JitInterface.cpp @@ -134,26 +134,23 @@ void GetProfileResults(ProfileStats* prof_stats) prof_stats->cost_sum = 0; prof_stats->timecost_sum = 0; prof_stats->block_stats.clear(); - prof_stats->block_stats.reserve(g_jit->GetBlockCache()->GetNumBlocks()); Core::EState old_state = Core::GetState(); if (old_state == Core::CORE_RUN) Core::SetState(Core::CORE_PAUSE); QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec); - for (int i = 0; i < g_jit->GetBlockCache()->GetNumBlocks(); i++) - { - const JitBlock* block = g_jit->GetBlockCache()->GetBlock(i); + g_jit->GetBlockCache()->RunOnBlocks([&prof_stats](const JitBlock& block) { // Rough heuristic. Mem instructions should cost more. - u64 cost = block->originalSize * (block->runCount / 4); - u64 timecost = block->ticCounter; + u64 cost = block.originalSize * (block.runCount / 4); + u64 timecost = block.ticCounter; // Todo: tweak. - if (block->runCount >= 1) - prof_stats->block_stats.emplace_back(i, block->effectiveAddress, cost, timecost, - block->runCount, block->codeSize); + if (block.runCount >= 1) + prof_stats->block_stats.emplace_back(block.effectiveAddress, cost, timecost, block.runCount, + block.codeSize); prof_stats->cost_sum += cost; prof_stats->timecost_sum += timecost; - } + }); sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end()); if (old_state == Core::CORE_RUN) diff --git a/Source/Core/Core/PowerPC/Profiler.h b/Source/Core/Core/PowerPC/Profiler.h index 4c11af58ed..6146bee4d1 100644 --- a/Source/Core/Core/PowerPC/Profiler.h +++ b/Source/Core/Core/PowerPC/Profiler.h @@ -43,11 +43,10 @@ struct BlockStat { - BlockStat(int bn, u32 _addr, u64 c, u64 ticks, u64 run, u32 size) - : blockNum(bn), addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size) + BlockStat(u32 _addr, u64 c, u64 ticks, u64 run, u32 size) + : addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size) { } - int blockNum; u32 addr; u64 cost; u64 tick_counter; From 3ee178abe7d243bd266a64a015da3b5c4cfb8a2c Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 11 Jan 2017 20:27:01 +0100 Subject: [PATCH 12/14] JitCache: Drop unused functions. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 12 +----------- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 2 -- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 1f825fa9ec..559c082b98 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -96,12 +96,7 @@ void JitBaseBlockCache::SchedulateClearCacheThreadSafe() bool JitBaseBlockCache::IsFull() const { - return GetNumBlocks() >= MAX_NUM_BLOCKS - 1; -} - -JitBlock* JitBaseBlockCache::GetBlock(int no) -{ - return &blocks[no]; + return num_blocks >= MAX_NUM_BLOCKS - 1; } JitBlock* JitBaseBlockCache::GetBlocks() @@ -109,11 +104,6 @@ JitBlock* JitBaseBlockCache::GetBlocks() return blocks.data(); } -int JitBaseBlockCache::GetNumBlocks() const -{ - return num_blocks; -} - int* JitBaseBlockCache::GetICache() { return iCache.data(); diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 781fb596f4..6e8e8fa6f9 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -127,9 +127,7 @@ public: bool IsFull() const; // Code Cache - JitBlock* GetBlock(int block_num); JitBlock* GetBlocks(); - int GetNumBlocks() const; int* GetICache(); void RunOnBlocks(std::function f); From 214f37ecefb3e05f7a5f0267e3bb4b9ccfe78ffa Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 11 Jan 2017 21:54:10 +0100 Subject: [PATCH 13/14] JitCache: Rename variables. --- .../Core/Core/PowerPC/JitCommon/JitCache.cpp | 74 +++++++++---------- Source/Core/Core/PowerPC/JitCommon/JitCache.h | 10 +-- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 559c082b98..4be02d1c64 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -127,41 +127,41 @@ JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address) return &b; } -void JitBaseBlockCache::FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr) +void JitBaseBlockCache::FinalizeBlock(JitBlock& block, bool block_link, const u8* code_ptr) { - if (start_block_map.count(b.physicalAddress)) + if (start_block_map.count(block.physicalAddress)) { // We already have a block at this address; invalidate the old block. // This should be very rare. This will only happen if the same block // is called both with DR/IR enabled or disabled. - WARN_LOG(DYNA_REC, "Invalidating compiled block at same address %08x", b.physicalAddress); - JitBlock& old_b = *start_block_map[b.physicalAddress]; + WARN_LOG(DYNA_REC, "Invalidating compiled block at same address %08x", block.physicalAddress); + JitBlock& old_b = *start_block_map[block.physicalAddress]; block_map.erase( std::make_pair(old_b.physicalAddress + 4 * old_b.originalSize - 1, old_b.physicalAddress)); DestroyBlock(old_b, true); } - const int block_num = static_cast(&b - &blocks[0]); - start_block_map[b.physicalAddress] = &b; - FastLookupEntryForAddress(b.effectiveAddress) = block_num; + const int block_num = static_cast(&block - &blocks[0]); + start_block_map[block.physicalAddress] = █ + FastLookupEntryForAddress(block.effectiveAddress) = block_num; - u32 pAddr = b.physicalAddress; + u32 pAddr = block.physicalAddress; - for (u32 block = pAddr / 32; block <= (pAddr + (b.originalSize - 1) * 4) / 32; ++block) - valid_block.Set(block); + for (u32 addr = pAddr / 32; addr <= (pAddr + (block.originalSize - 1) * 4) / 32; ++addr) + valid_block.Set(addr); - block_map[std::make_pair(pAddr + 4 * b.originalSize - 1, pAddr)] = &b; + block_map[std::make_pair(pAddr + 4 * block.originalSize - 1, pAddr)] = █ if (block_link) { - for (const auto& e : b.linkData) + for (const auto& e : block.linkData) { - links_to.emplace(e.exitAddress, &b); + links_to.emplace(e.exitAddress, &block); } - LinkBlock(b); + LinkBlock(block); } - JitRegister::Register(b.checkedEntry, b.codeSize, "JIT_PPC_%08x", b.physicalAddress); + JitRegister::Register(block.checkedEntry, block.codeSize, "JIT_PPC_%08x", block.physicalAddress); } JitBlock* JitBaseBlockCache::GetBlockFromStartAddress(u32 addr, u32 msr) @@ -263,18 +263,18 @@ void JitBaseBlockCache::WriteDestroyBlock(const JitBlock& block) // Can be faster by doing a queue for blocks to link up, and only process those // Should probably be done -void JitBaseBlockCache::LinkBlockExits(JitBlock& b) +void JitBaseBlockCache::LinkBlockExits(JitBlock& block) { - if (b.invalid) + if (block.invalid) { // This block is dead. Don't relink it. return; } - for (auto& e : b.linkData) + for (auto& e : block.linkData) { if (!e.linkStatus) { - JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, b.msrBits); + JitBlock* destinationBlock = GetBlockFromStartAddress(e.exitAddress, block.msrBits); if (destinationBlock && !destinationBlock->invalid) { WriteLinkBlock(e, destinationBlock); @@ -284,32 +284,32 @@ void JitBaseBlockCache::LinkBlockExits(JitBlock& b) } } -void JitBaseBlockCache::LinkBlock(JitBlock& b) +void JitBaseBlockCache::LinkBlock(JitBlock& block) { - LinkBlockExits(b); - auto ppp = links_to.equal_range(b.effectiveAddress); + LinkBlockExits(block); + auto ppp = links_to.equal_range(block.effectiveAddress); for (auto iter = ppp.first; iter != ppp.second; ++iter) { JitBlock& b2 = *iter->second; - if (b.msrBits == b2.msrBits) + if (block.msrBits == b2.msrBits) LinkBlockExits(b2); } } -void JitBaseBlockCache::UnlinkBlock(const JitBlock& b) +void JitBaseBlockCache::UnlinkBlock(const JitBlock& block) { - auto ppp = links_to.equal_range(b.effectiveAddress); + auto ppp = links_to.equal_range(block.effectiveAddress); for (auto iter = ppp.first; iter != ppp.second; ++iter) { JitBlock& sourceBlock = *iter->second; - if (sourceBlock.msrBits != b.msrBits) + if (sourceBlock.msrBits != block.msrBits) continue; for (auto& e : sourceBlock.linkData) { - if (e.exitAddress == b.effectiveAddress) + if (e.exitAddress == block.effectiveAddress) { WriteLinkBlock(e, nullptr); e.linkStatus = false; @@ -318,32 +318,32 @@ void JitBaseBlockCache::UnlinkBlock(const JitBlock& b) } } -void JitBaseBlockCache::DestroyBlock(JitBlock& b, bool invalidate) +void JitBaseBlockCache::DestroyBlock(JitBlock& block, bool invalidate) { - if (b.invalid) + if (block.invalid) { if (invalidate) - PanicAlert("Invalidating invalid block %p", &b); + PanicAlert("Invalidating invalid block %p", &block); return; } - b.invalid = true; - start_block_map.erase(b.physicalAddress); - FastLookupEntryForAddress(b.effectiveAddress) = 0; + block.invalid = true; + start_block_map.erase(block.physicalAddress); + FastLookupEntryForAddress(block.effectiveAddress) = 0; - UnlinkBlock(b); + UnlinkBlock(block); // Delete linking addresses - auto it = links_to.equal_range(b.effectiveAddress); + auto it = links_to.equal_range(block.effectiveAddress); while (it.first != it.second) { - if (it.first->second == &b) + if (it.first->second == &block) it.first = links_to.erase(it.first); else it.first++; } // Raise an signal if we are going to call this block again - WriteDestroyBlock(b); + WriteDestroyBlock(block); } void JitBaseBlockCache::MoveBlockIntoFastCache(u32 addr, u32 msr) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.h b/Source/Core/Core/PowerPC/JitCommon/JitCache.h index 6e8e8fa6f9..3ffe6b8bd8 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.h +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.h @@ -132,7 +132,7 @@ public: void RunOnBlocks(std::function f); JitBlock* AllocateBlock(u32 em_address); - void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); + void FinalizeBlock(JitBlock& block, bool block_link, const u8* code_ptr); // Look for the block in the slow but accurate way. // This function shall be used if FastLookupEntryForAddress() failed. @@ -156,10 +156,10 @@ private: virtual void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) = 0; virtual void WriteDestroyBlock(const JitBlock& block); - void LinkBlockExits(JitBlock& b); - void LinkBlock(JitBlock& b); - void UnlinkBlock(const JitBlock& b); - void DestroyBlock(JitBlock& b, bool invalidate); + void LinkBlockExits(JitBlock& block); + void LinkBlock(JitBlock& block); + void UnlinkBlock(const JitBlock& block); + void DestroyBlock(JitBlock& block, bool invalidate); void MoveBlockIntoFastCache(u32 em_address, u32 msr); From a8b26937f3e1df068a8b8af0ed5fcd88bdca071b Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 12 Jan 2017 20:24:43 +0100 Subject: [PATCH 14/14] JitCache: Clean up GetBlockFromStartAddress. --- Source/Core/Core/PowerPC/JitCommon/JitCache.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp index 4be02d1c64..93937f9e32 100644 --- a/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp +++ b/Source/Core/Core/PowerPC/JitCommon/JitCache.cpp @@ -180,14 +180,12 @@ JitBlock* JitBaseBlockCache::GetBlockFromStartAddress(u32 addr, u32 msr) auto map_result = start_block_map.find(translated_addr); if (map_result == start_block_map.end()) return nullptr; - JitBlock& b = *map_result->second; - if (b.invalid) + + JitBlock* b = map_result->second; + if (b->invalid || b->effectiveAddress != addr || + b->msrBits != (msr & JitBlock::JIT_CACHE_MSR_MASK)) return nullptr; - if (b.effectiveAddress != addr) - return nullptr; - if (b.msrBits != (msr & JitBlock::JIT_CACHE_MSR_MASK)) - return nullptr; - return &b; + return b; } const u8* JitBaseBlockCache::Dispatch()