From 796f831296d36e339574540474616ed555dde5ee Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Tue, 20 Oct 2015 18:22:28 +0200 Subject: [PATCH] pcsx2: generate an exception when recompilation failed Avoid the cost of checking -1 for a very rare case. It misses currently a good fallback --- pcsx2/R5900.h | 6 ++++++ pcsx2/x86/iCore.cpp | 23 ++++++----------------- pcsx2/x86/ix86-32/iCore-32.cpp | 12 ++++-------- pcsx2/x86/ix86-32/iR5900-32.cpp | 15 ++++++++++++++- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/pcsx2/R5900.h b/pcsx2/R5900.h index 1b8057e0a4..2cd890dcfc 100644 --- a/pcsx2/R5900.h +++ b/pcsx2/R5900.h @@ -43,6 +43,12 @@ namespace Exception public: explicit CancelInstruction() { } }; + + class FailedToAllocateRegister + { + public: + explicit FailedToAllocateRegister() { } + }; } // -------------------------------------------------------------------------------------- diff --git a/pcsx2/x86/iCore.cpp b/pcsx2/x86/iCore.cpp index 7df76a2471..14c98d04e8 100644 --- a/pcsx2/x86/iCore.cpp +++ b/pcsx2/x86/iCore.cpp @@ -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<> 18) & 0x1)); - opcode.recompile(); + try { + opcode.recompile(); + } catch (Exception::FailedToAllocateRegister&) { + // TODO: fallback to interpreter +#if 0 + iFlushCall(FLUSH_INTERPRETER); + CALLFunc( (uptr)R5900::Interpreter::OpcodeImpl::MMI::PMFHL ); +#endif + // TODO: Free register ? +#if 0 + // _freeXMMregs(); + // _freeMMXregs(); +#endif + } } if( !delayslot ) {