Skip to content

Commit

Permalink
JitArm64: Fix lwbrx/lhbrx with optimized MMIO access
Browse files Browse the repository at this point in the history
  • Loading branch information
JosJuice committed Jul 1, 2021
1 parent 2409d30 commit d3ef5d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
27 changes: 3 additions & 24 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp
Expand Up @@ -15,6 +15,7 @@

#include "Core/HW/Memmap.h"
#include "Core/PowerPC/JitArm64/Jit.h"
#include "Core/PowerPC/JitArm64/Jit_Util.h"
#include "Core/PowerPC/JitArmCommon/BackPatch.h"
#include "Core/PowerPC/MMU.h"
#include "Core/PowerPC/PowerPC.h"
Expand Down Expand Up @@ -120,16 +121,7 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR
else if (flags & BackPatchInfo::FLAG_SIZE_8)
LDRB(RS, MEM_REG, addr);

if (!(flags & BackPatchInfo::FLAG_REVERSE))
{
if (flags & BackPatchInfo::FLAG_SIZE_32)
REV32(RS, RS);
else if (flags & BackPatchInfo::FLAG_SIZE_16)
REV16(RS, RS);
}

if (flags & BackPatchInfo::FLAG_EXTEND)
SXTH(RS, RS);
ByteswapAfterLoad(this, RS, RS, flags, true, false);
}
}
const u8* fastmem_end = GetCodePtr();
Expand Down Expand Up @@ -235,20 +227,7 @@ void JitArm64::EmitBackpatchRoutine(u32 flags, bool fastmem, bool do_farcode, AR

BLR(ARM64Reg::X8);

if (!(flags & BackPatchInfo::FLAG_REVERSE))
{
MOV(RS, ARM64Reg::W0);
}
else
{
if (flags & BackPatchInfo::FLAG_SIZE_32)
REV32(RS, ARM64Reg::W0);
else if (flags & BackPatchInfo::FLAG_SIZE_16)
REV16(RS, ARM64Reg::W0);
}

if (flags & BackPatchInfo::FLAG_EXTEND)
SXTH(RS, RS);
ByteswapAfterLoad(this, RS, ARM64Reg::W0, flags, false, false);
}

m_float_emit.ABI_PopRegisters(fprs_to_push, ARM64Reg::X30);
Expand Down
29 changes: 29 additions & 0 deletions Source/Core/Core/PowerPC/JitArm64/Jit_Util.cpp
Expand Up @@ -192,6 +192,33 @@ class MMIOReadCodeGenerator : public MMIO::ReadHandlingMethodVisitor<T>
bool m_sign_extend;
};

void ByteswapAfterLoad(ARM64XEmitter* emit, ARM64Reg dst_reg, ARM64Reg src_reg, u32 flags,
bool is_reversed, bool is_extended)
{
if (is_reversed == !(flags & BackPatchInfo::FLAG_REVERSE))
{
if (flags & BackPatchInfo::FLAG_SIZE_32)
{
emit->REV32(dst_reg, src_reg);
src_reg = dst_reg;
}
else if (flags & BackPatchInfo::FLAG_SIZE_16)
{
emit->REV16(dst_reg, src_reg);
src_reg = dst_reg;
}
}

if (!is_extended && (flags & BackPatchInfo::FLAG_EXTEND))
{
emit->SXTH(dst_reg, src_reg);
src_reg = dst_reg;
}

if (dst_reg != src_reg)
emit->MOV(dst_reg, src_reg);
}

void MMIOLoadToReg(MMIO::Mapping* mmio, Arm64Gen::ARM64XEmitter* emit, BitSet32 gprs_in_use,
BitSet32 fprs_in_use, ARM64Reg dst_reg, u32 address, u32 flags)
{
Expand All @@ -213,6 +240,8 @@ void MMIOLoadToReg(MMIO::Mapping* mmio, Arm64Gen::ARM64XEmitter* emit, BitSet32
flags & BackPatchInfo::FLAG_EXTEND);
mmio->GetHandlerForRead<u32>(address).Visit(gen);
}

ByteswapAfterLoad(emit, dst_reg, dst_reg, flags, false, true);
}

void MMIOWriteRegToAddr(MMIO::Mapping* mmio, Arm64Gen::ARM64XEmitter* emit, BitSet32 gprs_in_use,
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/PowerPC/JitArm64/Jit_Util.h
Expand Up @@ -9,6 +9,9 @@

#include "Core/HW/MMIO.h"

void ByteswapAfterLoad(Arm64Gen::ARM64XEmitter* emit, Arm64Gen::ARM64Reg dst_reg,
Arm64Gen::ARM64Reg src_reg, u32 flags, bool is_reversed, bool is_extended);

void MMIOLoadToReg(MMIO::Mapping* mmio, Arm64Gen::ARM64XEmitter* emit, BitSet32 gprs_in_use,
BitSet32 fprs_in_use, Arm64Gen::ARM64Reg dst_reg, u32 address, u32 flags);

Expand Down

0 comments on commit d3ef5d4

Please sign in to comment.