Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/LoongArch64/LoongArch64Jit.h
3188 views
1
// Copyright (c) 2025- 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/LoongArch64Emitter.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/LoongArch64/LoongArch64RegCache.h"
28
29
namespace MIPSComp {
30
31
class LoongArch64JitBackend : public LoongArch64Gen::LoongArch64CodeBlock, public IRNativeBackend {
32
public:
33
LoongArch64JitBackend(JitOptions &jo, IRBlockCache &blocks);
34
~LoongArch64JitBackend();
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) 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
private:
48
void RestoreRoundingMode(bool force = false);
49
void ApplyRoundingMode(bool force = false);
50
void MovFromPC(LoongArch64Gen::LoongArch64Reg r);
51
void MovToPC(LoongArch64Gen::LoongArch64Reg r);
52
void WriteDebugPC(uint32_t pc);
53
void WriteDebugPC(LoongArch64Gen::LoongArch64Reg r);
54
void WriteDebugProfilerStatus(IRProfilerStatus status);
55
56
void SaveStaticRegisters();
57
void LoadStaticRegisters();
58
59
// Note: destroys SCRATCH1.
60
void FlushAll();
61
62
void WriteConstExit(uint32_t pc);
63
void OverwriteExit(int srcOffset, int len, int block_num) override;
64
65
void CompIR_Arith(IRInst inst) override;
66
void CompIR_Assign(IRInst inst) override;
67
void CompIR_Basic(IRInst inst) override;
68
void CompIR_Bits(IRInst inst) override;
69
void CompIR_Breakpoint(IRInst inst) override;
70
void CompIR_Compare(IRInst inst) override;
71
void CompIR_CondAssign(IRInst inst) override;
72
void CompIR_CondStore(IRInst inst) override;
73
void CompIR_Div(IRInst inst) override;
74
void CompIR_Exit(IRInst inst) override;
75
void CompIR_ExitIf(IRInst inst) override;
76
void CompIR_FArith(IRInst inst) override;
77
void CompIR_FAssign(IRInst inst) override;
78
void CompIR_FCompare(IRInst inst) override;
79
void CompIR_FCondAssign(IRInst inst) override;
80
void CompIR_FCvt(IRInst inst) override;
81
void CompIR_FLoad(IRInst inst) override;
82
void CompIR_FRound(IRInst inst) override;
83
void CompIR_FSat(IRInst inst) override;
84
void CompIR_FSpecial(IRInst inst) override;
85
void CompIR_FStore(IRInst inst) override;
86
void CompIR_Generic(IRInst inst) override;
87
void CompIR_HiLo(IRInst inst) override;
88
void CompIR_Interpret(IRInst inst) override;
89
void CompIR_Load(IRInst inst) override;
90
void CompIR_LoadShift(IRInst inst) override;
91
void CompIR_Logic(IRInst inst) override;
92
void CompIR_Mult(IRInst inst) override;
93
void CompIR_RoundingMode(IRInst inst) override;
94
void CompIR_Shift(IRInst inst) override;
95
void CompIR_Store(IRInst inst) override;
96
void CompIR_StoreShift(IRInst inst) override;
97
void CompIR_System(IRInst inst) override;
98
void CompIR_Transfer(IRInst inst) override;
99
void CompIR_VecArith(IRInst inst) override;
100
void CompIR_VecAssign(IRInst inst) override;
101
void CompIR_VecClamp(IRInst inst) override;
102
void CompIR_VecHoriz(IRInst inst) override;
103
void CompIR_VecLoad(IRInst inst) override;
104
void CompIR_VecPack(IRInst inst) override;
105
void CompIR_VecStore(IRInst inst) override;
106
void CompIR_ValidateAddress(IRInst inst) override;
107
108
void SetScratch1ToSrc1Address(IRReg src1);
109
// Modifies SCRATCH regs.
110
int32_t AdjustForAddressOffset(LoongArch64Gen::LoongArch64Reg *reg, int32_t constant, int32_t range = 0);
111
void NormalizeSrc1(IRInst inst, LoongArch64Gen::LoongArch64Reg *reg, LoongArch64Gen::LoongArch64Reg tempReg, bool allowOverlap);
112
void NormalizeSrc12(IRInst inst, LoongArch64Gen::LoongArch64Reg *lhs, LoongArch64Gen::LoongArch64Reg *rhs, LoongArch64Gen::LoongArch64Reg lhsTempReg, LoongArch64Gen::LoongArch64Reg rhsTempReg, bool allowOverlap);
113
LoongArch64Gen::LoongArch64Reg NormalizeR(IRReg rs, IRReg rd, LoongArch64Gen::LoongArch64Reg tempReg);
114
115
JitOptions &jo;
116
LoongArch64RegCache regs_;
117
118
const u8 *outerLoop_ = nullptr;
119
const u8 *outerLoopPCInSCRATCH1_ = nullptr;
120
const u8 *dispatcherCheckCoreState_ = nullptr;
121
const u8 *dispatcherPCInSCRATCH1_ = nullptr;
122
const u8 *dispatcherNoCheck_ = nullptr;
123
const u8 *applyRoundingMode_ = nullptr;
124
125
const u8 *saveStaticRegisters_ = nullptr;
126
const u8 *loadStaticRegisters_ = nullptr;
127
128
int jitStartOffset_ = 0;
129
int compilingBlockNum_ = -1;
130
int logBlocks_ = 0;
131
};
132
133
class LoongArch64Jit : public IRNativeJit{
134
public:
135
LoongArch64Jit(MIPSState *mipsState) : IRNativeJit(mipsState), la64Backend_(jo, blocks_) {
136
Init(la64Backend_);
137
}
138
private:
139
LoongArch64JitBackend la64Backend_;
140
};
141
142
} // namespace MIPSComp
143