Skip to content

Commit

Permalink
Merge pull request #4857 from lioncash/global
Browse files Browse the repository at this point in the history
DSPCore: Make g_cycles_left a regular member variable of DSPEmitter
  • Loading branch information
Parlane committed Feb 8, 2017
2 parents b419219 + 4260afc commit f91290d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
2 changes: 0 additions & 2 deletions Source/Core/Core/DSP/DSPCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace DSP
SDSP g_dsp;
DSPBreakpoints g_dsp_breakpoints;
static State core_state = State::Stopped;
u16 g_cycles_left = 0;
bool g_init_hax = false;
std::unique_ptr<JIT::x86::DSPEmitter> g_dsp_jit;
std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
Expand Down Expand Up @@ -104,7 +103,6 @@ static void DSPCore_FreeMemoryPages()
bool DSPCore_Init(const DSPInitOptions& opts)
{
g_dsp.step_counter = 0;
g_cycles_left = 0;
g_init_hax = false;

g_dsp.irom = static_cast<u16*>(Common::AllocateMemoryPages(DSP_IROM_BYTE_SIZE));
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/DSP/DSPCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ struct SDSP

extern SDSP g_dsp;
extern DSPBreakpoints g_dsp_breakpoints;
extern u16 g_cycles_left;
extern bool g_init_hax;
extern std::unique_ptr<JIT::x86::DSPEmitter> g_dsp_jit;
extern std::unique_ptr<DSPCaptureLogger> g_dsp_cap;
Expand Down
12 changes: 9 additions & 3 deletions Source/Core/Core/DSP/Jit/DSPEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "Common/Assert.h"
#include "Common/BitSet.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"

Expand Down Expand Up @@ -57,14 +58,19 @@ u16 DSPEmitter::RunCycles(u16 cycles)
DSPCore_SetExternalInterrupt(false);
}

g_cycles_left = cycles;
m_cycles_left = cycles;
auto exec_addr = (DSPCompiledCode)m_enter_dispatcher;
exec_addr();

if (g_dsp.reset_dspjit_codespace)
ClearIRAMandDSPJITCodespaceReset();

return g_cycles_left;
return m_cycles_left;
}

void DSPEmitter::DoState(PointerWrap& p)
{
p.Do(m_cycles_left);
}

void DSPEmitter::ClearIRAM()
Expand Down Expand Up @@ -430,7 +436,7 @@ void DSPEmitter::CompileDispatcher()
m_return_dispatcher = GetCodePtr();

// Decrement cyclesLeft
SUB(16, M(&g_cycles_left), R(EAX));
SUB(16, M(&m_cycles_left), R(EAX));

J_CC(CC_A, dispatcherLoop);

Expand Down
6 changes: 6 additions & 0 deletions Source/Core/Core/DSP/Jit/DSPEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "Core/DSP/DSPCommon.h"
#include "Core/DSP/Jit/DSPJitRegCache.h"

class PointerWrap;

namespace DSP
{
enum class StackRegister;
Expand All @@ -36,6 +38,8 @@ class DSPEmitter : public Gen::X64CodeBlock

u16 RunCycles(u16 cycles);

void DoState(PointerWrap& p);

void EmitInstruction(UDSPInstruction inst);
void ClearIRAM();
void ClearIRAMandDSPJITCodespaceReset();
Expand Down Expand Up @@ -292,6 +296,8 @@ class DSPEmitter : public Gen::X64CodeBlock
std::vector<Block> m_block_links;
Block m_block_link_entry;

u16 m_cycles_left = 0;

// The index of the last stored ext value (compile time).
int m_store_index = -1;
int m_store_index2 = -1;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/DSP/Jit/DSPJitBranch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ void DSPEmitter::WriteBlockLink(u16 dest)
{
m_gpr.FlushRegs();
// Check if we have enough cycles to execute the next block
MOV(16, R(ECX), M(&g_cycles_left));
MOV(16, R(ECX), M(&m_cycles_left));
CMP(16, R(ECX), Imm16(m_block_size[m_start_address] + m_block_size[dest]));
FixupBranch notEnoughCycles = J_CC(CC_BE);

SUB(16, R(ECX), Imm16(m_block_size[m_start_address]));
MOV(16, M(&g_cycles_left), R(ECX));
MOV(16, M(&m_cycles_left), R(ECX));
JMP(m_block_links[dest], true);
SetJumpTarget(notEnoughCycles);
}
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/Core/HW/DSPLLE/DSPLLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ void DSPLLE::DoState(PointerWrap& p)
if (p.GetMode() == PointerWrap::MODE_READ)
Host::CodeLoaded((const u8*)g_dsp.iram, DSP_IRAM_BYTE_SIZE);
p.DoArray(g_dsp.dram, DSP_DRAM_SIZE);
p.Do(g_cycles_left);
p.Do(g_init_hax);
p.Do(m_cycle_count);

if (g_dsp_jit)
g_dsp_jit->DoState(p);
}

// Regular thread
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
static std::thread g_save_thread;

// Don't forget to increase this after doing changes on the savestate system
static const u32 STATE_VERSION = 74; // Last changed in PR 4408
static const u32 STATE_VERSION = 75; // Last changed in PR 4857

// Maps savestate versions to Dolphin versions.
// Versions after 42 don't need to be added to this list,
Expand Down

0 comments on commit f91290d

Please sign in to comment.