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/x86/X64IRCompBranch.cpp
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
#include "ppsspp_config.h"
19
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
20
21
#include "Core/MIPS/x86/X64IRJit.h"
22
#include "Core/MIPS/x86/X64IRRegCache.h"
23
24
// This file contains compilation for exits.
25
//
26
// All functions should have CONDITIONAL_DISABLE, so we can narrow things down to a file quickly.
27
// Currently known non working ones should have DISABLE. No flags because that's in IR already.
28
29
// #define CONDITIONAL_DISABLE { CompIR_Generic(inst); return; }
30
#define CONDITIONAL_DISABLE {}
31
#define DISABLE { CompIR_Generic(inst); return; }
32
#define INVALIDOP { _assert_msg_(false, "Invalid IR inst %d", (int)inst.op); CompIR_Generic(inst); return; }
33
34
namespace MIPSComp {
35
36
using namespace Gen;
37
using namespace X64IRJitConstants;
38
39
void X64JitBackend::CompIR_Exit(IRInst inst) {
40
CONDITIONAL_DISABLE;
41
42
X64Reg exitReg = INVALID_REG;
43
switch (inst.op) {
44
case IROp::ExitToConst:
45
FlushAll();
46
WriteConstExit(inst.constant);
47
break;
48
49
case IROp::ExitToReg:
50
exitReg = regs_.MapGPR(inst.src1);
51
FlushAll();
52
MOV(32, R(SCRATCH1), R(exitReg));
53
JMP(dispatcherPCInSCRATCH1_, true);
54
break;
55
56
case IROp::ExitToPC:
57
FlushAll();
58
JMP(dispatcherCheckCoreState_, true);
59
break;
60
61
default:
62
INVALIDOP;
63
break;
64
}
65
}
66
67
void X64JitBackend::CompIR_ExitIf(IRInst inst) {
68
CONDITIONAL_DISABLE;
69
70
X64Reg lhs = INVALID_REG;
71
X64Reg rhs = INVALID_REG;
72
FixupBranch fixup;
73
switch (inst.op) {
74
case IROp::ExitToConstIfEq:
75
case IROp::ExitToConstIfNeq:
76
regs_.Map(inst);
77
lhs = regs_.RX(inst.src1);
78
rhs = regs_.RX(inst.src2);
79
// This won't change those regs, intentionally. It might affect flags, though.
80
FlushAll();
81
82
CMP(32, R(lhs), R(rhs));
83
switch (inst.op) {
84
case IROp::ExitToConstIfEq:
85
fixup = J_CC(CC_NE);
86
break;
87
88
case IROp::ExitToConstIfNeq:
89
fixup = J_CC(CC_E);
90
break;
91
92
default:
93
INVALIDOP;
94
break;
95
}
96
97
WriteConstExit(inst.constant);
98
SetJumpTarget(fixup);
99
break;
100
101
case IROp::ExitToConstIfGtZ:
102
case IROp::ExitToConstIfGeZ:
103
case IROp::ExitToConstIfLtZ:
104
case IROp::ExitToConstIfLeZ:
105
regs_.Map(inst);
106
lhs = regs_.RX(inst.src1);
107
FlushAll();
108
109
CMP(32, R(lhs), Imm32(0));
110
switch (inst.op) {
111
case IROp::ExitToConstIfGtZ:
112
fixup = J_CC(CC_LE, lhs);
113
break;
114
115
case IROp::ExitToConstIfGeZ:
116
fixup = J_CC(CC_L, lhs);
117
break;
118
119
case IROp::ExitToConstIfLtZ:
120
fixup = J_CC(CC_GE, lhs);
121
break;
122
123
case IROp::ExitToConstIfLeZ:
124
fixup = J_CC(CC_G, lhs);
125
break;
126
127
default:
128
INVALIDOP;
129
break;
130
}
131
132
WriteConstExit(inst.constant);
133
SetJumpTarget(fixup);
134
break;
135
136
case IROp::ExitToConstIfFpTrue:
137
case IROp::ExitToConstIfFpFalse:
138
// Note: not used.
139
DISABLE;
140
break;
141
142
default:
143
INVALIDOP;
144
break;
145
}
146
}
147
148
} // namespace MIPSComp
149
150
#endif
151
152