Skip to content

Commit

Permalink
Merge pull request #4862 from lioncash/compile
Browse files Browse the repository at this point in the history
CPU Backends: Make instruction table initialization private
  • Loading branch information
lioncash committed Feb 15, 2017
2 parents 8fd16db + 1ce1304 commit 6f272b3
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 229 deletions.
3 changes: 0 additions & 3 deletions Source/Core/Core/Core.vcxproj
Expand Up @@ -463,13 +463,10 @@
<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" />
<ClInclude Include="PowerPC\Jit64IL\JitIL.h" />
<ClInclude Include="PowerPC\Jit64IL\JitIL_Tables.h" />
<ClInclude Include="PowerPC\Jit64\FPURegCache.h" />
<ClInclude Include="PowerPC\Jit64\GPRRegCache.h" />
<ClInclude Include="PowerPC\Jit64\Jit.h" />
<ClInclude Include="PowerPC\Jit64\Jit64_Tables.h" />
<ClInclude Include="PowerPC\Jit64\JitAsm.h" />
<ClInclude Include="PowerPC\Jit64\JitRegCache.h" />
<ClInclude Include="PowerPC\JitILCommon\IR.h" />
Expand Down
9 changes: 0 additions & 9 deletions Source/Core/Core/Core.vcxproj.filters
Expand Up @@ -940,15 +940,9 @@
<ClInclude Include="PowerPC\Interpreter\Interpreter_FPUtils.h">
<Filter>PowerPC\Interpreter</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Interpreter\Interpreter_Tables.h">
<Filter>PowerPC\Interpreter</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Jit64\Jit.h">
<Filter>PowerPC\Jit64</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Jit64\Jit64_Tables.h">
<Filter>PowerPC\Jit64</Filter>
</ClInclude>
<ClInclude Include="HW\AudioInterface.h">
<Filter>HW %28Flipper/Hollywood%29\AI - Audio Interface</Filter>
</ClInclude>
Expand Down Expand Up @@ -1261,9 +1255,6 @@
<ClInclude Include="PowerPC\Jit64IL\JitIL.h">
<Filter>PowerPC\JitIL</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Jit64IL\JitIL_Tables.h">
<Filter>PowerPC\JitIL</Filter>
</ClInclude>
<ClInclude Include="PowerPC\Jit64\FPURegCache.h">
<Filter>PowerPC\Jit64</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -63,6 +63,7 @@ void Interpreter::RunTable63(UGeckoInstruction inst)

void Interpreter::Init()
{
InitializeInstructionTables();
m_reserve = false;
m_end_block = false;
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter.h
Expand Up @@ -282,6 +282,8 @@ class Interpreter : public CPUCoreBase
static u32 Helper_Carry(u32 value1, u32 value2);

private:
static void InitializeInstructionTables();

// flag helper
static void Helper_UpdateCR0(u32 value);
static void Helper_UpdateCR1();
Expand Down
36 changes: 16 additions & 20 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter_Tables.cpp
Expand Up @@ -6,7 +6,6 @@

#include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/Interpreter/Interpreter.h"
#include "Core/PowerPC/Interpreter/Interpreter_Tables.h"
#include "Core/PowerPC/PPCTables.h"

struct GekkoOPTemplate
Expand Down Expand Up @@ -355,8 +354,6 @@ static std::array<GekkoOPTemplate, 10> table63_2 =
}};
// clang-format on

namespace InterpreterTables
{
constexpr size_t TotalInstructionFunctionCount()
{
return primarytable.size() + table4_2.size() + table4_3.size() + table4.size() + table31.size() +
Expand All @@ -366,7 +363,7 @@ constexpr size_t TotalInstructionFunctionCount()
static_assert(TotalInstructionFunctionCount() < m_allInstructions.size(),
"m_allInstructions is too small");

void InitTables()
void Interpreter::InitializeInstructionTables()
{
// once initialized, tables are read-only
static bool initialized = false;
Expand All @@ -376,22 +373,22 @@ void InitTables()
// clear
for (int i = 0; i < 64; i++)
{
Interpreter::m_op_table[i] = Interpreter::unknown_instruction;
m_op_table[i] = Interpreter::unknown_instruction;
m_infoTable[i] = &unknownopinfo;
}

for (int i = 0; i < 32; i++)
{
Interpreter::m_op_table59[i] = Interpreter::unknown_instruction;
m_op_table59[i] = Interpreter::unknown_instruction;
m_infoTable59[i] = &unknownopinfo;
}

for (int i = 0; i < 1024; i++)
{
Interpreter::m_op_table4[i] = Interpreter::unknown_instruction;
Interpreter::m_op_table19[i] = Interpreter::unknown_instruction;
Interpreter::m_op_table31[i] = Interpreter::unknown_instruction;
Interpreter::m_op_table63[i] = Interpreter::unknown_instruction;
m_op_table4[i] = Interpreter::unknown_instruction;
m_op_table19[i] = Interpreter::unknown_instruction;
m_op_table31[i] = Interpreter::unknown_instruction;
m_op_table63[i] = Interpreter::unknown_instruction;
m_infoTable4[i] = &unknownopinfo;
m_infoTable19[i] = &unknownopinfo;
m_infoTable31[i] = &unknownopinfo;
Expand All @@ -400,7 +397,7 @@ void InitTables()

for (auto& tpl : primarytable)
{
Interpreter::m_op_table[tpl.opcode] = tpl.Inst;
m_op_table[tpl.opcode] = tpl.Inst;
m_infoTable[tpl.opcode] = &tpl.opinfo;
}

Expand All @@ -410,7 +407,7 @@ void InitTables()
for (auto& tpl : table4_2)
{
int op = fill + tpl.opcode;
Interpreter::m_op_table4[op] = tpl.Inst;
m_op_table4[op] = tpl.Inst;
m_infoTable4[op] = &tpl.opinfo;
}
}
Expand All @@ -421,43 +418,43 @@ void InitTables()
for (auto& tpl : table4_3)
{
int op = fill + tpl.opcode;
Interpreter::m_op_table4[op] = tpl.Inst;
m_op_table4[op] = tpl.Inst;
m_infoTable4[op] = &tpl.opinfo;
}
}

for (auto& tpl : table4)
{
int op = tpl.opcode;
Interpreter::m_op_table4[op] = tpl.Inst;
m_op_table4[op] = tpl.Inst;
m_infoTable4[op] = &tpl.opinfo;
}

for (auto& tpl : table31)
{
int op = tpl.opcode;
Interpreter::m_op_table31[op] = tpl.Inst;
m_op_table31[op] = tpl.Inst;
m_infoTable31[op] = &tpl.opinfo;
}

for (auto& tpl : table19)
{
int op = tpl.opcode;
Interpreter::m_op_table19[op] = tpl.Inst;
m_op_table19[op] = tpl.Inst;
m_infoTable19[op] = &tpl.opinfo;
}

for (auto& tpl : table59)
{
int op = tpl.opcode;
Interpreter::m_op_table59[op] = tpl.Inst;
m_op_table59[op] = tpl.Inst;
m_infoTable59[op] = &tpl.opinfo;
}

for (auto& tpl : table63)
{
int op = tpl.opcode;
Interpreter::m_op_table63[op] = tpl.Inst;
m_op_table63[op] = tpl.Inst;
m_infoTable63[op] = &tpl.opinfo;
}

Expand All @@ -467,7 +464,7 @@ void InitTables()
for (auto& tpl : table63_2)
{
int op = fill + tpl.opcode;
Interpreter::m_op_table63[op] = tpl.Inst;
m_op_table63[op] = tpl.Inst;
m_infoTable63[op] = &tpl.opinfo;
}
}
Expand All @@ -494,4 +491,3 @@ void InitTables()

initialized = true;
}
} // namespace InterpreterTables
10 changes: 0 additions & 10 deletions Source/Core/Core/PowerPC/Interpreter/Interpreter_Tables.h

This file was deleted.

7 changes: 4 additions & 3 deletions Source/Core/Core/PowerPC/Jit64/Jit.cpp
Expand Up @@ -2,6 +2,8 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Core/PowerPC/Jit64/Jit.h"

#include <map>
#include <string>

Expand All @@ -22,8 +24,6 @@
#include "Core/HW/GPFifo.h"
#include "Core/HW/ProcessorInterface.h"
#include "Core/PatchEngine.h"
#include "Core/PowerPC/Jit64/Jit.h"
#include "Core/PowerPC/Jit64/Jit64_Tables.h"
#include "Core/PowerPC/Jit64/JitAsm.h"
#include "Core/PowerPC/Jit64/JitRegCache.h"
#include "Core/PowerPC/Jit64Common/FarCodeCache.h"
Expand Down Expand Up @@ -216,6 +216,7 @@ bool Jit64::HandleFault(uintptr_t access_address, SContext* ctx)

void Jit64::Init()
{
InitializeInstructionTables();
EnableBlockLink();

jo.optimizeGatherPipe = true;
Expand Down Expand Up @@ -874,7 +875,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc
fpr.BindToRegister(reg, true, false);
}

Jit64Tables::CompileInstruction(*this, ops[i]);
CompileInstruction(ops[i]);

if (jo.memcheck && (opinfo->flags & FL_LOADSTORE))
{
Expand Down
44 changes: 22 additions & 22 deletions Source/Core/Core/PowerPC/Jit64/Jit.h
Expand Up @@ -31,37 +31,18 @@

class Jit64 : public Jitx86Base
{
private:
void AllocStack();
void FreeStack();

GPRRegCache gpr{*this};
FPURegCache fpr{*this};

// The default code buffer. We keep it around to not have to alloc/dealloc a
// large chunk of memory for each recompiled block.
PPCAnalyst::CodeBuffer code_buffer;
Jit64AsmRoutineManager asm_routines;

bool m_enable_blr_optimization;
bool m_cleanup_after_stackfault;
u8* m_stack;

public:
Jit64() : code_buffer(32000) {}
~Jit64() {}
void Init() override;

void EnableOptimization();

void EnableBlockLink();

void Shutdown() override;

bool HandleFault(uintptr_t access_address, SContext* ctx) override;

bool HandleStackFault() override;

void EnableOptimization();
void EnableBlockLink();

// Jit!

void Jit(u32 em_address) override;
Expand Down Expand Up @@ -248,4 +229,23 @@ class Jit64 : public Jitx86Base
void dcbx(UGeckoInstruction inst);

void eieio(UGeckoInstruction inst);

private:
static void InitializeInstructionTables();
void CompileInstruction(PPCAnalyst::CodeOp& op);

void AllocStack();
void FreeStack();

GPRRegCache gpr{*this};
FPURegCache fpr{*this};

// The default code buffer. We keep it around to not have to alloc/dealloc a
// large chunk of memory for each recompiled block.
PPCAnalyst::CodeBuffer code_buffer;
Jit64AsmRoutineManager asm_routines;

bool m_enable_blr_optimization;
bool m_cleanup_after_stackfault;
u8* m_stack;
};
16 changes: 6 additions & 10 deletions Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp
Expand Up @@ -4,7 +4,6 @@

#include "Core/PowerPC/Jit64/Jit.h"
#include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/Jit64/Jit64_Tables.h"

static Jit64::Instruction dynaOpTable[64];
static Jit64::Instruction dynaOpTable4[1024];
Expand Down Expand Up @@ -358,26 +357,25 @@ static GekkoOPTemplate table63_2[] = {
{31, &Jit64::fmaddXX}, // fnmaddx
};

namespace Jit64Tables
void Jit64::CompileInstruction(PPCAnalyst::CodeOp& op)
{
void CompileInstruction(Jit64& jit, PPCAnalyst::CodeOp& op)
{
(jit.*dynaOpTable[op.inst.OPCD])(op.inst);
(this->*dynaOpTable[op.inst.OPCD])(op.inst);

GekkoOPInfo* info = op.opinfo;
if (info)
{
#ifdef OPLOG
if (!strcmp(info->opname, OP_TO_LOG)) // "mcrfs"
{
rsplocations.push_back(jit.js.compilerPC);
rsplocations.push_back(js.compilerPC);
}
#endif
info->compileCount++;
info->lastUse = jit.js.compilerPC;
info->lastUse = js.compilerPC;
}
}

void InitTables()
void Jit64::InitializeInstructionTables()
{
// once initialized, tables are read-only
static bool initialized = false;
Expand Down Expand Up @@ -470,5 +468,3 @@ void InitTables()

initialized = true;
}

} // namespace
18 changes: 0 additions & 18 deletions Source/Core/Core/PowerPC/Jit64/Jit64_Tables.h

This file was deleted.

0 comments on commit 6f272b3

Please sign in to comment.