Last active
August 29, 2015 14:10
-
-
Save unknownbrackets/3fa04f58e09118541179 to your computer and use it in GitHub Desktop.
SanityCheck for SIMD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int GetMRMtx(int mr) { | |
if (mr < 32) | |
return -1; | |
if (mr >= 128 + 32) | |
return -1; | |
return ((mr - 32) >> 2) & 7; | |
} | |
static int GetMRRow(int mr) { | |
if (mr < 32) | |
return -1; | |
if (mr >= 128 + 32) | |
return -1; | |
return ((mr - 32) >> 0) & 3; | |
} | |
static int GetMRCol(int mr) { | |
if (mr < 32) | |
return -1; | |
if (mr >= 128 + 32) | |
return -1; | |
return ((mr - 32) >> 5) & 3; | |
} | |
static bool IsMRTemp(int mr) { | |
return mr >= 128 + 32; | |
} | |
int FPURegCache::SanityCheck() const { | |
for (int i = 0; i < NUM_MIPS_FPRS; i++) { | |
const MIPSCachedFPReg &mr = regs[i]; | |
// FPR can never have imms. | |
if (mr.location.IsImm()) | |
return 1; | |
bool reallyAway = mr.location.IsSimpleReg(); | |
if (reallyAway != mr.away) | |
return 2; | |
if (mr.lane < 0 || mr.lane > 4) | |
return 3; | |
if (mr.lane != 0 && !reallyAway) | |
return 4; | |
if (mr.away) { | |
Gen::X64Reg simple = mr.location.GetSimpleReg(); | |
if (mr.lane == 0) { | |
if (xregs[simple].mipsReg != i) | |
return 5; | |
for (int j = 1; j < 4; ++j) { | |
if (xregs[simple].mipsRegs[j] != -1) | |
return 6; | |
} | |
} else { | |
if (xregs[simple].mipsRegs[mr.lane - 1] != i) | |
return 7; | |
} | |
} | |
} | |
for (int i = 0; i < NUM_X_FPREGS; ++i) { | |
const X64CachedFPReg &xr = xregs[i]; | |
bool hasReg = xr.mipsReg != -1; | |
if (!hasReg && xr.dirty) | |
return 8; | |
bool hasMoreRegs = hasReg; | |
int mtx = -2; | |
int row = -2; | |
int col = -2; | |
bool rowMatched = true; | |
bool colMatched = true; | |
for (int j = 0; j < 4; ++j) { | |
if (xr.mipsRegs[j] == -1) { | |
hasMoreRegs = false; | |
continue; | |
} | |
// We can't have a hole in the middle / front. | |
if (!hasMoreRegs) | |
return 9; | |
const MIPSCachedFPReg &mr = regs[xr.mipsRegs[j]]; | |
if (!mr.location.IsSimpleReg(X64Reg(i))) | |
return 10; | |
if (!IsMRTemp(xr.mipsRegs[j])) { | |
if (mtx == -2) | |
mtx = GetMRMtx(xr.mipsRegs[j]); | |
else if (mtx != GetMRMtx(xr.mipsRegs[j])) | |
return 11; | |
if (row == -2) | |
row = GetMRRow(xr.mipsRegs[j]); | |
else if (row != GetMRRow(xr.mipsRegs[j])) | |
rowMatched = false; | |
if (col == -2) | |
col = GetMRCol(xr.mipsRegs[j]); | |
else if (col != GetMRCol(xr.mipsRegs[j])) | |
colMatched = false; | |
} | |
} | |
if (!rowMatched && !colMatched) { | |
return 12; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment