diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b7c3a2d73..cb370df423 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1091,7 +1091,6 @@ elseif(ARM64)
elseif(X86)
set(CoreExtra ${CoreExtra}
Core/MIPS/x86/Asm.cpp
- Core/MIPS/x86/Asm.h
Core/MIPS/x86/CompALU.cpp
Core/MIPS/x86/CompBranch.cpp
Core/MIPS/x86/CompFPU.cpp
diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj
index d84ff688e7..6358eb313a 100644
--- a/Core/Core.vcxproj
+++ b/Core/Core.vcxproj
@@ -679,7 +679,6 @@
true
true
-
diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters
index c004922624..0752ffdb08 100644
--- a/Core/Core.vcxproj.filters
+++ b/Core/Core.vcxproj.filters
@@ -666,9 +666,6 @@
MIPS\x86
-
- MIPS\x86
-
MIPS\x86
diff --git a/Core/MIPS/ARM/ArmAsm.cpp b/Core/MIPS/ARM/ArmAsm.cpp
index 24accc8cef..5d29ca771b 100644
--- a/Core/MIPS/ARM/ArmAsm.cpp
+++ b/Core/MIPS/ARM/ArmAsm.cpp
@@ -31,6 +31,7 @@ using namespace ArmGen;
//static int temp32; // unused?
static const bool enableDebug = false;
+static const bool disasm = false;
//static bool enableStatistics = false; //unused?
@@ -70,9 +71,82 @@ namespace MIPSComp {
using namespace ArmJitConstants;
-void ArmJit::GenerateFixedCode()
-{
- enterCode = AlignCode16();
+void ArmJit::GenerateFixedCode() {
+ const u8 *start = GetCodePtr();
+
+ // LR == SCRATCHREG2 on ARM32 so it needs to be pushed.
+ restoreRoundingMode = AlignCode16(); {
+ PUSH(1, R_LR);
+ VMRS(SCRATCHREG2);
+ // Assume we're always in round-to-nearest mode beforehand. Flush-to-zero is 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 only skip if the rounding mode is zero and flush is not set.
+ CMP(SCRATCHREG2, Operand2(3));
+
+ // At this point, if it was zero, we can skip the rest. (could even return)
+ 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);
+ }
+
+ // Must preserve SCRATCHREG1 (R0), destroys SCRATCHREG2 (LR)
+ updateRoundingMode = 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 only skip if the rounding mode is zero and flush is not set.
+ CMP(SCRATCHREG2, Operand2(3));
+
+ FixupBranch skip = B_CC(CC_EQ);
+ MOVI2R(SCRATCHREG2, 1);
+ MOVP2R(SCRATCHREG1, &js.hasSetRounding);
+ STRB(SCRATCHREG2, SCRATCHREG1, 0);
+ SetJumpTarget(skip);
+ POP(2, SCRATCHREG1, R_PC);
+ }
+
+ FlushLitPool();
+
+ enterDispatcher = AlignCode16();
DEBUG_LOG(JIT, "Base: %08x", (u32)Memory::base);
@@ -203,9 +277,11 @@ void ArmJit::GenerateFixedCode()
// Uncomment if you want to see the output...
- // INFO_LOG(JIT, "THE DISASM ========================");
- // DisassembleArm(enterCode, GetCodePtr() - enterCode);
- // INFO_LOG(JIT, "END OF THE DISASM ========================");
+ if (disasm) {
+ INFO_LOG(JIT, "THE DISASM ========================");
+ DisassembleArm(start, GetCodePtr() - start);
+ INFO_LOG(JIT, "END OF THE DISASM ========================");
+ }
// Don't forget to zap the instruction cache!
FlushLitPool();
diff --git a/Core/MIPS/ARM/ArmJit.cpp b/Core/MIPS/ARM/ArmJit.cpp
index d889479e1f..4401172402 100644
--- a/Core/MIPS/ARM/ArmJit.cpp
+++ b/Core/MIPS/ARM/ArmJit.cpp
@@ -234,7 +234,7 @@ void ArmJit::Compile(u32 em_address) {
void ArmJit::RunLoopUntil(u64 globalticks) {
PROFILE_THIS_SCOPE("jit");
- ((void (*)())enterCode)();
+ ((void (*)())enterDispatcher)();
}
u32 ArmJit::GetCompilerPC() {
@@ -387,7 +387,7 @@ void ArmJit::AddContinuedBlock(u32 dest)
bool ArmJit::DescribeCodePtr(const u8 *ptr, std::string &name)
{
- // TODO: Not used by anything yet.
+ // TODO: Not used by anything yet (except the modified VerySleepy on Windows)
return false;
}
@@ -585,77 +585,25 @@ void ArmJit::WriteDownCountR(ARMReg reg) {
}
}
+// Destroys SCRATCHREG2. Does not destroy SCRATCHREG1.
void ArmJit::RestoreRoundingMode(bool force) {
// If the game has never set an interesting rounding mode, we can safely skip this.
if (force || js.hasSetRounding) {
- VMRS(SCRATCHREG2);
- // Assume we're always in round-to-nearest mode beforehand. Flush-to-zero is off.
- BIC(SCRATCHREG2, SCRATCHREG2, AssumeMakeOperand2((3 | 4) << 22));
- VMSR(SCRATCHREG2);
+ QuickCallFunction(R1, restoreRoundingMode);
}
}
+// Does not destroy R0 (SCRATCHREG1). Destroys R14 (SCRATCHREG2).
void ArmJit::ApplyRoundingMode(bool force) {
- // NOTE: Must not destroy R0.
// If the game has never set an interesting rounding mode, we can safely skip this.
if (force || js.hasSetRounding) {
- 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 only skip if the rounding mode is zero and flush is not set.
- CMP(SCRATCHREG2, Operand2(3));
-
- // At this point, if it was zero, we can skip the rest.
- FixupBranch skip = B_CC(CC_EQ);
- PUSH(1, SCRATCHREG1);
-
- // 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);
-
- POP(1, SCRATCHREG1);
- SetJumpTarget(skip);
+ QuickCallFunction(R1, applyRoundingMode);
}
}
+// Does (must!) not destroy R0 (SCRATCHREG1). Destroys R14 (SCRATCHREG2).
void ArmJit::UpdateRoundingMode() {
- // NOTE: Must not destroy R0.
- 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 only skip if the rounding mode is zero and flush is not set.
- CMP(SCRATCHREG2, Operand2(3));
-
- FixupBranch skip = B_CC(CC_EQ);
- PUSH(1, SCRATCHREG1);
- MOVI2R(SCRATCHREG2, 1);
- MOVP2R(SCRATCHREG1, &js.hasSetRounding);
- STRB(SCRATCHREG2, SCRATCHREG1, 0);
- POP(1, SCRATCHREG1);
- SetJumpTarget(skip);
+ QuickCallFunction(R1, updateRoundingMode);
}
// IDEA - could have a WriteDualExit that takes two destinations and two condition flags,
diff --git a/Core/MIPS/ARM/ArmJit.h b/Core/MIPS/ARM/ArmJit.h
index baf6ca587a..26859c86ab 100644
--- a/Core/MIPS/ARM/ArmJit.h
+++ b/Core/MIPS/ARM/ArmJit.h
@@ -287,7 +287,7 @@ private:
public:
// Code pointers
- const u8 *enterCode;
+ const u8 *enterDispatcher;
const u8 *outerLoop;
const u8 *outerLoopPCInR0;
@@ -296,6 +296,10 @@ public:
const u8 *dispatcher;
const u8 *dispatcherNoCheck;
+ const u8 *restoreRoundingMode;
+ const u8 *applyRoundingMode;
+ const u8 *updateRoundingMode;
+
const u8 *breakpointBailout;
};
diff --git a/Core/MIPS/ARM64/Arm64Asm.cpp b/Core/MIPS/ARM64/Arm64Asm.cpp
index ba59e64fb5..8eb5d8e50a 100644
--- a/Core/MIPS/ARM64/Arm64Asm.cpp
+++ b/Core/MIPS/ARM64/Arm64Asm.cpp
@@ -94,7 +94,7 @@ namespace MIPSComp {
using namespace Arm64JitConstants;
void Arm64Jit::GenerateFixedCode(const JitOptions &jo) {
- const u8 *start = nullptr;
+ const u8 *start = AlignCode16();
if (jo.useStaticAlloc) {
saveStaticRegisters = AlignCode16();
STR(INDEX_UNSIGNED, DOWNCOUNTREG, CTXREG, offsetof(MIPSState, downcount));
@@ -112,9 +112,84 @@ void Arm64Jit::GenerateFixedCode(const JitOptions &jo) {
loadStaticRegisters = nullptr;
}
- enterCode = AlignCode16();
- if (!start)
- start = enterCode;
+ restoreRoundingMode = AlignCode16(); {
+ MRS(SCRATCH2_64, FIELD_FPCR);
+ // We are not in flush-to-zero mode outside the JIT, so let's turn it off.
+ uint32_t mask = ~(4 << 22);
+ // Assume we're always in round-to-nearest mode beforehand.
+ mask &= ~(3 << 22);
+ ANDI2R(SCRATCH2, SCRATCH2, mask);
+ _MSR(FIELD_FPCR, SCRATCH2_64);
+ RET();
+ }
+
+ applyRoundingMode = AlignCode16(); {
+ LDR(INDEX_UNSIGNED, SCRATCH2, CTXREG, offsetof(MIPSState, fcr31));
+ TSTI2R(SCRATCH2, 1 << 24);
+ ANDI2R(SCRATCH2, SCRATCH2, 3);
+ FixupBranch skip1 = B(CC_EQ);
+ ADDI2R(SCRATCH2, SCRATCH2, 4);
+ SetJumpTarget(skip1);
+ // We can only skip if the rounding mode is zero and flush is set.
+ CMPI2R(SCRATCH2, 4);
+ // At this point, if it was zero, we can skip the rest.
+ FixupBranch skip = B(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
+ ANDI2R(SCRATCH1, SCRATCH2, 3);
+ CMPI2R(SCRATCH1, 1);
+
+ FixupBranch skipadd = B(CC_NEQ);
+ ADDI2R(SCRATCH2, SCRATCH2, 2);
+ SetJumpTarget(skipadd);
+ FixupBranch skipsub = B(CC_LE);
+ SUBI2R(SCRATCH2, SCRATCH2, 1);
+ SetJumpTarget(skipsub);
+
+ MRS(SCRATCH1_64, FIELD_FPCR);
+
+ // Clear both flush-to-zero and rounding before re-setting them.
+ ANDI2R(SCRATCH1, SCRATCH1, ~((4 | 3) << 22));
+
+ ORR(SCRATCH1, SCRATCH1, SCRATCH2, ArithOption(SCRATCH2, ST_LSL, 22));
+ _MSR(FIELD_FPCR, SCRATCH1_64);
+
+ // Let's update js.currentRoundingFunc with the right convertS0ToSCRATCH1 func.
+ MOVP2R(SCRATCH1_64, convertS0ToSCRATCH1);
+ // We already index this array including the FZ bit. Easy.
+ LSL(SCRATCH2, SCRATCH2, 3);
+ LDR(SCRATCH2_64, SCRATCH1_64, SCRATCH2);
+ MOVP2R(SCRATCH1_64, &js.currentRoundingFunc);
+ STR(INDEX_UNSIGNED, SCRATCH2_64, SCRATCH1_64, 0);
+
+ SetJumpTarget(skip);
+ RET();
+ }
+
+ updateRoundingMode = AlignCode16(); {
+ LDR(INDEX_UNSIGNED, SCRATCH2, CTXREG, offsetof(MIPSState, fcr31));
+
+ TSTI2R(SCRATCH2, 1 << 24);
+ ANDI2R(SCRATCH2, SCRATCH2, 3);
+ FixupBranch skip = B(CC_EQ);
+ ADDI2R(SCRATCH2, SCRATCH2, 4);
+ SetJumpTarget(skip);
+
+ // We can only skip if the rounding mode is zero and flush is not set.
+ CMPI2R(SCRATCH2, 3);
+
+ FixupBranch skip2 = B(CC_EQ);
+ MOVI2R(SCRATCH2, 1);
+ MOVP2R(SCRATCH1_64, &js.hasSetRounding);
+ STRB(INDEX_UNSIGNED, SCRATCH2, SCRATCH1_64, 0);
+ SetJumpTarget(skip2);
+ }
+
+ enterDispatcher = AlignCode16();
BitSet32 regs_to_save(Arm64Gen::ALL_CALLEE_SAVED);
BitSet32 regs_to_save_fp(Arm64Gen::ALL_CALLEE_SAVED_FP);
@@ -176,7 +251,7 @@ void Arm64Jit::GenerateFixedCode(const JitOptions &jo) {
LDR(INDEX_UNSIGNED, SCRATCH1, CTXREG, offsetof(MIPSState, pc));
LDR(SCRATCH1, MEMBASEREG, SCRATCH1_64);
- LSR(SCRATCH2, SCRATCH1, 24);
+ LSR(SCRATCH2, SCRATCH1, 24); // or UBFX(SCRATCH2, SCRATCH1, 24, 8)
ANDI2R(SCRATCH1, SCRATCH1, 0x00FFFFFF);
CMP(SCRATCH2, MIPS_EMUHACK_OPCODE >> 24);
FixupBranch skipJump = B(CC_NEQ);
diff --git a/Core/MIPS/ARM64/Arm64Jit.cpp b/Core/MIPS/ARM64/Arm64Jit.cpp
index 96b4b51807..a8770bba29 100644
--- a/Core/MIPS/ARM64/Arm64Jit.cpp
+++ b/Core/MIPS/ARM64/Arm64Jit.cpp
@@ -220,7 +220,7 @@ void Arm64Jit::Compile(u32 em_address) {
void Arm64Jit::RunLoopUntil(u64 globalticks) {
PROFILE_THIS_SCOPE("jit");
- ((void (*)())enterCode)();
+ ((void (*)())enterDispatcher)();
}
u32 Arm64Jit::GetCompilerPC() {
@@ -350,7 +350,7 @@ void Arm64Jit::AddContinuedBlock(u32 dest) {
}
bool Arm64Jit::DescribeCodePtr(const u8 *ptr, std::string &name) {
- // TODO: Not used by anything yet.
+ // TODO: Not used by anything yet (except the modified VerySleepy on Windows)
return false;
}
@@ -528,13 +528,7 @@ void Arm64Jit::WriteDownCountR(ARM64Reg reg, bool updateFlags) {
void Arm64Jit::RestoreRoundingMode(bool force) {
// If the game has never set an interesting rounding mode, we can safely skip this.
if (force || js.hasSetRounding) {
- MRS(SCRATCH2_64, FIELD_FPCR);
- // We are not in flush-to-zero mode outside the JIT, so let's turn it off.
- uint32_t mask = ~(4 << 22);
- // Assume we're always in round-to-nearest mode beforehand.
- mask &= ~(3 << 22);
- ANDI2R(SCRATCH2, SCRATCH2, mask);
- _MSR(FIELD_FPCR, SCRATCH2_64);
+ QuickCallFunction(SCRATCH2_64, restoreRoundingMode);
}
}
@@ -542,70 +536,13 @@ void Arm64Jit::RestoreRoundingMode(bool force) {
void Arm64Jit::ApplyRoundingMode(bool force) {
// If the game has never set an interesting rounding mode, we can safely skip this.
if (force || js.hasSetRounding) {
- LDR(INDEX_UNSIGNED, SCRATCH2, CTXREG, offsetof(MIPSState, fcr31));
- TSTI2R(SCRATCH2, 1 << 24);
- ANDI2R(SCRATCH2, SCRATCH2, 3);
- FixupBranch skip1 = B(CC_EQ);
- ADDI2R(SCRATCH2, SCRATCH2, 4);
- SetJumpTarget(skip1);
- // We can only skip if the rounding mode is zero and flush is set.
- CMPI2R(SCRATCH2, 4);
- // At this point, if it was zero, we can skip the rest.
- FixupBranch skip = B(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
- ANDI2R(SCRATCH1, SCRATCH2, 3);
- CMPI2R(SCRATCH1, 1);
-
- FixupBranch skipadd = B(CC_NEQ);
- ADDI2R(SCRATCH2, SCRATCH2, 2);
- SetJumpTarget(skipadd);
- FixupBranch skipsub = B(CC_LE);
- SUBI2R(SCRATCH2, SCRATCH2, 1);
- SetJumpTarget(skipsub);
-
- MRS(SCRATCH1_64, FIELD_FPCR);
-
- // Clear both flush-to-zero and rounding before re-setting them.
- ANDI2R(SCRATCH1, SCRATCH1, ~((4 | 3) << 22));
-
- ORR(SCRATCH1, SCRATCH1, SCRATCH2, ArithOption(SCRATCH2, ST_LSL, 22));
- _MSR(FIELD_FPCR, SCRATCH1_64);
-
- // Let's update js.currentRoundingFunc with the right convertS0ToSCRATCH1 func.
- MOVP2R(SCRATCH1_64, convertS0ToSCRATCH1);
- // We already index this array including the FZ bit. Easy.
- LSL(SCRATCH2, SCRATCH2, 3);
- LDR(SCRATCH2_64, SCRATCH1_64, SCRATCH2);
- MOVP2R(SCRATCH1_64, &js.currentRoundingFunc);
- STR(INDEX_UNSIGNED, SCRATCH2_64, SCRATCH1_64, 0);
-
- SetJumpTarget(skip);
+ QuickCallFunction(SCRATCH2_64, applyRoundingMode);
}
}
// Destroys SCRATCH1 and SCRATCH2
void Arm64Jit::UpdateRoundingMode() {
- LDR(INDEX_UNSIGNED, SCRATCH2, CTXREG, offsetof(MIPSState, fcr31));
-
- TSTI2R(SCRATCH2, 1 << 24);
- ANDI2R(SCRATCH2, SCRATCH2, 3);
- FixupBranch skip = B(CC_EQ);
- ADDI2R(SCRATCH2, SCRATCH2, 4);
- SetJumpTarget(skip);
-
- // We can only skip if the rounding mode is zero and flush is not set.
- CMPI2R(SCRATCH2, 3);
-
- FixupBranch skip2 = B(CC_EQ);
- MOVI2R(SCRATCH2, 1);
- MOVP2R(SCRATCH1_64, &js.hasSetRounding);
- STRB(INDEX_UNSIGNED, SCRATCH2, SCRATCH1_64, 0);
- SetJumpTarget(skip2);
+ QuickCallFunction(SCRATCH2_64, updateRoundingMode);
}
// IDEA - could have a WriteDualExit that takes two destinations and two condition flags,
diff --git a/Core/MIPS/ARM64/Arm64Jit.h b/Core/MIPS/ARM64/Arm64Jit.h
index 0cbecc743c..2877024338 100644
--- a/Core/MIPS/ARM64/Arm64Jit.h
+++ b/Core/MIPS/ARM64/Arm64Jit.h
@@ -251,7 +251,7 @@ private:
public:
// Code pointers
- const u8 *enterCode;
+ const u8 *enterDispatcher;
const u8 *outerLoop;
const u8 *outerLoopPCInSCRATCH1;
@@ -265,6 +265,10 @@ public:
const u8 *saveStaticRegisters;
const u8 *loadStaticRegisters;
+ const u8 *restoreRoundingMode;
+ const u8 *applyRoundingMode;
+ const u8 *updateRoundingMode;
+
// Indexed by FPCR FZ:RN bits for convenience. Uses SCRATCH2.
const u8 *convertS0ToSCRATCH1[8];
};
diff --git a/Core/MIPS/JitCommon/JitBlockCache.cpp b/Core/MIPS/JitCommon/JitBlockCache.cpp
index 2e49d4834b..9fa6ceb040 100644
--- a/Core/MIPS/JitCommon/JitBlockCache.cpp
+++ b/Core/MIPS/JitCommon/JitBlockCache.cpp
@@ -46,7 +46,6 @@
#if defined(_M_IX86) || defined(_M_X64)
#include "Common/x64Analyzer.h"
-#include "Core/MIPS/x86/Asm.h"
#endif
// #include "JitBase.h"
@@ -593,7 +592,7 @@ void JitBlockCache::DestroyBlock(int block_num, bool invalidate) {
// Spurious entrances from previously linked blocks can only come through checkedEntry
XEmitter emit((u8 *)b->checkedEntry);
emit.MOV(32, M(&mips_->pc), Imm32(b->originalAddress));
- emit.JMP(MIPSComp::jit->Asm().dispatcher, true);
+ emit.JMP(MIPSComp::jit->GetDispatcher(), true);
#elif defined(ARM64)
diff --git a/Core/MIPS/JitCommon/JitCommon.cpp b/Core/MIPS/JitCommon/JitCommon.cpp
index d96a69ce65..0591f5b286 100644
--- a/Core/MIPS/JitCommon/JitCommon.cpp
+++ b/Core/MIPS/JitCommon/JitCommon.cpp
@@ -154,15 +154,12 @@ const char *ppsspp_resolver(struct ud*,
*offset = addr - (uint64_t)(¤tMIPS->v[0]);
return "mips.v";
}
+
// But these do.
if (MIPSComp::jit->IsInSpace((u8 *)(intptr_t)addr)) {
*offset = addr - (uint64_t)MIPSComp::jit->GetBasePtr();
return "jitcode";
}
- if (MIPSComp::jit->Asm().IsInSpace((u8 *)(intptr_t)addr)) {
- *offset = addr - (uint64_t)MIPSComp::jit->Asm().GetBasePtr();
- return "dispatcher";
- }
return NULL;
}
diff --git a/Core/MIPS/x86/Asm.cpp b/Core/MIPS/x86/Asm.cpp
index 8bdc2915a3..a261e2be5c 100644
--- a/Core/MIPS/x86/Asm.cpp
+++ b/Core/MIPS/x86/Asm.cpp
@@ -28,15 +28,20 @@
#include "Common/MemoryUtil.h"
#include "Core/MIPS/JitCommon/JitCommon.h"
-#include "Core/MIPS/x86/Asm.h"
#include "Core/MIPS/x86/Jit.h"
using namespace Gen;
using namespace X64JitConstants;
+extern volatile CoreState coreState;
+
+namespace MIPSComp
+{
+
//TODO - make an option
//#if _DEBUG
static bool enableDebug = false;
+
//#else
// bool enableDebug = false;
//#endif
@@ -53,34 +58,87 @@ static bool enableDebug = false;
//R14 - Pointer to fpr/gpr regs
//R15 - Pointer to array of block pointers
-extern volatile CoreState coreState;
-
-void ImHere()
-{
+void ImHere() {
DEBUG_LOG(CPU, "JIT Here: %08x", currentMIPS->pc);
}
-void AsmRoutineManager::Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::JitOptions *jo)
-{
- enterCode = AlignCode16();
+void Jit::GenerateFixedCode(JitOptions &jo) {
+ const u8 *start = AlignCode16();
+
+ restoreRoundingMode = AlignCode16(); {
+ STMXCSR(M(&mips_->temp));
+ // Clear the rounding mode and flush-to-zero bits back to 0.
+ AND(32, M(&mips_->temp), Imm32(~(7 << 13)));
+ LDMXCSR(M(&mips_->temp));
+ RET();
+ }
+
+ applyRoundingMode = AlignCode16(); {
+ MOV(32, R(EAX), M(&mips_->fcr31));
+ AND(32, R(EAX), Imm32(0x1000003));
+
+ // If it's 0, we don't actually bother setting. This is the most common.
+ // We always use nearest as the default rounding mode with
+ // flush-to-zero disabled.
+ FixupBranch skip = J_CC(CC_Z);
+
+ STMXCSR(M(&mips_->temp));
+
+ // The MIPS bits don't correspond exactly, so we have to adjust.
+ // 0 -> 0 (skip2), 1 -> 3, 2 -> 2 (skip2), 3 -> 1
+ TEST(8, R(AL), Imm8(1));
+ FixupBranch skip2 = J_CC(CC_Z);
+ XOR(32, R(EAX), Imm8(2));
+ SetJumpTarget(skip2);
+
+ SHL(32, R(EAX), Imm8(13));
+ OR(32, M(&mips_->temp), R(EAX));
+
+ TEST(32, M(&mips_->fcr31), Imm32(1 << 24));
+ FixupBranch skip3 = J_CC(CC_Z);
+ OR(32, M(&mips_->temp), Imm32(1 << 15));
+ SetJumpTarget(skip3);
+
+ LDMXCSR(M(&mips_->temp));
+ SetJumpTarget(skip);
+ RET();
+ }
+
+ updateRoundingMode = AlignCode16(); {
+ // If it's only ever 0, we don't actually bother applying or restoring it.
+ // This is the most common situation.
+ TEST(32, M(&mips_->fcr31), Imm32(0x01000003));
+ FixupBranch skip = J_CC(CC_Z);
+#ifdef _M_X64
+ // TODO: Move the hasSetRounding flag somewhere we can reach it through the context pointer, or something.
+ MOV(64, R(RAX), Imm64((uintptr_t)&js.hasSetRounding));
+ MOV(8, MatR(RAX), Imm8(1));
+#else
+ MOV(8, M(&js.hasSetRounding), Imm8(1));
+#endif
+ SetJumpTarget(skip);
+
+ RET();
+ }
+
+ enterDispatcher = AlignCode16();
ABI_PushAllCalleeSavedRegsAndAdjustStack();
#ifdef _M_X64
// Two statically allocated registers.
MOV(64, R(MEMBASEREG), ImmPtr(Memory::base));
- uintptr_t jitbase = (uintptr_t)jit->GetBasePtr();
- if (jitbase > 0x7FFFFFFFULL)
- {
- MOV(64, R(JITBASEREG), ImmPtr(jit->GetBasePtr()));
- jo->reserveR15ForAsm = true;
+ uintptr_t jitbase = (uintptr_t)GetBasePtr();
+ if (jitbase > 0x7FFFFFFFULL) {
+ MOV(64, R(JITBASEREG), ImmPtr(GetBasePtr()));
+ jo.reserveR15ForAsm = true;
}
#endif
// From the start of the FP reg, a single byte offset can reach all GPR + all FPR (but no VFPUR)
- MOV(PTRBITS, R(CTXREG), ImmPtr(&mips->f[0]));
+ MOV(PTRBITS, R(CTXREG), ImmPtr(&mips_->f[0]));
outerLoop = GetCodePtr();
- jit->RestoreRoundingMode(true, this);
+ RestoreRoundingMode(true);
ABI_CallFunction(reinterpret_cast(&CoreTiming::Advance));
- jit->ApplyRoundingMode(true, this);
+ ApplyRoundingMode(true);
FixupBranch skipToRealDispatch = J(); //skip the sync and compare first time
dispatcherCheckCoreState = GetCodePtr();
@@ -104,7 +162,7 @@ void AsmRoutineManager::Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::
dispatcherNoCheck = GetCodePtr();
- MOV(32, R(EAX), M(&mips->pc));
+ MOV(32, R(EAX), M(&mips_->pc));
dispatcherInEAXNoCheck = GetCodePtr();
#ifdef _M_IX86
@@ -121,14 +179,14 @@ void AsmRoutineManager::Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::
FixupBranch notfound = J_CC(CC_NE);
if (enableDebug)
{
- ADD(32, M(&mips->debugCount), Imm8(1));
+ ADD(32, M(&mips_->debugCount), Imm8(1));
}
//grab from list and jump to it
AND(32, R(EAX), Imm32(MIPS_EMUHACK_VALUE_MASK));
#ifdef _M_IX86
- ADD(32, R(EAX), ImmPtr(jit->GetBasePtr()));
+ ADD(32, R(EAX), ImmPtr(GetBasePtr()));
#elif _M_X64
- if (jo->reserveR15ForAsm)
+ if (jo.reserveR15ForAsm)
ADD(64, R(RAX), R(JITBASEREG));
else
ADD(64, R(EAX), Imm32(jitbase));
@@ -137,9 +195,9 @@ void AsmRoutineManager::Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::
SetJumpTarget(notfound);
//Ok, no block, let's jit
- jit->RestoreRoundingMode(true, this);
+ RestoreRoundingMode(true);
ABI_CallFunction(&MIPSComp::JitAt);
- jit->ApplyRoundingMode(true, this);
+ ApplyRoundingMode(true);
JMP(dispatcherNoCheck, true); // Let's just dispatch again, we'll enter the block since we know it's there.
SetJumpTarget(bail);
@@ -149,12 +207,16 @@ void AsmRoutineManager::Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::
J_CC(CC_Z, outerLoop, true);
SetJumpTarget(badCoreState);
- jit->RestoreRoundingMode(true, this);
+ RestoreRoundingMode(true);
ABI_PopAllCalleeSavedRegsAndAdjustStack();
RET();
breakpointBailout = GetCodePtr();
- jit->RestoreRoundingMode(true, this);
+ RestoreRoundingMode(true);
ABI_PopAllCalleeSavedRegsAndAdjustStack();
RET();
+
+ endOfPregeneratedCode = GetCodePtr();
}
+
+} // namespace
\ No newline at end of file
diff --git a/Core/MIPS/x86/Asm.h b/Core/MIPS/x86/Asm.h
deleted file mode 100644
index 4b9bb77354..0000000000
--- a/Core/MIPS/x86/Asm.h
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright (C) 2003 Dolphin 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 SVN repository and contact information can be found at
-// http://code.google.com/p/dolphin-emu/
-
-#pragma once
-
-#include "Common/x64Emitter.h"
-#include "Core/MIPS/MIPS.h"
-
-// Runtime generated assembly routines, like the Dispatcher.
-
-namespace MIPSComp {
- class Jit;
- struct JitOptions;
-}
-
-class AsmRoutineManager : public Gen::XCodeBlock {
-private:
- void Generate(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::JitOptions *jo);
-
-public:
- void Init(MIPSState *mips, MIPSComp::Jit *jit, MIPSComp::JitOptions *jo) {
- AllocCodeSpace(8192);
- Generate(mips, jit, jo);
- WriteProtect();
- }
-
- const u8 *enterCode;
-
- const u8 *outerLoop;
- const u8 *dispatcher;
- const u8 *dispatcherCheckCoreState;
- const u8 *dispatcherNoCheck;
- const u8 *dispatcherInEAXNoCheck;
-
- const u8 *breakpointBailout;
-};
diff --git a/Core/MIPS/x86/Jit.cpp b/Core/MIPS/x86/Jit.cpp
index c1a0a4ef01..88bcfff1a2 100644
--- a/Core/MIPS/x86/Jit.cpp
+++ b/Core/MIPS/x86/Jit.cpp
@@ -119,13 +119,13 @@ static void JitLogMiss(MIPSOpcode op)
// JitBlockCache doesn't use this, just stores it.
#pragma warning(disable:4355)
#endif
-Jit::Jit(MIPSState *mips) : blocks(mips, this), mips_(mips)
-{
+Jit::Jit(MIPSState *mips)
+ : blocks(mips, this), mips_(mips) {
blocks.Init();
gpr.SetEmitter(this);
fpr.SetEmitter(this);
AllocCodeSpace(1024 * 1024 * 16);
- asm_.Init(mips, this, &jo);
+ GenerateFixedCode(jo);
safeMemFuncs.Init(&thunks);
js.startDefaultPrefix = mips_->HasDefaultPrefix();
@@ -220,80 +220,29 @@ void Jit::WriteDowncount(int offset)
SUB(32, M(&mips_->downcount), downcount > 127 ? Imm32(downcount) : Imm8(downcount));
}
-void Jit::RestoreRoundingMode(bool force, XEmitter *emitter)
-{
+void Jit::RestoreRoundingMode(bool force) {
// If the game has never set an interesting rounding mode, we can safely skip this.
- if (force || js.hasSetRounding)
- {
- if (emitter == NULL)
- emitter = this;
- emitter->STMXCSR(M(&mips_->temp));
- // Clear the rounding mode and flush-to-zero bits back to 0.
- emitter->AND(32, M(&mips_->temp), Imm32(~(7 << 13)));
- emitter->LDMXCSR(M(&mips_->temp));
+ if (force || js.hasSetRounding) {
+ CALL(restoreRoundingMode);
}
}
-void Jit::ApplyRoundingMode(bool force, XEmitter *emitter)
-{
+void Jit::ApplyRoundingMode(bool force) {
// If the game has never set an interesting rounding mode, we can safely skip this.
- if (force || js.hasSetRounding)
- {
- if (emitter == NULL)
- emitter = this;
- emitter->MOV(32, R(EAX), M(&mips_->fcr31));
- emitter->AND(32, R(EAX), Imm32(0x1000003));
-
- // If it's 0, we don't actually bother setting. This is the most common.
- // We always use nearest as the default rounding mode with
- // flush-to-zero disabled.
- FixupBranch skip = emitter->J_CC(CC_Z);
-
- emitter->STMXCSR(M(&mips_->temp));
-
- // The MIPS bits don't correspond exactly, so we have to adjust.
- // 0 -> 0 (skip2), 1 -> 3, 2 -> 2 (skip2), 3 -> 1
- emitter->TEST(8, R(AL), Imm8(1));
- FixupBranch skip2 = emitter->J_CC(CC_Z);
- emitter->XOR(32, R(EAX), Imm8(2));
- emitter->SetJumpTarget(skip2);
-
- emitter->SHL(32, R(EAX), Imm8(13));
- emitter->OR(32, M(&mips_->temp), R(EAX));
-
- emitter->TEST(32, M(&mips_->fcr31), Imm32(1 << 24));
- FixupBranch skip3 = emitter->J_CC(CC_Z);
- emitter->OR(32, M(&mips_->temp), Imm32(1 << 15));
- emitter->SetJumpTarget(skip3);
-
- emitter->LDMXCSR(M(&mips_->temp));
- emitter->SetJumpTarget(skip);
+ if (force || js.hasSetRounding) {
+ CALL(applyRoundingMode);
}
}
-void Jit::UpdateRoundingMode(XEmitter *emitter)
-{
- if (emitter == NULL)
- emitter = this;
-
- // If it's only ever 0, we don't actually bother applying or restoring it.
- // This is the most common situation.
- emitter->TEST(32, M(&mips_->fcr31), Imm32(0x01000003));
- FixupBranch skip = emitter->J_CC(CC_Z);
-#ifdef _M_X64
- // TODO: Move the hasSetRounding flag somewhere we can reach it through the context pointer, or something.
- emitter->MOV(64, R(RAX), Imm64((uintptr_t)&js.hasSetRounding));
- emitter->MOV(8, MatR(RAX), Imm8(1));
-#else
- emitter->MOV(8, M(&js.hasSetRounding), Imm8(1));
-#endif
- emitter->SetJumpTarget(skip);
+void Jit::UpdateRoundingMode() {
+ CALL(updateRoundingMode);
}
void Jit::ClearCache()
{
blocks.Clear();
ClearCodeSpace();
+ GenerateFixedCode(jo);
}
void Jit::InvalidateCache()
@@ -383,7 +332,7 @@ void Jit::Compile(u32 em_address)
void Jit::RunLoopUntil(u64 globalticks)
{
PROFILE_THIS_SCOPE("jit");
- ((void (*)())asm_.enterCode)();
+ ((void (*)())enterDispatcher)();
}
u32 Jit::GetCompilerPC() {
@@ -413,7 +362,7 @@ const u8 *Jit::DoJit(u32 em_address, JitBlock *b)
// Downcount flag check. The last block decremented downcounter, and the flag should still be available.
FixupBranch skip = J_CC(CC_NS);
MOV(32, M(&mips_->pc), Imm32(js.blockStart));
- JMP(asm_.outerLoop, true); // downcount hit zero - go advance.
+ JMP(outerLoop, true); // downcount hit zero - go advance.
SetJumpTarget(skip);
b->normalEntry = GetCodePtr();
@@ -491,15 +440,13 @@ void Jit::AddContinuedBlock(u32 dest)
js.lastContinuedPC = dest;
}
-bool Jit::DescribeCodePtr(const u8 *ptr, std::string &name)
-{
+bool Jit::DescribeCodePtr(const u8 *ptr, std::string &name) {
u32 jitAddr = blocks.GetAddressFromBlockPtr(ptr);
// Returns 0 when it's valid, but unknown.
- if (jitAddr == 0)
+ if (jitAddr == 0) {
name = "UnknownOrDeletedBlock";
- else if (jitAddr != (u32)-1)
- {
+ } else if (jitAddr != (u32)-1) {
char temp[1024];
const std::string label = symbolMap.GetDescription(jitAddr);
if (!label.empty())
@@ -507,18 +454,20 @@ bool Jit::DescribeCodePtr(const u8 *ptr, std::string &name)
else
snprintf(temp, sizeof(temp), "%08x", jitAddr);
name = temp;
- }
- else if (asm_.IsInSpace(ptr))
- name = "RunLoopUntil";
- else if (thunks.IsInSpace(ptr))
+ } else if (IsInSpace(ptr)) {
+ if (ptr < endOfPregeneratedCode) {
+ name = "PreGenCode";
+ } else {
+ name = "Unknown";
+ }
+ } else if (thunks.IsInSpace(ptr)) {
name = "Thunk";
- else if (safeMemFuncs.IsInSpace(ptr))
+ } else if (safeMemFuncs.IsInSpace(ptr)) {
name = "JitSafeMem";
- else if (IsInSpace(ptr))
- name = "Unknown";
- // Not anywhere in jit, then.
- else
+ } else {
+ // Not anywhere in jit, then.
return false;
+ }
// If we got here, one of the above cases matched.
return true;
@@ -706,7 +655,7 @@ void Jit::WriteExit(u32 destination, int exit_num)
} else {
// No blocklinking.
MOV(32, M(&mips_->pc), Imm32(destination));
- JMP(asm_.dispatcher, true);
+ JMP(dispatcher, true);
// Normally, exits are 15 bytes (MOV + &pc + dest + JMP + dest) on 64 or 32 bit.
// But just in case we somehow optimized, pad.
@@ -745,8 +694,8 @@ void Jit::WriteExitDestInReg(X64Reg reg)
// Need to set neg flag again.
SUB(32, M(&mips_->downcount), Imm8(0));
if (reg == EAX)
- J_CC(CC_NS, asm_.dispatcherInEAXNoCheck, true);
- JMP(asm_.dispatcher, true);
+ J_CC(CC_NS, dispatcherInEAXNoCheck, true);
+ JMP(dispatcher, true);
SetJumpTarget(tooLow);
SetJumpTarget(tooHigh);
@@ -763,15 +712,15 @@ void Jit::WriteExitDestInReg(X64Reg reg)
}
SUB(32, M(&mips_->downcount), Imm8(0));
- JMP(asm_.dispatcherCheckCoreState, true);
+ JMP(dispatcherCheckCoreState, true);
}
else if (reg == EAX)
{
- J_CC(CC_NS, asm_.dispatcherInEAXNoCheck, true);
- JMP(asm_.dispatcher, true);
+ J_CC(CC_NS, dispatcherInEAXNoCheck, true);
+ JMP(dispatcher, true);
}
else
- JMP(asm_.dispatcher, true);
+ JMP(dispatcher, true);
}
void Jit::WriteSyscallExit()
@@ -782,7 +731,7 @@ void Jit::WriteSyscallExit()
ABI_CallFunction(&JitMemCheckCleanup);
ApplyRoundingMode();
}
- JMP(asm_.dispatcherCheckCoreState, true);
+ JMP(dispatcherCheckCoreState, true);
}
bool Jit::CheckJitBreakpoint(u32 addr, int downcountOffset)
@@ -802,7 +751,7 @@ bool Jit::CheckJitBreakpoint(u32 addr, int downcountOffset)
ApplyRoundingMode();
// Just to fix the stack.
LOAD_FLAGS;
- JMP(asm_.dispatcherCheckCoreState, true);
+ JMP(dispatcherCheckCoreState, true);
SetJumpTarget(skip);
ApplyRoundingMode();
diff --git a/Core/MIPS/x86/Jit.h b/Core/MIPS/x86/Jit.h
index 9f0fc27148..1e4d631b2c 100644
--- a/Core/MIPS/x86/Jit.h
+++ b/Core/MIPS/x86/Jit.h
@@ -20,7 +20,6 @@
#include "Common/CommonTypes.h"
#include "Common/Thunk.h"
#include "Common/x64Emitter.h"
-#include "Core/MIPS/x86/Asm.h"
#if defined(ARM)
#error DO NOT BUILD X86 JIT ON ARM
@@ -140,7 +139,6 @@ public:
void Comp_DoNothing(MIPSOpcode op);
int Replace_fabsf();
- int Replace_dl_write_matrix();
void ApplyPrefixST(u8 *vregs, u32 prefix, VectorSize sz);
void ApplyPrefixD(const u8 *vregs, VectorSize sz);
@@ -157,12 +155,11 @@ public:
void GetVectorRegsPrefixD(u8 *regs, VectorSize sz, int vectorReg);
void EatPrefix() { js.EatPrefix(); }
- void RestoreRoundingMode(bool force = false, XEmitter *emitter = NULL);
- void ApplyRoundingMode(bool force = false, XEmitter *emitter = NULL);
- void UpdateRoundingMode(XEmitter *emitter = NULL);
+ void RestoreRoundingMode(bool force = false);
+ void ApplyRoundingMode(bool force = false);
+ void UpdateRoundingMode();
JitBlockCache *GetBlockCache() { return &blocks; }
- AsmRoutineManager &Asm() { return asm_; }
void ClearCache();
void InvalidateCache();
@@ -172,7 +169,12 @@ public:
}
}
+ const u8 *GetDispatcher() const {
+ return dispatcher;
+ }
+
private:
+ void GenerateFixedCode(JitOptions &jo);
void GetStateAndFlushAll(RegCacheState &state);
void RestoreState(const RegCacheState& state);
void FlushAll();
@@ -296,12 +298,28 @@ private:
GPRRegCache gpr;
FPURegCache fpr;
- AsmRoutineManager asm_;
ThunkManager thunks;
JitSafeMemFuncs safeMemFuncs;
MIPSState *mips_;
+
+ const u8 *enterDispatcher;
+
+ const u8 *outerLoop;
+ const u8 *dispatcher;
+ const u8 *dispatcherCheckCoreState;
+ const u8 *dispatcherNoCheck;
+ const u8 *dispatcherInEAXNoCheck;
+
+ const u8 *breakpointBailout;
+
+ const u8 *restoreRoundingMode;
+ const u8 *applyRoundingMode;
+ const u8 *updateRoundingMode;
+
+ const u8 *endOfPregeneratedCode;
+
friend class JitSafeMem;
friend class JitSafeMemFuncs;
};
diff --git a/Core/MIPS/x86/RegCache.cpp b/Core/MIPS/x86/RegCache.cpp
index d93df0b8fd..5a48b290f2 100644
--- a/Core/MIPS/x86/RegCache.cpp
+++ b/Core/MIPS/x86/RegCache.cpp
@@ -23,7 +23,6 @@
#include "Core/MIPS/MIPSTables.h"
#include "Core/MIPS/MIPSAnalyst.h"
#include "Core/MIPS/x86/Jit.h"
-#include "Core/MIPS/x86/Asm.h"
#include "Core/MIPS/x86/RegCache.h"
using namespace Gen;