Permalink
Browse files

SafeMem: Remove the "far" optimization that saves 3 bytes sometimes b…

…ut is really dangerous and not worth the complexity.
  • Loading branch information...
hrydgard committed Aug 30, 2017
1 parent ee6086c commit 884aef66039495a1b93cfb18f27f5d72cd5725ae
Showing with 2 additions and 22 deletions.
  1. +0 −1 Core/MIPS/x86/CompLoadStore.cpp
  2. +0 −6 Core/MIPS/x86/CompVFPU.cpp
  3. +1 −9 Core/MIPS/x86/JitSafeMem.cpp
  4. +1 −6 Core/MIPS/x86/JitSafeMem.h
@@ -162,7 +162,6 @@ namespace MIPSComp {
{
JitSafeMem safe(this, rs, offset, ~3);
safe.SetFar();
OpArg src;
if (safe.PrepareRead(src, 4))
{
@@ -252,7 +252,6 @@ void Jit::Comp_SV(MIPSOpcode op) {
fpr.MapRegV(vt, MAP_DIRTY | MAP_NOINIT);
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg src;
if (safe.PrepareRead(src, 4)) {
MOVSS(fpr.VX(vt), safe.NextFastAddress(0));
@@ -274,7 +273,6 @@ void Jit::Comp_SV(MIPSOpcode op) {
fpr.MapRegV(vt, 0);
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg dest;
if (safe.PrepareWrite(dest, 4)) {
MOVSS(safe.NextFastAddress(0), fpr.VX(vt));
@@ -391,7 +389,6 @@ void Jit::Comp_SVQ(MIPSOpcode op) {
if (fpr.TryMapRegsVS(vregs, V_Quad, MAP_NOINIT | MAP_DIRTY)) {
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg src;
if (safe.PrepareRead(src, 16)) {
// Should be safe, since lv.q must be aligned, but let's try to avoid crashing in safe mode.
@@ -421,7 +418,6 @@ void Jit::Comp_SVQ(MIPSOpcode op) {
fpr.MapRegsV(vregs, V_Quad, MAP_DIRTY | MAP_NOINIT);
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg src;
if (safe.PrepareRead(src, 16)) {
// Just copy 4 words the easiest way while not wasting registers.
@@ -454,7 +450,6 @@ void Jit::Comp_SVQ(MIPSOpcode op) {
if (fpr.TryMapRegsVS(vregs, V_Quad, 0)) {
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg dest;
if (safe.PrepareWrite(dest, 16)) {
// Should be safe, since sv.q must be aligned, but let's try to avoid crashing in safe mode.
@@ -482,7 +477,6 @@ void Jit::Comp_SVQ(MIPSOpcode op) {
fpr.MapRegsV(vregs, V_Quad, 0);
JitSafeMem safe(this, rs, imm);
safe.SetFar();
OpArg dest;
if (safe.PrepareWrite(dest, 16)) {
for (int i = 0; i < 4; i++)
@@ -53,8 +53,6 @@ void JitMemCheckCleanup()
JitSafeMem::JitSafeMem(Jit *jit, MIPSGPReg raddr, s32 offset, u32 alignMask)
: jit_(jit), raddr_(raddr), offset_(offset), needsCheck_(false), needsSkip_(false), alignMask_(alignMask)
{
// This makes it more instructions, so let's play it safe and say we need a far jump.
far_ = !g_Config.bIgnoreBadMemAccess || !CBreakPoints::GetMemChecks().empty();
// Mask out the kernel RAM bit, because we'll end up with a negative offset to MEMBASEREG.
if (jit_->gpr.IsImm(raddr_))
iaddr_ = (jit_->gpr.GetImm(raddr_) + offset_) & 0x7FFFFFFF;
@@ -70,12 +68,6 @@ JitSafeMem::JitSafeMem(Jit *jit, MIPSGPReg raddr, s32 offset, u32 alignMask)
jit_->gpr.MapReg(raddr_, true, false);
}
void JitSafeMem::SetFar()
{
_dbg_assert_msg_(JIT, !needsSkip_, "Sorry, you need to call SetFar() earlier.");
far_ = true;
}
bool JitSafeMem::PrepareWrite(OpArg &dest, int size)
{
size_ = size;
@@ -222,7 +214,7 @@ OpArg JitSafeMem::PrepareMemoryOpArg(MemoryOpType type)
void JitSafeMem::PrepareSlowAccess()
{
// Skip the fast path (which the caller wrote just now.)
skip_ = jit_->J(far_);
skip_ = jit_->J(true);
needsSkip_ = true;
jit_->SetJumpTarget(tooLow_);
jit_->SetJumpTarget(tooHigh_);
@@ -29,8 +29,6 @@ class JitSafeMem {
public:
JitSafeMem(Jit *jit, MIPSGPReg raddr, s32 offset, u32 alignMask = 0xFFFFFFFF);
static void Init(Jit *jit);
// Emit code necessary for a memory write, returns true if MOV to dest is needed.
bool PrepareWrite(Gen::OpArg &dest, int size);
// Emit code proceeding a slow write call, returns true if slow write is needed.
@@ -54,8 +52,6 @@ class JitSafeMem {
// Cleans up final code for the memory access.
void Finish();
// Use this before anything else if you're gonna use the below.
void SetFar();
// WARNING: Only works for non-GPR. Do not use for reads into GPR.
Gen::OpArg NextFastAddress(int suboffset);
// WARNING: Only works for non-GPR. Do not use for reads into GPR.
@@ -83,7 +79,6 @@ class JitSafeMem {
int size_;
bool needsCheck_;
bool needsSkip_;
bool far_;
bool fast_;
u32 alignMask_;
u32 iaddr_;
@@ -124,4 +119,4 @@ class JitSafeMemFuncs : public Gen::XCodeBlock
ThunkManager *thunks_;
};
};
};

2 comments on commit 884aef6

@twinaphex

This comment has been minimized.

Show comment
Hide comment
@twinaphex

twinaphex Aug 30, 2017

Contributor

Still getting what seems to be a PIC error when running the PPSSPP core with FastMem turned off -

34:24:418 user_main E[SYSTEM]: Common/MsgHandler.cpp:61 Warning: WriteRest: op out of range (0x41ae18da uses 0x7fdf1bd38318)
[libretro ERROR] E Warning: WriteRest: op out of range (0x41ae18da uses 0x7fdf1bd38318)

Contributor

twinaphex replied Aug 30, 2017

Still getting what seems to be a PIC error when running the PPSSPP core with FastMem turned off -

34:24:418 user_main E[SYSTEM]: Common/MsgHandler.cpp:61 Warning: WriteRest: op out of range (0x41ae18da uses 0x7fdf1bd38318)
[libretro ERROR] E Warning: WriteRest: op out of range (0x41ae18da uses 0x7fdf1bd38318)

@hrydgard

This comment has been minimized.

Show comment
Hide comment
@hrydgard

hrydgard Aug 30, 2017

Owner

Thanks for reporting, hm, that's curious...

Owner

hrydgard replied Aug 30, 2017

Thanks for reporting, hm, that's curious...

Please sign in to comment.