blob: dd6dcd189608066c4fa7e90899886879c1ab1b61 [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"
31#include "managed_register_mips64.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080032#include "offsets.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070033#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070034#include "utils/jni_macro_assembler.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070035#include "utils/label.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080036
37namespace art {
38namespace mips64 {
39
Chris Larsenc733dca2016-05-13 16:11:47 -070040enum LoadConst64Path {
41 kLoadConst64PathZero = 0x0,
42 kLoadConst64PathOri = 0x1,
43 kLoadConst64PathDaddiu = 0x2,
44 kLoadConst64PathLui = 0x4,
45 kLoadConst64PathLuiOri = 0x8,
46 kLoadConst64PathOriDahi = 0x10,
47 kLoadConst64PathOriDati = 0x20,
48 kLoadConst64PathLuiDahi = 0x40,
49 kLoadConst64PathLuiDati = 0x80,
50 kLoadConst64PathDaddiuDsrlX = 0x100,
51 kLoadConst64PathOriDsllX = 0x200,
52 kLoadConst64PathDaddiuDsllX = 0x400,
53 kLoadConst64PathLuiOriDsllX = 0x800,
54 kLoadConst64PathOriDsllXOri = 0x1000,
55 kLoadConst64PathDaddiuDsllXOri = 0x2000,
56 kLoadConst64PathDaddiuDahi = 0x4000,
57 kLoadConst64PathDaddiuDati = 0x8000,
58 kLoadConst64PathDinsu1 = 0x10000,
59 kLoadConst64PathDinsu2 = 0x20000,
60 kLoadConst64PathCatchAll = 0x40000,
61 kLoadConst64PathAllPaths = 0x7ffff,
62};
63
64template <typename Asm>
65void TemplateLoadConst32(Asm* a, GpuRegister rd, int32_t value) {
66 if (IsUint<16>(value)) {
67 // Use OR with (unsigned) immediate to encode 16b unsigned int.
68 a->Ori(rd, ZERO, value);
69 } else if (IsInt<16>(value)) {
70 // Use ADD with (signed) immediate to encode 16b signed int.
71 a->Addiu(rd, ZERO, value);
72 } else {
73 // Set 16 most significant bits of value. The "lui" instruction
74 // also clears the 16 least significant bits to zero.
75 a->Lui(rd, value >> 16);
76 if (value & 0xFFFF) {
77 // If the 16 least significant bits are non-zero, set them
78 // here.
79 a->Ori(rd, rd, value);
80 }
81 }
82}
83
84static inline int InstrCountForLoadReplicatedConst32(int64_t value) {
85 int32_t x = Low32Bits(value);
86 int32_t y = High32Bits(value);
87
88 if (x == y) {
Chris Larsen8859cec2017-08-30 16:40:02 -070089 return (IsUint<16>(x) || IsInt<16>(x) || ((x & 0xFFFF) == 0)) ? 2 : 3;
Chris Larsenc733dca2016-05-13 16:11:47 -070090 }
91
92 return INT_MAX;
93}
94
95template <typename Asm, typename Rtype, typename Vtype>
96void TemplateLoadConst64(Asm* a, Rtype rd, Vtype value) {
97 int bit31 = (value & UINT64_C(0x80000000)) != 0;
98 int rep32_count = InstrCountForLoadReplicatedConst32(value);
99
100 // Loads with 1 instruction.
101 if (IsUint<16>(value)) {
102 // 64-bit value can be loaded as an unsigned 16-bit number.
103 a->RecordLoadConst64Path(kLoadConst64PathOri);
104 a->Ori(rd, ZERO, value);
105 } else if (IsInt<16>(value)) {
106 // 64-bit value can be loaded as an signed 16-bit number.
107 a->RecordLoadConst64Path(kLoadConst64PathDaddiu);
108 a->Daddiu(rd, ZERO, value);
109 } else if ((value & 0xFFFF) == 0 && IsInt<16>(value >> 16)) {
110 // 64-bit value can be loaded as an signed 32-bit number which has all
111 // of its 16 least significant bits set to zero.
112 a->RecordLoadConst64Path(kLoadConst64PathLui);
113 a->Lui(rd, value >> 16);
114 } else if (IsInt<32>(value)) {
115 // Loads with 2 instructions.
116 // 64-bit value can be loaded as an signed 32-bit number which has some
117 // or all of its 16 least significant bits set to one.
118 a->RecordLoadConst64Path(kLoadConst64PathLuiOri);
119 a->Lui(rd, value >> 16);
120 a->Ori(rd, rd, value);
121 } else if ((value & 0xFFFF0000) == 0 && IsInt<16>(value >> 32)) {
122 // 64-bit value which consists of an unsigned 16-bit value in its
123 // least significant 32-bits, and a signed 16-bit value in its
124 // most significant 32-bits.
125 a->RecordLoadConst64Path(kLoadConst64PathOriDahi);
126 a->Ori(rd, ZERO, value);
127 a->Dahi(rd, value >> 32);
128 } else if ((value & UINT64_C(0xFFFFFFFF0000)) == 0) {
129 // 64-bit value which consists of an unsigned 16-bit value in its
130 // least significant 48-bits, and a signed 16-bit value in its
131 // most significant 16-bits.
132 a->RecordLoadConst64Path(kLoadConst64PathOriDati);
133 a->Ori(rd, ZERO, value);
134 a->Dati(rd, value >> 48);
135 } else if ((value & 0xFFFF) == 0 &&
136 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
137 // 16 LSBs (Least Significant Bits) all set to zero.
138 // 48 MSBs (Most Significant Bits) hold a signed 32-bit value.
139 a->RecordLoadConst64Path(kLoadConst64PathLuiDahi);
140 a->Lui(rd, value >> 16);
141 a->Dahi(rd, (value >> 32) + bit31);
142 } else if ((value & 0xFFFF) == 0 && ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
143 // 16 LSBs all set to zero.
144 // 48 MSBs hold a signed value which can't be represented by signed
145 // 32-bit number, and the middle 16 bits are all zero, or all one.
146 a->RecordLoadConst64Path(kLoadConst64PathLuiDati);
147 a->Lui(rd, value >> 16);
148 a->Dati(rd, (value >> 48) + bit31);
149 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
150 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
151 // 32 LSBs contain an unsigned 16-bit number.
152 // 32 MSBs contain a signed 16-bit number.
153 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDahi);
154 a->Daddiu(rd, ZERO, value);
155 a->Dahi(rd, (value >> 32) + bit31);
156 } else if (IsInt<16>(static_cast<int32_t>(value)) &&
157 ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
158 // 48 LSBs contain an unsigned 16-bit number.
159 // 16 MSBs contain a signed 16-bit number.
160 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDati);
161 a->Daddiu(rd, ZERO, value);
162 a->Dati(rd, (value >> 48) + bit31);
163 } else if (IsPowerOfTwo(value + UINT64_C(1))) {
164 // 64-bit values which have their "n" MSBs set to one, and their
165 // "64-n" LSBs set to zero. "n" must meet the restrictions 0 < n < 64.
166 int shift_cnt = 64 - CTZ(value + UINT64_C(1));
167 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsrlX);
168 a->Daddiu(rd, ZERO, -1);
169 if (shift_cnt < 32) {
170 a->Dsrl(rd, rd, shift_cnt);
171 } else {
172 a->Dsrl32(rd, rd, shift_cnt & 31);
173 }
174 } else {
175 int shift_cnt = CTZ(value);
176 int64_t tmp = value >> shift_cnt;
177 a->RecordLoadConst64Path(kLoadConst64PathOriDsllX);
178 if (IsUint<16>(tmp)) {
179 // Value can be computed by loading a 16-bit unsigned value, and
180 // then shifting left.
181 a->Ori(rd, ZERO, tmp);
182 if (shift_cnt < 32) {
183 a->Dsll(rd, rd, shift_cnt);
184 } else {
185 a->Dsll32(rd, rd, shift_cnt & 31);
186 }
187 } else if (IsInt<16>(tmp)) {
188 // Value can be computed by loading a 16-bit signed value, and
189 // then shifting left.
190 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllX);
191 a->Daddiu(rd, ZERO, tmp);
192 if (shift_cnt < 32) {
193 a->Dsll(rd, rd, shift_cnt);
194 } else {
195 a->Dsll32(rd, rd, shift_cnt & 31);
196 }
197 } else if (rep32_count < 3) {
198 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
199 // value loaded into the 32 LSBs can be loaded with a single
200 // MIPS instruction.
201 a->LoadConst32(rd, value);
202 a->Dinsu(rd, rd, 32, 32);
203 a->RecordLoadConst64Path(kLoadConst64PathDinsu1);
204 } else if (IsInt<32>(tmp)) {
205 // Loads with 3 instructions.
206 // Value can be computed by loading a 32-bit signed value, and
207 // then shifting left.
208 a->RecordLoadConst64Path(kLoadConst64PathLuiOriDsllX);
209 a->Lui(rd, tmp >> 16);
210 a->Ori(rd, rd, tmp);
211 if (shift_cnt < 32) {
212 a->Dsll(rd, rd, shift_cnt);
213 } else {
214 a->Dsll32(rd, rd, shift_cnt & 31);
215 }
216 } else {
217 shift_cnt = 16 + CTZ(value >> 16);
218 tmp = value >> shift_cnt;
219 if (IsUint<16>(tmp)) {
220 // Value can be computed by loading a 16-bit unsigned value,
221 // shifting left, and "or"ing in another 16-bit unsigned value.
222 a->RecordLoadConst64Path(kLoadConst64PathOriDsllXOri);
223 a->Ori(rd, ZERO, tmp);
224 if (shift_cnt < 32) {
225 a->Dsll(rd, rd, shift_cnt);
226 } else {
227 a->Dsll32(rd, rd, shift_cnt & 31);
228 }
229 a->Ori(rd, rd, value);
230 } else if (IsInt<16>(tmp)) {
231 // Value can be computed by loading a 16-bit signed value,
232 // shifting left, and "or"ing in a 16-bit unsigned value.
233 a->RecordLoadConst64Path(kLoadConst64PathDaddiuDsllXOri);
234 a->Daddiu(rd, ZERO, tmp);
235 if (shift_cnt < 32) {
236 a->Dsll(rd, rd, shift_cnt);
237 } else {
238 a->Dsll32(rd, rd, shift_cnt & 31);
239 }
240 a->Ori(rd, rd, value);
241 } else if (rep32_count < 4) {
242 // Value being loaded has 32 LSBs equal to the 32 MSBs, and the
243 // value in the 32 LSBs requires 2 MIPS instructions to load.
244 a->LoadConst32(rd, value);
245 a->Dinsu(rd, rd, 32, 32);
246 a->RecordLoadConst64Path(kLoadConst64PathDinsu2);
247 } else {
248 // Loads with 3-4 instructions.
249 // Catch-all case to get any other 64-bit values which aren't
250 // handled by special cases above.
251 uint64_t tmp2 = value;
252 a->RecordLoadConst64Path(kLoadConst64PathCatchAll);
253 a->LoadConst32(rd, value);
254 if (bit31) {
255 tmp2 += UINT64_C(0x100000000);
256 }
257 if (((tmp2 >> 32) & 0xFFFF) != 0) {
258 a->Dahi(rd, tmp2 >> 32);
259 }
260 if (tmp2 & UINT64_C(0x800000000000)) {
261 tmp2 += UINT64_C(0x1000000000000);
262 }
263 if ((tmp2 >> 48) != 0) {
264 a->Dati(rd, tmp2 >> 48);
265 }
266 }
267 }
268 }
269}
270
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000271static constexpr size_t kMips64HalfwordSize = 2;
Lazar Trsicd9672662015-09-03 17:33:01 +0200272static constexpr size_t kMips64WordSize = 4;
273static constexpr size_t kMips64DoublewordSize = 8;
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700274
Andreas Gampe57b34292015-01-14 15:45:59 -0800275enum LoadOperandType {
276 kLoadSignedByte,
277 kLoadUnsignedByte,
278 kLoadSignedHalfword,
279 kLoadUnsignedHalfword,
280 kLoadWord,
Douglas Leungd90957f2015-04-30 19:22:49 -0700281 kLoadUnsignedWord,
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200282 kLoadDoubleword,
283 kLoadQuadword
Andreas Gampe57b34292015-01-14 15:45:59 -0800284};
285
286enum StoreOperandType {
287 kStoreByte,
288 kStoreHalfword,
289 kStoreWord,
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200290 kStoreDoubleword,
291 kStoreQuadword
Andreas Gampe57b34292015-01-14 15:45:59 -0800292};
293
Chris Larsen14500822015-10-01 11:35:18 -0700294// Used to test the values returned by ClassS/ClassD.
295enum FPClassMaskType {
296 kSignalingNaN = 0x001,
297 kQuietNaN = 0x002,
298 kNegativeInfinity = 0x004,
299 kNegativeNormal = 0x008,
300 kNegativeSubnormal = 0x010,
301 kNegativeZero = 0x020,
302 kPositiveInfinity = 0x040,
303 kPositiveNormal = 0x080,
304 kPositiveSubnormal = 0x100,
305 kPositiveZero = 0x200,
306};
307
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700308class Mips64Label : public Label {
309 public:
310 Mips64Label() : prev_branch_id_plus_one_(0) {}
311
312 Mips64Label(Mips64Label&& src)
313 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
314
315 private:
316 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
317
318 friend class Mips64Assembler;
319 DISALLOW_COPY_AND_ASSIGN(Mips64Label);
320};
321
Alexey Frunze19f6c692016-11-30 19:19:55 -0800322// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
323class Literal {
324 public:
325 static constexpr size_t kMaxSize = 8;
326
327 Literal(uint32_t size, const uint8_t* data)
328 : label_(), size_(size) {
329 DCHECK_LE(size, Literal::kMaxSize);
330 memcpy(data_, data, size);
331 }
332
333 template <typename T>
334 T GetValue() const {
335 DCHECK_EQ(size_, sizeof(T));
336 T value;
337 memcpy(&value, data_, sizeof(T));
338 return value;
339 }
340
341 uint32_t GetSize() const {
342 return size_;
343 }
344
345 const uint8_t* GetData() const {
346 return data_;
347 }
348
349 Mips64Label* GetLabel() {
350 return &label_;
351 }
352
353 const Mips64Label* GetLabel() const {
354 return &label_;
355 }
356
357 private:
358 Mips64Label label_;
359 const uint32_t size_;
360 uint8_t data_[kMaxSize];
361
362 DISALLOW_COPY_AND_ASSIGN(Literal);
363};
364
Alexey Frunze0960ac52016-12-20 17:24:59 -0800365// Jump table: table of labels emitted after the code and before the literals. Similar to literals.
366class JumpTable {
367 public:
368 explicit JumpTable(std::vector<Mips64Label*>&& labels)
369 : label_(), labels_(std::move(labels)) {
370 }
371
372 size_t GetSize() const {
373 return labels_.size() * sizeof(uint32_t);
374 }
375
376 const std::vector<Mips64Label*>& GetData() const {
377 return labels_;
378 }
379
380 Mips64Label* GetLabel() {
381 return &label_;
382 }
383
384 const Mips64Label* GetLabel() const {
385 return &label_;
386 }
387
388 private:
389 Mips64Label label_;
390 std::vector<Mips64Label*> labels_;
391
392 DISALLOW_COPY_AND_ASSIGN(JumpTable);
393};
394
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700395// Slowpath entered when Thread::Current()->_exception is non-null.
396class Mips64ExceptionSlowPath {
397 public:
398 explicit Mips64ExceptionSlowPath(Mips64ManagedRegister scratch, size_t stack_adjust)
399 : scratch_(scratch), stack_adjust_(stack_adjust) {}
400
401 Mips64ExceptionSlowPath(Mips64ExceptionSlowPath&& src)
402 : scratch_(src.scratch_),
403 stack_adjust_(src.stack_adjust_),
404 exception_entry_(std::move(src.exception_entry_)) {}
405
406 private:
407 Mips64Label* Entry() { return &exception_entry_; }
408 const Mips64ManagedRegister scratch_;
409 const size_t stack_adjust_;
410 Mips64Label exception_entry_;
411
412 friend class Mips64Assembler;
413 DISALLOW_COPY_AND_ASSIGN(Mips64ExceptionSlowPath);
414};
415
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700416class Mips64Assembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k64> {
Andreas Gampe57b34292015-01-14 15:45:59 -0800417 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700418 using JNIBase = JNIMacroAssembler<PointerSize::k64>;
419
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100420 explicit Mips64Assembler(ArenaAllocator* arena,
421 const Mips64InstructionSetFeatures* instruction_set_features = nullptr)
Vladimir Marko93205e32016-04-13 11:59:46 +0100422 : Assembler(arena),
423 overwriting_(false),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700424 overwrite_location_(0),
Alexey Frunze19f6c692016-11-30 19:19:55 -0800425 literals_(arena->Adapter(kArenaAllocAssembler)),
426 long_literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze0960ac52016-12-20 17:24:59 -0800427 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700428 last_position_adjustment_(0),
429 last_old_position_(0),
Goran Jakovljevic27af9372017-03-15 15:31:34 +0100430 last_branch_id_(0),
431 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700432 cfi().DelayEmittingAdvancePCs();
433 }
434
435 virtual ~Mips64Assembler() {
436 for (auto& branch : branches_) {
437 CHECK(branch.IsResolved());
438 }
439 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800440
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700441 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
442 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
443
Andreas Gampe57b34292015-01-14 15:45:59 -0800444 // Emit Machine Instructions.
Andreas Gampe57b34292015-01-14 15:45:59 -0800445 void Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
446 void Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700447 void Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
448 void Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800449 void Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700450 void Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
451
Alexey Frunzec857c742015-09-23 15:12:39 -0700452 void MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
453 void MuhR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
454 void DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
455 void ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
456 void DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
457 void ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt);
458 void Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
459 void Dmuh(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
460 void Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
461 void Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
462 void Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
463 void Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800464
465 void And(GpuRegister rd, GpuRegister rs, GpuRegister rt);
466 void Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16);
467 void Or(GpuRegister rd, GpuRegister rs, GpuRegister rt);
468 void Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
469 void Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
470 void Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16);
471 void Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt);
472
Alexey Frunzec857c742015-09-23 15:12:39 -0700473 void Bitswap(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800474 void Dbitswap(GpuRegister rd, GpuRegister rt); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700475 void Seb(GpuRegister rd, GpuRegister rt);
476 void Seh(GpuRegister rd, GpuRegister rt);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800477 void Dsbh(GpuRegister rd, GpuRegister rt); // MIPS64
478 void Dshd(GpuRegister rd, GpuRegister rt); // MIPS64
Lazar Trsicd9672662015-09-03 17:33:01 +0200479 void Dext(GpuRegister rs, GpuRegister rt, int pos, int size); // MIPS64
480 void Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size); // MIPS64
Chris Larsene3660592016-11-09 11:13:42 -0800481 void Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne);
482 void Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700483 void Wsbh(GpuRegister rd, GpuRegister rt);
484 void Sc(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800485 void Scd(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700486 void Ll(GpuRegister rt, GpuRegister base, int16_t imm9 = 0);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800487 void Lld(GpuRegister rt, GpuRegister base, int16_t imm9 = 0); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700488
489 void Sll(GpuRegister rd, GpuRegister rt, int shamt);
490 void Srl(GpuRegister rd, GpuRegister rt, int shamt);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700491 void Rotr(GpuRegister rd, GpuRegister rt, int shamt);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700492 void Sra(GpuRegister rd, GpuRegister rt, int shamt);
493 void Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
494 void Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Chris Larsen9aebff22015-09-22 17:54:15 -0700495 void Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700496 void Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs);
497 void Dsll(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
498 void Dsrl(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800499 void Drotr(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700500 void Dsra(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
501 void Dsll32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
502 void Dsrl32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700503 void Drotr32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700504 void Dsra32(GpuRegister rd, GpuRegister rt, int shamt); // MIPS64
505 void Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
506 void Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Chris Larsen9aebff22015-09-22 17:54:15 -0700507 void Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700508 void Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800509
510 void Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
511 void Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
512 void Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700513 void Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800514 void Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
515 void Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700516 void Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze19f6c692016-11-30 19:19:55 -0800517 void Lwpc(GpuRegister rs, uint32_t imm19);
518 void Lwupc(GpuRegister rs, uint32_t imm19); // MIPS64
519 void Ldpc(GpuRegister rs, uint32_t imm18); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800520 void Lui(GpuRegister rt, uint16_t imm16);
Alexey Frunze0960ac52016-12-20 17:24:59 -0800521 void Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunzec061de12017-02-14 13:27:23 -0800522 void Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunzec857c742015-09-23 15:12:39 -0700523 void Dahi(GpuRegister rs, uint16_t imm16); // MIPS64
524 void Dati(GpuRegister rs, uint16_t imm16); // MIPS64
Alexey Frunze4dda3372015-06-01 18:31:49 -0700525 void Sync(uint32_t stype);
Andreas Gampe57b34292015-01-14 15:45:59 -0800526
527 void Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16);
528 void Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16);
529 void Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700530 void Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800531
532 void Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt);
533 void Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt);
534 void Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16);
535 void Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700536 void Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt);
537 void Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt);
538 void Clz(GpuRegister rd, GpuRegister rs);
539 void Clo(GpuRegister rd, GpuRegister rs);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800540 void Dclz(GpuRegister rd, GpuRegister rs); // MIPS64
541 void Dclo(GpuRegister rd, GpuRegister rs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800542
Alexey Frunze4dda3372015-06-01 18:31:49 -0700543 void Jalr(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800544 void Jalr(GpuRegister rs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700545 void Jr(GpuRegister rs);
Alexey Frunzec857c742015-09-23 15:12:39 -0700546 void Auipc(GpuRegister rs, uint16_t imm16);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700547 void Addiupc(GpuRegister rs, uint32_t imm19);
548 void Bc(uint32_t imm26);
Alexey Frunze19f6c692016-11-30 19:19:55 -0800549 void Balc(uint32_t imm26);
Alexey Frunzec857c742015-09-23 15:12:39 -0700550 void Jic(GpuRegister rt, uint16_t imm16);
551 void Jialc(GpuRegister rt, uint16_t imm16);
552 void Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
553 void Bltzc(GpuRegister rt, uint16_t imm16);
554 void Bgtzc(GpuRegister rt, uint16_t imm16);
555 void Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
556 void Bgezc(GpuRegister rt, uint16_t imm16);
557 void Blezc(GpuRegister rt, uint16_t imm16);
558 void Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
559 void Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
560 void Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16);
561 void Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16);
562 void Beqzc(GpuRegister rs, uint32_t imm21);
563 void Bnezc(GpuRegister rs, uint32_t imm21);
Alexey Frunze299a9392015-12-08 16:08:02 -0800564 void Bc1eqz(FpuRegister ft, uint16_t imm16);
565 void Bc1nez(FpuRegister ft, uint16_t imm16);
Alexey Frunze0cab6562017-07-25 15:19:36 -0700566 void Beq(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
567 void Bne(GpuRegister rs, GpuRegister rt, uint16_t imm16); // R2
568 void Beqz(GpuRegister rt, uint16_t imm16); // R2
569 void Bnez(GpuRegister rt, uint16_t imm16); // R2
570 void Bltz(GpuRegister rt, uint16_t imm16); // R2
571 void Bgez(GpuRegister rt, uint16_t imm16); // R2
572 void Blez(GpuRegister rt, uint16_t imm16); // R2
573 void Bgtz(GpuRegister rt, uint16_t imm16); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -0800574
575 void AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
576 void SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
577 void MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
578 void DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
579 void AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
580 void SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
581 void MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
582 void DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700583 void SqrtS(FpuRegister fd, FpuRegister fs);
584 void SqrtD(FpuRegister fd, FpuRegister fs);
585 void AbsS(FpuRegister fd, FpuRegister fs);
586 void AbsD(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800587 void MovS(FpuRegister fd, FpuRegister fs);
588 void MovD(FpuRegister fd, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700589 void NegS(FpuRegister fd, FpuRegister fs);
590 void NegD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700591 void RoundLS(FpuRegister fd, FpuRegister fs);
592 void RoundLD(FpuRegister fd, FpuRegister fs);
593 void RoundWS(FpuRegister fd, FpuRegister fs);
594 void RoundWD(FpuRegister fd, FpuRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800595 void TruncLS(FpuRegister fd, FpuRegister fs);
596 void TruncLD(FpuRegister fd, FpuRegister fs);
597 void TruncWS(FpuRegister fd, FpuRegister fs);
598 void TruncWD(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700599 void CeilLS(FpuRegister fd, FpuRegister fs);
600 void CeilLD(FpuRegister fd, FpuRegister fs);
601 void CeilWS(FpuRegister fd, FpuRegister fs);
602 void CeilWD(FpuRegister fd, FpuRegister fs);
603 void FloorLS(FpuRegister fd, FpuRegister fs);
604 void FloorLD(FpuRegister fd, FpuRegister fs);
605 void FloorWS(FpuRegister fd, FpuRegister fs);
606 void FloorWD(FpuRegister fd, FpuRegister fs);
607 void SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
608 void SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Goran Jakovljevic2dec9272017-08-02 11:41:26 +0200609 void SeleqzS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
610 void SeleqzD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
611 void SelnezS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
612 void SelnezD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700613 void RintS(FpuRegister fd, FpuRegister fs);
614 void RintD(FpuRegister fd, FpuRegister fs);
615 void ClassS(FpuRegister fd, FpuRegister fs);
616 void ClassD(FpuRegister fd, FpuRegister fs);
617 void MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
618 void MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
619 void MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
620 void MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze299a9392015-12-08 16:08:02 -0800621 void CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
622 void CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
623 void CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
624 void CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
625 void CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
626 void CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
627 void CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
628 void CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
629 void CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
630 void CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft);
631 void CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
632 void CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
633 void CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
634 void CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
635 void CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
636 void CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
637 void CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
638 void CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
639 void CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
640 void CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700641
642 void Cvtsw(FpuRegister fd, FpuRegister fs);
643 void Cvtdw(FpuRegister fd, FpuRegister fs);
644 void Cvtsd(FpuRegister fd, FpuRegister fs);
645 void Cvtds(FpuRegister fd, FpuRegister fs);
Chris Larsen51417632015-10-02 13:24:25 -0700646 void Cvtsl(FpuRegister fd, FpuRegister fs);
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700647 void Cvtdl(FpuRegister fd, FpuRegister fs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800648
649 void Mfc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200650 void Mfhc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700651 void Mtc1(GpuRegister rt, FpuRegister fs);
Lazar Trsicd9672662015-09-03 17:33:01 +0200652 void Mthc1(GpuRegister rt, FpuRegister fs);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700653 void Dmfc1(GpuRegister rt, FpuRegister fs); // MIPS64
654 void Dmtc1(GpuRegister rt, FpuRegister fs); // MIPS64
Andreas Gampe57b34292015-01-14 15:45:59 -0800655 void Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
656 void Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
657 void Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
658 void Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16);
659
660 void Break();
661 void Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -0700662 void Move(GpuRegister rd, GpuRegister rs);
663 void Clear(GpuRegister rd);
664 void Not(GpuRegister rd, GpuRegister rs);
Andreas Gampe57b34292015-01-14 15:45:59 -0800665
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000666 // MSA instructions.
667 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
668 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
669 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
670 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
671
672 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
673 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
674 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
675 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
676 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
677 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
678 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
679 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
680 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
681 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
682 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
683 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
684 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
685 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
686 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
687 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
688 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
689 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
690 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
691 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
692 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
693 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
694 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
695 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
696 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
697 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
698 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
699 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic80248d72017-04-20 11:55:47 +0200700 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
701 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
702 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
703 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
704 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
705 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
706 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
707 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
708 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
709 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
710 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
711 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
712 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
713 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
714 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
715 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
716 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
717 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
718 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
719 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200720 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
721 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
722 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
723 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
724 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
725 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
726 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
727 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
728 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
729 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
730 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
731 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
732 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
733 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
734 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
735 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000736
737 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
738 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
739 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
740 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
741 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
742 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
743 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
744 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic658263e2017-06-07 09:35:53 +0200745 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
746 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
747 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
748 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000749
750 void Ffint_sW(VectorRegister wd, VectorRegister ws);
751 void Ffint_sD(VectorRegister wd, VectorRegister ws);
752 void Ftint_sW(VectorRegister wd, VectorRegister ws);
753 void Ftint_sD(VectorRegister wd, VectorRegister ws);
754
755 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
756 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
757 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
758 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
759 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
760 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
761 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
762 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
763 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
764 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
765 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
766 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
767
768 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
769 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
770 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
771 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
772 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
773 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
774 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
775 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
776 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
777 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
778 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
779 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
780 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
781
782 void MoveV(VectorRegister wd, VectorRegister ws);
783 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
784 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
785 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
786 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
787 void FillB(VectorRegister wd, GpuRegister rs);
788 void FillH(VectorRegister wd, GpuRegister rs);
789 void FillW(VectorRegister wd, GpuRegister rs);
790 void FillD(VectorRegister wd, GpuRegister rs);
791
Goran Jakovljevic3f444032017-03-31 14:38:20 +0200792 void LdiB(VectorRegister wd, int imm8);
793 void LdiH(VectorRegister wd, int imm10);
794 void LdiW(VectorRegister wd, int imm10);
795 void LdiD(VectorRegister wd, int imm10);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000796 void LdB(VectorRegister wd, GpuRegister rs, int offset);
797 void LdH(VectorRegister wd, GpuRegister rs, int offset);
798 void LdW(VectorRegister wd, GpuRegister rs, int offset);
799 void LdD(VectorRegister wd, GpuRegister rs, int offset);
800 void StB(VectorRegister wd, GpuRegister rs, int offset);
801 void StH(VectorRegister wd, GpuRegister rs, int offset);
802 void StW(VectorRegister wd, GpuRegister rs, int offset);
803 void StD(VectorRegister wd, GpuRegister rs, int offset);
804
Goran Jakovljevic38370112017-05-10 14:30:28 +0200805 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
806 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
807 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
808 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
809
Lena Djokicb3d79e42017-07-25 11:20:52 +0200810 void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
811 void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
812 void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
813 void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
814 void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
815 void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
816 void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
817 void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
818 void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
819 void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
820 void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
821 void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
822
Goran Jakovljevic19680d32017-05-11 10:38:36 +0200823 // Helper for replicating floating point value in all destination elements.
824 void ReplicateFPToVectorRegister(VectorRegister dst, FpuRegister src, bool is_double);
825
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700826 // Higher level composite instructions.
Chris Larsenc733dca2016-05-13 16:11:47 -0700827 int InstrCountForLoadReplicatedConst32(int64_t);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700828 void LoadConst32(GpuRegister rd, int32_t value);
829 void LoadConst64(GpuRegister rd, int64_t value); // MIPS64
830
Chris Larsenc733dca2016-05-13 16:11:47 -0700831 // This function is only used for testing purposes.
832 void RecordLoadConst64Path(int value);
833
Alexey Frunze0960ac52016-12-20 17:24:59 -0800834 void Addiu32(GpuRegister rt, GpuRegister rs, int32_t value);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700835 void Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp = AT); // MIPS64
836
Alexey Frunzec061de12017-02-14 13:27:23 -0800837 //
838 // Heap poisoning.
839 //
840
841 // Poison a heap reference contained in `src` and store it in `dst`.
842 void PoisonHeapReference(GpuRegister dst, GpuRegister src) {
843 // dst = -src.
844 // Negate the 32-bit ref.
845 Dsubu(dst, ZERO, src);
846 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
847 Dext(dst, dst, 0, 32);
848 }
849 // Poison a heap reference contained in `reg`.
850 void PoisonHeapReference(GpuRegister reg) {
851 // reg = -reg.
852 PoisonHeapReference(reg, reg);
853 }
854 // Unpoison a heap reference contained in `reg`.
855 void UnpoisonHeapReference(GpuRegister reg) {
856 // reg = -reg.
857 // Negate the 32-bit ref.
858 Dsubu(reg, ZERO, reg);
859 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64.
860 Dext(reg, reg, 0, 32);
861 }
862 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
863 void MaybePoisonHeapReference(GpuRegister reg) {
864 if (kPoisonHeapReferences) {
865 PoisonHeapReference(reg);
866 }
867 }
868 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
869 void MaybeUnpoisonHeapReference(GpuRegister reg) {
870 if (kPoisonHeapReferences) {
871 UnpoisonHeapReference(reg);
872 }
873 }
874
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700875 void Bind(Label* label) OVERRIDE {
876 Bind(down_cast<Mips64Label*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700877 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700878 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
879 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS64";
880 }
881
882 void Bind(Mips64Label* label);
Igor Murashkinae7ff922016-10-06 14:59:19 -0700883
884 // Don't warn about a different virtual Bind/Jump in the base class.
885 using JNIBase::Bind;
886 using JNIBase::Jump;
887
888 // Create a new label that can be used with Jump/Bind calls.
889 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
890 LOG(FATAL) << "Not implemented on MIPS64";
891 UNREACHABLE();
892 }
893 // Emit an unconditional jump to the label.
894 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
895 LOG(FATAL) << "Not implemented on MIPS64";
896 UNREACHABLE();
897 }
898 // Emit a conditional jump to the label by applying a unary condition test to the register.
899 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
900 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
901 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
902 LOG(FATAL) << "Not implemented on MIPS64";
903 UNREACHABLE();
904 }
905
906 // Code at this offset will serve as the target for the Jump call.
907 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
908 LOG(FATAL) << "Not implemented on MIPS64";
909 UNREACHABLE();
910 }
911
Alexey Frunze19f6c692016-11-30 19:19:55 -0800912 // Create a new literal with a given value.
913 // NOTE: Force the template parameter to be explicitly specified.
914 template <typename T>
915 Literal* NewLiteral(typename Identity<T>::type value) {
916 static_assert(std::is_integral<T>::value, "T must be an integral type.");
917 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
918 }
919
920 // Load label address using PC-relative loads. To be used with data labels in the literal /
921 // jump table area only and not with regular code labels.
922 void LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label);
923
924 // Create a new literal with the given data.
925 Literal* NewLiteral(size_t size, const uint8_t* data);
926
927 // Load literal using PC-relative loads.
928 void LoadLiteral(GpuRegister dest_reg, LoadOperandType load_type, Literal* literal);
929
Alexey Frunze0960ac52016-12-20 17:24:59 -0800930 // Create a jump table for the given labels that will be emitted when finalizing.
931 // When the table is emitted, offsets will be relative to the location of the table.
932 // The table location is determined by the location of its label (the label precedes
933 // the table data) and should be loaded using LoadLabelAddress().
934 JumpTable* CreateJumpTable(std::vector<Mips64Label*>&& labels);
935
Alexey Frunze0cab6562017-07-25 15:19:36 -0700936 // When `is_bare` is false, the branches will promote to long (if the range
937 // of the individual branch instruction is insufficient) and the delay/
938 // forbidden slots will be taken care of.
939 // Use `is_bare = false` when the branch target may be out of reach of the
940 // individual branch instruction. IOW, this is for general purpose use.
941 //
942 // When `is_bare` is true, just the branch instructions will be generated
943 // leaving delay/forbidden slot filling up to the caller and the branches
944 // won't promote to long if the range is insufficient (you'll get a
945 // compilation error when the range is exceeded).
946 // Use `is_bare = true` when the branch target is known to be within reach
947 // of the individual branch instruction. This is intended for small local
948 // optimizations around delay/forbidden slots.
949 // Also prefer using `is_bare = true` if the code near the branch is to be
950 // patched or analyzed at run time (e.g. introspection) to
951 // - show the intent and
952 // - fail during compilation rather than during patching/execution if the
953 // bare branch range is insufficent but the code size and layout are
954 // expected to remain unchanged
955 //
956 // R6 compact branches without delay/forbidden slots.
957 void Bc(Mips64Label* label, bool is_bare = false);
958 void Balc(Mips64Label* label, bool is_bare = false);
959 // R6 compact branches with forbidden slots.
960 void Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
961 void Bltzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
962 void Bgtzc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
963 void Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
964 void Bgezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
965 void Blezc(GpuRegister rt, Mips64Label* label, bool is_bare = false);
966 void Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
967 void Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
968 void Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
969 void Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false);
970 void Beqzc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
971 void Bnezc(GpuRegister rs, Mips64Label* label, bool is_bare = false);
972 // R6 branches with delay slots.
973 void Bc1eqz(FpuRegister ft, Mips64Label* label, bool is_bare = false);
974 void Bc1nez(FpuRegister ft, Mips64Label* label, bool is_bare = false);
975 // R2 branches with delay slots that are also available on R6.
976 // The `is_bare` parameter exists and is checked in these branches only to
977 // prevent programming mistakes. These branches never promote to long, not
978 // even if `is_bare` is false.
979 void Bltz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
980 void Bgtz(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
981 void Bgez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
982 void Blez(GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
983 void Beq(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
984 void Bne(GpuRegister rs, GpuRegister rt, Mips64Label* label, bool is_bare = false); // R2
985 void Beqz(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
986 void Bnez(GpuRegister rs, Mips64Label* label, bool is_bare = false); // R2
Andreas Gampe57b34292015-01-14 15:45:59 -0800987
988 void EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset, size_t size);
Chris Larsenc3fec0c2016-12-15 11:44:14 -0800989 void AdjustBaseAndOffset(GpuRegister& base, int32_t& offset, bool is_doubleword);
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +0200990 // If element_size_shift is negative at entry, its value will be calculated based on the offset.
991 void AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
992 int32_t& offset,
993 int& element_size_shift);
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100994
995 private:
996 // This will be used as an argument for loads/stores
997 // when there is no need for implicit null checks.
998 struct NoImplicitNullChecker {
999 void operator()() const {}
1000 };
1001
1002 public:
1003 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001004 void StoreConstToOffset(StoreOperandType type,
1005 int64_t value,
1006 GpuRegister base,
1007 int32_t offset,
1008 GpuRegister temp,
1009 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
1010 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
1011 // in which case the `base` register may be overwritten in the process.
1012 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 -08001013 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevicba89c342017-03-10 13:36:08 +01001014 GpuRegister reg;
1015 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
1016 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
1017 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
1018 // original `base` (that is, `base` prior to the adjustment), the original `base`
1019 // register will be overwritten.
1020 if (base == temp) {
1021 temp = AT;
1022 }
1023
1024 if (type == kStoreDoubleword && IsAligned<kMips64DoublewordSize>(offset)) {
1025 if (value == 0) {
1026 reg = ZERO;
1027 } else {
1028 reg = temp;
1029 LoadConst64(reg, value);
1030 }
1031 Sd(reg, base, offset);
1032 null_checker();
1033 } else {
1034 uint32_t low = Low32Bits(value);
1035 uint32_t high = High32Bits(value);
1036 if (low == 0) {
1037 reg = ZERO;
1038 } else {
1039 reg = temp;
1040 LoadConst32(reg, low);
1041 }
1042 switch (type) {
1043 case kStoreByte:
1044 Sb(reg, base, offset);
1045 break;
1046 case kStoreHalfword:
1047 Sh(reg, base, offset);
1048 break;
1049 case kStoreWord:
1050 Sw(reg, base, offset);
1051 break;
1052 case kStoreDoubleword:
1053 // not aligned to kMips64DoublewordSize
1054 CHECK_ALIGNED(offset, kMips64WordSize);
1055 Sw(reg, base, offset);
1056 null_checker();
1057 if (high == 0) {
1058 reg = ZERO;
1059 } else {
1060 reg = temp;
1061 if (high != low) {
1062 LoadConst32(reg, high);
1063 }
1064 }
1065 Sw(reg, base, offset + kMips64WordSize);
1066 break;
1067 default:
1068 LOG(FATAL) << "UNREACHABLE";
1069 }
1070 if (type != kStoreDoubleword) {
1071 null_checker();
1072 }
1073 }
1074 }
1075
1076 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001077 void LoadFromOffset(LoadOperandType type,
1078 GpuRegister reg,
1079 GpuRegister base,
1080 int32_t offset,
1081 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001082 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001083
1084 switch (type) {
1085 case kLoadSignedByte:
1086 Lb(reg, base, offset);
1087 break;
1088 case kLoadUnsignedByte:
1089 Lbu(reg, base, offset);
1090 break;
1091 case kLoadSignedHalfword:
1092 Lh(reg, base, offset);
1093 break;
1094 case kLoadUnsignedHalfword:
1095 Lhu(reg, base, offset);
1096 break;
1097 case kLoadWord:
1098 CHECK_ALIGNED(offset, kMips64WordSize);
1099 Lw(reg, base, offset);
1100 break;
1101 case kLoadUnsignedWord:
1102 CHECK_ALIGNED(offset, kMips64WordSize);
1103 Lwu(reg, base, offset);
1104 break;
1105 case kLoadDoubleword:
1106 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1107 CHECK_ALIGNED(offset, kMips64WordSize);
1108 Lwu(reg, base, offset);
1109 null_checker();
1110 Lwu(TMP2, base, offset + kMips64WordSize);
1111 Dinsu(reg, TMP2, 32, 32);
1112 } else {
1113 Ld(reg, base, offset);
1114 null_checker();
1115 }
1116 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001117 default:
1118 LOG(FATAL) << "UNREACHABLE";
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001119 }
1120 if (type != kLoadDoubleword) {
1121 null_checker();
1122 }
1123 }
1124
1125 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1126 void LoadFpuFromOffset(LoadOperandType type,
1127 FpuRegister reg,
1128 GpuRegister base,
1129 int32_t offset,
1130 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001131 int element_size_shift = -1;
1132 if (type != kLoadQuadword) {
1133 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
1134 } else {
1135 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1136 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001137
1138 switch (type) {
1139 case kLoadWord:
1140 CHECK_ALIGNED(offset, kMips64WordSize);
1141 Lwc1(reg, base, offset);
1142 null_checker();
1143 break;
1144 case kLoadDoubleword:
1145 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1146 CHECK_ALIGNED(offset, kMips64WordSize);
1147 Lwc1(reg, base, offset);
1148 null_checker();
1149 Lw(TMP2, base, offset + kMips64WordSize);
1150 Mthc1(TMP2, reg);
1151 } else {
1152 Ldc1(reg, base, offset);
1153 null_checker();
1154 }
1155 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001156 case kLoadQuadword:
1157 switch (element_size_shift) {
1158 case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break;
1159 case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break;
1160 case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break;
1161 case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break;
1162 default:
1163 LOG(FATAL) << "UNREACHABLE";
1164 }
1165 null_checker();
1166 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001167 default:
1168 LOG(FATAL) << "UNREACHABLE";
1169 }
1170 }
1171
1172 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1173 void StoreToOffset(StoreOperandType type,
1174 GpuRegister reg,
1175 GpuRegister base,
1176 int32_t offset,
1177 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Chris Larsenc3fec0c2016-12-15 11:44:14 -08001178 // Must not use AT as `reg`, so as not to overwrite the value being stored
1179 // with the adjusted `base`.
1180 CHECK_NE(reg, AT);
1181 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001182
1183 switch (type) {
1184 case kStoreByte:
1185 Sb(reg, base, offset);
1186 break;
1187 case kStoreHalfword:
1188 Sh(reg, base, offset);
1189 break;
1190 case kStoreWord:
1191 CHECK_ALIGNED(offset, kMips64WordSize);
1192 Sw(reg, base, offset);
1193 break;
1194 case kStoreDoubleword:
1195 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1196 CHECK_ALIGNED(offset, kMips64WordSize);
1197 Sw(reg, base, offset);
1198 null_checker();
1199 Dsrl32(TMP2, reg, 0);
1200 Sw(TMP2, base, offset + kMips64WordSize);
1201 } else {
1202 Sd(reg, base, offset);
1203 null_checker();
1204 }
1205 break;
1206 default:
1207 LOG(FATAL) << "UNREACHABLE";
1208 }
1209 if (type != kStoreDoubleword) {
1210 null_checker();
1211 }
1212 }
1213
1214 template <typename ImplicitNullChecker = NoImplicitNullChecker>
1215 void StoreFpuToOffset(StoreOperandType type,
1216 FpuRegister reg,
1217 GpuRegister base,
1218 int32_t offset,
1219 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001220 int element_size_shift = -1;
1221 if (type != kStoreQuadword) {
1222 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
1223 } else {
1224 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
1225 }
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001226
1227 switch (type) {
1228 case kStoreWord:
1229 CHECK_ALIGNED(offset, kMips64WordSize);
1230 Swc1(reg, base, offset);
1231 null_checker();
1232 break;
1233 case kStoreDoubleword:
1234 if (!IsAligned<kMips64DoublewordSize>(offset)) {
1235 CHECK_ALIGNED(offset, kMips64WordSize);
1236 Mfhc1(TMP2, reg);
1237 Swc1(reg, base, offset);
1238 null_checker();
1239 Sw(TMP2, base, offset + kMips64WordSize);
1240 } else {
1241 Sdc1(reg, base, offset);
1242 null_checker();
1243 }
1244 break;
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02001245 case kStoreQuadword:
1246 switch (element_size_shift) {
1247 case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break;
1248 case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break;
1249 case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break;
1250 case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break;
1251 default:
1252 LOG(FATAL) << "UNREACHABLE";
1253 }
1254 null_checker();
1255 break;
Tijana Jakovljevic57433862017-01-17 16:59:03 +01001256 default:
1257 LOG(FATAL) << "UNREACHABLE";
1258 }
1259 }
1260
Andreas Gampe57b34292015-01-14 15:45:59 -08001261 void LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1262 void LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1263 void StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base, int32_t offset);
1264 void StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base, int32_t offset);
1265
1266 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001267 void Emit(uint32_t value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001268
1269 //
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001270 // Overridden common assembler high-level functionality.
Andreas Gampe57b34292015-01-14 15:45:59 -08001271 //
1272
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001273 // Emit code that will create an activation on the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001274 void BuildFrame(size_t frame_size,
1275 ManagedRegister method_reg,
1276 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001277 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
1278
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001279 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001280 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001281
1282 void IncreaseFrameSize(size_t adjust) OVERRIDE;
1283 void DecreaseFrameSize(size_t adjust) OVERRIDE;
1284
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001285 // Store routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001286 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
1287 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1288 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1289
1290 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
1291
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001292 void StoreStackOffsetToThread(ThreadOffset64 thr_offs,
1293 FrameOffset fr_offs,
1294 ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001295
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001296 void StoreStackPointerToThread(ThreadOffset64 thr_offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001297
1298 void StoreSpanning(FrameOffset dest, ManagedRegister msrc, FrameOffset in_off,
1299 ManagedRegister mscratch) OVERRIDE;
1300
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001301 // Load routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001302 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
1303
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001304 void LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001305
Mathieu Chartiere401d142015-04-22 13:56:20 -07001306 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001307
Mathieu Chartiere401d142015-04-22 13:56:20 -07001308 void LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001309 bool unpoison_reference) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001310
1311 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
1312
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001313 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001314
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001315 // Copying routines.
Andreas Gampe57b34292015-01-14 15:45:59 -08001316 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
1317
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001318 void CopyRawPtrFromThread(FrameOffset fr_offs,
1319 ThreadOffset64 thr_offs,
Andreas Gampe57b34292015-01-14 15:45:59 -08001320 ManagedRegister mscratch) OVERRIDE;
1321
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001322 void CopyRawPtrToThread(ThreadOffset64 thr_offs,
1323 FrameOffset fr_offs,
1324 ManagedRegister mscratch) OVERRIDE;
1325
Andreas Gampe57b34292015-01-14 15:45:59 -08001326 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
1327
1328 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
1329
1330 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister mscratch,
1331 size_t size) OVERRIDE;
1332
1333 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
1334 ManagedRegister mscratch, size_t size) OVERRIDE;
1335
1336 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister mscratch,
1337 size_t size) OVERRIDE;
1338
1339 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
1340 ManagedRegister mscratch, size_t size) OVERRIDE;
1341
1342 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
1343 ManagedRegister mscratch, size_t size) OVERRIDE;
1344
1345 void MemoryBarrier(ManagedRegister) OVERRIDE;
1346
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001347 // Sign extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001348 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1349
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001350 // Zero extension.
Andreas Gampe57b34292015-01-14 15:45:59 -08001351 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
1352
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001353 // Exploit fast access in managed code to Thread::Current().
Andreas Gampe57b34292015-01-14 15:45:59 -08001354 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1355 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
1356
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001357 // 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 -08001358 // value is null and null_allowed. in_reg holds a possibly stale reference
1359 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001360 // null.
Andreas Gampe57b34292015-01-14 15:45:59 -08001361 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
1362 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
1363
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001364 // 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 -08001365 // value is null and null_allowed.
1366 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset, ManagedRegister
1367 mscratch, bool null_allowed) OVERRIDE;
1368
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001369 // src holds a handle scope entry (Object**) load this into dst.
Andreas Gampe57b34292015-01-14 15:45:59 -08001370 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
1371
1372 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1373 // know that src may not be null.
1374 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1375 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
1376
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001377 // Call to address held at [base+offset].
Andreas Gampe57b34292015-01-14 15:45:59 -08001378 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1379 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001380 void CallFromThread(ThreadOffset64 offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe57b34292015-01-14 15:45:59 -08001381
1382 // Generate code to check if Thread::Current()->exception_ is non-null
1383 // and branch to a ExceptionSlowPath if it is.
1384 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
1385
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001386 // Emit slow paths queued during assembly and promote short branches to long if needed.
1387 void FinalizeCode() OVERRIDE;
1388
1389 // Emit branches and finalize all instructions.
1390 void FinalizeInstructions(const MemoryRegion& region);
1391
1392 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS64,
1393 // must be used instead of Mips64Label::GetPosition()).
Alexey Frunze19f6c692016-11-30 19:19:55 -08001394 uint32_t GetLabelLocation(const Mips64Label* label) const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001395
1396 // Get the final position of a label after local fixup based on the old position
1397 // recorded before FinalizeCode().
1398 uint32_t GetAdjustedPosition(uint32_t old_position);
1399
Alexey Frunze19f6c692016-11-30 19:19:55 -08001400 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1401 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1402 // to PC.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001403 enum BranchCondition {
1404 kCondLT,
1405 kCondGE,
1406 kCondLE,
1407 kCondGT,
1408 kCondLTZ,
1409 kCondGEZ,
1410 kCondLEZ,
1411 kCondGTZ,
1412 kCondEQ,
1413 kCondNE,
1414 kCondEQZ,
1415 kCondNEZ,
1416 kCondLTU,
1417 kCondGEU,
Alexey Frunze299a9392015-12-08 16:08:02 -08001418 kCondF, // Floating-point predicate false.
1419 kCondT, // Floating-point predicate true.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001420 kUncond,
1421 };
1422 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1423
Andreas Gampe57b34292015-01-14 15:45:59 -08001424 private:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001425 class Branch {
1426 public:
1427 enum Type {
Alexey Frunze0cab6562017-07-25 15:19:36 -07001428 // R6 short branches (can be promoted to long).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001429 kUncondBranch,
1430 kCondBranch,
1431 kCall,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001432 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
1433 kBareUncondBranch,
1434 kBareCondBranch,
1435 kBareCall,
1436 // R2 short branches (can't be promoted to long), delay slots filled manually.
1437 kR2BareCondBranch,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001438 // Near label.
1439 kLabel,
1440 // Near literals.
1441 kLiteral,
1442 kLiteralUnsigned,
1443 kLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001444 // Long branches.
1445 kLongUncondBranch,
1446 kLongCondBranch,
1447 kLongCall,
Alexey Frunze19f6c692016-11-30 19:19:55 -08001448 // Far label.
1449 kFarLabel,
1450 // Far literals.
1451 kFarLiteral,
1452 kFarLiteralUnsigned,
1453 kFarLiteralLong,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001454 };
1455
1456 // Bit sizes of offsets defined as enums to minimize chance of typos.
1457 enum OffsetBits {
1458 kOffset16 = 16,
1459 kOffset18 = 18,
1460 kOffset21 = 21,
1461 kOffset23 = 23,
1462 kOffset28 = 28,
1463 kOffset32 = 32,
1464 };
1465
1466 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1467 static constexpr int32_t kMaxBranchLength = 32;
1468 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
1469
1470 struct BranchInfo {
1471 // Branch length as a number of 4-byte-long instructions.
1472 uint32_t length;
1473 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1474 // PC-relative offset (or its most significant 16-bit half, which goes first).
1475 uint32_t instr_offset;
1476 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1477 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1478 // instructions) from the instruction containing the offset.
1479 uint32_t pc_org;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001480 // How large (in bits) a PC-relative offset can be for a given type of branch (kCondBranch
1481 // and kBareCondBranch are an exception: use kOffset23 for beqzc/bnezc).
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001482 OffsetBits offset_size;
1483 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1484 // count.
1485 int offset_shift;
1486 };
1487 static const BranchInfo branch_info_[/* Type */];
1488
Alexey Frunze19f6c692016-11-30 19:19:55 -08001489 // Unconditional branch or call.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001490 Branch(uint32_t location, uint32_t target, bool is_call, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001491 // Conditional branch.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001492 Branch(bool is_r6,
1493 uint32_t location,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001494 uint32_t target,
1495 BranchCondition condition,
1496 GpuRegister lhs_reg,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001497 GpuRegister rhs_reg,
1498 bool is_bare);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001499 // Label address (in literal area) or literal.
1500 Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001501
1502 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1503 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1504 // So, we need a way to identify such branches in order to emit no instructions for them
1505 // or change them to unconditional.
1506 static bool IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1507 static bool IsUncond(BranchCondition condition, GpuRegister lhs, GpuRegister rhs);
1508
1509 static BranchCondition OppositeCondition(BranchCondition cond);
1510
1511 Type GetType() const;
1512 BranchCondition GetCondition() const;
1513 GpuRegister GetLeftRegister() const;
1514 GpuRegister GetRightRegister() const;
1515 uint32_t GetTarget() const;
1516 uint32_t GetLocation() const;
1517 uint32_t GetOldLocation() const;
1518 uint32_t GetLength() const;
1519 uint32_t GetOldLength() const;
1520 uint32_t GetSize() const;
1521 uint32_t GetOldSize() const;
1522 uint32_t GetEndLocation() const;
1523 uint32_t GetOldEndLocation() const;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001524 bool IsBare() const;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001525 bool IsLong() const;
1526 bool IsResolved() const;
1527
1528 // Returns the bit size of the signed offset that the branch instruction can handle.
1529 OffsetBits GetOffsetSize() const;
1530
1531 // Calculates the distance between two byte locations in the assembler buffer and
1532 // returns the number of bits needed to represent the distance as a signed integer.
1533 //
1534 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1535 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1536 //
1537 // Composite branches (made of several instructions) with longer reach have 32-bit
1538 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
1539 // The composite branches cover the range of PC + ~+/-2GB. The range is not end-to-end,
1540 // however. Consider the following implementation of a long unconditional branch, for
1541 // example:
1542 //
1543 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1544 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1545 //
1546 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1547 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1548 // due to sign extension. This must be compensated for by incrementing offset_31_16
1549 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1550 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1551 // Therefore, the long branch range is something like from PC - 0x80000000 to
1552 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
1553 //
1554 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1555 // case with the addiu instruction and a 16 bit offset.
1556 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1557
1558 // Resolve a branch when the target is known.
1559 void Resolve(uint32_t target);
1560
1561 // Relocate a branch by a given delta if needed due to expansion of this or another
1562 // branch at a given location by this delta (just changes location_ and target_).
1563 void Relocate(uint32_t expand_location, uint32_t delta);
1564
1565 // If the branch is short, changes its type to long.
1566 void PromoteToLong();
1567
1568 // If necessary, updates the type by promoting a short branch to a long branch
1569 // based on the branch location and target. Returns the amount (in bytes) by
1570 // which the branch size has increased.
1571 // max_short_distance caps the maximum distance between location_ and target_
1572 // that is allowed for short branches. This is for debugging/testing purposes.
1573 // max_short_distance = 0 forces all short branches to become long.
1574 // Use the implicit default argument when not debugging/testing.
1575 uint32_t PromoteIfNeeded(uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
1576
1577 // Returns the location of the instruction(s) containing the offset.
1578 uint32_t GetOffsetLocation() const;
1579
1580 // Calculates and returns the offset ready for encoding in the branch instruction(s).
1581 uint32_t GetOffset() const;
1582
1583 private:
1584 // Completes branch construction by determining and recording its type.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001585 void InitializeType(Type initial_type, bool is_r6);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001586 // Helper for the above.
1587 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1588
1589 uint32_t old_location_; // Offset into assembler buffer in bytes.
1590 uint32_t location_; // Offset into assembler buffer in bytes.
1591 uint32_t target_; // Offset into assembler buffer in bytes.
1592
1593 GpuRegister lhs_reg_; // Left-hand side register in conditional branches or
Alexey Frunze19f6c692016-11-30 19:19:55 -08001594 // destination register in literals.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001595 GpuRegister rhs_reg_; // Right-hand side register in conditional branches.
1596 BranchCondition condition_; // Condition for conditional branches.
1597
1598 Type type_; // Current type of the branch.
1599 Type old_type_; // Initial type of the branch.
1600 };
1601 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1602 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1603
Andreas Gampe57b34292015-01-14 15:45:59 -08001604 void EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001605 void EmitRsd(int opcode, GpuRegister rs, GpuRegister rd, int shamt, int funct);
1606 void EmitRtd(int opcode, GpuRegister rt, GpuRegister rd, int shamt, int funct);
Andreas Gampe57b34292015-01-14 15:45:59 -08001607 void EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001608 void EmitI21(int opcode, GpuRegister rs, uint32_t imm21);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001609 void EmitI26(int opcode, uint32_t imm26);
Andreas Gampe57b34292015-01-14 15:45:59 -08001610 void EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd, int funct);
1611 void EmitFI(int opcode, int fmt, FpuRegister rt, uint16_t imm);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001612 void EmitBcondR6(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint32_t imm16_21);
1613 void EmitBcondR2(BranchCondition cond, GpuRegister rs, GpuRegister rt, uint16_t imm16);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001614 void EmitMsa3R(int operation,
1615 int df,
1616 VectorRegister wt,
1617 VectorRegister ws,
1618 VectorRegister wd,
1619 int minor_opcode);
1620 void EmitMsaBIT(int operation, int df_m, VectorRegister ws, VectorRegister wd, int minor_opcode);
1621 void EmitMsaELM(int operation, int df_n, VectorRegister ws, VectorRegister wd, int minor_opcode);
1622 void EmitMsaMI10(int s10, GpuRegister rs, VectorRegister wd, int minor_opcode, int df);
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001623 void EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001624 void EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1625 void EmitMsa2RF(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001626
Alexey Frunze0cab6562017-07-25 15:19:36 -07001627 void Buncond(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001628 void Bcond(Mips64Label* label,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001629 bool is_r6,
1630 bool is_bare,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001631 BranchCondition condition,
1632 GpuRegister lhs,
1633 GpuRegister rhs = ZERO);
Alexey Frunze0cab6562017-07-25 15:19:36 -07001634 void Call(Mips64Label* label, bool is_bare);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001635 void FinalizeLabeledBranch(Mips64Label* label);
1636
1637 Branch* GetBranch(uint32_t branch_id);
1638 const Branch* GetBranch(uint32_t branch_id) const;
1639
Alexey Frunze19f6c692016-11-30 19:19:55 -08001640 void EmitLiterals();
Alexey Frunze0960ac52016-12-20 17:24:59 -08001641 void ReserveJumpTableSpace();
1642 void EmitJumpTables();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001643 void PromoteBranches();
1644 void EmitBranch(Branch* branch);
1645 void EmitBranches();
1646 void PatchCFI();
1647
1648 // Emits exception block.
1649 void EmitExceptionPoll(Mips64ExceptionSlowPath* exception);
1650
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001651 bool HasMsa() const {
1652 return has_msa_;
1653 }
1654
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001655 // List of exception blocks to generate at the end of the code cache.
1656 std::vector<Mips64ExceptionSlowPath> exception_blocks_;
1657
1658 std::vector<Branch> branches_;
1659
1660 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1661 bool overwriting_;
1662 // The current overwrite location.
1663 uint32_t overwrite_location_;
1664
Alexey Frunze19f6c692016-11-30 19:19:55 -08001665 // Use std::deque<> for literal labels to allow insertions at the end
1666 // without invalidating pointers and references to existing elements.
1667 ArenaDeque<Literal> literals_;
1668 ArenaDeque<Literal> long_literals_; // 64-bit literals separated for alignment reasons.
1669
Alexey Frunze0960ac52016-12-20 17:24:59 -08001670 // Jump table list.
1671 ArenaDeque<JumpTable> jump_tables_;
1672
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001673 // Data for AdjustedPosition(), see the description there.
1674 uint32_t last_position_adjustment_;
1675 uint32_t last_old_position_;
1676 uint32_t last_branch_id_;
Andreas Gampe57b34292015-01-14 15:45:59 -08001677
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001678 const bool has_msa_;
1679
Andreas Gampe57b34292015-01-14 15:45:59 -08001680 DISALLOW_COPY_AND_ASSIGN(Mips64Assembler);
1681};
1682
Andreas Gampe57b34292015-01-14 15:45:59 -08001683} // namespace mips64
1684} // namespace art
1685
1686#endif // ART_COMPILER_UTILS_MIPS64_ASSEMBLER_MIPS64_H_