Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/MIPS/LoongArch64/LoongArch64RegCache.h
3188 views
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 "Common/LoongArch64Emitter.h"
21
#include "Core/MIPS/MIPS.h"
22
#include "Core/MIPS/IR/IRJit.h"
23
#include "Core/MIPS/IR/IRRegCache.h"
24
25
namespace LoongArch64JitConstants {
26
27
const LoongArch64Gen::LoongArch64Reg DOWNCOUNTREG = LoongArch64Gen::R28;
28
const LoongArch64Gen::LoongArch64Reg JITBASEREG = LoongArch64Gen::R29;
29
const LoongArch64Gen::LoongArch64Reg CTXREG = LoongArch64Gen::R30;
30
const LoongArch64Gen::LoongArch64Reg MEMBASEREG = LoongArch64Gen::R31;
31
const LoongArch64Gen::LoongArch64Reg SCRATCH1 = LoongArch64Gen::R12;
32
const LoongArch64Gen::LoongArch64Reg SCRATCH2 = LoongArch64Gen::R13;
33
const LoongArch64Gen::LoongArch64Reg SCRATCHF1 = LoongArch64Gen::F8;
34
const LoongArch64Gen::LoongArch64Reg SCRATCHF2 = LoongArch64Gen::F9;
35
36
} // namespace LoongArch64JitConstants
37
38
class LoongArch64RegCache : public IRNativeRegCacheBase {
39
public:
40
LoongArch64RegCache(MIPSComp::JitOptions *jo);
41
42
void Init(LoongArch64Gen::LoongArch64Emitter *emitter);
43
44
// May fail and return INVALID_REG if it needs flushing.
45
LoongArch64Gen::LoongArch64Reg TryMapTempImm(IRReg reg);
46
47
// Returns an LA register containing the requested MIPS register.
48
LoongArch64Gen::LoongArch64Reg MapGPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
49
LoongArch64Gen::LoongArch64Reg MapGPRAsPointer(IRReg reg);
50
LoongArch64Gen::LoongArch64Reg MapFPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
51
LoongArch64Gen::LoongArch64Reg MapVec4(IRReg first, MIPSMap mapFlags = MIPSMap::INIT);
52
53
LoongArch64Gen::LoongArch64Reg MapWithFPRTemp(const IRInst &inst);
54
55
bool IsNormalized32(IRReg reg);
56
57
// Copies to another reg if specified, otherwise same reg.
58
LoongArch64Gen::LoongArch64Reg Normalize32(IRReg reg, LoongArch64Gen::LoongArch64Reg destReg = LoongArch64Gen::INVALID_REG);
59
60
void FlushBeforeCall();
61
62
LoongArch64Gen::LoongArch64Reg GetAndLockTempGPR();
63
64
LoongArch64Gen::LoongArch64Reg R(IRReg preg); // Returns a cached register, while checking that it's NOT mapped as a pointer
65
LoongArch64Gen::LoongArch64Reg RPtr(IRReg preg); // Returns a cached register, if it has been mapped as a pointer
66
LoongArch64Gen::LoongArch64Reg F(IRReg preg);
67
LoongArch64Gen::LoongArch64Reg V(IRReg preg);
68
69
// These are called once on startup to generate functions, that you should then call.
70
void EmitLoadStaticRegisters();
71
void EmitSaveStaticRegisters();
72
73
protected:
74
void SetupInitialRegs() override;
75
const StaticAllocation *GetStaticAllocations(int &count) const override;
76
const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;
77
void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;
78
79
bool IsNativeRegCompatible(IRNativeReg nreg, MIPSLoc type, MIPSMap flags, int lanes) override;
80
void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
81
void StoreNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
82
void SetNativeRegValue(IRNativeReg nreg, uint32_t imm) override;
83
void StoreRegValue(IRReg mreg, uint32_t imm) override;
84
bool TransferNativeReg(IRNativeReg nreg, IRNativeReg dest, MIPSLoc type, IRReg first, int lanes, MIPSMap flags) override;
85
86
private:
87
bool TransferVecTo1(IRNativeReg nreg, IRNativeReg dest, IRReg first, int oldlanes);
88
bool Transfer1ToVec(IRNativeReg nreg, IRNativeReg dest, IRReg first, int lanes);
89
90
LoongArch64Gen::LoongArch64Reg FromNativeReg(IRNativeReg r) {
91
if (r >= NUM_LAGPR)
92
return (LoongArch64Gen::LoongArch64Reg)(LoongArch64Gen::V0 + (r - NUM_LAGPR));
93
return (LoongArch64Gen::LoongArch64Reg)(LoongArch64Gen::R0 + r);
94
}
95
96
LoongArch64Gen::LoongArch64Emitter *emit_ = nullptr;
97
98
enum {
99
NUM_LAGPR = 32,
100
NUM_LAFPR = 32,
101
};
102
};
103
104