JitCache: Get rid of reliance on the JIT global variable

This commit is contained in:
Lioncash 2017-01-08 23:12:40 -05:00
parent f75aab1a85
commit 37d10064b8
11 changed files with 45 additions and 13 deletions

View File

@ -59,7 +59,7 @@ private:
const u8* GetCodePtr() { return (u8*)(m_code.data() + m_code.size()); }
void ExecuteOneBlock();
BlockCache m_block_cache;
BlockCache m_block_cache{*this};
std::vector<Instruction> m_code;
PPCAnalyst::CodeBuffer code_buffer;
};

View File

@ -3,8 +3,11 @@
// Refer to the license.txt file included.
#include "Core/PowerPC/CachedInterpreter/InterpreterBlockCache.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
BlockCache::BlockCache() = default;
BlockCache::BlockCache(JitBase& jit) : JitBaseBlockCache{jit}
{
}
void BlockCache::WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest)
{

View File

@ -6,10 +6,12 @@
#include "Core/PowerPC/JitCommon/JitCache.h"
class JitBase;
class BlockCache final : public JitBaseBlockCache
{
public:
BlockCache();
explicit BlockCache(JitBase& jit);
private:
void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) override;

View File

@ -8,10 +8,14 @@
#include "Common/x64Emitter.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
JitBlockCache::JitBlockCache(JitBase& jit) : JitBaseBlockCache{jit}
{
}
void JitBlockCache::WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest)
{
u8* location = source.exitPtrs;
const u8* address = dest ? dest->checkedEntry : g_jit->GetAsmRoutines()->dispatcher;
const u8* address = dest ? dest->checkedEntry : m_jit.GetAsmRoutines()->dispatcher;
Gen::XEmitter emit(location);
if (*location == 0xE8)
{

View File

@ -6,8 +6,13 @@
#include "Core/PowerPC/JitCommon/JitCache.h"
class JitBase;
class JitBlockCache : public JitBaseBlockCache
{
public:
explicit JitBlockCache(JitBase& jit);
private:
void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) override;
void WriteDestroyBlock(const JitBlock& block) override;

View File

@ -39,7 +39,7 @@ class Jitx86Base : public JitBase, public QuantizedMemoryRoutines
{
protected:
bool BackPatch(u32 emAddress, SContext* ctx);
JitBlockCache blocks;
JitBlockCache blocks{*this};
TrampolineCache trampolines;
public:

View File

@ -178,7 +178,7 @@ private:
Arm64GPRCache gpr;
Arm64FPRCache fpr;
JitArm64BlockCache blocks;
JitArm64BlockCache blocks{*this};
PPCAnalyst::CodeBuffer code_buffer;

View File

@ -5,8 +5,13 @@
#include "Core/PowerPC/JitArm64/Jit.h"
#include "Common/CommonTypes.h"
#include "Core/PowerPC/JitArm64/JitArm64Cache.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/JitInterface.h"
JitArm64BlockCache::JitArm64BlockCache(JitBase& jit) : JitBaseBlockCache{jit}
{
}
void JitArm64BlockCache::WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest)
{
u8* location = source.exitPtrs;
@ -28,7 +33,7 @@ void JitArm64BlockCache::WriteLinkBlock(const JitBlock::LinkData& source, const
else
{
emit.MOVI2R(DISPATCHER_PC, source.exitAddress);
emit.B(g_jit->GetAsmRoutines()->dispatcher);
emit.B(m_jit.GetAsmRoutines()->dispatcher);
}
emit.FlushIcache();
}

View File

@ -6,10 +6,15 @@
#include "Core/PowerPC/JitCommon/JitCache.h"
class JitBase;
typedef void (*CompiledCode)();
class JitArm64BlockCache : public JitBaseBlockCache
{
public:
explicit JitArm64BlockCache(JitBase& jit);
private:
void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) override;
void WriteDestroyBlock(const JitBlock& block) override;

View File

@ -35,7 +35,10 @@ static void ClearCacheThreadSafe(u64 userdata, s64 cyclesdata)
JitInterface::ClearCache();
}
JitBaseBlockCache::JitBaseBlockCache() = default;
JitBaseBlockCache::JitBaseBlockCache(JitBase& jit) : m_jit{jit}
{
}
JitBaseBlockCache::~JitBaseBlockCache() = default;
void JitBaseBlockCache::Init()
@ -64,8 +67,8 @@ void JitBaseBlockCache::Clear()
else
Core::DisplayMessage("Clearing code cache.", 3000);
#endif
g_jit->js.fifoWriteAddresses.clear();
g_jit->js.pairedQuantizeAddresses.clear();
m_jit.js.fifoWriteAddresses.clear();
m_jit.js.pairedQuantizeAddresses.clear();
for (int i = 1; i < num_blocks; i++)
{
DestroyBlock(i, false);
@ -244,8 +247,8 @@ void JitBaseBlockCache::InvalidateICache(u32 address, const u32 length, bool for
{
for (u32 i = address; i < address + length; i += 4)
{
g_jit->js.fifoWriteAddresses.erase(i);
g_jit->js.pairedQuantizeAddresses.erase(i);
m_jit.js.fifoWriteAddresses.erase(i);
m_jit.js.pairedQuantizeAddresses.erase(i);
}
}
}

View File

@ -12,6 +12,8 @@
#include "Common/CommonTypes.h"
class JitBase;
// A JitBlock is block of compiled code which corresponds to the PowerPC
// code at a given address.
//
@ -112,7 +114,7 @@ public:
static constexpr u32 iCache_Num_Elements = 0x10000;
static constexpr u32 iCache_Mask = iCache_Num_Elements - 1;
JitBaseBlockCache();
explicit JitBaseBlockCache(JitBase& jit);
virtual ~JitBaseBlockCache();
void Init();
@ -146,6 +148,9 @@ public:
u32* GetBlockBitSet() const;
protected:
JitBase& m_jit;
private:
virtual void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) = 0;
virtual void WriteDestroyBlock(const JitBlock& block);