CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/x86/X64IRJit.h
Views: 1401
1
// Copyright (c) 2023- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include "ppsspp_config.h"
21
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
22
23
#include <string>
24
#include <vector>
25
#include "Common/x64Emitter.h"
26
#include "Core/MIPS/IR/IRJit.h"
27
#include "Core/MIPS/IR/IRNativeCommon.h"
28
#include "Core/MIPS/JitCommon/JitState.h"
29
#include "Core/MIPS/JitCommon/JitCommon.h"
30
#include "Core/MIPS/x86/X64IRRegCache.h"
31
32
#if PPSSPP_PLATFORM(WINDOWS) && (defined(_MSC_VER) || defined(__clang__) || defined(__INTEL_COMPILER))
33
#define X64JIT_XMM_CALL __vectorcall
34
#define X64JIT_USE_XMM_CALL 1
35
#elif PPSSPP_ARCH(AMD64)
36
// SystemV ABI supports XMM registers.
37
#define X64JIT_XMM_CALL
38
#define X64JIT_USE_XMM_CALL 1
39
#else
40
// GCC on x86 doesn't support vectorcall.
41
#define X64JIT_XMM_CALL
42
#define X64JIT_USE_XMM_CALL 0
43
#endif
44
45
namespace MIPSComp {
46
47
class X64JitBackend : public Gen::XCodeBlock, public IRNativeBackend {
48
public:
49
X64JitBackend(JitOptions &jo, IRBlockCache &blocks);
50
~X64JitBackend();
51
52
bool DescribeCodePtr(const u8 *ptr, std::string &name) const override;
53
54
void GenerateFixedCode(MIPSState *mipsState) override;
55
bool CompileBlock(IRBlockCache *irBlockCache, int block_num, bool preload) override;
56
void ClearAllBlocks() override;
57
void InvalidateBlock(IRBlockCache *irBlockCache, int block_num) override;
58
59
protected:
60
const CodeBlockCommon &CodeBlock() const override {
61
return *this;
62
}
63
64
private:
65
void RestoreRoundingMode(bool force = false);
66
void ApplyRoundingMode(bool force = false);
67
void MovFromPC(Gen::X64Reg r);
68
void MovToPC(Gen::X64Reg r);
69
void WriteDebugPC(uint32_t pc);
70
void WriteDebugPC(Gen::X64Reg r);
71
void WriteDebugProfilerStatus(IRProfilerStatus status);
72
73
void SaveStaticRegisters();
74
void LoadStaticRegisters();
75
76
// Note: destroys SCRATCH1.
77
void FlushAll();
78
79
void WriteConstExit(uint32_t pc);
80
void OverwriteExit(int srcOffset, int len, int block_num) override;
81
82
void CompIR_Arith(IRInst inst) override;
83
void CompIR_Assign(IRInst inst) override;
84
void CompIR_Basic(IRInst inst) override;
85
void CompIR_Bits(IRInst inst) override;
86
void CompIR_Breakpoint(IRInst inst) override;
87
void CompIR_Compare(IRInst inst) override;
88
void CompIR_CondAssign(IRInst inst) override;
89
void CompIR_CondStore(IRInst inst) override;
90
void CompIR_Div(IRInst inst) override;
91
void CompIR_Exit(IRInst inst) override;
92
void CompIR_ExitIf(IRInst inst) override;
93
void CompIR_FArith(IRInst inst) override;
94
void CompIR_FAssign(IRInst inst) override;
95
void CompIR_FCompare(IRInst inst) override;
96
void CompIR_FCondAssign(IRInst inst) override;
97
void CompIR_FCvt(IRInst inst) override;
98
void CompIR_FLoad(IRInst inst) override;
99
void CompIR_FRound(IRInst inst) override;
100
void CompIR_FSat(IRInst inst) override;
101
void CompIR_FSpecial(IRInst inst) override;
102
void CompIR_FStore(IRInst inst) override;
103
void CompIR_Generic(IRInst inst) override;
104
void CompIR_HiLo(IRInst inst) override;
105
void CompIR_Interpret(IRInst inst) override;
106
void CompIR_Load(IRInst inst) override;
107
void CompIR_LoadShift(IRInst inst) override;
108
void CompIR_Logic(IRInst inst) override;
109
void CompIR_Mult(IRInst inst) override;
110
void CompIR_RoundingMode(IRInst inst) override;
111
void CompIR_Shift(IRInst inst) override;
112
void CompIR_Store(IRInst inst) override;
113
void CompIR_StoreShift(IRInst inst) override;
114
void CompIR_System(IRInst inst) override;
115
void CompIR_Transfer(IRInst inst) override;
116
void CompIR_VecArith(IRInst inst) override;
117
void CompIR_VecAssign(IRInst inst) override;
118
void CompIR_VecClamp(IRInst inst) override;
119
void CompIR_VecHoriz(IRInst inst) override;
120
void CompIR_VecLoad(IRInst inst) override;
121
void CompIR_VecPack(IRInst inst) override;
122
void CompIR_VecStore(IRInst inst) override;
123
void CompIR_ValidateAddress(IRInst inst) override;
124
125
void EmitConst4x32(const void **c, uint32_t v);
126
void EmitFPUConstants();
127
void EmitVecConstants();
128
129
Gen::OpArg PrepareSrc1Address(IRInst inst);
130
void CopyVec4ToFPRLane0(Gen::X64Reg dest, Gen::X64Reg src, int lane);
131
132
JitOptions &jo;
133
X64IRRegCache regs_;
134
135
const u8 *outerLoop_ = nullptr;
136
const u8 *outerLoopPCInSCRATCH1_ = nullptr;
137
const u8 *dispatcherCheckCoreState_ = nullptr;
138
const u8 *dispatcherPCInSCRATCH1_ = nullptr;
139
const u8 *dispatcherNoCheck_ = nullptr;
140
const u8 *restoreRoundingMode_ = nullptr;
141
const u8 *applyRoundingMode_ = nullptr;
142
143
const u8 *saveStaticRegisters_ = nullptr;
144
const u8 *loadStaticRegisters_ = nullptr;
145
146
typedef struct { float f[4]; } Float4Constant;
147
struct Constants {
148
const void *noSignMask;
149
const void *signBitAll;
150
const void *positiveZeroes;
151
const void *positiveInfinity;
152
const void *positiveOnes;
153
const void *negativeOnes;
154
const void *qNAN;
155
const void *maxIntBelowAsFloat;
156
const float *mulTableVi2f;
157
const float *mulTableVf2i;
158
const Float4Constant *vec4InitValues;
159
};
160
Constants constants;
161
162
int jitStartOffset_ = 0;
163
int compilingBlockNum_ = -1;
164
int logBlocks_ = 0;
165
// Only useful in breakpoints, where it's set immediately prior.
166
uint32_t lastConstPC_ = 0;
167
};
168
169
class X64IRJit : public IRNativeJit {
170
public:
171
X64IRJit(MIPSState *mipsState)
172
: IRNativeJit(mipsState), x64Backend_(jo, blocks_) {
173
Init(x64Backend_);
174
}
175
176
private:
177
X64JitBackend x64Backend_;
178
};
179
180
} // namespace MIPSComp
181
182
#endif
183
184