Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make spu_decoder<> objects constexpr #7844

Merged
merged 2 commits into from Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,7 +1,7 @@

version: '{build}'

image: Visual Studio 2019
image: Previous Visual Studio 2019

environment:
QTDIR: C:\Qt\5.14\msvc2017_64
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp
Expand Up @@ -22,8 +22,8 @@
#define SPU_OFF_16(x, ...) asmjit::x86::word_ptr(*cpu, offset32(&spu_thread::x, ##__VA_ARGS__))
#define SPU_OFF_8(x, ...) asmjit::x86::byte_ptr(*cpu, offset32(&spu_thread::x, ##__VA_ARGS__))

extern const spu_decoder<spu_interpreter_fast> g_spu_interpreter_fast; // TODO: avoid
const spu_decoder<spu_recompiler> s_spu_decoder;
constexpr spu_decoder<spu_interpreter_fast> g_spu_interpreter_fast; // TODO: avoid
constexpr spu_decoder<spu_recompiler> s_spu_decoder;

extern u64 get_timebased_time();

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPUDisAsm.cpp
@@ -1,7 +1,7 @@
#include "stdafx.h"
#include "SPUDisAsm.h"

const spu_decoder<SPUDisAsm> s_spu_disasm;
constexpr spu_decoder<SPUDisAsm> s_spu_disasm;

u32 SPUDisAsm::disasm(u32 pc)
{
Expand Down
8 changes: 2 additions & 6 deletions rpcs3/Emu/Cell/SPUInterpreter.cpp
Expand Up @@ -1691,7 +1691,7 @@ bool spu_interpreter::SELB(spu_thread& spu, spu_opcode_t op)
return true;
}

static bool SHUFB_(spu_thread& spu, spu_opcode_t op)
bool spu_interpreter::SHUFB(spu_thread& spu, spu_opcode_t op)
{
__m128i ab[2]{spu.gpr[op.rb].vi, spu.gpr[op.ra].vi};
v128 c = spu.gpr[op.rc];
Expand All @@ -1714,7 +1714,7 @@ static bool SHUFB_(spu_thread& spu, spu_opcode_t op)
return true;
}

const spu_inter_func_t spu_interpreter::SHUFB = !utils::has_ssse3() ? &SHUFB_ : build_function_asm<spu_inter_func_t>([](asmjit::X86Assembler& c, auto& args)
const spu_inter_func_t optimized_shufb = build_function_asm<spu_inter_func_t>([](asmjit::X86Assembler& c, auto& args)
{
using namespace asmjit;

Expand Down Expand Up @@ -2645,7 +2645,3 @@ bool spu_interpreter_precise::FNMS(spu_thread& spu, spu_opcode_t op) { ::FMA(spu
bool spu_interpreter_precise::FMA(spu_thread& spu, spu_opcode_t op) { ::FMA(spu, op, false, false); return true; }

bool spu_interpreter_precise::FMS(spu_thread& spu, spu_opcode_t op) { ::FMA(spu, op, false, true); return true; }

extern const spu_decoder<spu_interpreter_precise> g_spu_interpreter_precise{};

extern const spu_decoder<spu_interpreter_fast> g_spu_interpreter_fast{};
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPUInterpreter.h
Expand Up @@ -175,7 +175,7 @@ struct spu_interpreter
static bool HBRR(spu_thread&, spu_opcode_t);
static bool ILA(spu_thread&, spu_opcode_t);
static bool SELB(spu_thread&, spu_opcode_t);
static const spu_inter_func_t SHUFB;
static bool SHUFB(spu_thread&, spu_opcode_t);
static bool MPYA(spu_thread&, spu_opcode_t);
static bool DFCGT(spu_thread&, spu_opcode_t);
static bool DFCMGT(spu_thread&, spu_opcode_t);
Expand Down
19 changes: 8 additions & 11 deletions rpcs3/Emu/Cell/SPUOpcodes.h
Expand Up @@ -46,22 +46,22 @@ template <typename D, typename T = decltype(&D::UNK)>
class spu_decoder
{
// Fast lookup table
std::array<T, 2048> m_table;
std::array<T, 2048> m_table{};

struct instruction_info
{
u32 magn; // Count = 2 ^ magn
u32 value;
T pointer;

instruction_info(u32 m, u32 v, T p)
constexpr instruction_info(u32 m, u32 v, T p)
: magn(m)
, value(v)
, pointer(p)
{
}

instruction_info(u32 m, u32 v, const T* p)
constexpr instruction_info(u32 m, u32 v, const T* p)
: magn(m)
, value(v)
, pointer(*p)
Expand All @@ -70,7 +70,7 @@ class spu_decoder
};

public:
spu_decoder()
constexpr spu_decoder()
{
const std::initializer_list<instruction_info> instructions
{
Expand Down Expand Up @@ -275,7 +275,10 @@ class spu_decoder
{ 7, 0xf, &D::FMS },
};

m_table.fill(&D::UNK);
for (auto& x : m_table)
{
x = &D::UNK;
}

for (auto& entry : instructions)
{
Expand All @@ -286,12 +289,6 @@ class spu_decoder
}
}

template <typename F>
spu_decoder(F&& init) : spu_decoder()
{
init(m_table);
}

const std::array<T, 2048>& get_table() const
{
return m_table;
Expand Down
25 changes: 15 additions & 10 deletions rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -22,12 +22,12 @@ extern atomic_t<const char*> g_progr;
extern atomic_t<u32> g_progr_ptotal;
extern atomic_t<u32> g_progr_pdone;

const spu_decoder<spu_itype> s_spu_itype;
const spu_decoder<spu_iname> s_spu_iname;
const spu_decoder<spu_iflag> s_spu_iflag;
constexpr spu_decoder<spu_itype> s_spu_itype;
constexpr spu_decoder<spu_iname> s_spu_iname;
constexpr spu_decoder<spu_iflag> s_spu_iflag;

extern const spu_decoder<spu_interpreter_precise> g_spu_interpreter_precise;
extern const spu_decoder<spu_interpreter_fast> g_spu_interpreter_fast;
constexpr spu_decoder<spu_interpreter_precise> g_spu_interpreter_precise;
constexpr spu_decoder<spu_interpreter_fast> g_spu_interpreter_fast;

extern u64 get_timebased_time();

Expand Down Expand Up @@ -4603,7 +4603,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
}

// Execute recompiler function (TODO)
(this->*g_decoder.decode(op))({op});
(this->*decode(op))({op});
}

// Finalize block with fallthrough if necessary
Expand Down Expand Up @@ -4999,7 +4999,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
if (itype & spu_itype::branch)
{
// Instruction changes pc - change order.
(this->*g_decoder.decode(op))({op});
(this->*decode(op))({op});

if (m_interp_bblock)
{
Expand Down Expand Up @@ -5030,7 +5030,7 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
}

// Normal instruction.
(this->*g_decoder.decode(op))({op});
(this->*decode(op))({op});

if (check && !m_ir->GetInsertBlock()->getTerminator())
{
Expand Down Expand Up @@ -8277,15 +8277,20 @@ class spu_llvm_recompiler : public spu_recompiler_base, public cpu_translator
}
}

static const spu_decoder<spu_llvm_recompiler> g_decoder;
static decltype(&spu_llvm_recompiler::UNK) decode(u32 op);
};

std::unique_ptr<spu_recompiler_base> spu_recompiler_base::make_llvm_recompiler(u8 magn)
{
return std::make_unique<spu_llvm_recompiler>(magn);
}

DECLARE(spu_llvm_recompiler::g_decoder);
constexpr spu_decoder<spu_llvm_recompiler> g_spu_llvm_decoder;

decltype(&spu_llvm_recompiler::UNK) spu_llvm_recompiler::decode(u32 op)
{
return g_spu_llvm_decoder.decode(op);
}

#else

Expand Down