blob: dd4ce6dc80447f8bf29c501b3e45203d62bd2088 [file] [log] [blame]
jeffhao7fbee072012-08-24 17:56:54 -07001/*
2 * Copyright (C) 2011 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
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_
18#define ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_
jeffhao7fbee072012-08-24 17:56:54 -070019
Alexey Frunzee3fb2452016-05-10 16:08:05 -070020#include <deque>
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020021#include <utility>
jeffhao7fbee072012-08-24 17:56:54 -070022#include <vector>
Elliott Hughes76160052012-12-12 16:31:20 -080023
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020024#include "arch/mips/instruction_set_features_mips.h"
Alexey Frunzee3fb2452016-05-10 16:08:05 -070025#include "base/arena_containers.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070026#include "base/enums.h"
Elliott Hughes76160052012-12-12 16:31:20 -080027#include "base/macros.h"
Andreas Gampe5678db52017-06-08 14:11:18 -070028#include "base/stl_util_identity.h"
jeffhao7fbee072012-08-24 17:56:54 -070029#include "constants_mips.h"
30#include "globals.h"
31#include "managed_register_mips.h"
jeffhao7fbee072012-08-24 17:56:54 -070032#include "offsets.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020033#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070034#include "utils/jni_macro_assembler.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020035#include "utils/label.h"
jeffhao7fbee072012-08-24 17:56:54 -070036
37namespace art {
38namespace mips {
jeffhao7fbee072012-08-24 17:56:54 -070039
Lena Djokic0758ae72017-05-23 11:06:23 +020040static constexpr size_t kMipsHalfwordSize = 2;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020041static constexpr size_t kMipsWordSize = 4;
42static constexpr size_t kMipsDoublewordSize = 8;
43
jeffhao7fbee072012-08-24 17:56:54 -070044enum LoadOperandType {
45 kLoadSignedByte,
46 kLoadUnsignedByte,
47 kLoadSignedHalfword,
48 kLoadUnsignedHalfword,
49 kLoadWord,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020050 kLoadDoubleword
jeffhao7fbee072012-08-24 17:56:54 -070051};
52
53enum StoreOperandType {
54 kStoreByte,
55 kStoreHalfword,
56 kStoreWord,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020057 kStoreDoubleword
58};
59
Chris Larsenb74353a2015-11-20 09:07:09 -080060// Used to test the values returned by ClassS/ClassD.
61enum FPClassMaskType {
62 kSignalingNaN = 0x001,
63 kQuietNaN = 0x002,
64 kNegativeInfinity = 0x004,
65 kNegativeNormal = 0x008,
66 kNegativeSubnormal = 0x010,
67 kNegativeZero = 0x020,
68 kPositiveInfinity = 0x040,
69 kPositiveNormal = 0x080,
70 kPositiveSubnormal = 0x100,
71 kPositiveZero = 0x200,
72};
73
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020074class MipsLabel : public Label {
75 public:
76 MipsLabel() : prev_branch_id_plus_one_(0) {}
77
78 MipsLabel(MipsLabel&& src)
79 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
80
81 private:
82 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
83
84 friend class MipsAssembler;
85 DISALLOW_COPY_AND_ASSIGN(MipsLabel);
86};
87
Alexey Frunzee3fb2452016-05-10 16:08:05 -070088// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
89class Literal {
90 public:
91 static constexpr size_t kMaxSize = 8;
92
93 Literal(uint32_t size, const uint8_t* data)
94 : label_(), size_(size) {
95 DCHECK_LE(size, Literal::kMaxSize);
96 memcpy(data_, data, size);
97 }
98
99 template <typename T>
100 T GetValue() const {
101 DCHECK_EQ(size_, sizeof(T));
102 T value;
103 memcpy(&value, data_, sizeof(T));
104 return value;
105 }
106
107 uint32_t GetSize() const {
108 return size_;
109 }
110
111 const uint8_t* GetData() const {
112 return data_;
113 }
114
115 MipsLabel* GetLabel() {
116 return &label_;
117 }
118
119 const MipsLabel* GetLabel() const {
120 return &label_;
121 }
122
123 private:
124 MipsLabel label_;
125 const uint32_t size_;
126 uint8_t data_[kMaxSize];
127
128 DISALLOW_COPY_AND_ASSIGN(Literal);
129};
130
Alexey Frunze96b66822016-09-10 02:32:44 -0700131// Jump table: table of labels emitted after the literals. Similar to literals.
132class JumpTable {
133 public:
134 explicit JumpTable(std::vector<MipsLabel*>&& labels)
135 : label_(), labels_(std::move(labels)) {
136 }
137
138 uint32_t GetSize() const {
139 return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
140 }
141
142 const std::vector<MipsLabel*>& GetData() const {
143 return labels_;
144 }
145
146 MipsLabel* GetLabel() {
147 return &label_;
148 }
149
150 const MipsLabel* GetLabel() const {
151 return &label_;
152 }
153
154 private:
155 MipsLabel label_;
156 std::vector<MipsLabel*> labels_;
157
158 DISALLOW_COPY_AND_ASSIGN(JumpTable);
159};
160
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200161// Slowpath entered when Thread::Current()->_exception is non-null.
162class MipsExceptionSlowPath {
163 public:
164 explicit MipsExceptionSlowPath(MipsManagedRegister scratch, size_t stack_adjust)
165 : scratch_(scratch), stack_adjust_(stack_adjust) {}
166
167 MipsExceptionSlowPath(MipsExceptionSlowPath&& src)
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800168 : scratch_(src.scratch_),
169 stack_adjust_(src.stack_adjust_),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200170 exception_entry_(std::move(src.exception_entry_)) {}
171
172 private:
173 MipsLabel* Entry() { return &exception_entry_; }
174 const MipsManagedRegister scratch_;
175 const size_t stack_adjust_;
176 MipsLabel exception_entry_;
177
178 friend class MipsAssembler;
179 DISALLOW_COPY_AND_ASSIGN(MipsExceptionSlowPath);
jeffhao7fbee072012-08-24 17:56:54 -0700180};
181
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700182class MipsAssembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> {
jeffhao7fbee072012-08-24 17:56:54 -0700183 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700184 using JNIBase = JNIMacroAssembler<PointerSize::k32>;
185
Vladimir Marko93205e32016-04-13 11:59:46 +0100186 explicit MipsAssembler(ArenaAllocator* arena,
187 const MipsInstructionSetFeatures* instruction_set_features = nullptr)
188 : Assembler(arena),
189 overwriting_(false),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200190 overwrite_location_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700191 reordering_(true),
192 ds_fsm_state_(kExpectingLabel),
193 ds_fsm_target_pc_(0),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700194 literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze96b66822016-09-10 02:32:44 -0700195 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200196 last_position_adjustment_(0),
197 last_old_position_(0),
198 last_branch_id_(0),
Lena Djokic0758ae72017-05-23 11:06:23 +0200199 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false),
Vladimir Marko10ef6942015-10-22 15:25:54 +0100200 isa_features_(instruction_set_features) {
201 cfi().DelayEmittingAdvancePCs();
202 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200203
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700204 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700205 size_t CodePosition() OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700206 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
207
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200208 virtual ~MipsAssembler() {
209 for (auto& branch : branches_) {
210 CHECK(branch.IsResolved());
211 }
212 }
jeffhao7fbee072012-08-24 17:56:54 -0700213
214 // Emit Machine Instructions.
jeffhao7fbee072012-08-24 17:56:54 -0700215 void Addu(Register rd, Register rs, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700216 void Addiu(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700217 void Subu(Register rd, Register rs, Register rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200218
219 void MultR2(Register rs, Register rt); // R2
220 void MultuR2(Register rs, Register rt); // R2
221 void DivR2(Register rs, Register rt); // R2
222 void DivuR2(Register rs, Register rt); // R2
223 void MulR2(Register rd, Register rs, Register rt); // R2
224 void DivR2(Register rd, Register rs, Register rt); // R2
225 void ModR2(Register rd, Register rs, Register rt); // R2
226 void DivuR2(Register rd, Register rs, Register rt); // R2
227 void ModuR2(Register rd, Register rs, Register rt); // R2
228 void MulR6(Register rd, Register rs, Register rt); // R6
Alexey Frunze7e99e052015-11-24 19:28:01 -0800229 void MuhR6(Register rd, Register rs, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200230 void MuhuR6(Register rd, Register rs, Register rt); // R6
231 void DivR6(Register rd, Register rs, Register rt); // R6
232 void ModR6(Register rd, Register rs, Register rt); // R6
233 void DivuR6(Register rd, Register rs, Register rt); // R6
234 void ModuR6(Register rd, Register rs, Register rt); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700235
236 void And(Register rd, Register rs, Register rt);
237 void Andi(Register rt, Register rs, uint16_t imm16);
238 void Or(Register rd, Register rs, Register rt);
239 void Ori(Register rt, Register rs, uint16_t imm16);
240 void Xor(Register rd, Register rs, Register rt);
241 void Xori(Register rt, Register rs, uint16_t imm16);
242 void Nor(Register rd, Register rs, Register rt);
243
Chris Larsene3845472015-11-18 12:27:15 -0800244 void Movz(Register rd, Register rs, Register rt); // R2
245 void Movn(Register rd, Register rs, Register rt); // R2
246 void Seleqz(Register rd, Register rs, Register rt); // R6
247 void Selnez(Register rd, Register rs, Register rt); // R6
248 void ClzR6(Register rd, Register rs);
249 void ClzR2(Register rd, Register rs);
250 void CloR6(Register rd, Register rs);
251 void CloR2(Register rd, Register rs);
252
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200253 void Seb(Register rd, Register rt); // R2+
254 void Seh(Register rd, Register rt); // R2+
Chris Larsen3f8bf652015-10-28 10:08:56 -0700255 void Wsbh(Register rd, Register rt); // R2+
Chris Larsen70014c82015-11-18 12:26:08 -0800256 void Bitswap(Register rd, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200257
258 void Sll(Register rd, Register rt, int shamt);
259 void Srl(Register rd, Register rt, int shamt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700260 void Rotr(Register rd, Register rt, int shamt); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200261 void Sra(Register rd, Register rt, int shamt);
262 void Sllv(Register rd, Register rt, Register rs);
263 void Srlv(Register rd, Register rt, Register rs);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800264 void Rotrv(Register rd, Register rt, Register rs); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200265 void Srav(Register rd, Register rt, Register rs);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800266 void Ext(Register rd, Register rt, int pos, int size); // R2+
267 void Ins(Register rd, Register rt, int pos, int size); // R2+
Chris Larsen692235e2016-11-21 16:04:53 -0800268 void Lsa(Register rd, Register rs, Register rt, int saPlusOne); // R6
Chris Larsencd0295d2017-03-31 15:26:54 -0700269 void ShiftAndAdd(Register dst, Register src_idx, Register src_base, int shamt, Register tmp = AT);
jeffhao7fbee072012-08-24 17:56:54 -0700270
271 void Lb(Register rt, Register rs, uint16_t imm16);
272 void Lh(Register rt, Register rs, uint16_t imm16);
273 void Lw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800274 void Lwl(Register rt, Register rs, uint16_t imm16);
275 void Lwr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700276 void Lbu(Register rt, Register rs, uint16_t imm16);
277 void Lhu(Register rt, Register rs, uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700278 void Lwpc(Register rs, uint32_t imm19); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700279 void Lui(Register rt, uint16_t imm16);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700280 void Aui(Register rt, Register rs, uint16_t imm16); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200281 void Sync(uint32_t stype);
282 void Mfhi(Register rd); // R2
283 void Mflo(Register rd); // R2
jeffhao7fbee072012-08-24 17:56:54 -0700284
285 void Sb(Register rt, Register rs, uint16_t imm16);
286 void Sh(Register rt, Register rs, uint16_t imm16);
287 void Sw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800288 void Swl(Register rt, Register rs, uint16_t imm16);
289 void Swr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700290
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700291 void LlR2(Register rt, Register base, int16_t imm16 = 0);
292 void ScR2(Register rt, Register base, int16_t imm16 = 0);
293 void LlR6(Register rt, Register base, int16_t imm9 = 0);
294 void ScR6(Register rt, Register base, int16_t imm9 = 0);
295
jeffhao7fbee072012-08-24 17:56:54 -0700296 void Slt(Register rd, Register rs, Register rt);
297 void Sltu(Register rd, Register rs, Register rt);
298 void Slti(Register rt, Register rs, uint16_t imm16);
299 void Sltiu(Register rt, Register rs, uint16_t imm16);
300
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700301 // Branches and jumps to immediate offsets/addresses do not take care of their
302 // delay/forbidden slots and generally should not be used directly. This applies
303 // to the following R2 and R6 branch/jump instructions with imm16, imm21, addr26
304 // offsets/addresses.
305 // Use branches/jumps to labels instead.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200306 void B(uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700307 void Bal(uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200308 void Beq(Register rs, Register rt, uint16_t imm16);
309 void Bne(Register rs, Register rt, uint16_t imm16);
310 void Beqz(Register rt, uint16_t imm16);
311 void Bnez(Register rt, uint16_t imm16);
312 void Bltz(Register rt, uint16_t imm16);
313 void Bgez(Register rt, uint16_t imm16);
314 void Blez(Register rt, uint16_t imm16);
315 void Bgtz(Register rt, uint16_t imm16);
Chris Larsenb74353a2015-11-20 09:07:09 -0800316 void Bc1f(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800317 void Bc1f(int cc, uint16_t imm16); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800318 void Bc1t(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800319 void Bc1t(int cc, uint16_t imm16); // R2
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200320 void J(uint32_t addr26);
321 void Jal(uint32_t addr26);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700322 // Jalr() and Jr() fill their delay slots when reordering is enabled.
323 // When reordering is disabled, the delay slots must be filled manually.
324 // You may use NopIfNoReordering() to fill them when reordering is disabled.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200325 void Jalr(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700326 void Jalr(Register rs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200327 void Jr(Register rs);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700328 // Nal() does not fill its delay slot. It must be filled manually.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200329 void Nal();
330 void Auipc(Register rs, uint16_t imm16); // R6
331 void Addiupc(Register rs, uint32_t imm19); // R6
332 void Bc(uint32_t imm26); // R6
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700333 void Balc(uint32_t imm26); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200334 void Jic(Register rt, uint16_t imm16); // R6
335 void Jialc(Register rt, uint16_t imm16); // R6
336 void Bltc(Register rs, Register rt, uint16_t imm16); // R6
337 void Bltzc(Register rt, uint16_t imm16); // R6
338 void Bgtzc(Register rt, uint16_t imm16); // R6
339 void Bgec(Register rs, Register rt, uint16_t imm16); // R6
340 void Bgezc(Register rt, uint16_t imm16); // R6
341 void Blezc(Register rt, uint16_t imm16); // R6
342 void Bltuc(Register rs, Register rt, uint16_t imm16); // R6
343 void Bgeuc(Register rs, Register rt, uint16_t imm16); // R6
344 void Beqc(Register rs, Register rt, uint16_t imm16); // R6
345 void Bnec(Register rs, Register rt, uint16_t imm16); // R6
346 void Beqzc(Register rs, uint32_t imm21); // R6
347 void Bnezc(Register rs, uint32_t imm21); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800348 void Bc1eqz(FRegister ft, uint16_t imm16); // R6
349 void Bc1nez(FRegister ft, uint16_t imm16); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700350
351 void AddS(FRegister fd, FRegister fs, FRegister ft);
352 void SubS(FRegister fd, FRegister fs, FRegister ft);
353 void MulS(FRegister fd, FRegister fs, FRegister ft);
354 void DivS(FRegister fd, FRegister fs, FRegister ft);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200355 void AddD(FRegister fd, FRegister fs, FRegister ft);
356 void SubD(FRegister fd, FRegister fs, FRegister ft);
357 void MulD(FRegister fd, FRegister fs, FRegister ft);
358 void DivD(FRegister fd, FRegister fs, FRegister ft);
Chris Larsenb74353a2015-11-20 09:07:09 -0800359 void SqrtS(FRegister fd, FRegister fs);
360 void SqrtD(FRegister fd, FRegister fs);
361 void AbsS(FRegister fd, FRegister fs);
362 void AbsD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700363 void MovS(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200364 void MovD(FRegister fd, FRegister fs);
365 void NegS(FRegister fd, FRegister fs);
366 void NegD(FRegister fd, FRegister fs);
367
Chris Larsenb74353a2015-11-20 09:07:09 -0800368 void CunS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800369 void CunS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800370 void CeqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800371 void CeqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800372 void CueqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800373 void CueqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800374 void ColtS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800375 void ColtS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800376 void CultS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800377 void CultS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800378 void ColeS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800379 void ColeS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800380 void CuleS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800381 void CuleS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800382 void CunD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800383 void CunD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800384 void CeqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800385 void CeqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800386 void CueqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800387 void CueqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800388 void ColtD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800389 void ColtD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800390 void CultD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800391 void CultD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800392 void ColeD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800393 void ColeD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800394 void CuleD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800395 void CuleD(int cc, FRegister fs, FRegister ft); // R2
396 void CmpUnS(FRegister fd, FRegister fs, FRegister ft); // R6
397 void CmpEqS(FRegister fd, FRegister fs, FRegister ft); // R6
398 void CmpUeqS(FRegister fd, FRegister fs, FRegister ft); // R6
399 void CmpLtS(FRegister fd, FRegister fs, FRegister ft); // R6
400 void CmpUltS(FRegister fd, FRegister fs, FRegister ft); // R6
401 void CmpLeS(FRegister fd, FRegister fs, FRegister ft); // R6
402 void CmpUleS(FRegister fd, FRegister fs, FRegister ft); // R6
403 void CmpOrS(FRegister fd, FRegister fs, FRegister ft); // R6
404 void CmpUneS(FRegister fd, FRegister fs, FRegister ft); // R6
405 void CmpNeS(FRegister fd, FRegister fs, FRegister ft); // R6
406 void CmpUnD(FRegister fd, FRegister fs, FRegister ft); // R6
407 void CmpEqD(FRegister fd, FRegister fs, FRegister ft); // R6
408 void CmpUeqD(FRegister fd, FRegister fs, FRegister ft); // R6
409 void CmpLtD(FRegister fd, FRegister fs, FRegister ft); // R6
410 void CmpUltD(FRegister fd, FRegister fs, FRegister ft); // R6
411 void CmpLeD(FRegister fd, FRegister fs, FRegister ft); // R6
412 void CmpUleD(FRegister fd, FRegister fs, FRegister ft); // R6
413 void CmpOrD(FRegister fd, FRegister fs, FRegister ft); // R6
414 void CmpUneD(FRegister fd, FRegister fs, FRegister ft); // R6
415 void CmpNeD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800416 void Movf(Register rd, Register rs, int cc = 0); // R2
417 void Movt(Register rd, Register rs, int cc = 0); // R2
418 void MovfS(FRegister fd, FRegister fs, int cc = 0); // R2
419 void MovfD(FRegister fd, FRegister fs, int cc = 0); // R2
420 void MovtS(FRegister fd, FRegister fs, int cc = 0); // R2
421 void MovtD(FRegister fd, FRegister fs, int cc = 0); // R2
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700422 void MovzS(FRegister fd, FRegister fs, Register rt); // R2
423 void MovzD(FRegister fd, FRegister fs, Register rt); // R2
424 void MovnS(FRegister fd, FRegister fs, Register rt); // R2
425 void MovnD(FRegister fd, FRegister fs, Register rt); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800426 void SelS(FRegister fd, FRegister fs, FRegister ft); // R6
427 void SelD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700428 void SeleqzS(FRegister fd, FRegister fs, FRegister ft); // R6
429 void SeleqzD(FRegister fd, FRegister fs, FRegister ft); // R6
430 void SelnezS(FRegister fd, FRegister fs, FRegister ft); // R6
431 void SelnezD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800432 void ClassS(FRegister fd, FRegister fs); // R6
433 void ClassD(FRegister fd, FRegister fs); // R6
434 void MinS(FRegister fd, FRegister fs, FRegister ft); // R6
435 void MinD(FRegister fd, FRegister fs, FRegister ft); // R6
436 void MaxS(FRegister fd, FRegister fs, FRegister ft); // R6
437 void MaxD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800438
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800439 void TruncLS(FRegister fd, FRegister fs); // R2+, FR=1
440 void TruncLD(FRegister fd, FRegister fs); // R2+, FR=1
441 void TruncWS(FRegister fd, FRegister fs);
442 void TruncWD(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200443 void Cvtsw(FRegister fd, FRegister fs);
444 void Cvtdw(FRegister fd, FRegister fs);
445 void Cvtsd(FRegister fd, FRegister fs);
446 void Cvtds(FRegister fd, FRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800447 void Cvtsl(FRegister fd, FRegister fs); // R2+, FR=1
448 void Cvtdl(FRegister fd, FRegister fs); // R2+, FR=1
Chris Larsenb74353a2015-11-20 09:07:09 -0800449 void FloorWS(FRegister fd, FRegister fs);
450 void FloorWD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700451
452 void Mfc1(Register rt, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200453 void Mtc1(Register rt, FRegister fs);
454 void Mfhc1(Register rt, FRegister fs);
455 void Mthc1(Register rt, FRegister fs);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800456 void MoveFromFpuHigh(Register rt, FRegister fs);
457 void MoveToFpuHigh(Register rt, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700458 void Lwc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200459 void Ldc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700460 void Swc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200461 void Sdc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700462
463 void Break();
jeffhao07030602012-09-26 14:33:14 -0700464 void Nop();
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700465 void NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200466 void Move(Register rd, Register rs);
467 void Clear(Register rd);
468 void Not(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700469
Lena Djokic0758ae72017-05-23 11:06:23 +0200470 // MSA instructions.
471 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
472 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
473 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
474 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
475
476 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
477 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
478 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
479 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
480 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
481 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
482 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
483 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
484 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
485 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
486 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
487 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
488 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
489 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
490 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
491 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
492 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
493 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
494 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
495 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
496 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
497 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
498 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
499 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
500 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
501 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
502 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
503 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
504 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
505 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
506 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
507 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
508 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
509 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
510 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
511 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
512 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
513 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
514 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
515 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
516 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
517 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
518 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
519 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
520 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
521 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
522 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
523 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
524 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
525 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
526 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
527 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
528 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
529 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
530 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
531 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
532 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
533 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
534 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
535 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
536 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
537 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
538 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
539 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
540
541 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
542 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
543 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
544 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
545 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
546 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
547 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
548 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
549 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
550 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
551 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
552 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
553
554 void Ffint_sW(VectorRegister wd, VectorRegister ws);
555 void Ffint_sD(VectorRegister wd, VectorRegister ws);
556 void Ftint_sW(VectorRegister wd, VectorRegister ws);
557 void Ftint_sD(VectorRegister wd, VectorRegister ws);
558
559 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
560 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
561 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
562 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
563 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
564 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
565 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
566 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
567 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
568 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
569 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
570 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
571
572 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
573 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
574 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
575 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
576 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
577 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
578 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
579 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
580 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
581 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
582 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
583 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
584 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
585
586 void MoveV(VectorRegister wd, VectorRegister ws);
587 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
588 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
589 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
590 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
591 void FillB(VectorRegister wd, Register rs);
592 void FillH(VectorRegister wd, Register rs);
593 void FillW(VectorRegister wd, Register rs);
594
595 void LdiB(VectorRegister wd, int imm8);
596 void LdiH(VectorRegister wd, int imm10);
597 void LdiW(VectorRegister wd, int imm10);
598 void LdiD(VectorRegister wd, int imm10);
599 void LdB(VectorRegister wd, Register rs, int offset);
600 void LdH(VectorRegister wd, Register rs, int offset);
601 void LdW(VectorRegister wd, Register rs, int offset);
602 void LdD(VectorRegister wd, Register rs, int offset);
603 void StB(VectorRegister wd, Register rs, int offset);
604 void StH(VectorRegister wd, Register rs, int offset);
605 void StW(VectorRegister wd, Register rs, int offset);
606 void StD(VectorRegister wd, Register rs, int offset);
607
608 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
609 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
610 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
611 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
612
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200613 // Higher level composite instructions.
614 void LoadConst32(Register rd, int32_t value);
615 void LoadConst64(Register reg_hi, Register reg_lo, int64_t value);
616 void LoadDConst64(FRegister rd, int64_t value, Register temp);
617 void LoadSConst32(FRegister r, int32_t value, Register temp);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200618 void Addiu32(Register rt, Register rs, int32_t value, Register rtmp = AT);
619
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700620 // These will generate R2 branches or R6 branches as appropriate and take care of
621 // the delay/forbidden slots.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200622 void Bind(MipsLabel* label);
623 void B(MipsLabel* label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700624 void Bal(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200625 void Beq(Register rs, Register rt, MipsLabel* label);
626 void Bne(Register rs, Register rt, MipsLabel* label);
627 void Beqz(Register rt, MipsLabel* label);
628 void Bnez(Register rt, MipsLabel* label);
629 void Bltz(Register rt, MipsLabel* label);
630 void Bgez(Register rt, MipsLabel* label);
631 void Blez(Register rt, MipsLabel* label);
632 void Bgtz(Register rt, MipsLabel* label);
633 void Blt(Register rs, Register rt, MipsLabel* label);
634 void Bge(Register rs, Register rt, MipsLabel* label);
635 void Bltu(Register rs, Register rt, MipsLabel* label);
636 void Bgeu(Register rs, Register rt, MipsLabel* label);
Chris Larsenb74353a2015-11-20 09:07:09 -0800637 void Bc1f(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800638 void Bc1f(int cc, MipsLabel* label); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800639 void Bc1t(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800640 void Bc1t(int cc, MipsLabel* label); // R2
641 void Bc1eqz(FRegister ft, MipsLabel* label); // R6
642 void Bc1nez(FRegister ft, MipsLabel* label); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700643
644 void EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset, size_t size);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700645 void AdjustBaseAndOffset(Register& base,
646 int32_t& offset,
647 bool is_doubleword,
648 bool is_float = false);
Alexey Frunze2923db72016-08-20 01:55:47 -0700649
650 private:
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100651 // This will be used as an argument for loads/stores
652 // when there is no need for implicit null checks.
Alexey Frunze2923db72016-08-20 01:55:47 -0700653 struct NoImplicitNullChecker {
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100654 void operator()() const {}
Alexey Frunze2923db72016-08-20 01:55:47 -0700655 };
656
657 public:
658 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunzef58b2482016-09-02 22:14:06 -0700659 void StoreConstToOffset(StoreOperandType type,
660 int64_t value,
661 Register base,
662 int32_t offset,
663 Register temp,
664 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
665 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
666 // in which case the `base` register may be overwritten in the process.
Alexey Frunze2923db72016-08-20 01:55:47 -0700667 CHECK_NE(temp, AT); // Must not use AT as temp, so as not to overwrite the adjusted base.
Alexey Frunzef58b2482016-09-02 22:14:06 -0700668 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Alexey Frunze2923db72016-08-20 01:55:47 -0700669 uint32_t low = Low32Bits(value);
670 uint32_t high = High32Bits(value);
Alexey Frunzef58b2482016-09-02 22:14:06 -0700671 Register reg;
672 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
673 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
674 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
675 // original `base` (that is, `base` prior to the adjustment), the original `base`
676 // register will be overwritten.
677 if (base == temp) {
678 temp = AT;
Alexey Frunze2923db72016-08-20 01:55:47 -0700679 }
Alexey Frunzef58b2482016-09-02 22:14:06 -0700680 if (low == 0) {
681 reg = ZERO;
Alexey Frunze2923db72016-08-20 01:55:47 -0700682 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -0700683 reg = temp;
684 LoadConst32(reg, low);
685 }
686 switch (type) {
687 case kStoreByte:
688 Sb(reg, base, offset);
689 break;
690 case kStoreHalfword:
691 Sh(reg, base, offset);
692 break;
693 case kStoreWord:
694 Sw(reg, base, offset);
695 break;
696 case kStoreDoubleword:
697 Sw(reg, base, offset);
698 null_checker();
699 if (high == 0) {
700 reg = ZERO;
701 } else {
702 reg = temp;
703 if (high != low) {
704 LoadConst32(reg, high);
705 }
706 }
707 Sw(reg, base, offset + kMipsWordSize);
708 break;
709 default:
710 LOG(FATAL) << "UNREACHABLE";
711 }
712 if (type != kStoreDoubleword) {
713 null_checker();
Alexey Frunze2923db72016-08-20 01:55:47 -0700714 }
715 }
716
717 template <typename ImplicitNullChecker = NoImplicitNullChecker>
718 void LoadFromOffset(LoadOperandType type,
719 Register reg,
720 Register base,
721 int32_t offset,
722 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
723 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
724 switch (type) {
725 case kLoadSignedByte:
726 Lb(reg, base, offset);
727 break;
728 case kLoadUnsignedByte:
729 Lbu(reg, base, offset);
730 break;
731 case kLoadSignedHalfword:
732 Lh(reg, base, offset);
733 break;
734 case kLoadUnsignedHalfword:
735 Lhu(reg, base, offset);
736 break;
737 case kLoadWord:
738 Lw(reg, base, offset);
739 break;
740 case kLoadDoubleword:
741 if (reg == base) {
742 // This will clobber the base when loading the lower register. Since we have to load the
743 // higher register as well, this will fail. Solution: reverse the order.
744 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
745 null_checker();
746 Lw(reg, base, offset);
747 } else {
748 Lw(reg, base, offset);
749 null_checker();
750 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
751 }
752 break;
753 default:
754 LOG(FATAL) << "UNREACHABLE";
755 }
756 if (type != kLoadDoubleword) {
757 null_checker();
758 }
759 }
760
761 template <typename ImplicitNullChecker = NoImplicitNullChecker>
762 void LoadSFromOffset(FRegister reg,
763 Register base,
764 int32_t offset,
765 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
766 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
767 Lwc1(reg, base, offset);
768 null_checker();
769 }
770
771 template <typename ImplicitNullChecker = NoImplicitNullChecker>
772 void LoadDFromOffset(FRegister reg,
773 Register base,
774 int32_t offset,
775 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
776 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
777 if (IsAligned<kMipsDoublewordSize>(offset)) {
778 Ldc1(reg, base, offset);
779 null_checker();
780 } else {
781 if (Is32BitFPU()) {
782 Lwc1(reg, base, offset);
783 null_checker();
784 Lwc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
785 } else {
786 // 64-bit FPU.
787 Lwc1(reg, base, offset);
788 null_checker();
789 Lw(T8, base, offset + kMipsWordSize);
790 Mthc1(T8, reg);
791 }
792 }
793 }
794
795 template <typename ImplicitNullChecker = NoImplicitNullChecker>
796 void StoreToOffset(StoreOperandType type,
797 Register reg,
798 Register base,
799 int32_t offset,
800 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
801 // Must not use AT as `reg`, so as not to overwrite the value being stored
802 // with the adjusted `base`.
803 CHECK_NE(reg, AT);
804 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
805 switch (type) {
806 case kStoreByte:
807 Sb(reg, base, offset);
808 break;
809 case kStoreHalfword:
810 Sh(reg, base, offset);
811 break;
812 case kStoreWord:
813 Sw(reg, base, offset);
814 break;
815 case kStoreDoubleword:
816 CHECK_NE(reg, base);
817 CHECK_NE(static_cast<Register>(reg + 1), base);
818 Sw(reg, base, offset);
819 null_checker();
820 Sw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
821 break;
822 default:
823 LOG(FATAL) << "UNREACHABLE";
824 }
825 if (type != kStoreDoubleword) {
826 null_checker();
827 }
828 }
829
830 template <typename ImplicitNullChecker = NoImplicitNullChecker>
831 void StoreSToOffset(FRegister reg,
832 Register base,
833 int32_t offset,
834 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
835 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
836 Swc1(reg, base, offset);
837 null_checker();
838 }
839
840 template <typename ImplicitNullChecker = NoImplicitNullChecker>
841 void StoreDToOffset(FRegister reg,
842 Register base,
843 int32_t offset,
844 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
845 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
846 if (IsAligned<kMipsDoublewordSize>(offset)) {
847 Sdc1(reg, base, offset);
848 null_checker();
849 } else {
850 if (Is32BitFPU()) {
851 Swc1(reg, base, offset);
852 null_checker();
853 Swc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
854 } else {
855 // 64-bit FPU.
856 Mfhc1(T8, reg);
857 Swc1(reg, base, offset);
858 null_checker();
859 Sw(T8, base, offset + kMipsWordSize);
860 }
861 }
862 }
863
jeffhao7fbee072012-08-24 17:56:54 -0700864 void LoadFromOffset(LoadOperandType type, Register reg, Register base, int32_t offset);
865 void LoadSFromOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200866 void LoadDFromOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700867 void StoreToOffset(StoreOperandType type, Register reg, Register base, int32_t offset);
Goran Jakovljevicff734982015-08-24 12:58:55 +0000868 void StoreSToOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200869 void StoreDToOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700870
jeffhao7fbee072012-08-24 17:56:54 -0700871 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200872 void Emit(uint32_t value);
873
874 // Push/pop composite routines.
875 void Push(Register rs);
876 void Pop(Register rd);
877 void PopAndReturn(Register rd, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700878
Alexey Frunzec061de12017-02-14 13:27:23 -0800879 //
880 // Heap poisoning.
881 //
882
883 // Poison a heap reference contained in `src` and store it in `dst`.
884 void PoisonHeapReference(Register dst, Register src) {
885 // dst = -src.
886 Subu(dst, ZERO, src);
887 }
888 // Poison a heap reference contained in `reg`.
889 void PoisonHeapReference(Register reg) {
890 // reg = -reg.
891 PoisonHeapReference(reg, reg);
892 }
893 // Unpoison a heap reference contained in `reg`.
894 void UnpoisonHeapReference(Register reg) {
895 // reg = -reg.
896 Subu(reg, ZERO, reg);
897 }
898 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
899 void MaybePoisonHeapReference(Register reg) {
900 if (kPoisonHeapReferences) {
901 PoisonHeapReference(reg);
902 }
903 }
904 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
905 void MaybeUnpoisonHeapReference(Register reg) {
906 if (kPoisonHeapReferences) {
907 UnpoisonHeapReference(reg);
908 }
909 }
910
Andreas Gampe85b62f22015-09-09 13:15:38 -0700911 void Bind(Label* label) OVERRIDE {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200912 Bind(down_cast<MipsLabel*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700913 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200914 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
915 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700916 }
917
Igor Murashkinae7ff922016-10-06 14:59:19 -0700918 // Don't warn about a different virtual Bind/Jump in the base class.
919 using JNIBase::Bind;
920 using JNIBase::Jump;
921
922 // Create a new label that can be used with Jump/Bind calls.
923 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
924 LOG(FATAL) << "Not implemented on MIPS32";
925 UNREACHABLE();
926 }
927 // Emit an unconditional jump to the label.
928 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
929 LOG(FATAL) << "Not implemented on MIPS32";
930 UNREACHABLE();
931 }
932 // Emit a conditional jump to the label by applying a unary condition test to the register.
933 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
934 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
935 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
936 LOG(FATAL) << "Not implemented on MIPS32";
937 UNREACHABLE();
938 }
939
940 // Code at this offset will serve as the target for the Jump call.
941 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
942 LOG(FATAL) << "Not implemented on MIPS32";
943 UNREACHABLE();
944 }
945
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700946 // Create a new literal with a given value.
947 // NOTE: Force the template parameter to be explicitly specified.
948 template <typename T>
949 Literal* NewLiteral(typename Identity<T>::type value) {
950 static_assert(std::is_integral<T>::value, "T must be an integral type.");
951 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
952 }
953
Alexey Frunze96b66822016-09-10 02:32:44 -0700954 // Load label address using the base register (for R2 only) or using PC-relative loads
955 // (for R6 only; base_reg must be ZERO). To be used with data labels in the literal /
956 // jump table area only and not with regular code labels.
957 void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label);
958
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700959 // Create a new literal with the given data.
960 Literal* NewLiteral(size_t size, const uint8_t* data);
961
962 // Load literal using the base register (for R2 only) or using PC-relative loads
963 // (for R6 only; base_reg must be ZERO).
964 void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal);
965
Alexey Frunze96b66822016-09-10 02:32:44 -0700966 // Create a jump table for the given labels that will be emitted when finalizing.
967 // When the table is emitted, offsets will be relative to the location of the table.
968 // The table location is determined by the location of its label (the label precedes
969 // the table data) and should be loaded using LoadLabelAddress().
970 JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels);
971
jeffhao7fbee072012-08-24 17:56:54 -0700972 //
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200973 // Overridden common assembler high-level functionality.
jeffhao7fbee072012-08-24 17:56:54 -0700974 //
975
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200976 // Emit code that will create an activation on the stack.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800977 void BuildFrame(size_t frame_size,
978 ManagedRegister method_reg,
Vladimir Marko32248382016-05-19 10:37:24 +0100979 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700980 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700981
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200982 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +0100983 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700984 OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700985
Ian Rogersdd7624d2014-03-14 17:43:00 -0700986 void IncreaseFrameSize(size_t adjust) OVERRIDE;
987 void DecreaseFrameSize(size_t adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700988
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200989 // Store routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700990 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
991 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
992 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700993
Ian Rogersdd7624d2014-03-14 17:43:00 -0700994 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700995
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700996 void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
997 FrameOffset fr_offs,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800998 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700999
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001000 void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001001
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001002 void StoreSpanning(FrameOffset dest,
1003 ManagedRegister msrc,
1004 FrameOffset in_off,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001005 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001006
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001007 // Load routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001008 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001009
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001010 void LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001011
Mathieu Chartiere401d142015-04-22 13:56:20 -07001012 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001013
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001014 void LoadRef(ManagedRegister mdest,
1015 ManagedRegister base,
1016 MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001017 bool unpoison_reference) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001018
Ian Rogersdd7624d2014-03-14 17:43:00 -07001019 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001020
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001021 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001022
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001023 // Copying routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001024 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001025
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001026 void CopyRawPtrFromThread(FrameOffset fr_offs,
1027 ThreadOffset32 thr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001028 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001029
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001030 void CopyRawPtrToThread(ThreadOffset32 thr_offs,
1031 FrameOffset fr_offs,
1032 ManagedRegister mscratch) OVERRIDE;
1033
Ian Rogersdd7624d2014-03-14 17:43:00 -07001034 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001035
Ian Rogersdd7624d2014-03-14 17:43:00 -07001036 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001037
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001038 void Copy(FrameOffset dest,
1039 ManagedRegister src_base,
1040 Offset src_offset,
1041 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001042 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001043
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001044 void Copy(ManagedRegister dest_base,
1045 Offset dest_offset,
1046 FrameOffset src,
1047 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001048 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001049
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001050 void Copy(FrameOffset dest,
1051 FrameOffset src_base,
1052 Offset src_offset,
1053 ManagedRegister mscratch,
1054 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001055
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001056 void Copy(ManagedRegister dest,
1057 Offset dest_offset,
1058 ManagedRegister src,
1059 Offset src_offset,
1060 ManagedRegister mscratch,
1061 size_t size) OVERRIDE;
1062
1063 void Copy(FrameOffset dest,
1064 Offset dest_offset,
1065 FrameOffset src,
1066 Offset src_offset,
1067 ManagedRegister mscratch,
1068 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001069
Ian Rogersdd7624d2014-03-14 17:43:00 -07001070 void MemoryBarrier(ManagedRegister) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001071
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001072 // Sign extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001073 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001074
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001075 // Zero extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001076 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001077
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001078 // Exploit fast access in managed code to Thread::Current().
Ian Rogersdd7624d2014-03-14 17:43:00 -07001079 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1080 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001081
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001082 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001083 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001084 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001085 // null.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001086 void CreateHandleScopeEntry(ManagedRegister out_reg,
1087 FrameOffset handlescope_offset,
1088 ManagedRegister in_reg,
1089 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001090
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001091 // Set up out_off to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001092 // value is null and null_allowed.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001093 void CreateHandleScopeEntry(FrameOffset out_off,
1094 FrameOffset handlescope_offset,
1095 ManagedRegister mscratch,
1096 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001097
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001098 // src holds a handle scope entry (Object**) load this into dst.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001099 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001100
1101 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1102 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001103 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1104 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001105
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001106 // Call to address held at [base+offset].
Ian Rogersdd7624d2014-03-14 17:43:00 -07001107 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1108 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001109 void CallFromThread(ThreadOffset32 offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001110
jeffhao7fbee072012-08-24 17:56:54 -07001111 // Generate code to check if Thread::Current()->exception_ is non-null
1112 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001113 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001114
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001115 // Emit slow paths queued during assembly and promote short branches to long if needed.
1116 void FinalizeCode() OVERRIDE;
1117
1118 // Emit branches and finalize all instructions.
1119 void FinalizeInstructions(const MemoryRegion& region);
1120
1121 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS,
1122 // must be used instead of MipsLabel::GetPosition()).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001123 uint32_t GetLabelLocation(const MipsLabel* label) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001124
1125 // Get the final position of a label after local fixup based on the old position
1126 // recorded before FinalizeCode().
1127 uint32_t GetAdjustedPosition(uint32_t old_position);
1128
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001129 // R2 doesn't have PC-relative addressing, which we need to access literals. We simulate it by
1130 // reading the PC value into a general-purpose register with the NAL instruction and then loading
1131 // literals through this base register. The code generator calls this method (at most once per
1132 // method being compiled) to bind a label to the location for which the PC value is acquired.
1133 // The assembler then computes literal offsets relative to this label.
1134 void BindPcRelBaseLabel();
1135
Alexey Frunze06a46c42016-07-19 15:00:40 -07001136 // Returns the location of the label bound with BindPcRelBaseLabel().
1137 uint32_t GetPcRelBaseLabelLocation() const;
1138
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001139 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1140 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1141 // to PC.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001142 enum BranchCondition {
1143 kCondLT,
1144 kCondGE,
1145 kCondLE,
1146 kCondGT,
1147 kCondLTZ,
1148 kCondGEZ,
1149 kCondLEZ,
1150 kCondGTZ,
1151 kCondEQ,
1152 kCondNE,
1153 kCondEQZ,
1154 kCondNEZ,
1155 kCondLTU,
1156 kCondGEU,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001157 kCondF, // Floating-point predicate false.
1158 kCondT, // Floating-point predicate true.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001159 kUncond,
1160 };
1161 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1162
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001163 // Enables or disables instruction reordering (IOW, automatic filling of delay slots)
1164 // similarly to ".set reorder" / ".set noreorder" in traditional MIPS assembly.
1165 // Returns the last state, which may be useful for temporary enabling/disabling of
1166 // reordering.
1167 bool SetReorder(bool enable);
1168
jeffhao7fbee072012-08-24 17:56:54 -07001169 private:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001170 // Description of the last instruction in terms of input and output registers.
1171 // Used to make the decision of moving the instruction into a delay slot.
1172 struct DelaySlot {
1173 DelaySlot();
1174 // Encoded instruction that may be used to fill the delay slot or 0
1175 // (0 conveniently represents NOP).
1176 uint32_t instruction_;
1177 // Mask of output GPRs for the instruction.
1178 uint32_t gpr_outs_mask_;
1179 // Mask of input GPRs for the instruction.
1180 uint32_t gpr_ins_mask_;
1181 // Mask of output FPRs for the instruction.
1182 uint32_t fpr_outs_mask_;
1183 // Mask of input FPRs for the instruction.
1184 uint32_t fpr_ins_mask_;
1185 // Mask of output FPU condition code flags for the instruction.
1186 uint32_t cc_outs_mask_;
1187 // Mask of input FPU condition code flags for the instruction.
1188 uint32_t cc_ins_mask_;
1189 // Branches never operate on the LO and HI registers, hence there's
1190 // no mask for LO and HI.
1191 };
1192
1193 // Delay slot finite state machine's (DS FSM's) state. The FSM state is updated
1194 // upon every new instruction and label generated. The FSM detects instructions
1195 // suitable for delay slots and immediately preceded with labels. These are target
1196 // instructions for branches. If an unconditional R2 branch does not get its delay
1197 // slot filled with the immediately preceding instruction, it may instead get the
1198 // slot filled with the target instruction (the branch will need its offset
1199 // incremented past the target instruction). We call this "absorption". The FSM
1200 // records PCs of the target instructions suitable for this optimization.
1201 enum DsFsmState {
1202 kExpectingLabel,
1203 kExpectingInstruction,
1204 kExpectingCommit
1205 };
1206 friend std::ostream& operator<<(std::ostream& os, const DsFsmState& rhs);
1207
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001208 class Branch {
1209 public:
1210 enum Type {
1211 // R2 short branches.
1212 kUncondBranch,
1213 kCondBranch,
1214 kCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001215 // R2 near label.
1216 kLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001217 // R2 near literal.
1218 kLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001219 // R2 long branches.
1220 kLongUncondBranch,
1221 kLongCondBranch,
1222 kLongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001223 // R2 far label.
1224 kFarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001225 // R2 far literal.
1226 kFarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001227 // R6 short branches.
1228 kR6UncondBranch,
1229 kR6CondBranch,
1230 kR6Call,
Alexey Frunze96b66822016-09-10 02:32:44 -07001231 // R6 near label.
1232 kR6Label,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001233 // R6 near literal.
1234 kR6Literal,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001235 // R6 long branches.
1236 kR6LongUncondBranch,
1237 kR6LongCondBranch,
1238 kR6LongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001239 // R6 far label.
1240 kR6FarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001241 // R6 far literal.
1242 kR6FarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001243 };
1244 // Bit sizes of offsets defined as enums to minimize chance of typos.
1245 enum OffsetBits {
1246 kOffset16 = 16,
1247 kOffset18 = 18,
1248 kOffset21 = 21,
1249 kOffset23 = 23,
1250 kOffset28 = 28,
1251 kOffset32 = 32,
1252 };
1253
1254 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1255 static constexpr int32_t kMaxBranchLength = 32;
1256 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001257 // The following two instruction encodings can never legally occur in branch delay
1258 // slots and are used as markers.
1259 //
1260 // kUnfilledDelaySlot means that the branch may use either the preceding or the target
1261 // instruction to fill its delay slot (the latter is only possible with unconditional
1262 // R2 branches and is termed here as "absorption").
1263 static constexpr uint32_t kUnfilledDelaySlot = 0x10000000; // beq zero, zero, 0.
1264 // kUnfillableDelaySlot means that the branch cannot use an instruction (other than NOP)
1265 // to fill its delay slot. This is only used for unconditional R2 branches to prevent
1266 // absorption of the target instruction when reordering is disabled.
1267 static constexpr uint32_t kUnfillableDelaySlot = 0x13FF0000; // beq ra, ra, 0.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001268
1269 struct BranchInfo {
1270 // Branch length as a number of 4-byte-long instructions.
1271 uint32_t length;
1272 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1273 // PC-relative offset (or its most significant 16-bit half, which goes first).
1274 uint32_t instr_offset;
1275 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1276 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1277 // instructions) from the instruction containing the offset.
1278 uint32_t pc_org;
1279 // How large (in bits) a PC-relative offset can be for a given type of branch (kR6CondBranch
1280 // is an exception: use kOffset23 for beqzc/bnezc).
1281 OffsetBits offset_size;
1282 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1283 // count.
1284 int offset_shift;
1285 };
1286 static const BranchInfo branch_info_[/* Type */];
1287
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001288 // Unconditional branch or call.
1289 Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001290 // Conditional branch.
1291 Branch(bool is_r6,
1292 uint32_t location,
1293 uint32_t target,
1294 BranchCondition condition,
1295 Register lhs_reg,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001296 Register rhs_reg);
Alexey Frunze96b66822016-09-10 02:32:44 -07001297 // Label address (in literal area) or literal.
1298 Branch(bool is_r6,
1299 uint32_t location,
1300 Register dest_reg,
1301 Register base_reg,
1302 Type label_or_literal_type);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001303
1304 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1305 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1306 // So, we need a way to identify such branches in order to emit no instructions for them
1307 // or change them to unconditional.
1308 static bool IsNop(BranchCondition condition, Register lhs, Register rhs);
1309 static bool IsUncond(BranchCondition condition, Register lhs, Register rhs);
1310
1311 static BranchCondition OppositeCondition(BranchCondition cond);
1312
1313 Type GetType() const;
1314 BranchCondition GetCondition() const;
1315 Register GetLeftRegister() const;
1316 Register GetRightRegister() const;
1317 uint32_t GetTarget() const;
1318 uint32_t GetLocation() const;
1319 uint32_t GetOldLocation() const;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001320 uint32_t GetPrecedingInstructionLength(Type type) const;
1321 uint32_t GetPrecedingInstructionSize(Type type) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001322 uint32_t GetLength() const;
1323 uint32_t GetOldLength() const;
1324 uint32_t GetSize() const;
1325 uint32_t GetOldSize() const;
1326 uint32_t GetEndLocation() const;
1327 uint32_t GetOldEndLocation() const;
1328 bool IsLong() const;
1329 bool IsResolved() const;
1330
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001331 // Various helpers for branch delay slot management.
1332 bool CanHaveDelayedInstruction(const DelaySlot& delay_slot) const;
1333 void SetDelayedInstruction(uint32_t instruction);
1334 uint32_t GetDelayedInstruction() const;
1335 void DecrementLocations();
1336
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001337 // Returns the bit size of the signed offset that the branch instruction can handle.
1338 OffsetBits GetOffsetSize() const;
1339
1340 // Calculates the distance between two byte locations in the assembler buffer and
1341 // returns the number of bits needed to represent the distance as a signed integer.
1342 //
1343 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1344 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1345 //
1346 // Composite branches (made of several instructions) with longer reach have 32-bit
1347 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001348 // The composite branches cover the range of PC + +/-2GB on MIPS32 CPUs. However,
1349 // the range is not end-to-end on MIPS64 (unless addresses are forced to zero- or
1350 // sign-extend from 32 to 64 bits by the appropriate CPU configuration).
1351 // Consider the following implementation of a long unconditional branch, for
1352 // example:
1353 //
1354 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1355 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1356 //
1357 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1358 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1359 // due to sign extension. This must be compensated for by incrementing offset_31_16
1360 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1361 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1362 // Therefore, the long branch range is something like from PC - 0x80000000 to
1363 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001364 //
1365 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1366 // case with the addiu instruction and a 16 bit offset.
1367 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1368
1369 // Resolve a branch when the target is known.
1370 void Resolve(uint32_t target);
1371
1372 // Relocate a branch by a given delta if needed due to expansion of this or another
1373 // branch at a given location by this delta (just changes location_ and target_).
1374 void Relocate(uint32_t expand_location, uint32_t delta);
1375
1376 // If the branch is short, changes its type to long.
1377 void PromoteToLong();
1378
1379 // If necessary, updates the type by promoting a short branch to a long branch
1380 // based on the branch location and target. Returns the amount (in bytes) by
1381 // which the branch size has increased.
1382 // max_short_distance caps the maximum distance between location_ and target_
1383 // that is allowed for short branches. This is for debugging/testing purposes.
1384 // max_short_distance = 0 forces all short branches to become long.
1385 // Use the implicit default argument when not debugging/testing.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001386 uint32_t PromoteIfNeeded(uint32_t location,
1387 uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001388
1389 // Returns the location of the instruction(s) containing the offset.
1390 uint32_t GetOffsetLocation() const;
1391
1392 // Calculates and returns the offset ready for encoding in the branch instruction(s).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001393 uint32_t GetOffset(uint32_t location) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001394
1395 private:
1396 // Completes branch construction by determining and recording its type.
Alexey Frunze96b66822016-09-10 02:32:44 -07001397 void InitializeType(Type initial_type, bool is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001398 // Helper for the above.
1399 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1400
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001401 uint32_t old_location_; // Offset into assembler buffer in bytes.
1402 uint32_t location_; // Offset into assembler buffer in bytes.
1403 uint32_t target_; // Offset into assembler buffer in bytes.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001404
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001405 uint32_t lhs_reg_; // Left-hand side register in conditional branches or
1406 // FPU condition code. Destination register in literals.
1407 uint32_t rhs_reg_; // Right-hand side register in conditional branches.
1408 // Base register in literals (ZERO on R6).
1409 BranchCondition condition_; // Condition for conditional branches.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001410
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001411 Type type_; // Current type of the branch.
1412 Type old_type_; // Initial type of the branch.
1413
1414 uint32_t delayed_instruction_; // Encoded instruction for the delay slot or
1415 // kUnfilledDelaySlot if none but fillable or
1416 // kUnfillableDelaySlot if none and unfillable
1417 // (the latter is only used for unconditional R2
1418 // branches).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001419 };
1420 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1421 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1422
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001423 uint32_t EmitR(int opcode, Register rs, Register rt, Register rd, int shamt, int funct);
1424 uint32_t EmitI(int opcode, Register rs, Register rt, uint16_t imm);
1425 uint32_t EmitI21(int opcode, Register rs, uint32_t imm21);
1426 uint32_t EmitI26(int opcode, uint32_t imm26);
1427 uint32_t EmitFR(int opcode, int fmt, FRegister ft, FRegister fs, FRegister fd, int funct);
1428 uint32_t EmitFI(int opcode, int fmt, FRegister rt, uint16_t imm);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001429 void EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16);
1430 void EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21);
Lena Djokic0758ae72017-05-23 11:06:23 +02001431 uint32_t EmitMsa3R(int operation,
1432 int df,
1433 VectorRegister wt,
1434 VectorRegister ws,
1435 VectorRegister wd,
1436 int minor_opcode);
1437 uint32_t EmitMsaBIT(int operation,
1438 int df_m,
1439 VectorRegister ws,
1440 VectorRegister wd,
1441 int minor_opcode);
1442 uint32_t EmitMsaELM(int operation,
1443 int df_n,
1444 VectorRegister ws,
1445 VectorRegister wd,
1446 int minor_opcode);
1447 uint32_t EmitMsaMI10(int s10, Register rs, VectorRegister wd, int minor_opcode, int df);
1448 uint32_t EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
1449 uint32_t EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1450 uint32_t EmitMsa2RF(int operation,
1451 int df,
1452 VectorRegister ws,
1453 VectorRegister wd,
1454 int minor_opcode);
jeffhao7fbee072012-08-24 17:56:54 -07001455
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001456 void Buncond(MipsLabel* label);
1457 void Bcond(MipsLabel* label, BranchCondition condition, Register lhs, Register rhs = ZERO);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001458 void Call(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001459 void FinalizeLabeledBranch(MipsLabel* label);
jeffhao7fbee072012-08-24 17:56:54 -07001460
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001461 // Various helpers for branch delay slot management.
1462 void DsFsmInstr(uint32_t instruction,
1463 uint32_t gpr_outs_mask,
1464 uint32_t gpr_ins_mask,
1465 uint32_t fpr_outs_mask,
1466 uint32_t fpr_ins_mask,
1467 uint32_t cc_outs_mask,
1468 uint32_t cc_ins_mask);
1469 void DsFsmInstrNop(uint32_t instruction);
1470 void DsFsmInstrRrr(uint32_t instruction, Register out, Register in1, Register in2);
1471 void DsFsmInstrRrrr(uint32_t instruction, Register in1_out, Register in2, Register in3);
1472 void DsFsmInstrFff(uint32_t instruction, FRegister out, FRegister in1, FRegister in2);
1473 void DsFsmInstrFfff(uint32_t instruction, FRegister in1_out, FRegister in2, FRegister in3);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001474 void DsFsmInstrFffr(uint32_t instruction, FRegister in1_out, FRegister in2, Register in3);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001475 void DsFsmInstrRf(uint32_t instruction, Register out, FRegister in);
1476 void DsFsmInstrFr(uint32_t instruction, FRegister out, Register in);
1477 void DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2);
1478 void DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2);
1479 void DsFsmInstrRrrc(uint32_t instruction, Register in1_out, Register in2, int cc_in);
1480 void DsFsmInstrFffc(uint32_t instruction, FRegister in1_out, FRegister in2, int cc_in);
1481 void DsFsmLabel();
1482 void DsFsmCommitLabel();
1483 void DsFsmDropLabel();
1484 void MoveInstructionToDelaySlot(Branch& branch);
1485 bool CanExchangeWithSlt(Register rs, Register rt) const;
1486 void ExchangeWithSlt(const DelaySlot& forwarded_slot);
1487 void GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt);
1488
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001489 Branch* GetBranch(uint32_t branch_id);
1490 const Branch* GetBranch(uint32_t branch_id) const;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001491 uint32_t GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const;
1492 uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001493
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001494 void EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -07001495 void ReserveJumpTableSpace();
1496 void EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001497 void PromoteBranches();
1498 void EmitBranch(Branch* branch);
1499 void EmitBranches();
Vladimir Marko10ef6942015-10-22 15:25:54 +01001500 void PatchCFI(size_t number_of_delayed_adjust_pcs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001501
1502 // Emits exception block.
1503 void EmitExceptionPoll(MipsExceptionSlowPath* exception);
1504
Lena Djokic0758ae72017-05-23 11:06:23 +02001505 bool HasMsa() const {
1506 return has_msa_;
1507 }
1508
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001509 bool IsR6() const {
1510 if (isa_features_ != nullptr) {
1511 return isa_features_->IsR6();
1512 } else {
1513 return false;
1514 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001515 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001516
1517 bool Is32BitFPU() const {
1518 if (isa_features_ != nullptr) {
1519 return isa_features_->Is32BitFloatingPoint();
1520 } else {
1521 return true;
1522 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001523 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001524
1525 // List of exception blocks to generate at the end of the code cache.
1526 std::vector<MipsExceptionSlowPath> exception_blocks_;
1527
1528 std::vector<Branch> branches_;
1529
1530 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1531 bool overwriting_;
1532 // The current overwrite location.
1533 uint32_t overwrite_location_;
1534
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001535 // Whether instruction reordering (IOW, automatic filling of delay slots) is enabled.
1536 bool reordering_;
1537 // Information about the last instruction that may be used to fill a branch delay slot.
1538 DelaySlot delay_slot_;
1539 // Delay slot FSM state.
1540 DsFsmState ds_fsm_state_;
1541 // PC of the current labeled target instruction.
1542 uint32_t ds_fsm_target_pc_;
1543 // PCs of labeled target instructions.
1544 std::vector<uint32_t> ds_fsm_target_pcs_;
1545
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001546 // Use std::deque<> for literal labels to allow insertions at the end
1547 // without invalidating pointers and references to existing elements.
1548 ArenaDeque<Literal> literals_;
1549
Alexey Frunze96b66822016-09-10 02:32:44 -07001550 // Jump table list.
1551 ArenaDeque<JumpTable> jump_tables_;
1552
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001553 // There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC
1554 // we get PC using the NAL instruction. This label marks the position within the assembler buffer
1555 // that PC (from NAL) points to.
1556 MipsLabel pc_rel_base_label_;
1557
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001558 // Data for GetAdjustedPosition(), see the description there.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001559 uint32_t last_position_adjustment_;
1560 uint32_t last_old_position_;
1561 uint32_t last_branch_id_;
1562
Lena Djokic0758ae72017-05-23 11:06:23 +02001563 const bool has_msa_;
1564
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001565 const MipsInstructionSetFeatures* isa_features_;
Goran Jakovljevicff734982015-08-24 12:58:55 +00001566
jeffhao7fbee072012-08-24 17:56:54 -07001567 DISALLOW_COPY_AND_ASSIGN(MipsAssembler);
1568};
1569
jeffhao7fbee072012-08-24 17:56:54 -07001570} // namespace mips
1571} // namespace art
1572
Ian Rogers166db042013-07-26 12:05:57 -07001573#endif // ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_