blob: 2f991e92c5b6b2931b7b0e9c5c2f5858bd66952e [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"
David Sehr1979c642018-04-26 14:41:18 -070027#include "base/globals.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080028#include "base/macros.h"
Andreas Gampe5678db52017-06-08 14:11:18 -070029#include "base/stl_util_identity.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080030#include "constants_mips64.h"
Andreas Gampe09659c22017-09-18 18:23:32 -070031#include "heap_poisoning.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080032#include "managed_register_mips64.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080033#include "offsets.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070034#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070035#include "utils/jni_macro_assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070036#include "utils/label.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080037
38namespace art {
39namespace mips64 {
40
Chris Larsenc733dca2016-05-13 16:11:47 -070041enum LoadConst64Path {
42 kLoadConst64PathZero = 0x0,
43 kLoadConst64PathOri = 0x1,
44 kLoadConst64PathDaddiu = 0x2,
45 kLoadConst64PathLui = 0x4,
46 kLoadConst64PathLuiOri = 0x8,
47 kLoadConst64PathOriDahi = 0x10,
48 kLoadConst64PathOriDati = 0x20,
49 kLoadConst64PathLuiDahi = 0x40,
50 kLoadConst64PathLuiDati = 0x80,
51 kLoadConst64PathDaddiuDsrlX = 0x100,
52 kLoadConst64PathOriDsllX = 0x200,
53 kLoadConst64PathDaddiuDsllX = 0x400,
54 kLoadConst64PathLuiOriDsllX = 0x800,
55 kLoadConst64PathOriDsllXOri = 0x1000,
56 kLoadConst64PathDaddiuDsllXOri = 0x2000,
57 kLoadConst64PathDaddiuDahi = 0x4000,
58 kLoadConst64PathDaddiuDati = 0x8000,
59 kLoadConst64PathDinsu1 = 0x10000,
60 kLoadConst64PathDinsu2 = 0x20000,
61 kLoadConst64PathCatchAll = 0x40000,
62 kLoadConst64PathAllPaths = 0x7ffff,
63};
64
65template <typename Asm>
66void TemplateLoadConst32(Asm* a, GpuRegister rd, int32_t value) {
67 if (IsUint<16>(value)) {
68 // Use OR with (unsigned) immediate to encode 16b unsigned int.
69 a->Ori(rd, ZERO, value);
70 } else if (IsInt<16>(value)) {
71 // Use ADD with (signed) immediate to encode 16b signed int.
72 a->Addiu(rd, ZERO, value);
73 } else {
74 // Set 16 most significant bits of value. The "lui" instruction
75 // also clears the 16 least significant bits to zero.
76 a->Lui(rd, value >> 16);
77 if (value & 0xFFFF) {
78 // If the 16 least significant bits are non-zero, set them
79 // here.
80 a->Ori(rd, rd, value);
81 }
82 }
83}
84
85static inline int InstrCountForLoadReplicatedConst32(int64_t value) {
86 int32_t x = Low32Bits(value);
87 int32_t y = High32Bits(value);
88
89 if (x == y) {
Chris Larsen8859cec2017-08-30 16:40:02 -070090 return (IsUint<16>(x) || IsInt<16>(x) || ((x & 0xFFFF) == 0)) ? 2 : 3;
Chris Larsenc733dca2016-05-13 16:11:47 -070091 }
92
93 return INT_MAX;
94}
95
96template <typename Asm, typename Rtype, typename Vtype>
97void TemplateLoadConst64(Asm* a, Rtype rd, Vtype value) {
98 int bit31 = (value & UINT64_C(0x80000000)) != 0;
99 int rep32_count = InstrCountForLoadReplicatedConst32(value);
100
101 // Loads with 1 instruction.
102 if (IsUint<16>(value)) {
103 // 64-bit value can be loaded as an unsigned 16-bit number.
104 a->RecordLoadConst64Path(kLoadConst64PathOri);
105 a->Ori(rd, ZERO, value);
106 } else if (IsInt<16>(value)) {
107 // 64-bit value can be loaded as an signed 16-bit number.
108 a->RecordLoadConst64Path(kLoadConst64PathDaddiu);
109 a->Daddiu(rd, ZERO, value);
110 } else if ((value & 0xFFFF) == 0 && IsInt<16>(value >> 16)) {
111 // 64-bit value can be loaded as an signed 32-bit number which has all
112 // of its 16 least significant bits set to zero.
113 a->RecordLoadConst64Path(kLoadConst64PathLui);
114 a->Lui(rd, value >> 16);
115 } else if (IsInt<32>(value)) {
116 // Loads with 2 instructions.
117 // 64-bit value can be loaded as an signed 32-bit number which has some
118 // or all of its 16 least significant bits set to one.
119 a->RecordLoadConst64Path(kLoadConst64PathLuiOri);
120 a->Lui(rd, value >> 16);
121 a->Ori(rd, rd, value);
122 } else if ((value & 0xFFFF0000) == 0 && IsInt<16>(value >> 32)) {
123 // 64-bit value which consists of an unsigned 16-bit value in its
124 // least significant 32-bits, and a signed 16-bit value in its
125 // most significant 32-bits.
126 a->RecordLoadConst64Path(kLoadConst64PathOriDahi);
127 a->Ori(rd, ZERO, value);
128 a->Dahi(rd, value >> 32);
129 } else if ((value & UINT64_C(0xFFFFFFFF0000)) == 0) {
130 // 64-bit value which consists of an unsigned 16-bit value in its
131 // least significant 48-bits, and a signed 16-bit value in its
132 // most significant 16-bits.
133 a->RecordLoadConst64Path(kLoadConst64PathOriDati);
134 a->Ori(rd, ZERO, value);
135 a->Dati(rd, value >> 48);
136 } else if ((value & 0xFFFF) == 0 &&
137 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
138 // 16 LSBs (Least Significant Bits) all set to zero.
139 // 48 MSBs (Most Significant Bits) hold a signed 32-bit value.
140 a->RecordLoadConst64Path(kLoadConst64PathLuiDahi);
141 a->Lui(rd, value >> 16);
142 a->Dahi(rd, (value >> 32) + bit31);
143 } else if ((value & 0xFFFF) == 0 && ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
144 // 16 LSBs all set to zero.
145 // 48 MSBs hold a signed value which can't be represented by signed
146 // 32-bit number, and the middle 16 bits are all zero, or all one.
147 a->RecordLoadConst64Path(kLoadConst64PathLuiDati);
148 a->Lui(rd, value >> 16);
149 a->Dati(rd, (value >> 48) + bit31);
150 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
151 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
152 // 32 LSBs contain an unsigned 16-bit number.
153 // 32 MSBs contain a signed 16-bit number.
154 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDahi);
155 a->Daddiu(rd, ZERO, value);
156 a->Dahi(rd, (value >> 32) + bit31);
157 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
158 ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
159 // 48 LSBs contain an unsigned 16-bit number.
160 // 16 MSBs contain a signed 16-bit number.
161 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDati);
162 a->Daddiu(rd, ZERO, value);
163 a->Dati(rd, (value >> 48) + bit31);
164 } else if (IsPowerOfTwo(value + UINT64_C(1))) {
165 // 64-bit values which have their "n" MSBs set to one, and their
166 // "64-n" LSBs set to zero. "n" must meet the restrictions 0 < n < 64.
167 int shift_cnt = 64 - CTZ(value + UINT64_C(1));
168 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsrlX);
169 a->Daddiu(rd, ZERO, -1);
170 if (shift_cnt < 32) {
171 a->Dsrl(rd, rd, shift_cnt);
172 } else {
173 a->Dsrl32(rd, rd, shift_cnt & 31);
174 }
175 } else {
176 int shift_cnt = CTZ(value);
177 int64_t tmp = value >> shift_cnt;
178 a->RecordLoadConst64Path(kLoadConst64PathOriDsllX);
179 if (IsUint<16>(tmp)) {
180 // Value can be computed by loading a 16-bit unsigned value, and
181 // then shifting left.
182 a->Ori(rd, ZERO, tmp);
183 if (shift_cnt < 32) {
184 a->Dsll(rd, rd, shift_cnt);
185 } else {
186 a->Dsll32(rd, rd, shift_cnt & 31);
187 }
188 } else if (IsInt<16>(tmp)) {
189 // Value can be computed by loading a 16-bit signed value, and
190 // then shifting left.
191 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllX);
192 a->Daddiu(rd, ZERO, tmp);
193 if (shift_cnt < 32) {
194 a->Dsll(rd, rd, shift_cnt);
195 } else {
196 a->Dsll32(rd, rd, shift_cnt & 31);
197 }
198 } else if (rep32_count < 3) {
199 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
200 // value loaded into the 32 LSBs can be loaded with a single
201 // MIPS instruction.
202 a->LoadConst32(rd, value);
203 a->Dinsu(rd, rd, 32, 32);
204 a->RecordLoadConst64Path(kLoadConst64PathDinsu1);
205 } else if (IsInt<32>(tmp)) {
206 // Loads with 3 instructions.
207 // Value can be computed by loading a 32-bit signed value, and
208 // then shifting left.
209 a->RecordLoadConst64Path(kLoadConst64PathLuiOriDsllX);
210 a->Lui(rd, tmp >> 16);
211 a->Ori(rd, rd, tmp);
212 if (shift_cnt < 32) {
213 a->Dsll(rd, rd, shift_cnt);
214 } else {
215 a->Dsll32(rd, rd, shift_cnt & 31);
216 }
217 } else {
218 shift_cnt = 16 + CTZ(value >> 16);
219 tmp = value >> shift_cnt;
220 if (IsUint<16>(tmp)) {
221 // Value can be computed by loading a 16-bit unsigned value,
222 // shifting left, and "or"ing in another 16-bit unsigned value.
223 a->RecordLoadConst64Path(kLoadConst64PathOriDsllXOri);
224 a->Ori(rd, ZERO, tmp);
225 if (shift_cnt < 32) {
226 a->Dsll(rd, rd, shift_cnt);
227 } else {
228 a->Dsll32(rd, rd, shift_cnt & 31);
229 }
230 a->Ori(rd, rd, value);
231 } else if (IsInt<16>(tmp)) {
232 // Value can be computed by loading a 16-bit signed value,
233 // shifting left, and "or"ing in a 16-bit unsigned value.
234 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllXOri);
235 a->Daddiu(rd, ZERO, tmp);
236 if (shift_cnt < 32) {
237 a->Dsll(rd, rd, shift_cnt);
238 } else {
239 a->Dsll32(rd, rd, shift_cnt & 31);
240 }
241 a->Ori(rd, rd, value);
242 } else if (rep32_count < 4) {
243 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
244 // value in the 32 LSBs requires 2 MIPS instructions to load.
245 a->LoadConst32(rd, value);
246 a->Dinsu(rd, rd, 32, 32);
247 a->RecordLoadConst64Path(kLoadConst64PathDinsu2);
248 } else {
249 // Loads with 3-4 instructions.
250 // Catch-all case to get any other 64-bit values which aren't
251 // handled by special cases above.
252 uint64_t tmp2 = value;
253 a->RecordLoadConst64Path(kLoadConst64PathCatchAll);
254 a->LoadConst32(rd, value);
255 if (bit31) {
256 tmp2 += UINT64_C(0x100000000);
257 }
258 if (((tmp2 >> 32) & 0xFFFF) != 0) {
259 a->Dahi(rd, tmp2 >> 32);
260 }
261 if (tmp2 & UINT64_C(0x800000000000)) {
262 tmp2 += UINT64_C(0x1000000000000);
263 }
264 if ((tmp2 >> 48) != 0) {
265 a->Dati(rd, tmp2 >> 48);
266 }
267 }
268 }
269 }
270}
271
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000272static constexpr size_t kMips64HalfwordSize = 2;
Lazar Trsicd9672662015-09-03 17:33:01 +0200273static constexpr size_t kMips64WordSize = 4;
274static constexpr size_t kMips64DoublewordSize = 8;
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700275
Andreas Gampe57b34292015-01-14 15:45:59 -0800276enum LoadOperandType {
277 kLoadSignedByte,
278 kLoadUnsignedByte,
279 kLoadSignedHalfword,
280 kLoadUnsignedHalfword,
281 kLoadWord,
Douglas Leungd90957f2015-04-30 19:22:49 -0700282 kLoadUnsignedWord,
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200283 kLoadDoubleword,
284 kLoadQuadword
Andreas Gampe57b34292015-01-14 15:45:59 -0800285};
286
287enum StoreOperandType {
288 kStoreByte,
289 kStoreHalfword,
290 kStoreWord,
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200291 kStoreDoubleword,
292 kStoreQuadword
Andreas Gampe57b34292015-01-14 15:45:59 -0800293};
294
Chris Larsen14500822015-10-01 11:35:18 -0700295// Used to test the values returned by ClassS/ClassD.
296enum FPClassMaskType {
297 kSignalingNaN = 0x001,
298 kQuietNaN = 0x002,
299 kNegativeInfinity = 0x004,
300 kNegativeNormal = 0x008,
301 kNegativeSubnormal = 0x010,
302 kNegativeZero = 0x020,
303 kPositiveInfinity = 0x040,
304 kPositiveNormal = 0x080,
305 kPositiveSubnormal = 0x100,
306 kPositiveZero = 0x200,
307};
308
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700309class Mips64Label : public Label {
310 public:
311 Mips64Label() : prev_branch_id_plus_one_(0) {}
312
313 Mips64Label(Mips64Label&& src)
314 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
315
316 private:
317 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
318
319 friend class Mips64Assembler;
320 DISALLOW_COPY_AND_ASSIGN(Mips64Label);
321};
322
Alexey Frunze19f6c692016-11-30 19:19:55 -0800323// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
324class Literal {
325 public:
326 static constexpr size_t kMaxSize = 8;
327
328 Literal(uint32_t size, const uint8_t* data)
329 : label_(), size_(size) {
330 DCHECK_LE(size, Literal::kMaxSize);
331 memcpy(data_, data, size);
332 }
333
334 template <typename T>
335 T GetValue() const {
336 DCHECK_EQ(size_, sizeof(T));
337 T value;
338 memcpy(&value, data_, sizeof(T));
339 return value;
340 }
341
342 uint32_t GetSize() const {
343 return size_;
344 }
345
346 const uint8_t* GetData() const {
347 return data_;
348 }
349
350 Mips64Label* GetLabel() {
351 return &label_;
352 }
353
354 const Mips64Label* GetLabel() const {
355 return &label_;
356 }
357
358 private:
359 Mips64Label label_;
360 const uint32_t size_;
361 uint8_t data_[kMaxSize];
362
363 DISALLOW_COPY_AND_ASSIGN(Literal);
364};
365
Alexey Frunze0960ac52016-12-20 17:24:59 -0800366// Jump table: table of labels emitted after the code and before the literals. Similar to literals.
367class JumpTable {
368 public:
369 explicit JumpTable(std::vector<Mips64Label*>&& labels)
370 : label_(), labels_(std::move(labels)) {
371 }
372
373 size_t GetSize() const {
374 return labels_.size() * sizeof(uint32_t);
375 }
376
377 const std::vector<Mips64Label*>& GetData() const {
378 return labels_;
379 }
380
381 Mips64Label* GetLabel() {
382 return &label_;
383 }
384
385 const Mips64Label* GetLabel() const {
386 return &label_;
387 }
388
389 private:
390 Mips64Label label_;
391 std::vector<Mips64Label*> labels_;
392
393 DISALLOW_COPY_AND_ASSIGN(JumpTable);
394};
395
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700396// Slowpath entered when Thread::Current()->_exception is non-null.
397class Mips64ExceptionSlowPath {
398 public:
399 explicit Mips64ExceptionSlowPath(Mips64ManagedRegister scratch, size_t stack_adjust)
400 : scratch_(scratch), stack_adjust_(stack_adjust) {}
401
402 Mips64ExceptionSlowPath(Mips64ExceptionSlowPath&& src)
403 : scratch_(src.scratch_),
404 stack_adjust_(src.stack_adjust_),
405 exception_entry_(std::move(src.exception_entry_)) {}
406
407 private:
408 Mips64Label* Entry() { return &exception_entry_; }
409 const Mips64ManagedRegister scratch_;
410 const size_t stack_adjust_;
411 Mips64Label exception_entry_;
412
413 friend class Mips64Assembler;
414 DISALLOW_COPY_AND_ASSIGN(Mips64ExceptionSlowPath);
415};
416
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100417class Mips64Assembler final : public Assembler, public JNIMacroAssembler<PointerSize::k64> {
Andreas Gampe57b34292015-01-14 15:45:59 -0800418 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700419 using JNIBase = JNIMacroAssembler<PointerSize::k64>;
420
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100421 explicit Mips64Assembler(ArenaAllocator* allocator,
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100422 const Mips64InstructionSetFeatures* instruction_set_features = nullptr)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100423 : Assembler(allocator),
Vladimir Marko93205e32016-04-13 11:59:46 +0100424 overwriting_(false),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700425 overwrite_location_(0),
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100426 literals_(allocator->Adapter(kArenaAllocAssembler)),
427 long_literals_(allocator->Adapter(kArenaAllocAssembler)),
428 jump_tables_(allocator->Adapter(kArenaAllocAssembler)),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700429 last_position_adjustment_(0),
430 last_old_position_(0),
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100431 last_branch_id_(0),
432 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700433 cfi().DelayEmittingAdvancePCs();
434 }
435
436 virtual ~Mips64Assembler() {
437 for (auto& branch : branches_) {
438 CHECK(branch.IsResolved());
439 }
440 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800441
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100442 size_t CodeSize() const override { return Assembler::CodeSize(); }
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700443 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
444
Andreas Gampe57b34292015-01-14 15:45:59 -0800445 // Emit Machine Instructions.
Andreas Gampe57b34292015-01-14 15:45:59 -0800446 void Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
447 void Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700448 void Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
449 void Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800450 void Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700451 void Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
452
Alexey Frunzec857c742015-09-23 15:12:39 -0700453 void MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
454 void MuhR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
455 void DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
456 void ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
457 void DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
458 void ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
459 void Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
460 void Dmuh(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
461 void Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
462 void Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
463 void Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
464 void Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800465
466 void And(GpuRegister rd, GpuRegister rs, GpuRegister rt);
467 void Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16);
468 void Or(GpuRegister rd, GpuRegister rs, GpuRegister rt);
469 void Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
470 void Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
471 void Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
472 void Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
473
Alexey Frunzec857c742015-09-23 15:12:39 -0700474 void Bitswap(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800475 void Dbitswap(GpuRegister rd, GpuRegister rt); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700476 void Seb(GpuRegister rd, GpuRegister rt);
477 void Seh(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800478 void Dsbh(GpuRegister rd, GpuRegister rt); // MIPS64
479 void Dshd(GpuRegister rd, GpuRegister rt); // MIPS64
Lazar Trsicd9672662015-09-03 17:33:01 +0200480 void Dext(GpuRegister rs, GpuRegister rt, int pos, int size); // MIPS64
Lena Djokica556e6b2017-12-13 12:09:42 +0100481 void Ins(GpuRegister rt, GpuRegister rs, int pos, int size);
482 void Dins(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
483 void Dinsm(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Lazar Trsicd9672662015-09-03 17:33:01 +0200484 void Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Lena Djokica556e6b2017-12-13 12:09:42 +0100485 void DblIns(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Chris Larsene3660592016-11-09 11:13:42 -0800486 void Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne);
487 void Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700488 void Wsbh(GpuRegister rd, GpuRegister rt);
489 void Sc(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800490 void Scd(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700491 void Ll(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800492 void Lld(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700493
494 void Sll(GpuRegister rd, GpuRegister rt, int shamt);
495 void Srl(GpuRegister rd, GpuRegister rt, int shamt);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700496 void Rotr(GpuRegister rd, GpuRegister rt, int shamt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700497 void Sra(GpuRegister rd, GpuRegister rt, int shamt);
498 void Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
499 void Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Chris Larsen9aebff22015-09-22 17:54:15 -0700500 void Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700501 void Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs);
502 void Dsll(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
503 void Dsrl(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800504 void Drotr(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700505 void Dsra(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
506 void Dsll32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
507 void Dsrl32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700508 void Drotr32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700509 void Dsra32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
510 void Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
511 void Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700512 void Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700513 void Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800514
515 void Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
516 void Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
517 void Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700518 void Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800519 void Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
520 void Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700521 void Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800522 void Lwpc(GpuRegister rs, uint32_t imm19);
523 void Lwupc(GpuRegister rs, uint32_t imm19); // MIPS64
524 void Ldpc(GpuRegister rs, uint32_t imm18); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800525 void Lui(GpuRegister rt, uint16_t imm16);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800526 void Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunzec061de12017-02-14 13:27:23 -0800527 void Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700528 void Dahi(GpuRegister rs, uint16_t imm16); // MIPS64
529 void Dati(GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700530 void Sync(uint32_t stype);
Andreas Gampe57b34292015-01-14 15:45:59 -0800531
532 void Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
533 void Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
534 void Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700535 void Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800536
537 void Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt);
538 void Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
539 void Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16);
540 void Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700541 void Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt);
542 void Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt);
543 void Clz(GpuRegister rd, GpuRegister rs);
544 void Clo(GpuRegister rd, GpuRegister rs);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800545 void Dclz(GpuRegister rd, GpuRegister rs); // MIPS64
546 void Dclo(GpuRegister rd, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800547
Alexey Frunze4dda3372015-06-01 18:31:49 -0700548 void Jalr(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800549 void Jalr(GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700550 void Jr(GpuRegister rs);
Alexey Frunzec857c742015-09-23 15:12:39 -0700551 void Auipc(GpuRegister rs, uint16_t imm16);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700552 void Addiupc(GpuRegister rs, uint32_t imm19);
553 void Bc(uint32_t imm26);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800554 void Balc(uint32_t imm26);
Alexey Frunzec857c742015-09-23 15:12:39 -0700555 void Jic(GpuRegister rt, uint16_t imm16);
556 void Jialc(GpuRegister rt, uint16_t imm16);
557 void Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
558 void Bltzc(GpuRegister rt, uint16_t imm16);
559 void Bgtzc(GpuRegister rt, uint16_t imm16);
560 void Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
561 void Bgezc(GpuRegister rt, uint16_t imm16);
562 void Blezc(GpuRegister rt, uint16_t imm16);
563 void Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
564 void Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
565 void Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
566 void Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
567 void Beqzc(GpuRegister rs, uint32_t imm21);
568 void Bnezc(GpuRegister rs, uint32_t imm21);
Alexey Frunze299a9392015-12-08 16:08:02 -0800569 void Bc1eqz(FpuRegister ft, uint16_t imm16);
570 void Bc1nez(FpuRegister ft, uint16_t imm16);
Alexey Frunze0cab6562017-07-25 15:19:36 -0700571 void Beq(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
572 void Bne(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
573 void Beqz(GpuRegister rt, uint16_t imm16); // R2
574 void Bnez(GpuRegister rt, uint16_t imm16); // R2
575 void Bltz(GpuRegister rt, uint16_t imm16); // R2
576 void Bgez(GpuRegister rt, uint16_t imm16); // R2
577 void Blez(GpuRegister rt, uint16_t imm16); // R2
578 void Bgtz(GpuRegister rt, uint16_t imm16); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -0800579
580 void AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
581 void SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
582 void MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
583 void DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
584 void AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
585 void SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
586 void MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
587 void DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700588 void SqrtS(FpuRegister fd, FpuRegister fs);
589 void SqrtD(FpuRegister fd, FpuRegister fs);
590 void AbsS(FpuRegister fd, FpuRegister fs);
591 void AbsD(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800592 void MovS(FpuRegister fd, FpuRegister fs);
593 void MovD(FpuRegister fd, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700594 void NegS(FpuRegister fd, FpuRegister fs);
595 void NegD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700596 void RoundLS(FpuRegister fd, FpuRegister fs);
597 void RoundLD(FpuRegister fd, FpuRegister fs);
598 void RoundWS(FpuRegister fd, FpuRegister fs);
599 void RoundWD(FpuRegister fd, FpuRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800600 void TruncLS(FpuRegister fd, FpuRegister fs);
601 void TruncLD(FpuRegister fd, FpuRegister fs);
602 void TruncWS(FpuRegister fd, FpuRegister fs);
603 void TruncWD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700604 void CeilLS(FpuRegister fd, FpuRegister fs);
605 void CeilLD(FpuRegister fd, FpuRegister fs);
606 void CeilWS(FpuRegister fd, FpuRegister fs);
607 void CeilWD(FpuRegister fd, FpuRegister fs);
608 void FloorLS(FpuRegister fd, FpuRegister fs);
609 void FloorLD(FpuRegister fd, FpuRegister fs);
610 void FloorWS(FpuRegister fd, FpuRegister fs);
611 void FloorWD(FpuRegister fd, FpuRegister fs);
612 void SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
613 void SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200614 void SeleqzS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
615 void SeleqzD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
616 void SelnezS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
617 void SelnezD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700618 void RintS(FpuRegister fd, FpuRegister fs);
619 void RintD(FpuRegister fd, FpuRegister fs);
620 void ClassS(FpuRegister fd, FpuRegister fs);
621 void ClassD(FpuRegister fd, FpuRegister fs);
622 void MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
623 void MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
624 void MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
625 void MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze299a9392015-12-08 16:08:02 -0800626 void CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
627 void CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
628 void CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
629 void CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
630 void CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
631 void CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
632 void CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
633 void CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
634 void CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
635 void CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
636 void CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
637 void CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
638 void CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
639 void CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
640 void CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
641 void CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
642 void CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
643 void CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
644 void CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
645 void CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700646
647 void Cvtsw(FpuRegister fd, FpuRegister fs);
648 void Cvtdw(FpuRegister fd, FpuRegister fs);
649 void Cvtsd(FpuRegister fd, FpuRegister fs);
650 void Cvtds(FpuRegister fd, FpuRegister fs);
Chris Larsen51417632015-10-02 13:24:25 -0700651 void Cvtsl(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700652 void Cvtdl(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800653
654 void Mfc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200655 void Mfhc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700656 void Mtc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200657 void Mthc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700658 void Dmfc1(GpuRegister rt, FpuRegister fs); // MIPS64
659 void Dmtc1(GpuRegister rt, FpuRegister fs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800660 void Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
661 void Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
662 void Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
663 void Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
664
665 void Break();
666 void Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700667 void Move(GpuRegister rd, GpuRegister rs);
668 void Clear(GpuRegister rd);
669 void Not(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800670
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000671 // MSA instructions.
672 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
673 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
674 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
675 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
676
677 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
678 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
679 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
680 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
681 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
682 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
683 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
684 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Lena Djokic72aba712017-10-30 15:47:20 +0100685 void Asub_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
686 void Asub_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
687 void Asub_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
688 void Asub_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
689 void Asub_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
690 void Asub_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
691 void Asub_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
692 void Asub_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000693 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
694 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
695 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
696 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
697 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
698 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
699 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
700 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
701 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
702 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
703 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
704 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
705 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
706 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
707 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
708 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
709 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
710 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
711 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
712 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic80248d72017-04-20 11:55:47 +0200713 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
714 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
715 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
716 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
717 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
718 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
719 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
720 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
721 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
722 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
723 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
724 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
725 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
726 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
727 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
728 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
729 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
730 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
731 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
732 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200733 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
734 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
735 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
736 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
737 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
738 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
739 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
740 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
741 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
742 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
743 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
744 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
745 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
746 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
747 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
748 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000749
750 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
751 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
752 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
753 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
754 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
755 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
756 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
757 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200758 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
759 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
760 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
761 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000762
763 void Ffint_sW(VectorRegister wd, VectorRegister ws);
764 void Ffint_sD(VectorRegister wd, VectorRegister ws);
765 void Ftint_sW(VectorRegister wd, VectorRegister ws);
766 void Ftint_sD(VectorRegister wd, VectorRegister ws);
767
768 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
769 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
770 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
771 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
772 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
773 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
774 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
775 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
776 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
777 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
778 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
779 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
780
781 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
782 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
783 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
784 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
785 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
786 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
787 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
788 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
789 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
790 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
791 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
792 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
793 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
794
795 void MoveV(VectorRegister wd, VectorRegister ws);
796 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
797 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
798 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
799 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
Lena Djokic3309c012017-10-13 14:34:32 +0200800 void Copy_sB(GpuRegister rd, VectorRegister ws, int n4);
801 void Copy_sH(GpuRegister rd, VectorRegister ws, int n3);
802 void Copy_sW(GpuRegister rd, VectorRegister ws, int n2);
803 void Copy_sD(GpuRegister rd, VectorRegister ws, int n1);
804 void Copy_uB(GpuRegister rd, VectorRegister ws, int n4);
805 void Copy_uH(GpuRegister rd, VectorRegister ws, int n3);
806 void Copy_uW(GpuRegister rd, VectorRegister ws, int n2);
807 void InsertB(VectorRegister wd, GpuRegister rs, int n4);
808 void InsertH(VectorRegister wd, GpuRegister rs, int n3);
809 void InsertW(VectorRegister wd, GpuRegister rs, int n2);
810 void InsertD(VectorRegister wd, GpuRegister rs, int n1);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000811 void FillB(VectorRegister wd, GpuRegister rs);
812 void FillH(VectorRegister wd, GpuRegister rs);
813 void FillW(VectorRegister wd, GpuRegister rs);
814 void FillD(VectorRegister wd, GpuRegister rs);
815
Goran Jakovljevic3f444032017-03-31 14:38:20 +0200816 void LdiB(VectorRegister wd, int imm8);
817 void LdiH(VectorRegister wd, int imm10);
818 void LdiW(VectorRegister wd, int imm10);
819 void LdiD(VectorRegister wd, int imm10);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000820 void LdB(VectorRegister wd, GpuRegister rs, int offset);
821 void LdH(VectorRegister wd, GpuRegister rs, int offset);
822 void LdW(VectorRegister wd, GpuRegister rs, int offset);
823 void LdD(VectorRegister wd, GpuRegister rs, int offset);
824 void StB(VectorRegister wd, GpuRegister rs, int offset);
825 void StH(VectorRegister wd, GpuRegister rs, int offset);
826 void StW(VectorRegister wd, GpuRegister rs, int offset);
827 void StD(VectorRegister wd, GpuRegister rs, int offset);
828
Lena Djokic3309c012017-10-13 14:34:32 +0200829 void IlvlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
830 void IlvlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
831 void IlvlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
832 void IlvlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic38370112017-05-10 14:30:28 +0200833 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
834 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
835 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
836 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Lena Djokic3309c012017-10-13 14:34:32 +0200837 void IlvevB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
838 void IlvevH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
839 void IlvevW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
840 void IlvevD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
841 void IlvodB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
842 void IlvodH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
843 void IlvodW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
844 void IlvodD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic38370112017-05-10 14:30:28 +0200845
Lena Djokicb3d79e42017-07-25 11:20:52 +0200846 void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
847 void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
848 void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
849 void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
850 void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
851 void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
852 void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
853 void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
854 void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
855 void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
856 void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
857 void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
858
Lena Djokic3309c012017-10-13 14:34:32 +0200859 void Hadd_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
860 void Hadd_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
861 void Hadd_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
862 void Hadd_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
863 void Hadd_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
864 void Hadd_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
865
Lena Djokic0d2cab52018-03-06 15:20:45 +0100866 void PcntB(VectorRegister wd, VectorRegister ws);
867 void PcntH(VectorRegister wd, VectorRegister ws);
868 void PcntW(VectorRegister wd, VectorRegister ws);
869 void PcntD(VectorRegister wd, VectorRegister ws);
870
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200871 // Helper for replicating floating point value in all destination elements.
872 void ReplicateFPToVectorRegister(VectorRegister dst, FpuRegister src, bool is_double);
873
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700874 // Higher level composite instructions.
Chris Larsenc733dca2016-05-13 16:11:47 -0700875 int InstrCountForLoadReplicatedConst32(int64_t);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700876 void LoadConst32(GpuRegister rd, int32_t value);
877 void LoadConst64(GpuRegister rd, int64_t value); // MIPS64
878
Chris Larsenc733dca2016-05-13 16:11:47 -0700879 // This function is only used for testing purposes.
880 void RecordLoadConst64Path(int value);
881
Alexey Frunze0960ac52016-12-20 17:24:59 -0800882 void Addiu32(GpuRegister rt, GpuRegister rs, int32_t value);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700883 void Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp = AT); // MIPS64
884
Alexey Frunzec061de12017-02-14 13:27:23 -0800885 //
886 // Heap poisoning.
887 //
888
889 // Poison a heap reference contained in `src` and store it in `dst`.
890 void PoisonHeapReference(GpuRegister dst, GpuRegister src) {
891 // dst = -src.
892 // Negate the 32-bit ref.
893 Dsubu(dst, ZERO, src);
894 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
895 Dext(dst, dst, 0, 32);
896 }
897 // Poison a heap reference contained in `reg`.
898 void PoisonHeapReference(GpuRegister reg) {
899 // reg = -reg.
900 PoisonHeapReference(reg, reg);
901 }
902 // Unpoison a heap reference contained in `reg`.
903 void UnpoisonHeapReference(GpuRegister reg) {
904 // reg = -reg.
905 // Negate the 32-bit ref.
906 Dsubu(reg, ZERO, reg);
907 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
908 Dext(reg, reg, 0, 32);
909 }
910 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
911 void MaybePoisonHeapReference(GpuRegister reg) {
912 if (kPoisonHeapReferences) {
913 PoisonHeapReference(reg);
914 }
915 }
916 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
917 void MaybeUnpoisonHeapReference(GpuRegister reg) {
918 if (kPoisonHeapReferences) {
919 UnpoisonHeapReference(reg);
920 }
921 }
922
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100923 void Bind(Label* label) override {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700924 Bind(down_cast<Mips64Label*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700925 }
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100926 void Jump(Label* label ATTRIBUTE_UNUSED) override {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700927 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS64";
928 }
929
930 void Bind(Mips64Label* label);
Igor Murashkinae7ff922016-10-06 14:59:19 -0700931
932 // Don't warn about a different virtual Bind/Jump in the base class.
933 using JNIBase::Bind;
934 using JNIBase::Jump;
935
936 // Create a new label that can be used with Jump/Bind calls.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100937 std::unique_ptr<JNIMacroLabel> CreateLabel() override {
Igor Murashkinae7ff922016-10-06 14:59:19 -0700938 LOG(FATAL) << "Not implemented on MIPS64";
939 UNREACHABLE();
940 }
941 // Emit an unconditional jump to the label.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100942 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) override {
Igor Murashkinae7ff922016-10-06 14:59:19 -0700943 LOG(FATAL) << "Not implemented on MIPS64";
944 UNREACHABLE();
945 }
946 // Emit a conditional jump to the label by applying a unary condition test to the register.
947 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
948 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100949 ManagedRegister test ATTRIBUTE_UNUSED) override {
Igor Murashkinae7ff922016-10-06 14:59:19 -0700950 LOG(FATAL) << "Not implemented on MIPS64";
951 UNREACHABLE();
952 }
953
954 // Code at this offset will serve as the target for the Jump call.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100955 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) override {
Igor Murashkinae7ff922016-10-06 14:59:19 -0700956 LOG(FATAL) << "Not implemented on MIPS64";
957 UNREACHABLE();
958 }
959
Alexey Frunze19f6c692016-11-30 19:19:55 -0800960 // Create a new literal with a given value.
961 // NOTE: Force the template parameter to be explicitly specified.
962 template <typename T>
963 Literal* NewLiteral(typename Identity<T>::type value) {
964 static_assert(std::is_integral<T>::value, "T must be an integral type.");
965 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
966 }
967
968 // Load label address using PC-relative loads. To be used with data labels in the literal /
969 // jump table area only and not with regular code labels.
970 void LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label);
971
972 // Create a new literal with the given data.
973 Literal* NewLiteral(size_t size, const uint8_t* data);
974
975 // Load literal using PC-relative loads.
976 void LoadLiteral(GpuRegister dest_reg, LoadOperandType load_type, Literal* literal);
977
Alexey Frunze0960ac52016-12-20 17:24:59 -0800978 // Create a jump table for the given labels that will be emitted when finalizing.
979 // When the table is emitted, offsets will be relative to the location of the table.
980 // The table location is determined by the location of its label (the label precedes
981 // the table data) and should be loaded using LoadLabelAddress().
982 JumpTable* CreateJumpTable(std::vector<Mips64Label*>&& labels);
983
Alexey Frunze0cab6562017-07-25 15:19:36 -0700984 // When `is_bare` is false, the branches will promote to long (if the range
985 // of the individual branch instruction is insufficient) and the delay/
986 // forbidden slots will be taken care of.
987 // Use `is_bare = false` when the branch target may be out of reach of the
988 // individual branch instruction. IOW, this is for general purpose use.
989 //
990 // When `is_bare` is true, just the branch instructions will be generated
991 // leaving delay/forbidden slot filling up to the caller and the branches
992 // won't promote to long if the range is insufficient (you'll get a
993 // compilation error when the range is exceeded).
994 // Use `is_bare = true` when the branch target is known to be within reach
995 // of the individual branch instruction. This is intended for small local
996 // optimizations around delay/forbidden slots.
997 // Also prefer using `is_bare = true` if the code near the branch is to be
998 // patched or analyzed at run time (e.g. introspection) to
999 // - show the intent and
1000 // - fail during compilation rather than during patching/execution if the
1001 // bare branch range is insufficent but the code size and layout are
1002 // expected to remain unchanged
1003 //
1004 // R6 compact branches without delay/forbidden slots.
1005 void Bc(Mips64Label* label, bool is_bare = false);
1006 void Balc(Mips64Label* label, bool is_bare = false);
1007 // R6 compact branches with forbidden slots.
1008 void Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1009 void Bltzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
1010 void Bgtzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
1011 void Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1012 void Bgezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
1013 void Blezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
1014 void Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1015 void Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1016 void Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1017 void Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
1018 void Beqzc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
1019 void Bnezc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
1020 // R6 branches with delay slots.
1021 void Bc1eqz(FpuRegister ft, Mips64Label* label, bool is_bare = false);
1022 void Bc1nez(FpuRegister ft, Mips64Label* label, bool is_bare = false);
1023 // R2 branches with delay slots that are also available on R6.
1024 // The `is_bare` parameter exists and is checked in these branches only to
1025 // prevent programming mistakes. These branches never promote to long, not
1026 // even if `is_bare` is false.
1027 void Bltz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1028 void Bgtz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1029 void Bgez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1030 void Blez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1031 void Beq(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1032 void Bne(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
1033 void Beqz(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
1034 void Bnez(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -08001035
1036 void EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset, size_t size);
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001037 void AdjustBaseAndOffset(GpuRegister& base, int32_t& offset, bool is_doubleword);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001038 // If element_size_shift is negative at entry, its value will be calculated based on the offset.
1039 void AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
1040 int32_t& offset,
1041 int& element_size_shift);
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001042
1043 private:
1044 // This will be used as an argument for loads/stores
1045 // when there is no need for implicit null checks.
1046 struct NoImplicitNullChecker {
1047 void operator()() const {}
1048 };
1049
1050 public:
1051 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001052 void StoreConstToOffset(StoreOperandType type,
1053 int64_t value,
1054 GpuRegister base,
1055 int32_t offset,
1056 GpuRegister temp,
1057 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
1058 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
1059 // in which case the `base` register may be overwritten in the process.
1060 CHECK_NE(temp, AT); // Must not use AT as temp, so as not to overwrite the adjusted base.
Andreas Gampe3db70682018-12-26 15:12:03 -08001061 AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword));
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001062 GpuRegister reg;
1063 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
1064 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
1065 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
1066 // original `base` (that is, `base` prior to the adjustment), the original `base`
1067 // register will be overwritten.
1068 if (base == temp) {
1069 temp = AT;
1070 }
1071
1072 if (type == kStoreDoubleword && IsAligned<kMips64DoublewordSize>(offset)) {
1073 if (value == 0) {
1074 reg = ZERO;
1075 } else {
1076 reg = temp;
1077 LoadConst64(reg, value);
1078 }
1079 Sd(reg, base, offset);
1080 null_checker();
1081 } else {
1082 uint32_t low = Low32Bits(value);
1083 uint32_t high = High32Bits(value);
1084 if (low == 0) {
1085 reg = ZERO;
1086 } else {
1087 reg = temp;
1088 LoadConst32(reg, low);
1089 }
1090 switch (type) {
1091 case kStoreByte:
1092 Sb(reg, base, offset);
1093 break;
1094 case kStoreHalfword:
1095 Sh(reg, base, offset);
1096 break;
1097 case kStoreWord:
1098 Sw(reg, base, offset);
1099 break;
1100 case kStoreDoubleword:
1101 // not aligned to kMips64DoublewordSize
1102 CHECK_ALIGNED(offset, kMips64WordSize);
1103 Sw(reg, base, offset);
1104 null_checker();
1105 if (high == 0) {
1106 reg = ZERO;
1107 } else {
1108 reg = temp;
1109 if (high != low) {
1110 LoadConst32(reg, high);
1111 }
1112 }
1113 Sw(reg, base, offset + kMips64WordSize);
1114 break;
1115 default:
1116 LOG(FATAL) << "UNREACHABLE";
1117 }
1118 if (type != kStoreDoubleword) {
1119 null_checker();
1120 }
1121 }
1122 }
1123
1124 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001125 void LoadFromOffset(LoadOperandType type,
1126 GpuRegister reg,
1127 GpuRegister base,
1128 int32_t offset,
1129 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Andreas Gampe3db70682018-12-26 15:12:03 -08001130 AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kLoadDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001131
1132 switch (type) {
1133 case kLoadSignedByte:
1134 Lb(reg, base, offset);
1135 break;
1136 case kLoadUnsignedByte:
1137 Lbu(reg, base, offset);
1138 break;
1139 case kLoadSignedHalfword:
1140 Lh(reg, base, offset);
1141 break;
1142 case kLoadUnsignedHalfword:
1143 Lhu(reg, base, offset);
1144 break;
1145 case kLoadWord:
1146 CHECK_ALIGNED(offset, kMips64WordSize);
1147 Lw(reg, base, offset);
1148 break;
1149 case kLoadUnsignedWord:
1150 CHECK_ALIGNED(offset, kMips64WordSize);
1151 Lwu(reg, base, offset);
1152 break;
1153 case kLoadDoubleword:
1154 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1155 CHECK_ALIGNED(offset, kMips64WordSize);
1156 Lwu(reg, base, offset);
1157 null_checker();
1158 Lwu(TMP2, base, offset + kMips64WordSize);
1159 Dinsu(reg, TMP2, 32, 32);
1160 } else {
1161 Ld(reg, base, offset);
1162 null_checker();
1163 }
1164 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001165 default:
1166 LOG(FATAL) << "UNREACHABLE";
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001167 }
1168 if (type != kLoadDoubleword) {
1169 null_checker();
1170 }
1171 }
1172
1173 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1174 void LoadFpuFromOffset(LoadOperandType type,
1175 FpuRegister reg,
1176 GpuRegister base,
1177 int32_t offset,
1178 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001179 int element_size_shift = -1;
1180 if (type != kLoadQuadword) {
Andreas Gampe3db70682018-12-26 15:12:03 -08001181 AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kLoadDoubleword));
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001182 } else {
1183 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1184 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001185
1186 switch (type) {
1187 case kLoadWord:
1188 CHECK_ALIGNED(offset, kMips64WordSize);
1189 Lwc1(reg, base, offset);
1190 null_checker();
1191 break;
1192 case kLoadDoubleword:
1193 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1194 CHECK_ALIGNED(offset, kMips64WordSize);
1195 Lwc1(reg, base, offset);
1196 null_checker();
1197 Lw(TMP2, base, offset + kMips64WordSize);
1198 Mthc1(TMP2, reg);
1199 } else {
1200 Ldc1(reg, base, offset);
1201 null_checker();
1202 }
1203 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001204 case kLoadQuadword:
1205 switch (element_size_shift) {
1206 case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break;
1207 case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break;
1208 case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break;
1209 case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break;
1210 default:
1211 LOG(FATAL) << "UNREACHABLE";
1212 }
1213 null_checker();
1214 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001215 default:
1216 LOG(FATAL) << "UNREACHABLE";
1217 }
1218 }
1219
1220 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1221 void StoreToOffset(StoreOperandType type,
1222 GpuRegister reg,
1223 GpuRegister base,
1224 int32_t offset,
1225 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001226 // Must not use AT as `reg`, so as not to overwrite the value being stored
1227 // with the adjusted `base`.
1228 CHECK_NE(reg, AT);
Andreas Gampe3db70682018-12-26 15:12:03 -08001229 AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001230
1231 switch (type) {
1232 case kStoreByte:
1233 Sb(reg, base, offset);
1234 break;
1235 case kStoreHalfword:
1236 Sh(reg, base, offset);
1237 break;
1238 case kStoreWord:
1239 CHECK_ALIGNED(offset, kMips64WordSize);
1240 Sw(reg, base, offset);
1241 break;
1242 case kStoreDoubleword:
1243 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1244 CHECK_ALIGNED(offset, kMips64WordSize);
1245 Sw(reg, base, offset);
1246 null_checker();
1247 Dsrl32(TMP2, reg, 0);
1248 Sw(TMP2, base, offset + kMips64WordSize);
1249 } else {
1250 Sd(reg, base, offset);
1251 null_checker();
1252 }
1253 break;
1254 default:
1255 LOG(FATAL) << "UNREACHABLE";
1256 }
1257 if (type != kStoreDoubleword) {
1258 null_checker();
1259 }
1260 }
1261
1262 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1263 void StoreFpuToOffset(StoreOperandType type,
1264 FpuRegister reg,
1265 GpuRegister base,
1266 int32_t offset,
1267 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001268 int element_size_shift = -1;
1269 if (type != kStoreQuadword) {
Andreas Gampe3db70682018-12-26 15:12:03 -08001270 AdjustBaseAndOffset(base, offset, /* is_doubleword= */ (type == kStoreDoubleword));
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001271 } else {
1272 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1273 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001274
1275 switch (type) {
1276 case kStoreWord:
1277 CHECK_ALIGNED(offset, kMips64WordSize);
1278 Swc1(reg, base, offset);
1279 null_checker();
1280 break;
1281 case kStoreDoubleword:
1282 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1283 CHECK_ALIGNED(offset, kMips64WordSize);
1284 Mfhc1(TMP2, reg);
1285 Swc1(reg, base, offset);
1286 null_checker();
1287 Sw(TMP2, base, offset + kMips64WordSize);
1288 } else {
1289 Sdc1(reg, base, offset);
1290 null_checker();
1291 }
1292 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001293 case kStoreQuadword:
1294 switch (element_size_shift) {
1295 case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break;
1296 case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break;
1297 case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break;
1298 case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break;
1299 default:
1300 LOG(FATAL) << "UNREACHABLE";
1301 }
1302 null_checker();
1303 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001304 default:
1305 LOG(FATAL) << "UNREACHABLE";
1306 }
1307 }
1308
Andreas Gampe57b34292015-01-14 15:45:59 -08001309 void LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1310 void LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1311 void StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1312 void StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1313
1314 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001315 void Emit(uint32_t value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001316
1317 //
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001318 // Overridden common assembler high-level functionality.
Andreas Gampe57b34292015-01-14 15:45:59 -08001319 //
1320
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001321 // Emit code that will create an activation on the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001322 void BuildFrame(size_t frame_size,
1323 ManagedRegister method_reg,
1324 ArrayRef<const ManagedRegister> callee_save_regs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001325 const ManagedRegisterEntrySpills& entry_spills) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001326
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001327 // Emit code that will remove an activation from the stack.
Roland Levillain0d127e12017-07-05 17:01:11 +01001328 void RemoveFrame(size_t frame_size,
1329 ArrayRef<const ManagedRegister> callee_save_regs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001330 bool may_suspend) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001331
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001332 void IncreaseFrameSize(size_t adjust) override;
1333 void DecreaseFrameSize(size_t adjust) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001334
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001335 // Store routines.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001336 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) override;
1337 void StoreRef(FrameOffset dest, ManagedRegister msrc) override;
1338 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001339
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001340 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001341
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001342 void StoreStackOffsetToThread(ThreadOffset64 thr_offs,
1343 FrameOffset fr_offs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001344 ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001345
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001346 void StoreStackPointerToThread(ThreadOffset64 thr_offs) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001347
1348 void StoreSpanning(FrameOffset dest, ManagedRegister msrc, FrameOffset in_off,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001349 ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001350
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001351 // Load routines.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001352 void Load(ManagedRegister mdest, FrameOffset src, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001353
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001354 void LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001355
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001356 void LoadRef(ManagedRegister dest, FrameOffset src) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001357
Mathieu Chartiere401d142015-04-22 13:56:20 -07001358 void LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001359 bool unpoison_reference) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001360
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001361 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001362
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001363 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001364
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001365 // Copying routines.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001366 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001367
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001368 void CopyRawPtrFromThread(FrameOffset fr_offs,
1369 ThreadOffset64 thr_offs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001370 ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001371
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001372 void CopyRawPtrToThread(ThreadOffset64 thr_offs,
1373 FrameOffset fr_offs,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001374 ManagedRegister mscratch) override;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001375
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001376 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001377
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001378 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001379
1380 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister mscratch,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001381 size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001382
1383 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001384 ManagedRegister mscratch, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001385
1386 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister mscratch,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001387 size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001388
1389 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001390 ManagedRegister mscratch, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001391
1392 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001393 ManagedRegister mscratch, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001394
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001395 void MemoryBarrier(ManagedRegister) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001396
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001397 // Sign extension.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001398 void SignExtend(ManagedRegister mreg, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001399
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001400 // Zero extension.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001401 void ZeroExtend(ManagedRegister mreg, size_t size) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001402
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001403 // Exploit fast access in managed code to Thread::Current().
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001404 void GetCurrentThread(ManagedRegister tr) override;
1405 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001406
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001407 // 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 -08001408 // value is null and null_allowed. in_reg holds a possibly stale reference
1409 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001410 // null.
Andreas Gampe57b34292015-01-14 15:45:59 -08001411 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001412 ManagedRegister in_reg, bool null_allowed) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001413
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001414 // 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 -08001415 // value is null and null_allowed.
1416 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset, ManagedRegister
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001417 mscratch, bool null_allowed) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001418
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001419 // src holds a handle scope entry (Object**) load this into dst.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001420 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001421
1422 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1423 // know that src may not be null.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001424 void VerifyObject(ManagedRegister src, bool could_be_null) override;
1425 void VerifyObject(FrameOffset src, bool could_be_null) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001426
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001427 // Call to address held at [base+offset].
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001428 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) override;
1429 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) override;
1430 void CallFromThread(ThreadOffset64 offset, ManagedRegister mscratch) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001431
1432 // Generate code to check if Thread::Current()->exception_ is non-null
1433 // and branch to a ExceptionSlowPath if it is.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001434 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) override;
Andreas Gampe57b34292015-01-14 15:45:59 -08001435
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001436 // Emit slow paths queued during assembly and promote short branches to long if needed.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001437 void FinalizeCode() override;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001438
1439 // Emit branches and finalize all instructions.
1440 void FinalizeInstructions(const MemoryRegion& region);
1441
1442 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS64,
1443 // must be used instead of Mips64Label::GetPosition()).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001444 uint32_t GetLabelLocation(const Mips64Label* label) const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001445
1446 // Get the final position of a label after local fixup based on the old position
1447 // recorded before FinalizeCode().
1448 uint32_t GetAdjustedPosition(uint32_t old_position);
1449
Alexey Frunze19f6c692016-11-30 19:19:55 -08001450 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1451 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1452 // to PC.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001453 enum BranchCondition {
1454 kCondLT,
1455 kCondGE,
1456 kCondLE,
1457 kCondGT,
1458 kCondLTZ,
1459 kCondGEZ,
1460 kCondLEZ,
1461 kCondGTZ,
1462 kCondEQ,
1463 kCondNE,
1464 kCondEQZ,
1465 kCondNEZ,
1466 kCondLTU,
1467 kCondGEU,
Alexey Frunze299a9392015-12-08 16:08:02 -08001468 kCondF, // Floating-point predicate false.
1469 kCondT, // Floating-point predicate true.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001470 kUncond,
1471 };
1472 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1473
Andreas Gampe57b34292015-01-14 15:45:59 -08001474 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001475 class Branch {
1476 public:
1477 enum Type {
Alexey Frunze0cab6562017-07-25 15:19:36 -07001478 // R6 short branches (can be promoted to long).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001479 kUncondBranch,
1480 kCondBranch,
1481 kCall,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001482 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
1483 kBareUncondBranch,
1484 kBareCondBranch,
1485 kBareCall,
1486 // R2 short branches (can't be promoted to long), delay slots filled manually.
1487 kR2BareCondBranch,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001488 // Near label.
1489 kLabel,
1490 // Near literals.
1491 kLiteral,
1492 kLiteralUnsigned,
1493 kLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001494 // Long branches.
1495 kLongUncondBranch,
1496 kLongCondBranch,
1497 kLongCall,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001498 // Far label.
1499 kFarLabel,
1500 // Far literals.
1501 kFarLiteral,
1502 kFarLiteralUnsigned,
1503 kFarLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001504 };
1505
1506 // Bit sizes of offsets defined as enums to minimize chance of typos.
1507 enum OffsetBits {
1508 kOffset16 = 16,
1509 kOffset18 = 18,
1510 kOffset21 = 21,
1511 kOffset23 = 23,
1512 kOffset28 = 28,
1513 kOffset32 = 32,
1514 };
1515
1516 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1517 static constexpr int32_t kMaxBranchLength = 32;
1518 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
1519
1520 struct BranchInfo {
1521 // Branch length as a number of 4-byte-long instructions.
1522 uint32_t length;
1523 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1524 // PC-relative offset (or its most significant 16-bit half, which goes first).
1525 uint32_t instr_offset;
1526 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1527 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1528 // instructions) from the instruction containing the offset.
1529 uint32_t pc_org;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001530 // How large (in bits) a PC-relative offset can be for a given type of branch (kCondBranch
1531 // and kBareCondBranch are an exception: use kOffset23 for beqzc/bnezc).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001532 OffsetBits offset_size;
1533 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1534 // count.
1535 int offset_shift;
1536 };
1537 static const BranchInfo branch_info_[/* Type */];
1538
Alexey Frunze19f6c692016-11-30 19:19:55 -08001539 // Unconditional branch or call.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001540 Branch(uint32_t location, uint32_t target, bool is_call, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001541 // Conditional branch.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001542 Branch(bool is_r6,
1543 uint32_t location,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001544 uint32_t target,
1545 BranchCondition condition,
1546 GpuRegister lhs_reg,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001547 GpuRegister rhs_reg,
1548 bool is_bare);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001549 // Label address (in literal area) or literal.
1550 Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001551
1552 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1553 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1554 // So, we need a way to identify such branches in order to emit no instructions for them
1555 // or change them to unconditional.
1556 static bool IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1557 static bool IsUncond(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1558
1559 static BranchCondition OppositeCondition(BranchCondition cond);
1560
1561 Type GetType() const;
1562 BranchCondition GetCondition() const;
1563 GpuRegister GetLeftRegister() const;
1564 GpuRegister GetRightRegister() const;
1565 uint32_t GetTarget() const;
1566 uint32_t GetLocation() const;
1567 uint32_t GetOldLocation() const;
1568 uint32_t GetLength() const;
1569 uint32_t GetOldLength() const;
1570 uint32_t GetSize() const;
1571 uint32_t GetOldSize() const;
1572 uint32_t GetEndLocation() const;
1573 uint32_t GetOldEndLocation() const;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001574 bool IsBare() const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001575 bool IsLong() const;
1576 bool IsResolved() const;
1577
1578 // Returns the bit size of the signed offset that the branch instruction can handle.
1579 OffsetBits GetOffsetSize() const;
1580
1581 // Calculates the distance between two byte locations in the assembler buffer and
1582 // returns the number of bits needed to represent the distance as a signed integer.
1583 //
1584 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1585 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1586 //
1587 // Composite branches (made of several instructions) with longer reach have 32-bit
1588 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
1589 // The composite branches cover the range of PC + ~+/-2GB. The range is not end-to-end,
1590 // however. Consider the following implementation of a long unconditional branch, for
1591 // example:
1592 //
1593 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1594 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1595 //
1596 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1597 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1598 // due to sign extension. This must be compensated for by incrementing offset_31_16
1599 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1600 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1601 // Therefore, the long branch range is something like from PC - 0x80000000 to
1602 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
1603 //
1604 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1605 // case with the addiu instruction and a 16 bit offset.
1606 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1607
1608 // Resolve a branch when the target is known.
1609 void Resolve(uint32_t target);
1610
1611 // Relocate a branch by a given delta if needed due to expansion of this or another
1612 // branch at a given location by this delta (just changes location_ and target_).
1613 void Relocate(uint32_t expand_location, uint32_t delta);
1614
1615 // If the branch is short, changes its type to long.
1616 void PromoteToLong();
1617
1618 // If necessary, updates the type by promoting a short branch to a long branch
1619 // based on the branch location and target. Returns the amount (in bytes) by
1620 // which the branch size has increased.
1621 // max_short_distance caps the maximum distance between location_ and target_
1622 // that is allowed for short branches. This is for debugging/testing purposes.
1623 // max_short_distance = 0 forces all short branches to become long.
1624 // Use the implicit default argument when not debugging/testing.
1625 uint32_t PromoteIfNeeded(uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
1626
1627 // Returns the location of the instruction(s) containing the offset.
1628 uint32_t GetOffsetLocation() const;
1629
1630 // Calculates and returns the offset ready for encoding in the branch instruction(s).
1631 uint32_t GetOffset() const;
1632
1633 private:
1634 // Completes branch construction by determining and recording its type.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001635 void InitializeType(Type initial_type, bool is_r6);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001636 // Helper for the above.
1637 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1638
1639 uint32_t old_location_; // Offset into assembler buffer in bytes.
1640 uint32_t location_; // Offset into assembler buffer in bytes.
1641 uint32_t target_; // Offset into assembler buffer in bytes.
1642
1643 GpuRegister lhs_reg_; // Left-hand side register in conditional branches or
Alexey Frunze19f6c692016-11-30 19:19:55 -08001644 // destination register in literals.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001645 GpuRegister rhs_reg_; // Right-hand side register in conditional branches.
1646 BranchCondition condition_; // Condition for conditional branches.
1647
1648 Type type_; // Current type of the branch.
1649 Type old_type_; // Initial type of the branch.
1650 };
1651 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1652 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1653
Andreas Gampe57b34292015-01-14 15:45:59 -08001654 void EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001655 void EmitRsd(int opcode, GpuRegister rs, GpuRegister rd, int shamt, int funct);
1656 void EmitRtd(int opcode, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Andreas Gampe57b34292015-01-14 15:45:59 -08001657 void EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001658 void EmitI21(int opcode, GpuRegister rs, uint32_t imm21);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001659 void EmitI26(int opcode, uint32_t imm26);
Andreas Gampe57b34292015-01-14 15:45:59 -08001660 void EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd, int funct);
1661 void EmitFI(int opcode, int fmt, FpuRegister rt, uint16_t imm);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001662 void EmitBcondR6(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint32_t imm16_21);
1663 void EmitBcondR2(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint16_t imm16);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001664 void EmitMsa3R(int operation,
1665 int df,
1666 VectorRegister wt,
1667 VectorRegister ws,
1668 VectorRegister wd,
1669 int minor_opcode);
1670 void EmitMsaBIT(int operation, int df_m, VectorRegister ws, VectorRegister wd, int minor_opcode);
1671 void EmitMsaELM(int operation, int df_n, VectorRegister ws, VectorRegister wd, int minor_opcode);
1672 void EmitMsaMI10(int s10, GpuRegister rs, VectorRegister wd, int minor_opcode, int df);
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001673 void EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001674 void EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1675 void EmitMsa2RF(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001676
Alexey Frunze0cab6562017-07-25 15:19:36 -07001677 void Buncond(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001678 void Bcond(Mips64Label* label,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001679 bool is_r6,
1680 bool is_bare,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001681 BranchCondition condition,
1682 GpuRegister lhs,
1683 GpuRegister rhs = ZERO);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001684 void Call(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001685 void FinalizeLabeledBranch(Mips64Label* label);
1686
1687 Branch* GetBranch(uint32_t branch_id);
1688 const Branch* GetBranch(uint32_t branch_id) const;
1689
Alexey Frunze19f6c692016-11-30 19:19:55 -08001690 void EmitLiterals();
Alexey Frunze0960ac52016-12-20 17:24:59 -08001691 void ReserveJumpTableSpace();
1692 void EmitJumpTables();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001693 void PromoteBranches();
1694 void EmitBranch(Branch* branch);
1695 void EmitBranches();
1696 void PatchCFI();
1697
1698 // Emits exception block.
1699 void EmitExceptionPoll(Mips64ExceptionSlowPath* exception);
1700
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001701 bool HasMsa() const {
1702 return has_msa_;
1703 }
1704
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001705 // List of exception blocks to generate at the end of the code cache.
1706 std::vector<Mips64ExceptionSlowPath> exception_blocks_;
1707
1708 std::vector<Branch> branches_;
1709
1710 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1711 bool overwriting_;
1712 // The current overwrite location.
1713 uint32_t overwrite_location_;
1714
Alexey Frunze19f6c692016-11-30 19:19:55 -08001715 // Use std::deque<> for literal labels to allow insertions at the end
1716 // without invalidating pointers and references to existing elements.
1717 ArenaDeque<Literal> literals_;
1718 ArenaDeque<Literal> long_literals_; // 64-bit literals separated for alignment reasons.
1719
Alexey Frunze0960ac52016-12-20 17:24:59 -08001720 // Jump table list.
1721 ArenaDeque<JumpTable> jump_tables_;
1722
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001723 // Data for AdjustedPosition(), see the description there.
1724 uint32_t last_position_adjustment_;
1725 uint32_t last_old_position_;
1726 uint32_t last_branch_id_;
Andreas Gampe57b34292015-01-14 15:45:59 -08001727
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001728 const bool has_msa_;
1729
Andreas Gampe57b34292015-01-14 15:45:59 -08001730 DISALLOW_COPY_AND_ASSIGN(Mips64Assembler);
1731};
1732
Andreas Gampe57b34292015-01-14 15:45:59 -08001733} // namespace mips64
1734} // namespace art
1735
1736#endif // ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_