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/Arm64IRRegCache.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 "Common/Arm64Emitter.h"
25
#include "Core/MIPS/MIPS.h"
26
#include "Core/MIPS/IR/IRJit.h"
27
#include "Core/MIPS/IR/IRRegCache.h"
28
29
namespace Arm64IRJitConstants {
30
31
const Arm64Gen::ARM64Reg DOWNCOUNTREG = Arm64Gen::W25;
32
// Note: this is actually offset from the base.
33
const Arm64Gen::ARM64Reg JITBASEREG = Arm64Gen::X26;
34
const Arm64Gen::ARM64Reg CTXREG = Arm64Gen::X27;
35
const Arm64Gen::ARM64Reg MEMBASEREG = Arm64Gen::X28;
36
const Arm64Gen::ARM64Reg SCRATCH1_64 = Arm64Gen::X16;
37
const Arm64Gen::ARM64Reg SCRATCH2_64 = Arm64Gen::X17;
38
const Arm64Gen::ARM64Reg SCRATCH1 = Arm64Gen::W16;
39
const Arm64Gen::ARM64Reg SCRATCH2 = Arm64Gen::W17;
40
// TODO: How many do we actually need?
41
const Arm64Gen::ARM64Reg SCRATCHF1 = Arm64Gen::S0;
42
const Arm64Gen::ARM64Reg SCRATCHF2 = Arm64Gen::S1;
43
const Arm64Gen::ARM64Reg SCRATCHF3 = Arm64Gen::S2;
44
const Arm64Gen::ARM64Reg SCRATCHF4 = Arm64Gen::S3;
45
46
} // namespace X64IRJitConstants
47
48
class Arm64IRRegCache : public IRNativeRegCacheBase {
49
public:
50
Arm64IRRegCache(MIPSComp::JitOptions *jo);
51
52
void Init(Arm64Gen::ARM64XEmitter *emitter, Arm64Gen::ARM64FloatEmitter *fp);
53
54
// May fail and return INVALID_REG if it needs flushing.
55
Arm64Gen::ARM64Reg TryMapTempImm(IRReg reg);
56
57
// Returns an arm64 register containing the requested MIPS register.
58
Arm64Gen::ARM64Reg MapGPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
59
Arm64Gen::ARM64Reg MapGPR2(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
60
Arm64Gen::ARM64Reg MapGPRAsPointer(IRReg reg);
61
Arm64Gen::ARM64Reg MapFPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);
62
Arm64Gen::ARM64Reg MapVec2(IRReg first, MIPSMap mapFlags = MIPSMap::INIT);
63
Arm64Gen::ARM64Reg MapVec4(IRReg first, MIPSMap mapFlags = MIPSMap::INIT);
64
65
Arm64Gen::ARM64Reg MapWithFPRTemp(const IRInst &inst);
66
67
void FlushBeforeCall();
68
void FlushAll(bool gprs = true, bool fprs = true) override;
69
70
Arm64Gen::ARM64Reg GetAndLockTempGPR();
71
Arm64Gen::ARM64Reg GetAndLockTempFPR();
72
73
Arm64Gen::ARM64Reg R(IRReg preg); // Returns a cached register, while checking that it's NOT mapped as a pointer
74
Arm64Gen::ARM64Reg R64(IRReg preg);
75
Arm64Gen::ARM64Reg RPtr(IRReg preg); // Returns a cached register, if it has been mapped as a pointer
76
Arm64Gen::ARM64Reg F(IRReg preg);
77
Arm64Gen::ARM64Reg FD(IRReg preg);
78
Arm64Gen::ARM64Reg FQ(IRReg preg);
79
80
// These are called once on startup to generate functions, that you should then call.
81
void EmitLoadStaticRegisters();
82
void EmitSaveStaticRegisters();
83
84
protected:
85
const StaticAllocation *GetStaticAllocations(int &count) const override;
86
const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;
87
void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;
88
89
bool IsNativeRegCompatible(IRNativeReg nreg, MIPSLoc type, MIPSMap flags, int lanes) override;
90
void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
91
void StoreNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;
92
void SetNativeRegValue(IRNativeReg nreg, uint32_t imm) override;
93
void StoreRegValue(IRReg mreg, uint32_t imm) override;
94
bool TransferNativeReg(IRNativeReg nreg, IRNativeReg dest, MIPSLoc type, IRReg first, int lanes, MIPSMap flags) override;
95
96
private:
97
bool TransferVecTo1(IRNativeReg nreg, IRNativeReg dest, IRReg first, int oldlanes);
98
bool Transfer1ToVec(IRNativeReg nreg, IRNativeReg dest, IRReg first, int lanes);
99
100
IRNativeReg GPRToNativeReg(Arm64Gen::ARM64Reg r);
101
IRNativeReg VFPToNativeReg(Arm64Gen::ARM64Reg r);
102
Arm64Gen::ARM64Reg FromNativeReg(IRNativeReg r);
103
Arm64Gen::ARM64Reg FromNativeReg64(IRNativeReg r);
104
105
Arm64Gen::ARM64XEmitter *emit_ = nullptr;
106
Arm64Gen::ARM64FloatEmitter *fp_ = nullptr;
107
108
enum {
109
NUM_X_REGS = 32,
110
NUM_X_FREGS = 32,
111
};
112
};
113
114
#endif
115
116