Merge pull request #3186 from lioncash/dsp

DSPJitRegCache: Minor changes
This commit is contained in:
Scott Mansell 2015-10-29 10:29:26 +13:00
commit 1984416df4
2 changed files with 62 additions and 59 deletions

View File

@ -10,6 +10,12 @@
using namespace Gen; using namespace Gen;
// Ordered in order of prefered use.
// Not all of these are actually available
const std::array<X64Reg, 15> DSPJitRegCache::m_allocation_order = {{
R8, R9, R10, R11, R12, R13, R14, R15, RSI, RDI, RBX, RCX, RDX, RAX, RBP
}};
static void* GetRegisterPointer(size_t reg) static void* GetRegisterPointer(size_t reg)
{ {
switch (reg) switch (reg)
@ -943,17 +949,11 @@ void DSPJitRegCache::WriteReg(int dreg, OpArg arg)
PutReg(dreg, true); PutReg(dreg, true);
} }
//ordered in order of prefered use
//not all of these are actually available
static X64Reg alloc_order[] = {
R8,R9,R10,R11,R12,R13,R14,R15,RSI,RDI,RBX,RCX,RDX,RAX,RBP
};
X64Reg DSPJitRegCache::SpillXReg() X64Reg DSPJitRegCache::SpillXReg()
{ {
int max_use_ctr_diff = 0; int max_use_ctr_diff = 0;
X64Reg least_recent_use_reg = INVALID_REG; X64Reg least_recent_use_reg = INVALID_REG;
for (X64Reg reg : alloc_order) for (X64Reg reg : m_allocation_order)
{ {
if (xregs[reg].guest_reg <= DSP_REG_MAX_MEM_BACKED && if (xregs[reg].guest_reg <= DSP_REG_MAX_MEM_BACKED &&
!regs[xregs[reg].guest_reg].used) !regs[xregs[reg].guest_reg].used)
@ -974,7 +974,7 @@ X64Reg DSPJitRegCache::SpillXReg()
} }
//just choose one. //just choose one.
for (X64Reg reg : alloc_order) for (X64Reg reg : m_allocation_order)
{ {
if (xregs[reg].guest_reg <= DSP_REG_MAX_MEM_BACKED && if (xregs[reg].guest_reg <= DSP_REG_MAX_MEM_BACKED &&
!regs[xregs[reg].guest_reg].used) !regs[xregs[reg].guest_reg].used)
@ -1007,13 +1007,14 @@ void DSPJitRegCache::SpillXReg(X64Reg reg)
X64Reg DSPJitRegCache::FindFreeXReg() X64Reg DSPJitRegCache::FindFreeXReg()
{ {
for (X64Reg x : alloc_order) for (X64Reg x : m_allocation_order)
{ {
if (xregs[x].guest_reg == DSP_REG_NONE) if (xregs[x].guest_reg == DSP_REG_NONE)
{ {
return x; return x;
} }
} }
return INVALID_REG; return INVALID_REG;
} }

View File

@ -32,56 +32,6 @@ enum DSPJitSignExtend
class DSPJitRegCache class DSPJitRegCache
{ {
private:
struct X64CachedReg
{
size_t guest_reg; //including DSPJitRegSpecial
bool pushed;
};
struct DynamicReg
{
Gen::OpArg loc;
void *mem;
size_t size;
bool dirty;
bool used;
int last_use_ctr;
int parentReg;
int shift;//current shift if parentReg == DSP_REG_NONE
//otherwise the shift this part can be found at
Gen::X64Reg host_reg;
/* TODO:
+ drop sameReg
+ add parentReg
+ add shift:
- if parentReg != DSP_REG_NONE, this is the shift where this
register is found in the parentReg
- if parentReg == DSP_REG_NONE, this is the current shift _state_
*/
};
std::array<DynamicReg, 37> regs;
std::array<X64CachedReg, 16> xregs;
DSPEmitter &emitter;
bool temporary;
bool merged;
int use_ctr;
private:
// Find a free host reg
Gen::X64Reg FindFreeXReg();
Gen::X64Reg SpillXReg();
Gen::X64Reg FindSpillFreeXReg();
void SpillXReg(Gen::X64Reg reg);
void MovToHostReg(size_t reg, Gen::X64Reg host_reg, bool load);
void MovToHostReg(size_t reg, bool load);
void RotateHostReg(size_t reg, int shift, bool emit);
void MovToMemory(size_t reg);
void FlushMemBackedRegs();
public: public:
DSPJitRegCache(DSPEmitter &_emitter); DSPJitRegCache(DSPEmitter &_emitter);
@ -176,4 +126,56 @@ public:
void GetXReg(Gen::X64Reg reg); void GetXReg(Gen::X64Reg reg);
// Unreserve the given host reg // Unreserve the given host reg
void PutXReg(Gen::X64Reg reg); void PutXReg(Gen::X64Reg reg);
private:
struct X64CachedReg
{
size_t guest_reg; // Including DSPJitRegSpecial
bool pushed;
};
struct DynamicReg
{
Gen::OpArg loc;
void *mem;
size_t size;
bool dirty;
bool used;
int last_use_ctr;
int parentReg;
int shift; // Current shift if parentReg == DSP_REG_NONE
// otherwise the shift this part can be found at
Gen::X64Reg host_reg;
// TODO:
// + drop sameReg
// + add parentReg
// + add shift:
// - if parentReg != DSP_REG_NONE, this is the shift where this
// register is found in the parentReg
// - if parentReg == DSP_REG_NONE, this is the current shift _state_
};
// Find a free host reg
Gen::X64Reg FindFreeXReg();
Gen::X64Reg SpillXReg();
Gen::X64Reg FindSpillFreeXReg();
void SpillXReg(Gen::X64Reg reg);
void MovToHostReg(size_t reg, Gen::X64Reg host_reg, bool load);
void MovToHostReg(size_t reg, bool load);
void RotateHostReg(size_t reg, int shift, bool emit);
void MovToMemory(size_t reg);
void FlushMemBackedRegs();
static const std::array<Gen::X64Reg, 15> m_allocation_order;
std::array<DynamicReg, 37> regs;
std::array<X64CachedReg, 16> xregs;
DSPEmitter& emitter;
bool temporary;
bool merged;
int use_ctr;
}; };