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/ARM64/Arm64IRJit.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
// In other words, PPSSPP_ARCH(ARM64) || DISASM_ALL.
22
#if PPSSPP_ARCH(ARM64) || (PPSSPP_PLATFORM(WINDOWS) && !defined(__LIBRETRO__))
23
24
#include <string>
25
#include <vector>
26
#include "Common/Arm64Emitter.h"
27
#include "Core/MIPS/IR/IRJit.h"
28
#include "Core/MIPS/IR/IRNativeCommon.h"
29
#include "Core/MIPS/JitCommon/JitState.h"
30
#include "Core/MIPS/JitCommon/JitCommon.h"
31
#include "Core/MIPS/ARM64/Arm64IRRegCache.h"
32
33
namespace MIPSComp {
34
35
class Arm64JitBackend : public Arm64Gen::ARM64CodeBlock, public IRNativeBackend {
36
public:
37
Arm64JitBackend(JitOptions &jo, IRBlockCache &blocks);
38
~Arm64JitBackend();
39
40
bool DescribeCodePtr(const u8 *ptr, std::string &name) const override;
41
42
void GenerateFixedCode(MIPSState *mipsState) override;
43
bool CompileBlock(IRBlockCache *irBlockCache, int block_num, bool preload) override;
44
void ClearAllBlocks() override;
45
void InvalidateBlock(IRBlockCache *irBlockCache, int block_num) override;
46
47
void UpdateFCR31(MIPSState *mipsState) override;
48
49
protected:
50
const CodeBlockCommon &CodeBlock() const override {
51
return *this;
52
}
53
54
private:
55
void RestoreRoundingMode(bool force = false);
56
void ApplyRoundingMode(bool force = false);
57
void UpdateRoundingMode(bool force = false);
58
void MovFromPC(Arm64Gen::ARM64Reg r);
59
void MovToPC(Arm64Gen::ARM64Reg r);
60
// Destroys SCRATCH2.
61
void WriteDebugPC(uint32_t pc);
62
void WriteDebugPC(Arm64Gen::ARM64Reg r);
63
// Destroys SCRATCH2.
64
void WriteDebugProfilerStatus(IRProfilerStatus status);
65
66
void SaveStaticRegisters();
67
void LoadStaticRegisters();
68
69
// Note: destroys SCRATCH1.
70
void FlushAll();
71
72
void WriteConstExit(uint32_t pc);
73
void OverwriteExit(int srcOffset, int len, int block_num) override;
74
75
void CompIR_Arith(IRInst inst) override;
76
void CompIR_Assign(IRInst inst) override;
77
void CompIR_Basic(IRInst inst) override;
78
void CompIR_Bits(IRInst inst) override;
79
void CompIR_Breakpoint(IRInst inst) override;
80
void CompIR_Compare(IRInst inst) override;
81
void CompIR_CondAssign(IRInst inst) override;
82
void CompIR_CondStore(IRInst inst) override;
83
void CompIR_Div(IRInst inst) override;
84
void CompIR_Exit(IRInst inst) override;
85
void CompIR_ExitIf(IRInst inst) override;
86
void CompIR_FArith(IRInst inst) override;
87
void CompIR_FAssign(IRInst inst) override;
88
void CompIR_FCompare(IRInst inst) override;
89
void CompIR_FCondAssign(IRInst inst) override;
90
void CompIR_FCvt(IRInst inst) override;
91
void CompIR_FLoad(IRInst inst) override;
92
void CompIR_FRound(IRInst inst) override;
93
void CompIR_FSat(IRInst inst) override;
94
void CompIR_FSpecial(IRInst inst) override;
95
void CompIR_FStore(IRInst inst) override;
96
void CompIR_Generic(IRInst inst) override;
97
void CompIR_HiLo(IRInst inst) override;
98
void CompIR_Interpret(IRInst inst) override;
99
void CompIR_Load(IRInst inst) override;
100
void CompIR_LoadShift(IRInst inst) override;
101
void CompIR_Logic(IRInst inst) override;
102
void CompIR_Mult(IRInst inst) override;
103
void CompIR_RoundingMode(IRInst inst) override;
104
void CompIR_Shift(IRInst inst) override;
105
void CompIR_Store(IRInst inst) override;
106
void CompIR_StoreShift(IRInst inst) override;
107
void CompIR_System(IRInst inst) override;
108
void CompIR_Transfer(IRInst inst) override;
109
void CompIR_VecArith(IRInst inst) override;
110
void CompIR_VecAssign(IRInst inst) override;
111
void CompIR_VecClamp(IRInst inst) override;
112
void CompIR_VecHoriz(IRInst inst) override;
113
void CompIR_VecLoad(IRInst inst) override;
114
void CompIR_VecPack(IRInst inst) override;
115
void CompIR_VecStore(IRInst inst) override;
116
void CompIR_ValidateAddress(IRInst inst) override;
117
118
struct LoadStoreArg {
119
Arm64Gen::ARM64Reg base = Arm64Gen::INVALID_REG;
120
Arm64Gen::ARM64Reg regOffset = Arm64Gen::INVALID_REG;
121
int immOffset = 0;
122
bool useUnscaled = false;
123
bool useRegisterOffset = false;
124
bool signExtendRegOffset = false;
125
};
126
LoadStoreArg PrepareSrc1Address(IRInst inst);
127
128
JitOptions &jo;
129
Arm64IRRegCache regs_;
130
Arm64Gen::ARM64FloatEmitter fp_;
131
132
const u8 *outerLoop_ = nullptr;
133
const u8 *outerLoopPCInSCRATCH1_ = nullptr;
134
const u8 *dispatcherCheckCoreState_ = nullptr;
135
const u8 *dispatcherPCInSCRATCH1_ = nullptr;
136
const u8 *dispatcherNoCheck_ = nullptr;
137
const u8 *restoreRoundingMode_ = nullptr;
138
const u8 *applyRoundingMode_ = nullptr;
139
const u8 *updateRoundingMode_ = nullptr;
140
141
const u8 *saveStaticRegisters_ = nullptr;
142
const u8 *loadStaticRegisters_ = nullptr;
143
144
// Indexed by FPCR FZ:RN bits for convenience. Uses SCRATCH2.
145
const u8 *convertS0ToSCRATCH1_[8];
146
147
// Note: mutable state used at runtime.
148
const u8 *currentRoundingFunc_ = nullptr;
149
150
int jitStartOffset_ = 0;
151
int compilingBlockNum_ = -1;
152
int logBlocks_ = 0;
153
// Only useful in breakpoints, where it's set immediately prior.
154
uint32_t lastConstPC_ = 0;
155
};
156
157
class Arm64IRJit : public IRNativeJit {
158
public:
159
Arm64IRJit(MIPSState *mipsState)
160
: IRNativeJit(mipsState), arm64Backend_(jo, blocks_) {
161
Init(arm64Backend_);
162
}
163
164
private:
165
Arm64JitBackend arm64Backend_;
166
};
167
168
} // namespace MIPSComp
169
170
#endif
171
172