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/RiscV/RiscVJit.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 <string>
21
#include <vector>
22
#include "Common/RiscVEmitter.h"
23
#include "Core/MIPS/IR/IRJit.h"
24
#include "Core/MIPS/IR/IRNativeCommon.h"
25
#include "Core/MIPS/JitCommon/JitState.h"
26
#include "Core/MIPS/JitCommon/JitCommon.h"
27
#include "Core/MIPS/RiscV/RiscVRegCache.h"
28
29
namespace MIPSComp {
30
31
class RiscVJitBackend : public RiscVGen::RiscVCodeBlock, public IRNativeBackend {
32
public:
33
RiscVJitBackend(JitOptions &jo, IRBlockCache &blocks);
34
~RiscVJitBackend();
35
36
bool DescribeCodePtr(const u8 *ptr, std::string &name) const override;
37
38
void GenerateFixedCode(MIPSState *mipsState) override;
39
bool CompileBlock(IRBlockCache *irBlockCache, int block_num, bool preload) override;
40
void ClearAllBlocks() override;
41
void InvalidateBlock(IRBlockCache *irBlockCache, int block_num) override;
42
43
protected:
44
const CodeBlockCommon &CodeBlock() const override {
45
return *this;
46
}
47
48
private:
49
void RestoreRoundingMode(bool force = false);
50
void ApplyRoundingMode(bool force = false);
51
void MovFromPC(RiscVGen::RiscVReg r);
52
void MovToPC(RiscVGen::RiscVReg r);
53
void WriteDebugPC(uint32_t pc);
54
void WriteDebugPC(RiscVGen::RiscVReg r);
55
void WriteDebugProfilerStatus(IRProfilerStatus status);
56
57
void SaveStaticRegisters();
58
void LoadStaticRegisters();
59
60
// Note: destroys SCRATCH1.
61
void FlushAll();
62
63
void WriteConstExit(uint32_t pc);
64
void OverwriteExit(int srcOffset, int len, int block_num) override;
65
66
void CompIR_Arith(IRInst inst) override;
67
void CompIR_Assign(IRInst inst) override;
68
void CompIR_Basic(IRInst inst) override;
69
void CompIR_Bits(IRInst inst) override;
70
void CompIR_Breakpoint(IRInst inst) override;
71
void CompIR_Compare(IRInst inst) override;
72
void CompIR_CondAssign(IRInst inst) override;
73
void CompIR_CondStore(IRInst inst) override;
74
void CompIR_Div(IRInst inst) override;
75
void CompIR_Exit(IRInst inst) override;
76
void CompIR_ExitIf(IRInst inst) override;
77
void CompIR_FArith(IRInst inst) override;
78
void CompIR_FAssign(IRInst inst) override;
79
void CompIR_FCompare(IRInst inst) override;
80
void CompIR_FCondAssign(IRInst inst) override;
81
void CompIR_FCvt(IRInst inst) override;
82
void CompIR_FLoad(IRInst inst) override;
83
void CompIR_FRound(IRInst inst) override;
84
void CompIR_FSat(IRInst inst) override;
85
void CompIR_FSpecial(IRInst inst) override;
86
void CompIR_FStore(IRInst inst) override;
87
void CompIR_Generic(IRInst inst) override;
88
void CompIR_HiLo(IRInst inst) override;
89
void CompIR_Interpret(IRInst inst) override;
90
void CompIR_Load(IRInst inst) override;
91
void CompIR_LoadShift(IRInst inst) override;
92
void CompIR_Logic(IRInst inst) override;
93
void CompIR_Mult(IRInst inst) override;
94
void CompIR_RoundingMode(IRInst inst) override;
95
void CompIR_Shift(IRInst inst) override;
96
void CompIR_Store(IRInst inst) override;
97
void CompIR_StoreShift(IRInst inst) override;
98
void CompIR_System(IRInst inst) override;
99
void CompIR_Transfer(IRInst inst) override;
100
void CompIR_VecArith(IRInst inst) override;
101
void CompIR_VecAssign(IRInst inst) override;
102
void CompIR_VecClamp(IRInst inst) override;
103
void CompIR_VecHoriz(IRInst inst) override;
104
void CompIR_VecLoad(IRInst inst) override;
105
void CompIR_VecPack(IRInst inst) override;
106
void CompIR_VecStore(IRInst inst) override;
107
void CompIR_ValidateAddress(IRInst inst) override;
108
109
void SetScratch1ToSrc1Address(IRReg src1);
110
// Modifies SCRATCH regs.
111
int32_t AdjustForAddressOffset(RiscVGen::RiscVReg *reg, int32_t constant, int32_t range = 0);
112
void NormalizeSrc1(IRInst inst, RiscVGen::RiscVReg *reg, RiscVGen::RiscVReg tempReg, bool allowOverlap);
113
void NormalizeSrc12(IRInst inst, RiscVGen::RiscVReg *lhs, RiscVGen::RiscVReg *rhs, RiscVGen::RiscVReg lhsTempReg, RiscVGen::RiscVReg rhsTempReg, bool allowOverlap);
114
RiscVGen::RiscVReg NormalizeR(IRReg rs, IRReg rd, RiscVGen::RiscVReg tempReg);
115
116
JitOptions &jo;
117
RiscVRegCache regs_;
118
119
const u8 *outerLoop_ = nullptr;
120
const u8 *outerLoopPCInSCRATCH1_ = nullptr;
121
const u8 *dispatcherCheckCoreState_ = nullptr;
122
const u8 *dispatcherPCInSCRATCH1_ = nullptr;
123
const u8 *dispatcherNoCheck_ = nullptr;
124
const u8 *applyRoundingMode_ = nullptr;
125
126
const u8 *saveStaticRegisters_ = nullptr;
127
const u8 *loadStaticRegisters_ = nullptr;
128
129
int jitStartOffset_ = 0;
130
int compilingBlockNum_ = -1;
131
int logBlocks_ = 0;
132
};
133
134
class RiscVJit : public IRNativeJit {
135
public:
136
RiscVJit(MIPSState *mipsState)
137
: IRNativeJit(mipsState), rvBackend_(jo, blocks_) {
138
Init(rvBackend_);
139
}
140
141
private:
142
RiscVJitBackend rvBackend_;
143
};
144
145
} // namespace MIPSComp
146
147