Skip to content

Commit

Permalink
Merge pull request #1980 from Sonicadvance1/AArch64_more_optimizations
Browse files Browse the repository at this point in the history
[AArch64] Minor optimizations
  • Loading branch information
Sonicadvance1 committed Jan 30, 2015
2 parents 92294bf + 7cd8020 commit a277172
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 22 deletions.
23 changes: 23 additions & 0 deletions Source/Core/Common/Arm64Emitter.h
Expand Up @@ -597,6 +597,29 @@ class ARM64XEmitter
// ABI related
void ABI_PushRegisters(BitSet32 registers);
void ABI_PopRegisters(BitSet32 registers, BitSet32 ignore_mask = BitSet32(0));

// Utility to generate a call to a std::function object.
//
// Unfortunately, calling operator() directly is undefined behavior in C++
// (this method might be a thunk in the case of multi-inheritance) so we
// have to go through a trampoline function.
template <typename T, typename... Args>
static void CallLambdaTrampoline(const std::function<T(Args...)>* f,
Args... args)
{
(*f)(args...);
}

// This function expects you to have set up the state.
// Overwrites X0 and X30
template <typename T, typename... Args>
ARM64Reg ABI_SetupLambda(const std::function<T(Args...)>* f)
{
auto trampoline = &ARM64XEmitter::CallLambdaTrampoline<T, Args...>;
MOVI2R(X30, (u64)trampoline);
MOVI2R(X0, (u64)const_cast<void*>((const void*)f));
return X30;
}
};

class ARM64FloatEmitter
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/CMakeLists.txt
Expand Up @@ -237,6 +237,7 @@ elseif(_M_ARM_64)
PowerPC/JitArm64/JitArm64_Paired.cpp
PowerPC/JitArm64/JitArm64_LoadStorePaired.cpp
PowerPC/JitArm64/JitArm64_SystemRegisters.cpp
PowerPC/JitArm64/Jit_Util.cpp
PowerPC/JitArm64/JitArm64_Tables.cpp)
endif()

Expand Down
3 changes: 0 additions & 3 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp
Expand Up @@ -180,10 +180,7 @@ u32 JitArm64::EmitBackpatchRoutine(ARM64XEmitter* emit, u32 flags, bool fastmem,
else if (flags & BackPatchInfo::FLAG_SIZE_16)
emit->STRH(INDEX_UNSIGNED, temp, addr, 0);
else
{
emit->STRB(INDEX_UNSIGNED, RS, addr, 0);
emit->HINT(HINT_NOP);
}
}
else
{
Expand Down
29 changes: 23 additions & 6 deletions Source/Core/Core/PowerPC/JitArm64/JitArm64_LoadStore.cpp
Expand Up @@ -7,9 +7,12 @@

#include "Core/Core.h"
#include "Core/CoreTiming.h"
#include "Core/HW/MMIO.h"

#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/PPCTables.h"
#include "Core/PowerPC/JitArm64/Jit.h"
#include "Core/PowerPC/JitArm64/Jit_Util.h"
#include "Core/PowerPC/JitArm64/JitArm64_RegCache.h"
#include "Core/PowerPC/JitArm64/JitAsm.h"

Expand Down Expand Up @@ -42,10 +45,9 @@ void JitArm64::SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 o

BitSet32 regs_in_use = gpr.GetCallerSavedUsed();
BitSet32 fprs_in_use = fpr.GetCallerSavedUsed();
BitSet32 ignore_mask(0);
regs_in_use[W0] = 0;
regs_in_use[W30] = 0;
ignore_mask[dest_reg] = 1;
regs_in_use[dest_reg] = 0;

ARM64Reg addr_reg = W0;
u32 imm_addr = 0;
Expand Down Expand Up @@ -149,6 +151,12 @@ void JitArm64::SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 o
{
EmitBackpatchRoutine(this, flags, true, false, dest_reg, XA);
}
else if (is_immediate && MMIO::IsMMIOAddress(imm_addr))
{
MMIOLoadToReg(Memory::mmio_mapping, this,
regs_in_use, fprs_in_use, dest_reg,
imm_addr, flags);
}
else
{
// Has a chance of being backpatched which will destroy our state
Expand All @@ -160,7 +168,7 @@ void JitArm64::SafeLoadToReg(u32 dest, s32 addr, s32 offsetReg, u32 flags, s32 o
SConfig::GetInstance().m_LocalCoreStartupParameter.bFastmem,
dest_reg, XA);
m_float_emit.ABI_PopRegisters(fprs_in_use);
ABI_PopRegisters(regs_in_use, ignore_mask);
ABI_PopRegisters(regs_in_use);
}

gpr.Unlock(W0, W30);
Expand Down Expand Up @@ -280,15 +288,24 @@ void JitArm64::SafeStoreFromReg(s32 dest, u32 value, s32 regOffset, u32 flags, s

ARM64Reg XA = EncodeRegTo64(addr_reg);

if (is_immediate)
MOVI2R(XA, imm_addr);

if (is_immediate && Memory::IsRAMAddress(imm_addr))
{
MOVI2R(XA, imm_addr);

EmitBackpatchRoutine(this, flags, true, false, RS, XA);
}
else if (is_immediate && MMIO::IsMMIOAddress(imm_addr) &&
!(flags & BackPatchInfo::FLAG_REVERSE))
{
MMIOWriteRegToAddr(Memory::mmio_mapping, this,
regs_in_use, fprs_in_use, RS,
imm_addr, flags);
}
else
{
if (is_immediate)
MOVI2R(XA, imm_addr);

// Has a chance of being backpatched which will destroy our state
// push and pop everything in this instance
ABI_PushRegisters(regs_in_use);
Expand Down
Expand Up @@ -176,11 +176,10 @@ void JitArm64::lfXX(UGeckoInstruction inst)

BitSet32 regs_in_use = gpr.GetCallerSavedUsed();
BitSet32 fprs_in_use = fpr.GetCallerSavedUsed();
BitSet32 fpr_ignore_mask(0);
regs_in_use[W0] = 0;
regs_in_use[W30] = 0;
fprs_in_use[0] = 0; // Q0
fpr_ignore_mask[VD - Q0] = 1;
fprs_in_use[VD - Q0] = 0;

if (is_immediate && Memory::IsRAMAddress(imm_addr))
{
Expand All @@ -196,7 +195,7 @@ void JitArm64::lfXX(UGeckoInstruction inst)
SConfig::GetInstance().m_LocalCoreStartupParameter.bFastmem,
SConfig::GetInstance().m_LocalCoreStartupParameter.bFastmem,
VD, XA);
m_float_emit.ABI_PopRegisters(fprs_in_use, fpr_ignore_mask);
m_float_emit.ABI_PopRegisters(fprs_in_use);
ABI_PopRegisters(regs_in_use);
}

Expand Down
17 changes: 7 additions & 10 deletions Source/Core/Core/PowerPC/JitArm64/JitAsm.cpp
Expand Up @@ -273,8 +273,7 @@ void JitArm64AsmRoutineManager::GenerateCommon()

float_emit.REV32(8, D0, D0);
MOVK(addr_reg, ((u64)Memory::base >> 32) & 0xFFFF, SHIFT_32);
float_emit.ST1(32, Q0, 0, addr_reg, SP);
float_emit.ST1(32, Q0, 1, addr_reg, SP);
float_emit.ST1(64, Q0, 0, addr_reg, SP);
RET(X30);

SetJumpTarget(argh);
Expand Down Expand Up @@ -304,9 +303,9 @@ void JitArm64AsmRoutineManager::GenerateCommon()

TST(DecodeReg(addr_reg), 6, 1);
FixupBranch argh = B(CC_NEQ);

MOVK(addr_reg, ((u64)Memory::base >> 32) & 0xFFFF, SHIFT_32);
float_emit.ST1(8, Q0, 0, addr_reg, SP);
float_emit.ST1(8, Q0, 1, addr_reg, SP);
float_emit.ST1(16, Q0, 0, addr_reg, SP);
RET(X30);

SetJumpTarget(argh);
Expand Down Expand Up @@ -335,9 +334,9 @@ void JitArm64AsmRoutineManager::GenerateCommon()

TST(DecodeReg(addr_reg), 6, 1);
FixupBranch argh = B(CC_NEQ);

MOVK(addr_reg, ((u64)Memory::base >> 32) & 0xFFFF, SHIFT_32);
float_emit.ST1(8, Q0, 0, addr_reg, SP);
float_emit.ST1(8, Q0, 1, addr_reg, SP);
float_emit.ST1(16, Q0, 0, addr_reg, SP);
RET(X30);

SetJumpTarget(argh);
Expand Down Expand Up @@ -368,8 +367,7 @@ void JitArm64AsmRoutineManager::GenerateCommon()
TST(DecodeReg(addr_reg), 6, 1);
FixupBranch argh = B(CC_NEQ);
MOVK(addr_reg, ((u64)Memory::base >> 32) & 0xFFFF, SHIFT_32);
float_emit.ST1(16, Q0, 0, addr_reg, SP);
float_emit.ST1(16, Q0, 1, addr_reg, SP);
float_emit.ST1(32, Q0, 0, addr_reg, SP);
RET(X30);

SetJumpTarget(argh);
Expand Down Expand Up @@ -399,8 +397,7 @@ void JitArm64AsmRoutineManager::GenerateCommon()
TST(DecodeReg(addr_reg), 6, 1);
FixupBranch argh = B(CC_NEQ);
MOVK(addr_reg, ((u64)Memory::base >> 32) & 0xFFFF, SHIFT_32);
float_emit.ST1(16, Q0, 0, addr_reg, SP);
float_emit.ST1(16, Q0, 1, addr_reg, SP);
float_emit.ST1(32, Q0, 0, addr_reg, SP);
RET(X30);

SetJumpTarget(argh);
Expand Down

0 comments on commit a277172

Please sign in to comment.