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/RiscVRegCache.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 "Common/RiscVEmitter.h"
21
#include "Core/MIPS/MIPS.h"
22
#include "Core/MIPS/IR/IRJit.h"
23
#include "Core/MIPS/IR/IRRegCache.h"
24
25
namespace RiscVJitConstants {
26
27
// Note: we don't support 32-bit or 128-bit CPUs currently.
28
constexpr int XLEN = 64;
29
30
const RiscVGen::RiscVReg DOWNCOUNTREG = RiscVGen::X24;
31
const RiscVGen::RiscVReg JITBASEREG = RiscVGen::X25;
32
const RiscVGen::RiscVReg CTXREG = RiscVGen::X26;
33
const RiscVGen::RiscVReg MEMBASEREG = RiscVGen::X27;
34
// TODO: Experiment. X7-X13 are compressed regs. X8/X9 are saved so nice for static alloc, though.
35
const RiscVGen::RiscVReg SCRATCH1 = RiscVGen::X10;
36
const RiscVGen::RiscVReg SCRATCH2 = RiscVGen::X11;
37
38
} // namespace RiscVJitConstants
39
40
class RiscVRegCache : public IRNativeRegCacheBase {
41
public:
42
RiscVRegCache(MIPSComp::JitOptions *jo);
43
44
void Init(RiscVGen::RiscVEmitter *emitter);
45
46
// May fail and return INVALID_REG if it needs flushing.
47
RiscVGen::RiscVReg TryMapTempImm(IRReg reg);
48
49
// Returns an RV register containing the requested MIPS register.
50
RiscVGen::RiscVReg MapGPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
51
RiscVGen::RiscVReg MapGPRAsPointer(IRReg reg);
52
RiscVGen::RiscVReg MapFPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
53
54
RiscVGen::RiscVReg MapWithFPRTemp(const IRInst &inst);
55
56
bool IsNormalized32(IRReg reg);
57
58
// Copies to another reg if specified, otherwise same reg.
59
RiscVGen::RiscVReg Normalize32(IRReg reg, RiscVGen::RiscVReg destReg = RiscVGen::INVALID_REG);
60
61
void FlushBeforeCall();
62
63
RiscVGen::RiscVReg GetAndLockTempGPR();
64
65
RiscVGen::RiscVReg R(IRReg preg); // Returns a cached register, while checking that it's NOT mapped as a pointer
66
RiscVGen::RiscVReg RPtr(IRReg preg); // Returns a cached register, if it has been mapped as a pointer
67
RiscVGen::RiscVReg F(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
85
private:
86
RiscVGen::RiscVEmitter *emit_ = nullptr;
87
88
enum {
89
NUM_RVGPR = 32,
90
NUM_RVFPR = 32,
91
NUM_RVVPR = 32,
92
};
93
};
94
95