blob: 6ac336178bf858bbc9eb1c76cc2fa2f2dd7aa997 [file] [log] [blame]
Andreas Gampe57b34292015-01-14 15:45:59 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_
18#define ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_
19
Alexey Frunze19f6c692016-11-30 19:19:55 -080020#include <deque>
Alexey Frunzea0e87b02015-09-24 22:57:20 -070021#include <utility>
Andreas Gampe57b34292015-01-14 15:45:59 -080022#include <vector>
23
Goran Jakovljevic27af9372017-03-15 15:31:34 +010024#include "arch/mips64/instruction_set_features_mips64.h"
Alexey Frunze19f6c692016-11-30 19:19:55 -080025#include "base/arena_containers.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070026#include "base/enums.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080027#include "base/macros.h"
28#include "constants_mips64.h"
29#include "globals.h"
30#include "managed_register_mips64.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080031#include "offsets.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070032#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070033#include "utils/jni_macro_assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070034#include "utils/label.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080035
36namespace art {
37namespace mips64 {
38
Chris Larsenc733dca2016-05-13 16:11:47 -070039enum LoadConst64Path {
40 kLoadConst64PathZero = 0x0,
41 kLoadConst64PathOri = 0x1,
42 kLoadConst64PathDaddiu = 0x2,
43 kLoadConst64PathLui = 0x4,
44 kLoadConst64PathLuiOri = 0x8,
45 kLoadConst64PathOriDahi = 0x10,
46 kLoadConst64PathOriDati = 0x20,
47 kLoadConst64PathLuiDahi = 0x40,
48 kLoadConst64PathLuiDati = 0x80,
49 kLoadConst64PathDaddiuDsrlX = 0x100,
50 kLoadConst64PathOriDsllX = 0x200,
51 kLoadConst64PathDaddiuDsllX = 0x400,
52 kLoadConst64PathLuiOriDsllX = 0x800,
53 kLoadConst64PathOriDsllXOri = 0x1000,
54 kLoadConst64PathDaddiuDsllXOri = 0x2000,
55 kLoadConst64PathDaddiuDahi = 0x4000,
56 kLoadConst64PathDaddiuDati = 0x8000,
57 kLoadConst64PathDinsu1 = 0x10000,
58 kLoadConst64PathDinsu2 = 0x20000,
59 kLoadConst64PathCatchAll = 0x40000,
60 kLoadConst64PathAllPaths = 0x7ffff,
61};
62
63template <typename Asm>
64void TemplateLoadConst32(Asm* a, GpuRegister rd, int32_t value) {
65 if (IsUint<16>(value)) {
66 // Use OR with (unsigned) immediate to encode 16b unsigned int.
67 a->Ori(rd, ZERO, value);
68 } else if (IsInt<16>(value)) {
69 // Use ADD with (signed) immediate to encode 16b signed int.
70 a->Addiu(rd, ZERO, value);
71 } else {
72 // Set 16 most significant bits of value. The "lui" instruction
73 // also clears the 16 least significant bits to zero.
74 a->Lui(rd, value >> 16);
75 if (value & 0xFFFF) {
76 // If the 16 least significant bits are non-zero, set them
77 // here.
78 a->Ori(rd, rd, value);
79 }
80 }
81}
82
83static inline int InstrCountForLoadReplicatedConst32(int64_t value) {
84 int32_t x = Low32Bits(value);
85 int32_t y = High32Bits(value);
86
87 if (x == y) {
88 return (IsUint<16>(x) || IsInt<16>(x) || ((x & 0xFFFF) == 0 && IsInt<16>(value >> 16))) ? 2 : 3;
89 }
90
91 return INT_MAX;
92}
93
94template <typename Asm, typename Rtype, typename Vtype>
95void TemplateLoadConst64(Asm* a, Rtype rd, Vtype value) {
96 int bit31 = (value & UINT64_C(0x80000000)) != 0;
97 int rep32_count = InstrCountForLoadReplicatedConst32(value);
98
99 // Loads with 1 instruction.
100 if (IsUint<16>(value)) {
101 // 64-bit value can be loaded as an unsigned 16-bit number.
102 a->RecordLoadConst64Path(kLoadConst64PathOri);
103 a->Ori(rd, ZERO, value);
104 } else if (IsInt<16>(value)) {
105 // 64-bit value can be loaded as an signed 16-bit number.
106 a->RecordLoadConst64Path(kLoadConst64PathDaddiu);
107 a->Daddiu(rd, ZERO, value);
108 } else if ((value & 0xFFFF) == 0 && IsInt<16>(value >> 16)) {
109 // 64-bit value can be loaded as an signed 32-bit number which has all
110 // of its 16 least significant bits set to zero.
111 a->RecordLoadConst64Path(kLoadConst64PathLui);
112 a->Lui(rd, value >> 16);
113 } else if (IsInt<32>(value)) {
114 // Loads with 2 instructions.
115 // 64-bit value can be loaded as an signed 32-bit number which has some
116 // or all of its 16 least significant bits set to one.
117 a->RecordLoadConst64Path(kLoadConst64PathLuiOri);
118 a->Lui(rd, value >> 16);
119 a->Ori(rd, rd, value);
120 } else if ((value & 0xFFFF0000) == 0 && IsInt<16>(value >> 32)) {
121 // 64-bit value which consists of an unsigned 16-bit value in its
122 // least significant 32-bits, and a signed 16-bit value in its
123 // most significant 32-bits.
124 a->RecordLoadConst64Path(kLoadConst64PathOriDahi);
125 a->Ori(rd, ZERO, value);
126 a->Dahi(rd, value >> 32);
127 } else if ((value & UINT64_C(0xFFFFFFFF0000)) == 0) {
128 // 64-bit value which consists of an unsigned 16-bit value in its
129 // least significant 48-bits, and a signed 16-bit value in its
130 // most significant 16-bits.
131 a->RecordLoadConst64Path(kLoadConst64PathOriDati);
132 a->Ori(rd, ZERO, value);
133 a->Dati(rd, value >> 48);
134 } else if ((value & 0xFFFF) == 0 &&
135 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
136 // 16 LSBs (Least Significant Bits) all set to zero.
137 // 48 MSBs (Most Significant Bits) hold a signed 32-bit value.
138 a->RecordLoadConst64Path(kLoadConst64PathLuiDahi);
139 a->Lui(rd, value >> 16);
140 a->Dahi(rd, (value >> 32) + bit31);
141 } else if ((value & 0xFFFF) == 0 && ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
142 // 16 LSBs all set to zero.
143 // 48 MSBs hold a signed value which can't be represented by signed
144 // 32-bit number, and the middle 16 bits are all zero, or all one.
145 a->RecordLoadConst64Path(kLoadConst64PathLuiDati);
146 a->Lui(rd, value >> 16);
147 a->Dati(rd, (value >> 48) + bit31);
148 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
149 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
150 // 32 LSBs contain an unsigned 16-bit number.
151 // 32 MSBs contain a signed 16-bit number.
152 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDahi);
153 a->Daddiu(rd, ZERO, value);
154 a->Dahi(rd, (value >> 32) + bit31);
155 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
156 ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
157 // 48 LSBs contain an unsigned 16-bit number.
158 // 16 MSBs contain a signed 16-bit number.
159 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDati);
160 a->Daddiu(rd, ZERO, value);
161 a->Dati(rd, (value >> 48) + bit31);
162 } else if (IsPowerOfTwo(value + UINT64_C(1))) {
163 // 64-bit values which have their "n" MSBs set to one, and their
164 // "64-n" LSBs set to zero. "n" must meet the restrictions 0 < n < 64.
165 int shift_cnt = 64 - CTZ(value + UINT64_C(1));
166 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsrlX);
167 a->Daddiu(rd, ZERO, -1);
168 if (shift_cnt < 32) {
169 a->Dsrl(rd, rd, shift_cnt);
170 } else {
171 a->Dsrl32(rd, rd, shift_cnt & 31);
172 }
173 } else {
174 int shift_cnt = CTZ(value);
175 int64_t tmp = value >> shift_cnt;
176 a->RecordLoadConst64Path(kLoadConst64PathOriDsllX);
177 if (IsUint<16>(tmp)) {
178 // Value can be computed by loading a 16-bit unsigned value, and
179 // then shifting left.
180 a->Ori(rd, ZERO, tmp);
181 if (shift_cnt < 32) {
182 a->Dsll(rd, rd, shift_cnt);
183 } else {
184 a->Dsll32(rd, rd, shift_cnt & 31);
185 }
186 } else if (IsInt<16>(tmp)) {
187 // Value can be computed by loading a 16-bit signed value, and
188 // then shifting left.
189 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllX);
190 a->Daddiu(rd, ZERO, tmp);
191 if (shift_cnt < 32) {
192 a->Dsll(rd, rd, shift_cnt);
193 } else {
194 a->Dsll32(rd, rd, shift_cnt & 31);
195 }
196 } else if (rep32_count < 3) {
197 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
198 // value loaded into the 32 LSBs can be loaded with a single
199 // MIPS instruction.
200 a->LoadConst32(rd, value);
201 a->Dinsu(rd, rd, 32, 32);
202 a->RecordLoadConst64Path(kLoadConst64PathDinsu1);
203 } else if (IsInt<32>(tmp)) {
204 // Loads with 3 instructions.
205 // Value can be computed by loading a 32-bit signed value, and
206 // then shifting left.
207 a->RecordLoadConst64Path(kLoadConst64PathLuiOriDsllX);
208 a->Lui(rd, tmp >> 16);
209 a->Ori(rd, rd, tmp);
210 if (shift_cnt < 32) {
211 a->Dsll(rd, rd, shift_cnt);
212 } else {
213 a->Dsll32(rd, rd, shift_cnt & 31);
214 }
215 } else {
216 shift_cnt = 16 + CTZ(value >> 16);
217 tmp = value >> shift_cnt;
218 if (IsUint<16>(tmp)) {
219 // Value can be computed by loading a 16-bit unsigned value,
220 // shifting left, and "or"ing in another 16-bit unsigned value.
221 a->RecordLoadConst64Path(kLoadConst64PathOriDsllXOri);
222 a->Ori(rd, ZERO, tmp);
223 if (shift_cnt < 32) {
224 a->Dsll(rd, rd, shift_cnt);
225 } else {
226 a->Dsll32(rd, rd, shift_cnt & 31);
227 }
228 a->Ori(rd, rd, value);
229 } else if (IsInt<16>(tmp)) {
230 // Value can be computed by loading a 16-bit signed value,
231 // shifting left, and "or"ing in a 16-bit unsigned value.
232 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllXOri);
233 a->Daddiu(rd, ZERO, tmp);
234 if (shift_cnt < 32) {
235 a->Dsll(rd, rd, shift_cnt);
236 } else {
237 a->Dsll32(rd, rd, shift_cnt & 31);
238 }
239 a->Ori(rd, rd, value);
240 } else if (rep32_count < 4) {
241 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
242 // value in the 32 LSBs requires 2 MIPS instructions to load.
243 a->LoadConst32(rd, value);
244 a->Dinsu(rd, rd, 32, 32);
245 a->RecordLoadConst64Path(kLoadConst64PathDinsu2);
246 } else {
247 // Loads with 3-4 instructions.
248 // Catch-all case to get any other 64-bit values which aren't
249 // handled by special cases above.
250 uint64_t tmp2 = value;
251 a->RecordLoadConst64Path(kLoadConst64PathCatchAll);
252 a->LoadConst32(rd, value);
253 if (bit31) {
254 tmp2 += UINT64_C(0x100000000);
255 }
256 if (((tmp2 >> 32) & 0xFFFF) != 0) {
257 a->Dahi(rd, tmp2 >> 32);
258 }
259 if (tmp2 & UINT64_C(0x800000000000)) {
260 tmp2 += UINT64_C(0x1000000000000);
261 }
262 if ((tmp2 >> 48) != 0) {
263 a->Dati(rd, tmp2 >> 48);
264 }
265 }
266 }
267 }
268}
269
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000270static constexpr size_t kMips64HalfwordSize = 2;
Lazar Trsicd9672662015-09-03 17:33:01 +0200271static constexpr size_t kMips64WordSize = 4;
272static constexpr size_t kMips64DoublewordSize = 8;
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700273
Andreas Gampe57b34292015-01-14 15:45:59 -0800274enum LoadOperandType {
275 kLoadSignedByte,
276 kLoadUnsignedByte,
277 kLoadSignedHalfword,
278 kLoadUnsignedHalfword,
279 kLoadWord,
Douglas Leungd90957f2015-04-30 19:22:49 -0700280 kLoadUnsignedWord,
Andreas Gampe57b34292015-01-14 15:45:59 -0800281 kLoadDoubleword
282};
283
284enum StoreOperandType {
285 kStoreByte,
286 kStoreHalfword,
287 kStoreWord,
288 kStoreDoubleword
289};
290
Chris Larsen14500822015-10-01 11:35:18 -0700291// Used to test the values returned by ClassS/ClassD.
292enum FPClassMaskType {
293 kSignalingNaN = 0x001,
294 kQuietNaN = 0x002,
295 kNegativeInfinity = 0x004,
296 kNegativeNormal = 0x008,
297 kNegativeSubnormal = 0x010,
298 kNegativeZero = 0x020,
299 kPositiveInfinity = 0x040,
300 kPositiveNormal = 0x080,
301 kPositiveSubnormal = 0x100,
302 kPositiveZero = 0x200,
303};
304
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700305class Mips64Label : public Label {
306 public:
307 Mips64Label() : prev_branch_id_plus_one_(0) {}
308
309 Mips64Label(Mips64Label&& src)
310 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
311
312 private:
313 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
314
315 friend class Mips64Assembler;
316 DISALLOW_COPY_AND_ASSIGN(Mips64Label);
317};
318
Alexey Frunze19f6c692016-11-30 19:19:55 -0800319// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
320class Literal {
321 public:
322 static constexpr size_t kMaxSize = 8;
323
324 Literal(uint32_t size, const uint8_t* data)
325 : label_(), size_(size) {
326 DCHECK_LE(size, Literal::kMaxSize);
327 memcpy(data_, data, size);
328 }
329
330 template <typename T>
331 T GetValue() const {
332 DCHECK_EQ(size_, sizeof(T));
333 T value;
334 memcpy(&value, data_, sizeof(T));
335 return value;
336 }
337
338 uint32_t GetSize() const {
339 return size_;
340 }
341
342 const uint8_t* GetData() const {
343 return data_;
344 }
345
346 Mips64Label* GetLabel() {
347 return &label_;
348 }
349
350 const Mips64Label* GetLabel() const {
351 return &label_;
352 }
353
354 private:
355 Mips64Label label_;
356 const uint32_t size_;
357 uint8_t data_[kMaxSize];
358
359 DISALLOW_COPY_AND_ASSIGN(Literal);
360};
361
Alexey Frunze0960ac52016-12-20 17:24:59 -0800362// Jump table: table of labels emitted after the code and before the literals. Similar to literals.
363class JumpTable {
364 public:
365 explicit JumpTable(std::vector<Mips64Label*>&& labels)
366 : label_(), labels_(std::move(labels)) {
367 }
368
369 size_t GetSize() const {
370 return labels_.size() * sizeof(uint32_t);
371 }
372
373 const std::vector<Mips64Label*>& GetData() const {
374 return labels_;
375 }
376
377 Mips64Label* GetLabel() {
378 return &label_;
379 }
380
381 const Mips64Label* GetLabel() const {
382 return &label_;
383 }
384
385 private:
386 Mips64Label label_;
387 std::vector<Mips64Label*> labels_;
388
389 DISALLOW_COPY_AND_ASSIGN(JumpTable);
390};
391
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700392// Slowpath entered when Thread::Current()->_exception is non-null.
393class Mips64ExceptionSlowPath {
394 public:
395 explicit Mips64ExceptionSlowPath(Mips64ManagedRegister scratch, size_t stack_adjust)
396 : scratch_(scratch), stack_adjust_(stack_adjust) {}
397
398 Mips64ExceptionSlowPath(Mips64ExceptionSlowPath&& src)
399 : scratch_(src.scratch_),
400 stack_adjust_(src.stack_adjust_),
401 exception_entry_(std::move(src.exception_entry_)) {}
402
403 private:
404 Mips64Label* Entry() { return &exception_entry_; }
405 const Mips64ManagedRegister scratch_;
406 const size_t stack_adjust_;
407 Mips64Label exception_entry_;
408
409 friend class Mips64Assembler;
410 DISALLOW_COPY_AND_ASSIGN(Mips64ExceptionSlowPath);
411};
412
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700413class Mips64Assembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k64> {
Andreas Gampe57b34292015-01-14 15:45:59 -0800414 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700415 using JNIBase = JNIMacroAssembler<PointerSize::k64>;
416
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100417 explicit Mips64Assembler(ArenaAllocator* arena,
418 const Mips64InstructionSetFeatures* instruction_set_features = nullptr)
Vladimir Marko93205e32016-04-13 11:59:46 +0100419 : Assembler(arena),
420 overwriting_(false),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700421 overwrite_location_(0),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800422 literals_(arena->Adapter(kArenaAllocAssembler)),
423 long_literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze0960ac52016-12-20 17:24:59 -0800424 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700425 last_position_adjustment_(0),
426 last_old_position_(0),
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100427 last_branch_id_(0),
428 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700429 cfi().DelayEmittingAdvancePCs();
430 }
431
432 virtual ~Mips64Assembler() {
433 for (auto& branch : branches_) {
434 CHECK(branch.IsResolved());
435 }
436 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800437
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700438 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
439 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
440
Andreas Gampe57b34292015-01-14 15:45:59 -0800441 // Emit Machine Instructions.
Andreas Gampe57b34292015-01-14 15:45:59 -0800442 void Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
443 void Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700444 void Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
445 void Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800446 void Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700447 void Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
448
Alexey Frunzec857c742015-09-23 15:12:39 -0700449 void MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
450 void MuhR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
451 void DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
452 void ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
453 void DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
454 void ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
455 void Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
456 void Dmuh(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
457 void Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
458 void Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
459 void Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
460 void Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800461
462 void And(GpuRegister rd, GpuRegister rs, GpuRegister rt);
463 void Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16);
464 void Or(GpuRegister rd, GpuRegister rs, GpuRegister rt);
465 void Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
466 void Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
467 void Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
468 void Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
469
Alexey Frunzec857c742015-09-23 15:12:39 -0700470 void Bitswap(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800471 void Dbitswap(GpuRegister rd, GpuRegister rt); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700472 void Seb(GpuRegister rd, GpuRegister rt);
473 void Seh(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800474 void Dsbh(GpuRegister rd, GpuRegister rt); // MIPS64
475 void Dshd(GpuRegister rd, GpuRegister rt); // MIPS64
Lazar Trsicd9672662015-09-03 17:33:01 +0200476 void Dext(GpuRegister rs, GpuRegister rt, int pos, int size); // MIPS64
477 void Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Chris Larsene3660592016-11-09 11:13:42 -0800478 void Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne);
479 void Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700480 void Wsbh(GpuRegister rd, GpuRegister rt);
481 void Sc(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800482 void Scd(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700483 void Ll(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800484 void Lld(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700485
486 void Sll(GpuRegister rd, GpuRegister rt, int shamt);
487 void Srl(GpuRegister rd, GpuRegister rt, int shamt);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700488 void Rotr(GpuRegister rd, GpuRegister rt, int shamt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700489 void Sra(GpuRegister rd, GpuRegister rt, int shamt);
490 void Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
491 void Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Chris Larsen9aebff22015-09-22 17:54:15 -0700492 void Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700493 void Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs);
494 void Dsll(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
495 void Dsrl(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800496 void Drotr(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700497 void Dsra(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
498 void Dsll32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
499 void Dsrl32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700500 void Drotr32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700501 void Dsra32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
502 void Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
503 void Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700504 void Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700505 void Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800506
507 void Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
508 void Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
509 void Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700510 void Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800511 void Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
512 void Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700513 void Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800514 void Lwpc(GpuRegister rs, uint32_t imm19);
515 void Lwupc(GpuRegister rs, uint32_t imm19); // MIPS64
516 void Ldpc(GpuRegister rs, uint32_t imm18); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800517 void Lui(GpuRegister rt, uint16_t imm16);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800518 void Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunzec061de12017-02-14 13:27:23 -0800519 void Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700520 void Dahi(GpuRegister rs, uint16_t imm16); // MIPS64
521 void Dati(GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700522 void Sync(uint32_t stype);
Andreas Gampe57b34292015-01-14 15:45:59 -0800523
524 void Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
525 void Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
526 void Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700527 void Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800528
529 void Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt);
530 void Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
531 void Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16);
532 void Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700533 void Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt);
534 void Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt);
535 void Clz(GpuRegister rd, GpuRegister rs);
536 void Clo(GpuRegister rd, GpuRegister rs);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800537 void Dclz(GpuRegister rd, GpuRegister rs); // MIPS64
538 void Dclo(GpuRegister rd, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800539
Alexey Frunze4dda3372015-06-01 18:31:49 -0700540 void Jalr(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800541 void Jalr(GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700542 void Jr(GpuRegister rs);
Alexey Frunzec857c742015-09-23 15:12:39 -0700543 void Auipc(GpuRegister rs, uint16_t imm16);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700544 void Addiupc(GpuRegister rs, uint32_t imm19);
545 void Bc(uint32_t imm26);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800546 void Balc(uint32_t imm26);
Alexey Frunzec857c742015-09-23 15:12:39 -0700547 void Jic(GpuRegister rt, uint16_t imm16);
548 void Jialc(GpuRegister rt, uint16_t imm16);
549 void Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
550 void Bltzc(GpuRegister rt, uint16_t imm16);
551 void Bgtzc(GpuRegister rt, uint16_t imm16);
552 void Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
553 void Bgezc(GpuRegister rt, uint16_t imm16);
554 void Blezc(GpuRegister rt, uint16_t imm16);
555 void Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
556 void Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
557 void Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
558 void Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
559 void Beqzc(GpuRegister rs, uint32_t imm21);
560 void Bnezc(GpuRegister rs, uint32_t imm21);
Alexey Frunze299a9392015-12-08 16:08:02 -0800561 void Bc1eqz(FpuRegister ft, uint16_t imm16);
562 void Bc1nez(FpuRegister ft, uint16_t imm16);
Andreas Gampe57b34292015-01-14 15:45:59 -0800563
564 void AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
565 void SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
566 void MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
567 void DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
568 void AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
569 void SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
570 void MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
571 void DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700572 void SqrtS(FpuRegister fd, FpuRegister fs);
573 void SqrtD(FpuRegister fd, FpuRegister fs);
574 void AbsS(FpuRegister fd, FpuRegister fs);
575 void AbsD(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800576 void MovS(FpuRegister fd, FpuRegister fs);
577 void MovD(FpuRegister fd, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700578 void NegS(FpuRegister fd, FpuRegister fs);
579 void NegD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700580 void RoundLS(FpuRegister fd, FpuRegister fs);
581 void RoundLD(FpuRegister fd, FpuRegister fs);
582 void RoundWS(FpuRegister fd, FpuRegister fs);
583 void RoundWD(FpuRegister fd, FpuRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800584 void TruncLS(FpuRegister fd, FpuRegister fs);
585 void TruncLD(FpuRegister fd, FpuRegister fs);
586 void TruncWS(FpuRegister fd, FpuRegister fs);
587 void TruncWD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700588 void CeilLS(FpuRegister fd, FpuRegister fs);
589 void CeilLD(FpuRegister fd, FpuRegister fs);
590 void CeilWS(FpuRegister fd, FpuRegister fs);
591 void CeilWD(FpuRegister fd, FpuRegister fs);
592 void FloorLS(FpuRegister fd, FpuRegister fs);
593 void FloorLD(FpuRegister fd, FpuRegister fs);
594 void FloorWS(FpuRegister fd, FpuRegister fs);
595 void FloorWD(FpuRegister fd, FpuRegister fs);
596 void SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
597 void SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
598 void RintS(FpuRegister fd, FpuRegister fs);
599 void RintD(FpuRegister fd, FpuRegister fs);
600 void ClassS(FpuRegister fd, FpuRegister fs);
601 void ClassD(FpuRegister fd, FpuRegister fs);
602 void MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
603 void MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
604 void MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
605 void MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze299a9392015-12-08 16:08:02 -0800606 void CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
607 void CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
608 void CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
609 void CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
610 void CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
611 void CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
612 void CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
613 void CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
614 void CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
615 void CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
616 void CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
617 void CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
618 void CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
619 void CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
620 void CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
621 void CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
622 void CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
623 void CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
624 void CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
625 void CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700626
627 void Cvtsw(FpuRegister fd, FpuRegister fs);
628 void Cvtdw(FpuRegister fd, FpuRegister fs);
629 void Cvtsd(FpuRegister fd, FpuRegister fs);
630 void Cvtds(FpuRegister fd, FpuRegister fs);
Chris Larsen51417632015-10-02 13:24:25 -0700631 void Cvtsl(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700632 void Cvtdl(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800633
634 void Mfc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200635 void Mfhc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700636 void Mtc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200637 void Mthc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700638 void Dmfc1(GpuRegister rt, FpuRegister fs); // MIPS64
639 void Dmtc1(GpuRegister rt, FpuRegister fs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800640 void Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
641 void Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
642 void Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
643 void Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
644
645 void Break();
646 void Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700647 void Move(GpuRegister rd, GpuRegister rs);
648 void Clear(GpuRegister rd);
649 void Not(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800650
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000651 // MSA instructions.
652 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
653 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
654 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
655 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
656
657 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
658 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
659 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
660 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
661 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
662 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
663 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
664 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
665 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
666 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
667 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
668 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
669 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
670 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
671 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
672 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
673 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
674 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
675 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
676 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
677 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
678 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
679 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
680 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
681 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
682 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
683 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
684 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic80248d72017-04-20 11:55:47 +0200685 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
686 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
687 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
688 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
689 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
690 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
691 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
692 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
693 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
694 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
695 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
696 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
697 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
698 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
699 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
700 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
701 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
702 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
703 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
704 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000705
706 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
707 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
708 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
709 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
710 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
711 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
712 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
713 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
714
715 void Ffint_sW(VectorRegister wd, VectorRegister ws);
716 void Ffint_sD(VectorRegister wd, VectorRegister ws);
717 void Ftint_sW(VectorRegister wd, VectorRegister ws);
718 void Ftint_sD(VectorRegister wd, VectorRegister ws);
719
720 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
721 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
722 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
723 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
724 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
725 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
726 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
727 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
728 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
729 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
730 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
731 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
732
733 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
734 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
735 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
736 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
737 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
738 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
739 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
740 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
741 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
742 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
743 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
744 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
745 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
746
747 void MoveV(VectorRegister wd, VectorRegister ws);
748 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
749 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
750 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
751 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
752 void FillB(VectorRegister wd, GpuRegister rs);
753 void FillH(VectorRegister wd, GpuRegister rs);
754 void FillW(VectorRegister wd, GpuRegister rs);
755 void FillD(VectorRegister wd, GpuRegister rs);
756
Goran Jakovljevic3f444032017-03-31 14:38:20 +0200757 void LdiB(VectorRegister wd, int imm8);
758 void LdiH(VectorRegister wd, int imm10);
759 void LdiW(VectorRegister wd, int imm10);
760 void LdiD(VectorRegister wd, int imm10);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000761 void LdB(VectorRegister wd, GpuRegister rs, int offset);
762 void LdH(VectorRegister wd, GpuRegister rs, int offset);
763 void LdW(VectorRegister wd, GpuRegister rs, int offset);
764 void LdD(VectorRegister wd, GpuRegister rs, int offset);
765 void StB(VectorRegister wd, GpuRegister rs, int offset);
766 void StH(VectorRegister wd, GpuRegister rs, int offset);
767 void StW(VectorRegister wd, GpuRegister rs, int offset);
768 void StD(VectorRegister wd, GpuRegister rs, int offset);
769
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700770 // Higher level composite instructions.
Chris Larsenc733dca2016-05-13 16:11:47 -0700771 int InstrCountForLoadReplicatedConst32(int64_t);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700772 void LoadConst32(GpuRegister rd, int32_t value);
773 void LoadConst64(GpuRegister rd, int64_t value); // MIPS64
774
Chris Larsenc733dca2016-05-13 16:11:47 -0700775 // This function is only used for testing purposes.
776 void RecordLoadConst64Path(int value);
777
Alexey Frunze0960ac52016-12-20 17:24:59 -0800778 void Addiu32(GpuRegister rt, GpuRegister rs, int32_t value);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700779 void Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp = AT); // MIPS64
780
Alexey Frunzec061de12017-02-14 13:27:23 -0800781 //
782 // Heap poisoning.
783 //
784
785 // Poison a heap reference contained in `src` and store it in `dst`.
786 void PoisonHeapReference(GpuRegister dst, GpuRegister src) {
787 // dst = -src.
788 // Negate the 32-bit ref.
789 Dsubu(dst, ZERO, src);
790 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
791 Dext(dst, dst, 0, 32);
792 }
793 // Poison a heap reference contained in `reg`.
794 void PoisonHeapReference(GpuRegister reg) {
795 // reg = -reg.
796 PoisonHeapReference(reg, reg);
797 }
798 // Unpoison a heap reference contained in `reg`.
799 void UnpoisonHeapReference(GpuRegister reg) {
800 // reg = -reg.
801 // Negate the 32-bit ref.
802 Dsubu(reg, ZERO, reg);
803 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
804 Dext(reg, reg, 0, 32);
805 }
806 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
807 void MaybePoisonHeapReference(GpuRegister reg) {
808 if (kPoisonHeapReferences) {
809 PoisonHeapReference(reg);
810 }
811 }
812 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
813 void MaybeUnpoisonHeapReference(GpuRegister reg) {
814 if (kPoisonHeapReferences) {
815 UnpoisonHeapReference(reg);
816 }
817 }
818
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700819 void Bind(Label* label) OVERRIDE {
820 Bind(down_cast<Mips64Label*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700821 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700822 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
823 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS64";
824 }
825
826 void Bind(Mips64Label* label);
Igor Murashkinae7ff922016-10-06 14:59:19 -0700827
828 // Don't warn about a different virtual Bind/Jump in the base class.
829 using JNIBase::Bind;
830 using JNIBase::Jump;
831
832 // Create a new label that can be used with Jump/Bind calls.
833 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
834 LOG(FATAL) << "Not implemented on MIPS64";
835 UNREACHABLE();
836 }
837 // Emit an unconditional jump to the label.
838 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
839 LOG(FATAL) << "Not implemented on MIPS64";
840 UNREACHABLE();
841 }
842 // Emit a conditional jump to the label by applying a unary condition test to the register.
843 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
844 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
845 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
846 LOG(FATAL) << "Not implemented on MIPS64";
847 UNREACHABLE();
848 }
849
850 // Code at this offset will serve as the target for the Jump call.
851 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
852 LOG(FATAL) << "Not implemented on MIPS64";
853 UNREACHABLE();
854 }
855
Alexey Frunze19f6c692016-11-30 19:19:55 -0800856 // Create a new literal with a given value.
857 // NOTE: Force the template parameter to be explicitly specified.
858 template <typename T>
859 Literal* NewLiteral(typename Identity<T>::type value) {
860 static_assert(std::is_integral<T>::value, "T must be an integral type.");
861 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
862 }
863
864 // Load label address using PC-relative loads. To be used with data labels in the literal /
865 // jump table area only and not with regular code labels.
866 void LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label);
867
868 // Create a new literal with the given data.
869 Literal* NewLiteral(size_t size, const uint8_t* data);
870
871 // Load literal using PC-relative loads.
872 void LoadLiteral(GpuRegister dest_reg, LoadOperandType load_type, Literal* literal);
873
Alexey Frunze0960ac52016-12-20 17:24:59 -0800874 // Create a jump table for the given labels that will be emitted when finalizing.
875 // When the table is emitted, offsets will be relative to the location of the table.
876 // The table location is determined by the location of its label (the label precedes
877 // the table data) and should be loaded using LoadLabelAddress().
878 JumpTable* CreateJumpTable(std::vector<Mips64Label*>&& labels);
879
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700880 void Bc(Mips64Label* label);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800881 void Balc(Mips64Label* label);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700882 void Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label);
883 void Bltzc(GpuRegister rt, Mips64Label* label);
884 void Bgtzc(GpuRegister rt, Mips64Label* label);
885 void Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label);
886 void Bgezc(GpuRegister rt, Mips64Label* label);
887 void Blezc(GpuRegister rt, Mips64Label* label);
888 void Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label);
889 void Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label);
890 void Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label);
891 void Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label);
892 void Beqzc(GpuRegister rs, Mips64Label* label);
893 void Bnezc(GpuRegister rs, Mips64Label* label);
Alexey Frunze299a9392015-12-08 16:08:02 -0800894 void Bc1eqz(FpuRegister ft, Mips64Label* label);
895 void Bc1nez(FpuRegister ft, Mips64Label* label);
Andreas Gampe57b34292015-01-14 15:45:59 -0800896
897 void EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset, size_t size);
Chris Larsenc3fec0c2016-12-15 11:44:14 -0800898 void AdjustBaseAndOffset(GpuRegister& base, int32_t& offset, bool is_doubleword);
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100899
900 private:
901 // This will be used as an argument for loads/stores
902 // when there is no need for implicit null checks.
903 struct NoImplicitNullChecker {
904 void operator()() const {}
905 };
906
907 public:
908 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevicba89c342017-03-10 13:36:08 +0100909 void StoreConstToOffset(StoreOperandType type,
910 int64_t value,
911 GpuRegister base,
912 int32_t offset,
913 GpuRegister temp,
914 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
915 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
916 // in which case the `base` register may be overwritten in the process.
917 CHECK_NE(temp, AT); // Must not use AT as temp, so as not to overwrite the adjusted base.
Chris Larsenc3fec0c2016-12-15 11:44:14 -0800918 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevicba89c342017-03-10 13:36:08 +0100919 GpuRegister reg;
920 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
921 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
922 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
923 // original `base` (that is, `base` prior to the adjustment), the original `base`
924 // register will be overwritten.
925 if (base == temp) {
926 temp = AT;
927 }
928
929 if (type == kStoreDoubleword && IsAligned<kMips64DoublewordSize>(offset)) {
930 if (value == 0) {
931 reg = ZERO;
932 } else {
933 reg = temp;
934 LoadConst64(reg, value);
935 }
936 Sd(reg, base, offset);
937 null_checker();
938 } else {
939 uint32_t low = Low32Bits(value);
940 uint32_t high = High32Bits(value);
941 if (low == 0) {
942 reg = ZERO;
943 } else {
944 reg = temp;
945 LoadConst32(reg, low);
946 }
947 switch (type) {
948 case kStoreByte:
949 Sb(reg, base, offset);
950 break;
951 case kStoreHalfword:
952 Sh(reg, base, offset);
953 break;
954 case kStoreWord:
955 Sw(reg, base, offset);
956 break;
957 case kStoreDoubleword:
958 // not aligned to kMips64DoublewordSize
959 CHECK_ALIGNED(offset, kMips64WordSize);
960 Sw(reg, base, offset);
961 null_checker();
962 if (high == 0) {
963 reg = ZERO;
964 } else {
965 reg = temp;
966 if (high != low) {
967 LoadConst32(reg, high);
968 }
969 }
970 Sw(reg, base, offset + kMips64WordSize);
971 break;
972 default:
973 LOG(FATAL) << "UNREACHABLE";
974 }
975 if (type != kStoreDoubleword) {
976 null_checker();
977 }
978 }
979 }
980
981 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100982 void LoadFromOffset(LoadOperandType type,
983 GpuRegister reg,
984 GpuRegister base,
985 int32_t offset,
986 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -0800987 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100988
989 switch (type) {
990 case kLoadSignedByte:
991 Lb(reg, base, offset);
992 break;
993 case kLoadUnsignedByte:
994 Lbu(reg, base, offset);
995 break;
996 case kLoadSignedHalfword:
997 Lh(reg, base, offset);
998 break;
999 case kLoadUnsignedHalfword:
1000 Lhu(reg, base, offset);
1001 break;
1002 case kLoadWord:
1003 CHECK_ALIGNED(offset, kMips64WordSize);
1004 Lw(reg, base, offset);
1005 break;
1006 case kLoadUnsignedWord:
1007 CHECK_ALIGNED(offset, kMips64WordSize);
1008 Lwu(reg, base, offset);
1009 break;
1010 case kLoadDoubleword:
1011 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1012 CHECK_ALIGNED(offset, kMips64WordSize);
1013 Lwu(reg, base, offset);
1014 null_checker();
1015 Lwu(TMP2, base, offset + kMips64WordSize);
1016 Dinsu(reg, TMP2, 32, 32);
1017 } else {
1018 Ld(reg, base, offset);
1019 null_checker();
1020 }
1021 break;
1022 }
1023 if (type != kLoadDoubleword) {
1024 null_checker();
1025 }
1026 }
1027
1028 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1029 void LoadFpuFromOffset(LoadOperandType type,
1030 FpuRegister reg,
1031 GpuRegister base,
1032 int32_t offset,
1033 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001034 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001035
1036 switch (type) {
1037 case kLoadWord:
1038 CHECK_ALIGNED(offset, kMips64WordSize);
1039 Lwc1(reg, base, offset);
1040 null_checker();
1041 break;
1042 case kLoadDoubleword:
1043 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1044 CHECK_ALIGNED(offset, kMips64WordSize);
1045 Lwc1(reg, base, offset);
1046 null_checker();
1047 Lw(TMP2, base, offset + kMips64WordSize);
1048 Mthc1(TMP2, reg);
1049 } else {
1050 Ldc1(reg, base, offset);
1051 null_checker();
1052 }
1053 break;
1054 default:
1055 LOG(FATAL) << "UNREACHABLE";
1056 }
1057 }
1058
1059 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1060 void StoreToOffset(StoreOperandType type,
1061 GpuRegister reg,
1062 GpuRegister base,
1063 int32_t offset,
1064 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001065 // Must not use AT as `reg`, so as not to overwrite the value being stored
1066 // with the adjusted `base`.
1067 CHECK_NE(reg, AT);
1068 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001069
1070 switch (type) {
1071 case kStoreByte:
1072 Sb(reg, base, offset);
1073 break;
1074 case kStoreHalfword:
1075 Sh(reg, base, offset);
1076 break;
1077 case kStoreWord:
1078 CHECK_ALIGNED(offset, kMips64WordSize);
1079 Sw(reg, base, offset);
1080 break;
1081 case kStoreDoubleword:
1082 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1083 CHECK_ALIGNED(offset, kMips64WordSize);
1084 Sw(reg, base, offset);
1085 null_checker();
1086 Dsrl32(TMP2, reg, 0);
1087 Sw(TMP2, base, offset + kMips64WordSize);
1088 } else {
1089 Sd(reg, base, offset);
1090 null_checker();
1091 }
1092 break;
1093 default:
1094 LOG(FATAL) << "UNREACHABLE";
1095 }
1096 if (type != kStoreDoubleword) {
1097 null_checker();
1098 }
1099 }
1100
1101 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1102 void StoreFpuToOffset(StoreOperandType type,
1103 FpuRegister reg,
1104 GpuRegister base,
1105 int32_t offset,
1106 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001107 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001108
1109 switch (type) {
1110 case kStoreWord:
1111 CHECK_ALIGNED(offset, kMips64WordSize);
1112 Swc1(reg, base, offset);
1113 null_checker();
1114 break;
1115 case kStoreDoubleword:
1116 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1117 CHECK_ALIGNED(offset, kMips64WordSize);
1118 Mfhc1(TMP2, reg);
1119 Swc1(reg, base, offset);
1120 null_checker();
1121 Sw(TMP2, base, offset + kMips64WordSize);
1122 } else {
1123 Sdc1(reg, base, offset);
1124 null_checker();
1125 }
1126 break;
1127 default:
1128 LOG(FATAL) << "UNREACHABLE";
1129 }
1130 }
1131
Andreas Gampe57b34292015-01-14 15:45:59 -08001132 void LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1133 void LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1134 void StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1135 void StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1136
1137 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001138 void Emit(uint32_t value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001139
1140 //
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001141 // Overridden common assembler high-level functionality.
Andreas Gampe57b34292015-01-14 15:45:59 -08001142 //
1143
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001144 // Emit code that will create an activation on the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001145 void BuildFrame(size_t frame_size,
1146 ManagedRegister method_reg,
1147 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001148 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
1149
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001150 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001151 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001152
1153 void IncreaseFrameSize(size_t adjust) OVERRIDE;
1154 void DecreaseFrameSize(size_t adjust) OVERRIDE;
1155
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001156 // Store routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001157 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
1158 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1159 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1160
1161 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
1162
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001163 void StoreStackOffsetToThread(ThreadOffset64 thr_offs,
1164 FrameOffset fr_offs,
1165 ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001166
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001167 void StoreStackPointerToThread(ThreadOffset64 thr_offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001168
1169 void StoreSpanning(FrameOffset dest, ManagedRegister msrc, FrameOffset in_off,
1170 ManagedRegister mscratch) OVERRIDE;
1171
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001172 // Load routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001173 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
1174
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001175 void LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001176
Mathieu Chartiere401d142015-04-22 13:56:20 -07001177 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001178
Mathieu Chartiere401d142015-04-22 13:56:20 -07001179 void LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001180 bool unpoison_reference) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001181
1182 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
1183
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001184 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001185
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001186 // Copying routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001187 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
1188
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001189 void CopyRawPtrFromThread(FrameOffset fr_offs,
1190 ThreadOffset64 thr_offs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001191 ManagedRegister mscratch) OVERRIDE;
1192
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001193 void CopyRawPtrToThread(ThreadOffset64 thr_offs,
1194 FrameOffset fr_offs,
1195 ManagedRegister mscratch) OVERRIDE;
1196
Andreas Gampe57b34292015-01-14 15:45:59 -08001197 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
1198
1199 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
1200
1201 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister mscratch,
1202 size_t size) OVERRIDE;
1203
1204 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1205 ManagedRegister mscratch, size_t size) OVERRIDE;
1206
1207 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister mscratch,
1208 size_t size) OVERRIDE;
1209
1210 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
1211 ManagedRegister mscratch, size_t size) OVERRIDE;
1212
1213 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1214 ManagedRegister mscratch, size_t size) OVERRIDE;
1215
1216 void MemoryBarrier(ManagedRegister) OVERRIDE;
1217
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001218 // Sign extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001219 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1220
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001221 // Zero extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001222 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1223
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001224 // Exploit fast access in managed code to Thread::Current().
Andreas Gampe57b34292015-01-14 15:45:59 -08001225 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1226 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
1227
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001228 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
Andreas Gampe57b34292015-01-14 15:45:59 -08001229 // value is null and null_allowed. in_reg holds a possibly stale reference
1230 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001231 // null.
Andreas Gampe57b34292015-01-14 15:45:59 -08001232 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
1233 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
1234
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001235 // Set up out_off to hold a Object** into the handle scope, or to be null if the
Andreas Gampe57b34292015-01-14 15:45:59 -08001236 // value is null and null_allowed.
1237 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset, ManagedRegister
1238 mscratch, bool null_allowed) OVERRIDE;
1239
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001240 // src holds a handle scope entry (Object**) load this into dst.
Andreas Gampe57b34292015-01-14 15:45:59 -08001241 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
1242
1243 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1244 // know that src may not be null.
1245 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1246 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
1247
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001248 // Call to address held at [base+offset].
Andreas Gampe57b34292015-01-14 15:45:59 -08001249 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1250 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001251 void CallFromThread(ThreadOffset64 offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001252
1253 // Generate code to check if Thread::Current()->exception_ is non-null
1254 // and branch to a ExceptionSlowPath if it is.
1255 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
1256
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001257 // Emit slow paths queued during assembly and promote short branches to long if needed.
1258 void FinalizeCode() OVERRIDE;
1259
1260 // Emit branches and finalize all instructions.
1261 void FinalizeInstructions(const MemoryRegion& region);
1262
1263 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS64,
1264 // must be used instead of Mips64Label::GetPosition()).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001265 uint32_t GetLabelLocation(const Mips64Label* label) const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001266
1267 // Get the final position of a label after local fixup based on the old position
1268 // recorded before FinalizeCode().
1269 uint32_t GetAdjustedPosition(uint32_t old_position);
1270
Alexey Frunze19f6c692016-11-30 19:19:55 -08001271 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1272 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1273 // to PC.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001274 enum BranchCondition {
1275 kCondLT,
1276 kCondGE,
1277 kCondLE,
1278 kCondGT,
1279 kCondLTZ,
1280 kCondGEZ,
1281 kCondLEZ,
1282 kCondGTZ,
1283 kCondEQ,
1284 kCondNE,
1285 kCondEQZ,
1286 kCondNEZ,
1287 kCondLTU,
1288 kCondGEU,
Alexey Frunze299a9392015-12-08 16:08:02 -08001289 kCondF, // Floating-point predicate false.
1290 kCondT, // Floating-point predicate true.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001291 kUncond,
1292 };
1293 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1294
Andreas Gampe57b34292015-01-14 15:45:59 -08001295 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001296 class Branch {
1297 public:
1298 enum Type {
1299 // Short branches.
1300 kUncondBranch,
1301 kCondBranch,
1302 kCall,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001303 // Near label.
1304 kLabel,
1305 // Near literals.
1306 kLiteral,
1307 kLiteralUnsigned,
1308 kLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001309 // Long branches.
1310 kLongUncondBranch,
1311 kLongCondBranch,
1312 kLongCall,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001313 // Far label.
1314 kFarLabel,
1315 // Far literals.
1316 kFarLiteral,
1317 kFarLiteralUnsigned,
1318 kFarLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001319 };
1320
1321 // Bit sizes of offsets defined as enums to minimize chance of typos.
1322 enum OffsetBits {
1323 kOffset16 = 16,
1324 kOffset18 = 18,
1325 kOffset21 = 21,
1326 kOffset23 = 23,
1327 kOffset28 = 28,
1328 kOffset32 = 32,
1329 };
1330
1331 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1332 static constexpr int32_t kMaxBranchLength = 32;
1333 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
1334
1335 struct BranchInfo {
1336 // Branch length as a number of 4-byte-long instructions.
1337 uint32_t length;
1338 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1339 // PC-relative offset (or its most significant 16-bit half, which goes first).
1340 uint32_t instr_offset;
1341 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1342 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1343 // instructions) from the instruction containing the offset.
1344 uint32_t pc_org;
1345 // How large (in bits) a PC-relative offset can be for a given type of branch (kCondBranch is
1346 // an exception: use kOffset23 for beqzc/bnezc).
1347 OffsetBits offset_size;
1348 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1349 // count.
1350 int offset_shift;
1351 };
1352 static const BranchInfo branch_info_[/* Type */];
1353
Alexey Frunze19f6c692016-11-30 19:19:55 -08001354 // Unconditional branch or call.
1355 Branch(uint32_t location, uint32_t target, bool is_call);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001356 // Conditional branch.
1357 Branch(uint32_t location,
1358 uint32_t target,
1359 BranchCondition condition,
1360 GpuRegister lhs_reg,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001361 GpuRegister rhs_reg);
1362 // Label address (in literal area) or literal.
1363 Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001364
1365 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1366 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1367 // So, we need a way to identify such branches in order to emit no instructions for them
1368 // or change them to unconditional.
1369 static bool IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1370 static bool IsUncond(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1371
1372 static BranchCondition OppositeCondition(BranchCondition cond);
1373
1374 Type GetType() const;
1375 BranchCondition GetCondition() const;
1376 GpuRegister GetLeftRegister() const;
1377 GpuRegister GetRightRegister() const;
1378 uint32_t GetTarget() const;
1379 uint32_t GetLocation() const;
1380 uint32_t GetOldLocation() const;
1381 uint32_t GetLength() const;
1382 uint32_t GetOldLength() const;
1383 uint32_t GetSize() const;
1384 uint32_t GetOldSize() const;
1385 uint32_t GetEndLocation() const;
1386 uint32_t GetOldEndLocation() const;
1387 bool IsLong() const;
1388 bool IsResolved() const;
1389
1390 // Returns the bit size of the signed offset that the branch instruction can handle.
1391 OffsetBits GetOffsetSize() const;
1392
1393 // Calculates the distance between two byte locations in the assembler buffer and
1394 // returns the number of bits needed to represent the distance as a signed integer.
1395 //
1396 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1397 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1398 //
1399 // Composite branches (made of several instructions) with longer reach have 32-bit
1400 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
1401 // The composite branches cover the range of PC + ~+/-2GB. The range is not end-to-end,
1402 // however. Consider the following implementation of a long unconditional branch, for
1403 // example:
1404 //
1405 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1406 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1407 //
1408 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1409 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1410 // due to sign extension. This must be compensated for by incrementing offset_31_16
1411 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1412 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1413 // Therefore, the long branch range is something like from PC - 0x80000000 to
1414 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
1415 //
1416 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1417 // case with the addiu instruction and a 16 bit offset.
1418 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1419
1420 // Resolve a branch when the target is known.
1421 void Resolve(uint32_t target);
1422
1423 // Relocate a branch by a given delta if needed due to expansion of this or another
1424 // branch at a given location by this delta (just changes location_ and target_).
1425 void Relocate(uint32_t expand_location, uint32_t delta);
1426
1427 // If the branch is short, changes its type to long.
1428 void PromoteToLong();
1429
1430 // If necessary, updates the type by promoting a short branch to a long branch
1431 // based on the branch location and target. Returns the amount (in bytes) by
1432 // which the branch size has increased.
1433 // max_short_distance caps the maximum distance between location_ and target_
1434 // that is allowed for short branches. This is for debugging/testing purposes.
1435 // max_short_distance = 0 forces all short branches to become long.
1436 // Use the implicit default argument when not debugging/testing.
1437 uint32_t PromoteIfNeeded(uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
1438
1439 // Returns the location of the instruction(s) containing the offset.
1440 uint32_t GetOffsetLocation() const;
1441
1442 // Calculates and returns the offset ready for encoding in the branch instruction(s).
1443 uint32_t GetOffset() const;
1444
1445 private:
1446 // Completes branch construction by determining and recording its type.
Alexey Frunze19f6c692016-11-30 19:19:55 -08001447 void InitializeType(Type initial_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001448 // Helper for the above.
1449 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1450
1451 uint32_t old_location_; // Offset into assembler buffer in bytes.
1452 uint32_t location_; // Offset into assembler buffer in bytes.
1453 uint32_t target_; // Offset into assembler buffer in bytes.
1454
1455 GpuRegister lhs_reg_; // Left-hand side register in conditional branches or
Alexey Frunze19f6c692016-11-30 19:19:55 -08001456 // destination register in literals.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001457 GpuRegister rhs_reg_; // Right-hand side register in conditional branches.
1458 BranchCondition condition_; // Condition for conditional branches.
1459
1460 Type type_; // Current type of the branch.
1461 Type old_type_; // Initial type of the branch.
1462 };
1463 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1464 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1465
Andreas Gampe57b34292015-01-14 15:45:59 -08001466 void EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001467 void EmitRsd(int opcode, GpuRegister rs, GpuRegister rd, int shamt, int funct);
1468 void EmitRtd(int opcode, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Andreas Gampe57b34292015-01-14 15:45:59 -08001469 void EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001470 void EmitI21(int opcode, GpuRegister rs, uint32_t imm21);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001471 void EmitI26(int opcode, uint32_t imm26);
Andreas Gampe57b34292015-01-14 15:45:59 -08001472 void EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd, int funct);
1473 void EmitFI(int opcode, int fmt, FpuRegister rt, uint16_t imm);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001474 void EmitBcondc(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint32_t imm16_21);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001475 void EmitMsa3R(int operation,
1476 int df,
1477 VectorRegister wt,
1478 VectorRegister ws,
1479 VectorRegister wd,
1480 int minor_opcode);
1481 void EmitMsaBIT(int operation, int df_m, VectorRegister ws, VectorRegister wd, int minor_opcode);
1482 void EmitMsaELM(int operation, int df_n, VectorRegister ws, VectorRegister wd, int minor_opcode);
1483 void EmitMsaMI10(int s10, GpuRegister rs, VectorRegister wd, int minor_opcode, int df);
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001484 void EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001485 void EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1486 void EmitMsa2RF(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001487
1488 void Buncond(Mips64Label* label);
1489 void Bcond(Mips64Label* label,
1490 BranchCondition condition,
1491 GpuRegister lhs,
1492 GpuRegister rhs = ZERO);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001493 void Call(Mips64Label* label);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001494 void FinalizeLabeledBranch(Mips64Label* label);
1495
1496 Branch* GetBranch(uint32_t branch_id);
1497 const Branch* GetBranch(uint32_t branch_id) const;
1498
Alexey Frunze19f6c692016-11-30 19:19:55 -08001499 void EmitLiterals();
Alexey Frunze0960ac52016-12-20 17:24:59 -08001500 void ReserveJumpTableSpace();
1501 void EmitJumpTables();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001502 void PromoteBranches();
1503 void EmitBranch(Branch* branch);
1504 void EmitBranches();
1505 void PatchCFI();
1506
1507 // Emits exception block.
1508 void EmitExceptionPoll(Mips64ExceptionSlowPath* exception);
1509
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001510 bool HasMsa() const {
1511 return has_msa_;
1512 }
1513
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001514 // List of exception blocks to generate at the end of the code cache.
1515 std::vector<Mips64ExceptionSlowPath> exception_blocks_;
1516
1517 std::vector<Branch> branches_;
1518
1519 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1520 bool overwriting_;
1521 // The current overwrite location.
1522 uint32_t overwrite_location_;
1523
Alexey Frunze19f6c692016-11-30 19:19:55 -08001524 // Use std::deque<> for literal labels to allow insertions at the end
1525 // without invalidating pointers and references to existing elements.
1526 ArenaDeque<Literal> literals_;
1527 ArenaDeque<Literal> long_literals_; // 64-bit literals separated for alignment reasons.
1528
Alexey Frunze0960ac52016-12-20 17:24:59 -08001529 // Jump table list.
1530 ArenaDeque<JumpTable> jump_tables_;
1531
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001532 // Data for AdjustedPosition(), see the description there.
1533 uint32_t last_position_adjustment_;
1534 uint32_t last_old_position_;
1535 uint32_t last_branch_id_;
Andreas Gampe57b34292015-01-14 15:45:59 -08001536
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001537 const bool has_msa_;
1538
Andreas Gampe57b34292015-01-14 15:45:59 -08001539 DISALLOW_COPY_AND_ASSIGN(Mips64Assembler);
1540};
1541
Andreas Gampe57b34292015-01-14 15:45:59 -08001542} // namespace mips64
1543} // namespace art
1544
1545#endif // ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_