RegCache64: Use std::array

This commit is contained in:
degasus 2014-06-02 13:13:21 +02:00
parent 6089812482
commit 8693e0abaa
2 changed files with 18 additions and 16 deletions

View File

@ -11,22 +11,22 @@ using namespace PowerPC;
RegCache::RegCache() : emit(nullptr) RegCache::RegCache() : emit(nullptr)
{ {
memset(regs, 0, sizeof(regs));
memset(xregs, 0, sizeof(xregs));
} }
void RegCache::Start(PPCAnalyst::BlockRegStats &stats) void RegCache::Start(PPCAnalyst::BlockRegStats &stats)
{ {
for (int i = 0; i < NUMXREGS; i++) for (auto& xreg : xregs)
{ {
xregs[i].free = true; xreg.free = true;
xregs[i].dirty = false; xreg.dirty = false;
xregs[i].locked = false; xreg.locked = false;
xreg.ppcReg = -1;
} }
for (int i = 0; i < 32; i++) for (int i = 0; i < (int)regs.size(); i++)
{ {
regs[i].location = GetDefaultLocation(i); regs[i].location = GetDefaultLocation(i);
regs[i].away = false; regs[i].away = false;
regs[i].locked = false;
} }
// todo: sort to find the most popular regs // todo: sort to find the most popular regs
@ -113,7 +113,7 @@ X64Reg RegCache::GetFreeXReg()
void RegCache::FlushR(X64Reg reg) void RegCache::FlushR(X64Reg reg)
{ {
if (reg >= NUMXREGS) if (reg >= xregs.size())
PanicAlert("Flushing non existent reg"); PanicAlert("Flushing non existent reg");
if (!xregs[reg].free) if (!xregs[reg].free)
{ {
@ -123,7 +123,7 @@ void RegCache::FlushR(X64Reg reg)
int RegCache::SanityCheck() const int RegCache::SanityCheck() const
{ {
for (int i = 0; i < 32; i++) for (int i = 0; i < (int)regs.size(); i++)
{ {
if (regs[i].away) if (regs[i].away)
{ {
@ -243,7 +243,7 @@ void GPRRegCache::BindToRegister(int i, bool doLoad, bool makeDirty)
OpArg newloc = ::Gen::R(xr); OpArg newloc = ::Gen::R(xr);
if (doLoad) if (doLoad)
emit->MOV(32, newloc, regs[i].location); emit->MOV(32, newloc, regs[i].location);
for (int j = 0; j < 32; j++) for (int j = 0; j < (int)regs.size(); j++)
{ {
if (i != j && regs[j].location.IsSimpleReg() && regs[j].location.GetSimpleReg() == xr) if (i != j && regs[j].location.IsSimpleReg() && regs[j].location.GetSimpleReg() == xr)
{ {
@ -299,7 +299,7 @@ void FPURegCache::BindToRegister(int i, bool doLoad, bool makeDirty)
{ {
// Reg is at home in the memory register file. Let's pull it out. // Reg is at home in the memory register file. Let's pull it out.
X64Reg xr = GetFreeXReg(); X64Reg xr = GetFreeXReg();
_assert_msg_(DYNA_REC, xr < NUMXREGS, "WTF - load - invalid reg"); _assert_msg_(DYNA_REC, xr < xregs.size(), "WTF - load - invalid reg");
xregs[xr].ppcReg = i; xregs[xr].ppcReg = i;
xregs[xr].free = false; xregs[xr].free = false;
xregs[xr].dirty = makeDirty; xregs[xr].dirty = makeDirty;
@ -328,7 +328,7 @@ void FPURegCache::StoreFromRegister(int i)
if (regs[i].away) if (regs[i].away)
{ {
X64Reg xr = regs[i].location.GetSimpleReg(); X64Reg xr = regs[i].location.GetSimpleReg();
_assert_msg_(DYNA_REC, xr < NUMXREGS, "WTF - store - invalid reg"); _assert_msg_(DYNA_REC, xr < xregs.size(), "WTF - store - invalid reg");
OpArg newLoc = GetDefaultLocation(i); OpArg newLoc = GetDefaultLocation(i);
if (xregs[xr].dirty) if (xregs[xr].dirty)
emit->MOVAPD(newLoc, xr); emit->MOVAPD(newLoc, xr);
@ -342,13 +342,13 @@ void FPURegCache::StoreFromRegister(int i)
void RegCache::Flush() void RegCache::Flush()
{ {
for (int i = 0; i < NUMXREGS; i++) for (int i = 0; i < (int)xregs.size(); i++)
{ {
if (xregs[i].locked) if (xregs[i].locked)
PanicAlert("Someone forgot to unlock X64 reg %i.", i); PanicAlert("Someone forgot to unlock X64 reg %i.", i);
} }
for (int i = 0; i < 32; i++) for (int i = 0; i < (int)regs.size(); i++)
{ {
if (regs[i].locked) if (regs[i].locked)
{ {

View File

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <array>
#include "Common/x64Emitter.h" #include "Common/x64Emitter.h"
using namespace Gen; using namespace Gen;
@ -35,8 +37,8 @@ typedef int PReg;
class RegCache class RegCache
{ {
protected: protected:
PPCCachedReg regs[32]; std::array<PPCCachedReg, 32> regs;
X64CachedReg xregs[NUMXREGS]; std::array<X64CachedReg, NUMXREGS> xregs;
virtual const int *GetAllocationOrder(int &count) = 0; virtual const int *GetAllocationOrder(int &count) = 0;