yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Favor switch case over jump table

Easier to read and will emit a jump table automatically.
This commit is contained in:
David Marcec 2020-05-30 12:23:58 +10:00
parent b032ebdfee
commit 8118ea160b
2 changed files with 26 additions and 18 deletions

View File

@ -14,18 +14,6 @@ MICROPROFILE_DEFINE(MacroJitCompile, "GPU", "Compile macro JIT", MP_RGB(173, 255
MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255, 0)); MICROPROFILE_DEFINE(MacroJitExecute, "GPU", "Execute macro JIT", MP_RGB(255, 255, 0));
namespace Tegra { namespace Tegra {
using JitFunction = void (MacroJITx64Impl::*)(Macro::Opcode opcode);
const std::array<JitFunction, 8> InstructionTable{
&MacroJITx64Impl::Compile_ALU,
&MacroJITx64Impl::Compile_AddImmediate,
&MacroJITx64Impl::Compile_ExtractInsert,
&MacroJITx64Impl::Compile_ExtractShiftLeftImmediate,
&MacroJITx64Impl::Compile_ExtractShiftLeftRegister,
&MacroJITx64Impl::Compile_Read,
nullptr,
&MacroJITx64Impl::Compile_Branch,
};
static const Xbyak::Reg64 PARAMETERS = Xbyak::util::r9; static const Xbyak::Reg64 PARAMETERS = Xbyak::util::r9;
static const Xbyak::Reg64 REGISTERS = Xbyak::util::r10; static const Xbyak::Reg64 REGISTERS = Xbyak::util::r10;
static const Xbyak::Reg64 STATE = Xbyak::util::r11; static const Xbyak::Reg64 STATE = Xbyak::util::r11;
@ -489,12 +477,31 @@ bool MacroJITx64Impl::Compile_NextInstruction() {
L(labels[pc]); L(labels[pc]);
const std::size_t op = static_cast<std::size_t>(opcode.operation.Value()); switch (opcode.operation) {
case Macro::Operation::ALU:
if (InstructionTable[op] == nullptr) { Compile_ALU(opcode);
UNIMPLEMENTED_MSG("Unimplemented opcode {}", op); break;
} else { case Macro::Operation::AddImmediate:
((*this).*InstructionTable[op])(opcode); Compile_AddImmediate(opcode);
break;
case Macro::Operation::ExtractInsert:
Compile_ExtractInsert(opcode);
break;
case Macro::Operation::ExtractShiftLeftImmediate:
Compile_ExtractShiftLeftImmediate(opcode);
break;
case Macro::Operation::ExtractShiftLeftRegister:
Compile_ExtractShiftLeftRegister(opcode);
break;
case Macro::Operation::Read:
Compile_Read(opcode);
break;
case Macro::Operation::Branch:
Compile_Branch(opcode);
break;
default:
UNIMPLEMENTED_MSG("Unimplemented opcode {}", opcode.operation.Value());
break;
} }
if (optimizer.has_delayed_pc) { if (optimizer.has_delayed_pc) {

View File

@ -35,6 +35,7 @@ class MacroJITx64Impl : public Xbyak::CodeGenerator, public CachedMacro {
public: public:
MacroJITx64Impl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code); MacroJITx64Impl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code);
~MacroJITx64Impl(); ~MacroJITx64Impl();
void Execute(std::vector<u32>& parameters, u32 method) override; void Execute(std::vector<u32>& parameters, u32 method) override;
void Compile_ALU(Macro::Opcode opcode); void Compile_ALU(Macro::Opcode opcode);