diff --git a/CMakeLists.txt b/CMakeLists.txt
index 33958432e9..2c97e3906f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1397,8 +1397,6 @@ if(UNITTEST)
unittest/TestLoongArch64Emitter.cpp
unittest/TestThreadManager.cpp
unittest/JitHarness.cpp
- Core/MIPS/ARM/ArmRegCache.cpp
- Core/MIPS/ARM/ArmRegCacheFPU.cpp
)
if(APPLE)
target_sources(PPSSPPUnitTest PRIVATE
diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index 61bf4de6b0..c31541ba96 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -25,19 +25,17 @@ list(APPEND CoreExtra
)
list(APPEND CoreExtra
- MIPS/ARM/ArmAsm.cpp
- MIPS/ARM/ArmCompALU.cpp
- MIPS/ARM/ArmCompBranch.cpp
- MIPS/ARM/ArmCompFPU.cpp
- MIPS/ARM/ArmCompLoadStore.cpp
- MIPS/ARM/ArmCompVFPU.cpp
- MIPS/ARM/ArmCompReplace.cpp
- MIPS/ARM/ArmJit.cpp
- MIPS/ARM/ArmJit.h
- MIPS/ARM/ArmRegCache.cpp
- MIPS/ARM/ArmRegCache.h
- MIPS/ARM/ArmRegCacheFPU.cpp
- MIPS/ARM/ArmRegCacheFPU.h
+ MIPS/ARM/ArmIRAsm.cpp
+ MIPS/ARM/ArmIRCompALU.cpp
+ MIPS/ARM/ArmIRCompBranch.cpp
+ MIPS/ARM/ArmIRCompFPU.cpp
+ MIPS/ARM/ArmIRCompLoadStore.cpp
+ MIPS/ARM/ArmIRCompSystem.cpp
+ MIPS/ARM/ArmIRCompVec.cpp
+ MIPS/ARM/ArmIRJit.cpp
+ MIPS/ARM/ArmIRRegCache.cpp
+ MIPS/ARM/ArmIRJit.h
+ MIPS/ARM/ArmIRRegCache.h
)
list(APPEND CoreExtra
diff --git a/Core/Config.cpp b/Core/Config.cpp
index 88f40cdfc7..b8e59fd76c 100644
--- a/Core/Config.cpp
+++ b/Core/Config.cpp
@@ -1588,8 +1588,8 @@ bool Config::Save(const char *saveReason) {
// A lot more cleanup tasks should be moved into here, and some of these are severely outdated.
void Config::PostLoadCleanup() {
- // JIT_IR is the same core as JIT now that the legacy x86 and ARM64 JITs are gone, and the
- // settings no longer offer it.
+ // JIT_IR is the same core as JIT now that every native JIT is IR-based, and the settings no
+ // longer offer it.
if (iCpuCore == (int)CPUCore::JIT_IR) {
iCpuCore = (int)CPUCore::JIT;
}
diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj
index 192b4c0ef7..163be032c6 100644
--- a/Core/Core.vcxproj
+++ b/Core/Core.vcxproj
@@ -685,79 +685,15 @@
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
+
+
+
+
+
+
+
+
+
@@ -1080,23 +1016,8 @@
-
- true
- true
- true
- true
- true
- true
-
-
- true
- true
- true
- true
- true
- true
-
-
+
+
diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters
index 57782a769b..9e17d9263a 100644
--- a/Core/Core.vcxproj.filters
+++ b/Core/Core.vcxproj.filters
@@ -420,34 +420,34 @@
Ext\Snappy
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
-
- MIPS\ARM
-
Ext
-
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
+ MIPS\ARM
+
+
MIPS\ARM
@@ -544,9 +544,6 @@
HLE
-
- MIPS\ARM
-
HW
@@ -1722,13 +1719,10 @@
Ext\Snappy
-
+
MIPS\ARM
-
- MIPS\ARM
-
-
+
MIPS\ARM
diff --git a/Core/MIPS/ARM/ArmAsm.cpp b/Core/MIPS/ARM/ArmAsm.cpp
deleted file mode 100644
index a91efc6b26..0000000000
--- a/Core/MIPS/ARM/ArmAsm.cpp
+++ /dev/null
@@ -1,276 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include "Core/MemMap.h"
-#include "Core/MIPS/MIPS.h"
-#include "Core/Core.h"
-#include "Core/CoreTiming.h"
-#include "Common/MemoryUtil.h"
-#include "Common/CPUDetect.h"
-#include "Common/ArmEmitter.h"
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/JitCommon/JitCommon.h"
-
-using namespace ArmGen;
-
-//static int temp32; // unused?
-
-static const bool enableDebug = false;
-static const bool disasm = false;
-
-//static bool enableStatistics = false; //unused?
-
-//The standard ARM calling convention allocates the 16 ARM registers as:
-
-// r15 is the program counter.
-// r14 is the link register. (The BL instruction, used in a subroutine call, stores the return address in this register).
-// r13 is the stack pointer. (The Push/Pop instructions in "Thumb" operating mode use this register only).
-// r12 is the Intra-Procedure-call scratch register.
-// r4 to r11: used to hold local variables.
-// r0 to r3: used to hold argument values passed to a subroutine, and also hold results returned from a subroutine.
-
-// Mappable registers:
-// R2, R3, R4, R5, R6, R8, R11
-
-// STATIC ALLOCATION ARM:
-// R10 : MIPS state
-// R11 : Memory base pointer.
-// R7 : Down counter
-extern volatile CoreState coreState;
-
-void ShowPC(u32 sp) {
- ERROR_LOG(Log::JIT, "ShowPC : %08x ArmSP : %08x", currentMIPS->pc, sp);
- // Sleep(1);
-}
-
-void DisassembleArm(const u8 *data, int size);
-
-// PLAN: no more block numbers - crazy opcodes just contain offset within
-// dynarec buffer
-// At this offset - 4, there is an int specifying the block number.
-
-namespace MIPSComp {
-
-using namespace ArmJitConstants;
-
-void ArmJit::GenerateFixedCode() {
- BeginWrite(GetMemoryProtectPageSize());
- const u8 *start = AlignCodePage();
-
- // LR == SCRATCHREG2 on ARM32 so it needs to be pushed.
- restoreRoundingMode = AlignCode16(); {
- PUSH(1, R_LR);
- VMRS(SCRATCHREG2);
- // Outside the JIT we run with round-to-nearest and flush0 off.
- BIC(SCRATCHREG2, SCRATCHREG2, AssumeMakeOperand2((3 | 4) << 22));
- VMSR(SCRATCHREG2);
- POP(1, R_PC);
- }
-
- // Must preserve SCRATCHREG1 (R0), destroys SCRATCHREG2 (LR)
- applyRoundingMode = AlignCode16(); {
- PUSH(2, SCRATCHREG1, R_LR);
- LDR(SCRATCHREG2, CTXREG, offsetof(MIPSState, fcr31));
-
- TST(SCRATCHREG2, AssumeMakeOperand2(1 << 24));
- AND(SCRATCHREG2, SCRATCHREG2, Operand2(3));
- SetCC(CC_NEQ);
- ADD(SCRATCHREG2, SCRATCHREG2, Operand2(4));
- SetCC(CC_AL);
-
- // We can skip if the rounding mode is nearest (0) and flush is not set.
- // (as restoreRoundingMode cleared it out anyway)
- CMP(SCRATCHREG2, Operand2(0));
- FixupBranch skip = B_CC(CC_EQ);
-
- // MIPS Rounding Mode: ARM Rounding Mode
- // 0: Round nearest 0
- // 1: Round to zero 3
- // 2: Round up (ceil) 1
- // 3: Round down (floor) 2
- AND(SCRATCHREG1, SCRATCHREG2, Operand2(3));
- CMP(SCRATCHREG1, Operand2(1));
-
- SetCC(CC_EQ); ADD(SCRATCHREG2, SCRATCHREG2, Operand2(2));
- SetCC(CC_GT); SUB(SCRATCHREG2, SCRATCHREG2, Operand2(1));
- SetCC(CC_AL);
-
- VMRS(SCRATCHREG1);
- // Assume we're always in round-to-nearest mode beforehand.
- // But we need to clear flush to zero in this case anyway.
- BIC(SCRATCHREG1, SCRATCHREG1, AssumeMakeOperand2((3 | 4) << 22));
- ORR(SCRATCHREG1, SCRATCHREG1, Operand2(SCRATCHREG2, ST_LSL, 22));
- VMSR(SCRATCHREG1);
-
- SetJumpTarget(skip);
- POP(2, SCRATCHREG1, R_PC);
- }
-
- FlushLitPool();
-
- enterDispatcher = AlignCode16();
-
- DEBUG_LOG(Log::JIT, "Base: %08x", (u32)Memory::base);
-
- SetCC(CC_AL);
-
- PUSH(9, R4, R5, R6, R7, R8, R9, R10, R11, R_LR);
- // Take care to 8-byte align stack for function calls.
- // We are misaligned here because of an odd number of args for PUSH.
- // It's not like x86 where you need to account for an extra 4 bytes
- // consumed by CALL.
- SUB(R_SP, R_SP, 4);
- // Now we are correctly aligned and plan to stay that way.
- VPUSH(D8, 8);
-
- // Fixed registers, these are always kept when in Jit context.
- // R8 is used to hold flags during delay slots. Not always needed.
- // R13 cannot be used as it's the stack pointer.
- // TODO: Consider statically allocating:
- // * r2-r4
- // Really starting to run low on registers already though...
-
- // R11, R10, R9
- MOVP2R(MEMBASEREG, Memory::base);
- MOVP2R(CTXREG, mips_);
- MOVP2R(JITBASEREG, GetBasePtr());
-
- RestoreDowncount();
- MovFromPC(R0);
- outerLoopPCInR0 = GetCodePtr();
- MovToPC(R0);
- outerLoop = GetCodePtr();
- SaveDowncount();
- RestoreRoundingMode(true);
- QuickCallFunctionR(R1, &CoreTiming::Advance, CTXREG);
- ApplyRoundingMode(true);
- RestoreDowncount();
- FixupBranch skipToCoreStateCheck = B(); //skip the downcount check
-
- dispatcherCheckCoreState = GetCodePtr();
-
- // The result of slice decrementation should be in flags if somebody jumped here
- // IMPORTANT - We jump on negative, not carry!!!
- FixupBranch bailCoreState = B_CC(CC_MI);
-
- SetJumpTarget(skipToCoreStateCheck);
-
- MOVI2R(R0, (u32)(uintptr_t)&coreState);
- LDR(R0, R0);
- CMP(R0, 0);
- FixupBranch badCoreState = B_CC(CC_NEQ);
- FixupBranch skipToRealDispatch2 = B(); //skip the sync and compare first time
-
- dispatcherPCInR0 = GetCodePtr();
- // TODO: Do we always need to write PC to RAM here?
- MovToPC(R0);
-
- // At this point : flags = EQ. Fine for the next check, no need to jump over it.
- dispatcher = GetCodePtr();
-
- // The result of slice decrementation should be in flags if somebody jumped here
- // IMPORTANT - We jump on negative, not carry!!!
- FixupBranch bail = B_CC(CC_MI);
-
- SetJumpTarget(skipToRealDispatch2);
-
- dispatcherNoCheck = GetCodePtr();
-
- // Debug
- if (enableDebug) {
- MOV(R0, R13);
- QuickCallFunction(R1, (void *)&ShowPC);
- }
-
- LDR(R0, CTXREG, offsetof(MIPSState, pc));
- static_assert(Memory::BLOCK_SHADOW_ENTRY_MASK == 0x0FFFFFFC, "BICs below assume the 32-bit shadow mask");
- BIC(R0, R0, Operand2(0xF0, 4)); // &= 0x0FFFFFFF. Rotation is to the right, in 2-bit increments.
- BIC(R0, R0, Operand2(3));
- MOVI2R(R1, (u32)(uintptr_t)Memory::blockShadow);
- dispatcherFetch = GetCodePtr();
- LDR(R0, R1, R0);
- // The entry is the block's offset into the code space, or 0 for none.
- CMP(R0, Operand2(0));
- SetCC(CC_NEQ);
-#if PPSSPP_PLATFORM(IOS)
- // On iOS, R9 (JITBASEREG) is volatile. We have to reload it.
- MOVI2R(JITBASEREG, (u32)(uintptr_t)GetBasePtr());
-#endif
- ADD(R0, R0, JITBASEREG);
- B(R0);
- SetCC(CC_AL);
-
- // No block found, let's jit
- // A replacement hook's block shadow entry jumps here too (GetBlockShadowHookValue()). JitAt
- // replaces it with the new block's entry, and destroying that block puts the hook value back.
- blockShadowHook = GetCodePtr();
- SaveDowncount();
- RestoreRoundingMode(true);
- QuickCallFunctionR(R2, (void *)&MIPSComp::JitAt, CTXREG);
- ApplyRoundingMode(true);
- RestoreDowncount();
-
- B(dispatcherNoCheck); // no point in special casing this
-
- SetJumpTarget(bail);
- SetJumpTarget(bailCoreState);
-
- MOVI2R(R0, (u32)(uintptr_t)&coreState);
- LDR(R0, R0);
- CMP(R0, 0);
- B_CC(CC_EQ, outerLoop);
-
- const uint8_t *quitLoop = GetCodePtr();
- SetJumpTarget(badCoreState);
-
- SaveDowncount();
- RestoreRoundingMode(true);
-
- VPOP(D8, 8);
-
- ADD(R_SP, R_SP, 4);
-
- POP(9, R4, R5, R6, R7, R8, R9, R10, R11, R_PC); // Returns
-
- crashHandler = GetCodePtr();
- MOVP2R(R0, &coreState);
- MOVI2R(R1, CORE_RUNTIME_ERROR);
- STR(R1, R0, 0);
- B(quitLoop);
-
- // Uncomment if you want to see the output...
- if (disasm) {
- INFO_LOG(Log::JIT, "THE DISASM ========================");
- DisassembleArm(start, GetCodePtr() - start);
- INFO_LOG(Log::JIT, "END OF THE DISASM ========================");
- }
-
- // Don't forget to zap the instruction cache!
- FlushLitPool();
- FlushIcache();
-
- // Let's spare the pre-generated code from unprotect-reprotect.
- AlignCodePage();
- EndWrite();
-}
-
-} // namespace MIPSComp
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompALU.cpp b/Core/MIPS/ARM/ArmCompALU.cpp
deleted file mode 100644
index 44d22199bb..0000000000
--- a/Core/MIPS/ARM/ArmCompALU.cpp
+++ /dev/null
@@ -1,898 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include
-
-#include "Common/BitSet.h"
-#include "Common/CPUDetect.h"
-#include "Common/Data/Convert/SmallDataConvert.h"
-#include "Core/MIPS/MIPS.h"
-#include "Core/MIPS/MIPSAnalyst.h"
-#include "Core/MIPS/MIPSCodeUtils.h"
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-
-using namespace MIPSAnalyst;
-
-#define _RS MIPS_GET_RS(op)
-#define _RT MIPS_GET_RT(op)
-#define _RD MIPS_GET_RD(op)
-#define _FS MIPS_GET_FS(op)
-#define _FT MIPS_GET_FT(op)
-#define _FD MIPS_GET_FD(op)
-#define _SA MIPS_GET_SA(op)
-#define _POS ((op>> 6) & 0x1F)
-#define _SIZE ((op>>11) & 0x1F)
-#define _IMM16 (signed short)(op & 0xFFFF)
-#define _IMM26 (op & 0x03FFFFFF)
-
-// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
-// Currently known non working ones should have DISABLE.
-
-// #define CONDITIONAL_DISABLE(flag) { Comp_Generic(op); return; }
-#define CONDITIONAL_DISABLE(flag) if (jo.Disabled(JitDisable::flag)) { Comp_Generic(op); return; }
-#define DISABLE { Comp_Generic(op); return; }
-
-namespace MIPSComp
-{
- using namespace ArmGen;
- using namespace ArmJitConstants;
-
- static u32 EvalOr(u32 a, u32 b) { return a | b; }
- static u32 EvalEor(u32 a, u32 b) { return a ^ b; }
- static u32 EvalAnd(u32 a, u32 b) { return a & b; }
- static u32 EvalAdd(u32 a, u32 b) { return a + b; }
- static u32 EvalSub(u32 a, u32 b) { return a - b; }
-
- void ArmJit::CompImmLogic(MIPSGPReg rs, MIPSGPReg rt, u32 uimm, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg src, Operand2 op2), bool (ARMXEmitter::*tryArithI2R)(ARMReg dst, ARMReg src, u32 val), u32 (*eval)(u32 a, u32 b))
- {
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rt, (*eval)(gpr.GetImm(rs), uimm));
- } else {
- gpr.MapDirtyIn(rt, rs);
- if (!(this->*tryArithI2R)(gpr.R(rt), gpr.R(rs), uimm)) {
- gpr.SetRegImm(SCRATCHREG1, uimm);
- (this->*arith)(gpr.R(rt), gpr.R(rs), SCRATCHREG1);
- }
- }
- }
-
- void ArmJit::Comp_IType(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU_IMM);
- u32 uimm = op & 0xFFFF;
- s32 simm = SignExtend16ToS32(op);
- u32 suimm = SignExtend16ToU32(op);
-
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
-
- // noop, won't write to ZERO.
- if (rt == 0)
- return;
-
- switch (op >> 26)
- {
- case 8: // same as addiu?
- case 9: // R(rt) = R(rs) + simm; break; //addiu
- CompImmLogic(rs, rt, simm, &ARMXEmitter::ADD, &ARMXEmitter::TryADDI2R, &EvalAdd);
- break;
-
- case 12: CompImmLogic(rs, rt, uimm, &ARMXEmitter::AND, &ARMXEmitter::TryANDI2R, &EvalAnd); break;
- case 13: CompImmLogic(rs, rt, uimm, &ARMXEmitter::ORR, &ARMXEmitter::TryORI2R, &EvalOr); break;
- case 14: CompImmLogic(rs, rt, uimm, &ARMXEmitter::EOR, &ARMXEmitter::TryEORI2R, &EvalEor); break;
-
- case 10: // R(rt) = (s32)R(rs) < simm; break; //slti
- {
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rt, (s32)gpr.GetImm(rs) < simm ? 1 : 0);
- break;
- } else if (simm == 0) {
- gpr.MapDirtyIn(rt, rs);
- // Shift to get the sign bit only (for < 0.)
- LSR(gpr.R(rt), gpr.R(rs), 31);
- break;
- }
- gpr.MapDirtyIn(rt, rs);
- if (!TryCMPI2R(gpr.R(rs), simm)) {
- gpr.SetRegImm(SCRATCHREG1, simm);
- CMP(gpr.R(rs), SCRATCHREG1);
- }
- SetCC(CC_LT);
- MOVI2R(gpr.R(rt), 1);
- SetCC(CC_GE);
- MOVI2R(gpr.R(rt), 0);
- SetCC(CC_AL);
- }
- break;
-
- case 11: // R(rt) = R(rs) < suimm; break; //sltiu
- {
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rt, gpr.GetImm(rs) < suimm ? 1 : 0);
- break;
- }
- gpr.MapDirtyIn(rt, rs);
- if (!TryCMPI2R(gpr.R(rs), suimm)) {
- gpr.SetRegImm(SCRATCHREG1, suimm);
- CMP(gpr.R(rs), SCRATCHREG1);
- }
- SetCC(CC_LO);
- MOVI2R(gpr.R(rt), 1);
- SetCC(CC_HS);
- MOVI2R(gpr.R(rt), 0);
- SetCC(CC_AL);
- }
- break;
-
- case 15: // R(rt) = uimm << 16; //lui
- gpr.SetImm(rt, uimm << 16);
- break;
-
- default:
- Comp_Generic(op);
- break;
- }
- }
-
- void ArmJit::Comp_RType2(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU_BIT);
- MIPSGPReg rs = _RS;
- MIPSGPReg rd = _RD;
-
- // Don't change $zr.
- if (rd == 0)
- return;
-
- switch (op & 63)
- {
- case 22: //clz
- if (gpr.IsImm(rs)) {
- u32 value = gpr.GetImm(rs);
- int x = 31;
- int count = 0;
- while (x >= 0 && !(value & (1 << x))) {
- count++;
- x--;
- }
- gpr.SetImm(rd, count);
- break;
- }
- gpr.MapDirtyIn(rd, rs);
- CLZ(gpr.R(rd), gpr.R(rs));
- break;
- case 23: //clo
- if (gpr.IsImm(rs)) {
- u32 value = gpr.GetImm(rs);
- int x = 31;
- int count = 0;
- while (x >= 0 && (value & (1 << x))) {
- count++;
- x--;
- }
- gpr.SetImm(rd, count);
- break;
- }
- gpr.MapDirtyIn(rd, rs);
- MVN(SCRATCHREG1, gpr.R(rs));
- CLZ(gpr.R(rd), SCRATCHREG1);
- break;
- default:
- DISABLE;
- }
- }
-
- void ArmJit::CompType3(MIPSGPReg rd, MIPSGPReg rs, MIPSGPReg rt, void (ARMXEmitter::*arith)(ARMReg dst, ARMReg rm, Operand2 rn), bool (ARMXEmitter::*tryArithI2R)(ARMReg dst, ARMReg rm, u32 val), u32 (*eval)(u32 a, u32 b), bool symmetric)
- {
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, (*eval)(gpr.GetImm(rs), gpr.GetImm(rt)));
- return;
- }
-
- if (gpr.IsImm(rt) || (gpr.IsImm(rs) && symmetric)) {
- MIPSGPReg lhs = gpr.IsImm(rs) ? rt : rs;
- MIPSGPReg rhs = gpr.IsImm(rs) ? rs : rt;
- u32 rhsImm = gpr.GetImm(rhs);
- gpr.MapDirtyIn(rd, lhs);
- if ((this->*tryArithI2R)(gpr.R(rd), gpr.R(lhs), rhsImm)) {
- return;
- }
- // If rd is rhs, we may have lost it in the MapDirtyIn(). lhs was kept.
- // This means the rhsImm value was never flushed to rhs, and would be garbage.
- if (rd == rhs) {
- // Luckily, it was just an imm.
- gpr.SetImm(rhs, rhsImm);
- }
- } else if (gpr.IsImm(rs) && !symmetric) {
- Operand2 op2;
- // For SUB, we can use RSB as a reverse operation.
- if (eval == &EvalSub && TryMakeOperand2(gpr.GetImm(rs), op2)) {
- gpr.MapDirtyIn(rd, rt);
- RSB(gpr.R(rd), gpr.R(rt), op2);
- return;
- }
- }
-
- // Generic solution. If it's an imm, better to flush at this point.
- gpr.MapDirtyInIn(rd, rs, rt);
- (this->*arith)(gpr.R(rd), gpr.R(rs), gpr.R(rt));
- }
-
- void ArmJit::Comp_RType3(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU);
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- MIPSGPReg rd = _RD;
-
- // noop, won't write to ZERO.
- if (rd == 0)
- return;
-
- switch (op & 63)
- {
- case 10: //if (!R(rt)) R(rd) = R(rs); break; //movz
- if (rd == rs || (gpr.IsImm(rd) && gpr.IsImm(rs) && gpr.GetImm(rd) == gpr.GetImm(rs)))
- break;
- if (!gpr.IsImm(rt)) {
- Operand2 op2;
- // Avoid flushing the imm if possible.
- if (gpr.IsImm(rs) && TryMakeOperand2(gpr.GetImm(rs), op2)) {
- gpr.MapDirtyIn(rd, rt, false);
- } else {
- gpr.MapDirtyInIn(rd, rt, rs, false);
- op2 = gpr.R(rs);
- }
- CMP(gpr.R(rt), Operand2(0));
- SetCC(CC_EQ);
- MOV(gpr.R(rd), op2);
- SetCC(CC_AL);
- } else if (gpr.GetImm(rt) == 0) {
- // Yes, this actually happens.
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rd, gpr.GetImm(rs));
- } else {
- gpr.MapDirtyIn(rd, rs);
- MOV(gpr.R(rd), gpr.R(rs));
- }
- }
- break;
- case 11:// if (R(rt)) R(rd) = R(rs); break; //movn
- if (rd == rs || (gpr.IsImm(rd) && gpr.IsImm(rs) && gpr.GetImm(rd) == gpr.GetImm(rs)))
- break;
- if (!gpr.IsImm(rt)) {
- Operand2 op2;
- // Avoid flushing the imm if possible.
- if (gpr.IsImm(rs) && TryMakeOperand2(gpr.GetImm(rs), op2)) {
- gpr.MapDirtyIn(rd, rt, false);
- } else {
- gpr.MapDirtyInIn(rd, rt, rs, false);
- op2 = gpr.R(rs);
- }
- CMP(gpr.R(rt), Operand2(0));
- SetCC(CC_NEQ);
- MOV(gpr.R(rd), op2);
- SetCC(CC_AL);
- } else if (gpr.GetImm(rt) != 0) {
- // Yes, this actually happens.
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rd, gpr.GetImm(rs));
- } else {
- gpr.MapDirtyIn(rd, rs);
- MOV(gpr.R(rd), gpr.R(rs));
- }
- }
- break;
-
- case 32: //R(rd) = R(rs) + R(rt); break; //add
- case 33: //R(rd) = R(rs) + R(rt); break; //addu
- // We optimize out 0 as an operand2 ADD.
- CompType3(rd, rs, rt, &ARMXEmitter::ADD, &ARMXEmitter::TryADDI2R, &EvalAdd, true);
- break;
-
- case 34: //R(rd) = R(rs) - R(rt); break; //sub
- case 35: //R(rd) = R(rs) - R(rt); break; //subu
- CompType3(rd, rs, rt, &ARMXEmitter::SUB, &ARMXEmitter::TrySUBI2R, &EvalSub, false);
- break;
- case 36: //R(rd) = R(rs) & R(rt); break; //and
- CompType3(rd, rs, rt, &ARMXEmitter::AND, &ARMXEmitter::TryANDI2R, &EvalAnd, true);
- break;
- case 37: //R(rd) = R(rs) | R(rt); break; //or
- CompType3(rd, rs, rt, &ARMXEmitter::ORR, &ARMXEmitter::TryORI2R, &EvalOr, true);
- break;
- case 38: //R(rd) = R(rs) ^ R(rt); break; //xor/eor
- CompType3(rd, rs, rt, &ARMXEmitter::EOR, &ARMXEmitter::TryEORI2R, &EvalEor, true);
- break;
-
- case 39: // R(rd) = ~(R(rs) | R(rt)); break; //nor
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, ~(gpr.GetImm(rs) | gpr.GetImm(rt)));
- } else if (gpr.IsImm(rs) || gpr.IsImm(rt)) {
- MIPSGPReg lhs = gpr.IsImm(rs) ? rt : rs;
- MIPSGPReg rhs = gpr.IsImm(rs) ? rs : rt;
- u32 rhsImm = gpr.GetImm(rhs);
- Operand2 op2;
- if (TryMakeOperand2(rhsImm, op2)) {
- gpr.MapDirtyIn(rd, lhs);
- } else {
- gpr.MapDirtyInIn(rd, rs, rt);
- op2 = gpr.R(rhs);
- }
- if (rhsImm == 0) {
- MVN(gpr.R(rd), gpr.R(lhs));
- } else {
- ORR(gpr.R(rd), gpr.R(lhs), op2);
- MVN(gpr.R(rd), gpr.R(rd));
- }
- } else {
- gpr.MapDirtyInIn(rd, rs, rt);
- ORR(gpr.R(rd), gpr.R(rs), gpr.R(rt));
- MVN(gpr.R(rd), gpr.R(rd));
- }
- break;
-
- case 42: //R(rd) = (int)R(rs) < (int)R(rt); break; //slt
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, (s32)gpr.GetImm(rs) < (s32)gpr.GetImm(rt));
- } else {
- CCFlags caseOne = CC_LT;
- CCFlags caseZero = CC_GE;
- Operand2 op2;
- bool negated;
- if (gpr.IsImm(rs) && TryMakeOperand2_AllowNegation(gpr.GetImm(rs), op2, &negated)) {
- gpr.MapDirtyIn(rd, rt);
- if (!negated)
- CMP(gpr.R(rt), op2);
- else
- CMN(gpr.R(rt), op2);
-
- // Swap the condition since we swapped the arguments.
- caseOne = CC_GT;
- caseZero = CC_LE;
- } else if (gpr.IsImm(rt) && TryMakeOperand2_AllowNegation(gpr.GetImm(rt), op2, &negated)) {
- gpr.MapDirtyIn(rd, rs);
- if (!negated)
- CMP(gpr.R(rs), op2);
- else
- CMN(gpr.R(rs), op2);
- } else {
- gpr.MapDirtyInIn(rd, rs, rt);
- CMP(gpr.R(rs), gpr.R(rt));
- }
-
- SetCC(caseOne);
- MOVI2R(gpr.R(rd), 1);
- SetCC(caseZero);
- MOVI2R(gpr.R(rd), 0);
- SetCC(CC_AL);
- }
- break;
-
- case 43: //R(rd) = R(rs) < R(rt); break; //sltu
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, gpr.GetImm(rs) < gpr.GetImm(rt));
- } else {
- CCFlags caseOne = CC_LO;
- CCFlags caseZero = CC_HS;
- Operand2 op2;
- bool negated;
- if (gpr.IsImm(rs) && TryMakeOperand2_AllowNegation(gpr.GetImm(rs), op2, &negated)) {
- gpr.MapDirtyIn(rd, rt);
- if (!negated)
- CMP(gpr.R(rt), op2);
- else
- CMN(gpr.R(rt), op2);
-
- // Swap the condition since we swapped the arguments.
- caseOne = CC_HI;
- caseZero = CC_LS;
- } else if (gpr.IsImm(rt) && TryMakeOperand2_AllowNegation(gpr.GetImm(rt), op2, &negated)) {
- gpr.MapDirtyIn(rd, rs);
- if (!negated)
- CMP(gpr.R(rs), op2);
- else
- CMN(gpr.R(rs), op2);
- } else {
- gpr.MapDirtyInIn(rd, rs, rt);
- CMP(gpr.R(rs), gpr.R(rt));
- }
-
- SetCC(caseOne);
- MOVI2R(gpr.R(rd), 1);
- SetCC(caseZero);
- MOVI2R(gpr.R(rd), 0);
- SetCC(CC_AL);
- }
- break;
-
- case 44: //R(rd) = max(R(rs), R(rt); break; //max
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, std::max((s32)gpr.GetImm(rs), (s32)gpr.GetImm(rt)));
- break;
- }
- gpr.MapDirtyInIn(rd, rs, rt);
- CMP(gpr.R(rs), gpr.R(rt));
- SetCC(CC_GT);
- if (rd != rs)
- MOV(gpr.R(rd), gpr.R(rs));
- SetCC(CC_LE);
- if (rd != rt)
- MOV(gpr.R(rd), gpr.R(rt));
- SetCC(CC_AL);
- break;
-
- case 45: //R(rd) = min(R(rs), R(rt)); break; //min
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- gpr.SetImm(rd, std::min((s32)gpr.GetImm(rs), (s32)gpr.GetImm(rt)));
- break;
- }
- gpr.MapDirtyInIn(rd, rs, rt);
- CMP(gpr.R(rs), gpr.R(rt));
- SetCC(CC_LT);
- if (rd != rs)
- MOV(gpr.R(rd), gpr.R(rs));
- SetCC(CC_GE);
- if (rd != rt)
- MOV(gpr.R(rd), gpr.R(rt));
- SetCC(CC_AL);
- break;
-
- default:
- Comp_Generic(op);
- break;
- }
- }
-
- void ArmJit::CompShiftImm(MIPSOpcode op, ArmGen::ShiftType shiftType, int sa)
- {
- MIPSGPReg rd = _RD;
- MIPSGPReg rt = _RT;
-
- if (gpr.IsImm(rt)) {
- switch (shiftType) {
- case ST_LSL:
- gpr.SetImm(rd, gpr.GetImm(rt) << sa);
- break;
- case ST_LSR:
- gpr.SetImm(rd, gpr.GetImm(rt) >> sa);
- break;
- case ST_ASR:
- gpr.SetImm(rd, (int)gpr.GetImm(rt) >> sa);
- break;
- case ST_ROR:
- gpr.SetImm(rd, (gpr.GetImm(rt) >> sa) | (gpr.GetImm(rt) << (32 - sa)));
- break;
- default:
- DISABLE;
- }
- } else {
- gpr.MapDirtyIn(rd, rt);
- MOV(gpr.R(rd), Operand2(gpr.R(rt), shiftType, sa));
- }
- }
-
- void ArmJit::CompShiftVar(MIPSOpcode op, ArmGen::ShiftType shiftType)
- {
- MIPSGPReg rd = _RD;
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- if (gpr.IsImm(rs)) {
- int sa = gpr.GetImm(rs) & 0x1F;
- CompShiftImm(op, shiftType, sa);
- return;
- }
- gpr.MapDirtyInIn(rd, rs, rt);
- AND(SCRATCHREG1, gpr.R(rs), Operand2(0x1F));
- MOV(gpr.R(rd), Operand2(gpr.R(rt), shiftType, SCRATCHREG1));
- }
-
- void ArmJit::Comp_ShiftType(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU);
- MIPSGPReg rs = _RS;
- MIPSGPReg rd = _RD;
- int fd = _FD;
- int sa = _SA;
-
- // noop, won't write to ZERO.
- if (rd == 0)
- return;
-
- // WARNING : ROTR
- switch (op & 0x3f) {
- case 0: CompShiftImm(op, ST_LSL, sa); break; //sll
- case 2: CompShiftImm(op, (rs & 1) ? ST_ROR : ST_LSR, sa); break; //srl
- case 3: CompShiftImm(op, ST_ASR, sa); break; //sra
- case 4: CompShiftVar(op, ST_LSL); break; //sllv
- case 6: CompShiftVar(op, (fd & 1) ? ST_ROR : ST_LSR); break; //srlv
- case 7: CompShiftVar(op, ST_ASR); break; //srav
-
- default:
- Comp_Generic(op);
- break;
- }
- }
-
- void ArmJit::Comp_Special3(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU_BIT);
-
- MIPSGPReg rs = _RS;
- MIPSGPReg rt = _RT;
-
- int pos = _POS;
- int size = _SIZE + 1;
- u32 mask = 0xFFFFFFFFUL >> (32 - size);
-
- // Don't change $zr.
- if (rt == 0)
- return;
-
- switch (op & 0x3f) {
- case 0x0: //ext
- if (gpr.IsImm(rs)) {
- gpr.SetImm(rt, (gpr.GetImm(rs) >> pos) & mask);
- return;
- }
-
- gpr.MapDirtyIn(rt, rs);
-#if PPSSPP_ARCH(ARMV7)
- // Bits past 31 come out as zero, and UBFX can't encode them.
- UBFX(gpr.R(rt), gpr.R(rs), pos, std::min(size, 32 - pos));
-#else
- MOV(gpr.R(rt), Operand2(gpr.R(rs), ST_LSR, pos));
- ANDI2R(gpr.R(rt), gpr.R(rt), mask, SCRATCHREG1);
-#endif
- break;
-
- case 0x4: //ins
- {
- u32 sourcemask = mask >> pos;
- u32 destmask = ~(sourcemask << pos);
- // With msb below pos there's nothing to insert, and no BFI for it.
- if (sourcemask == 0)
- return;
- if (gpr.IsImm(rs)) {
- u32 inserted = (gpr.GetImm(rs) & sourcemask) << pos;
- if (gpr.IsImm(rt)) {
- gpr.SetImm(rt, (gpr.GetImm(rt) & destmask) | inserted);
- return;
- }
-
- gpr.MapReg(rt, MAP_DIRTY);
- ANDI2R(gpr.R(rt), gpr.R(rt), destmask, SCRATCHREG1);
- if (inserted != 0) {
- ORI2R(gpr.R(rt), gpr.R(rt), inserted, SCRATCHREG1);
- }
- } else {
- gpr.MapDirtyIn(rt, rs, false);
-#if PPSSPP_ARCH(ARMV7)
- BFI(gpr.R(rt), gpr.R(rs), pos, size - pos);
-#else
- ANDI2R(SCRATCHREG1, gpr.R(rs), sourcemask, SCRATCHREG2);
- ANDI2R(gpr.R(rt), gpr.R(rt), destmask, SCRATCHREG2);
- ORR(gpr.R(rt), gpr.R(rt), Operand2(SCRATCHREG1, ST_LSL, pos));
-#endif
- }
- }
- break;
- }
- }
-
- void ArmJit::Comp_Allegrex(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU_BIT);
- MIPSGPReg rt = _RT;
- MIPSGPReg rd = _RD;
- // Don't change $zr.
- if (rd == 0)
- return;
-
- switch (AllegrexBitOp(op)) {
- case 16: // seb // R(rd) = SignExtend8ToU32(R(rt));
- if (gpr.IsImm(rt)) {
- gpr.SetImm(rd, SignExtend8ToU32(gpr.GetImm(rt)));
- return;
- }
- gpr.MapDirtyIn(rd, rt);
- SXTB(gpr.R(rd), gpr.R(rt));
- break;
-
- case 24: // seh
- if (gpr.IsImm(rt)) {
- gpr.SetImm(rd, SignExtend16ToU32(gpr.GetImm(rt)));
- return;
- }
- gpr.MapDirtyIn(rd, rt);
- SXTH(gpr.R(rd), gpr.R(rt));
- break;
-
- case 20: //bitrev
- if (gpr.IsImm(rt)) {
- // http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
- u32 v = gpr.GetImm(rt);
- v = ((v >> 1) & 0x55555555) | ((v & 0x55555555) << 1); // odd<->even
- v = ((v >> 2) & 0x33333333) | ((v & 0x33333333) << 2); // pair<->pair
- v = ((v >> 4) & 0x0F0F0F0F) | ((v & 0x0F0F0F0F) << 4); // nibb<->nibb
- v = ((v >> 8) & 0x00FF00FF) | ((v & 0x00FF00FF) << 8); // byte<->byte
- v = ( v >> 16 ) | ( v << 16); // hword<->hword
- gpr.SetImm(rd, v);
- return;
- }
-
-#if PPSSPP_ARCH(ARMV7)
- gpr.MapDirtyIn(rd, rt);
- RBIT(gpr.R(rd), gpr.R(rt));
-#else
- Comp_Generic(op);
-#endif
- break;
- default:
- Comp_Generic(op);
- return;
- }
- }
-
- void ArmJit::Comp_Allegrex2(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(ALU_BIT);
- MIPSGPReg rt = _RT;
- MIPSGPReg rd = _RD;
- // Don't change $zr.
- if (rd == 0)
- return;
-
- switch (AllegrexBitOp(op)) {
- case 2: //wsbh
- if (gpr.IsImm(rt)) {
- gpr.SetImm(rd, ((gpr.GetImm(rt) & 0xFF00FF00) >> 8) | ((gpr.GetImm(rt) & 0x00FF00FF) << 8));
- } else {
- gpr.MapDirtyIn(rd, rt);
- REV16(gpr.R(rd), gpr.R(rt));
- }
- break;
- case 3: //wsbw
- if (gpr.IsImm(rt)) {
- gpr.SetImm(rd, swap32(gpr.GetImm(rt)));
- } else {
- gpr.MapDirtyIn(rd, rt);
- REV(gpr.R(rd), gpr.R(rt));
- }
- break;
- default:
- Comp_Generic(op);
- break;
- }
- }
-
- void ArmJit::Comp_MulDivType(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(MULDIV);
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- MIPSGPReg rd = _RD;
-
- switch (op & 63) {
- case 16: // R(rd) = HI; //mfhi
- if (rd != MIPS_REG_ZERO) {
- if (gpr.IsImm(MIPS_REG_HI)) {
- gpr.SetImm(rd, gpr.GetImm(MIPS_REG_HI));
- break;
- }
- gpr.MapDirtyIn(rd, MIPS_REG_HI);
- MOV(gpr.R(rd), gpr.R(MIPS_REG_HI));
- }
- break;
-
- case 17: // HI = R(rs); //mthi
- if (gpr.IsImm(rs)) {
- gpr.SetImm(MIPS_REG_HI, gpr.GetImm(rs));
- break;
- }
- gpr.MapDirtyIn(MIPS_REG_HI, rs);
- MOV(gpr.R(MIPS_REG_HI), gpr.R(rs));
- break;
-
- case 18: // R(rd) = LO; break; //mflo
- if (rd != MIPS_REG_ZERO) {
- if (gpr.IsImm(MIPS_REG_LO)) {
- gpr.SetImm(rd, gpr.GetImm(MIPS_REG_LO));
- break;
- }
- gpr.MapDirtyIn(rd, MIPS_REG_LO);
- MOV(gpr.R(rd), gpr.R(MIPS_REG_LO));
- }
- break;
-
- case 19: // LO = R(rs); break; //mtlo
- if (gpr.IsImm(rs)) {
- gpr.SetImm(MIPS_REG_LO, gpr.GetImm(rs));
- break;
- }
- gpr.MapDirtyIn(MIPS_REG_LO, rs);
- MOV(gpr.R(MIPS_REG_LO), gpr.R(rs));
- break;
-
- case 24: //mult (the most popular one). lo,hi = signed mul (rs * rt)
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- s64 result = (s64)(s32)gpr.GetImm(rs) * (s64)(s32)gpr.GetImm(rt);
- u64 resultBits = (u64)result;
- gpr.SetImm(MIPS_REG_LO, (u32)(resultBits >> 0));
- gpr.SetImm(MIPS_REG_HI, (u32)(resultBits >> 32));
- break;
- }
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt);
- SMULL(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_HI), gpr.R(rs), gpr.R(rt));
- break;
-
- case 25: //multu (2nd) lo,hi = unsigned mul (rs * rt)
- if (gpr.IsImm(rs) && gpr.IsImm(rt)) {
- u64 resultBits = (u64)gpr.GetImm(rs) * (u64)gpr.GetImm(rt);
- gpr.SetImm(MIPS_REG_LO, (u32)(resultBits >> 0));
- gpr.SetImm(MIPS_REG_HI, (u32)(resultBits >> 32));
- break;
- }
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt);
- UMULL(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_HI), gpr.R(rs), gpr.R(rt));
- break;
-
- case 26: //div
- if (cpu_info.bIDIVa) {
- // INT_MIN / -1: SDIV gives INT_MIN, and the MUL/SUB below wraps the remainder to 0,
- // which is what the hardware does (cpu/cpu_alu/cpu_div).
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt);
-
- CMPI2R(gpr.R(rt), 0, SCRATCHREG1);
- FixupBranch skipZero = B_CC(CC_NEQ);
- MOV(gpr.R(MIPS_REG_HI), gpr.R(rs));
- MOVI2R(gpr.R(MIPS_REG_LO), -1);
- CMPI2R(gpr.R(rs), 0, SCRATCHREG1);
- SetCC(CC_LT);
- MOVI2R(gpr.R(MIPS_REG_LO), 1);
- SetCC(CC_AL);
- FixupBranch skipDiv = B();
-
- SetJumpTarget(skipZero);
- SDIV(gpr.R(MIPS_REG_LO), gpr.R(rs), gpr.R(rt));
- SetJumpTarget(skipDiv);
- MUL(SCRATCHREG1, gpr.R(rt), gpr.R(MIPS_REG_LO));
- SUB(gpr.R(MIPS_REG_HI), gpr.R(rs), Operand2(SCRATCHREG1));
- } else {
- DISABLE;
- }
- break;
-
- case 27: //divu
- // Do we have a known power-of-two denominator? Yes, this happens.
- if (gpr.IsImm(rt) && (gpr.GetImm(rt) & (gpr.GetImm(rt) - 1)) == 0 && gpr.GetImm(rt) != 0) {
- u32 denominator = gpr.GetImm(rt);
- gpr.MapDirtyDirtyIn(MIPS_REG_LO, MIPS_REG_HI, rs);
- // Remainder is just an AND, neat.
- ANDI2R(gpr.R(MIPS_REG_HI), gpr.R(rs), denominator - 1, SCRATCHREG1);
- int shift = 0;
- while (denominator != 0) {
- ++shift;
- denominator >>= 1;
- }
- // The shift value is one too much for the divide by the same value.
- if (shift > 1) {
- LSR(gpr.R(MIPS_REG_LO), gpr.R(rs), shift - 1);
- } else {
- MOV(gpr.R(MIPS_REG_LO), gpr.R(rs));
- }
- } else if (cpu_info.bIDIVa) {
- // TODO: Does this handle INT_MAX, 0, etc. correctly?
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt);
-
- CMPI2R(gpr.R(rt), 0, SCRATCHREG1);
- FixupBranch skipZero = B_CC(CC_NEQ);
- MOV(gpr.R(MIPS_REG_HI), gpr.R(rs));
- MOVI2R(SCRATCHREG1, 0xFFFF);
- CMP(gpr.R(rs), SCRATCHREG1);
- MOVI2R(gpr.R(MIPS_REG_LO), -1);
- SetCC(CC_LS);
- MOV(gpr.R(MIPS_REG_LO), SCRATCHREG1);
- SetCC(CC_AL);
- FixupBranch skipDiv = B();
-
- SetJumpTarget(skipZero);
- UDIV(gpr.R(MIPS_REG_LO), gpr.R(rs), gpr.R(rt));
- SetJumpTarget(skipDiv);
- MUL(SCRATCHREG1, gpr.R(rt), gpr.R(MIPS_REG_LO));
- SUB(gpr.R(MIPS_REG_HI), gpr.R(rs), Operand2(SCRATCHREG1));
- } else {
- // If rt is 0, we either caught it above, or it's not an imm.
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt);
- MOV(SCRATCHREG1, gpr.R(rt));
- // We start at rs for the remainder and subtract out.
- MOV(gpr.R(MIPS_REG_HI), gpr.R(rs));
-
- CMP(gpr.R(rt), 0);
- FixupBranch skipper = B_CC(CC_EQ);
-
- // Double SCRATCHREG1 until it would be (but isn't) bigger than the numerator.
- CMP(SCRATCHREG1, Operand2(gpr.R(rs), ST_LSR, 1));
- const u8 *doubleLoop = GetCodePtr();
- SetCC(CC_LS);
- MOV(SCRATCHREG1, Operand2(SCRATCHREG1, ST_LSL, 1));
- SetCC(CC_AL);
- CMP(SCRATCHREG1, Operand2(gpr.R(rs), ST_LSR, 1));
- B_CC(CC_LS, doubleLoop);
-
- MOV(gpr.R(MIPS_REG_LO), 0);
-
- // Subtract and halve SCRATCHREG1 (doubling and adding the result) until it's below the denominator.
- const u8 *subLoop = GetCodePtr();
- CMP(gpr.R(MIPS_REG_HI), SCRATCHREG1);
- SetCC(CC_HS);
- SUB(gpr.R(MIPS_REG_HI), gpr.R(MIPS_REG_HI), SCRATCHREG1);
- SetCC(CC_AL);
- // Carry will be set if we subtracted.
- ADC(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_LO));
- MOV(SCRATCHREG1, Operand2(SCRATCHREG1, ST_LSR, 1));
- CMP(SCRATCHREG1, gpr.R(rt));
- B_CC(CC_HS, subLoop);
-
- // We didn't change rt. If it was 0, then clear HI and LO.
- FixupBranch zeroSkip = B();
- SetJumpTarget(skipper);
- MOVI2R(SCRATCHREG1, 0xFFFF);
- CMP(gpr.R(rs), SCRATCHREG1);
- MOVI2R(gpr.R(MIPS_REG_LO), -1);
- SetCC(CC_LS);
- MOV(gpr.R(MIPS_REG_LO), SCRATCHREG1);
- SetCC(CC_AL);
- SetJumpTarget(zeroSkip);
- }
- break;
-
- case 28: //madd
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt, false);
- SMLAL(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_HI), gpr.R(rs), gpr.R(rt));
- break;
-
- case 29: //maddu
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt, false);
- UMLAL(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_HI), gpr.R(rs), gpr.R(rt));
- break;
-
- case 46: // msub
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt, false);
- SMULL(SCRATCHREG1, SCRATCHREG2, gpr.R(rs), gpr.R(rt));
- SUBS(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_LO), SCRATCHREG1);
- SBC(gpr.R(MIPS_REG_HI), gpr.R(MIPS_REG_HI), SCRATCHREG2);
- break;
-
- case 47: // msubu
- gpr.MapDirtyDirtyInIn(MIPS_REG_LO, MIPS_REG_HI, rs, rt, false);
- UMULL(SCRATCHREG1, SCRATCHREG2, gpr.R(rs), gpr.R(rt));
- SUBS(gpr.R(MIPS_REG_LO), gpr.R(MIPS_REG_LO), SCRATCHREG1);
- SBC(gpr.R(MIPS_REG_HI), gpr.R(MIPS_REG_HI), SCRATCHREG2);
- break;
-
- default:
- DISABLE;
- }
- }
-
-}
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompBranch.cpp b/Core/MIPS/ARM/ArmCompBranch.cpp
deleted file mode 100644
index f1634164d4..0000000000
--- a/Core/MIPS/ARM/ArmCompBranch.cpp
+++ /dev/null
@@ -1,655 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include "Common/Data/Convert/SmallDataConvert.h"
-#include "Common/Profiler/Profiler.h"
-
-#include "Core/Config.h"
-#include "Core/Core.h"
-#include "Core/Reporting.h"
-#include "Core/MemMap.h"
-#include "Core/HLE/HLE.h"
-#include "Core/HLE/HLETables.h"
-
-#include "Core/MIPS/MIPS.h"
-#include "Core/MIPS/MIPSCodeUtils.h"
-#include "Core/MIPS/MIPSAnalyst.h"
-#include "Core/MIPS/MIPSTables.h"
-
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-#include "Core/MIPS/JitCommon/JitBlockCache.h"
-
-#include "Common/ArmEmitter.h"
-
-#define _RS MIPS_GET_RS(op)
-#define _RT MIPS_GET_RT(op)
-#define _RD MIPS_GET_RD(op)
-#define _FS MIPS_GET_FS(op)
-#define _FT MIPS_GET_FT(op)
-#define _FD MIPS_GET_FD(op)
-#define _SA MIPS_GET_SA(op)
-#define _POS ((op>> 6) & 0x1F)
-#define _SIZE ((op>>11) & 0x1F)
-#define _IMM26 (op & 0x03FFFFFF)
-#define TARGET16 ((int)(SignExtend16ToU32(op) << 2))
-#define TARGET26 (_IMM26 << 2)
-
-#define LOOPOPTIMIZATION 0
-
-// We can disable nice delay slots.
-// #define CONDITIONAL_NICE_DELAYSLOT branchInfo.delaySlotIsNice = false;
-#define CONDITIONAL_NICE_DELAYSLOT ;
-
-using namespace MIPSAnalyst;
-
-namespace MIPSComp
-{
- using namespace ArmGen;
- using namespace ArmJitConstants;
-
-void ArmJit::BranchRSRTComp(MIPSOpcode op, CCFlags cc, bool likely)
-{
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in RSRTComp delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- int offset = TARGET16;
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- u32 targetAddr = GetCompilerPC() + offset + 4;
-
- BranchInfo branchInfo(GetCompilerPC(), op, GetOffsetInstruction(1), false, likely);
- branchInfo.delaySlotIsNice = IsDelaySlotNiceReg(op, branchInfo.delaySlotOp, rt, rs);
- CONDITIONAL_NICE_DELAYSLOT;
-
- bool immBranch = false;
- bool immBranchTaken = false;
- if (gpr.IsImm(rs) && gpr.IsImm(rt) && !branchInfo.delaySlotIsBranch) {
- // The cc flags are opposites: when NOT to take the branch.
- bool immBranchNotTaken;
- s32 rsImm = (s32)gpr.GetImm(rs);
- s32 rtImm = (s32)gpr.GetImm(rt);
-
- switch (cc)
- {
- case CC_EQ: immBranchNotTaken = rsImm == rtImm; break;
- case CC_NEQ: immBranchNotTaken = rsImm != rtImm; break;
- default: immBranchNotTaken = false; _dbg_assert_msg_(false, "Bad cc flag in BranchRSRTComp().");
- }
- immBranch = true;
- immBranchTaken = !immBranchNotTaken;
- }
-
- js.downcountAmount += MIPSGetInstructionCycleEstimate(branchInfo.delaySlotOp);
-
- u32 notTakenTarget = ResolveNotTakenTarget(branchInfo);
- if (immBranch) {
- // Continuing is handled above, this is just static jumping.
- if (immBranchTaken || !likely)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- else
- FlushAll();
-
- const u32 destAddr = immBranchTaken ? targetAddr : notTakenTarget;
- WriteExit(destAddr, js.nextExit++);
- } else {
- if (!likely && branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_NICE);
-
- // We might be able to flip the condition (EQ/NEQ are easy.)
- const bool canFlip = cc == CC_EQ || cc == CC_NEQ;
-
- Operand2 op2;
- bool negated;
- if (gpr.IsImm(rt) && TryMakeOperand2_AllowNegation(gpr.GetImm(rt), op2, &negated)) {
- gpr.MapReg(rs);
- if (!negated)
- CMP(gpr.R(rs), op2);
- else
- CMN(gpr.R(rs), op2);
- } else {
- if (gpr.IsImm(rs) && TryMakeOperand2_AllowNegation(gpr.GetImm(rs), op2, &negated) && canFlip) {
- gpr.MapReg(rt);
- if (!negated)
- CMP(gpr.R(rt), op2);
- else
- CMN(gpr.R(rt), op2);
- } else {
- gpr.MapInIn(rs, rt);
- CMP(gpr.R(rs), gpr.R(rt));
- }
- }
-
- ArmGen::FixupBranch ptr;
- if (!likely) {
- if (!branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
- else
- FlushAll();
- ptr = B_CC(cc);
- } else {
- FlushAll();
- ptr = B_CC(cc);
- if (!branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- }
-
- if (branchInfo.delaySlotIsBranch) {
- // We still link when the branch is taken (targetAddr case.)
- // Remember, it's from the perspective of the delay slot, so +12.
- if ((branchInfo.delaySlotInfo & OUT_RA) != 0)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 12);
- if ((branchInfo.delaySlotInfo & OUT_RD) != 0)
- gpr.SetImm(MIPS_GET_RD(branchInfo.delaySlotOp), GetCompilerPC() + 12);
- FlushAll();
- }
-
- // Take the branch
- WriteExit(targetAddr, js.nextExit++);
-
- SetJumpTarget(ptr);
- // Not taken
- WriteExit(notTakenTarget, js.nextExit++);
- }
-
- js.compiling = false;
-}
-
-
-void ArmJit::BranchRSZeroComp(MIPSOpcode op, CCFlags cc, bool andLink, bool likely)
-{
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in RSZeroComp delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- int offset = TARGET16;
- MIPSGPReg rs = _RS;
- u32 targetAddr = GetCompilerPC() + offset + 4;
-
- BranchInfo branchInfo(GetCompilerPC(), op, GetOffsetInstruction(1), andLink, likely);
- branchInfo.delaySlotIsNice = IsDelaySlotNiceReg(op, branchInfo.delaySlotOp, rs);
- CONDITIONAL_NICE_DELAYSLOT;
-
- bool immBranch = false;
- bool immBranchTaken = false;
- if (gpr.IsImm(rs) && !branchInfo.delaySlotIsBranch) {
- // The cc flags are opposites: when NOT to take the branch.
- bool immBranchNotTaken;
- s32 imm = (s32)gpr.GetImm(rs);
-
- switch (cc)
- {
- case CC_GT: immBranchNotTaken = imm > 0; break;
- case CC_GE: immBranchNotTaken = imm >= 0; break;
- case CC_LT: immBranchNotTaken = imm < 0; break;
- case CC_LE: immBranchNotTaken = imm <= 0; break;
- default: immBranchNotTaken = false; _dbg_assert_msg_(false, "Bad cc flag in BranchRSZeroComp().");
- }
- immBranch = true;
- immBranchTaken = !immBranchNotTaken;
- }
-
- js.downcountAmount += MIPSGetInstructionCycleEstimate(branchInfo.delaySlotOp);
-
- u32 notTakenTarget = ResolveNotTakenTarget(branchInfo);
- if (immBranch) {
- // Continuing is handled above, this is just static jumping.
- if (andLink)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 8);
- if (immBranchTaken || !likely)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- else
- FlushAll();
-
- const u32 destAddr = immBranchTaken ? targetAddr : notTakenTarget;
- WriteExit(destAddr, js.nextExit++);
- } else {
- if (!likely && branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_NICE);
-
- gpr.MapReg(rs);
- CMP(gpr.R(rs), Operand2(0, TYPE_IMM));
-
- if (andLink)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 8);
-
- ArmGen::FixupBranch ptr;
- if (!likely)
- {
- if (!branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
- else
- FlushAll();
- ptr = B_CC(cc);
- }
- else
- {
- FlushAll();
- ptr = B_CC(cc);
- if (!branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- }
-
- if (branchInfo.delaySlotIsBranch) {
- // We still link when the branch is taken (targetAddr case.)
- // Remember, it's from the perspective of the delay slot, so +12.
- if ((branchInfo.delaySlotInfo & OUT_RA) != 0)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 12);
- if ((branchInfo.delaySlotInfo & OUT_RD) != 0)
- gpr.SetImm(MIPS_GET_RD(branchInfo.delaySlotOp), GetCompilerPC() + 12);
- FlushAll();
- }
-
- // Take the branch
- WriteExit(targetAddr, js.nextExit++);
-
- SetJumpTarget(ptr);
- // Not taken
- WriteExit(notTakenTarget, js.nextExit++);
- }
- js.compiling = false;
-}
-
-
-void ArmJit::Comp_RelBranch(MIPSOpcode op)
-{
- // The CC flags here should be opposite of the actual branch becuase they skip the branching action.
- switch (op >> 26)
- {
- case 4: BranchRSRTComp(op, CC_NEQ, false); break;//beq
- case 5: BranchRSRTComp(op, CC_EQ, false); break;//bne
-
- case 6: BranchRSZeroComp(op, CC_GT, false, false); break;//blez
- case 7: BranchRSZeroComp(op, CC_LE, false, false); break;//bgtz
-
- case 20: BranchRSRTComp(op, CC_NEQ, true); break;//beql
- case 21: BranchRSRTComp(op, CC_EQ, true); break;//bnel
-
- case 22: BranchRSZeroComp(op, CC_GT, false, true); break;//blezl
- case 23: BranchRSZeroComp(op, CC_LE, false, true); break;//bgtzl
-
- default:
- _dbg_assert_msg_(false,"Trying to compile instruction that can't be compiled");
- break;
- }
-}
-
-void ArmJit::Comp_RelBranchRI(MIPSOpcode op)
-{
- switch ((op >> 16) & 0x1F)
- {
- case 0: BranchRSZeroComp(op, CC_GE, false, false); break; //if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltz
- case 1: BranchRSZeroComp(op, CC_LT, false, false); break; //if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgez
- case 2: BranchRSZeroComp(op, CC_GE, false, true); break; //if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 8; break;//bltzl
- case 3: BranchRSZeroComp(op, CC_LT, false, true); break; //if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 8; break;//bgezl
- case 16: BranchRSZeroComp(op, CC_GE, true, false); break; //R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else PC += 4; break;//bltzal
- case 17: BranchRSZeroComp(op, CC_LT, true, false); break; //R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else PC += 4; break;//bgezal
- case 18: BranchRSZeroComp(op, CC_GE, true, true); break; //R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) < 0) DelayBranchTo(addr); else SkipLikely(); break;//bltzall
- case 19: BranchRSZeroComp(op, CC_LT, true, true); break; //R(MIPS_REG_RA) = PC + 8; if ((s32)R(rs) >= 0) DelayBranchTo(addr); else SkipLikely(); break;//bgezall
- default:
- _dbg_assert_msg_(false,"Trying to compile instruction that can't be compiled");
- break;
- }
-}
-
-// If likely is set, discard the branch slot if NOT taken.
-void ArmJit::BranchFPFlag(MIPSOpcode op, CCFlags cc, bool likely)
-{
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in FPFlag delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- int offset = TARGET16;
- u32 targetAddr = GetCompilerPC() + offset + 4;
-
- BranchInfo branchInfo(GetCompilerPC(), op, GetOffsetInstruction(1), false, likely);
- branchInfo.delaySlotIsNice = IsDelaySlotNiceFPU(op, branchInfo.delaySlotOp);
- CONDITIONAL_NICE_DELAYSLOT;
-
- js.downcountAmount += MIPSGetInstructionCycleEstimate(branchInfo.delaySlotOp);
- if (!likely && branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_NICE);
-
- gpr.MapReg(MIPS_REG_FPCOND);
- TST(gpr.R(MIPS_REG_FPCOND), Operand2(1, TYPE_IMM));
-
- ArmGen::FixupBranch ptr;
- if (!likely)
- {
- if (!branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
- else
- FlushAll();
- ptr = B_CC(cc);
- }
- else
- {
- FlushAll();
- ptr = B_CC(cc);
- if (!branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- }
-
- if (branchInfo.delaySlotIsBranch) {
- // We still link when the branch is taken (targetAddr case.)
- // Remember, it's from the perspective of the delay slot, so +12.
- if ((branchInfo.delaySlotInfo & OUT_RA) != 0)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 12);
- if ((branchInfo.delaySlotInfo & OUT_RD) != 0)
- gpr.SetImm(MIPS_GET_RD(branchInfo.delaySlotOp), GetCompilerPC() + 12);
- FlushAll();
- }
-
- // Take the branch
- WriteExit(targetAddr, js.nextExit++);
-
- SetJumpTarget(ptr);
- // Not taken
- WriteExit(ResolveNotTakenTarget(branchInfo), js.nextExit++);
- js.compiling = false;
-}
-
-void ArmJit::Comp_FPUBranch(MIPSOpcode op)
-{
- switch((op >> 16) & 0x1f)
- {
- case 0: BranchFPFlag(op, CC_NEQ, false); break; // bc1f
- case 1: BranchFPFlag(op, CC_EQ, false); break; // bc1t
- case 2: BranchFPFlag(op, CC_NEQ, true); break; // bc1fl
- case 3: BranchFPFlag(op, CC_EQ, true); break; // bc1tl
- default:
- _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted");
- break;
- }
-}
-
-// If likely is set, discard the branch slot if NOT taken.
-void ArmJit::BranchVFPUFlag(MIPSOpcode op, CCFlags cc, bool likely)
-{
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in VFPU delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- int offset = TARGET16;
- u32 targetAddr = GetCompilerPC() + offset + 4;
-
- BranchInfo branchInfo(GetCompilerPC(), op, GetOffsetInstruction(1), false, likely);
- // Sometimes there's a VFPU branch in a delay slot (Disgaea 2: Dark Hero Days, Zettai Hero Project, La Pucelle)
- // The behavior is undefined - the CPU may take the second branch even if the first one passes.
- // However, it does consistently try each branch, which these games seem to expect.
- branchInfo.delaySlotIsNice = IsDelaySlotNiceVFPU(op, branchInfo.delaySlotOp);
- CONDITIONAL_NICE_DELAYSLOT;
-
- js.downcountAmount += MIPSGetInstructionCycleEstimate(branchInfo.delaySlotOp);
- if (!likely && branchInfo.delaySlotIsNice)
- CompileDelaySlot(DELAYSLOT_NICE);
-
- int imm3 = (op >> 18) & 7;
-
- gpr.MapReg(MIPS_REG_VFPUCC);
- TST(gpr.R(MIPS_REG_VFPUCC), Operand2(1 << imm3, TYPE_IMM));
-
- ArmGen::FixupBranch ptr;
- js.inDelaySlot = true;
- if (!likely)
- {
- if (!branchInfo.delaySlotIsNice && !branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_SAFE_FLUSH);
- else
- FlushAll();
- ptr = B_CC(cc);
- }
- else
- {
- FlushAll();
- ptr = B_CC(cc);
- if (!branchInfo.delaySlotIsBranch)
- CompileDelaySlot(DELAYSLOT_FLUSH);
- }
- js.inDelaySlot = false;
-
- if (branchInfo.delaySlotIsBranch) {
- // We still link when the branch is taken (targetAddr case.)
- // Remember, it's from the perspective of the delay slot, so +12.
- if ((branchInfo.delaySlotInfo & OUT_RA) != 0)
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 12);
- if ((branchInfo.delaySlotInfo & OUT_RD) != 0)
- gpr.SetImm(MIPS_GET_RD(branchInfo.delaySlotOp), GetCompilerPC() + 12);
- FlushAll();
- }
-
- // Take the branch
- WriteExit(targetAddr, js.nextExit++);
-
- SetJumpTarget(ptr);
- // Not taken
- WriteExit(ResolveNotTakenTarget(branchInfo), js.nextExit++);
- js.compiling = false;
-}
-
-void ArmJit::Comp_VBranch(MIPSOpcode op)
-{
- switch ((op >> 16) & 3)
- {
- case 0: BranchVFPUFlag(op, CC_NEQ, false); break; // bvf
- case 1: BranchVFPUFlag(op, CC_EQ, false); break; // bvt
- case 2: BranchVFPUFlag(op, CC_NEQ, true); break; // bvfl
- case 3: BranchVFPUFlag(op, CC_EQ, true); break; // bvtl
- }
-}
-
-static void HitInvalidJump(uint32_t dest) {
- Core_ExecException(dest, currentMIPS->pc - 8, ExecExceptionType::JUMP);
-}
-
-void ArmJit::Comp_Jump(MIPSOpcode op) {
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in Jump delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- u32 off = TARGET26;
- u32 targetAddr = (GetCompilerPC() & 0xF0000000) | off;
-
- // Might be a stubbed address or something?
- if (!Memory::IsValidAddress(targetAddr) || (targetAddr & 3) != 0) {
- if (js.nextExit == 0) {
- ERROR_LOG(Log::JIT, "Jump to invalid address: %08x", targetAddr);
- } else {
- js.compiling = false;
- }
- // TODO: Mark this block dirty or something? May be indication it will be changed by imports.
- CompileDelaySlot(DELAYSLOT_NICE);
- FlushAll();
- gpr.SetRegImm(SCRATCHREG1, GetCompilerPC() + 8);
- MovToPC(SCRATCHREG1);
- MOVI2R(R0, targetAddr);
- QuickCallFunction(SCRATCHREG2, &HitInvalidJump);
- WriteSyscallExit();
- return;
- }
-
- switch (op >> 26) {
- case 2: //j
- CompileDelaySlot(DELAYSLOT_NICE);
- FlushAll();
- WriteExit(targetAddr, js.nextExit++);
- break;
-
- case 3: //jal
- gpr.SetImm(MIPS_REG_RA, GetCompilerPC() + 8);
- CompileDelaySlot(DELAYSLOT_NICE);
- FlushAll();
- WriteExit(targetAddr, js.nextExit++);
- break;
-
- default:
- _dbg_assert_msg_(false,"Trying to compile instruction that can't be compiled");
- break;
- }
- js.compiling = false;
-}
-
-void ArmJit::Comp_JumpReg(MIPSOpcode op)
-{
- if (js.inDelaySlot) {
- ERROR_LOG_REPORT(Log::JIT, "Branch in JumpReg delay slot at %08x in block starting at %08x", GetCompilerPC(), js.blockStart);
- return;
- }
- MIPSGPReg rs = _RS;
- MIPSGPReg rd = _RD;
- bool andLink = (op & 0x3f) == 9 && rd != MIPS_REG_ZERO;
-
- MIPSOpcode delaySlotOp = GetOffsetInstruction(1);
- js.downcountAmount += MIPSGetInstructionCycleEstimate(delaySlotOp);
- bool delaySlotIsNice = IsDelaySlotNiceReg(op, delaySlotOp, rs);
- if (andLink && rs == rd)
- delaySlotIsNice = false;
- CONDITIONAL_NICE_DELAYSLOT;
-
- ARMReg destReg = R8;
- if (IsSyscall(delaySlotOp)) {
- gpr.MapReg(rs);
- MovToPC(gpr.R(rs)); // For syscall to be able to return.
- if (andLink)
- gpr.SetImm(rd, GetCompilerPC() + 8);
- CompileDelaySlot(DELAYSLOT_FLUSH);
- return; // Syscall wrote exit code.
- } else if (delaySlotIsNice) {
- if (andLink)
- gpr.SetImm(rd, GetCompilerPC() + 8);
- CompileDelaySlot(DELAYSLOT_NICE);
-
- if (!andLink && rs == MIPS_REG_RA && g_Config.bDiscardRegsOnJRRA) {
- // According to the MIPS ABI, there are some regs we don't need to preserve.
- // Let's discard them so we don't need to write them back.
- // NOTE: Not all games follow the MIPS ABI! Tekken 6, for example, will crash
- // with this enabled.
- gpr.DiscardR(MIPS_REG_COMPILER_SCRATCH);
- for (int i = MIPS_REG_A0; i <= MIPS_REG_T7; i++)
- gpr.DiscardR((MIPSGPReg)i);
- gpr.DiscardR(MIPS_REG_T8);
- gpr.DiscardR(MIPS_REG_T9);
- }
-
- gpr.MapReg(rs);
- destReg = gpr.R(rs); // Safe because FlushAll doesn't change any regs
- FlushAll();
- } else {
- // Delay slot - this case is very rare, might be able to free up R8.
- gpr.MapReg(rs);
- MOV(R8, gpr.R(rs));
- if (andLink)
- gpr.SetImm(rd, GetCompilerPC() + 8);
- CompileDelaySlot(DELAYSLOT_NICE);
- FlushAll();
- }
-
- switch (op & 0x3f)
- {
- case 8: //jr
- break;
- case 9: //jalr
- break;
- default:
- _dbg_assert_msg_(false,"Trying to compile instruction that can't be compiled");
- break;
- }
-
- WriteExitDestInR(destReg);
- js.compiling = false;
-}
-
-
-void ArmJit::Comp_Syscall(MIPSOpcode op)
-{
- if (op.encoding == 0x03FFFFcc) {
- WARN_LOG(Log::JIT, "Encountered bad syscall instruction at %08x (%08x)", js.compilerPC, op.encoding);
- }
-
- if (!g_Config.bSkipDeadbeefFilling)
- {
- // All of these will be overwritten with DEADBEEF anyway.
- gpr.DiscardR(MIPS_REG_COMPILER_SCRATCH);
- // We need to keep A0 - T3, which are used for args.
- gpr.DiscardR(MIPS_REG_T4);
- gpr.DiscardR(MIPS_REG_T5);
- gpr.DiscardR(MIPS_REG_T6);
- gpr.DiscardR(MIPS_REG_T7);
- gpr.DiscardR(MIPS_REG_T8);
- gpr.DiscardR(MIPS_REG_T9);
-
- gpr.DiscardR(MIPS_REG_HI);
- gpr.DiscardR(MIPS_REG_LO);
- }
-
- // If we're in a delay slot, this is off by one.
- const int offset = js.inDelaySlot ? -1 : 0;
- WriteDownCount(offset);
- RestoreRoundingMode();
- js.downcountAmount = -offset;
-
- if (!js.inDelaySlot) {
- gpr.SetRegImm(SCRATCHREG1, GetCompilerPC() + 4);
- MovToPC(SCRATCHREG1);
- }
-
- FlushAll();
-
- SaveDowncount();
-#ifdef USE_PROFILER
- // When profiling, we can't skip CallSyscall, since it times syscalls.
- gpr.SetRegImm(R0, op.encoding);
- QuickCallFunction(R1, (void *)&CallSyscall);
-#else
- // Skip the CallSyscall where possible.
- const HLEFunction *func = GetSyscallFunctionData(op, js.compilerPC);
- if (func) {
- void *quickFunc = GetQuickSyscallFunc(func, op);
- if (quickFunc) {
- gpr.SetRegImm(R0, (uintptr_t)func);
- // Already flushed, so R1 is safe.
- QuickCallFunction(R1, quickFunc);
- } else {
- gpr.SetRegImm(R0, op.encoding);
- QuickCallFunction(R1, (void *)&CallSyscall);
- }
- } else {
- gpr.SetRegImm(R0, js.compilerPC);
- QuickCallFunction(R1, (void *)&CallSyscallUnresolvedAtPC);
- }
-#endif
- ApplyRoundingMode();
- RestoreDowncount();
-
- WriteSyscallExit();
- js.compiling = false;
-}
-
-void ArmJit::Comp_Break(MIPSOpcode op)
-{
- Comp_Generic(op);
- WriteSyscallExit();
- js.compiling = false;
-}
-
-} // namespace Mipscomp
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompFPU.cpp b/Core/MIPS/ARM/ArmCompFPU.cpp
deleted file mode 100644
index ad931188f6..0000000000
--- a/Core/MIPS/ARM/ArmCompFPU.cpp
+++ /dev/null
@@ -1,445 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include "Core/Config.h"
-#include "Core/MemMap.h"
-#include "Core/MIPS/MIPS.h"
-#include "Core/MIPS/MIPSCodeUtils.h"
-#include "Core/MIPS/MIPSTables.h"
-
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-#include "Common/CPUDetect.h"
-
-#define _RS MIPS_GET_RS(op)
-#define _RT MIPS_GET_RT(op)
-#define _RD MIPS_GET_RD(op)
-#define _FS MIPS_GET_FS(op)
-#define _FT MIPS_GET_FT(op)
-#define _FD MIPS_GET_FD(op)
-#define _SA MIPS_GET_SA(op)
-#define _POS ((op>> 6) & 0x1F)
-#define _SIZE ((op>>11) & 0x1F)
-#define _IMM16 (signed short)(op & 0xFFFF)
-#define _IMM26 (op & 0x03FFFFFF)
-
-// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
-// Currently known non working ones should have DISABLE.
-
-// #define CONDITIONAL_DISABLE(flag) { Comp_Generic(op); return; }
-#define CONDITIONAL_DISABLE(flag) if (jo.Disabled(JitDisable::flag)) { Comp_Generic(op); return; }
-#define DISABLE { Comp_Generic(op); return; }
-
-namespace MIPSComp
-{
- using namespace ArmGen;
- using namespace ArmJitConstants;
-
-void ArmJit::Comp_FPU3op(MIPSOpcode op)
-{
- CONDITIONAL_DISABLE(FPU);
-
- int ft = _FT;
- int fs = _FS;
- int fd = _FD;
-
- fpr.MapDirtyInIn(fd, fs, ft);
- switch (op & 0x3f)
- {
- case 0: VADD(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) + F(ft); //add
- case 1: VSUB(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) - F(ft); //sub
- case 2: { //F(fd) = F(fs) * F(ft); //mul
- MIPSOpcode nextOp = GetOffsetInstruction(1);
- // Optimization possible if destination is the same
- if (fd == (int)((nextOp>>6) & 0x1F)) {
- // VMUL + VNEG -> VNMUL
- if (!strcmp(MIPSGetName(nextOp), "neg.s")) {
- if (fd == (int)((nextOp>>11) & 0x1F)) {
- VNMUL(fpr.R(fd), fpr.R(fs), fpr.R(ft));
- EatInstruction(nextOp);
- }
- return;
- }
- }
- VMUL(fpr.R(fd), fpr.R(fs), fpr.R(ft));
- break;
- }
- case 3: VDIV(fpr.R(fd), fpr.R(fs), fpr.R(ft)); break; //F(fd) = F(fs) / F(ft); //div
- default:
- DISABLE;
- return;
- }
-}
-
-extern int logBlocks;
-
-void ArmJit::Comp_FPULS(MIPSOpcode op)
-{
- CONDITIONAL_DISABLE(LSU_FPU);
- CheckMemoryBreakpoint();
-
- if (js.kernelMode) {
- // Send all memory accesses to the interpreter in kernel mode.
- // TODO: Do something faster - but it hardly matters, currently this is VSH-only.
- DISABLE;
- return;
- }
-
- s32 offset = SignExtend16ToS32(op & 0xFFFF);
- int ft = _FT;
- MIPSGPReg rs = _RS;
- bool doCheck = false;
- switch(op >> 26)
- {
- case 49: //lwc1
- if (!gpr.IsImm(rs) && jo.cachePointers && g_Config.bFastMemory && (offset & 3) == 0 && offset < 0x400 && offset > -0x400) {
- gpr.MapRegAsPointer(rs);
- fpr.MapReg(ft, MAP_NOINIT | MAP_DIRTY);
- VLDR(fpr.R(ft), gpr.RPtr(rs), offset);
- break;
- }
-
- fpr.SpillLock(ft);
- fpr.MapReg(ft, MAP_NOINIT | MAP_DIRTY);
- if (gpr.IsImm(rs)) {
- u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, offset);
- } else {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip;
- if (doCheck) {
- skip = B_CC(CC_EQ);
- }
- VLDR(fpr.R(ft), R0, 0);
- if (doCheck) {
- SetJumpTarget(skip);
- }
-#else
- VLDR(fpr.R(ft), R0, 0);
- if (doCheck) {
- SetCC(CC_EQ);
- MOVI2R(R0, 0);
- VMOV(fpr.R(ft), R0);
- SetCC(CC_AL);
- }
-#endif
- fpr.ReleaseSpillLocksAndDiscardTemps();
- break;
-
- case 57: //swc1
- if (!gpr.IsImm(rs) && jo.cachePointers && g_Config.bFastMemory && (offset & 3) == 0 && offset < 0x400 && offset > -0x400) {
- gpr.MapRegAsPointer(rs);
- fpr.MapReg(ft, 0);
- VSTR(fpr.R(ft), gpr.RPtr(rs), offset);
- break;
- }
-
- fpr.MapReg(ft);
- if (gpr.IsImm(rs)) {
- u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, offset);
- } else {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip2;
- if (doCheck) {
- skip2 = B_CC(CC_EQ);
- }
- VSTR(fpr.R(ft), R0, 0);
- if (doCheck) {
- SetJumpTarget(skip2);
- }
-#else
- VSTR(fpr.R(ft), R0, 0);
- if (doCheck) {
- SetCC(CC_AL);
- }
-#endif
- break;
-
- default:
- Comp_Generic(op);
- return;
- }
-}
-
-void ArmJit::Comp_FPUComp(MIPSOpcode op) {
- CONDITIONAL_DISABLE(FPU_COMP);
-
- int opc = op & 0xF;
- if (opc >= 8) opc -= 8; // alias
- if (opc == 0) { // f, sf (signalling false)
- gpr.SetImm(MIPS_REG_FPCOND, 0);
- return;
- }
-
- int fs = _FS;
- int ft = _FT;
- gpr.MapReg(MIPS_REG_FPCOND, MAP_DIRTY | MAP_NOINIT);
- fpr.MapInIn(fs, ft);
- VCMP(fpr.R(fs), fpr.R(ft));
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- switch(opc)
- {
- case 1: // un, ngle (unordered)
- SetCC(CC_VS);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_VC);
- break;
- case 2: // eq, seq (equal, ordered)
- SetCC(CC_EQ);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_NEQ);
- break;
- case 3: // ueq, ngl (equal, unordered)
- SetCC(CC_EQ);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_NEQ);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 0);
- SetCC(CC_VS);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_AL);
- return;
- case 4: // olt, lt (less than, ordered)
- SetCC(CC_LO);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_HS);
- break;
- case 5: // ult, nge (less than, unordered)
- SetCC(CC_LT);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_GE);
- break;
- case 6: // ole, le (less equal, ordered)
- SetCC(CC_LS);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_HI);
- break;
- case 7: // ule, ngt (less equal, unordered)
- SetCC(CC_LE);
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 1);
- SetCC(CC_GT);
- break;
- default:
- Comp_Generic(op);
- return;
- }
- MOVI2R(gpr.R(MIPS_REG_FPCOND), 0);
- SetCC(CC_AL);
-}
-
-// round.w.s, ceil.w.s and floor.w.s use their own rounding mode. Only RMode is swapped, so the
-// guest's flush-to-zero still applies to a denormal input (cpu/fpu/denormal).
-void ArmJit::CompFixedRoundConversion(int fd, int fs, int rmode) {
- fpr.MapDirtyIn(fd, fs);
- VMRS(SCRATCHREG2);
- BIC(SCRATCHREG1, SCRATCHREG2, AssumeMakeOperand2(3 << 22));
- if (rmode != 0) {
- ORR(SCRATCHREG1, SCRATCHREG1, AssumeMakeOperand2(rmode << 22));
- }
- VMSR(SCRATCHREG1);
- VCMP(fpr.R(fs), fpr.R(fs));
- VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_VS);
- MOVIU2F(fpr.R(fd), 0x7FFFFFFF, SCRATCHREG1);
- SetCC(CC_AL);
- VMSR(SCRATCHREG2);
-}
-
-void ArmJit::Comp_FPU2op(MIPSOpcode op) {
- CONDITIONAL_DISABLE(FPU);
-
- int fs = _FS;
- int fd = _FD;
-
- switch (op & 0x3f) {
- case 4: //F(fd) = sqrtf(F(fs)); break; //sqrt
- fpr.MapDirtyIn(fd, fs);
- VSQRT(fpr.R(fd), fpr.R(fs));
- break;
- case 5: //F(fd) = fabsf(F(fs)); break; //abs
- fpr.MapDirtyIn(fd, fs);
- VABS(fpr.R(fd), fpr.R(fs));
- break;
- case 6: //F(fd) = F(fs); break; //mov
- fpr.MapDirtyIn(fd, fs);
- VMOV(fpr.R(fd), fpr.R(fs));
- break;
- case 7: //F(fd) = -F(fs); break; //neg
- fpr.MapDirtyIn(fd, fs);
- VNEG(fpr.R(fd), fpr.R(fs));
- break;
- case 12: //FsI(fd) = (int)floorf(F(fs)+0.5f); break; //round.w.s
- CompFixedRoundConversion(fd, fs, 0);
- break;
- case 13: //FsI(fd) = Rto0(F(fs))); break; //trunc.w.s
- fpr.MapDirtyIn(fd, fs);
- VCMP(fpr.R(fs), fpr.R(fs));
- VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED | ROUND_TO_ZERO);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_VS);
- MOVIU2F(fpr.R(fd), 0x7FFFFFFF, SCRATCHREG1);
- SetCC(CC_AL);
- break;
- case 14: //FsI(fd) = (int)ceilf (F(fs)); break; //ceil.w.s
- CompFixedRoundConversion(fd, fs, 1);
- break;
- case 15: //FsI(fd) = (int)floorf(F(fs)); break; //floor.w.s
- CompFixedRoundConversion(fd, fs, 2);
- break;
- case 32: //F(fd) = (float)FsI(fs); break; //cvt.s.w
- fpr.MapDirtyIn(fd, fs);
- VCVT(fpr.R(fd), fpr.R(fs), TO_FLOAT | IS_SIGNED);
- break;
- case 36: //FsI(fd) = (int) F(fs); break; //cvt.w.s
- fpr.MapDirtyIn(fd, fs);
- VCMP(fpr.R(fs), fpr.R(fs));
- VCVT(fpr.R(fd), fpr.R(fs), TO_INT | IS_SIGNED);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_VS);
- MOVIU2F(fpr.R(fd), 0x7FFFFFFF, SCRATCHREG1);
- SetCC(CC_AL);
- break;
- default:
- DISABLE;
- }
-}
-
-void ArmJit::Comp_mxc1(MIPSOpcode op)
-{
- CONDITIONAL_DISABLE(FPU_XFER);
-
- int fs = _FS;
- MIPSGPReg rt = _RT;
-
- switch ((op >> 21) & 0x1f)
- {
- case 0: // R(rt) = FI(fs); break; //mfc1
- if (rt == MIPS_REG_ZERO) {
- return;
- }
- gpr.MapReg(rt, MAP_DIRTY | MAP_NOINIT);
- if (fpr.IsMapped(fs)) {
- VMOV(gpr.R(rt), fpr.R(fs));
- } else {
- LDR(gpr.R(rt), CTXREG, fpr.GetMipsRegOffset(fs));
- }
- return;
-
- case 2: //cfc1
- if (rt == MIPS_REG_ZERO) {
- return;
- }
- if (fs == 31) {
- if (gpr.IsImm(MIPS_REG_FPCOND)) {
- gpr.MapReg(rt, MAP_DIRTY | MAP_NOINIT);
- LDR(gpr.R(rt), CTXREG, offsetof(MIPSState, fcr31));
- if (gpr.GetImm(MIPS_REG_FPCOND) & 1) {
- ORI2R(gpr.R(rt), gpr.R(rt), 0x1 << 23, SCRATCHREG2);
- } else {
- ANDI2R(gpr.R(rt), gpr.R(rt), ~(0x1 << 23), SCRATCHREG2);
- }
- } else {
- gpr.MapDirtyIn(rt, MIPS_REG_FPCOND);
- LDR(gpr.R(rt), CTXREG, offsetof(MIPSState, fcr31));
-#if PPSSPP_ARCH(ARMV7)
- BFI(gpr.R(rt), gpr.R(MIPS_REG_FPCOND), 23, 1);
-#else
- AND(SCRATCHREG1, gpr.R(MIPS_REG_FPCOND), Operand2(1)); // Just in case
- ANDI2R(gpr.R(rt), gpr.R(rt), ~(0x1 << 23), SCRATCHREG2); // SCRATCHREG2 won't be used, this turns into a simple BIC.
- ORR(gpr.R(rt), gpr.R(rt), Operand2(SCRATCHREG1, ST_LSL, 23));
-#endif
- }
- } else if (fs == 0) {
- gpr.SetImm(rt, MIPSState::FCR0_VALUE);
- } else {
- // Unsupported regs are always 0.
- gpr.SetImm(rt, 0);
- }
- return;
-
- case 4: //FI(fs) = R(rt); break; //mtc1
- if (gpr.IsImm(rt) && gpr.GetImm(rt) == 0) {
- fpr.MapReg(fs, MAP_NOINIT);
- MOVI2F(fpr.R(fs), 0.0f, R0);
- } else {
- gpr.MapReg(rt);
- fpr.MapReg(fs, MAP_NOINIT);
- VMOV(fpr.R(fs), gpr.R(rt));
- }
- return;
-
- case 6: //ctc1
- if (fs == 31) {
- // Must clear before setting, since ApplyRoundingMode() assumes it was cleared.
- RestoreRoundingMode();
- bool wasImm = gpr.IsImm(rt);
- u32 immVal = -1;
- if (wasImm) {
- immVal = gpr.GetImm(rt);
- gpr.SetImm(MIPS_REG_FPCOND, (immVal >> 23) & 1);
- gpr.MapReg(rt);
- } else {
- gpr.MapDirtyIn(MIPS_REG_FPCOND, rt);
- }
-
- // Update MIPS state. Only these bits can be written (pspautotests cpu/fpu/fcr).
- ANDI2R(SCRATCHREG1, gpr.R(rt), 0x0181FFFF, SCRATCHREG2);
- STR(SCRATCHREG1, CTXREG, offsetof(MIPSState, fcr31));
- if (!wasImm) {
-#if PPSSPP_ARCH(ARMV7)
- UBFX(gpr.R(MIPS_REG_FPCOND), gpr.R(rt), 23, 1);
-#else
- MOV(SCRATCHREG1, Operand2(gpr.R(rt), ST_LSR, 23));
- AND(gpr.R(MIPS_REG_FPCOND), SCRATCHREG1, Operand2(1));
-#endif
- UpdateRoundingMode();
- } else {
- UpdateRoundingMode(immVal);
- }
- ApplyRoundingMode();
- } else {
- Comp_Generic(op);
- }
- return;
- }
-}
-
-} // namespace MIPSComp
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompLoadStore.cpp b/Core/MIPS/ARM/ArmCompLoadStore.cpp
deleted file mode 100644
index 249d4a9f69..0000000000
--- a/Core/MIPS/ARM/ArmCompLoadStore.cpp
+++ /dev/null
@@ -1,424 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include "Core/MemMap.h"
-#include "Core/Config.h"
-#include "Core/MIPS/MIPS.h"
-#include "Core/MIPS/MIPSAnalyst.h"
-#include "Core/MIPS/MIPSCodeUtils.h"
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-
-#define _RS MIPS_GET_RS(op)
-#define _RT MIPS_GET_RT(op)
-#define _RD MIPS_GET_RD(op)
-#define _FS MIPS_GET_FS(op)
-#define _FT MIPS_GET_FT(op)
-#define _FD MIPS_GET_FD(op)
-#define _SA MIPS_GET_SA(op)
-#define _POS ((op>> 6) & 0x1F)
-#define _SIZE ((op>>11) & 0x1F)
-#define _IMM16 (signed short)(op & 0xFFFF)
-#define _IMM26 (op & 0x03FFFFFF)
-
-// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
-// Currently known non working ones should have DISABLE.
-
-// #define CONDITIONAL_DISABLE(flag) { Comp_Generic(op); return; }
-#define CONDITIONAL_DISABLE(flag) if (jo.Disabled(JitDisable::flag)) { Comp_Generic(op); return; }
-#define DISABLE { Comp_Generic(op); return; }
-
-namespace MIPSComp
-{
- using namespace ArmGen;
- using namespace ArmJitConstants;
-
- void ArmJit::SetR0ToEffectiveAddress(MIPSGPReg rs, s16 offset) {
- Operand2 op2;
- if (offset) {
- bool negated;
- if (TryMakeOperand2_AllowNegation(offset, op2, &negated)) {
- if (!negated)
- ADD(R0, gpr.R(rs), op2);
- else
- SUB(R0, gpr.R(rs), op2);
- } else {
- // Try to avoid using MOVT
- if (offset < 0) {
- gpr.SetRegImm(R0, (u32)(-offset));
- SUB(R0, gpr.R(rs), R0);
- } else {
- gpr.SetRegImm(R0, (u32)offset);
- ADD(R0, gpr.R(rs), R0);
- }
- }
- BIC(R0, R0, Operand2(0xC0, 4)); // &= 0x3FFFFFFF
- } else {
- BIC(R0, gpr.R(rs), Operand2(0xC0, 4)); // &= 0x3FFFFFFF
- }
- }
-
- void ArmJit::SetCCAndR0ForSafeAddress(MIPSGPReg rs, s16 offset, ARMReg tempReg, bool reverse) {
- SetR0ToEffectiveAddress(rs, offset);
-
- // There are three valid ranges. Each one gets a bit.
- const u32 BIT_SCRATCH = 1, BIT_RAM = 2, BIT_VRAM = 4;
- MOVI2R(tempReg, BIT_SCRATCH | BIT_RAM | BIT_VRAM);
-
- CMP(R0, AssumeMakeOperand2(PSP_GetScratchpadMemoryBase()));
- SetCC(CC_LO);
- BIC(tempReg, tempReg, BIT_SCRATCH);
- SetCC(CC_HS);
- CMP(R0, AssumeMakeOperand2(PSP_GetScratchpadMemoryEnd()));
- BIC(tempReg, tempReg, BIT_SCRATCH);
-
- // If it was in that range, later compares don't matter.
- CMP(R0, AssumeMakeOperand2(PSP_GetVidMemBase()));
- SetCC(CC_LO);
- BIC(tempReg, tempReg, BIT_VRAM);
- SetCC(CC_HS);
- CMP(R0, AssumeMakeOperand2(PSP_GetVidMemEnd()));
- BIC(tempReg, tempReg, BIT_VRAM);
-
- CMP(R0, AssumeMakeOperand2(PSP_GetKernelMemoryBase()));
- SetCC(CC_LO);
- BIC(tempReg, tempReg, BIT_RAM);
- SetCC(CC_HS);
- CMP(R0, AssumeMakeOperand2(PSP_GetUserMemoryEnd()));
- BIC(tempReg, tempReg, BIT_RAM);
-
- // If we left any bit set, the address is OK.
- SetCC(CC_AL);
- CMP(tempReg, 0);
- SetCC(reverse ? CC_EQ : CC_GT);
- }
-
- void ArmJit::Comp_ITypeMemLR(MIPSOpcode op, bool load) {
- CONDITIONAL_DISABLE(LSU);
- CheckMemoryBreakpoint();
- int offset = SignExtend16ToS32(op & 0xFFFF);
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- int o = op >> 26;
-
- if (!js.inDelaySlot && !jo.Disabled(JitDisable::LSU_UNALIGNED)) {
- // Optimisation: Combine to single unaligned load/store
- bool isLeft = (o == 34 || o == 42);
- CheckMemoryBreakpoint(1);
- MIPSOpcode nextOp = GetOffsetInstruction(1);
- // Find a matching shift in opposite direction with opposite offset.
- if (nextOp == (isLeft ? (op.encoding + (4<<26) - 3)
- : (op.encoding - (4<<26) + 3)))
- {
- EatInstruction(nextOp);
- nextOp = MIPSOpcode(((load ? 35 : 43) << 26) | ((isLeft ? nextOp : op) & 0x03FFFFFF)); //lw, sw
- Comp_ITypeMem(nextOp);
- return;
- }
- }
-
- u32 iaddr = gpr.IsImm(rs) ? offset + gpr.GetImm(rs) : 0xFFFFFFFF;
- bool doCheck = false;
- FixupBranch skip;
-
- if (gpr.IsImm(rs) && Memory::IsValidAddress(iaddr)) {
- u32 addr = iaddr & 0x3FFFFFFF;
- // Need to initialize since this only loads part of the register.
- // But rs no longer matters (even if rs == rt) since we have the address.
- gpr.MapReg(rt, load ? MAP_DIRTY : 0);
- gpr.SetRegImm(R0, addr & ~3);
-
- u8 shift = (addr & 3) * 8;
-
- switch (o) {
- case 34: // lwl
- LDR(R0, MEMBASEREG, R0);
- ANDI2R(gpr.R(rt), gpr.R(rt), 0x00ffffff >> shift, SCRATCHREG2);
- ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSL, 24 - shift));
- break;
-
- case 38: // lwr
- LDR(R0, MEMBASEREG, R0);
- ANDI2R(gpr.R(rt), gpr.R(rt), 0xffffff00 << (24 - shift), SCRATCHREG2);
- ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSR, shift));
- break;
-
- case 42: // swl
- LDR(SCRATCHREG2, MEMBASEREG, R0);
- // Don't worry, can't use temporary.
- ANDI2R(SCRATCHREG2, SCRATCHREG2, 0xffffff00 << shift, R0);
- ORR(SCRATCHREG2, SCRATCHREG2, Operand2(gpr.R(rt), ST_LSR, 24 - shift));
- STR(SCRATCHREG2, MEMBASEREG, R0);
- break;
-
- case 46: // swr
- LDR(SCRATCHREG2, MEMBASEREG, R0);
- // Don't worry, can't use temporary.
- ANDI2R(SCRATCHREG2, SCRATCHREG2, 0x00ffffff >> (24 - shift), R0);
- ORR(SCRATCHREG2, SCRATCHREG2, Operand2(gpr.R(rt), ST_LSL, shift));
- STR(SCRATCHREG2, MEMBASEREG, R0);
- break;
- }
- return;
- }
-
- // This gets hit in a few games, as a result of never-taken delay slots (some branch types
- // conditionally execute the delay slot instructions). Ignore in those cases.
- if (!js.inDelaySlot) {
- _dbg_assert_msg_(!gpr.IsImm(rs), "Invalid immediate address %08x? CPU bug?", iaddr);
- }
-
- if (load) {
- gpr.MapDirtyIn(rt, rs, false);
- } else {
- gpr.MapInIn(rt, rs);
- }
-
- if (!g_Config.bFastMemory && rs != MIPS_REG_SP) {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2, true);
- doCheck = true;
- } else {
- SetR0ToEffectiveAddress(rs, offset);
- }
- if (doCheck) {
- skip = B();
- }
- SetCC(CC_AL);
-
- // Need temp regs. TODO: Get from the regcache?
- static const ARMReg LR_SCRATCHREG3 = R9;
- static const ARMReg LR_SCRATCHREG4 = R10;
- if (load) {
- PUSH(1, LR_SCRATCHREG3);
- } else {
- PUSH(2, LR_SCRATCHREG3, LR_SCRATCHREG4);
- }
-
- // Here's our shift amount.
- AND(SCRATCHREG2, R0, 3);
- LSL(SCRATCHREG2, SCRATCHREG2, 3);
-
- // Now align the address for the actual read.
- BIC(R0, R0, 3);
-
- switch (o) {
- case 34: // lwl
- MOVI2R(LR_SCRATCHREG3, 0x00ffffff);
- LDR(R0, MEMBASEREG, R0);
- AND(gpr.R(rt), gpr.R(rt), Operand2(LR_SCRATCHREG3, ST_LSR, SCRATCHREG2));
- RSB(SCRATCHREG2, SCRATCHREG2, 24);
- ORR(gpr.R(rt), gpr.R(rt), Operand2(R0, ST_LSL, SCRATCHREG2));
- break;
-
- case 38: // lwr
- MOVI2R(LR_SCRATCHREG3, 0xffffff00);
- LDR(R0, MEMBASEREG, R0);
- LSR(R0, R0, SCRATCHREG2);
- RSB(SCRATCHREG2, SCRATCHREG2, 24);
- AND(gpr.R(rt), gpr.R(rt), Operand2(LR_SCRATCHREG3, ST_LSL, SCRATCHREG2));
- ORR(gpr.R(rt), gpr.R(rt), R0);
- break;
-
- case 42: // swl
- MOVI2R(LR_SCRATCHREG3, 0xffffff00);
- LDR(LR_SCRATCHREG4, MEMBASEREG, R0);
- AND(LR_SCRATCHREG4, LR_SCRATCHREG4, Operand2(LR_SCRATCHREG3, ST_LSL, SCRATCHREG2));
- RSB(SCRATCHREG2, SCRATCHREG2, 24);
- ORR(LR_SCRATCHREG4, LR_SCRATCHREG4, Operand2(gpr.R(rt), ST_LSR, SCRATCHREG2));
- STR(LR_SCRATCHREG4, MEMBASEREG, R0);
- break;
-
- case 46: // swr
- MOVI2R(LR_SCRATCHREG3, 0x00ffffff);
- LDR(LR_SCRATCHREG4, MEMBASEREG, R0);
- RSB(SCRATCHREG2, SCRATCHREG2, 24);
- AND(LR_SCRATCHREG4, LR_SCRATCHREG4, Operand2(LR_SCRATCHREG3, ST_LSR, SCRATCHREG2));
- RSB(SCRATCHREG2, SCRATCHREG2, 24);
- ORR(LR_SCRATCHREG4, LR_SCRATCHREG4, Operand2(gpr.R(rt), ST_LSL, SCRATCHREG2));
- STR(LR_SCRATCHREG4, MEMBASEREG, R0);
- break;
- }
-
- if (load) {
- POP(1, LR_SCRATCHREG3);
- } else {
- POP(2, LR_SCRATCHREG3, LR_SCRATCHREG4);
- }
-
- if (doCheck) {
- SetJumpTarget(skip);
- }
- }
-
- void ArmJit::Comp_ITypeMem(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(LSU);
- CheckMemoryBreakpoint();
-
- if (js.kernelMode) {
- // Send all memory accesses to the interpreter in kernel mode.
- // TODO: Do something faster - but it hardly matters, currently this is VSH-only.
- DISABLE;
- return;
- }
-
- int offset = (signed short)(op&0xFFFF);
- bool load = false;
- MIPSGPReg rt = _RT;
- MIPSGPReg rs = _RS;
- int o = op>>26;
- // 16-bit accesses can go through the depth layout (Memory::DepthMirrored16).
- if (Memory::DepthMirrorsActive() && (o == 33 || o == 37 || o == 41)) {
- DISABLE;
- }
- if (((op >> 29) & 1) == 0 && rt == MIPS_REG_ZERO) {
- // Don't load anything into $zr
- return;
- }
-
- u32 iaddr = gpr.IsImm(rs) ? offset + gpr.GetImm(rs) : 0xFFFFFFFF;
- bool doCheck = false;
- ARMReg addrReg = R0;
-
- switch (o) {
- case 32: //lb
- case 33: //lh
- case 35: //lw
- case 36: //lbu
- case 37: //lhu
- load = true;
- case 40: //sb
- case 41: //sh
- case 43: //sw
- // Map base register as pointer and go from there - if the displacement isn't too big.
- // This is faster if there are multiple loads from the same pointer. Need to hook up the MIPS analyzer..
- if (jo.cachePointers && g_Config.bFastMemory) {
- // ARM has smaller load/store immediate displacements than MIPS, 12 bits - and some memory ops only have 8 bits.
- int offsetRange = 0x3ff;
- if (o == 41 || o == 33 || o == 37 || o == 32)
- offsetRange = 0xff; // 8 bit offset only
- if (!gpr.IsImm(rs) && rs != rt && (offset <= offsetRange) && offset >= -offsetRange) {
- gpr.SpillLock(rs, rt);
- gpr.MapRegAsPointer(rs);
- gpr.MapReg(rt, load ? MAP_NOINIT : 0);
- switch (o) {
- case 35: LDR (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 37: LDRH (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 33: LDRSH(gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 36: LDRB (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 32: LDRSB(gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- // Store
- case 43: STR (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 41: STRH (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- case 40: STRB (gpr.R(rt), gpr.RPtr(rs), Operand2(offset, TYPE_IMM)); break;
- }
- gpr.ReleaseSpillLocks();
- break;
- }
- }
-
- if (gpr.IsImm(rs) && Memory::IsValidAddress(iaddr)) {
- // TODO: Avoid mapping a register for the "zero" register, use R0 instead.
-
- // We can compute the full address at compile time. Kickass.
- u32 addr = iaddr & 0x3FFFFFFF;
-
- if (addr == iaddr && offset == 0) {
- // It was already safe. Let's shove it into a reg and use it directly.
- load ? gpr.MapDirtyIn(rt, rs) : gpr.MapInIn(rt, rs);
- addrReg = gpr.R(rs);
- } else {
- // In this case, only map rt. rs+offset will be in R0.
- gpr.MapReg(rt, load ? MAP_NOINIT : 0);
- gpr.SetRegImm(R0, addr);
- addrReg = R0;
- }
- } else {
- _dbg_assert_msg_(!gpr.IsImm(rs), "Invalid immediate address? CPU bug?");
- load ? gpr.MapDirtyIn(rt, rs) : gpr.MapInIn(rt, rs);
-
- if (!g_Config.bFastMemory && rs != MIPS_REG_SP) {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2);
- doCheck = true;
- } else {
- SetR0ToEffectiveAddress(rs, offset);
- }
- addrReg = R0;
- }
-
- switch (o)
- {
- // Load
- case 35: LDR (gpr.R(rt), MEMBASEREG, addrReg); break;
- case 37: LDRH (gpr.R(rt), MEMBASEREG, addrReg); break;
- case 33: LDRSH(gpr.R(rt), MEMBASEREG, addrReg); break;
- case 36: LDRB (gpr.R(rt), MEMBASEREG, addrReg); break;
- case 32: LDRSB(gpr.R(rt), MEMBASEREG, addrReg); break;
- // Store
- case 43: STR (gpr.R(rt), MEMBASEREG, addrReg); break;
- case 41: STRH (gpr.R(rt), MEMBASEREG, addrReg); break;
- case 40: STRB (gpr.R(rt), MEMBASEREG, addrReg); break;
- }
- if (doCheck) {
- if (load) {
- SetCC(CC_EQ);
- MOVI2R(gpr.R(rt), 0);
- }
- SetCC(CC_AL);
- }
- break;
- case 34: //lwl
- case 38: //lwr
- load = true;
- case 42: //swl
- case 46: //swr
- Comp_ITypeMemLR(op, load);
- break;
- default:
- Comp_Generic(op);
- return;
- }
- }
-
- void ArmJit::Comp_StoreSync(MIPSOpcode op) {
- CONDITIONAL_DISABLE(LSU);
-
- DISABLE;
- }
-
- void ArmJit::Comp_Cache(MIPSOpcode op) {
- CONDITIONAL_DISABLE(LSU);
-
- int func = (op >> 16) & 0x1F;
-
- // See Int_Cache for the definitions.
- switch (func) {
- case 24: break;
- case 25: break;
- case 27: break;
- case 30: break;
- default:
- // Fall back to the interpreter.
- DISABLE;
- }
- }
-}
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompReplace.cpp b/Core/MIPS/ARM/ArmCompReplace.cpp
deleted file mode 100644
index dbe49cd256..0000000000
--- a/Core/MIPS/ARM/ArmCompReplace.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2013- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include "Common/CPUDetect.h"
-#include "Core/MemMap.h"
-#include "Core/MIPS/JitCommon/JitCommon.h"
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-
-namespace MIPSComp {
-
-int ArmJit::Replace_fabsf() {
- fpr.MapDirtyIn(0, 12);
- VABS(fpr.R(0), fpr.R(12));
- return 4; // Number of instructions in the MIPS function
-}
-
-}
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmCompVFPU.cpp b/Core/MIPS/ARM/ArmCompVFPU.cpp
deleted file mode 100644
index d5569adf06..0000000000
--- a/Core/MIPS/ARM/ArmCompVFPU.cpp
+++ /dev/null
@@ -1,2419 +0,0 @@
-// Copyright (c) 2012- PPSSPP Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0 or later versions.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// A copy of the GPL 2.0 should have been included with the program.
-// If not, see http://www.gnu.org/licenses/
-
-// Official git repository and contact information can be found at
-// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
-
-#include "ppsspp_config.h"
-#if PPSSPP_ARCH(ARM)
-
-#include
-#include
-#include "Common/CPUDetect.h"
-#include "Common/Data/Convert/SmallDataConvert.h"
-#include "Common/Math/math_util.h"
-
-#include "Core/Compatibility.h"
-#include "Core/Config.h"
-#include "Core/MemMap.h"
-#include "Core/Reporting.h"
-#include "Core/System.h"
-#include "Core/MIPS/MIPS.h"
-#include "Core/MIPS/MIPSTables.h"
-#include "Core/MIPS/MIPSAnalyst.h"
-#include "Core/MIPS/MIPSCodeUtils.h"
-
-#include "Core/MIPS/ARM/ArmJit.h"
-#include "Core/MIPS/ARM/ArmRegCache.h"
-
-// Cool NEON references:
-// http://www.delmarnorth.com/microwave/requirements/neon-test-tutorial.pdf
-
-// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
-// Currently known non working ones should have DISABLE.
-
-// #define CONDITIONAL_DISABLE { fpr.ReleaseSpillLocksAndDiscardTemps(); Comp_Generic(op); return; }
-#define CONDITIONAL_DISABLE(flag) if (jo.Disabled(JitDisable::flag)) { Comp_Generic(op); return; }
-#define DISABLE { fpr.ReleaseSpillLocksAndDiscardTemps(); Comp_Generic(op); return; }
-
-#define _RS MIPS_GET_RS(op)
-#define _RT MIPS_GET_RT(op)
-#define _RD MIPS_GET_RD(op)
-#define _FS MIPS_GET_FS(op)
-#define _FT MIPS_GET_FT(op)
-#define _FD MIPS_GET_FD(op)
-#define _SA MIPS_GET_SA(op)
-#define _POS ((op>> 6) & 0x1F)
-#define _SIZE ((op>>11) & 0x1F)
-#define _IMM16 (signed short)(op & 0xFFFF)
-#define _IMM26 (op & 0x03FFFFFF)
-
-namespace MIPSComp
-{
- using namespace ArmGen;
- using namespace ArmJitConstants;
-
- // Vector regs can overlap in all sorts of swizzled ways.
- // This does allow a single overlap in sregs[i].
- // True if the prefix only touches lanes the op has. A position past the size may only be the
- // identity, and a position within it may not name a lane past it (which zeroes the result lane
- // on hardware, see cpu/vfpu/prefix_ctrl - the interpreter handles that).
- static bool IsPrefixWithinSize(u32 prefix, VectorSize sz) {
- int n = GetNumVectorElements(sz);
- for (int i = 0; i < 4; i++) {
- int regnum = (prefix >> (i * 2)) & 3;
- int abs = (prefix >> (8 + i)) & 1;
- int negate = (prefix >> (16 + i)) & 1;
- int constants = (prefix >> (12 + i)) & 1;
- if (constants) {
- continue;
- }
- if (i >= n) {
- if (abs || negate || regnum != i)
- return false;
- } else if (regnum >= n) {
- return false;
- }
- }
-
- return true;
- }
-
- static bool IsPrefixWithinSize(u32 prefix, MIPSOpcode op) {
- return IsPrefixWithinSize(prefix, GetVecSize(op));
- }
-
- static bool IsOverlapSafeAllowS(int dreg, int di, int sn, u8 sregs[], int tn = 0, u8 tregs[] = NULL)
- {
- for (int i = 0; i < sn; ++i)
- {
- if (sregs[i] == dreg && i != di)
- return false;
- }
- for (int i = 0; i < tn; ++i)
- {
- if (tregs[i] == dreg)
- return false;
- }
-
- // Hurray, no overlap, we can write directly.
- return true;
- }
-
- static bool IsOverlapSafe(int dreg, int di, int sn, u8 sregs[], int tn = 0, u8 tregs[] = NULL)
- {
- return IsOverlapSafeAllowS(dreg, di, sn, sregs, tn, tregs) && sregs[di] != dreg;
- }
-
- void ArmJit::Comp_VPFX(MIPSOpcode op)
- {
- CONDITIONAL_DISABLE(VFPU_XFER);
- int data = op & 0xFFFFF;
- int regnum = (op >> 24) & 3;
- switch (regnum) {
- case 0: // S
- js.prefixS = data;
- js.prefixSFlag = JitState::PREFIX_KNOWN_DIRTY;
- break;
- case 1: // T
- js.prefixT = data;
- js.prefixTFlag = JitState::PREFIX_KNOWN_DIRTY;
- break;
- case 2: // D
- js.prefixD = data & 0x00000FFF;
- js.prefixDFlag = JitState::PREFIX_KNOWN_DIRTY;
- break;
- default:
- ERROR_LOG(Log::CPU, "VPFX - bad regnum %i : data=%08x", regnum, data);
- break;
- }
- }
-
- void ArmJit::ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz) {
- if (prefix == 0xE4)
- return;
-
- int n = GetNumVectorElements(sz);
- u8 origV[4];
- static const float constantArray[8] = {0.f, 1.f, 2.f, 0.5f, 3.f, 1.f/3.f, 0.25f, 1.f/6.f};
-
- for (int i = 0; i < n; i++)
- origV[i] = vregs[i];
-
- for (int i = 0; i < n; i++) {
- int regnum = (prefix >> (i*2)) & 3;
- int abs = (prefix >> (8+i)) & 1;
- int negate = (prefix >> (16+i)) & 1;
- int constants = (prefix >> (12+i)) & 1;
-
- // Unchanged, hurray.
- if (!constants && regnum == i && !abs && !negate)
- continue;
-
- // This puts the value into a temp reg, so we won't write the modified value back.
- vregs[i] = fpr.GetTempV();
- if (!constants) {
- fpr.MapDirtyInV(vregs[i], origV[regnum]);
- fpr.SpillLockV(vregs[i]);
-
- // Prefix may say "z, z, z, z" but if this is a pair, we force to x.
- // TODO: But some ops seem to use const 0 instead?
- if (regnum >= n) {
- WARN_LOG(Log::CPU, "JIT: Invalid VFPU swizzle: %08x : %d / %d at PC = %08x (%s)", prefix, regnum, n, GetCompilerPC(), MIPSDisasmAt(GetCompilerPC()).c_str());
- regnum = 0;
- }
-
- if (abs) {
- VABS(fpr.V(vregs[i]), fpr.V(origV[regnum]));
- if (negate)
- VNEG(fpr.V(vregs[i]), fpr.V(vregs[i]));
- } else {
- if (negate)
- VNEG(fpr.V(vregs[i]), fpr.V(origV[regnum]));
- else
- VMOV(fpr.V(vregs[i]), fpr.V(origV[regnum]));
- }
- } else {
- fpr.MapRegV(vregs[i], MAP_DIRTY | MAP_NOINIT);
- fpr.SpillLockV(vregs[i]);
- MOVI2F(fpr.V(vregs[i]), constantArray[regnum + (abs<<2)], SCRATCHREG1, negate != 0);
- }
- }
- }
-
- void ArmJit::GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg) {
- _assert_(js.prefixDFlag & JitState::PREFIX_KNOWN);
-
- GetVectorRegs(regs, sz, vectorReg);
- if (js.prefixD == 0)
- return;
-
- int n = GetNumVectorElements(sz);
- for (int i = 0; i < n; i++) {
- // Hopefully this is rare, we'll just write it into a reg we drop.
- if (js.VfpuWriteMask(i))
- regs[i] = fpr.GetTempV();
- }
- }
-
- void ArmJit::ApplyPrefixD(const u8 *vregs, VectorSize sz) {
- _assert_(js.prefixDFlag & JitState::PREFIX_KNOWN);
- if (!js.prefixD)
- return;
-
- int n = GetNumVectorElements(sz);
- for (int i = 0; i < n; i++) {
- if (js.VfpuWriteMask(i))
- continue;
-
- int sat = (js.prefixD >> (i * 2)) & 3;
- if (sat == 1) {
- // clamped = x < 0 ? (x > 1 ? 1 : x) : x [0, 1]
- fpr.MapRegV(vregs[i], MAP_DIRTY);
-
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- VCMP(fpr.V(vregs[i]), S0);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_LS);
- VMOV(fpr.V(vregs[i]), S0);
- SetCC(CC_AL);
- VCMP(fpr.V(vregs[i]), S1);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_GT);
- VMOV(fpr.V(vregs[i]), S1);
- SetCC(CC_AL);
- } else if (sat == 3) {
- // clamped = x < -1 ? (x > 1 ? 1 : x) : x [-1, 1]
- fpr.MapRegV(vregs[i], MAP_DIRTY);
-
- MOVI2F(S0, -1.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- VCMP(fpr.V(vregs[i]), S0);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_LO);
- VMOV(fpr.V(vregs[i]), S0);
- SetCC(CC_AL);
- VCMP(fpr.V(vregs[i]), S1);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_GT);
- VMOV(fpr.V(vregs[i]), S1);
- SetCC(CC_AL);
- }
- }
- }
-
- void ArmJit::Comp_SV(MIPSOpcode op) {
- CONDITIONAL_DISABLE(LSU_VFPU);
- CheckMemoryBreakpoint();
-
- if (js.kernelMode) {
- // Send all memory accesses to the interpreter in kernel mode.
- // TODO: Do something faster - but it hardly matters, currently this is VSH-only.
- DISABLE;
- return;
- }
-
- s32 offset = (signed short)(op & 0xFFFC);
- int vt = ((op >> 16) & 0x1f) | ((op & 3) << 5);
- MIPSGPReg rs = _RS;
-
- bool doCheck = false;
- switch (op >> 26)
- {
- case 50: //lv.s
- {
- if (!gpr.IsImm(rs) && jo.cachePointers && g_Config.bFastMemory && (offset & 3) == 0 && offset < 0x400 && offset > -0x400) {
- gpr.MapRegAsPointer(rs);
- fpr.MapRegV(vt, MAP_NOINIT | MAP_DIRTY);
- VLDR(fpr.V(vt), gpr.RPtr(rs), offset);
- break;
- }
-
- // CC might be set by slow path below, so load regs first.
- fpr.MapRegV(vt, MAP_DIRTY | MAP_NOINIT);
- if (gpr.IsImm(rs)) {
- u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, offset);
- } else {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip;
- if (doCheck) {
- skip = B_CC(CC_EQ);
- }
- VLDR(fpr.V(vt), R0, 0);
- if (doCheck) {
- SetJumpTarget(skip);
- SetCC(CC_AL);
- }
-#else
- VLDR(fpr.V(vt), R0, 0);
- if (doCheck) {
- SetCC(CC_EQ);
- MOVI2F(fpr.V(vt), 0.0f, SCRATCHREG1);
- SetCC(CC_AL);
- }
-#endif
- }
- break;
-
- case 58: //sv.s
- {
- if (!gpr.IsImm(rs) && jo.cachePointers && g_Config.bFastMemory && (offset & 3) == 0 && offset < 0x400 && offset > -0x400) {
- gpr.MapRegAsPointer(rs);
- fpr.MapRegV(vt, 0);
- VSTR(fpr.V(vt), gpr.RPtr(rs), offset);
- break;
- }
-
- // CC might be set by slow path below, so load regs first.
- fpr.MapRegV(vt);
- if (gpr.IsImm(rs)) {
- u32 addr = (offset + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, offset);
- } else {
- SetCCAndR0ForSafeAddress(rs, offset, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip;
- if (doCheck) {
- skip = B_CC(CC_EQ);
- }
- VSTR(fpr.V(vt), R0, 0);
- if (doCheck) {
- SetJumpTarget(skip);
- SetCC(CC_AL);
- }
-#else
- VSTR(fpr.V(vt), R0, 0);
- if (doCheck) {
- SetCC(CC_AL);
- }
-#endif
- }
- break;
-
-
- default:
- DISABLE;
- }
- }
-
- void ArmJit::Comp_SVQ(MIPSOpcode op) {
- CONDITIONAL_DISABLE(LSU_VFPU);
- CheckMemoryBreakpoint();
-
- if (js.kernelMode) {
- // Send all memory accesses to the interpreter in kernel mode.
- // TODO: Do something faster - but it hardly matters, currently this is VSH-only.
- DISABLE;
- return;
- }
-
- int imm = (signed short)(op&0xFFFC);
- int vt = (((op >> 16) & 0x1f)) | ((op&1) << 5);
- MIPSGPReg rs = _RS;
-
- bool doCheck = false;
- switch (op >> 26)
- {
- case 54: //lv.q
- {
- // CC might be set by slow path below, so load regs first.
- u8 vregs[4];
- GetVectorRegs(vregs, V_Quad, vt);
- fpr.MapRegsAndSpillLockV(vregs, V_Quad, MAP_DIRTY | MAP_NOINIT);
-
- if (gpr.IsImm(rs)) {
- u32 addr = (imm + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, imm);
- } else {
- SetCCAndR0ForSafeAddress(rs, imm, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip;
- if (doCheck) {
- skip = B_CC(CC_EQ);
- }
-
- bool consecutive = true;
- for (int i = 0; i < 3 && consecutive; i++)
- if ((fpr.V(vregs[i]) + 1) != fpr.V(vregs[i+1]))
- consecutive = false;
- if (consecutive) {
- VLDMIA(R0, false, fpr.V(vregs[0]), 4);
- } else {
- for (int i = 0; i < 4; i++)
- VLDR(fpr.V(vregs[i]), R0, i * 4);
- }
-
- if (doCheck) {
- SetJumpTarget(skip);
- SetCC(CC_AL);
- }
-#else
- bool consecutive = true;
- for (int i = 0; i < 3 && consecutive; i++)
- if ((fpr.V(vregs[i]) + 1) != fpr.V(vregs[i+1]))
- consecutive = false;
- if (consecutive) {
- VLDMIA(R0, false, fpr.V(vregs[0]), 4);
- } else {
- for (int i = 0; i < 4; i++)
- VLDR(fpr.V(vregs[i]), R0, i * 4);
- }
-
- if (doCheck) {
- SetCC(CC_EQ);
- MOVI2R(SCRATCHREG1, 0);
- for (int i = 0; i < 4; i++)
- VMOV(fpr.V(vregs[i]), SCRATCHREG1);
- SetCC(CC_AL);
- }
-#endif
- }
- break;
-
- case 62: //sv.q
- {
- // CC might be set by slow path below, so load regs first.
- u8 vregs[4];
- GetVectorRegs(vregs, V_Quad, vt);
- fpr.MapRegsAndSpillLockV(vregs, V_Quad, 0);
-
- if (gpr.IsImm(rs)) {
- u32 addr = (imm + gpr.GetImm(rs)) & 0x3FFFFFFF;
- gpr.SetRegImm(R0, addr + (u32)Memory::base);
- } else {
- gpr.MapReg(rs);
- if (g_Config.bFastMemory) {
- SetR0ToEffectiveAddress(rs, imm);
- } else {
- SetCCAndR0ForSafeAddress(rs, imm, SCRATCHREG2);
- doCheck = true;
- }
- ADD(R0, R0, MEMBASEREG);
- }
-
-#ifdef __ARM_ARCH_7S__
- FixupBranch skip;
- if (doCheck) {
- skip = B_CC(CC_EQ);
- }
-
- bool consecutive = true;
- for (int i = 0; i < 3 && consecutive; i++)
- if ((fpr.V(vregs[i]) + 1) != fpr.V(vregs[i+1]))
- consecutive = false;
- if (consecutive) {
- VSTMIA(R0, false, fpr.V(vregs[0]), 4);
- } else {
- for (int i = 0; i < 4; i++)
- VSTR(fpr.V(vregs[i]), R0, i * 4);
- }
-
- if (doCheck) {
- SetJumpTarget(skip);
- SetCC(CC_AL);
- }
-#else
- bool consecutive = true;
- for (int i = 0; i < 3 && consecutive; i++)
- if ((fpr.V(vregs[i]) + 1) != fpr.V(vregs[i+1]))
- consecutive = false;
- if (consecutive) {
- VSTMIA(R0, false, fpr.V(vregs[0]), 4);
- } else {
- for (int i = 0; i < 4; i++)
- VSTR(fpr.V(vregs[i]), R0, i * 4);
- }
-
- if (doCheck) {
- SetCC(CC_AL);
- }
-#endif
- }
- break;
-
- default:
- DISABLE;
- break;
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VVectorInit(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- // WARNING: No prefix support!
- if (js.HasUnknownPrefix() || js.HasSPrefix()) {
- DISABLE;
- }
-
- switch ((op >> 16) & 0xF)
- {
- case 6: // v=zeros; break; //vzero
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- break;
- case 7: // v=ones; break; //vone
- MOVI2F(S0, 1.0f, SCRATCHREG1);
- break;
- default:
- DISABLE;
- break;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 dregs[4];
- GetVectorRegsPrefixD(dregs, sz, _VD);
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
-
- for (int i = 0; i < n; ++i)
- VMOV(fpr.V(dregs[i]), S0);
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VIdt(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- if (js.HasUnknownPrefix() || js.HasSPrefix()) {
- DISABLE;
- }
-
- int vd = _VD;
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
- // Only pairs and quads are handled here.
- if (sz != V_Pair && sz != V_Quad) {
- DISABLE;
- }
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- u8 dregs[4];
- GetVectorRegsPrefixD(dregs, sz, _VD);
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
- switch (sz)
- {
- case V_Pair:
- VMOV(fpr.V(dregs[0]), (vd&1)==0 ? S1 : S0);
- VMOV(fpr.V(dregs[1]), (vd&1)==1 ? S1 : S0);
- break;
- case V_Quad:
- VMOV(fpr.V(dregs[0]), (vd&3)==0 ? S1 : S0);
- VMOV(fpr.V(dregs[1]), (vd&3)==1 ? S1 : S0);
- VMOV(fpr.V(dregs[2]), (vd&3)==2 ? S1 : S0);
- VMOV(fpr.V(dregs[3]), (vd&3)==3 ? S1 : S0);
- break;
- default:
- _dbg_assert_msg_(false,"Trying to interpret instruction that can't be interpreted");
- break;
- }
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VMatrixInit(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- // They do care about prefixes, so leave those to the interpreter like the IR does.
- if (!js.HasNoPrefix()) {
- DISABLE;
- }
-
- MatrixSize sz = GetMtxSize(op);
- int n = GetMatrixSide(sz);
-
- u8 dregs[16];
- GetMatrixRegs(dregs, sz, _VD);
-
- switch ((op >> 16) & 0xF) {
- case 3: // vmidt
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- fpr.MapRegV(dregs[a * 4 + b], MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(dregs[a * 4 + b]), a == b ? S1 : S0);
- }
- }
- break;
- case 6: // vmzero
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- fpr.MapRegV(dregs[a * 4 + b], MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(dregs[a * 4 + b]), S0);
- }
- }
- break;
- case 7: // vmone
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- fpr.MapRegV(dregs[a * 4 + b], MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(dregs[a * 4 + b]), S1);
- }
- }
- break;
- }
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VHdp(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || js.HasSPrefix() || !IsPrefixWithinSize(js.prefixT, op)) {
- DISABLE;
- }
-
- int vd = _VD;
- int vs = _VS;
- int vt = _VT;
- VectorSize sz = GetVecSize(op);
-
- // TODO: Force read one of them into regs? probably not.
- u8 sregs[4], tregs[4], dregs[1];
- GetVectorRegsPrefixS(sregs, sz, vs);
- GetVectorRegsPrefixT(tregs, sz, vt);
- GetVectorRegsPrefixD(dregs, V_Single, vd);
-
- // TODO: applyprefixST here somehow (shuffle, etc...)
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- fpr.MapRegsAndSpillLockV(tregs, sz, 0);
- VMUL(S0, fpr.V(sregs[0]), fpr.V(tregs[0]));
-
- int n = GetNumVectorElements(sz);
- for (int i = 1; i < n; i++) {
- // sum += s[i]*t[i];
- if (i == n - 1) {
- VADD(S0, S0, fpr.V(tregs[i]));
- } else {
- VMLA(S0, fpr.V(sregs[i]), fpr.V(tregs[i]));
- }
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
-
- fpr.MapRegV(dregs[0], MAP_NOINIT | MAP_DIRTY);
-
- VMOV(fpr.V(dregs[0]), S0);
- ApplyPrefixD(dregs, V_Single);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- alignas(16) static const float vavg_table[4] = { 1.0f, 1.0f / 2.0f, 1.0f / 3.0f, 1.0f / 4.0f };
-
- void ArmJit::Comp_Vhoriz(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || js.HasTPrefix()) {
- DISABLE;
- }
-
- int vd = _VD;
- int vs = _VS;
- int vt = _VT;
- VectorSize sz = GetVecSize(op);
-
- // TODO: Force read one of them into regs? probably not.
- u8 sregs[4], dregs[1];
- GetVectorRegsPrefixS(sregs, sz, vs);
- GetVectorRegsPrefixD(dregs, V_Single, vd);
-
- // TODO: applyprefixST here somehow (shuffle, etc...)
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
-
- int n = GetNumVectorElements(sz);
-
- bool is_vavg = ((op >> 16) & 0x1f) == 7;
- if (is_vavg) {
- MOVI2F(S1, vavg_table[n - 1], R0);
- }
- // Have to start at +0.000 for the correct sign.
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- for (int i = 0; i < n; i++) {
- // sum += s[i];
- VADD(S0, S0, fpr.V(sregs[i]));
- }
-
- fpr.MapRegV(dregs[0], MAP_NOINIT | MAP_DIRTY);
- if (is_vavg) {
- VMUL(fpr.V(dregs[0]), S0, S1);
- } else {
- VMOV(fpr.V(dregs[0]), S0);
- }
- ApplyPrefixD(dregs, V_Single);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VDot(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || !IsPrefixWithinSize(js.prefixT, op)) {
- DISABLE;
- }
-
- int vd = _VD;
- int vs = _VS;
- int vt = _VT;
- VectorSize sz = GetVecSize(op);
-
- // TODO: Force read one of them into regs? probably not.
- u8 sregs[4], tregs[4], dregs[1];
- GetVectorRegsPrefixS(sregs, sz, vs);
- GetVectorRegsPrefixT(tregs, sz, vt);
- GetVectorRegsPrefixD(dregs, V_Single, vd);
-
- // TODO: applyprefixST here somehow (shuffle, etc...)
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- fpr.MapRegsAndSpillLockV(tregs, sz, 0);
- VMUL(S0, fpr.V(sregs[0]), fpr.V(tregs[0]));
-
- int n = GetNumVectorElements(sz);
- for (int i = 1; i < n; i++) {
- // sum += s[i]*t[i];
- VMLA(S0, fpr.V(sregs[i]), fpr.V(tregs[i]));
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
-
- fpr.MapRegV(dregs[0], MAP_NOINIT | MAP_DIRTY);
-
- VMOV(fpr.V(dregs[0]), S0);
- ApplyPrefixD(dregs, V_Single);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VecDo3(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || !IsPrefixWithinSize(js.prefixT, op)) {
- DISABLE;
- }
- // vdiv applies the prefixes to its last lane only, from position 0.
- if (((op >> 23) & 7) == 7 && GetVecSize(op) != V_Single && !js.HasNoPrefix()) {
- DISABLE;
- }
-
- int vd = _VD;
- int vs = _VS;
- int vt = _VT;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], tregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixT(tregs, sz, _VT);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; i++) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs, n, tregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- // Map first, then work. This will allow us to use VLDMIA more often
- // (when we add the appropriate map function) and the instruction ordering
- // will improve.
- // Note that mapping like this (instead of first all sregs, first all tregs etc)
- // reduces the amount of continuous registers a lot :(
- for (int i = 0; i < n; i++) {
- fpr.MapDirtyInInV(tempregs[i], sregs[i], tregs[i]);
- fpr.SpillLockV(tempregs[i]);
- fpr.SpillLockV(sregs[i]);
- fpr.SpillLockV(tregs[i]);
- }
-
- for (int i = 0; i < n; i++) {
- switch (op >> 26) {
- case 24: //VFPU0
- switch ((op >> 23)&7) {
- case 0: // d[i] = s[i] + t[i]; break; //vadd
- VADD(fpr.V(tempregs[i]), fpr.V(sregs[i]), fpr.V(tregs[i]));
- break;
- case 1: // d[i] = s[i] - t[i]; break; //vsub
- VSUB(fpr.V(tempregs[i]), fpr.V(sregs[i]), fpr.V(tregs[i]));
- break;
- case 7: // d[i] = s[i] / t[i]; break; //vdiv
- VDIV(fpr.V(tempregs[i]), fpr.V(sregs[i]), fpr.V(tregs[i]));
- break;
- default:
- DISABLE;
- }
- break;
- case 25: //VFPU1
- switch ((op >> 23) & 7) {
- case 0: // d[i] = s[i] * t[i]; break; //vmul
- VMUL(fpr.V(tempregs[i]), fpr.V(sregs[i]), fpr.V(tregs[i]));
- break;
- default:
- DISABLE;
- }
- break;
- // Unfortunately there is no VMIN/VMAX on ARM without NEON.
- case 27: //VFPU3
- switch ((op >> 23) & 7) {
- case 2: // vmin
- case 3: // vmax
- {
- // Compare by vfpu_minmax_key, select the operand with its bits. A tie takes t.
- auto key = [&](ARMReg r, MIPSReg v) {
- VMOV(r, fpr.V(v));
- // Negative: x ^ 0x7FFFFFFF.
- CMP(r, AssumeMakeOperand2(0));
- SetCC(CC_MI);
- MVN(r, R(r));
- EOR(r, r, AssumeMakeOperand2(0x80000000));
- SetCC(CC_AL);
- // A zero exponent leaves the key within +-0x800000, which makes it zero.
- ADD(r, r, AssumeMakeOperand2(0x00800000));
- CMP(r, AssumeMakeOperand2(0x01000000));
- SUB(r, r, AssumeMakeOperand2(0x00800000));
- SetCC(CC_LO);
- MOV(r, AssumeMakeOperand2(0));
- SetCC(CC_AL);
- };
- key(SCRATCHREG1, sregs[i]);
- key(SCRATCHREG2, tregs[i]);
- CMP(SCRATCHREG1, R(SCRATCHREG2));
- SetCC(((op >> 23) & 7) == 2 ? CC_LT : CC_GT);
- VMOV(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- SetCC(((op >> 23) & 7) == 2 ? CC_GE : CC_LE);
- VMOV(fpr.V(tempregs[i]), fpr.V(tregs[i]));
- SetCC(CC_AL);
- break;
- }
- case 6: // vsge
- DISABLE; // pending testing
- VCMP(fpr.V(tregs[i]), fpr.V(sregs[i]));
- VMRS_APSR();
- // Unordered is always 0.
- SetCC(CC_GE);
- MOVI2F(fpr.V(tempregs[i]), 1.0f, SCRATCHREG1);
- SetCC(CC_LT);
- MOVI2F(fpr.V(tempregs[i]), 0.0f, SCRATCHREG1);
- SetCC(CC_AL);
- break;
- case 7: // vslt
- DISABLE; // pending testing
- VCMP(fpr.V(tregs[i]), fpr.V(sregs[i]));
- VMRS_APSR();
- // Unordered is always 0.
- SetCC(CC_LO);
- MOVI2F(fpr.V(tempregs[i]), 1.0f, SCRATCHREG1);
- SetCC(CC_HS);
- MOVI2F(fpr.V(tempregs[i]), 0.0f, SCRATCHREG1);
- SetCC(CC_AL);
- break;
- }
- break;
-
- default:
- DISABLE;
- }
- }
-
- for (int i = 0; i < n; i++) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VV2Op(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix()) {
- DISABLE;
- }
-
- // The prefix rules here follow the IR frontend, which follows the interpreter and the
- // prefix tests in pspautotests. What's not handled goes to the interpreter.
- int optype = (op >> 16) & 0x1f;
- if (optype == 0) {
- if (!IsPrefixWithinSize(js.prefixS, op))
- DISABLE;
- } else if (optype == 1 || optype == 2) {
- // vabs and vneg are vmov with the abs/negate bit forced on, so a negate in the S prefix
- // doesn't negate twice. D prefix is fine for these, and used sometimes.
- if (js.HasSPrefix())
- DISABLE;
- } else if (optype == 5 && js.HasDPrefix()) {
- // vsat1 doesn't apply the D saturation.
- DISABLE;
- }
- if (optype >= 16 && !js.HasNoPrefix()) {
- // These apply the S and D prefixes to their last lane only, from prefix position 0.
- // That's the whole vector for a single, so only that case is handled here.
- if (GetVecSize(op) != V_Single)
- DISABLE;
- if (!IsPrefixWithinSize(js.prefixS, op))
- DISABLE;
- // The negative ones seem to use negate flags as a prefix hack.
- if (optype >= 24 && (js.prefixS & 0x000F0000) != 0)
- DISABLE;
- }
-
- // Pre-processing: Eliminate silly no-op VMOVs, common in Wipeout Pure
- if (((op >> 16) & 0x1f) == 0 && _VS == _VD && js.HasNoPrefix()) {
- return;
- }
-
- // Catch the disabled operations immediately so we don't map registers unnecessarily later.
- // Move these down to the big switch below as they are implemented.
- switch ((op >> 16) & 0x1f) {
- case 18: // d[i] = sinf((float)M_PI_2 * s[i]); break; //vsin
- DISABLE;
- break;
- case 19: // d[i] = cosf((float)M_PI_2 * s[i]); break; //vcos
- DISABLE;
- break;
- case 20: // d[i] = powf(2.0f, s[i]); break; //vexp2
- DISABLE;
- break;
- case 23: // vasin, which has to be bit exact (cpu/vfpu/exact)
- DISABLE;
- break;
- case 21: // d[i] = logf(s[i])/log(2.0f); break; //vlog2
- DISABLE;
- break;
- case 16: // vrcp
- case 17: // vrsq
- case 22: // vsqrt
- case 24: // vnrcp
- CompVV2OpCall(op);
- return;
- case 26: // d[i] = -sinf((float)M_PI_2 * s[i]); break; // vnsin
- DISABLE;
- break;
- case 28: // d[i] = 1.0f / expf(s[i] * (float)M_LOG2E); break; // vrexp2
- DISABLE;
- break;
- default:
- ;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- // Pre map the registers to get better instruction ordering.
- // Note that mapping like this (instead of first all sregs, first all tempregs etc)
- // reduces the amount of continuous registers a lot :(
- for (int i = 0; i < n; i++) {
- fpr.MapDirtyInV(tempregs[i], sregs[i]);
- fpr.SpillLockV(tempregs[i]);
- fpr.SpillLockV(sregs[i]);
- }
-
- // Warning: sregs[i] and tempxregs[i] may be the same reg.
- // Helps for vmov, hurts for vrcp, etc.
- for (int i = 0; i < n; i++) {
- switch ((op >> 16) & 0x1f) {
- case 0: // d[i] = s[i]; break; //vmov
- // Probably for swizzle.
- VMOV(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- break;
- case 1: // d[i] = fabsf(s[i]); break; //vabs
- VABS(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- break;
- case 2: // d[i] = -s[i]; break; //vneg
- VNEG(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- break;
- case 4: // if (s[i] < 0) d[i] = 0; else {if(s[i] > 1.0f) d[i] = 1.0f; else d[i] = s[i];} break; // vsat0
- if (i == 0) {
- MOVI2F(S0, 0.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- }
- VCMP(fpr.V(sregs[i]), S0);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- VMOV(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- SetCC(CC_LS);
- VMOV(fpr.V(tempregs[i]), S0);
- SetCC(CC_AL);
- VCMP(fpr.V(sregs[i]), S1);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_GT);
- VMOV(fpr.V(tempregs[i]), S1);
- SetCC(CC_AL);
- break;
- case 5: // if (s[i] < -1.0f) d[i] = -1.0f; else {if(s[i] > 1.0f) d[i] = 1.0f; else d[i] = s[i];} break; // vsat1
- if (i == 0) {
- MOVI2F(S0, -1.0f, SCRATCHREG1);
- MOVI2F(S1, 1.0f, SCRATCHREG1);
- }
- VCMP(fpr.V(sregs[i]), S0);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- VMOV(fpr.V(tempregs[i]), fpr.V(sregs[i]));
- SetCC(CC_LO);
- VMOV(fpr.V(tempregs[i]), S0);
- SetCC(CC_AL);
- VCMP(fpr.V(sregs[i]), S1);
- VMRS_APSR(); // Move FP flags from FPSCR to APSR (regular flags).
- SetCC(CC_GT);
- VMOV(fpr.V(tempregs[i]), S1);
- SetCC(CC_AL);
- break;
- default:
- ERROR_LOG(Log::JIT, "case missing in vfpu vv2op");
- DISABLE;
- break;
- }
- }
-
- for (int i = 0; i < n; ++i) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vi2f(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op)) {
- DISABLE;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- int imm = (op >> 16) & 0x1f;
- const float mult = 1.0f / (float)(1UL << imm);
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- if (mult != 1.0f)
- MOVI2F(S0, mult, SCRATCHREG1);
-
- for (int i = 0; i < n; i++) {
- fpr.MapDirtyInV(tempregs[i], sregs[i]);
- VCVT(fpr.V(tempregs[i]), fpr.V(sregs[i]), TO_FLOAT | IS_SIGNED);
- if (mult != 1.0f)
- VMUL(fpr.V(tempregs[i]), fpr.V(tempregs[i]), S0);
- }
-
- for (int i = 0; i < n; ++i) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vh2f(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || js.HasSPrefix()) {
- DISABLE;
- }
-
- // This multi-VCVT.F32.F16 is only available in the VFPv4 extension.
- // The VFPv3 one is VCVTB, VCVTT which we don't yet have support for.
- // It also quiets a NaN, where the VFPU keeps its bits (cpu/vfpu/convert), so it's off for now.
- if (true || !(cpu_info.bHalf && cpu_info.bVFPv4)) {
- // No hardware support for half-to-float, fallback to interpreter
- // TODO: Translate the fast SSE solution to standard integer/VFP stuff
- // for the weaker CPUs.
- DISABLE;
- }
-
- u8 sregs[4], dregs[4];
- VectorSize sz = GetVecSize(op);
- VectorSize outSz;
-
- switch (sz) {
- case V_Single:
- outSz = V_Pair;
- break;
- case V_Pair:
- outSz = V_Quad;
- break;
- default:
- DISABLE;
- }
-
- int n = GetNumVectorElements(sz);
- int nOut = n * 2;
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, outSz, _VD);
-
- static const ARMReg tmp[4] = { S0, S1, S2, S3 };
-
- for (int i = 0; i < n; i++) {
- fpr.MapRegV(sregs[i], sz);
- VMOV(tmp[i], fpr.V(sregs[i]));
- }
-
- // This always converts four 16-bit floats in D0 to four 32-bit floats
- // in Q0. If we are dealing with a pair here, we just ignore the upper two outputs.
- // There are also a couple of other instructions that do it one at a time but doesn't
- // seem worth the trouble.
- VCVTF32F16(Q0, D0);
-
- for (int i = 0; i < nOut; i++) {
- fpr.MapRegV(dregs[i], MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(dregs[i]), tmp[i]);
- }
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vf2i(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
-
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || (js.prefixD & 0xFF) != 0) {
- DISABLE;
- }
- DISABLE;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- int imm = (op >> 16) & 0x1f;
- float mult = (float)(1ULL << imm);
-
- switch ((op >> 21) & 0x1f)
- {
- case 17:
- break; //z - truncate. Easy to support.
- case 16:
- case 18:
- case 19:
- DISABLE;
- break;
- }
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- if (mult != 1.0f)
- MOVI2F(S1, mult, SCRATCHREG1);
-
- for (int i = 0; i < n; i++) {
- fpr.MapDirtyInV(tempregs[i], sregs[i]);
- switch ((op >> 21) & 0x1f) {
- case 16: /* TODO */ break; //n
- case 17:
- if (mult != 1.0f) {
- VMUL(S0, fpr.V(sregs[i]), S1);
- VCVT(fpr.V(tempregs[i]), S0, TO_INT | ROUND_TO_ZERO);
- } else {
- VCVT(fpr.V(tempregs[i]), fpr.V(sregs[i]), TO_INT | ROUND_TO_ZERO);
- }
- break;
- case 18: /* TODO */ break; //u
- case 19: /* TODO */ break; //d
- }
- }
-
- for (int i = 0; i < n; ++i) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Mftv(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
-
- int imm = op & 0xFF;
- MIPSGPReg rt = _RT;
- switch ((op >> 21) & 0x1f) {
- case 3: //mfv / mfvc
- // rt = 0, imm = 255 appears to be used as a CPU interlock by some games.
- if (rt != 0) {
- if (imm < 128) { //R(rt) = VI(imm);
- fpr.MapRegV(imm, 0);
- gpr.MapReg(rt, MAP_NOINIT | MAP_DIRTY);
- VMOV(gpr.R(rt), fpr.V(imm));
- } else if (imm < 128 + VFPU_CTRL_MAX) { //mtvc
- if (imm - 128 == VFPU_CTRL_CC) {
- if (gpr.IsImm(MIPS_REG_VFPUCC)) {
- gpr.SetImm(rt, gpr.GetImm(MIPS_REG_VFPUCC));
- } else {
- gpr.MapDirtyIn(rt, MIPS_REG_VFPUCC);
- MOV(gpr.R(rt), gpr.R(MIPS_REG_VFPUCC));
- }
- } else {
- // In case we have a saved prefix.
- FlushPrefixV();
- gpr.MapReg(rt, MAP_NOINIT | MAP_DIRTY);
- LDR(gpr.R(rt), CTXREG, offsetof(MIPSState, vfpuCtrl) + 4 * (imm - 128));
- }
- } else {
- //ERROR - maybe need to make this value too an "interlock" value?
- ERROR_LOG(Log::CPU, "mfv - invalid register %i", imm);
- }
- }
- break;
-
- case 7: // mtv
- if (imm < 128) {
- gpr.MapReg(rt);
- fpr.MapRegV(imm, MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(imm), gpr.R(rt));
- } else if (imm < 128 + VFPU_CTRL_MAX) { //mtvc //currentMIPS->vfpuCtrl[imm - 128] = R(rt);
- if (imm - 128 == VFPU_CTRL_CC) {
- // Six condition bits, the rest don't stick (cpu/vfpu/vbranch).
- if (gpr.IsImm(rt)) {
- gpr.SetImm(MIPS_REG_VFPUCC, gpr.GetImm(rt) & 0x3F);
- } else {
- gpr.MapDirtyIn(MIPS_REG_VFPUCC, rt);
- AND(gpr.R(MIPS_REG_VFPUCC), gpr.R(rt), Operand2(0x3F));
- }
- } else {
- // Only some of the bits stick (the low 20 of a prefix, say), same as the IR does it.
- u32 mask;
- u32 setBits = GetVFPUCtrlSetBits(imm - 128);
- if (!GetVFPUCtrlMask(imm - 128, &mask)) {
- // Read-only or unknown register: nothing is written.
- } else if (mask != 0xFFFFFFFF || setBits != 0) {
- gpr.MapReg(rt);
- ANDI2R(SCRATCHREG1, gpr.R(rt), mask, SCRATCHREG2);
- if (setBits != 0)
- ORI2R(SCRATCHREG1, SCRATCHREG1, setBits, SCRATCHREG2);
- STR(SCRATCHREG1, CTXREG, offsetof(MIPSState, vfpuCtrl) + 4 * (imm - 128));
- } else {
- gpr.MapReg(rt);
- STR(gpr.R(rt), CTXREG, offsetof(MIPSState, vfpuCtrl) + 4 * (imm - 128));
- }
- }
-
- // TODO: Optimization if rt is Imm?
- // Set these BEFORE disable!
- if (imm - 128 == VFPU_CTRL_SPREFIX) {
- js.prefixSFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- } else if (imm - 128 == VFPU_CTRL_TPREFIX) {
- js.prefixTFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- } else if (imm - 128 == VFPU_CTRL_DPREFIX) {
- js.prefixDFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- }
- } else {
- // Past the control registers, nothing is written, as in the interpreter.
- }
- break;
-
- default:
- DISABLE;
- }
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vmfvc(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
-
- int vd = _VD;
- int imm = (op >> 8) & 0x7F;
- if (imm < VFPU_CTRL_MAX) {
- fpr.MapRegV(vd, MAP_DIRTY | MAP_NOINIT);
- if (imm == VFPU_CTRL_CC) {
- gpr.MapReg(MIPS_REG_VFPUCC, 0);
- VMOV(fpr.V(vd), gpr.R(MIPS_REG_VFPUCC));
- } else {
- // In case we have a saved prefix.
- FlushPrefixV();
- ADDI2R(SCRATCHREG1, CTXREG, offsetof(MIPSState, vfpuCtrl[0]) + imm * 4, SCRATCHREG2);
- VLDR(fpr.V(vd), SCRATCHREG1, 0);
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
- } else {
- fpr.MapRegV(vd, MAP_DIRTY | MAP_NOINIT);
- MOVI2F(fpr.V(vd), 0.0f, SCRATCHREG1);
- }
- }
-
- void ArmJit::Comp_Vmtvc(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
-
- int vs = _VS;
- int imm = op & 0x7F;
- if (imm < VFPU_CTRL_MAX) {
- fpr.MapRegV(vs);
- if (imm == VFPU_CTRL_CC) {
- gpr.MapReg(MIPS_REG_VFPUCC, MAP_DIRTY | MAP_NOINIT);
- VMOV(gpr.R(MIPS_REG_VFPUCC), fpr.V(vs));
- } else {
- ADDI2R(SCRATCHREG1, CTXREG, offsetof(MIPSState, vfpuCtrl[0]) + imm * 4, SCRATCHREG2);
- VSTR(fpr.V(vs), SCRATCHREG1, 0);
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
-
- if (imm == VFPU_CTRL_SPREFIX) {
- js.prefixSFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- } else if (imm == VFPU_CTRL_TPREFIX) {
- js.prefixTFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- } else if (imm == VFPU_CTRL_DPREFIX) {
- js.prefixDFlag = JitState::PREFIX_UNKNOWN;
- js.blockWrotePrefixes = true;
- }
- }
- }
-
- void ArmJit::Comp_Vmmov(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_MTX_VMMOV);
- if (!js.HasNoPrefix()) {
- DISABLE;
- }
-
- // This probably ignores prefixes for all sane intents and purposes.
- if (_VS == _VD) {
- // A lot of these no-op matrix moves in Wipeout... Just drop the instruction entirely.
- return;
- }
-
- MatrixSize sz = GetMtxSize(op);
- int n = GetMatrixSide(sz);
-
- u8 sregs[16], dregs[16];
- GetMatrixRegs(sregs, sz, _VS);
- GetMatrixRegs(dregs, sz, _VD);
-
- // Rough overlap check.
- bool overlap = false;
- if (GetMtx(_VS) == GetMtx(_VD)) {
- // Potential overlap (guaranteed for 3x3 or more).
- overlap = true;
- }
-
- if (overlap) {
- // Not so common, fallback.
- DISABLE;
- } else {
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- fpr.MapDirtyInV(dregs[a * 4 + b], sregs[a * 4 + b]);
- VMOV(fpr.V(dregs[a * 4 + b]), fpr.V(sregs[a * 4 + b]));
- }
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
- }
-
- void ArmJit::Comp_VScl(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- // The T prefix is applied oddly here, the interpreter knows how.
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || js.HasTPrefix()) {
- DISABLE;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], dregs[4], treg;
- GetVectorRegsPrefixS(sregs, sz, _VS);
- // TODO: Prefixes seem strange...
- GetVectorRegsPrefixT(&treg, V_Single, _VT);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- // Move to S0 early, so we don't have to worry about overlap with scale.
- fpr.LoadToRegV(S0, treg);
-
- // For prefixes to work, we just have to ensure that none of the output registers spill
- // and that there's no overlap.
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- // Need to use temp regs
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- // The meat of the function!
- for (int i = 0; i < n; i++) {
- fpr.MapDirtyInV(tempregs[i], sregs[i]);
- VMUL(fpr.V(tempregs[i]), fpr.V(sregs[i]), S0);
- }
-
- for (int i = 0; i < n; i++) {
- // All must be mapped for prefixes to work.
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vmmul(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_MTX_VMMUL);
- if (!js.HasNoPrefix()) {
- DISABLE;
- }
-
- if (PSP_CoreParameter().compat.flags().MoreAccurateVMMUL) {
- // Fall back to interpreter, which has the accurate implementation.
- // Later we might do something more optimized here.
- DISABLE;
- }
-
- MatrixSize sz = GetMtxSize(op);
- int n = GetMatrixSide(sz);
-
- u8 sregs[16], tregs[16], dregs[16];
- GetMatrixRegs(sregs, sz, _VS);
- GetMatrixRegs(tregs, sz, _VT);
- GetMatrixRegs(dregs, sz, _VD);
-
- // Rough overlap check.
- bool overlap = false;
- if (GetMtx(_VS) == GetMtx(_VD) || GetMtx(_VT) == GetMtx(_VD)) {
- // Potential overlap (guaranteed for 3x3 or more).
- overlap = true;
- }
-
- if (overlap) {
- DISABLE;
- } else {
- for (int a = 0; a < n; a++) {
- for (int b = 0; b < n; b++) {
- fpr.MapInInV(sregs[b * 4], tregs[a * 4]);
- VMUL(S0, fpr.V(sregs[b * 4]), fpr.V(tregs[a * 4]));
- for (int c = 1; c < n; c++) {
- fpr.MapInInV(sregs[b * 4 + c], tregs[a * 4 + c]);
- VMLA(S0, fpr.V(sregs[b * 4 + c]), fpr.V(tregs[a * 4 + c]));
- }
- fpr.MapRegV(dregs[a * 4 + b], MAP_DIRTY | MAP_NOINIT);
- VMOV(fpr.V(dregs[a * 4 + b]), S0);
- }
- }
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
- }
-
- void ArmJit::Comp_Vmscl(MIPSOpcode op) {
- DISABLE;
- }
-
- void ArmJit::Comp_Vtfm(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_MTX_VTFM);
- if (!js.HasNoPrefix()) {
- DISABLE;
- }
-
- // TODO: This probably ignores prefixes? Or maybe uses D?
-
- VectorSize sz = GetVecSize(op);
- MatrixSize msz = GetMtxSize(op);
- int n = GetNumVectorElements(sz);
- int ins = (op >> 23) & 7;
-
- bool homogenous = false;
- if (n == ins) {
- n++;
- sz = (VectorSize)((int)(sz) + 1);
- msz = (MatrixSize)((int)(msz) + 1);
- homogenous = true;
- }
- // Otherwise, n should already be ins + 1.
- else if (n != ins + 1) {
- DISABLE;
- }
-
- u8 sregs[16], dregs[4], tregs[4];
- GetMatrixRegs(sregs, msz, _VS);
- GetVectorRegs(tregs, sz, _VT);
- GetVectorRegs(dregs, sz, _VD);
-
- // TODO: test overlap, optimize.
- int tempregs[4];
- for (int i = 0; i < n; i++) {
- fpr.MapInInV(sregs[i * 4], tregs[0]);
- VMUL(S0, fpr.V(sregs[i * 4]), fpr.V(tregs[0]));
- for (int k = 1; k < n; k++) {
- if (!homogenous || k != n - 1) {
- fpr.MapInInV(sregs[i * 4 + k], tregs[k]);
- VMLA(S0, fpr.V(sregs[i * 4 + k]), fpr.V(tregs[k]));
- } else {
- fpr.MapRegV(sregs[i * 4 + k]);
- VADD(S0, S0, fpr.V(sregs[i * 4 + k]));
- }
- }
-
- int temp = fpr.GetTempV();
- fpr.MapRegV(temp, MAP_NOINIT | MAP_DIRTY);
- fpr.SpillLockV(temp);
- VMOV(fpr.V(temp), S0);
- tempregs[i] = temp;
- }
- for (int i = 0; i < n; i++) {
- u8 temp = tempregs[i];
- fpr.MapRegV(dregs[i], MAP_NOINIT | MAP_DIRTY);
- VMOV(fpr.V(dregs[i]), fpr.V(temp));
- }
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VCrs(MIPSOpcode op) {
- DISABLE;
- }
-
- void ArmJit::Comp_VDet(MIPSOpcode op) {
- DISABLE;
- }
-
- void ArmJit::Comp_Vi2x(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || js.HasSPrefix()) {
- DISABLE;
- }
-
- int bits = ((op >> 16) & 2) == 0 ? 8 : 16; // vi2uc/vi2c (0/1), vi2us/vi2s (2/3)
- bool unsignedOp = ((op >> 16) & 1) == 0; // vi2uc (0), vi2us (2)
-
- if (unsignedOp) {
- // Requires a tricky clamp operation that we can't do without more temps, see below
- DISABLE;
- }
-
- // These instructions pack pairs or quads of integers into 32 bits.
- // The unsigned (u) versions skip the sign bit when packing.
- VectorSize sz = GetVecSize(op);
- VectorSize outsize;
- if (bits == 8) {
- outsize = V_Single;
- if (sz != V_Quad) {
- DISABLE;
- }
- } else {
- switch (sz) {
- case V_Pair:
- outsize = V_Single;
- break;
- case V_Quad:
- outsize = V_Pair;
- break;
- default:
- DISABLE;
- }
- }
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, outsize, _VD);
-
- // First, let's assemble the sregs into lanes of either D0 (pair) or Q0 (quad).
- bool quad = sz == V_Quad;
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- VMOV(S0, fpr.V(sregs[0]));
- VMOV(S1, fpr.V(sregs[1]));
- if (quad) {
- VMOV(S2, fpr.V(sregs[2]));
- VMOV(S3, fpr.V(sregs[3]));
- }
-
- // TODO: For "u" type ops, we clamp to zero and shift off the sign bit first.
- // Need some temp regs to do that efficiently, right?
-
- // At this point, we simply need to collect the high bits of each 32-bit lane into one register.
- if (bits == 8) {
- // Really want to do a VSHRN(..., 24) but that can't be encoded. So we synthesize it.
- VSHR(I_32, Q0, Q0, 16);
- VSHRN(I_32, D0, Q0, 8);
- VMOVN(I_16, D0, Q0);
- } else {
- VSHRN(I_32, D0, Q0, 16);
- }
-
- fpr.MapRegsAndSpillLockV(dregs, outsize, MAP_DIRTY|MAP_NOINIT);
- VMOV(fpr.V(dregs[0]), S0);
- if (outsize == V_Pair) {
- VMOV(fpr.V(dregs[1]), S1);
- }
-
- ApplyPrefixD(dregs, outsize);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vx2i(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || js.HasSPrefix()) {
- DISABLE;
- }
-
- int bits = ((op >> 16) & 2) == 0 ? 8 : 16; // vuc2i/vc2i (0/1), vus2i/vs2i (2/3)
- bool unsignedOp = ((op >> 16) & 1) == 0; // vuc2i (0), vus2i (2)
-
- if (bits == 8 && unsignedOp) {
- // vuc2i is odd and needs temp registers for implementation.
- DISABLE;
- }
- // vs2i or vus2i unpack pairs of 16-bit integers into 32-bit integers, with the values
- // at the top. vus2i shifts it an extra bit right afterward.
- // vc2i and vuc2i unpack quads of 8-bit integers into 32-bit integers, with the values
- // at the top too. vuc2i is a bit special (see below.)
- // Let's do this similarly as h2f - we do a solution that works for both singles and pairs
- // then use it for both.
-
- VectorSize sz = GetVecSize(op);
- VectorSize outsize;
- if (bits == 8) {
- outsize = V_Quad;
- } else {
- switch (sz) {
- case V_Single:
- outsize = V_Pair;
- break;
- case V_Pair:
- outsize = V_Quad;
- break;
- default:
- DISABLE;
- }
- }
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, outsize, _VD);
-
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- if (sz == V_Single) {
- VMOV(S0, fpr.V(sregs[0]));
- } else if (sz == V_Pair) {
- VMOV(S0, fpr.V(sregs[0]));
- VMOV(S1, fpr.V(sregs[1]));
- } else if (bits == 8) {
- // For some reason, sz is quad on vc2i.
- VMOV(S0, fpr.V(sregs[0]));
- }
-
-
- if (bits == 16) {
- // Simply expand, to upper bits.
- VSHLL(I_16, Q0, D0, 16);
- } else if (bits == 8) {
- if (unsignedOp) {
- // vuc2i is a bit special. It spreads out the bits like this:
- // s[0] = 0xDDCCBBAA -> d[0] = (0xAAAAAAAA >> 1), d[1] = (0xBBBBBBBB >> 1), etc.
- // TODO
- } else {
- VSHLL(I_8, Q0, D0, 8);
- VSHLL(I_16, Q0, D0, 16);
- }
- }
-
- // At this point we have the regs in the 4 lanes.
- // In the "u" mode, we need to shift it out of the sign bit.
- if (unsignedOp) {
- ArmGen::ARMReg reg = (outsize == V_Quad) ? Q0 : D0;
- VSHR(I_32 | I_UNSIGNED, reg, reg, 1);
- }
-
- fpr.MapRegsAndSpillLockV(dregs, outsize, MAP_NOINIT);
-
- VMOV(fpr.V(dregs[0]), S0);
- VMOV(fpr.V(dregs[1]), S1);
- if (outsize == V_Quad) {
- VMOV(fpr.V(dregs[2]), S2);
- VMOV(fpr.V(dregs[3]), S3);
- }
-
- ApplyPrefixD(dregs, outsize);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_VCrossQuat(MIPSOpcode op) {
- // This op does not support prefixes anyway.
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (!js.HasNoPrefix())
- DISABLE;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], tregs[4], dregs[4];
- GetVectorRegs(sregs, sz, _VS);
- GetVectorRegs(tregs, sz, _VT);
- GetVectorRegs(dregs, sz, _VD);
-
- // Map everything into registers.
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- fpr.MapRegsAndSpillLockV(tregs, sz, 0);
-
- if (sz == V_Triple) {
- MIPSReg temp3 = fpr.GetTempV();
- fpr.MapRegV(temp3, MAP_DIRTY | MAP_NOINIT);
- // Cross product vcrsp.t
-
- // Compute X
- VMUL(S0, fpr.V(sregs[1]), fpr.V(tregs[2]));
- VMLS(S0, fpr.V(sregs[2]), fpr.V(tregs[1]));
-
- // Compute Y
- VMUL(S1, fpr.V(sregs[2]), fpr.V(tregs[0]));
- VMLS(S1, fpr.V(sregs[0]), fpr.V(tregs[2]));
-
- // Compute Z
- VMUL(fpr.V(temp3), fpr.V(sregs[0]), fpr.V(tregs[1]));
- VMLS(fpr.V(temp3), fpr.V(sregs[1]), fpr.V(tregs[0]));
-
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_NOINIT);
- VMOV(fpr.V(dregs[0]), S0);
- VMOV(fpr.V(dregs[1]), S1);
- VMOV(fpr.V(dregs[2]), fpr.V(temp3));
- } else if (sz == V_Quad) {
- MIPSReg temp3 = fpr.GetTempV();
- MIPSReg temp4 = fpr.GetTempV();
- fpr.MapRegV(temp3, MAP_DIRTY | MAP_NOINIT);
- fpr.MapRegV(temp4, MAP_DIRTY | MAP_NOINIT);
-
- // Quaternion product vqmul.q untested
- // d[0] = s[0] * t[3] + s[1] * t[2] - s[2] * t[1] + s[3] * t[0];
- VMUL(S0, fpr.V(sregs[0]), fpr.V(tregs[3]));
- VMLA(S0, fpr.V(sregs[1]), fpr.V(tregs[2]));
- VMLS(S0, fpr.V(sregs[2]), fpr.V(tregs[1]));
- VMLA(S0, fpr.V(sregs[3]), fpr.V(tregs[0]));
-
- //d[1] = -s[0] * t[2] + s[1] * t[3] + s[2] * t[0] + s[3] * t[1];
- VNMUL(S1, fpr.V(sregs[0]), fpr.V(tregs[2]));
- VMLA(S1, fpr.V(sregs[1]), fpr.V(tregs[3]));
- VMLA(S1, fpr.V(sregs[2]), fpr.V(tregs[0]));
- VMLA(S1, fpr.V(sregs[3]), fpr.V(tregs[1]));
-
- //d[2] = s[0] * t[1] - s[1] * t[0] + s[2] * t[3] + s[3] * t[2];
- VMUL(fpr.V(temp3), fpr.V(sregs[0]), fpr.V(tregs[1]));
- VMLS(fpr.V(temp3), fpr.V(sregs[1]), fpr.V(tregs[0]));
- VMLA(fpr.V(temp3), fpr.V(sregs[2]), fpr.V(tregs[3]));
- VMLA(fpr.V(temp3), fpr.V(sregs[3]), fpr.V(tregs[2]));
-
- //d[3] = -s[0] * t[0] - s[1] * t[1] - s[2] * t[2] + s[3] * t[3];
- VNMUL(fpr.V(temp4), fpr.V(sregs[0]), fpr.V(tregs[0]));
- VMLS(fpr.V(temp4), fpr.V(sregs[1]), fpr.V(tregs[1]));
- VMLS(fpr.V(temp4), fpr.V(sregs[2]), fpr.V(tregs[2]));
- VMLA(fpr.V(temp4), fpr.V(sregs[3]), fpr.V(tregs[3]));
-
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_NOINIT);
- VMOV(fpr.V(dregs[0]), S0);
- VMOV(fpr.V(dregs[1]), S1);
- VMOV(fpr.V(dregs[2]), fpr.V(temp3));
- VMOV(fpr.V(dregs[3]), fpr.V(temp4));
- }
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vcmp(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_COMP);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || !IsPrefixWithinSize(js.prefixT, op))
- DISABLE;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- VCondition cond = (VCondition)(op & 0xF);
-
- u8 sregs[4], tregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixT(tregs, sz, _VT);
-
- // Some, we just fall back to the interpreter.
- // ES is just really equivalent to (value & 0x7F800000) == 0x7F800000.
-
- switch (cond) {
- case VC_EI: // c = my_isinf(s[i]); break;
- case VC_NI: // c = !my_isinf(s[i]); break;
- DISABLE;
- case VC_ES: // c = my_isnan(s[i]) || my_isinf(s[i]); break; // Tekken Dark Resurrection
- case VC_NS: // c = !my_isnan(s[i]) && !my_isinf(s[i]); break;
- case VC_EN: // c = my_isnan(s[i]); break;
- case VC_NN: // c = !my_isnan(s[i]); break;
- if (_VS != _VT)
- DISABLE;
- break;
-
- case VC_EZ:
- case VC_NZ:
- break;
- default:
- ;
- }
-
- // First, let's get the trivial ones.
- int affected_bits = (1 << 4) | (1 << 5); // 4 and 5
-
- MOVI2R(SCRATCHREG1, 0);
- for (int i = 0; i < n; ++i) {
- // Let's only handle the easy ones, and fall back on the interpreter for the rest.
- CCFlags flag = CC_AL;
- switch (cond) {
- case VC_FL: // c = 0;
- break;
-
- case VC_TR: // c = 1
- if (i == 0) {
- if (n == 1) {
- MOVI2R(SCRATCHREG1, 0x31);
- } else {
- MOVI2R(SCRATCHREG1, 1 << i);
- }
- } else {
- ORR(SCRATCHREG1, SCRATCHREG1, 1 << i);
- }
- break;
-
- case VC_ES: // c = my_isnan(s[i]) || my_isinf(s[i]); break; // Tekken Dark Resurrection
- case VC_NS: // c = !(my_isnan(s[i]) || my_isinf(s[i])); break;
- // For these, we use the integer ALU as there is no support on ARM for testing for INF.
- // Testing for nan or inf is the same as testing for &= 0x7F800000 == 0x7F800000.
- // We need an extra temporary register so we store away SCRATCHREG1.
- STR(SCRATCHREG1, CTXREG, offsetof(MIPSState, temp));
- fpr.MapRegV(sregs[i], 0);
- MOVI2R(SCRATCHREG1, 0x7F800000);
- VMOV(SCRATCHREG2, fpr.V(sregs[i]));
- AND(SCRATCHREG2, SCRATCHREG2, SCRATCHREG1);
- CMP(SCRATCHREG2, SCRATCHREG1); // (SCRATCHREG2 & 0x7F800000) == 0x7F800000
- flag = cond == VC_ES ? CC_EQ : CC_NEQ;
- LDR(SCRATCHREG1, CTXREG, offsetof(MIPSState, temp));
- break;
-
- case VC_EN: // c = my_isnan(s[i]); break; // Tekken 6
- // Should we involve T? Where I found this used, it compared a register with itself so should be fine.
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_VS; // overflow = unordered : http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Chdhcfbc.html
- break;
-
- case VC_NN: // c = !my_isnan(s[i]); break;
- // Should we involve T? Where I found this used, it compared a register with itself so should be fine.
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_VC; // !overflow = !unordered : http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Chdhcfbc.html
- break;
-
- case VC_EQ: // c = s[i] == t[i]
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_EQ;
- break;
-
- case VC_LT: // c = s[i] < t[i]
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_LO;
- break;
-
- case VC_LE: // c = s[i] <= t[i];
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_LS;
- break;
-
- case VC_NE: // c = s[i] != t[i]
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_NEQ;
- break;
-
- case VC_GE: // c = s[i] >= t[i]
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_GE;
- break;
-
- case VC_GT: // c = s[i] > t[i]
- fpr.MapInInV(sregs[i], tregs[i]);
- VCMP(fpr.V(sregs[i]), fpr.V(tregs[i]));
- VMRS_APSR();
- flag = CC_GT;
- break;
-
- case VC_EZ: // c = s[i] == 0.0f || s[i] == -0.0f
- fpr.MapRegV(sregs[i]);
- VCMP(fpr.V(sregs[i])); // vcmp(sregs[i], #0.0)
- VMRS_APSR();
- flag = CC_EQ;
- break;
-
- case VC_NZ: // c = s[i] != 0
- fpr.MapRegV(sregs[i]);
- VCMP(fpr.V(sregs[i])); // vcmp(sregs[i], #0.0)
- VMRS_APSR();
- flag = CC_NEQ;
- break;
-
- default:
- DISABLE;
- }
- if (flag != CC_AL) {
- SetCC(flag);
- if (i == 0) {
- if (n == 1) {
- MOVI2R(SCRATCHREG1, 0x31);
- } else {
- MOVI2R(SCRATCHREG1, 1); // 1 << i, but i == 0
- }
- } else {
- ORR(SCRATCHREG1, SCRATCHREG1, 1 << i);
- }
- SetCC(CC_AL);
- }
-
- affected_bits |= 1 << i;
- }
-
- // Aggregate the bits. Urgh, expensive. Can optimize for the case of one comparison, which is the most common
- // after all.
- if (n > 1) {
- CMP(SCRATCHREG1, affected_bits & 0xF);
- SetCC(CC_EQ);
- ORR(SCRATCHREG1, SCRATCHREG1, 1 << 5);
- SetCC(CC_AL);
-
- CMP(SCRATCHREG1, 0);
- SetCC(CC_NEQ);
- ORR(SCRATCHREG1, SCRATCHREG1, 1 << 4);
- SetCC(CC_AL);
- }
-
- gpr.MapReg(MIPS_REG_VFPUCC, MAP_DIRTY);
- BIC(gpr.R(MIPS_REG_VFPUCC), gpr.R(MIPS_REG_VFPUCC), affected_bits);
- ORR(gpr.R(MIPS_REG_VFPUCC), gpr.R(MIPS_REG_VFPUCC), SCRATCHREG1);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vcmov(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_COMP);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || js.HasTPrefix()) {
- DISABLE;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
- int tf = (op >> 19) & 1;
- int imm3 = (op >> 16) & 7;
-
- for (int i = 0; i < n; ++i) {
- // Simplification: Disable if overlap unsafe
- if (!IsOverlapSafeAllowS(dregs[i], i, n, sregs)) {
- DISABLE;
- }
- }
-
- // 7 tests a CC bit that is always clear (cpu/vfpu/undefined).
- if (imm3 != 6) {
- // Test one bit of CC. This bit decides whether none or all subregisters are copied.
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_DIRTY);
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- gpr.MapReg(MIPS_REG_VFPUCC);
- TST(gpr.R(MIPS_REG_VFPUCC), 1 << imm3);
- SetCC(tf ? CC_EQ : CC_NEQ);
- for (int i = 0; i < n; i++) {
- VMOV(fpr.V(dregs[i]), fpr.V(sregs[i]));
- }
- SetCC(CC_AL);
- } else {
- // Look at the bottom four bits of CC to individually decide if the subregisters should be copied.
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_DIRTY);
- fpr.MapRegsAndSpillLockV(sregs, sz, 0);
- gpr.MapReg(MIPS_REG_VFPUCC);
- for (int i = 0; i < n; i++) {
- TST(gpr.R(MIPS_REG_VFPUCC), 1 << i);
- SetCC(tf ? CC_EQ : CC_NEQ);
- VMOV(fpr.V(dregs[i]), fpr.V(sregs[i]));
- SetCC(CC_AL);
- }
- }
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Viim(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- if (js.HasUnknownPrefix()) {
- DISABLE;
- }
-
- u8 dreg;
- GetVectorRegs(&dreg, V_Single, _VT);
-
- s32 imm = SignExtend16ToS32(op);
- fpr.MapRegV(dreg, MAP_DIRTY | MAP_NOINIT);
- MOVI2F(fpr.V(dreg), (float)imm, SCRATCHREG1);
-
- ApplyPrefixD(&dreg, V_Single);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vfim(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- if (js.HasUnknownPrefix()) {
- DISABLE;
- }
-
- u8 dreg;
- GetVectorRegs(&dreg, V_Single, _VT);
-
- FP16 half;
- half.u = op & 0xFFFF;
- FP32 fval = half_to_float_fast5(half);
- fpr.MapRegV(dreg, MAP_DIRTY | MAP_NOINIT);
- MOVI2F(fpr.V(dreg), fval.f, SCRATCHREG1);
-
- ApplyPrefixD(&dreg, V_Single);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vcst(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_XFER);
- if (js.HasUnknownPrefix()) {
- DISABLE;
- }
-
- int conNum = (op >> 16) & 0x1f;
- int vd = _VD;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 dregs[4];
- GetVectorRegsPrefixD(dregs, sz, _VD);
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_NOINIT | MAP_DIRTY);
-
- gpr.SetRegImm(SCRATCHREG1, (u32)(void *)&cst_constants[conNum]);
- VLDR(S0, SCRATCHREG1, 0);
- for (int i = 0; i < n; ++i)
- VMOV(fpr.V(dregs[i]), S0);
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- // Float bits in and out, so the calls look the same with softfp and hardfp.
- static u32 CallWithBits(float (*func)(float), u32 x) {
- float f;
- memcpy(&f, &x, sizeof(f));
- f = func(f);
- memcpy(&x, &f, sizeof(x));
- return x;
- }
-
- static u32 VRcpBits(u32 x) {
- return CallWithBits(&vfpu_rcp, x);
- }
-
- static u32 VNRcpBits(u32 x) {
- return CallWithBits(&vfpu_rcp, x) ^ 0x80000000;
- }
-
- static u32 VRSqrtBits(u32 x) {
- return CallWithBits(&vfpu_rsqrt, x);
- }
-
- static u32 VSqrtBits(u32 x) {
- return CallWithBits(&vfpu_sqrt, x);
- }
-
- // vrcp, vrsq, vsqrt and vnrcp call the exact functions. The lanes stay in S16-S19 across the
- // calls (callee-saved), and the results are stored to the destinations' homes.
- void ArmJit::CompVV2OpCall(MIPSOpcode op) {
- // Like the interpreter, these apply the prefixes to the last lane only.
- if (js.HasSPrefix() || (js.HasDPrefix() && GetVecSize(op) != V_Single)) {
- DISABLE;
- }
-
- const int optype = (op >> 16) & 0x1f;
- u32 (*func)(u32) = &VRcpBits;
- if (optype == 17) {
- func = &VRSqrtBits;
- } else if (optype == 22) {
- func = &VSqrtBits;
- } else if (optype == 24) {
- func = &VNRcpBits;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
- u8 sregs[4], dregs[4];
- GetVectorRegs(sregs, sz, _VS);
- GetVectorRegs(dregs, sz, _VD);
-
- gpr.FlushBeforeCall();
- fpr.FlushAll();
-
- for (int i = 0; i < n; i++) {
- VLDR((ARMReg)(S16 + i), CTXREG, fpr.GetMipsRegOffsetV(sregs[i]));
- }
- for (int i = 0; i < n; i++) {
- VMOV(R0, (ARMReg)(S16 + i));
- // FlushBeforeCall saves R1.
- QuickCallFunction(R1, func);
- VMOV((ARMReg)(S16 + i), R0);
- }
- for (int i = 0; i < n; i++) {
- VSTR((ARMReg)(S16 + i), CTXREG, fpr.GetMipsRegOffsetV(dregs[i]));
- }
-
- ApplyPrefixD(dregs, sz);
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- static double SinCos(float angle) {
- union { struct { float sin; float cos; }; double out; } sincos;
- vfpu_sincos(angle, sincos.sin, sincos.cos);
- return sincos.out;
- }
-
- static double SinCosNegSin(float angle) {
- union { struct { float sin; float cos; }; double out; } sincos;
- vfpu_sincos(angle, sincos.sin, sincos.cos);
- sincos.sin = -sincos.sin;
- return sincos.out;
- }
-
- void ArmJit::CompVrotShuffle(u8 *dregs, int imm, VectorSize sz, bool negSin) {
- int n = GetNumVectorElements(sz);
- char what[4] = {'0', '0', '0', '0'};
- if (((imm >> 2) & 3) == (imm & 3)) {
- for (int i = 0; i < 4; i++)
- what[i] = 'S';
- }
- what[(imm >> 2) & 3] = 'S';
- what[imm & 3] = 'C';
-
- fpr.MapRegsAndSpillLockV(dregs, sz, MAP_DIRTY | MAP_NOINIT);
- for (int i = 0; i < n; i++) {
- switch (what[i]) {
- case 'C': VMOV(fpr.V(dregs[i]), S1); break;
- case 'S': if (negSin) VNEG(fpr.V(dregs[i]), S0); else VMOV(fpr.V(dregs[i]), S0); break;
- case '0':
- {
- MOVI2F(fpr.V(dregs[i]), 0.0f, SCRATCHREG1);
- break;
- }
- default:
- ERROR_LOG(Log::JIT, "Bad what in vrot");
- break;
- }
- }
- }
-
- // Very heavily used by FF:CC. Should be replaced by a fast approximation instead of
- // calling the math library.
- void ArmJit::Comp_VRot(MIPSOpcode op) {
- // VRot probably doesn't accept prefixes anyway.
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (!js.HasNoPrefix()) {
- DISABLE;
- }
-
- int vd = _VD;
- int vs = _VS;
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 dregs[4];
- u8 dregs2[4];
-
- MIPSOpcode nextOp = GetOffsetInstruction(1);
- int vd2 = -1;
- int imm2 = -1;
- if ((nextOp >> 26) == 60 && ((nextOp >> 21) & 0x1F) == 29 && _VS == MIPS_GET_VS(nextOp)) {
- // Pair of vrot. Let's join them.
- vd2 = MIPS_GET_VD(nextOp);
- imm2 = (nextOp >> 16) & 0x1f;
- // NOTICE_LOG(Log::JIT, "Joint VFPU at %08x", js.blockStart);
- }
- u8 sreg;
- GetVectorRegs(dregs, sz, vd);
- if (vd2 >= 0)
- GetVectorRegs(dregs2, sz, vd2);
- GetVectorRegs(&sreg, V_Single, vs);
- // With the angle in a destination lane, the cosine is taken of what was written there.
- // The assembler refuses that, so leave it to the interpreter, and don't pair such a vrot.
- for (int i = 0; i < n; i++) {
- if (dregs[i] == sreg) {
- DISABLE;
- }
- if (vd2 >= 0 && dregs2[i] == sreg) {
- vd2 = -1;
- }
- }
-
- int imm = (op >> 16) & 0x1f;
-
- gpr.FlushBeforeCall();
- fpr.FlushAll();
-
- bool negSin1 = (imm & 0x10) ? true : false;
-
- fpr.MapRegV(sreg);
- // We should write a custom pure-asm function instead.
-#if defined(__ARM_PCS_VFP) // Hardfp
- VMOV(S0, fpr.V(sreg));
-#else // Softfp
- VMOV(R0, fpr.V(sreg));
-#endif
- // FlushBeforeCall saves R1.
- QuickCallFunction(R1, negSin1 ? (void *)&SinCosNegSin : (void *)&SinCos);
-#if !defined(__ARM_PCS_VFP)
- // Returns D0 on hardfp and R0,R1 on softfp due to union joining the two floats
- VMOV(D0, R0, R1);
-#endif
- CompVrotShuffle(dregs, imm, sz, false);
- if (vd2 != -1) {
- // If the negsin setting differs between the two joint invocations, we need to flip the second one.
- bool negSin2 = (imm2 & 0x10) ? true : false;
- CompVrotShuffle(dregs2, imm2, sz, negSin1 != negSin2);
- EatInstruction(nextOp);
- }
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vsgn(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || js.HasTPrefix()) {
- DISABLE;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- u8 sregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- for (int i = 0; i < n; ++i) {
- fpr.MapDirtyInV(tempregs[i], sregs[i]);
- // Zero and denormals sign as zero, everything else (NaN too) by its sign bit.
- VMOV(SCRATCHREG1, fpr.V(sregs[i]));
- MOV(SCRATCHREG2, Operand2(SCRATCHREG1, ST_LSL, 1));
- MOVS(SCRATCHREG2, Operand2(SCRATCHREG2, ST_LSR, 24));
- SetCC(CC_NEQ);
- AND(SCRATCHREG1, SCRATCHREG1, AssumeMakeOperand2(0x80000000));
- ORR(SCRATCHREG1, SCRATCHREG1, AssumeMakeOperand2(0x3F800000));
- SetCC(CC_EQ);
- MOV(SCRATCHREG1, AssumeMakeOperand2(0x0));
- SetCC(CC_AL);
- VMOV(fpr.V(tempregs[i]), SCRATCHREG1);
- }
-
- for (int i = 0; i < n; ++i) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_Vocp(MIPSOpcode op) {
- CONDITIONAL_DISABLE(VFPU_VEC);
- if (js.HasUnknownPrefix() || !IsPrefixWithinSize(js.prefixS, op) || js.HasTPrefix() || (js.prefixS & VFPU_NEGATE(1, 1, 1, 1)) != 0) {
- DISABLE;
- }
-
- VectorSize sz = GetVecSize(op);
- int n = GetNumVectorElements(sz);
-
- // This is a hack that modifies prefixes. We eat them later, so just overwrite.
- // S prefix forces the negate flags.
- js.prefixS |= 0x000F0000;
- // T prefix forces constants on and regnum to 1.
- // That means negate still works, and abs activates a different constant.
- js.prefixT = (js.prefixT & ~0x000000FF) | 0x00000055 | 0x0000F000;
-
- u8 sregs[4], tregs[4], dregs[4];
- GetVectorRegsPrefixS(sregs, sz, _VS);
- GetVectorRegsPrefixT(tregs, sz, _VS);
- GetVectorRegsPrefixD(dregs, sz, _VD);
-
- MIPSReg tempregs[4];
- for (int i = 0; i < n; ++i) {
- if (!IsOverlapSafe(dregs[i], i, n, sregs)) {
- tempregs[i] = fpr.GetTempV();
- } else {
- tempregs[i] = dregs[i];
- }
- }
-
- for (int i = 0; i < n; ++i) {
- fpr.MapDirtyInInV(tempregs[i], sregs[i], tregs[i]);
- VADD(fpr.V(tempregs[i]), fpr.V(tregs[i]), fpr.V(sregs[i]));
- }
-
- for (int i = 0; i < n; ++i) {
- if (dregs[i] != tempregs[i]) {
- fpr.MapDirtyInV(dregs[i], tempregs[i]);
- VMOV(fpr.V(dregs[i]), fpr.V(tempregs[i]));
- }
- }
-
- ApplyPrefixD(dregs, sz);
-
- fpr.ReleaseSpillLocksAndDiscardTemps();
- }
-
- void ArmJit::Comp_ColorConv(MIPSOpcode op) {
- DISABLE;
- }
-
- void ArmJit::Comp_Vbfy(MIPSOpcode op) {
- DISABLE;
- }
-}
-
-#endif // PPSSPP_ARCH(ARM)
diff --git a/Core/MIPS/ARM/ArmIRAsm.cpp b/Core/MIPS/ARM/ArmIRAsm.cpp
new file mode 100644
index 0000000000..d8755a52bd
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRAsm.cpp
@@ -0,0 +1,223 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Common/Log.h"
+#include "Common/MemoryUtil.h"
+#include "Core/CoreTiming.h"
+#include "Core/MemMap.h"
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+#include "Core/MIPS/JitCommon/JitCommon.h"
+#include "Core/MIPS/JitCommon/JitState.h"
+#include "Core/Core.h"
+
+std::vector DisassembleArm2(const u8 *data, int size);
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+static const bool enableDisasm = false;
+
+void ArmJitBackend::GenerateFixedCode(MIPSState *mipsState) {
+ // This will be used as a writable scratch area, always 32-bit accessible.
+ const u8 *start = AlignCodePage();
+ if (DebugProfilerEnabled()) {
+ ProtectMemoryPages(start, GetMemoryProtectPageSize(), MEM_PROT_READ | MEM_PROT_WRITE);
+ hooks_.profilerPC = (uint32_t *)GetWritableCodePtr();
+ Write32(0);
+ hooks_.profilerStatus = (IRProfilerStatus *)GetWritableCodePtr();
+ Write32(0);
+ }
+
+ const u8 *disasmStart = AlignCodePage();
+ BeginWrite(GetMemoryProtectPageSize());
+
+ // These are called with BL, so LR has to survive.
+ restoreRoundingMode_ = AlignCode16();
+ {
+ VMRS(SCRATCH2);
+ // Outside the JIT we run with round-to-nearest and flush-to-zero off.
+ BIC(SCRATCH2, SCRATCH2, AssumeMakeOperand2((3 | 4) << 22));
+ VMSR(SCRATCH2);
+ B(R_LR);
+ }
+
+ // Must preserve SCRATCH1, since it may hold the PC. Destroys SCRATCH2 and R12.
+ applyRoundingMode_ = AlignCode16();
+ {
+ LDR(SCRATCH2, CTXREG, offsetof(MIPSState, fcr31));
+
+ TST(SCRATCH2, AssumeMakeOperand2(1 << 24));
+ AND(SCRATCH2, SCRATCH2, Operand2(3));
+ SetCC(CC_NEQ);
+ ADD(SCRATCH2, SCRATCH2, Operand2(4));
+ SetCC(CC_AL);
+
+ // We can skip if the rounding mode is nearest (0) and flush is not set.
+ // (as restoreRoundingMode cleared it out anyway)
+ CMP(SCRATCH2, Operand2(0));
+ FixupBranch skip = B_CC(CC_EQ);
+
+ // MIPS Rounding Mode: ARM Rounding Mode
+ // 0: Round nearest 0
+ // 1: Round to zero 3
+ // 2: Round up (ceil) 1
+ // 3: Round down (floor) 2
+ AND(R12, SCRATCH2, Operand2(3));
+ CMP(R12, Operand2(1));
+
+ SetCC(CC_EQ); ADD(SCRATCH2, SCRATCH2, Operand2(2));
+ SetCC(CC_GT); SUB(SCRATCH2, SCRATCH2, Operand2(1));
+ SetCC(CC_AL);
+
+ VMRS(R12);
+ // Assume we're always in round-to-nearest mode beforehand.
+ // But we need to clear flush to zero in this case anyway.
+ BIC(R12, R12, AssumeMakeOperand2((3 | 4) << 22));
+ ORR(R12, R12, Operand2(SCRATCH2, ST_LSL, 22));
+ VMSR(R12);
+
+ SetJumpTarget(skip);
+ B(R_LR);
+ }
+
+ hooks_.enterDispatcher = (IRNativeFuncNoArg)AlignCode16();
+
+ // Nine registers, so we're misaligned by 4 for calls, which the SUB fixes.
+ PUSH(9, R4, R5, R6, R7, R8, R9, R10, R11, R_LR);
+ SUB(R_SP, R_SP, 4);
+ VPUSH(D8, 8);
+
+ // Fixed registers, these are always kept when in Jit context.
+ MOVP2R(MEMBASEREG, Memory::base);
+ MOVP2R(CTXREG, mipsState);
+
+ LoadStaticRegisters();
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ MovFromPC(SCRATCH1);
+ WriteDebugPC(SCRATCH1);
+ outerLoopPCInSCRATCH1_ = GetCodePtr();
+ MovToPC(SCRATCH1);
+ outerLoop_ = GetCodePtr();
+ SaveStaticRegisters(); // Advance can change the downcount, so must save/restore
+ RestoreRoundingMode(true);
+ WriteDebugProfilerStatus(IRProfilerStatus::TIMER_ADVANCE);
+ QuickCallFunctionR(R12, &CoreTiming::Advance, CTXREG);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ ApplyRoundingMode(true);
+ LoadStaticRegisters();
+
+ dispatcherCheckCoreState_ = GetCodePtr();
+
+ MOVP2R(SCRATCH1, &coreState);
+ LDR(SCRATCH1, SCRATCH1, 0);
+ CMP(SCRATCH1, Operand2(0));
+ FixupBranch badCoreState = B_CC(CC_NEQ);
+
+ // Check downcount.
+ CMP(DOWNCOUNTREG, Operand2(0));
+ B_CC(CC_MI, outerLoop_);
+ FixupBranch skipToRealDispatch = B();
+
+ dispatcherPCInSCRATCH1_ = GetCodePtr();
+ MovToPC(SCRATCH1);
+
+ hooks_.dispatcher = GetCodePtr();
+
+ CMP(DOWNCOUNTREG, Operand2(0));
+ FixupBranch bail = B_CC(CC_MI);
+ SetJumpTarget(skipToRealDispatch);
+
+ dispatcherNoCheck_ = GetCodePtr();
+
+ MovFromPC(SCRATCH1);
+ WriteDebugPC(SCRATCH1);
+ static_assert(Memory::BLOCK_SHADOW_ENTRY_MASK == 0x0FFFFFFC, "BICs below assume the 32-bit shadow mask");
+ BIC(SCRATCH1, SCRATCH1, Operand2(0xF0, 4)); // &= 0x0FFFFFFF. Rotation is to the right, in 2-bit increments.
+ BIC(SCRATCH1, SCRATCH1, Operand2(3));
+ MOVP2R(SCRATCH2, Memory::blockShadow);
+ hooks_.dispatchFetch = GetCodePtr();
+ LDR(SCRATCH1, SCRATCH2, SCRATCH1);
+ // The entry is the block's offset into the code space, or 0 for none.
+ CMP(SCRATCH1, Operand2(0));
+ FixupBranch noBlock = B_CC(CC_EQ);
+ MOVP2R(SCRATCH2, GetBasePtr());
+ ADD(SCRATCH1, SCRATCH1, SCRATCH2);
+ B(SCRATCH1);
+ SetJumpTarget(noBlock);
+
+ // No block found, let's jit. We don't need to save static regs, they're all callee saved.
+ // A replacement hook's block shadow entry jumps here too (GetBlockShadowHookValue()). JitAt
+ // replaces it with the new block's entry, and destroying that block puts the hook value back.
+ hooks_.blockShadowHook = GetCodePtr();
+ RestoreRoundingMode(true);
+ WriteDebugProfilerStatus(IRProfilerStatus::COMPILING);
+ QuickCallFunctionR(R12, &MIPSComp::JitAt, CTXREG);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ ApplyRoundingMode(true);
+
+ // Let's just dispatch again, we'll enter the block since we know it's there.
+ B(dispatcherNoCheck_);
+
+ SetJumpTarget(bail);
+
+ MOVP2R(SCRATCH1, &coreState);
+ LDR(SCRATCH1, SCRATCH1, 0);
+ CMP(SCRATCH1, Operand2(0));
+ B_CC(CC_EQ, outerLoop_);
+
+ const uint8_t *quitLoop = GetCodePtr();
+ SetJumpTarget(badCoreState);
+
+ WriteDebugProfilerStatus(IRProfilerStatus::NOT_RUNNING);
+ SaveStaticRegisters();
+ RestoreRoundingMode(true);
+
+ VPOP(D8, 8);
+ ADD(R_SP, R_SP, 4);
+ POP(9, R4, R5, R6, R7, R8, R9, R10, R11, R_PC); // Returns
+
+ hooks_.crashHandler = GetCodePtr();
+ MOVP2R(SCRATCH1, &coreState);
+ MOVI2R(SCRATCH2, CORE_RUNTIME_ERROR);
+ STR(SCRATCH2, SCRATCH1, 0);
+ B(quitLoop);
+
+ // Leave this at the end, add more stuff above.
+ if (enableDisasm) {
+ std::vector lines = DisassembleArm2(disasmStart, (int)(GetCodePtr() - disasmStart));
+ for (auto s : lines) {
+ INFO_LOG(Log::JIT, "%s", s.c_str());
+ }
+ }
+
+ // Let's spare the pre-generated code from unprotect-reprotect.
+ AlignCodePage();
+ jitStartOffset_ = (int)(GetCodePtr() - start);
+ // Don't forget to zap the instruction cache! This must stay at the end of this function.
+ FlushIcache();
+ EndWrite();
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompALU.cpp b/Core/MIPS/ARM/ArmIRCompALU.cpp
new file mode 100644
index 0000000000..4c575e8895
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompALU.cpp
@@ -0,0 +1,509 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Common/CPUDetect.h"
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+
+// This file contains compilation for integer arithmetic, logic, shifts, compares, and multiplies.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+void ArmJitBackend::CompIR_Arith(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Add:
+ regs_.Map(inst);
+ ADD(regs_.R(inst.dest), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::Sub:
+ regs_.Map(inst);
+ SUB(regs_.R(inst.dest), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::AddConst:
+ regs_.Map(inst);
+ ADDI2R(regs_.R(inst.dest), regs_.R(inst.src1), inst.constant, SCRATCH1);
+ break;
+
+ case IROp::SubConst:
+ regs_.Map(inst);
+ SUBI2R(regs_.R(inst.dest), regs_.R(inst.src1), inst.constant, SCRATCH1);
+ break;
+
+ case IROp::Neg:
+ regs_.Map(inst);
+ RSB(regs_.R(inst.dest), regs_.R(inst.src1), Operand2(0));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Assign(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Mov:
+ if (inst.dest != inst.src1) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ }
+ break;
+
+ case IROp::Ext8to32:
+ regs_.Map(inst);
+ SXTB(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ case IROp::Ext16to32:
+ regs_.Map(inst);
+ SXTH(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Bits(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::BSwap16:
+ regs_.Map(inst);
+ REV16(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ case IROp::BSwap32:
+ regs_.Map(inst);
+ REV(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ case IROp::Clz:
+ regs_.Map(inst);
+ CLZ(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ case IROp::ReverseBits:
+ regs_.Map(inst);
+ RBIT(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Compare(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // Sets dest to 1 if cc holds, else 0. The MOVs don't touch the flags, so dest may be a source.
+ auto setCC = [&](ARMReg dest, CCFlags cc) {
+ MOV(dest, Operand2(0));
+ SetCC(cc);
+ MOV(dest, Operand2(1));
+ SetCC(CC_AL);
+ };
+
+ switch (inst.op) {
+ case IROp::Slt:
+ regs_.Map(inst);
+ CMP(regs_.R(inst.src1), regs_.R(inst.src2));
+ setCC(regs_.R(inst.dest), CC_LT);
+ break;
+
+ case IROp::SltConst:
+ if (inst.constant == 0) {
+ // Basically, getting the sign bit.
+ regs_.Map(inst);
+ LSR(regs_.R(inst.dest), regs_.R(inst.src1), Operand2(31));
+ } else {
+ regs_.Map(inst);
+ CMPI2R(regs_.R(inst.src1), inst.constant, SCRATCH1);
+ setCC(regs_.R(inst.dest), CC_LT);
+ }
+ break;
+
+ case IROp::SltU:
+ if (regs_.IsGPRImm(inst.src1) && regs_.GetGPRImm(inst.src1) == 0) {
+ // This is kinda common, same as != 0. Avoid flushing src1.
+ regs_.SpillLockGPR(inst.src2, inst.dest);
+ regs_.MapGPR(inst.src2);
+ regs_.MapGPR(inst.dest, MIPSMap::NOINIT);
+ CMP(regs_.R(inst.src2), Operand2(0));
+ setCC(regs_.R(inst.dest), CC_NEQ);
+ } else {
+ regs_.Map(inst);
+ CMP(regs_.R(inst.src1), regs_.R(inst.src2));
+ setCC(regs_.R(inst.dest), CC_LO);
+ }
+ break;
+
+ case IROp::SltUConst:
+ if (inst.constant == 0) {
+ regs_.SetGPRImm(inst.dest, 0);
+ } else {
+ regs_.Map(inst);
+ CMPI2R(regs_.R(inst.src1), inst.constant, SCRATCH1);
+ setCC(regs_.R(inst.dest), CC_LO);
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_CondAssign(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::MovZ:
+ case IROp::MovNZ:
+ if (inst.dest != inst.src2) {
+ regs_.Map(inst);
+ CMP(regs_.R(inst.src1), Operand2(0));
+ SetCC(inst.op == IROp::MovZ ? CC_EQ : CC_NEQ);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src2));
+ SetCC(CC_AL);
+ }
+ break;
+
+ case IROp::Max:
+ case IROp::Min:
+ if (inst.src1 != inst.src2) {
+ regs_.Map(inst);
+ CMP(regs_.R(inst.src1), regs_.R(inst.src2));
+ // Exactly one of these happens, so dest may be either source.
+ CCFlags pickSrc1 = inst.op == IROp::Max ? CC_GE : CC_LE;
+ SetCC(pickSrc1);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ SetCC(InvertCond(pickSrc1));
+ MOV(regs_.R(inst.dest), regs_.R(inst.src2));
+ SetCC(CC_AL);
+ } else if (inst.dest != inst.src1) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Div(IRInst inst) {
+ CONDITIONAL_DISABLE;
+ if (!cpu_info.bIDIVa) {
+ CompIR_Generic(inst);
+ return;
+ }
+
+ switch (inst.op) {
+ case IROp::Div:
+ {
+ regs_.MapWithExtra(inst, { { 'G', IRREG_LO, 1, MIPSMap::NOINIT }, { 'G', IRREG_HI, 1, MIPSMap::NOINIT } });
+ ARMReg lo = regs_.R(IRREG_LO);
+ ARMReg hi = regs_.R(IRREG_HI);
+ // INT_MIN divided by -1 = INT_MIN with remainder 0, anything divided by 0 = 0. The first is
+ // what the hardware does too (cpu/cpu_alu/cpu_div), so only the second needs tweaking.
+ SDIV(lo, regs_.R(inst.src1), regs_.R(inst.src2));
+ MUL(SCRATCH1, lo, regs_.R(inst.src2));
+ SUB(hi, regs_.R(inst.src1), SCRATCH1);
+
+ // Divide by zero, remainder is fine. mips->lo = numerator < 0 ? 1 : -1
+ CMP(regs_.R(inst.src2), Operand2(0));
+ FixupBranch skipNonZero = B_CC(CC_NEQ);
+ CMP(regs_.R(inst.src1), Operand2(0));
+ MOV(lo, Operand2(1));
+ SetCC(CC_GE);
+ MVN(lo, Operand2(0));
+ SetCC(CC_AL);
+ SetJumpTarget(skipNonZero);
+ break;
+ }
+
+ case IROp::DivU:
+ {
+ regs_.MapWithExtra(inst, { { 'G', IRREG_LO, 1, MIPSMap::NOINIT }, { 'G', IRREG_HI, 1, MIPSMap::NOINIT } });
+ ARMReg lo = regs_.R(IRREG_LO);
+ ARMReg hi = regs_.R(IRREG_HI);
+ // Anything divided by 0 = 0.
+ UDIV(lo, regs_.R(inst.src1), regs_.R(inst.src2));
+ MUL(SCRATCH1, lo, regs_.R(inst.src2));
+ SUB(hi, regs_.R(inst.src1), SCRATCH1);
+
+ // On divide by zero, we have to update LO - remainder is correct.
+ // If the numerator is <= 0xFFFF (unsigned), it's 0xFFFF, otherwise -1.
+ CMP(regs_.R(inst.src2), Operand2(0));
+ FixupBranch skipNonZero = B_CC(CC_NEQ);
+ MOVI2R(lo, 0xFFFF);
+ CMP(regs_.R(inst.src1), lo);
+ SetCC(CC_HI);
+ MVN(lo, Operand2(0));
+ SetCC(CC_AL);
+ SetJumpTarget(skipNonZero);
+ break;
+ }
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_HiLo(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::MtLo:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_LO, 1, MIPSMap::NOINIT } });
+ MOV(regs_.R(IRREG_LO), regs_.R(inst.src1));
+ break;
+
+ case IROp::MtHi:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_HI, 1, MIPSMap::NOINIT } });
+ MOV(regs_.R(IRREG_HI), regs_.R(inst.src1));
+ break;
+
+ case IROp::MfLo:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_LO, 1, MIPSMap::INIT } });
+ MOV(regs_.R(inst.dest), regs_.R(IRREG_LO));
+ break;
+
+ case IROp::MfHi:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_HI, 1, MIPSMap::INIT } });
+ MOV(regs_.R(inst.dest), regs_.R(IRREG_HI));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Logic(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::And:
+ if (inst.src1 != inst.src2) {
+ regs_.Map(inst);
+ AND(regs_.R(inst.dest), regs_.R(inst.src1), regs_.R(inst.src2));
+ } else if (inst.src1 != inst.dest) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ }
+ break;
+
+ case IROp::Or:
+ if (inst.src1 != inst.src2) {
+ regs_.Map(inst);
+ ORR(regs_.R(inst.dest), regs_.R(inst.src1), regs_.R(inst.src2));
+ } else if (inst.src1 != inst.dest) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ }
+ break;
+
+ case IROp::Xor:
+ if (inst.src1 == inst.src2) {
+ regs_.SetGPRImm(inst.dest, 0);
+ } else {
+ regs_.Map(inst);
+ EOR(regs_.R(inst.dest), regs_.R(inst.src1), regs_.R(inst.src2));
+ }
+ break;
+
+ case IROp::AndConst:
+ regs_.Map(inst);
+ ANDI2R(regs_.R(inst.dest), regs_.R(inst.src1), inst.constant, SCRATCH1);
+ break;
+
+ case IROp::OrConst:
+ regs_.Map(inst);
+ ORI2R(regs_.R(inst.dest), regs_.R(inst.src1), inst.constant, SCRATCH1);
+ break;
+
+ case IROp::XorConst:
+ regs_.Map(inst);
+ EORI2R(regs_.R(inst.dest), regs_.R(inst.src1), inst.constant, SCRATCH1);
+ break;
+
+ case IROp::Not:
+ regs_.Map(inst);
+ MVN(regs_.R(inst.dest), regs_.R(inst.src1));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Mult(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ auto mapHiLo = [&](MIPSMap flags) {
+ regs_.MapWithExtra(inst, { { 'G', IRREG_LO, 1, flags }, { 'G', IRREG_HI, 1, flags } });
+ };
+
+ switch (inst.op) {
+ case IROp::Mult:
+ mapHiLo(MIPSMap::NOINIT);
+ SMULL(regs_.R(IRREG_LO), regs_.R(IRREG_HI), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::MultU:
+ mapHiLo(MIPSMap::NOINIT);
+ UMULL(regs_.R(IRREG_LO), regs_.R(IRREG_HI), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::Madd:
+ mapHiLo(MIPSMap::DIRTY);
+ SMLAL(regs_.R(IRREG_LO), regs_.R(IRREG_HI), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::MaddU:
+ mapHiLo(MIPSMap::DIRTY);
+ UMLAL(regs_.R(IRREG_LO), regs_.R(IRREG_HI), regs_.R(inst.src1), regs_.R(inst.src2));
+ break;
+
+ case IROp::Msub:
+ case IROp::MsubU:
+ // No multiply-subtract-long, so do the product and a 64-bit subtract.
+ mapHiLo(MIPSMap::DIRTY);
+ if (inst.op == IROp::Msub)
+ SMULL(SCRATCH1, SCRATCH2, regs_.R(inst.src1), regs_.R(inst.src2));
+ else
+ UMULL(SCRATCH1, SCRATCH2, regs_.R(inst.src1), regs_.R(inst.src2));
+ SUBS(regs_.R(IRREG_LO), regs_.R(IRREG_LO), SCRATCH1);
+ SBC(regs_.R(IRREG_HI), regs_.R(IRREG_HI), SCRATCH2);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Shift(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // A shift by register uses the bottom byte of it, but MIPS only the bottom five bits.
+ auto shiftByReg = [&](ShiftType type) {
+ regs_.Map(inst);
+ AND(SCRATCH1, regs_.R(inst.src2), Operand2(31));
+ MOV(regs_.R(inst.dest), Operand2(regs_.R(inst.src1), type, SCRATCH1));
+ };
+ auto shiftByImm = [&](ShiftType type, int amount) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), Operand2(regs_.R(inst.src1), type, (u8)amount));
+ };
+ auto movOrNothing = [&]() {
+ if (inst.dest != inst.src1) {
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(inst.src1));
+ }
+ };
+
+ switch (inst.op) {
+ case IROp::Shl:
+ shiftByReg(ST_LSL);
+ break;
+
+ case IROp::Shr:
+ shiftByReg(ST_LSR);
+ break;
+
+ case IROp::Sar:
+ shiftByReg(ST_ASR);
+ break;
+
+ case IROp::Ror:
+ // Rotation by the bottom byte is the same as by its bottom five bits.
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), Operand2(regs_.R(inst.src1), ST_ROR, regs_.R(inst.src2)));
+ break;
+
+ case IROp::ShlImm:
+ // Shouldn't happen, but let's be safe of any passes that modify the ops.
+ if (inst.src2 >= 32)
+ regs_.SetGPRImm(inst.dest, 0);
+ else if (inst.src2 == 0)
+ movOrNothing();
+ else
+ shiftByImm(ST_LSL, inst.src2);
+ break;
+
+ case IROp::ShrImm:
+ if (inst.src2 >= 32)
+ regs_.SetGPRImm(inst.dest, 0);
+ else if (inst.src2 == 0)
+ movOrNothing();
+ else
+ shiftByImm(ST_LSR, inst.src2);
+ break;
+
+ case IROp::SarImm:
+ if (inst.src2 >= 32)
+ shiftByImm(ST_ASR, 31);
+ else if (inst.src2 == 0)
+ movOrNothing();
+ else
+ shiftByImm(ST_ASR, inst.src2);
+ break;
+
+ case IROp::RorImm:
+ if ((inst.src2 & 31) == 0)
+ movOrNothing();
+ else
+ shiftByImm(ST_ROR, inst.src2 & 31);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompBranch.cpp b/Core/MIPS/ARM/ArmIRCompBranch.cpp
new file mode 100644
index 0000000000..aa0336ad77
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompBranch.cpp
@@ -0,0 +1,134 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+
+// This file contains compilation for exits.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+void ArmJitBackend::CompIR_Exit(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ ARMReg exitReg = INVALID_REG;
+ switch (inst.op) {
+ case IROp::ExitToConst:
+ FlushAll();
+ WriteConstExit(inst.constant);
+ break;
+
+ case IROp::ExitToReg:
+ exitReg = regs_.MapGPR(inst.src1);
+ FlushAll();
+ MOV(SCRATCH1, exitReg);
+ B(dispatcherPCInSCRATCH1_);
+ break;
+
+ case IROp::ExitToPC:
+ FlushAll();
+ B(dispatcherCheckCoreState_);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_ExitIf(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ ARMReg lhs = INVALID_REG;
+ ARMReg rhs = INVALID_REG;
+ FixupBranch fixup;
+ switch (inst.op) {
+ case IROp::ExitToConstIfEq:
+ case IROp::ExitToConstIfNeq:
+ if (regs_.IsGPRImm(inst.src1) && regs_.GetGPRImm(inst.src1) == 0) {
+ lhs = regs_.MapGPR(inst.src2);
+ FlushAll();
+ CMP(lhs, Operand2(0));
+ } else if (regs_.IsGPRImm(inst.src2) && regs_.GetGPRImm(inst.src2) == 0) {
+ lhs = regs_.MapGPR(inst.src1);
+ FlushAll();
+ CMP(lhs, Operand2(0));
+ } else {
+ regs_.Map(inst);
+ lhs = regs_.R(inst.src1);
+ rhs = regs_.R(inst.src2);
+ FlushAll();
+ CMP(lhs, rhs);
+ }
+
+ fixup = B_CC(inst.op == IROp::ExitToConstIfEq ? CC_NEQ : CC_EQ);
+ WriteConstExit(inst.constant);
+ SetJumpTarget(fixup);
+ break;
+
+ case IROp::ExitToConstIfGtZ:
+ case IROp::ExitToConstIfGeZ:
+ case IROp::ExitToConstIfLtZ:
+ case IROp::ExitToConstIfLeZ:
+ {
+ lhs = regs_.MapGPR(inst.src1);
+ FlushAll();
+ CMP(lhs, Operand2(0));
+ // Branch over the exit when the condition fails.
+ CCFlags skip = CC_AL;
+ switch (inst.op) {
+ case IROp::ExitToConstIfGtZ: skip = CC_LE; break;
+ case IROp::ExitToConstIfGeZ: skip = CC_LT; break;
+ case IROp::ExitToConstIfLtZ: skip = CC_GE; break;
+ case IROp::ExitToConstIfLeZ: skip = CC_GT; break;
+ default: break;
+ }
+ fixup = B_CC(skip);
+ WriteConstExit(inst.constant);
+ SetJumpTarget(fixup);
+ break;
+ }
+
+ case IROp::ExitToConstIfFpTrue:
+ case IROp::ExitToConstIfFpFalse:
+ // Note: not used.
+ DISABLE;
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompFPU.cpp b/Core/MIPS/ARM/ArmIRCompFPU.cpp
new file mode 100644
index 0000000000..4841f5485a
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompFPU.cpp
@@ -0,0 +1,608 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+#include "Core/MIPS/MIPSVFPUUtils.h"
+
+// This file contains compilation for floating point arithmetic, compares, and conversions.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+void ArmJitBackend::CompIR_FArith(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::FAdd:
+ regs_.Map(inst);
+ VADD(regs_.F(inst.dest), regs_.F(inst.src1), regs_.F(inst.src2));
+ break;
+
+ case IROp::FSub:
+ regs_.Map(inst);
+ VSUB(regs_.F(inst.dest), regs_.F(inst.src1), regs_.F(inst.src2));
+ break;
+
+ case IROp::FMul:
+ // inf * 0 gives the default NaN, 0x7FC00000, as the IR expects.
+ regs_.Map(inst);
+ VMUL(regs_.F(inst.dest), regs_.F(inst.src1), regs_.F(inst.src2));
+ break;
+
+ case IROp::FDiv:
+ regs_.Map(inst);
+ VDIV(regs_.F(inst.dest), regs_.F(inst.src1), regs_.F(inst.src2));
+ break;
+
+ case IROp::FSqrt:
+ // A negative input gives the positive default NaN here too.
+ regs_.Map(inst);
+ VSQRT(regs_.F(inst.dest), regs_.F(inst.src1));
+ break;
+
+ case IROp::FNeg:
+ regs_.Map(inst);
+ VNEG(regs_.F(inst.dest), regs_.F(inst.src1));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FAssign(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::FMov:
+ if (inst.dest != inst.src1) {
+ regs_.Map(inst);
+ VMOV(regs_.F(inst.dest), regs_.F(inst.src1));
+ }
+ break;
+
+ case IROp::FAbs:
+ regs_.Map(inst);
+ VABS(regs_.F(inst.dest), regs_.F(inst.src1));
+ break;
+
+ case IROp::FSign:
+ // Zero and denormals both sign as zero on the hardware. Anything else, NaN included, is
+ // 1.0 with the input's sign.
+ regs_.Map(inst);
+ VMOV(SCRATCH1, regs_.F(inst.src1));
+ BIC(SCRATCH2, SCRATCH1, AssumeMakeOperand2(0x80000000));
+ CMP(SCRATCH2, AssumeMakeOperand2(0x00800000));
+ AND(SCRATCH1, SCRATCH1, AssumeMakeOperand2(0x80000000));
+ ORR(SCRATCH1, SCRATCH1, AssumeMakeOperand2(0x3F800000));
+ SetCC(CC_LO);
+ MOV(SCRATCH1, Operand2(0));
+ SetCC(CC_AL);
+ VMOV(regs_.F(inst.dest), SCRATCH1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FCompare(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ constexpr IRReg IRREG_VFPU_CC = IRREG_VFPU_CTRL_BASE + VFPU_CTRL_CC;
+
+ // Sets dest to 1 if any of the conditions holds after a VCMP, else 0.
+ auto setFromFlags = [&](ARMReg dest, CCFlags cc, CCFlags cc2 = CC_AL) {
+ VMRS_APSR();
+ MOV(dest, Operand2(0));
+ SetCC(cc);
+ MOV(dest, Operand2(1));
+ if (cc2 != CC_AL) {
+ SetCC(cc2);
+ MOV(dest, Operand2(1));
+ }
+ SetCC(CC_AL);
+ };
+
+ switch (inst.op) {
+ case IROp::FCmp:
+ if (inst.dest == IRFpCompareMode::False) {
+ regs_.SetGPRImm(IRREG_FPCOND, 0);
+ break;
+ }
+
+ regs_.MapWithExtra(inst, { { 'G', IRREG_FPCOND, 1, MIPSMap::NOINIT } });
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ switch (inst.dest) {
+ case IRFpCompareMode::EitherUnordered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_VS);
+ break;
+ case IRFpCompareMode::EqualOrdered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_EQ);
+ break;
+ case IRFpCompareMode::EqualUnordered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_EQ, CC_VS);
+ break;
+ case IRFpCompareMode::LessEqualOrdered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_LS);
+ break;
+ case IRFpCompareMode::LessEqualUnordered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_LE);
+ break;
+ case IRFpCompareMode::LessOrdered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_LO);
+ break;
+ case IRFpCompareMode::LessUnordered:
+ setFromFlags(regs_.R(IRREG_FPCOND), CC_LT);
+ break;
+ default:
+ _assert_msg_(false, "Unexpected IRFpCompareMode %d", inst.dest);
+ }
+ break;
+
+ case IROp::FCmovVfpuCC:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_VFPU_CC, 1, MIPSMap::INIT } });
+ TST(regs_.R(IRREG_VFPU_CC), AssumeMakeOperand2(1 << (inst.src2 & 0xF)));
+ if (inst.dest != inst.src1) {
+ // With bit 7 of src2, it moves when the CC bit is set, otherwise when it's clear.
+ SetCC(((inst.src2 >> 7) & 1) ? CC_NEQ : CC_EQ);
+ VMOV(regs_.F(inst.dest), regs_.F(inst.src1));
+ SetCC(CC_AL);
+ }
+ break;
+
+ case IROp::FCmpVfpuBit:
+ {
+ regs_.MapGPR(IRREG_VFPU_CC, MIPSMap::DIRTY);
+
+ // Compares the magnitude against infinity, for the EI/NI/ES/NS conditions.
+ auto cmpAbsToInf = [&]() {
+ MOVI2R(SCRATCH1, 0x7F800000);
+ VMOV(SCRATCHF2, SCRATCH1);
+ VABS(SCRATCHF1, regs_.F(inst.src1));
+ VCMP(SCRATCHF1, SCRATCHF2);
+ };
+
+ switch (VCondition(inst.dest & 0xF)) {
+ case VC_EQ:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_EQ);
+ break;
+ case VC_NE:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_NEQ);
+ break;
+ case VC_LT:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_LO);
+ break;
+ case VC_LE:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_LS);
+ break;
+ case VC_GT:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_GT);
+ break;
+ case VC_GE:
+ regs_.Map(inst);
+ VCMP(regs_.F(inst.src1), regs_.F(inst.src2));
+ setFromFlags(SCRATCH1, CC_GE);
+ break;
+ case VC_EZ:
+ regs_.MapFPR(inst.src1);
+ VCMP(regs_.F(inst.src1));
+ setFromFlags(SCRATCH1, CC_EQ);
+ break;
+ case VC_NZ:
+ regs_.MapFPR(inst.src1);
+ VCMP(regs_.F(inst.src1));
+ setFromFlags(SCRATCH1, CC_NEQ);
+ break;
+ case VC_EN:
+ regs_.MapFPR(inst.src1);
+ VCMP(regs_.F(inst.src1));
+ setFromFlags(SCRATCH1, CC_VS);
+ break;
+ case VC_NN:
+ regs_.MapFPR(inst.src1);
+ VCMP(regs_.F(inst.src1));
+ setFromFlags(SCRATCH1, CC_VC);
+ break;
+ case VC_EI:
+ regs_.MapFPR(inst.src1);
+ cmpAbsToInf();
+ setFromFlags(SCRATCH1, CC_GE);
+ break;
+ case VC_NI:
+ regs_.MapFPR(inst.src1);
+ cmpAbsToInf();
+ // Less than or NAN.
+ setFromFlags(SCRATCH1, CC_LT);
+ break;
+ case VC_ES:
+ regs_.MapFPR(inst.src1);
+ cmpAbsToInf();
+ // Greater than or equal to Infinity, or NAN.
+ setFromFlags(SCRATCH1, CC_HS);
+ break;
+ case VC_NS:
+ regs_.MapFPR(inst.src1);
+ cmpAbsToInf();
+ // Less than Infinity, but not NAN.
+ setFromFlags(SCRATCH1, CC_LO);
+ break;
+ case VC_TR:
+ MOVI2R(SCRATCH1, 1);
+ break;
+ case VC_FL:
+ MOVI2R(SCRATCH1, 0);
+ break;
+ }
+
+ BFI(regs_.R(IRREG_VFPU_CC), SCRATCH1, inst.dest >> 4, 1);
+ break;
+ }
+
+ case IROp::FCmpVfpuAggregate:
+ regs_.MapGPR(IRREG_VFPU_CC, MIPSMap::DIRTY);
+ if (inst.dest == 1) {
+ // Just replicate the lowest bit to the others.
+ BFI(regs_.R(IRREG_VFPU_CC), regs_.R(IRREG_VFPU_CC), 4, 1);
+ BFI(regs_.R(IRREG_VFPU_CC), regs_.R(IRREG_VFPU_CC), 5, 1);
+ } else {
+ ANDI2R(SCRATCH2, regs_.R(IRREG_VFPU_CC), inst.dest, SCRATCH1);
+ // The any bit.
+ CMP(SCRATCH2, Operand2(0));
+ MOV(SCRATCH1, Operand2(0));
+ SetCC(CC_NEQ);
+ MOV(SCRATCH1, Operand2(1));
+ SetCC(CC_AL);
+ BFI(regs_.R(IRREG_VFPU_CC), SCRATCH1, 4, 1);
+ // The all bit.
+ CMPI2R(SCRATCH2, inst.dest, SCRATCH1);
+ MOV(SCRATCH1, Operand2(0));
+ SetCC(CC_EQ);
+ MOV(SCRATCH1, Operand2(1));
+ SetCC(CC_AL);
+ BFI(regs_.R(IRREG_VFPU_CC), SCRATCH1, 5, 1);
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FCondAssign(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ if (inst.op != IROp::FMin && inst.op != IROp::FMax)
+ INVALIDOP;
+
+ // vmin/vmax: compare by vfpu_minmax_key, and select the operand with its bits.
+ ARMReg tempReg = regs_.GetAndLockTempGPR();
+ regs_.Map(inst);
+ auto key = [&](ARMReg r, IRReg src) {
+ VMOV(r, regs_.F(src));
+ // 0x7F800000 isn't a valid immediate, so this goes through tempReg.
+ TSTI2R(r, 0x7F800000, tempReg);
+ // These don't touch the flags.
+ ASR(tempReg, r, 31);
+ EOR(r, r, Operand2(tempReg, ST_LSR, 1));
+ SetCC(CC_EQ);
+ MOV(r, Operand2(0));
+ SetCC(CC_AL);
+ };
+ key(SCRATCH1, inst.src1);
+ key(SCRATCH2, inst.src2);
+ CMP(SCRATCH1, SCRATCH2);
+ // A tie takes src2. Exactly one of the moves happens, so dest may be either source.
+ CCFlags pickSrc1 = inst.op == IROp::FMin ? CC_LT : CC_GT;
+ if (inst.dest != inst.src1) {
+ SetCC(pickSrc1);
+ VMOV(regs_.F(inst.dest), regs_.F(inst.src1));
+ }
+ if (inst.dest != inst.src2) {
+ SetCC(InvertCond(pickSrc1));
+ VMOV(regs_.F(inst.dest), regs_.F(inst.src2));
+ }
+ SetCC(CC_AL);
+}
+
+// Converts to an integer with the given ARM rounding mode (0 nearest, 1 up, 2 down, 3 zero), or
+// with FPSCR's own when rmode is -1. Only RMode is swapped, so the guest's flush-to-zero still
+// applies. A NaN gives 0x7FFFFFFF, and the conversion saturates the rest.
+void ArmJitBackend::CompFloatToIntWithRounding(ARMReg dest, ARMReg src, int rmode) {
+ if (rmode == 3) {
+ VCMP(src, src);
+ VCVT(dest, src, TO_INT | IS_SIGNED | ROUND_TO_ZERO);
+ } else {
+ if (rmode >= 0) {
+ VMRS(SCRATCH2);
+ BIC(SCRATCH1, SCRATCH2, AssumeMakeOperand2(3 << 22));
+ if (rmode != 0)
+ ORR(SCRATCH1, SCRATCH1, AssumeMakeOperand2(rmode << 22));
+ VMSR(SCRATCH1);
+ }
+ VCMP(src, src);
+ VCVT(dest, src, TO_INT | IS_SIGNED);
+ // Restoring FPSCR restores its flags too, so take the compare's first.
+ VMRS_APSR();
+ if (rmode >= 0)
+ VMSR(SCRATCH2);
+ }
+ if (rmode == 3)
+ VMRS_APSR();
+ SetCC(CC_VS);
+ MVN(SCRATCH1, AssumeMakeOperand2(0x80000000));
+ VMOV(dest, SCRATCH1);
+ SetCC(CC_AL);
+}
+
+void ArmJitBackend::CompIR_FCvt(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::FCvtWS:
+ // The rounding mode in FPSCR is the guest's, see applyRoundingMode.
+ regs_.Map(inst);
+ CompFloatToIntWithRounding(regs_.F(inst.dest), regs_.F(inst.src1), -1);
+ break;
+
+ case IROp::FCvtSW:
+ regs_.Map(inst);
+ VCVT(regs_.F(inst.dest), regs_.F(inst.src1), TO_FLOAT | IS_SIGNED);
+ break;
+
+ case IROp::FCvtScaledWS:
+ {
+ int rmode = 0;
+ switch (IRRoundMode(inst.src2 >> 6)) {
+ case IRRoundMode::RINT_0: rmode = 0; break;
+ case IRRoundMode::CAST_1: rmode = 3; break;
+ case IRRoundMode::CEIL_2: rmode = 1; break;
+ case IRRoundMode::FLOOR_3: rmode = 2; break;
+ }
+ regs_.Map(inst);
+ // Scaling by a power of two is exact (or overflows, which saturates the same way.)
+ MOVI2F(SCRATCHF1, (float)(1UL << (inst.src2 & 0x1F)), SCRATCH1);
+ VMUL(SCRATCHF1, regs_.F(inst.src1), SCRATCHF1);
+ CompFloatToIntWithRounding(regs_.F(inst.dest), SCRATCHF1, rmode);
+ break;
+ }
+
+ case IROp::FCvtScaledSW:
+ regs_.Map(inst);
+ VCVT(regs_.F(inst.dest), regs_.F(inst.src1), TO_FLOAT | IS_SIGNED);
+ MOVI2F(SCRATCHF1, 1.0f / (1UL << (inst.src2 & 0x1F)), SCRATCH1);
+ VMUL(regs_.F(inst.dest), regs_.F(inst.dest), SCRATCHF1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FRound(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ regs_.Map(inst);
+ switch (inst.op) {
+ case IROp::FRound:
+ CompFloatToIntWithRounding(regs_.F(inst.dest), regs_.F(inst.src1), 0);
+ break;
+
+ case IROp::FTrunc:
+ CompFloatToIntWithRounding(regs_.F(inst.dest), regs_.F(inst.src1), 3);
+ break;
+
+ case IROp::FCeil:
+ CompFloatToIntWithRounding(regs_.F(inst.dest), regs_.F(inst.src1), 1);
+ break;
+
+ case IROp::FFloor:
+ CompFloatToIntWithRounding(regs_.F(inst.dest), regs_.F(inst.src1), 2);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FSat(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // vfpu_clamp: v >= max ? max : (v <= min ? min : v). A NaN stays, and -0.0 becomes the min
+ // when that's +0.0. There's no scalar min/max on VFP, so it's compares and moves.
+ switch (inst.op) {
+ case IROp::FSat0_1:
+ case IROp::FSatMinus1_1:
+ {
+ regs_.Map(inst);
+ ARMReg dest = regs_.F(inst.dest);
+ ARMReg src = regs_.F(inst.src1);
+ MOVI2F(SCRATCHF1, 1.0f, SCRATCH1);
+ if (inst.op == IROp::FSat0_1) {
+ MOVI2F(SCRATCHF2, 0.0f, SCRATCH1);
+ } else {
+ VNEG(SCRATCHF2, SCRATCHF1);
+ }
+ VCMP(src, SCRATCHF1);
+ VMRS_APSR();
+ if (dest != src)
+ VMOV(dest, src);
+ SetCC(CC_GE);
+ VMOV(dest, SCRATCHF1);
+ SetCC(CC_AL);
+ // If it was replaced, it's 1.0, which isn't <= either min.
+ VCMP(dest, SCRATCHF2);
+ VMRS_APSR();
+ SetCC(CC_LS);
+ VMOV(dest, SCRATCHF2);
+ SetCC(CC_AL);
+ break;
+ }
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FSpecial(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // The argument goes in S0 and the result comes back there with the hard float ABI. With
+ // softfp (Android's armeabi-v7a), floats are passed and returned in R0 (and R1.)
+ auto loadArg = [&]() {
+ regs_.FlushBeforeCall();
+ WriteDebugProfilerStatus(IRProfilerStatus::MATH_HELPER);
+ // It might be in a callee-saved register.
+ if (regs_.IsFPRMapped(inst.src1)) {
+ VMOV(S0, regs_.F(inst.src1));
+ } else {
+ VLDR(S0, CTXREG, offsetof(MIPSState, f) + inst.src1 * 4);
+ }
+#if !defined(__ARM_PCS_VFP)
+ VMOV(R0, S0);
+#endif
+ };
+ // Before anything else can use R0 and R1.
+ auto resultToS0 = [&](bool twoFloats) {
+#if !defined(__ARM_PCS_VFP)
+ VMOV(S0, R0);
+ if (twoFloats)
+ VMOV(S1, R1);
+#endif
+ };
+ auto callFuncF_F = [&](float (*func)(float)) {
+ loadArg();
+ QuickCallFunction(R12, func);
+ resultToS0(false);
+ regs_.MapFPR(inst.dest, MIPSMap::NOINIT);
+ VMOV(regs_.F(inst.dest), S0);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ };
+
+ switch (inst.op) {
+ case IROp::FSin:
+ callFuncF_F(&vfpu_sin);
+ break;
+
+ case IROp::FCos:
+ callFuncF_F(&vfpu_cos);
+ break;
+
+ case IROp::FRSqrt:
+ callFuncF_F(&vfpu_rsqrt);
+ break;
+
+ case IROp::FRecip:
+ callFuncF_F(&vfpu_rcp);
+ break;
+
+ case IROp::FAsin:
+ callFuncF_F(&vfpu_asin);
+ break;
+
+ case IROp::FVSqrt:
+ callFuncF_F(&vfpu_sqrt);
+ break;
+
+ case IROp::FExp2:
+ callFuncF_F(&vfpu_exp2);
+ break;
+
+ case IROp::FLog2:
+ callFuncF_F(&vfpu_log2);
+ break;
+
+ case IROp::FHalfToFloat:
+ callFuncF_F(inst.src2 ? &vfpu_h2f_upper : &vfpu_h2f_lower);
+ break;
+
+ case IROp::FSinCos:
+ // The helper returns the sine and cosine packed into a double, which is S0 and S1.
+ loadArg();
+ QuickCallFunction(R12, &vfpu_sincos_packed);
+ resultToS0(true);
+ regs_.Map(inst);
+ VMOV(regs_.F(inst.dest), S0);
+ VMOV(regs_.F(inst.dest + 1), S1);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_RoundingMode(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // The helpers are called with BL and use R12, so those mustn't hold anything.
+ switch (inst.op) {
+ case IROp::RestoreRoundingMode:
+ regs_.FlushBeforeCall();
+ RestoreRoundingMode();
+ break;
+
+ case IROp::ApplyRoundingMode:
+ regs_.FlushBeforeCall();
+ ApplyRoundingMode();
+ break;
+
+ case IROp::UpdateRoundingMode:
+ UpdateRoundingMode();
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompLoadStore.cpp b/Core/MIPS/ARM/ArmIRCompLoadStore.cpp
new file mode 100644
index 0000000000..9f2dcabda7
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompLoadStore.cpp
@@ -0,0 +1,262 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Core/MemMap.h"
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+
+// This file contains compilation for memory loads and stores.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+// Puts the masked PSP address of src1 + constant in SCRATCH1, for use as an offset from
+// MEMBASEREG. Destroys SCRATCH2.
+void ArmJitBackend::PrepareSrc1Address(IRInst inst) {
+ if (inst.src1 == MIPS_REG_ZERO) {
+ MOVI2R(SCRATCH1, inst.constant & Memory::MEMVIEW32_MASK);
+ return;
+ }
+
+ ARMReg src1 = regs_.MapGPR(inst.src1);
+ if (inst.constant == 0) {
+ BIC(SCRATCH1, src1, Operand2(0xC0, 4));
+ } else {
+ ADDI2R(SCRATCH1, src1, inst.constant, SCRATCH2);
+ BIC(SCRATCH1, SCRATCH1, Operand2(0xC0, 4));
+ }
+}
+
+void ArmJitBackend::CompIR_CondStore(IRInst inst) {
+ CONDITIONAL_DISABLE;
+ if (inst.op != IROp::Store32Conditional)
+ INVALIDOP;
+
+ regs_.SpillLockGPR(IRREG_LLBIT, inst.src3, inst.src1);
+ PrepareSrc1Address(inst);
+ // The result goes in the same register (dest == src3), so it must be flushed.
+ ARMReg valueReg = regs_.MapGPR(inst.src3, inst.dest == MIPS_REG_ZERO ? MIPSMap::INIT : MIPSMap::DIRTY);
+ regs_.MapGPR(IRREG_LLBIT, MIPSMap::INIT);
+
+ CMP(regs_.R(IRREG_LLBIT), Operand2(0));
+ FixupBranch condFailed = B_CC(CC_EQ);
+ STR(valueReg, MEMBASEREG, SCRATCH1);
+
+ if (inst.dest != MIPS_REG_ZERO) {
+ MOVI2R(regs_.R(inst.dest), 1);
+ FixupBranch finish = B();
+
+ SetJumpTarget(condFailed);
+ MOVI2R(regs_.R(inst.dest), 0);
+ SetJumpTarget(finish);
+ } else {
+ SetJumpTarget(condFailed);
+ }
+}
+
+void ArmJitBackend::CompIR_FLoad(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::LoadFloat:
+ // VLDR has no register offset form.
+ PrepareSrc1Address(inst);
+ ADD(SCRATCH1, SCRATCH1, MEMBASEREG);
+ regs_.MapFPR(inst.dest, MIPSMap::NOINIT);
+ VLDR(regs_.F(inst.dest), SCRATCH1, 0);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_FStore(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::StoreFloat:
+ PrepareSrc1Address(inst);
+ ADD(SCRATCH1, SCRATCH1, MEMBASEREG);
+ regs_.MapFPR(inst.src3);
+ VSTR(regs_.F(inst.src3), SCRATCH1, 0);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Load(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ regs_.SpillLockGPR(inst.dest, inst.src1);
+ PrepareSrc1Address(inst);
+ // Only ll can load into $zero (for the llBit), and must not map it.
+ ARMReg dest = INVALID_REG;
+ if (inst.dest != MIPS_REG_ZERO)
+ dest = regs_.MapGPR(inst.dest, MIPSMap::NOINIT);
+
+ switch (inst.op) {
+ case IROp::Load8:
+ LDRB(dest, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Load8Ext:
+ LDRSB(dest, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Load16:
+ LDRH(dest, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Load16Ext:
+ LDRSH(dest, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Load32:
+ LDR(dest, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Load32Linked:
+ if (inst.dest != MIPS_REG_ZERO)
+ LDR(dest, MEMBASEREG, SCRATCH1);
+ regs_.SetGPRImm(IRREG_LLBIT, 1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_LoadShift(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Load32Left:
+ case IROp::Load32Right:
+ // Should not happen if the pass to split is active.
+ DISABLE;
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Store(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ regs_.SpillLockGPR(inst.src3, inst.src1);
+ PrepareSrc1Address(inst);
+
+ ARMReg valueReg = regs_.TryMapTempImm(inst.src3);
+ if (valueReg == INVALID_REG)
+ valueReg = regs_.MapGPR(inst.src3);
+
+ switch (inst.op) {
+ case IROp::Store8:
+ STRB(valueReg, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Store16:
+ STRH(valueReg, MEMBASEREG, SCRATCH1);
+ break;
+
+ case IROp::Store32:
+ STR(valueReg, MEMBASEREG, SCRATCH1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_StoreShift(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Store32Left:
+ case IROp::Store32Right:
+ // Should not happen if the pass to split is active.
+ DISABLE;
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_VecLoad(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::LoadVec4:
+ PrepareSrc1Address(inst);
+ ADD(SCRATCH1, SCRATCH1, MEMBASEREG);
+ // The lanes are in separate registers.
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ VLDR(regs_.F(inst.dest + i), SCRATCH1, i * 4);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_VecStore(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::StoreVec4:
+ PrepareSrc1Address(inst);
+ ADD(SCRATCH1, SCRATCH1, MEMBASEREG);
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ VSTR(regs_.F(inst.src3 + i), SCRATCH1, i * 4);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompSystem.cpp b/Core/MIPS/ARM/ArmIRCompSystem.cpp
new file mode 100644
index 0000000000..129632f7d8
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompSystem.cpp
@@ -0,0 +1,427 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Common/Profiler/Profiler.h"
+#include "Core/Core.h"
+#include "Core/Debugger/Breakpoints.h"
+#include "Core/HLE/HLE.h"
+#include "Core/HLE/ReplaceTables.h"
+#include "Core/MemMap.h"
+#include "Core/MIPS/MIPSAnalyst.h"
+#include "Core/MIPS/IR/IRInterpreter.h"
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+
+// This file contains compilation for basic PC/downcount accounting, syscalls, debug funcs, etc.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+void ArmJitBackend::CompIR_Basic(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Downcount:
+ SUBI2R(DOWNCOUNTREG, DOWNCOUNTREG, inst.constant, SCRATCH1);
+ break;
+
+ case IROp::SetConst:
+ regs_.SetGPRImm(inst.dest, inst.constant);
+ break;
+
+ case IROp::SetConstF:
+ {
+ regs_.Map(inst);
+ float f;
+ memcpy(&f, &inst.constant, sizeof(f));
+ MOVI2F(regs_.F(inst.dest), f, SCRATCH1);
+ break;
+ }
+
+ case IROp::SetPC:
+ regs_.Map(inst);
+ MovToPC(regs_.R(inst.src1));
+ break;
+
+ case IROp::SetPCConst:
+ lastConstPC_ = inst.constant;
+ MOVI2R(SCRATCH1, inst.constant);
+ MovToPC(SCRATCH1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Breakpoint(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Breakpoint:
+ FlushAll();
+ // Note: the constant could be a delay slot.
+ MOVI2R(R0, inst.constant);
+ QuickCallFunction(R12, &IRRunBreakpoint);
+ CMP(R0, Operand2(0));
+ B_CC(CC_NEQ, dispatcherCheckCoreState_);
+ break;
+
+ case IROp::MemoryCheck:
+ if (regs_.IsGPRImm(inst.src1)) {
+ uint32_t iaddr = regs_.GetGPRImm(inst.src1) + inst.constant;
+ uint32_t checkedPC = lastConstPC_ + inst.dest;
+ int size = MIPSAnalyst::OpMemoryAccessSize(checkedPC);
+ if (size == 0) {
+ checkedPC += 4;
+ size = MIPSAnalyst::OpMemoryAccessSize(checkedPC);
+ }
+ bool isWrite = MIPSAnalyst::IsOpMemoryWrite(checkedPC);
+
+ MemCheck check;
+ if (g_breakpoints.GetMemCheckInRange(iaddr, size, &check)) {
+ if (!(check.cond & MEMCHECK_READ) && !isWrite)
+ break;
+ if (!(check.cond & (MEMCHECK_WRITE | MEMCHECK_WRITE_ONCHANGE)) && isWrite)
+ break;
+
+ // We need to flush, or conditions and log expressions will see old register values.
+ FlushAll();
+
+ MOVI2R(R0, checkedPC);
+ MOVI2R(R1, iaddr);
+ QuickCallFunction(R12, &IRRunMemCheck);
+ CMP(R0, Operand2(0));
+ B_CC(CC_NEQ, dispatcherCheckCoreState_);
+ }
+ } else {
+ uint32_t checkedPC = lastConstPC_ + inst.dest;
+ int size = MIPSAnalyst::OpMemoryAccessSize(checkedPC);
+ if (size == 0) {
+ checkedPC += 4;
+ size = MIPSAnalyst::OpMemoryAccessSize(checkedPC);
+ }
+ bool isWrite = MIPSAnalyst::IsOpMemoryWrite(checkedPC);
+
+ const auto memchecks = g_breakpoints.GetMemCheckRanges(isWrite);
+ // We can trivially skip if there are no checks for this type (i.e. read vs write.)
+ if (memchecks.empty())
+ break;
+
+ // We need to flush, or conditions and log expressions will see old register values.
+ // The flush may use SCRATCH1, so read the address after it. R12 is free after it too.
+ FlushAll();
+ LDR(SCRATCH1, CTXREG, inst.src1 * 4);
+ ADDI2R(SCRATCH1, SCRATCH1, inst.constant, SCRATCH2);
+
+ std::vector hitChecks;
+ for (auto it : memchecks) {
+ if (it.end != 0) {
+ // A hit when start - size < addr < end, as an unsigned range check.
+ uint32_t lo = it.start - size + 1;
+ SUBI2R(R12, SCRATCH1, lo, SCRATCH2);
+ CMPI2R(R12, it.end - lo, SCRATCH2);
+ hitChecks.push_back(B_CC(CC_LO));
+ } else {
+ CMPI2R(SCRATCH1, it.start, SCRATCH2);
+ hitChecks.push_back(B_CC(CC_EQ));
+ }
+ }
+
+ FixupBranch noHits = B();
+
+ // Okay, now land any hit here.
+ for (auto &fixup : hitChecks)
+ SetJumpTarget(fixup);
+ hitChecks.clear();
+
+ MOV(R1, SCRATCH1);
+ MOVI2R(R0, checkedPC);
+ QuickCallFunction(R12, &IRRunMemCheck);
+ CMP(R0, Operand2(0));
+ B_CC(CC_NEQ, dispatcherCheckCoreState_);
+
+ SetJumpTarget(noHits);
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_System(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Syscall:
+ FlushAll();
+ SaveStaticRegisters();
+
+ WriteDebugProfilerStatus(IRProfilerStatus::SYSCALL);
+#ifdef USE_PROFILER
+ // When profiling, we can't skip CallSyscall, since it times syscalls.
+ MOVI2R(R0, inst.constant);
+ QuickCallFunction(R12, &CallSyscall);
+#else
+ // Skip the CallSyscall where possible.
+ {
+ MIPSOpcode op(inst.constant);
+ const HLEFunction *func = GetSyscallFunctionData(op, 0);
+ if (func) {
+ void *quickFunc = GetQuickSyscallFunc(func, op);
+ if (quickFunc) {
+ MOVP2R(R0, func);
+ QuickCallFunction(R12, (const u8 *)quickFunc);
+ } else {
+ MOVI2R(R0, inst.constant);
+ QuickCallFunction(R12, &CallSyscall);
+ }
+ } else {
+ // Shouldn't get here.
+ MOVI2R(R0, 0);
+ QuickCallFunction(R12, &CallSyscallUnresolvedAtPC);
+ }
+ }
+#endif
+
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ LoadStaticRegisters();
+ // This is always followed by an ExitToPC, where we check coreState.
+ break;
+
+ case IROp::SyscallUnresolved:
+ FlushAll();
+ SaveStaticRegisters();
+ WriteDebugProfilerStatus(IRProfilerStatus::SYSCALL);
+ MOVI2R(R0, inst.constant);
+ QuickCallFunction(R12, &CallSyscallUnresolvedAtPC);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ LoadStaticRegisters();
+ break;
+
+ case IROp::CallReplacement:
+ FlushAll();
+ SaveStaticRegisters();
+ WriteDebugProfilerStatus(IRProfilerStatus::REPLACEMENT);
+ QuickCallFunction(R12, GetReplacementFunc(inst.constant)->replaceFunc);
+ WriteDebugProfilerStatus(IRProfilerStatus::IN_JIT);
+ LoadStaticRegisters();
+
+ // Absolute value the result and subtract.
+ CMP(R0, Operand2(0));
+ SetCC(CC_MI);
+ RSB(SCRATCH2, R0, Operand2(0));
+ SetCC(CC_PL);
+ MOV(SCRATCH2, R0);
+ SetCC(CC_AL);
+ SUB(DOWNCOUNTREG, DOWNCOUNTREG, SCRATCH2);
+
+ // Everything was flushed, so this can't touch R0.
+ // Set dest reg to the sign of the result.
+ regs_.Map(inst);
+ ASR(regs_.R(inst.dest), R0, 31);
+ break;
+
+ case IROp::Break:
+ FlushAll();
+ // This doesn't naturally have restore/apply around it.
+ RestoreRoundingMode(true);
+ SaveStaticRegisters();
+ MovFromPC(R0);
+ QuickCallFunction(R12, &Core_BreakException);
+ LoadStaticRegisters();
+ ApplyRoundingMode(true);
+ MovFromPC(SCRATCH1);
+ ADDI2R(SCRATCH1, SCRATCH1, 4, SCRATCH2);
+ B(dispatcherPCInSCRATCH1_);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_Transfer(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::SetCtrlVFPU:
+ regs_.SetGPRImm(IRREG_VFPU_CTRL_BASE + inst.dest, inst.constant);
+ break;
+
+ case IROp::SetCtrlVFPUReg:
+ regs_.Map(inst);
+ MOV(regs_.R(IRREG_VFPU_CTRL_BASE + inst.dest), regs_.R(inst.src1));
+ break;
+
+ case IROp::SetCtrlVFPUFReg:
+ regs_.Map(inst);
+ VMOV(regs_.R(IRREG_VFPU_CTRL_BASE + inst.dest), regs_.F(inst.src1));
+ break;
+
+ case IROp::FpCondFromReg:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_FPCOND, 1, MIPSMap::NOINIT } });
+ MOV(regs_.R(IRREG_FPCOND), regs_.R(inst.src1));
+ break;
+
+ case IROp::FpCondToReg:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_FPCOND, 1, MIPSMap::INIT } });
+ MOV(regs_.R(inst.dest), regs_.R(IRREG_FPCOND));
+ break;
+
+ case IROp::FpCtrlFromReg:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_FPCOND, 1, MIPSMap::NOINIT } });
+ ANDI2R(SCRATCH1, regs_.R(inst.src1), 0x0181FFFF, SCRATCH2);
+ // Extract the new fpcond value.
+ UBFX(regs_.R(IRREG_FPCOND), SCRATCH1, 23, 1);
+ STR(SCRATCH1, CTXREG, IRREG_FCR31 * 4);
+ break;
+
+ case IROp::FpCtrlToReg:
+ regs_.MapWithExtra(inst, { { 'G', IRREG_FPCOND, 1, MIPSMap::INIT } });
+ // Load fcr31 and clear the fpcond bit.
+ LDR(regs_.R(inst.dest), CTXREG, IRREG_FCR31 * 4);
+ BFI(regs_.R(inst.dest), regs_.R(IRREG_FPCOND), 23, 1);
+ // Also update mips->fcr31 while we're here.
+ STR(regs_.R(inst.dest), CTXREG, IRREG_FCR31 * 4);
+ break;
+
+ case IROp::VfpuCtrlToReg:
+ regs_.Map(inst);
+ MOV(regs_.R(inst.dest), regs_.R(IRREG_VFPU_CTRL_BASE + inst.src1));
+ break;
+
+ case IROp::FMovFromGPR:
+ if (regs_.IsGPRImm(inst.src1) && regs_.GetGPRImm(inst.src1) == 0) {
+ regs_.MapFPR(inst.dest, MIPSMap::NOINIT);
+ MOVI2F(regs_.F(inst.dest), 0.0f, SCRATCH1);
+ } else {
+ regs_.Map(inst);
+ VMOV(regs_.F(inst.dest), regs_.R(inst.src1));
+ }
+ break;
+
+ case IROp::FMovToGPR:
+ regs_.Map(inst);
+ VMOV(regs_.R(inst.dest), regs_.F(inst.src1));
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_ValidateAddress(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ bool isWrite = inst.src2 & 1;
+ int alignment = 0;
+ switch (inst.op) {
+ case IROp::ValidateAddress8:
+ alignment = 1;
+ break;
+
+ case IROp::ValidateAddress16:
+ alignment = 2;
+ break;
+
+ case IROp::ValidateAddress32:
+ alignment = 4;
+ break;
+
+ case IROp::ValidateAddress128:
+ alignment = 16;
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+
+ regs_.Map(inst);
+ ADDI2R(SCRATCH1, regs_.R(inst.src1), inst.constant, SCRATCH2);
+ BIC(SCRATCH1, SCRATCH1, Operand2(0xC0, 4));
+
+ std::vector validJumps;
+
+ FixupBranch unaligned;
+ if (alignment != 1) {
+ TST(SCRATCH1, Operand2(alignment - 1));
+ unaligned = B_CC(CC_NEQ);
+ }
+
+ CMPI2R(SCRATCH1, PSP_GetUserMemoryEnd() - alignment, SCRATCH2);
+ FixupBranch tooHighRAM = B_CC(CC_HI);
+ CMPI2R(SCRATCH1, PSP_GetKernelMemoryBase(), SCRATCH2);
+ validJumps.push_back(B_CC(CC_HS));
+
+ CMPI2R(SCRATCH1, PSP_GetVidMemEnd() - alignment, SCRATCH2);
+ FixupBranch tooHighVid = B_CC(CC_HI);
+ CMPI2R(SCRATCH1, PSP_GetVidMemBase(), SCRATCH2);
+ validJumps.push_back(B_CC(CC_HS));
+
+ CMPI2R(SCRATCH1, PSP_GetScratchpadMemoryEnd() - alignment, SCRATCH2);
+ FixupBranch tooHighScratch = B_CC(CC_HI);
+ CMPI2R(SCRATCH1, PSP_GetScratchpadMemoryBase(), SCRATCH2);
+ validJumps.push_back(B_CC(CC_HS));
+
+ if (alignment != 1)
+ SetJumpTarget(unaligned);
+ SetJumpTarget(tooHighRAM);
+ SetJumpTarget(tooHighVid);
+ SetJumpTarget(tooHighScratch);
+
+ // If we got here, something unusual and bad happened, so we'll always go back to the dispatcher.
+ // Because of that, we can avoid flushing outside this case. The flush may use SCRATCH1, so the
+ // address waits on the stack (two regs, to keep it aligned for the call).
+ PUSH(2, SCRATCH1, SCRATCH2);
+ auto regsCopy = regs_;
+ regsCopy.FlushAll();
+ POP(2, SCRATCH1, SCRATCH2);
+
+ // Ignores the return value, always returns to the dispatcher.
+ // Otherwise would need a thunk to restore regs.
+ MOVI2R(R1, alignment);
+ MOVI2R(R2, isWrite ? 1 : 0);
+ QuickCallFunction(R12, &ReportBadAddress);
+ B(dispatcherCheckCoreState_);
+
+ for (FixupBranch &b : validJumps)
+ SetJumpTarget(b);
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRCompVec.cpp b/Core/MIPS/ARM/ArmIRCompVec.cpp
new file mode 100644
index 0000000000..b4436570ba
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRCompVec.cpp
@@ -0,0 +1,300 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include "Core/MIPS/ARM/ArmIRJit.h"
+#include "Core/MIPS/ARM/ArmIRRegCache.h"
+
+// This file contains compilation for Vec4 operations.
+//
+// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
+// Currently known non working ones should have DISABLE. No flags because that's in IR already.
+
+// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
+#define CONDITIONAL_DISABLE {}
+#define DISABLE { CompIR_Generic(inst); return; }
+#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
+
+namespace MIPSComp {
+
+using namespace ArmGen;
+using namespace ArmIRJitConstants;
+
+// Floats aren't mapped as SIMD, so each lane of a Vec4 is its own S register and these work lane
+// by lane. Vec4 regs are aligned to 4, so a dest and a source are either the same or disjoint,
+// but a scalar source can be one of the dest's lanes.
+
+void ArmJitBackend::CompIR_VecArith(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ auto lanes3 = [&](void (ARMXEmitter::*op)(ARMReg, ARMReg, ARMReg)) {
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ (this->*op)(regs_.F(inst.dest + i), regs_.F(inst.src1 + i), regs_.F(inst.src2 + i));
+ };
+ auto lanes2 = [&](void (ARMXEmitter::*op)(ARMReg, ARMReg)) {
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ (this->*op)(regs_.F(inst.dest + i), regs_.F(inst.src1 + i));
+ };
+
+ switch (inst.op) {
+ case IROp::Vec4Add:
+ lanes3(&ARMXEmitter::VADD);
+ break;
+
+ case IROp::Vec4Sub:
+ lanes3(&ARMXEmitter::VSUB);
+ break;
+
+ case IROp::Vec4Mul:
+ lanes3(&ARMXEmitter::VMUL);
+ break;
+
+ case IROp::Vec4Div:
+ lanes3(&ARMXEmitter::VDIV);
+ break;
+
+ case IROp::Vec4Scale:
+ regs_.Map(inst);
+ // The factor may be one of the dest lanes.
+ VMOV(SCRATCHF1, regs_.F(inst.src2));
+ for (int i = 0; i < 4; ++i)
+ VMUL(regs_.F(inst.dest + i), regs_.F(inst.src1 + i), SCRATCHF1);
+ break;
+
+ case IROp::Vec4Neg:
+ lanes2(&ARMXEmitter::VNEG);
+ break;
+
+ case IROp::Vec4Abs:
+ lanes2(&ARMXEmitter::VABS);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_VecAssign(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Vec4Init:
+ {
+ static const float values[7][4] = {
+ { 0.0f, 0.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 1.0f, 1.0f },
+ { -1.0f, -1.0f, -1.0f, -1.0f },
+ { 1.0f, 0.0f, 0.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f, 1.0f },
+ };
+ if (inst.src1 >= ARRAY_SIZE(values)) {
+ CompIR_Generic(inst);
+ break;
+ }
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ MOVI2F(regs_.F(inst.dest + i), values[inst.src1][i], SCRATCH1);
+ break;
+ }
+
+ case IROp::Vec4Shuffle:
+ regs_.Map(inst);
+ if (inst.dest == inst.src1) {
+ // Go through the scratch regs, since a lane may be read after it's written.
+ for (int i = 0; i < 4; ++i)
+ VMOV((ARMReg)(SCRATCHF1 + i), regs_.F(inst.src1 + ((inst.src2 >> (i * 2)) & 3)));
+ for (int i = 0; i < 4; ++i)
+ VMOV(regs_.F(inst.dest + i), (ARMReg)(SCRATCHF1 + i));
+ } else {
+ for (int i = 0; i < 4; ++i)
+ VMOV(regs_.F(inst.dest + i), regs_.F(inst.src1 + ((inst.src2 >> (i * 2)) & 3)));
+ }
+ break;
+
+ case IROp::Vec4Blend:
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i) {
+ IRReg src = ((inst.constant >> i) & 1) ? inst.src2 : inst.src1;
+ if (src != inst.dest)
+ VMOV(regs_.F(inst.dest + i), regs_.F(src + i));
+ }
+ break;
+
+ case IROp::Vec4Mov:
+ if (inst.dest != inst.src1) {
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ VMOV(regs_.F(inst.dest + i), regs_.F(inst.src1 + i));
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_VecHoriz(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ switch (inst.op) {
+ case IROp::Vec4Dot:
+ // In the IR interpreter's order, without fusing, into scratch since dest may be a source lane.
+ regs_.Map(inst);
+ VMUL(SCRATCHF1, regs_.F(inst.src1), regs_.F(inst.src2));
+ for (int i = 1; i < 4; ++i) {
+ VMUL(SCRATCHF2, regs_.F(inst.src1 + i), regs_.F(inst.src2 + i));
+ VADD(SCRATCHF1, SCRATCHF1, SCRATCHF2);
+ }
+ VMOV(regs_.F(inst.dest), SCRATCHF1);
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+void ArmJitBackend::CompIR_VecPack(IRInst inst) {
+ CONDITIONAL_DISABLE;
+
+ // These are bit manipulations, so they go through the integer registers. Every source is read
+ // before any dest lane is written.
+ switch (inst.op) {
+ case IROp::Vec2Unpack16To31:
+ case IROp::Vec2Unpack16To32:
+ {
+ regs_.Map(inst);
+ VMOV(SCRATCH1, regs_.F(inst.src1));
+ bool to31 = inst.op == IROp::Vec2Unpack16To31;
+ LSL(SCRATCH2, SCRATCH1, Operand2(16));
+ if (to31)
+ LSR(SCRATCH2, SCRATCH2, Operand2(1));
+ VMOV(regs_.F(inst.dest), SCRATCH2);
+ BIC(SCRATCH1, SCRATCH1, Operand2(0xFF, 0));
+ BIC(SCRATCH1, SCRATCH1, Operand2(0xFF, 12));
+ if (to31)
+ LSR(SCRATCH1, SCRATCH1, Operand2(1));
+ VMOV(regs_.F(inst.dest + 1), SCRATCH1);
+ break;
+ }
+
+ case IROp::Vec4Unpack8To32:
+ regs_.Map(inst);
+ VMOV(SCRATCH1, regs_.F(inst.src1));
+ for (int i = 0; i < 4; ++i) {
+ // Byte i goes to the top of lane i.
+ if (i < 3)
+ LSL(SCRATCH2, SCRATCH1, Operand2(24 - i * 8));
+ else
+ MOV(SCRATCH2, SCRATCH1);
+ if (i != 0)
+ AND(SCRATCH2, SCRATCH2, Operand2(0xFF, 4));
+ VMOV(regs_.F(inst.dest + i), SCRATCH2);
+ }
+ break;
+
+ case IROp::Vec2Pack32To16:
+ regs_.Map(inst);
+ VMOV(SCRATCH1, regs_.F(inst.src1));
+ VMOV(SCRATCH2, regs_.F(inst.src1 + 1));
+ LSR(SCRATCH1, SCRATCH1, Operand2(16));
+ // Keep the top half of the second.
+ BFI(SCRATCH2, SCRATCH1, 0, 16);
+ VMOV(regs_.F(inst.dest), SCRATCH2);
+ break;
+
+ case IROp::Vec2Pack31To16:
+ // Negative lanes clamp to zero.
+ regs_.Map(inst);
+ VMOV(SCRATCH1, regs_.F(inst.src1));
+ VMOV(SCRATCH2, regs_.F(inst.src1 + 1));
+ CMP(SCRATCH1, Operand2(0));
+ SetCC(CC_LT);
+ MOV(SCRATCH1, Operand2(0));
+ SetCC(CC_AL);
+ CMP(SCRATCH2, Operand2(0));
+ SetCC(CC_LT);
+ MOV(SCRATCH2, Operand2(0));
+ SetCC(CC_AL);
+ LSR(SCRATCH1, SCRATCH1, Operand2(15));
+ LSL(SCRATCH2, SCRATCH2, Operand2(1));
+ BFI(SCRATCH2, SCRATCH1, 0, 16);
+ VMOV(regs_.F(inst.dest), SCRATCH2);
+ break;
+
+ case IROp::Vec4Pack32To8:
+ case IROp::Vec4Pack31To8:
+ {
+ // The top byte of each lane (bits 30-23 for 31, with negative lanes as zero.)
+ bool from31 = inst.op == IROp::Vec4Pack31To8;
+ ARMReg temp = regs_.GetAndLockTempGPR();
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i) {
+ ARMReg target = i == 0 ? SCRATCH1 : SCRATCH2;
+ VMOV(target, regs_.F(inst.src1 + i));
+ if (from31) {
+ CMP(target, Operand2(0));
+ SetCC(CC_LT);
+ MOV(target, Operand2(0));
+ SetCC(CC_AL);
+ UBFX(target, target, 23, 8);
+ } else {
+ LSR(target, target, Operand2(24));
+ }
+ if (i != 0) {
+ // Accumulate into temp, then insert at the end.
+ if (i == 1)
+ MOV(temp, Operand2(target, ST_LSL, 8));
+ else
+ ORR(temp, temp, Operand2(target, ST_LSL, i * 8));
+ }
+ }
+ ORR(SCRATCH1, SCRATCH1, temp);
+ VMOV(regs_.F(inst.dest), SCRATCH1);
+ break;
+ }
+
+ case IROp::Vec4DuplicateUpperBitsAndShift1:
+ regs_.Map(inst);
+ for (int i = 0; i < 4; ++i)
+ VMOV((ARMReg)(SCRATCHF1 + i), regs_.F(inst.src1 + i));
+ for (int i = 0; i < 4; ++i) {
+ VMOV(SCRATCH1, (ARMReg)(SCRATCHF1 + i));
+ ORR(SCRATCH1, SCRATCH1, Operand2(SCRATCH1, ST_LSR, 8));
+ ORR(SCRATCH1, SCRATCH1, Operand2(SCRATCH1, ST_LSR, 16));
+ LSR(SCRATCH1, SCRATCH1, Operand2(1));
+ VMOV(regs_.F(inst.dest + i), SCRATCH1);
+ }
+ break;
+
+ default:
+ INVALIDOP;
+ break;
+ }
+}
+
+} // namespace MIPSComp
+
+#endif
diff --git a/Core/MIPS/ARM/ArmIRJit.cpp b/Core/MIPS/ARM/ArmIRJit.cpp
new file mode 100644
index 0000000000..605c39a180
--- /dev/null
+++ b/Core/MIPS/ARM/ArmIRJit.cpp
@@ -0,0 +1,375 @@
+// Copyright (c) 2012- PPSSPP Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0 or later versions.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// A copy of the GPL 2.0 should have been included with the program.
+// If not, see http://www.gnu.org/licenses/
+
+// Official git repository and contact information can be found at
+// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
+
+#include "ppsspp_config.h"
+#if PPSSPP_ARCH(ARM)
+
+#include
+#include
+#include