From ec7432ef36836f09f5181c0e280aac114ac6dd05 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 22 Dec 2022 17:31:29 -0800 Subject: [PATCH] Jit64_Tables: Use C++20 features --- .../Core/Core/PowerPC/Jit64/Jit64_Tables.cpp | 106 +++++++++--------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp b/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp index 482303f70d..d17d009865 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit64_Tables.cpp @@ -5,17 +5,19 @@ #include +#include "Common/Assert.h" +#include "Common/TypeUtils.h" #include "Core/PowerPC/Gekko.h" namespace { -struct GekkoOPTemplate +struct Jit64OpTemplate { u32 opcode; Jit64::Instruction fn; }; -constexpr std::array s_primary_table{{ +constexpr std::array s_primary_table{{ {4, &Jit64::DynaRunTable4}, // RunTable4 {19, &Jit64::DynaRunTable19}, // RunTable19 {31, &Jit64::DynaRunTable31}, // RunTable31 @@ -85,7 +87,7 @@ constexpr std::array s_primary_table{{ // missing: 0, 1, 2, 5, 6, 9, 22, 30, 62, 58 }}; -constexpr std::array s_table4{{ +constexpr std::array s_table4{{ // SUBOP10 {0, &Jit64::ps_cmpXX}, // ps_cmpu0 {32, &Jit64::ps_cmpXX}, // ps_cmpo0 @@ -103,7 +105,7 @@ constexpr std::array s_table4{{ {1014, &Jit64::FallBackToInterpreter}, // dcbz_l }}; -constexpr std::array s_table4_2{{ +constexpr std::array s_table4_2{{ {10, &Jit64::ps_sum}, // ps_sum0 {11, &Jit64::ps_sum}, // ps_sum1 {12, &Jit64::ps_muls}, // ps_muls0 @@ -123,14 +125,14 @@ constexpr std::array s_table4_2{{ {31, &Jit64::fmaddXX}, // ps_nmadd }}; -constexpr std::array s_table4_3{{ +constexpr std::array s_table4_3{{ {6, &Jit64::psq_lXX}, // psq_lx {7, &Jit64::psq_stXX}, // psq_stx {38, &Jit64::psq_lXX}, // psq_lux {39, &Jit64::psq_stXX}, // psq_stux }}; -constexpr std::array s_table19{{ +constexpr std::array s_table19{{ {528, &Jit64::bcctrx}, // bcctrx {16, &Jit64::bclrx}, // bclrx {257, &Jit64::crXXX}, // crand @@ -148,7 +150,7 @@ constexpr std::array s_table19{{ {50, &Jit64::rfi}, // rfi }}; -constexpr std::array s_table31{{ +constexpr std::array s_table31{{ {266, &Jit64::addx}, // addx {778, &Jit64::addx}, // addox {10, &Jit64::addx}, // addcx @@ -290,7 +292,7 @@ constexpr std::array s_table31{{ {566, &Jit64::DoNothing}, // tlbsync }}; -constexpr std::array s_table59{{ +constexpr std::array s_table59{{ {18, &Jit64::fp_arith}, // fdivsx {20, &Jit64::fp_arith}, // fsubsx {21, &Jit64::fp_arith}, // faddsx @@ -302,7 +304,7 @@ constexpr std::array s_table59{{ {31, &Jit64::fmaddXX}, // fnmaddsx }}; -constexpr std::array s_table63{{ +constexpr std::array s_table63{{ {264, &Jit64::fsign}, // fabsx {32, &Jit64::fcmpX}, // fcmpo {0, &Jit64::fcmpX}, // fcmpu @@ -321,7 +323,7 @@ constexpr std::array s_table63{{ {711, &Jit64::mtfsfx}, // mtfsfx }}; -constexpr std::array s_table63_2{{ +constexpr std::array s_table63_2{{ {18, &Jit64::fp_arith}, // fdivx {20, &Jit64::fp_arith}, // fsubx {21, &Jit64::fp_arith}, // faddx @@ -334,38 +336,25 @@ constexpr std::array s_table63_2{{ {31, &Jit64::fmaddXX}, // fnmaddx }}; -// TODO: This can be replaced with: -// -// table.fill(&Jit64::FallbackToInterpreter); -// -// whenever we end up migrating to C++20. Prior to C++20, -// std::array's fill() function is, unfortunately, not constexpr. -// Ditto for 's std::fill. Thus, this function exists -// to bridge the gap. -template -constexpr void FillWithFallbacks(std::array& table) +constexpr std::array s_dyna_op_table = []() consteval { - for (auto& entry : table) - { - entry = &Jit64::FallBackToInterpreter; - } -} - -constexpr std::array s_dyna_op_table = [] { std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (auto& tpl : s_primary_table) { + ASSERT(table[tpl.opcode] == &Jit64::FallBackToInterpreter); table[tpl.opcode] = tpl.fn; } return table; -}(); +} +(); -constexpr std::array s_dyna_op_table4 = [] { +constexpr std::array s_dyna_op_table4 = []() consteval +{ std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (u32 i = 0; i < 32; i++) { @@ -373,6 +362,7 @@ constexpr std::array s_dyna_op_table4 = [] { for (const auto& tpl : s_table4_2) { const u32 op = fill + tpl.opcode; + ASSERT(table[op] == &Jit64::FallBackToInterpreter); table[op] = tpl.fn; } } @@ -383,6 +373,7 @@ constexpr std::array s_dyna_op_table4 = [] { for (const auto& tpl : s_table4_3) { const u32 op = fill + tpl.opcode; + ASSERT(table[op] == &Jit64::FallBackToInterpreter); table[op] = tpl.fn; } } @@ -390,59 +381,68 @@ constexpr std::array s_dyna_op_table4 = [] { for (const auto& tpl : s_table4) { const u32 op = tpl.opcode; + ASSERT(table[op] == &Jit64::FallBackToInterpreter); table[op] = tpl.fn; } return table; -}(); +} +(); -constexpr std::array s_dyna_op_table19 = [] { +constexpr std::array s_dyna_op_table19 = []() consteval +{ std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (const auto& tpl : s_table19) { - const u32 op = tpl.opcode; - table[op] = tpl.fn; + ASSERT(table[tpl.opcode] == &Jit64::FallBackToInterpreter); + table[tpl.opcode] = tpl.fn; } return table; -}(); +} +(); -constexpr std::array s_dyna_op_table31 = [] { +constexpr std::array s_dyna_op_table31 = []() consteval +{ std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (const auto& tpl : s_table31) { - const u32 op = tpl.opcode; - table[op] = tpl.fn; + ASSERT(table[tpl.opcode] == &Jit64::FallBackToInterpreter); + table[tpl.opcode] = tpl.fn; } return table; -}(); +} +(); -constexpr std::array s_dyna_op_table59 = [] { +constexpr std::array s_dyna_op_table59 = []() consteval +{ std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (const auto& tpl : s_table59) { - const u32 op = tpl.opcode; - table[op] = tpl.fn; + ASSERT(table[tpl.opcode] == &Jit64::FallBackToInterpreter); + table[tpl.opcode] = tpl.fn; } return table; -}(); +} +(); -constexpr std::array s_dyna_op_table63 = [] { +constexpr std::array s_dyna_op_table63 = []() consteval +{ std::array table{}; - FillWithFallbacks(table); + Common::Fill(table, &Jit64::FallBackToInterpreter); for (const auto& tpl : s_table63) { - const u32 op = tpl.opcode; - table[op] = tpl.fn; + ASSERT(table[tpl.opcode] == &Jit64::FallBackToInterpreter); + table[tpl.opcode] = tpl.fn; } for (u32 i = 0; i < 32; i++) @@ -451,12 +451,14 @@ constexpr std::array s_dyna_op_table63 = [] { for (const auto& tpl : s_table63_2) { const u32 op = fill + tpl.opcode; + ASSERT(table[op] == &Jit64::FallBackToInterpreter); table[op] = tpl.fn; } } return table; -}(); +} +(); } // Anonymous namespace