From 400d5f694086acf884967355ccd8bd06d238ca2c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Dec 2016 18:07:15 -0500 Subject: [PATCH 1/5] DSPEmitter: In-class initialize variables --- Source/Core/Core/DSP/Jit/DSPEmitter.cpp | 2 +- Source/Core/Core/DSP/Jit/DSPEmitter.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp index 627018adf5..4f46d36b53 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp @@ -22,7 +22,7 @@ using namespace Gen; -DSPEmitter::DSPEmitter() : gpr(*this), storeIndex(-1), storeIndex2(-1) +DSPEmitter::DSPEmitter() { AllocCodeSpace(COMPILED_CODE_SIZE); diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.h b/Source/Core/Core/DSP/Jit/DSPEmitter.h index 25aa8e3ceb..c6951f7829 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.h @@ -247,7 +247,7 @@ public: u16* blockSize; std::list unresolvedJumps[MAX_BLOCKS]; - DSPJitRegCache gpr; + DSPJitRegCache gpr{*this}; private: DSPCompiledCode* blocks; @@ -255,8 +255,8 @@ private: u16 compileSR; // The index of the last stored ext value (compile time). - int storeIndex; - int storeIndex2; + int storeIndex = -1; + int storeIndex2 = -1; // Counts down. // int cycles; From c37889efcbd9b4d723798d469c943930522cab5c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Dec 2016 19:01:45 -0500 Subject: [PATCH 2/5] DSPEmitter: Use std::vector instead of raw allocation --- Source/Core/Core/DSP/Jit/DSPEmitter.cpp | 21 +++++---------------- Source/Core/Core/DSP/Jit/DSPEmitter.h | 7 ++++--- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp index 4f46d36b53..b68b8e33ea 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp @@ -4,6 +4,7 @@ #include "Core/DSP/Jit/DSPEmitter.h" +#include #include #include "Common/Assert.h" @@ -22,14 +23,10 @@ using namespace Gen; -DSPEmitter::DSPEmitter() +DSPEmitter::DSPEmitter() : blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS) { AllocCodeSpace(COMPILED_CODE_SIZE); - blocks = new DSPCompiledCode[MAX_BLOCKS]; - blockLinks = new Block[MAX_BLOCKS]; - blockSize = new u16[MAX_BLOCKS]; - compileSR = 0; compileSR |= SR_INT_ENABLE; compileSR |= SR_EXT_INT_ENABLE; @@ -37,20 +34,12 @@ DSPEmitter::DSPEmitter() CompileDispatcher(); stubEntryPoint = CompileStub(); - // clear all of the block references - for (int i = 0x0000; i < MAX_BLOCKS; i++) - { - blocks[i] = (DSPCompiledCode)stubEntryPoint; - blockLinks[i] = nullptr; - blockSize[i] = 0; - } + // Clear all of the block references + std::fill(blocks.begin(), blocks.end(), (DSPCompiledCode)stubEntryPoint); } DSPEmitter::~DSPEmitter() { - delete[] blocks; - delete[] blockLinks; - delete[] blockSize; FreeCodeSpace(); } @@ -408,7 +397,7 @@ void DSPEmitter::CompileDispatcher() // Execute block. Cycles executed returned in EAX. MOVZX(64, 16, ECX, M(&g_dsp.pc)); - MOV(64, R(RBX), ImmPtr(blocks)); + MOV(64, R(RBX), ImmPtr(blocks.data())); JMPptr(MComplex(RBX, RCX, SCALE_8, 0)); returnDispatcher = GetCodePtr(); diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.h b/Source/Core/Core/DSP/Jit/DSPEmitter.h index c6951f7829..3db25eef1a 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include "Common/x64ABI.h" #include "Common/x64Emitter.h" @@ -243,14 +244,14 @@ public: const u8* returnDispatcher; u16 compilePC; u16 startAddr; - Block* blockLinks; - u16* blockSize; + std::vector blockLinks; + std::vector blockSize; std::list unresolvedJumps[MAX_BLOCKS]; DSPJitRegCache gpr{*this}; private: - DSPCompiledCode* blocks; + std::vector blocks; Block blockLinkEntry; u16 compileSR; From 646d96a216a799a94337f28dd312bfd72a682280 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Dec 2016 19:15:34 -0500 Subject: [PATCH 3/5] DSPEmitter: Convert defines into typed constants Also moves them into more qualified scopes where possible. --- Source/Core/Core/DSP/Jit/DSPEmitter.cpp | 5 +++-- Source/Core/Core/DSP/Jit/DSPEmitter.h | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp index b68b8e33ea..b2b0c8d9c7 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp @@ -18,8 +18,9 @@ #include "Core/DSP/DSPMemoryMap.h" #include "Core/DSP/DSPTables.h" -#define MAX_BLOCK_SIZE 250 -#define DSP_IDLE_SKIP_CYCLES 0x1000 +constexpr size_t COMPILED_CODE_SIZE = 2097152; +constexpr size_t MAX_BLOCK_SIZE = 250; +constexpr u16 DSP_IDLE_SKIP_CYCLES = 0x1000; using namespace Gen; diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.h b/Source/Core/Core/DSP/Jit/DSPEmitter.h index 3db25eef1a..9ddcfa3980 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.h @@ -4,24 +4,25 @@ #pragma once +#include #include #include +#include "Common/CommonTypes.h" #include "Common/x64ABI.h" #include "Common/x64Emitter.h" #include "Core/DSP/DSPCommon.h" #include "Core/DSP/Jit/DSPJitRegCache.h" -#define COMPILED_CODE_SIZE 2097152 -#define MAX_BLOCKS 0x10000 - typedef u32 (*DSPCompiledCode)(); typedef const u8* Block; class DSPEmitter : public Gen::X64CodeBlock { public: + static constexpr size_t MAX_BLOCKS = 0x10000; + DSPEmitter(); ~DSPEmitter(); From f3d353a85d53f9e3f606634c94fc45085fd3db3d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Dec 2016 19:19:36 -0500 Subject: [PATCH 4/5] DSPEmitter: Move typedefs into DSPEmitter Keeps them associated with the emitter itself, rather than just letting them sit in global scope. --- Source/Core/Core/DSP/DSPCore.cpp | 4 ++-- Source/Core/Core/DSP/Jit/DSPEmitter.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index d6d0e0fe6b..f3ff8d6642 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -251,8 +251,8 @@ int DSPCore_RunCycles(int cycles) } g_cycles_left = cycles; - DSPCompiledCode pExecAddr = (DSPCompiledCode)g_dsp_jit->enterDispatcher; - pExecAddr(); + auto exec_addr = (DSPEmitter::DSPCompiledCode)g_dsp_jit->enterDispatcher; + exec_addr(); if (g_dsp.reset_dspjit_codespace) g_dsp_jit->ClearIRAMandDSPJITCodespaceReset(); diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.h b/Source/Core/Core/DSP/Jit/DSPEmitter.h index 9ddcfa3980..0c4bea5422 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.h +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.h @@ -15,12 +15,12 @@ #include "Core/DSP/DSPCommon.h" #include "Core/DSP/Jit/DSPJitRegCache.h" -typedef u32 (*DSPCompiledCode)(); -typedef const u8* Block; - class DSPEmitter : public Gen::X64CodeBlock { public: + using DSPCompiledCode = u32 (*)(); + using Block = const u8*; + static constexpr size_t MAX_BLOCKS = 0x10000; DSPEmitter(); From 50b1fcb1ed5f064f46b5347c7f382f70bae858c2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Dec 2016 19:42:09 -0500 Subject: [PATCH 5/5] DSPEmitter: Initialize compileSR in the initializer list --- Source/Core/Core/DSP/Jit/DSPEmitter.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp index b2b0c8d9c7..4e4076b2ed 100644 --- a/Source/Core/Core/DSP/Jit/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/DSPEmitter.cpp @@ -24,14 +24,12 @@ constexpr u16 DSP_IDLE_SKIP_CYCLES = 0x1000; using namespace Gen; -DSPEmitter::DSPEmitter() : blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS) +DSPEmitter::DSPEmitter() + : blockLinks(MAX_BLOCKS), blockSize(MAX_BLOCKS), blocks(MAX_BLOCKS), + compileSR{SR_INT_ENABLE | SR_EXT_INT_ENABLE} { AllocCodeSpace(COMPILED_CODE_SIZE); - compileSR = 0; - compileSR |= SR_INT_ENABLE; - compileSR |= SR_EXT_INT_ENABLE; - CompileDispatcher(); stubEntryPoint = CompileStub();