blob: 96586897754267746614b10cf143ce049fdddd03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "jit/riscv64/constant/Base-constant-riscv.h"
#include "mozilla/Assertions.h"
#include "mozilla/Types.h"
#include <stdio.h>
#include "jit/riscv64/constant/Constant-riscv-c.h"
#include "jit/riscv64/constant/Constant-riscv-d.h"
#include "jit/riscv64/constant/Constant-riscv-f.h"
#include "jit/riscv64/constant/Constant-riscv-i.h"
#include "jit/riscv64/constant/Constant-riscv-m.h"
#include "jit/riscv64/constant/Constant-riscv-v.h"
#include "jit/riscv64/constant/Constant-riscv-zicsr.h"
#include "jit/riscv64/constant/Constant-riscv-zifencei.h"
#include "jit/riscv64/Simulator-riscv64.h"
namespace js {
namespace jit {
int32_t ImmBranchMaxForwardOffset(OffsetSize bits) {
return (1 << (bits - 1)) - 1;
}
bool InstructionBase::IsShortInstruction() const {
uint8_t FirstByte = *reinterpret_cast<const uint8_t*>(this);
return (FirstByte & 0x03) <= C2;
}
template <class T>
int InstructionGetters<T>::RvcRdValue() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcRdShift + kRvcRdBits - 1, kRvcRdShift);
}
template <class T>
int InstructionGetters<T>::RvcRs2Value() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcRs2Shift + kRvcRs2Bits - 1, kRvcRs2Shift);
}
template <class T>
int InstructionGetters<T>::RvcRs1sValue() const {
MOZ_ASSERT(this->IsShortInstruction());
return 0b1000 + this->Bits(kRvcRs1sShift + kRvcRs1sBits - 1, kRvcRs1sShift);
}
template <class T>
int InstructionGetters<T>::RvcRs2sValue() const {
MOZ_ASSERT(this->IsShortInstruction());
return 0b1000 + this->Bits(kRvcRs2sShift + kRvcRs2sBits - 1, kRvcRs2sShift);
}
template <class T>
inline int InstructionGetters<T>::RvcFunct6Value() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcFunct6Shift + kRvcFunct6Bits - 1, kRvcFunct6Shift);
}
template <class T>
inline int InstructionGetters<T>::RvcFunct4Value() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcFunct4Shift + kRvcFunct4Bits - 1, kRvcFunct4Shift);
}
template <class T>
inline int InstructionGetters<T>::RvcFunct3Value() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcFunct3Shift + kRvcFunct3Bits - 1, kRvcFunct3Shift);
}
template <class T>
inline int InstructionGetters<T>::RvcFunct2Value() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcFunct2Shift + kRvcFunct2Bits - 1, kRvcFunct2Shift);
}
template <class T>
inline int InstructionGetters<T>::RvcFunct2BValue() const {
MOZ_ASSERT(this->IsShortInstruction());
return this->Bits(kRvcFunct2BShift + kRvcFunct2Bits - 1, kRvcFunct2BShift);
}
template <class T>
uint32_t InstructionGetters<T>::Rvvzimm() const {
if ((this->InstructionBits() &
(kBaseOpcodeMask | kFunct3Mask | 0x80000000)) == RO_V_VSETVLI) {
uint32_t Bits = this->InstructionBits();
uint32_t zimm = Bits & kRvvZimmMask;
return zimm >> kRvvZimmShift;
} else {
MOZ_ASSERT((this->InstructionBits() &
(kBaseOpcodeMask | kFunct3Mask | 0xC0000000)) == RO_V_VSETIVLI);
uint32_t Bits = this->InstructionBits();
uint32_t zimm = Bits & kRvvZimmMask;
return (zimm >> kRvvZimmShift) & 0x3FF;
}
}
template <class T>
uint32_t InstructionGetters<T>::Rvvuimm() const {
MOZ_ASSERT((this->InstructionBits() &
(kBaseOpcodeMask | kFunct3Mask | 0xC0000000)) == RO_V_VSETIVLI);
uint32_t Bits = this->InstructionBits();
uint32_t uimm = Bits & kRvvUimmMask;
return uimm >> kRvvUimmShift;
}
template class InstructionGetters<InstructionBase>;
#ifdef JS_SIMULATOR_RISCV64
template class InstructionGetters<SimInstructionBase>;
#endif
OffsetSize InstructionBase::GetOffsetSize() const {
if (IsIllegalInstruction()) {
MOZ_CRASH("IllegalInstruction");
}
if (IsShortInstruction()) {
switch (InstructionBits() & kRvcOpcodeMask) {
case RO_C_J:
return kOffset11;
case RO_C_BEQZ:
case RO_C_BNEZ:
return kOffset9;
default:
MOZ_CRASH("IllegalInstruction");
}
} else {
switch (InstructionBits() & kBaseOpcodeMask) {
case BRANCH:
return kOffset13;
case JAL:
return kOffset21;
default:
MOZ_CRASH("IllegalInstruction");
}
}
}
InstructionBase::Type InstructionBase::InstructionType() const {
if (IsIllegalInstruction()) {
return kUnsupported;
}
// RV64C Instruction
if (IsShortInstruction()) {
switch (InstructionBits() & kRvcOpcodeMask) {
case RO_C_ADDI4SPN:
return kCIWType;
case RO_C_FLD:
case RO_C_LW:
#ifdef JS_CODEGEN_RISCV64
case RO_C_LD:
#endif
return kCLType;
case RO_C_FSD:
case RO_C_SW:
#ifdef JS_CODEGEN_RISCV64
case RO_C_SD:
#endif
return kCSType;
case RO_C_NOP_ADDI:
case RO_C_LI:
#ifdef JS_CODEGEN_RISCV64
case RO_C_ADDIW:
#endif
case RO_C_LUI_ADD:
return kCIType;
case RO_C_MISC_ALU:
if (Bits(11, 10) != 0b11)
return kCBType;
else
return kCAType;
case RO_C_J:
return kCJType;
case RO_C_BEQZ:
case RO_C_BNEZ:
return kCBType;
case RO_C_SLLI:
case RO_C_FLDSP:
case RO_C_LWSP:
#ifdef JS_CODEGEN_RISCV64
case RO_C_LDSP:
#endif
return kCIType;
case RO_C_JR_MV_ADD:
return kCRType;
case RO_C_FSDSP:
case RO_C_SWSP:
#ifdef JS_CODEGEN_RISCV64
case RO_C_SDSP:
#endif
return kCSSType;
default:
break;
}
} else {
// RISCV routine
switch (InstructionBits() & kBaseOpcodeMask) {
case LOAD:
return kIType;
case LOAD_FP:
return kIType;
case MISC_MEM:
return kIType;
case OP_IMM:
return kIType;
case AUIPC:
return kUType;
case OP_IMM_32:
return kIType;
case STORE:
return kSType;
case STORE_FP:
return kSType;
case AMO:
return kRType;
case OP:
return kRType;
case LUI:
return kUType;
case OP_32:
return kRType;
case MADD:
case MSUB:
case NMSUB:
case NMADD:
return kR4Type;
case OP_FP:
return kRType;
case BRANCH:
return kBType;
case JALR:
return kIType;
case JAL:
return kJType;
case SYSTEM:
return kIType;
case OP_V:
return kVType;
}
}
return kUnsupported;
}
} // namespace jit
} // namespace js
|