Skip to content

Commit

Permalink
Merge pull request #4637 from lioncash/jitcache
Browse files Browse the repository at this point in the history
JitCache: Get rid of reliance on the JIT global variable
  • Loading branch information
degasus committed Jan 9, 2017
2 parents 8227994 + 37d1006 commit 440a2f8
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 132 deletions.
3 changes: 2 additions & 1 deletion Source/Core/Core/CMakeLists.txt
Expand Up @@ -167,6 +167,8 @@ set(SRCS ActionReplay.cpp
PowerPC/SignatureDB/DSYSignatureDB.cpp
PowerPC/SignatureDB/SignatureDB.cpp
PowerPC/JitInterface.cpp
PowerPC/CachedInterpreter/CachedInterpreter.cpp
PowerPC/CachedInterpreter/InterpreterBlockCache.cpp
PowerPC/Interpreter/Interpreter_Branch.cpp
PowerPC/Interpreter/Interpreter.cpp
PowerPC/Interpreter/Interpreter_FloatingPoint.cpp
Expand All @@ -179,7 +181,6 @@ set(SRCS ActionReplay.cpp
PowerPC/JitCommon/JitAsmCommon.cpp
PowerPC/JitCommon/JitBase.cpp
PowerPC/JitCommon/JitCache.cpp
PowerPC/CachedInterpreter.cpp
PowerPC/JitILCommon/IR.cpp
PowerPC/JitILCommon/JitILBase_Branch.cpp
PowerPC/JitILCommon/JitILBase_LoadStore.cpp
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Core/Core.vcxproj
Expand Up @@ -204,6 +204,8 @@
<ClCompile Include="NetPlayClient.cpp" />
<ClCompile Include="NetPlayServer.cpp" />
<ClCompile Include="PatchEngine.cpp" />
<ClCompile Include="PowerPC\CachedInterpreter\CachedInterpreter.cpp" />
<ClCompile Include="PowerPC\CachedInterpreter\InterpreterBlockCache.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter_Branch.cpp" />
<ClCompile Include="PowerPC\Interpreter\Interpreter_FloatingPoint.cpp" />
Expand Down Expand Up @@ -251,7 +253,6 @@
<ClCompile Include="PowerPC\SignatureDB\CSVSignatureDB.cpp" />
<ClCompile Include="PowerPC\SignatureDB\DSYSignatureDB.cpp" />
<ClCompile Include="PowerPC\SignatureDB\SignatureDB.cpp" />
<ClCompile Include="PowerPC\CachedInterpreter.cpp" />
<ClCompile Include="PowerPC\JitInterface.cpp" />
<ClCompile Include="PowerPC\MMU.cpp" />
<ClCompile Include="PowerPC\PowerPC.cpp" />
Expand Down Expand Up @@ -424,6 +425,8 @@
<ClInclude Include="PatchEngine.h" />
<ClInclude Include="PowerPC\CPUCoreBase.h" />
<ClInclude Include="PowerPC\Gekko.h" />
<ClInclude Include="PowerPC\CachedInterpreter\CachedInterpreter.h" />
<ClInclude Include="PowerPC\CachedInterpreter\InterpreterBlockCache.h" />
<ClInclude Include="PowerPC\Interpreter\Interpreter.h" />
<ClInclude Include="PowerPC\Interpreter\Interpreter_FPUtils.h" />
<ClInclude Include="PowerPC\Interpreter\Interpreter_Tables.h" />
Expand Down Expand Up @@ -451,7 +454,6 @@
<ClInclude Include="PowerPC\SignatureDB\CSVSignatureDB.h" />
<ClInclude Include="PowerPC\SignatureDB\DSYSignatureDB.h" />
<ClInclude Include="PowerPC\SignatureDB\SignatureDB.h" />
<ClInclude Include="PowerPC\CachedInterpreter.h" />
<ClInclude Include="PowerPC\JitInterface.h" />
<ClInclude Include="PowerPC\PowerPC.h" />
<ClInclude Include="PowerPC\PPCAnalyst.h" />
Expand Down
21 changes: 15 additions & 6 deletions Source/Core/Core/Core.vcxproj.filters
Expand Up @@ -31,6 +31,9 @@
<Filter Include="PowerPC">
<UniqueIdentifier>{ebd24590-dfdc-433e-a411-21723e4b7cb5}</UniqueIdentifier>
</Filter>
<Filter Include="PowerPC\Cached Interpreter">
<UniqueIdentifier>{d6410c05-51f9-422a-83d5-f0723e34b607}</UniqueIdentifier>
</Filter>
<Filter Include="PowerPC\Interpreter">
<UniqueIdentifier>{523f8d77-4aa6-4762-8f27-96f02b5070b4}</UniqueIdentifier>
</Filter>
Expand Down Expand Up @@ -273,6 +276,12 @@
<ClCompile Include="HLE\HLE_OS.cpp">
<Filter>HLE</Filter>
</ClCompile>
<ClCompile Include="PowerPC\CachedInterpreter\CachedInterpreter.cpp">
<Filter>PowerPC\Cached Interpreter</Filter>
</ClCompile>
<ClCompile Include="PowerPC\CachedInterpreter\InterpreterBlockCache.cpp">
<Filter>PowerPC\Cached Interpreter</Filter>
</ClCompile>
<ClCompile Include="PowerPC\Interpreter\Interpreter.cpp">
<Filter>PowerPC\Interpreter</Filter>
</ClCompile>
Expand Down Expand Up @@ -624,9 +633,6 @@
<ClCompile Include="HW\Wiimote.cpp">
<Filter>HW %28Flipper/Hollywood%29\Wiimote</Filter>
</ClCompile>
<ClCompile Include="PowerPC\CachedInterpreter.cpp">
<Filter>PowerPC</Filter>
</ClCompile>
<ClCompile Include="PowerPC\JitInterface.cpp">
<Filter>PowerPC</Filter>
</ClCompile>
Expand Down Expand Up @@ -869,6 +875,12 @@
<ClInclude Include="HLE\HLE_OS.h">
<Filter>HLE</Filter>
</ClInclude>
<ClInclude Include="PowerPC\CachedInterpreter\CachedInterpreter.h">
<Filter>PowerPC\Cached Interpreter</Filter>
</ClInclude>
<ClInclude Include="PowerPC\CachedInterpreter\InterpreterBlockCache.h">
<Filter>PowerPC\Cached Interpreter</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Interpreter\Interpreter.h">
<Filter>PowerPC\Interpreter</Filter>
</ClInclude>
Expand Down Expand Up @@ -1229,9 +1241,6 @@
<ClInclude Include="PowerPC\Gekko.h">
<Filter>PowerPC</Filter>
</ClInclude>
<ClInclude Include="PowerPC\CachedInterpreter.h">
<Filter>PowerPC</Filter>
</ClInclude>
<ClInclude Include="PowerPC\JitInterface.h">
<Filter>PowerPC</Filter>
</ClInclude>
Expand Down
Expand Up @@ -2,7 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Core/PowerPC/CachedInterpreter.h"
#include "Core/PowerPC/CachedInterpreter/CachedInterpreter.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"
Expand All @@ -20,7 +20,7 @@ void CachedInterpreter::Init()

jo.enableBlocklink = false;

JitBaseBlockCache::Init();
m_block_cache.Init();
UpdateMemoryOptions();

code_block.m_stats = &js.st;
Expand All @@ -30,12 +30,12 @@ void CachedInterpreter::Init()

void CachedInterpreter::Shutdown()
{
JitBaseBlockCache::Shutdown();
m_block_cache.Shutdown();
}

void CachedInterpreter::ExecuteOneBlock()
{
const u8* normal_entry = JitBaseBlockCache::Dispatch();
const u8* normal_entry = m_block_cache.Dispatch();
const Instruction* code = reinterpret_cast<const Instruction*>(normal_entry);

for (; code->type != Instruction::INSTRUCTION_ABORT; ++code)
Expand Down Expand Up @@ -123,7 +123,7 @@ static bool CheckDSI(u32 data)

void CachedInterpreter::Jit(u32 address)
{
if (m_code.size() >= CODE_SIZE / sizeof(Instruction) - 0x1000 || IsFull() ||
if (m_code.size() >= CODE_SIZE / sizeof(Instruction) - 0x1000 || m_block_cache.IsFull() ||
SConfig::GetInstance().bJITNoBlockCache)
{
ClearCache();
Expand All @@ -140,8 +140,8 @@ void CachedInterpreter::Jit(u32 address)
return;
}

int block_num = AllocateBlock(PC);
JitBlock* b = GetBlock(block_num);
int block_num = m_block_cache.AllocateBlock(PC);
JitBlock* b = m_block_cache.GetBlock(block_num);

js.blockStart = PC;
js.firstFPInstructionFound = false;
Expand Down Expand Up @@ -212,12 +212,12 @@ void CachedInterpreter::Jit(u32 address)
b->codeSize = (u32)(GetCodePtr() - b->checkedEntry);
b->originalSize = code_block.m_num_instructions;

FinalizeBlock(block_num, jo.enableBlocklink, b->checkedEntry);
m_block_cache.FinalizeBlock(block_num, jo.enableBlocklink, b->checkedEntry);
}

void CachedInterpreter::ClearCache()
{
m_code.clear();
JitBaseBlockCache::Clear();
m_block_cache.Clear();
UpdateMemoryOptions();
}
Expand Up @@ -7,10 +7,11 @@
#include <vector>

#include "Common/CommonTypes.h"
#include "Core/PowerPC/CachedInterpreter/InterpreterBlockCache.h"
#include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/PPCAnalyst.h"

class CachedInterpreter : public JitBase, JitBaseBlockCache
class CachedInterpreter : public JitBase
{
public:
CachedInterpreter() : code_buffer(32000) {}
Expand All @@ -26,9 +27,8 @@ class CachedInterpreter : public JitBase, JitBaseBlockCache

void Jit(u32 address) override;

JitBaseBlockCache* GetBlockCache() override { return this; }
JitBaseBlockCache* GetBlockCache() override { return &m_block_cache; }
const char* GetName() override { return "Cached Interpreter"; }
void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) override {}
const CommonAsmRoutinesBase* GetAsmRoutines() override { return nullptr; }
private:
struct Instruction
Expand Down Expand Up @@ -59,6 +59,7 @@ class CachedInterpreter : public JitBase, JitBaseBlockCache
const u8* GetCodePtr() { return (u8*)(m_code.data() + m_code.size()); }
void ExecuteOneBlock();

BlockCache m_block_cache{*this};
std::vector<Instruction> m_code;
PPCAnalyst::CodeBuffer code_buffer;
};
@@ -0,0 +1,14 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Core/PowerPC/CachedInterpreter/InterpreterBlockCache.h"
#include "Core/PowerPC/JitCommon/JitBase.h"

BlockCache::BlockCache(JitBase& jit) : JitBaseBlockCache{jit}
{
}

void BlockCache::WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest)
{
}
18 changes: 18 additions & 0 deletions Source/Core/Core/PowerPC/CachedInterpreter/InterpreterBlockCache.h
@@ -0,0 +1,18 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include "Core/PowerPC/JitCommon/JitCache.h"

class JitBase;

class BlockCache final : public JitBaseBlockCache
{
public:
explicit BlockCache(JitBase& jit);

private:
void WriteLinkBlock(const JitBlock::LinkData& source, const JitBlock* dest) override;
};
6 changes: 5 additions & 1 deletion Source/Core/Core/PowerPC/Jit64Common/BlockCache.cpp
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/PowerPC/Jit64Common/BlockCache.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Jit64Common/Jit64Base.h
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/JitArm64/Jit.h
Expand Up @@ -178,7 +178,7 @@ class JitArm64 : public JitBase, public Arm64Gen::ARM64CodeBlock, public CommonA
Arm64GPRCache gpr;
Arm64FPRCache fpr;

JitArm64BlockCache blocks;
JitArm64BlockCache blocks{*this};

PPCAnalyst::CodeBuffer code_buffer;

Expand Down
7 changes: 6 additions & 1 deletion Source/Core/Core/PowerPC/JitArm64/JitArm64Cache.cpp
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64Cache.h
Expand Up @@ -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;
Expand Down

0 comments on commit 440a2f8

Please sign in to comment.