Просмотр исходного кода

Favor switch case over jump table

Easier to read and will emit a jump table automatically.
David Marcec 6 лет назад
Родитель
Сommit
8118ea160b
2 измененных файлов с 26 добавлено и 18 удалено
  1. 25 18
      src/video_core/macro/macro_jit_x64.cpp
  2. 1 0
      src/video_core/macro/macro_jit_x64.h

+ 25 - 18
src/video_core/macro/macro_jit_x64.cpp

@@ -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());
-
-    if (InstructionTable[op] == nullptr) {
-        UNIMPLEMENTED_MSG("Unimplemented opcode {}", op);
-    } else {
-        ((*this).*InstructionTable[op])(opcode);
+    switch (opcode.operation) {
+    case Macro::Operation::ALU:
+        Compile_ALU(opcode);
+        break;
+    case Macro::Operation::AddImmediate:
+        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) {

+ 1 - 0
src/video_core/macro/macro_jit_x64.h

@@ -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);