Merge pull request #906 from PCSX2/try-catch-register-allocation-error

pcsx2: generate an exception when recompilation failed
This commit is contained in:
Gregory Hainaut 2015-10-21 15:16:45 +02:00
commit e5015faafa
4 changed files with 27 additions and 26 deletions

View File

@ -43,6 +43,12 @@ namespace Exception
public:
explicit CancelInstruction() { }
};
class FailedToAllocateRegister
{
public:
explicit FailedToAllocateRegister() { }
};
}
// --------------------------------------------------------------------------------------

View File

@ -133,9 +133,9 @@ int _getFreeXMMreg()
_freeXMMreg(tempi);
return tempi;
}
pxFailDev("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!");
return -1;
pxFailDev("*PCSX2*: XMM Reg Allocation Error in _getFreeXMMreg()!");
throw Exception::FailedToAllocateRegister();
}
int _allocTempXMMreg(XMMSSEType type, int xmmreg) {
@ -144,9 +144,6 @@ int _allocTempXMMreg(XMMSSEType type, int xmmreg) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_TEMP;
xmmregs[xmmreg].needed = 1;
@ -194,9 +191,6 @@ int _allocVFtoXMMreg(VURegs *VU, int xmmreg, int vfreg, int mode) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_VFREG;
@ -279,9 +273,6 @@ int _allocACCtoXMMreg(VURegs *VU, int xmmreg, int mode) {
else
_freeXMMreg(xmmreg);
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
xmmregs[xmmreg].type = XMMTYPE_ACC;
@ -322,8 +313,8 @@ int _allocFPtoXMMreg(int xmmreg, int fpreg, int mode) {
return i;
}
if (xmmreg == -1) xmmreg = _getFreeXMMreg();
if (xmmreg == -1) return -1;
if (xmmreg == -1)
xmmreg = _getFreeXMMreg();
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;
@ -388,8 +379,8 @@ int _allocGPRtoXMMreg(int xmmreg, int gprreg, int mode)
g_cpuHasConstReg &= ~(1<<gprreg);
}
if (xmmreg == -1) xmmreg = _getFreeXMMreg();
if (xmmreg == -1) return -1;
if (xmmreg == -1)
xmmreg = _getFreeXMMreg();
g_xmmtypes[xmmreg] = XMMT_INT;
xmmregs[xmmreg].inuse = 1;
@ -468,8 +459,6 @@ int _allocFPACCtoXMMreg(int xmmreg, int mode)
if (xmmreg == -1)
xmmreg = _getFreeXMMreg();
if (xmmreg == -1)
return -1;
g_xmmtypes[xmmreg] = XMMT_FPS;
xmmregs[xmmreg].inuse = 1;

View File

@ -155,8 +155,7 @@ int _getFreeX86reg(int mode)
}
pxFailDev( "x86 register allocation error" );
return -1;
throw Exception::FailedToAllocateRegister();
}
void _flushCachedRegs()
@ -311,9 +310,6 @@ int _allocX86reg(int x86reg, int type, int reg, int mode)
else
_freeX86reg(x86reg);
if (x86reg == -1)
return -1;
x86regs[x86reg].type = type;
x86regs[x86reg].reg = reg;
x86regs[x86reg].mode = mode;
@ -545,7 +541,7 @@ int _getFreeMMXreg()
}
pxFailDev( "mmx register allocation error" );
return -1;
throw Exception::FailedToAllocateRegister();
}
int _allocMMXreg(int mmxreg, int reg, int mode)
@ -586,8 +582,8 @@ int _allocMMXreg(int mmxreg, int reg, int mode)
}
}
if (mmxreg == -1) mmxreg = _getFreeMMXreg();
if (mmxreg == -1) return -1;
if (mmxreg == -1)
mmxreg = _getFreeMMXreg();
mmxregs[mmxreg].inuse = 1;
mmxregs[mmxreg].reg = reg;

View File

@ -1476,7 +1476,17 @@ void recompileNextInstruction(int delayslot)
else {
//If the COP0 DIE bit is disabled, cycles should be doubled.
s_nBlockCycles += opcode.cycles * (2 - ((cpuRegs.CP0.n.Config >> 18) & 0x1));
opcode.recompile();
try {
opcode.recompile();
} catch (Exception::FailedToAllocateRegister&) {
// Fall back to the interpreter
recCall(opcode.interpret);
#if 0
// TODO: Free register ?
// _freeXMMregs();
// _freeMMXregs();
#endif
}
}
if( !delayslot ) {