blob: bb54382811d81f1f270a072e18f79565faf9c4d7 [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"
Andreas Gampe5678db52017-06-08 14:11:18 -070028#include "base/stl_util_identity.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080029#include "constants_mips64.h"
30#include "globals.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
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700417class 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
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100421 explicit Mips64Assembler(ArenaAllocator* arena,
422 const Mips64InstructionSetFeatures* instruction_set_features = nullptr)
Vladimir Marko93205e32016-04-13 11:59:46 +0100423 : Assembler(arena),
424 overwriting_(false),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700425 overwrite_location_(0),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800426 literals_(arena->Adapter(kArenaAllocAssembler)),
427 long_literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze0960ac52016-12-20 17:24:59 -0800428 jump_tables_(arena->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
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700442 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
443 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
481 void Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Chris Larsene3660592016-11-09 11:13:42 -0800482 void Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne);
483 void Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700484 void Wsbh(GpuRegister rd, GpuRegister rt);
485 void Sc(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800486 void Scd(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700487 void Ll(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800488 void Lld(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700489
490 void Sll(GpuRegister rd, GpuRegister rt, int shamt);
491 void Srl(GpuRegister rd, GpuRegister rt, int shamt);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700492 void Rotr(GpuRegister rd, GpuRegister rt, int shamt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700493 void Sra(GpuRegister rd, GpuRegister rt, int shamt);
494 void Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
495 void Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Chris Larsen9aebff22015-09-22 17:54:15 -0700496 void Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700497 void Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs);
498 void Dsll(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
499 void Dsrl(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800500 void Drotr(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700501 void Dsra(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
502 void Dsll32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
503 void Dsrl32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700504 void Drotr32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700505 void Dsra32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
506 void Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
507 void Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700508 void Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700509 void Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800510
511 void Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
512 void Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
513 void Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700514 void Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800515 void Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
516 void Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700517 void Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800518 void Lwpc(GpuRegister rs, uint32_t imm19);
519 void Lwupc(GpuRegister rs, uint32_t imm19); // MIPS64
520 void Ldpc(GpuRegister rs, uint32_t imm18); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800521 void Lui(GpuRegister rt, uint16_t imm16);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800522 void Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunzec061de12017-02-14 13:27:23 -0800523 void Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700524 void Dahi(GpuRegister rs, uint16_t imm16); // MIPS64
525 void Dati(GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700526 void Sync(uint32_t stype);
Andreas Gampe57b34292015-01-14 15:45:59 -0800527
528 void Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
529 void Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
530 void Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700531 void Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800532
533 void Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt);
534 void Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
535 void Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16);
536 void Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700537 void Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt);
538 void Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt);
539 void Clz(GpuRegister rd, GpuRegister rs);
540 void Clo(GpuRegister rd, GpuRegister rs);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800541 void Dclz(GpuRegister rd, GpuRegister rs); // MIPS64
542 void Dclo(GpuRegister rd, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800543
Alexey Frunze4dda3372015-06-01 18:31:49 -0700544 void Jalr(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800545 void Jalr(GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700546 void Jr(GpuRegister rs);
Alexey Frunzec857c742015-09-23 15:12:39 -0700547 void Auipc(GpuRegister rs, uint16_t imm16);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700548 void Addiupc(GpuRegister rs, uint32_t imm19);
549 void Bc(uint32_t imm26);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800550 void Balc(uint32_t imm26);
Alexey Frunzec857c742015-09-23 15:12:39 -0700551 void Jic(GpuRegister rt, uint16_t imm16);
552 void Jialc(GpuRegister rt, uint16_t imm16);
553 void Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
554 void Bltzc(GpuRegister rt, uint16_t imm16);
555 void Bgtzc(GpuRegister rt, uint16_t imm16);
556 void Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
557 void Bgezc(GpuRegister rt, uint16_t imm16);
558 void Blezc(GpuRegister rt, uint16_t imm16);
559 void Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
560 void Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
561 void Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
562 void Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
563 void Beqzc(GpuRegister rs, uint32_t imm21);
564 void Bnezc(GpuRegister rs, uint32_t imm21);
Alexey Frunze299a9392015-12-08 16:08:02 -0800565 void Bc1eqz(FpuRegister ft, uint16_t imm16);
566 void Bc1nez(FpuRegister ft, uint16_t imm16);
Alexey Frunze0cab6562017-07-25 15:19:36 -0700567 void Beq(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
568 void Bne(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
569 void Beqz(GpuRegister rt, uint16_t imm16); // R2
570 void Bnez(GpuRegister rt, uint16_t imm16); // R2
571 void Bltz(GpuRegister rt, uint16_t imm16); // R2
572 void Bgez(GpuRegister rt, uint16_t imm16); // R2
573 void Blez(GpuRegister rt, uint16_t imm16); // R2
574 void Bgtz(GpuRegister rt, uint16_t imm16); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -0800575
576 void AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
577 void SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
578 void MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
579 void DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
580 void AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
581 void SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
582 void MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
583 void DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700584 void SqrtS(FpuRegister fd, FpuRegister fs);
585 void SqrtD(FpuRegister fd, FpuRegister fs);
586 void AbsS(FpuRegister fd, FpuRegister fs);
587 void AbsD(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800588 void MovS(FpuRegister fd, FpuRegister fs);
589 void MovD(FpuRegister fd, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700590 void NegS(FpuRegister fd, FpuRegister fs);
591 void NegD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700592 void RoundLS(FpuRegister fd, FpuRegister fs);
593 void RoundLD(FpuRegister fd, FpuRegister fs);
594 void RoundWS(FpuRegister fd, FpuRegister fs);
595 void RoundWD(FpuRegister fd, FpuRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800596 void TruncLS(FpuRegister fd, FpuRegister fs);
597 void TruncLD(FpuRegister fd, FpuRegister fs);
598 void TruncWS(FpuRegister fd, FpuRegister fs);
599 void TruncWD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700600 void CeilLS(FpuRegister fd, FpuRegister fs);
601 void CeilLD(FpuRegister fd, FpuRegister fs);
602 void CeilWS(FpuRegister fd, FpuRegister fs);
603 void CeilWD(FpuRegister fd, FpuRegister fs);
604 void FloorLS(FpuRegister fd, FpuRegister fs);
605 void FloorLD(FpuRegister fd, FpuRegister fs);
606 void FloorWS(FpuRegister fd, FpuRegister fs);
607 void FloorWD(FpuRegister fd, FpuRegister fs);
608 void SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
609 void SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200610 void SeleqzS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
611 void SeleqzD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
612 void SelnezS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
613 void SelnezD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700614 void RintS(FpuRegister fd, FpuRegister fs);
615 void RintD(FpuRegister fd, FpuRegister fs);
616 void ClassS(FpuRegister fd, FpuRegister fs);
617 void ClassD(FpuRegister fd, FpuRegister fs);
618 void MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
619 void MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
620 void MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
621 void MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze299a9392015-12-08 16:08:02 -0800622 void CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
623 void CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
624 void CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
625 void CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
626 void CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
627 void CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
628 void CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
629 void CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
630 void CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
631 void CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
632 void CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
633 void CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
634 void CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
635 void CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
636 void CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
637 void CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
638 void CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
639 void CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
640 void CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
641 void CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700642
643 void Cvtsw(FpuRegister fd, FpuRegister fs);
644 void Cvtdw(FpuRegister fd, FpuRegister fs);
645 void Cvtsd(FpuRegister fd, FpuRegister fs);
646 void Cvtds(FpuRegister fd, FpuRegister fs);
Chris Larsen51417632015-10-02 13:24:25 -0700647 void Cvtsl(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700648 void Cvtdl(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800649
650 void Mfc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200651 void Mfhc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700652 void Mtc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200653 void Mthc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700654 void Dmfc1(GpuRegister rt, FpuRegister fs); // MIPS64
655 void Dmtc1(GpuRegister rt, FpuRegister fs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800656 void Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
657 void Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
658 void Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
659 void Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
660
661 void Break();
662 void Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700663 void Move(GpuRegister rd, GpuRegister rs);
664 void Clear(GpuRegister rd);
665 void Not(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800666
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000667 // MSA instructions.
668 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
669 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
670 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
671 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
672
673 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
674 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
675 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
676 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
677 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
678 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
679 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
680 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
681 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
682 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
683 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
684 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
685 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
686 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
687 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
688 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
689 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
690 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
691 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
692 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
693 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
694 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
695 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
696 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
697 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
698 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
699 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
700 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic80248d72017-04-20 11:55:47 +0200701 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
702 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
703 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
704 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
705 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
706 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
707 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
708 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
709 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
710 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
711 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
712 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
713 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
714 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
715 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
716 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
717 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
718 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
719 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
720 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200721 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
722 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
723 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
724 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
725 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
726 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
727 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
728 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
729 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
730 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
731 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
732 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
733 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
734 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
735 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
736 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000737
738 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
739 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
740 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
741 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
742 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
743 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
744 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
745 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200746 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
747 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
748 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
749 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000750
751 void Ffint_sW(VectorRegister wd, VectorRegister ws);
752 void Ffint_sD(VectorRegister wd, VectorRegister ws);
753 void Ftint_sW(VectorRegister wd, VectorRegister ws);
754 void Ftint_sD(VectorRegister wd, VectorRegister ws);
755
756 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
757 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
758 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
759 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
760 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
761 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
762 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
763 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
764 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
765 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
766 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
767 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
768
769 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
770 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
771 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
772 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
773 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
774 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
775 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
776 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
777 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
778 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
779 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
780 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
781 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
782
783 void MoveV(VectorRegister wd, VectorRegister ws);
784 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
785 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
786 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
787 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
788 void FillB(VectorRegister wd, GpuRegister rs);
789 void FillH(VectorRegister wd, GpuRegister rs);
790 void FillW(VectorRegister wd, GpuRegister rs);
791 void FillD(VectorRegister wd, GpuRegister rs);
792
Goran Jakovljevic3f444032017-03-31 14:38:20 +0200793 void LdiB(VectorRegister wd, int imm8);
794 void LdiH(VectorRegister wd, int imm10);
795 void LdiW(VectorRegister wd, int imm10);
796 void LdiD(VectorRegister wd, int imm10);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000797 void LdB(VectorRegister wd, GpuRegister rs, int offset);
798 void LdH(VectorRegister wd, GpuRegister rs, int offset);
799 void LdW(VectorRegister wd, GpuRegister rs, int offset);
800 void LdD(VectorRegister wd, GpuRegister rs, int offset);
801 void StB(VectorRegister wd, GpuRegister rs, int offset);
802 void StH(VectorRegister wd, GpuRegister rs, int offset);
803 void StW(VectorRegister wd, GpuRegister rs, int offset);
804 void StD(VectorRegister wd, GpuRegister rs, int offset);
805
Goran Jakovljevic38370112017-05-10 14:30:28 +0200806 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
807 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
808 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
809 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
810
Lena Djokicb3d79e42017-07-25 11:20:52 +0200811 void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
812 void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
813 void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
814 void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
815 void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
816 void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
817 void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
818 void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
819 void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
820 void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
821 void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
822 void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
823
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200824 // Helper for replicating floating point value in all destination elements.
825 void ReplicateFPToVectorRegister(VectorRegister dst, FpuRegister src, bool is_double);
826
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700827 // Higher level composite instructions.
Chris Larsenc733dca2016-05-13 16:11:47 -0700828 int InstrCountForLoadReplicatedConst32(int64_t);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700829 void LoadConst32(GpuRegister rd, int32_t value);
830 void LoadConst64(GpuRegister rd, int64_t value); // MIPS64
831
Chris Larsenc733dca2016-05-13 16:11:47 -0700832 // This function is only used for testing purposes.
833 void RecordLoadConst64Path(int value);
834
Alexey Frunze0960ac52016-12-20 17:24:59 -0800835 void Addiu32(GpuRegister rt, GpuRegister rs, int32_t value);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700836 void Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp = AT); // MIPS64
837
Alexey Frunzec061de12017-02-14 13:27:23 -0800838 //
839 // Heap poisoning.
840 //
841
842 // Poison a heap reference contained in `src` and store it in `dst`.
843 void PoisonHeapReference(GpuRegister dst, GpuRegister src) {
844 // dst = -src.
845 // Negate the 32-bit ref.
846 Dsubu(dst, ZERO, src);
847 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
848 Dext(dst, dst, 0, 32);
849 }
850 // Poison a heap reference contained in `reg`.
851 void PoisonHeapReference(GpuRegister reg) {
852 // reg = -reg.
853 PoisonHeapReference(reg, reg);
854 }
855 // Unpoison a heap reference contained in `reg`.
856 void UnpoisonHeapReference(GpuRegister reg) {
857 // reg = -reg.
858 // Negate the 32-bit ref.
859 Dsubu(reg, ZERO, reg);
860 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
861 Dext(reg, reg, 0, 32);
862 }
863 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
864 void MaybePoisonHeapReference(GpuRegister reg) {
865 if (kPoisonHeapReferences) {
866 PoisonHeapReference(reg);
867 }
868 }
869 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
870 void MaybeUnpoisonHeapReference(GpuRegister reg) {
871 if (kPoisonHeapReferences) {
872 UnpoisonHeapReference(reg);
873 }
874 }
875
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700876 void Bind(Label* label) OVERRIDE {
877 Bind(down_cast<Mips64Label*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700878 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700879 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
880 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS64";
881 }
882
883 void Bind(Mips64Label* label);
Igor Murashkinae7ff922016-10-06 14:59:19 -0700884
885 // Don't warn about a different virtual Bind/Jump in the base class.
886 using JNIBase::Bind;
887 using JNIBase::Jump;
888
889 // Create a new label that can be used with Jump/Bind calls.
890 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
891 LOG(FATAL) << "Not implemented on MIPS64";
892 UNREACHABLE();
893 }
894 // Emit an unconditional jump to the label.
895 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
896 LOG(FATAL) << "Not implemented on MIPS64";
897 UNREACHABLE();
898 }
899 // Emit a conditional jump to the label by applying a unary condition test to the register.
900 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
901 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
902 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
903 LOG(FATAL) << "Not implemented on MIPS64";
904 UNREACHABLE();
905 }
906
907 // Code at this offset will serve as the target for the Jump call.
908 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
909 LOG(FATAL) << "Not implemented on MIPS64";
910 UNREACHABLE();
911 }
912
Alexey Frunze19f6c692016-11-30 19:19:55 -0800913 // Create a new literal with a given value.
914 // NOTE: Force the template parameter to be explicitly specified.
915 template <typename T>
916 Literal* NewLiteral(typename Identity<T>::type value) {
917 static_assert(std::is_integral<T>::value, "T must be an integral type.");
918 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
919 }
920
921 // Load label address using PC-relative loads. To be used with data labels in the literal /
922 // jump table area only and not with regular code labels.
923 void LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label);
924
925 // Create a new literal with the given data.
926 Literal* NewLiteral(size_t size, const uint8_t* data);
927
928 // Load literal using PC-relative loads.
929 void LoadLiteral(GpuRegister dest_reg, LoadOperandType load_type, Literal* literal);
930
Alexey Frunze0960ac52016-12-20 17:24:59 -0800931 // Create a jump table for the given labels that will be emitted when finalizing.
932 // When the table is emitted, offsets will be relative to the location of the table.
933 // The table location is determined by the location of its label (the label precedes
934 // the table data) and should be loaded using LoadLabelAddress().
935 JumpTable* CreateJumpTable(std::vector<Mips64Label*>&& labels);
936
Alexey Frunze0cab6562017-07-25 15:19:36 -0700937 // When `is_bare` is false, the branches will promote to long (if the range
938 // of the individual branch instruction is insufficient) and the delay/
939 // forbidden slots will be taken care of.
940 // Use `is_bare = false` when the branch target may be out of reach of the
941 // individual branch instruction. IOW, this is for general purpose use.
942 //
943 // When `is_bare` is true, just the branch instructions will be generated
944 // leaving delay/forbidden slot filling up to the caller and the branches
945 // won't promote to long if the range is insufficient (you'll get a
946 // compilation error when the range is exceeded).
947 // Use `is_bare = true` when the branch target is known to be within reach
948 // of the individual branch instruction. This is intended for small local
949 // optimizations around delay/forbidden slots.
950 // Also prefer using `is_bare = true` if the code near the branch is to be
951 // patched or analyzed at run time (e.g. introspection) to
952 // - show the intent and
953 // - fail during compilation rather than during patching/execution if the
954 // bare branch range is insufficent but the code size and layout are
955 // expected to remain unchanged
956 //
957 // R6 compact branches without delay/forbidden slots.
958 void Bc(Mips64Label* label, bool is_bare = false);
959 void Balc(Mips64Label* label, bool is_bare = false);
960 // R6 compact branches with forbidden slots.
961 void Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
962 void Bltzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
963 void Bgtzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
964 void Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
965 void Bgezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
966 void Blezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
967 void Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
968 void Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
969 void Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
970 void Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
971 void Beqzc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
972 void Bnezc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
973 // R6 branches with delay slots.
974 void Bc1eqz(FpuRegister ft, Mips64Label* label, bool is_bare = false);
975 void Bc1nez(FpuRegister ft, Mips64Label* label, bool is_bare = false);
976 // R2 branches with delay slots that are also available on R6.
977 // The `is_bare` parameter exists and is checked in these branches only to
978 // prevent programming mistakes. These branches never promote to long, not
979 // even if `is_bare` is false.
980 void Bltz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
981 void Bgtz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
982 void Bgez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
983 void Blez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
984 void Beq(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
985 void Bne(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
986 void Beqz(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
987 void Bnez(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -0800988
989 void EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset, size_t size);
Chris Larsenc3fec0c2016-12-15 11:44:14 -0800990 void AdjustBaseAndOffset(GpuRegister& base, int32_t& offset, bool is_doubleword);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200991 // If element_size_shift is negative at entry, its value will be calculated based on the offset.
992 void AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
993 int32_t& offset,
994 int& element_size_shift);
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100995
996 private:
997 // This will be used as an argument for loads/stores
998 // when there is no need for implicit null checks.
999 struct NoImplicitNullChecker {
1000 void operator()() const {}
1001 };
1002
1003 public:
1004 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001005 void StoreConstToOffset(StoreOperandType type,
1006 int64_t value,
1007 GpuRegister base,
1008 int32_t offset,
1009 GpuRegister temp,
1010 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
1011 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
1012 // in which case the `base` register may be overwritten in the process.
1013 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 -08001014 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001015 GpuRegister reg;
1016 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
1017 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
1018 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
1019 // original `base` (that is, `base` prior to the adjustment), the original `base`
1020 // register will be overwritten.
1021 if (base == temp) {
1022 temp = AT;
1023 }
1024
1025 if (type == kStoreDoubleword && IsAligned<kMips64DoublewordSize>(offset)) {
1026 if (value == 0) {
1027 reg = ZERO;
1028 } else {
1029 reg = temp;
1030 LoadConst64(reg, value);
1031 }
1032 Sd(reg, base, offset);
1033 null_checker();
1034 } else {
1035 uint32_t low = Low32Bits(value);
1036 uint32_t high = High32Bits(value);
1037 if (low == 0) {
1038 reg = ZERO;
1039 } else {
1040 reg = temp;
1041 LoadConst32(reg, low);
1042 }
1043 switch (type) {
1044 case kStoreByte:
1045 Sb(reg, base, offset);
1046 break;
1047 case kStoreHalfword:
1048 Sh(reg, base, offset);
1049 break;
1050 case kStoreWord:
1051 Sw(reg, base, offset);
1052 break;
1053 case kStoreDoubleword:
1054 // not aligned to kMips64DoublewordSize
1055 CHECK_ALIGNED(offset, kMips64WordSize);
1056 Sw(reg, base, offset);
1057 null_checker();
1058 if (high == 0) {
1059 reg = ZERO;
1060 } else {
1061 reg = temp;
1062 if (high != low) {
1063 LoadConst32(reg, high);
1064 }
1065 }
1066 Sw(reg, base, offset + kMips64WordSize);
1067 break;
1068 default:
1069 LOG(FATAL) << "UNREACHABLE";
1070 }
1071 if (type != kStoreDoubleword) {
1072 null_checker();
1073 }
1074 }
1075 }
1076
1077 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001078 void LoadFromOffset(LoadOperandType type,
1079 GpuRegister reg,
1080 GpuRegister base,
1081 int32_t offset,
1082 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001083 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001084
1085 switch (type) {
1086 case kLoadSignedByte:
1087 Lb(reg, base, offset);
1088 break;
1089 case kLoadUnsignedByte:
1090 Lbu(reg, base, offset);
1091 break;
1092 case kLoadSignedHalfword:
1093 Lh(reg, base, offset);
1094 break;
1095 case kLoadUnsignedHalfword:
1096 Lhu(reg, base, offset);
1097 break;
1098 case kLoadWord:
1099 CHECK_ALIGNED(offset, kMips64WordSize);
1100 Lw(reg, base, offset);
1101 break;
1102 case kLoadUnsignedWord:
1103 CHECK_ALIGNED(offset, kMips64WordSize);
1104 Lwu(reg, base, offset);
1105 break;
1106 case kLoadDoubleword:
1107 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1108 CHECK_ALIGNED(offset, kMips64WordSize);
1109 Lwu(reg, base, offset);
1110 null_checker();
1111 Lwu(TMP2, base, offset + kMips64WordSize);
1112 Dinsu(reg, TMP2, 32, 32);
1113 } else {
1114 Ld(reg, base, offset);
1115 null_checker();
1116 }
1117 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001118 default:
1119 LOG(FATAL) << "UNREACHABLE";
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001120 }
1121 if (type != kLoadDoubleword) {
1122 null_checker();
1123 }
1124 }
1125
1126 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1127 void LoadFpuFromOffset(LoadOperandType type,
1128 FpuRegister reg,
1129 GpuRegister base,
1130 int32_t offset,
1131 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001132 int element_size_shift = -1;
1133 if (type != kLoadQuadword) {
1134 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
1135 } else {
1136 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1137 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001138
1139 switch (type) {
1140 case kLoadWord:
1141 CHECK_ALIGNED(offset, kMips64WordSize);
1142 Lwc1(reg, base, offset);
1143 null_checker();
1144 break;
1145 case kLoadDoubleword:
1146 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1147 CHECK_ALIGNED(offset, kMips64WordSize);
1148 Lwc1(reg, base, offset);
1149 null_checker();
1150 Lw(TMP2, base, offset + kMips64WordSize);
1151 Mthc1(TMP2, reg);
1152 } else {
1153 Ldc1(reg, base, offset);
1154 null_checker();
1155 }
1156 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001157 case kLoadQuadword:
1158 switch (element_size_shift) {
1159 case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break;
1160 case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break;
1161 case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break;
1162 case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break;
1163 default:
1164 LOG(FATAL) << "UNREACHABLE";
1165 }
1166 null_checker();
1167 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001168 default:
1169 LOG(FATAL) << "UNREACHABLE";
1170 }
1171 }
1172
1173 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1174 void StoreToOffset(StoreOperandType type,
1175 GpuRegister reg,
1176 GpuRegister base,
1177 int32_t offset,
1178 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001179 // Must not use AT as `reg`, so as not to overwrite the value being stored
1180 // with the adjusted `base`.
1181 CHECK_NE(reg, AT);
1182 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001183
1184 switch (type) {
1185 case kStoreByte:
1186 Sb(reg, base, offset);
1187 break;
1188 case kStoreHalfword:
1189 Sh(reg, base, offset);
1190 break;
1191 case kStoreWord:
1192 CHECK_ALIGNED(offset, kMips64WordSize);
1193 Sw(reg, base, offset);
1194 break;
1195 case kStoreDoubleword:
1196 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1197 CHECK_ALIGNED(offset, kMips64WordSize);
1198 Sw(reg, base, offset);
1199 null_checker();
1200 Dsrl32(TMP2, reg, 0);
1201 Sw(TMP2, base, offset + kMips64WordSize);
1202 } else {
1203 Sd(reg, base, offset);
1204 null_checker();
1205 }
1206 break;
1207 default:
1208 LOG(FATAL) << "UNREACHABLE";
1209 }
1210 if (type != kStoreDoubleword) {
1211 null_checker();
1212 }
1213 }
1214
1215 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1216 void StoreFpuToOffset(StoreOperandType type,
1217 FpuRegister reg,
1218 GpuRegister base,
1219 int32_t offset,
1220 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001221 int element_size_shift = -1;
1222 if (type != kStoreQuadword) {
1223 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
1224 } else {
1225 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1226 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001227
1228 switch (type) {
1229 case kStoreWord:
1230 CHECK_ALIGNED(offset, kMips64WordSize);
1231 Swc1(reg, base, offset);
1232 null_checker();
1233 break;
1234 case kStoreDoubleword:
1235 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1236 CHECK_ALIGNED(offset, kMips64WordSize);
1237 Mfhc1(TMP2, reg);
1238 Swc1(reg, base, offset);
1239 null_checker();
1240 Sw(TMP2, base, offset + kMips64WordSize);
1241 } else {
1242 Sdc1(reg, base, offset);
1243 null_checker();
1244 }
1245 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001246 case kStoreQuadword:
1247 switch (element_size_shift) {
1248 case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break;
1249 case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break;
1250 case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break;
1251 case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break;
1252 default:
1253 LOG(FATAL) << "UNREACHABLE";
1254 }
1255 null_checker();
1256 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001257 default:
1258 LOG(FATAL) << "UNREACHABLE";
1259 }
1260 }
1261
Andreas Gampe57b34292015-01-14 15:45:59 -08001262 void LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1263 void LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1264 void StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1265 void StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1266
1267 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001268 void Emit(uint32_t value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001269
1270 //
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001271 // Overridden common assembler high-level functionality.
Andreas Gampe57b34292015-01-14 15:45:59 -08001272 //
1273
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001274 // Emit code that will create an activation on the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001275 void BuildFrame(size_t frame_size,
1276 ManagedRegister method_reg,
1277 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001278 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
1279
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001280 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001281 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001282
1283 void IncreaseFrameSize(size_t adjust) OVERRIDE;
1284 void DecreaseFrameSize(size_t adjust) OVERRIDE;
1285
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001286 // Store routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001287 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
1288 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1289 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1290
1291 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
1292
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001293 void StoreStackOffsetToThread(ThreadOffset64 thr_offs,
1294 FrameOffset fr_offs,
1295 ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001296
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001297 void StoreStackPointerToThread(ThreadOffset64 thr_offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001298
1299 void StoreSpanning(FrameOffset dest, ManagedRegister msrc, FrameOffset in_off,
1300 ManagedRegister mscratch) OVERRIDE;
1301
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001302 // Load routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001303 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
1304
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001305 void LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001306
Mathieu Chartiere401d142015-04-22 13:56:20 -07001307 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001308
Mathieu Chartiere401d142015-04-22 13:56:20 -07001309 void LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001310 bool unpoison_reference) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001311
1312 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
1313
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001314 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001315
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001316 // Copying routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001317 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
1318
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001319 void CopyRawPtrFromThread(FrameOffset fr_offs,
1320 ThreadOffset64 thr_offs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001321 ManagedRegister mscratch) OVERRIDE;
1322
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001323 void CopyRawPtrToThread(ThreadOffset64 thr_offs,
1324 FrameOffset fr_offs,
1325 ManagedRegister mscratch) OVERRIDE;
1326
Andreas Gampe57b34292015-01-14 15:45:59 -08001327 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
1328
1329 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
1330
1331 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister mscratch,
1332 size_t size) OVERRIDE;
1333
1334 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1335 ManagedRegister mscratch, size_t size) OVERRIDE;
1336
1337 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister mscratch,
1338 size_t size) OVERRIDE;
1339
1340 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
1341 ManagedRegister mscratch, size_t size) OVERRIDE;
1342
1343 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1344 ManagedRegister mscratch, size_t size) OVERRIDE;
1345
1346 void MemoryBarrier(ManagedRegister) OVERRIDE;
1347
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001348 // Sign extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001349 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1350
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001351 // Zero extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001352 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1353
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001354 // Exploit fast access in managed code to Thread::Current().
Andreas Gampe57b34292015-01-14 15:45:59 -08001355 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1356 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
1357
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001358 // 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 -08001359 // value is null and null_allowed. in_reg holds a possibly stale reference
1360 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001361 // null.
Andreas Gampe57b34292015-01-14 15:45:59 -08001362 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
1363 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
1364
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001365 // 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 -08001366 // value is null and null_allowed.
1367 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset, ManagedRegister
1368 mscratch, bool null_allowed) OVERRIDE;
1369
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001370 // src holds a handle scope entry (Object**) load this into dst.
Andreas Gampe57b34292015-01-14 15:45:59 -08001371 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
1372
1373 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1374 // know that src may not be null.
1375 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1376 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
1377
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001378 // Call to address held at [base+offset].
Andreas Gampe57b34292015-01-14 15:45:59 -08001379 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1380 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001381 void CallFromThread(ThreadOffset64 offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001382
1383 // Generate code to check if Thread::Current()->exception_ is non-null
1384 // and branch to a ExceptionSlowPath if it is.
1385 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
1386
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001387 // Emit slow paths queued during assembly and promote short branches to long if needed.
1388 void FinalizeCode() OVERRIDE;
1389
1390 // Emit branches and finalize all instructions.
1391 void FinalizeInstructions(const MemoryRegion& region);
1392
1393 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS64,
1394 // must be used instead of Mips64Label::GetPosition()).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001395 uint32_t GetLabelLocation(const Mips64Label* label) const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001396
1397 // Get the final position of a label after local fixup based on the old position
1398 // recorded before FinalizeCode().
1399 uint32_t GetAdjustedPosition(uint32_t old_position);
1400
Alexey Frunze19f6c692016-11-30 19:19:55 -08001401 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1402 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1403 // to PC.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001404 enum BranchCondition {
1405 kCondLT,
1406 kCondGE,
1407 kCondLE,
1408 kCondGT,
1409 kCondLTZ,
1410 kCondGEZ,
1411 kCondLEZ,
1412 kCondGTZ,
1413 kCondEQ,
1414 kCondNE,
1415 kCondEQZ,
1416 kCondNEZ,
1417 kCondLTU,
1418 kCondGEU,
Alexey Frunze299a9392015-12-08 16:08:02 -08001419 kCondF, // Floating-point predicate false.
1420 kCondT, // Floating-point predicate true.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001421 kUncond,
1422 };
1423 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1424
Andreas Gampe57b34292015-01-14 15:45:59 -08001425 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001426 class Branch {
1427 public:
1428 enum Type {
Alexey Frunze0cab6562017-07-25 15:19:36 -07001429 // R6 short branches (can be promoted to long).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001430 kUncondBranch,
1431 kCondBranch,
1432 kCall,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001433 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
1434 kBareUncondBranch,
1435 kBareCondBranch,
1436 kBareCall,
1437 // R2 short branches (can't be promoted to long), delay slots filled manually.
1438 kR2BareCondBranch,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001439 // Near label.
1440 kLabel,
1441 // Near literals.
1442 kLiteral,
1443 kLiteralUnsigned,
1444 kLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001445 // Long branches.
1446 kLongUncondBranch,
1447 kLongCondBranch,
1448 kLongCall,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001449 // Far label.
1450 kFarLabel,
1451 // Far literals.
1452 kFarLiteral,
1453 kFarLiteralUnsigned,
1454 kFarLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001455 };
1456
1457 // Bit sizes of offsets defined as enums to minimize chance of typos.
1458 enum OffsetBits {
1459 kOffset16 = 16,
1460 kOffset18 = 18,
1461 kOffset21 = 21,
1462 kOffset23 = 23,
1463 kOffset28 = 28,
1464 kOffset32 = 32,
1465 };
1466
1467 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1468 static constexpr int32_t kMaxBranchLength = 32;
1469 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
1470
1471 struct BranchInfo {
1472 // Branch length as a number of 4-byte-long instructions.
1473 uint32_t length;
1474 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1475 // PC-relative offset (or its most significant 16-bit half, which goes first).
1476 uint32_t instr_offset;
1477 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1478 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1479 // instructions) from the instruction containing the offset.
1480 uint32_t pc_org;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001481 // How large (in bits) a PC-relative offset can be for a given type of branch (kCondBranch
1482 // and kBareCondBranch are an exception: use kOffset23 for beqzc/bnezc).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001483 OffsetBits offset_size;
1484 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1485 // count.
1486 int offset_shift;
1487 };
1488 static const BranchInfo branch_info_[/* Type */];
1489
Alexey Frunze19f6c692016-11-30 19:19:55 -08001490 // Unconditional branch or call.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001491 Branch(uint32_t location, uint32_t target, bool is_call, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001492 // Conditional branch.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001493 Branch(bool is_r6,
1494 uint32_t location,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001495 uint32_t target,
1496 BranchCondition condition,
1497 GpuRegister lhs_reg,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001498 GpuRegister rhs_reg,
1499 bool is_bare);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001500 // Label address (in literal area) or literal.
1501 Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001502
1503 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1504 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1505 // So, we need a way to identify such branches in order to emit no instructions for them
1506 // or change them to unconditional.
1507 static bool IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1508 static bool IsUncond(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1509
1510 static BranchCondition OppositeCondition(BranchCondition cond);
1511
1512 Type GetType() const;
1513 BranchCondition GetCondition() const;
1514 GpuRegister GetLeftRegister() const;
1515 GpuRegister GetRightRegister() const;
1516 uint32_t GetTarget() const;
1517 uint32_t GetLocation() const;
1518 uint32_t GetOldLocation() const;
1519 uint32_t GetLength() const;
1520 uint32_t GetOldLength() const;
1521 uint32_t GetSize() const;
1522 uint32_t GetOldSize() const;
1523 uint32_t GetEndLocation() const;
1524 uint32_t GetOldEndLocation() const;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001525 bool IsBare() const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001526 bool IsLong() const;
1527 bool IsResolved() const;
1528
1529 // Returns the bit size of the signed offset that the branch instruction can handle.
1530 OffsetBits GetOffsetSize() const;
1531
1532 // Calculates the distance between two byte locations in the assembler buffer and
1533 // returns the number of bits needed to represent the distance as a signed integer.
1534 //
1535 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1536 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1537 //
1538 // Composite branches (made of several instructions) with longer reach have 32-bit
1539 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
1540 // The composite branches cover the range of PC + ~+/-2GB. The range is not end-to-end,
1541 // however. Consider the following implementation of a long unconditional branch, for
1542 // example:
1543 //
1544 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1545 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1546 //
1547 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1548 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1549 // due to sign extension. This must be compensated for by incrementing offset_31_16
1550 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1551 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1552 // Therefore, the long branch range is something like from PC - 0x80000000 to
1553 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
1554 //
1555 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1556 // case with the addiu instruction and a 16 bit offset.
1557 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1558
1559 // Resolve a branch when the target is known.
1560 void Resolve(uint32_t target);
1561
1562 // Relocate a branch by a given delta if needed due to expansion of this or another
1563 // branch at a given location by this delta (just changes location_ and target_).
1564 void Relocate(uint32_t expand_location, uint32_t delta);
1565
1566 // If the branch is short, changes its type to long.
1567 void PromoteToLong();
1568
1569 // If necessary, updates the type by promoting a short branch to a long branch
1570 // based on the branch location and target. Returns the amount (in bytes) by
1571 // which the branch size has increased.
1572 // max_short_distance caps the maximum distance between location_ and target_
1573 // that is allowed for short branches. This is for debugging/testing purposes.
1574 // max_short_distance = 0 forces all short branches to become long.
1575 // Use the implicit default argument when not debugging/testing.
1576 uint32_t PromoteIfNeeded(uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
1577
1578 // Returns the location of the instruction(s) containing the offset.
1579 uint32_t GetOffsetLocation() const;
1580
1581 // Calculates and returns the offset ready for encoding in the branch instruction(s).
1582 uint32_t GetOffset() const;
1583
1584 private:
1585 // Completes branch construction by determining and recording its type.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001586 void InitializeType(Type initial_type, bool is_r6);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001587 // Helper for the above.
1588 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1589
1590 uint32_t old_location_; // Offset into assembler buffer in bytes.
1591 uint32_t location_; // Offset into assembler buffer in bytes.
1592 uint32_t target_; // Offset into assembler buffer in bytes.
1593
1594 GpuRegister lhs_reg_; // Left-hand side register in conditional branches or
Alexey Frunze19f6c692016-11-30 19:19:55 -08001595 // destination register in literals.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001596 GpuRegister rhs_reg_; // Right-hand side register in conditional branches.
1597 BranchCondition condition_; // Condition for conditional branches.
1598
1599 Type type_; // Current type of the branch.
1600 Type old_type_; // Initial type of the branch.
1601 };
1602 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1603 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1604
Andreas Gampe57b34292015-01-14 15:45:59 -08001605 void EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001606 void EmitRsd(int opcode, GpuRegister rs, GpuRegister rd, int shamt, int funct);
1607 void EmitRtd(int opcode, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Andreas Gampe57b34292015-01-14 15:45:59 -08001608 void EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001609 void EmitI21(int opcode, GpuRegister rs, uint32_t imm21);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001610 void EmitI26(int opcode, uint32_t imm26);
Andreas Gampe57b34292015-01-14 15:45:59 -08001611 void EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd, int funct);
1612 void EmitFI(int opcode, int fmt, FpuRegister rt, uint16_t imm);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001613 void EmitBcondR6(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint32_t imm16_21);
1614 void EmitBcondR2(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint16_t imm16);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001615 void EmitMsa3R(int operation,
1616 int df,
1617 VectorRegister wt,
1618 VectorRegister ws,
1619 VectorRegister wd,
1620 int minor_opcode);
1621 void EmitMsaBIT(int operation, int df_m, VectorRegister ws, VectorRegister wd, int minor_opcode);
1622 void EmitMsaELM(int operation, int df_n, VectorRegister ws, VectorRegister wd, int minor_opcode);
1623 void EmitMsaMI10(int s10, GpuRegister rs, VectorRegister wd, int minor_opcode, int df);
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001624 void EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001625 void EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1626 void EmitMsa2RF(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001627
Alexey Frunze0cab6562017-07-25 15:19:36 -07001628 void Buncond(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001629 void Bcond(Mips64Label* label,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001630 bool is_r6,
1631 bool is_bare,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001632 BranchCondition condition,
1633 GpuRegister lhs,
1634 GpuRegister rhs = ZERO);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001635 void Call(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001636 void FinalizeLabeledBranch(Mips64Label* label);
1637
1638 Branch* GetBranch(uint32_t branch_id);
1639 const Branch* GetBranch(uint32_t branch_id) const;
1640
Alexey Frunze19f6c692016-11-30 19:19:55 -08001641 void EmitLiterals();
Alexey Frunze0960ac52016-12-20 17:24:59 -08001642 void ReserveJumpTableSpace();
1643 void EmitJumpTables();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001644 void PromoteBranches();
1645 void EmitBranch(Branch* branch);
1646 void EmitBranches();
1647 void PatchCFI();
1648
1649 // Emits exception block.
1650 void EmitExceptionPoll(Mips64ExceptionSlowPath* exception);
1651
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001652 bool HasMsa() const {
1653 return has_msa_;
1654 }
1655
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001656 // List of exception blocks to generate at the end of the code cache.
1657 std::vector<Mips64ExceptionSlowPath> exception_blocks_;
1658
1659 std::vector<Branch> branches_;
1660
1661 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1662 bool overwriting_;
1663 // The current overwrite location.
1664 uint32_t overwrite_location_;
1665
Alexey Frunze19f6c692016-11-30 19:19:55 -08001666 // Use std::deque<> for literal labels to allow insertions at the end
1667 // without invalidating pointers and references to existing elements.
1668 ArenaDeque<Literal> literals_;
1669 ArenaDeque<Literal> long_literals_; // 64-bit literals separated for alignment reasons.
1670
Alexey Frunze0960ac52016-12-20 17:24:59 -08001671 // Jump table list.
1672 ArenaDeque<JumpTable> jump_tables_;
1673
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001674 // Data for AdjustedPosition(), see the description there.
1675 uint32_t last_position_adjustment_;
1676 uint32_t last_old_position_;
1677 uint32_t last_branch_id_;
Andreas Gampe57b34292015-01-14 15:45:59 -08001678
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001679 const bool has_msa_;
1680
Andreas Gampe57b34292015-01-14 15:45:59 -08001681 DISALLOW_COPY_AND_ASSIGN(Mips64Assembler);
1682};
1683
Andreas Gampe57b34292015-01-14 15:45:59 -08001684} // namespace mips64
1685} // namespace art
1686
1687#endif // ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_