blob: e4c99408f467eac44c1ec91eb39b67ff903bbe89 [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"
jeffhao7fbee072012-08-24 17:56:54 -070028#include "constants_mips.h"
29#include "globals.h"
30#include "managed_register_mips.h"
jeffhao7fbee072012-08-24 17:56:54 -070031#include "offsets.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020032#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070033#include "utils/jni_macro_assembler.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020034#include "utils/label.h"
jeffhao7fbee072012-08-24 17:56:54 -070035
36namespace art {
37namespace mips {
jeffhao7fbee072012-08-24 17:56:54 -070038
Lena Djokic0758ae72017-05-23 11:06:23 +020039static constexpr size_t kMipsHalfwordSize = 2;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020040static constexpr size_t kMipsWordSize = 4;
41static constexpr size_t kMipsDoublewordSize = 8;
42
jeffhao7fbee072012-08-24 17:56:54 -070043enum LoadOperandType {
44 kLoadSignedByte,
45 kLoadUnsignedByte,
46 kLoadSignedHalfword,
47 kLoadUnsignedHalfword,
48 kLoadWord,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020049 kLoadDoubleword
jeffhao7fbee072012-08-24 17:56:54 -070050};
51
52enum StoreOperandType {
53 kStoreByte,
54 kStoreHalfword,
55 kStoreWord,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020056 kStoreDoubleword
57};
58
Chris Larsenb74353a2015-11-20 09:07:09 -080059// Used to test the values returned by ClassS/ClassD.
60enum FPClassMaskType {
61 kSignalingNaN = 0x001,
62 kQuietNaN = 0x002,
63 kNegativeInfinity = 0x004,
64 kNegativeNormal = 0x008,
65 kNegativeSubnormal = 0x010,
66 kNegativeZero = 0x020,
67 kPositiveInfinity = 0x040,
68 kPositiveNormal = 0x080,
69 kPositiveSubnormal = 0x100,
70 kPositiveZero = 0x200,
71};
72
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020073class MipsLabel : public Label {
74 public:
75 MipsLabel() : prev_branch_id_plus_one_(0) {}
76
77 MipsLabel(MipsLabel&& src)
78 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
79
80 private:
81 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
82
83 friend class MipsAssembler;
84 DISALLOW_COPY_AND_ASSIGN(MipsLabel);
85};
86
Alexey Frunzee3fb2452016-05-10 16:08:05 -070087// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
88class Literal {
89 public:
90 static constexpr size_t kMaxSize = 8;
91
92 Literal(uint32_t size, const uint8_t* data)
93 : label_(), size_(size) {
94 DCHECK_LE(size, Literal::kMaxSize);
95 memcpy(data_, data, size);
96 }
97
98 template <typename T>
99 T GetValue() const {
100 DCHECK_EQ(size_, sizeof(T));
101 T value;
102 memcpy(&value, data_, sizeof(T));
103 return value;
104 }
105
106 uint32_t GetSize() const {
107 return size_;
108 }
109
110 const uint8_t* GetData() const {
111 return data_;
112 }
113
114 MipsLabel* GetLabel() {
115 return &label_;
116 }
117
118 const MipsLabel* GetLabel() const {
119 return &label_;
120 }
121
122 private:
123 MipsLabel label_;
124 const uint32_t size_;
125 uint8_t data_[kMaxSize];
126
127 DISALLOW_COPY_AND_ASSIGN(Literal);
128};
129
Alexey Frunze96b66822016-09-10 02:32:44 -0700130// Jump table: table of labels emitted after the literals. Similar to literals.
131class JumpTable {
132 public:
133 explicit JumpTable(std::vector<MipsLabel*>&& labels)
134 : label_(), labels_(std::move(labels)) {
135 }
136
137 uint32_t GetSize() const {
138 return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
139 }
140
141 const std::vector<MipsLabel*>& GetData() const {
142 return labels_;
143 }
144
145 MipsLabel* GetLabel() {
146 return &label_;
147 }
148
149 const MipsLabel* GetLabel() const {
150 return &label_;
151 }
152
153 private:
154 MipsLabel label_;
155 std::vector<MipsLabel*> labels_;
156
157 DISALLOW_COPY_AND_ASSIGN(JumpTable);
158};
159
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200160// Slowpath entered when Thread::Current()->_exception is non-null.
161class MipsExceptionSlowPath {
162 public:
163 explicit MipsExceptionSlowPath(MipsManagedRegister scratch, size_t stack_adjust)
164 : scratch_(scratch), stack_adjust_(stack_adjust) {}
165
166 MipsExceptionSlowPath(MipsExceptionSlowPath&& src)
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800167 : scratch_(src.scratch_),
168 stack_adjust_(src.stack_adjust_),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200169 exception_entry_(std::move(src.exception_entry_)) {}
170
171 private:
172 MipsLabel* Entry() { return &exception_entry_; }
173 const MipsManagedRegister scratch_;
174 const size_t stack_adjust_;
175 MipsLabel exception_entry_;
176
177 friend class MipsAssembler;
178 DISALLOW_COPY_AND_ASSIGN(MipsExceptionSlowPath);
jeffhao7fbee072012-08-24 17:56:54 -0700179};
180
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700181class MipsAssembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> {
jeffhao7fbee072012-08-24 17:56:54 -0700182 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700183 using JNIBase = JNIMacroAssembler<PointerSize::k32>;
184
Vladimir Marko93205e32016-04-13 11:59:46 +0100185 explicit MipsAssembler(ArenaAllocator* arena,
186 const MipsInstructionSetFeatures* instruction_set_features = nullptr)
187 : Assembler(arena),
188 overwriting_(false),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200189 overwrite_location_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700190 reordering_(true),
191 ds_fsm_state_(kExpectingLabel),
192 ds_fsm_target_pc_(0),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700193 literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze96b66822016-09-10 02:32:44 -0700194 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200195 last_position_adjustment_(0),
196 last_old_position_(0),
197 last_branch_id_(0),
Lena Djokic0758ae72017-05-23 11:06:23 +0200198 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false),
Vladimir Marko10ef6942015-10-22 15:25:54 +0100199 isa_features_(instruction_set_features) {
200 cfi().DelayEmittingAdvancePCs();
201 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200202
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700203 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700204 size_t CodePosition() OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700205 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
206
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200207 virtual ~MipsAssembler() {
208 for (auto& branch : branches_) {
209 CHECK(branch.IsResolved());
210 }
211 }
jeffhao7fbee072012-08-24 17:56:54 -0700212
213 // Emit Machine Instructions.
jeffhao7fbee072012-08-24 17:56:54 -0700214 void Addu(Register rd, Register rs, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700215 void Addiu(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700216 void Subu(Register rd, Register rs, Register rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200217
218 void MultR2(Register rs, Register rt); // R2
219 void MultuR2(Register rs, Register rt); // R2
220 void DivR2(Register rs, Register rt); // R2
221 void DivuR2(Register rs, Register rt); // R2
222 void MulR2(Register rd, Register rs, Register rt); // R2
223 void DivR2(Register rd, Register rs, Register rt); // R2
224 void ModR2(Register rd, Register rs, Register rt); // R2
225 void DivuR2(Register rd, Register rs, Register rt); // R2
226 void ModuR2(Register rd, Register rs, Register rt); // R2
227 void MulR6(Register rd, Register rs, Register rt); // R6
Alexey Frunze7e99e052015-11-24 19:28:01 -0800228 void MuhR6(Register rd, Register rs, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200229 void MuhuR6(Register rd, Register rs, Register rt); // R6
230 void DivR6(Register rd, Register rs, Register rt); // R6
231 void ModR6(Register rd, Register rs, Register rt); // R6
232 void DivuR6(Register rd, Register rs, Register rt); // R6
233 void ModuR6(Register rd, Register rs, Register rt); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700234
235 void And(Register rd, Register rs, Register rt);
236 void Andi(Register rt, Register rs, uint16_t imm16);
237 void Or(Register rd, Register rs, Register rt);
238 void Ori(Register rt, Register rs, uint16_t imm16);
239 void Xor(Register rd, Register rs, Register rt);
240 void Xori(Register rt, Register rs, uint16_t imm16);
241 void Nor(Register rd, Register rs, Register rt);
242
Chris Larsene3845472015-11-18 12:27:15 -0800243 void Movz(Register rd, Register rs, Register rt); // R2
244 void Movn(Register rd, Register rs, Register rt); // R2
245 void Seleqz(Register rd, Register rs, Register rt); // R6
246 void Selnez(Register rd, Register rs, Register rt); // R6
247 void ClzR6(Register rd, Register rs);
248 void ClzR2(Register rd, Register rs);
249 void CloR6(Register rd, Register rs);
250 void CloR2(Register rd, Register rs);
251
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200252 void Seb(Register rd, Register rt); // R2+
253 void Seh(Register rd, Register rt); // R2+
Chris Larsen3f8bf652015-10-28 10:08:56 -0700254 void Wsbh(Register rd, Register rt); // R2+
Chris Larsen70014c82015-11-18 12:26:08 -0800255 void Bitswap(Register rd, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200256
257 void Sll(Register rd, Register rt, int shamt);
258 void Srl(Register rd, Register rt, int shamt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700259 void Rotr(Register rd, Register rt, int shamt); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200260 void Sra(Register rd, Register rt, int shamt);
261 void Sllv(Register rd, Register rt, Register rs);
262 void Srlv(Register rd, Register rt, Register rs);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800263 void Rotrv(Register rd, Register rt, Register rs); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200264 void Srav(Register rd, Register rt, Register rs);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800265 void Ext(Register rd, Register rt, int pos, int size); // R2+
266 void Ins(Register rd, Register rt, int pos, int size); // R2+
Chris Larsen692235e2016-11-21 16:04:53 -0800267 void Lsa(Register rd, Register rs, Register rt, int saPlusOne); // R6
Chris Larsencd0295d2017-03-31 15:26:54 -0700268 void ShiftAndAdd(Register dst, Register src_idx, Register src_base, int shamt, Register tmp = AT);
jeffhao7fbee072012-08-24 17:56:54 -0700269
270 void Lb(Register rt, Register rs, uint16_t imm16);
271 void Lh(Register rt, Register rs, uint16_t imm16);
272 void Lw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800273 void Lwl(Register rt, Register rs, uint16_t imm16);
274 void Lwr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700275 void Lbu(Register rt, Register rs, uint16_t imm16);
276 void Lhu(Register rt, Register rs, uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700277 void Lwpc(Register rs, uint32_t imm19); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700278 void Lui(Register rt, uint16_t imm16);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700279 void Aui(Register rt, Register rs, uint16_t imm16); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200280 void Sync(uint32_t stype);
281 void Mfhi(Register rd); // R2
282 void Mflo(Register rd); // R2
jeffhao7fbee072012-08-24 17:56:54 -0700283
284 void Sb(Register rt, Register rs, uint16_t imm16);
285 void Sh(Register rt, Register rs, uint16_t imm16);
286 void Sw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800287 void Swl(Register rt, Register rs, uint16_t imm16);
288 void Swr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700289
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700290 void LlR2(Register rt, Register base, int16_t imm16 = 0);
291 void ScR2(Register rt, Register base, int16_t imm16 = 0);
292 void LlR6(Register rt, Register base, int16_t imm9 = 0);
293 void ScR6(Register rt, Register base, int16_t imm9 = 0);
294
jeffhao7fbee072012-08-24 17:56:54 -0700295 void Slt(Register rd, Register rs, Register rt);
296 void Sltu(Register rd, Register rs, Register rt);
297 void Slti(Register rt, Register rs, uint16_t imm16);
298 void Sltiu(Register rt, Register rs, uint16_t imm16);
299
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700300 // Branches and jumps to immediate offsets/addresses do not take care of their
301 // delay/forbidden slots and generally should not be used directly. This applies
302 // to the following R2 and R6 branch/jump instructions with imm16, imm21, addr26
303 // offsets/addresses.
304 // Use branches/jumps to labels instead.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200305 void B(uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700306 void Bal(uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200307 void Beq(Register rs, Register rt, uint16_t imm16);
308 void Bne(Register rs, Register rt, uint16_t imm16);
309 void Beqz(Register rt, uint16_t imm16);
310 void Bnez(Register rt, uint16_t imm16);
311 void Bltz(Register rt, uint16_t imm16);
312 void Bgez(Register rt, uint16_t imm16);
313 void Blez(Register rt, uint16_t imm16);
314 void Bgtz(Register rt, uint16_t imm16);
Chris Larsenb74353a2015-11-20 09:07:09 -0800315 void Bc1f(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800316 void Bc1f(int cc, uint16_t imm16); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800317 void Bc1t(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800318 void Bc1t(int cc, uint16_t imm16); // R2
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200319 void J(uint32_t addr26);
320 void Jal(uint32_t addr26);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700321 // Jalr() and Jr() fill their delay slots when reordering is enabled.
322 // When reordering is disabled, the delay slots must be filled manually.
323 // You may use NopIfNoReordering() to fill them when reordering is disabled.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200324 void Jalr(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700325 void Jalr(Register rs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200326 void Jr(Register rs);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700327 // Nal() does not fill its delay slot. It must be filled manually.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200328 void Nal();
329 void Auipc(Register rs, uint16_t imm16); // R6
330 void Addiupc(Register rs, uint32_t imm19); // R6
331 void Bc(uint32_t imm26); // R6
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700332 void Balc(uint32_t imm26); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200333 void Jic(Register rt, uint16_t imm16); // R6
334 void Jialc(Register rt, uint16_t imm16); // R6
335 void Bltc(Register rs, Register rt, uint16_t imm16); // R6
336 void Bltzc(Register rt, uint16_t imm16); // R6
337 void Bgtzc(Register rt, uint16_t imm16); // R6
338 void Bgec(Register rs, Register rt, uint16_t imm16); // R6
339 void Bgezc(Register rt, uint16_t imm16); // R6
340 void Blezc(Register rt, uint16_t imm16); // R6
341 void Bltuc(Register rs, Register rt, uint16_t imm16); // R6
342 void Bgeuc(Register rs, Register rt, uint16_t imm16); // R6
343 void Beqc(Register rs, Register rt, uint16_t imm16); // R6
344 void Bnec(Register rs, Register rt, uint16_t imm16); // R6
345 void Beqzc(Register rs, uint32_t imm21); // R6
346 void Bnezc(Register rs, uint32_t imm21); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800347 void Bc1eqz(FRegister ft, uint16_t imm16); // R6
348 void Bc1nez(FRegister ft, uint16_t imm16); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700349
350 void AddS(FRegister fd, FRegister fs, FRegister ft);
351 void SubS(FRegister fd, FRegister fs, FRegister ft);
352 void MulS(FRegister fd, FRegister fs, FRegister ft);
353 void DivS(FRegister fd, FRegister fs, FRegister ft);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200354 void AddD(FRegister fd, FRegister fs, FRegister ft);
355 void SubD(FRegister fd, FRegister fs, FRegister ft);
356 void MulD(FRegister fd, FRegister fs, FRegister ft);
357 void DivD(FRegister fd, FRegister fs, FRegister ft);
Chris Larsenb74353a2015-11-20 09:07:09 -0800358 void SqrtS(FRegister fd, FRegister fs);
359 void SqrtD(FRegister fd, FRegister fs);
360 void AbsS(FRegister fd, FRegister fs);
361 void AbsD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700362 void MovS(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200363 void MovD(FRegister fd, FRegister fs);
364 void NegS(FRegister fd, FRegister fs);
365 void NegD(FRegister fd, FRegister fs);
366
Chris Larsenb74353a2015-11-20 09:07:09 -0800367 void CunS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800368 void CunS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800369 void CeqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800370 void CeqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800371 void CueqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800372 void CueqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800373 void ColtS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800374 void ColtS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800375 void CultS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800376 void CultS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800377 void ColeS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800378 void ColeS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800379 void CuleS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800380 void CuleS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800381 void CunD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800382 void CunD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800383 void CeqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800384 void CeqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800385 void CueqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800386 void CueqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800387 void ColtD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800388 void ColtD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800389 void CultD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800390 void CultD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800391 void ColeD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800392 void ColeD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800393 void CuleD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800394 void CuleD(int cc, FRegister fs, FRegister ft); // R2
395 void CmpUnS(FRegister fd, FRegister fs, FRegister ft); // R6
396 void CmpEqS(FRegister fd, FRegister fs, FRegister ft); // R6
397 void CmpUeqS(FRegister fd, FRegister fs, FRegister ft); // R6
398 void CmpLtS(FRegister fd, FRegister fs, FRegister ft); // R6
399 void CmpUltS(FRegister fd, FRegister fs, FRegister ft); // R6
400 void CmpLeS(FRegister fd, FRegister fs, FRegister ft); // R6
401 void CmpUleS(FRegister fd, FRegister fs, FRegister ft); // R6
402 void CmpOrS(FRegister fd, FRegister fs, FRegister ft); // R6
403 void CmpUneS(FRegister fd, FRegister fs, FRegister ft); // R6
404 void CmpNeS(FRegister fd, FRegister fs, FRegister ft); // R6
405 void CmpUnD(FRegister fd, FRegister fs, FRegister ft); // R6
406 void CmpEqD(FRegister fd, FRegister fs, FRegister ft); // R6
407 void CmpUeqD(FRegister fd, FRegister fs, FRegister ft); // R6
408 void CmpLtD(FRegister fd, FRegister fs, FRegister ft); // R6
409 void CmpUltD(FRegister fd, FRegister fs, FRegister ft); // R6
410 void CmpLeD(FRegister fd, FRegister fs, FRegister ft); // R6
411 void CmpUleD(FRegister fd, FRegister fs, FRegister ft); // R6
412 void CmpOrD(FRegister fd, FRegister fs, FRegister ft); // R6
413 void CmpUneD(FRegister fd, FRegister fs, FRegister ft); // R6
414 void CmpNeD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800415 void Movf(Register rd, Register rs, int cc = 0); // R2
416 void Movt(Register rd, Register rs, int cc = 0); // R2
417 void MovfS(FRegister fd, FRegister fs, int cc = 0); // R2
418 void MovfD(FRegister fd, FRegister fs, int cc = 0); // R2
419 void MovtS(FRegister fd, FRegister fs, int cc = 0); // R2
420 void MovtD(FRegister fd, FRegister fs, int cc = 0); // R2
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700421 void MovzS(FRegister fd, FRegister fs, Register rt); // R2
422 void MovzD(FRegister fd, FRegister fs, Register rt); // R2
423 void MovnS(FRegister fd, FRegister fs, Register rt); // R2
424 void MovnD(FRegister fd, FRegister fs, Register rt); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800425 void SelS(FRegister fd, FRegister fs, FRegister ft); // R6
426 void SelD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700427 void SeleqzS(FRegister fd, FRegister fs, FRegister ft); // R6
428 void SeleqzD(FRegister fd, FRegister fs, FRegister ft); // R6
429 void SelnezS(FRegister fd, FRegister fs, FRegister ft); // R6
430 void SelnezD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800431 void ClassS(FRegister fd, FRegister fs); // R6
432 void ClassD(FRegister fd, FRegister fs); // R6
433 void MinS(FRegister fd, FRegister fs, FRegister ft); // R6
434 void MinD(FRegister fd, FRegister fs, FRegister ft); // R6
435 void MaxS(FRegister fd, FRegister fs, FRegister ft); // R6
436 void MaxD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800437
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800438 void TruncLS(FRegister fd, FRegister fs); // R2+, FR=1
439 void TruncLD(FRegister fd, FRegister fs); // R2+, FR=1
440 void TruncWS(FRegister fd, FRegister fs);
441 void TruncWD(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200442 void Cvtsw(FRegister fd, FRegister fs);
443 void Cvtdw(FRegister fd, FRegister fs);
444 void Cvtsd(FRegister fd, FRegister fs);
445 void Cvtds(FRegister fd, FRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800446 void Cvtsl(FRegister fd, FRegister fs); // R2+, FR=1
447 void Cvtdl(FRegister fd, FRegister fs); // R2+, FR=1
Chris Larsenb74353a2015-11-20 09:07:09 -0800448 void FloorWS(FRegister fd, FRegister fs);
449 void FloorWD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700450
451 void Mfc1(Register rt, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200452 void Mtc1(Register rt, FRegister fs);
453 void Mfhc1(Register rt, FRegister fs);
454 void Mthc1(Register rt, FRegister fs);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800455 void MoveFromFpuHigh(Register rt, FRegister fs);
456 void MoveToFpuHigh(Register rt, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700457 void Lwc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200458 void Ldc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700459 void Swc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200460 void Sdc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700461
462 void Break();
jeffhao07030602012-09-26 14:33:14 -0700463 void Nop();
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700464 void NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200465 void Move(Register rd, Register rs);
466 void Clear(Register rd);
467 void Not(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700468
Lena Djokic0758ae72017-05-23 11:06:23 +0200469 // MSA instructions.
470 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
471 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
472 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
473 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
474
475 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
476 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
477 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
478 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
479 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
480 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
481 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
482 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
483 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
484 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
485 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
486 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
487 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
488 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
489 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
490 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
491 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
492 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
493 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
494 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
495 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
496 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
497 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
498 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
499 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
500 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
501 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
502 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
503 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
504 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
505 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
506 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
507 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
508 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
509 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
510 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
511 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
512 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
513 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
514 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
515 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
516 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
517 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
518 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
519 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
520 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
521 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
522 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
523 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
524 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
525 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
526 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
527 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
528 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
529 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
530 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
531 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
532 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
533 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
534 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
535 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
536 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
537 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
538 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
539
540 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
541 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
542 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
543 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
544 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
545 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
546 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
547 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
548 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
549 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
550 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
551 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
552
553 void Ffint_sW(VectorRegister wd, VectorRegister ws);
554 void Ffint_sD(VectorRegister wd, VectorRegister ws);
555 void Ftint_sW(VectorRegister wd, VectorRegister ws);
556 void Ftint_sD(VectorRegister wd, VectorRegister ws);
557
558 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
559 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
560 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
561 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
562 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
563 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
564 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
565 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
566 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
567 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
568 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
569 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
570
571 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
572 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
573 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
574 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
575 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
576 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
577 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
578 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
579 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
580 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
581 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
582 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
583 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
584
585 void MoveV(VectorRegister wd, VectorRegister ws);
586 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
587 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
588 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
589 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
590 void FillB(VectorRegister wd, Register rs);
591 void FillH(VectorRegister wd, Register rs);
592 void FillW(VectorRegister wd, Register rs);
593
594 void LdiB(VectorRegister wd, int imm8);
595 void LdiH(VectorRegister wd, int imm10);
596 void LdiW(VectorRegister wd, int imm10);
597 void LdiD(VectorRegister wd, int imm10);
598 void LdB(VectorRegister wd, Register rs, int offset);
599 void LdH(VectorRegister wd, Register rs, int offset);
600 void LdW(VectorRegister wd, Register rs, int offset);
601 void LdD(VectorRegister wd, Register rs, int offset);
602 void StB(VectorRegister wd, Register rs, int offset);
603 void StH(VectorRegister wd, Register rs, int offset);
604 void StW(VectorRegister wd, Register rs, int offset);
605 void StD(VectorRegister wd, Register rs, int offset);
606
607 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
608 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
609 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
610 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
611
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200612 // Higher level composite instructions.
613 void LoadConst32(Register rd, int32_t value);
614 void LoadConst64(Register reg_hi, Register reg_lo, int64_t value);
615 void LoadDConst64(FRegister rd, int64_t value, Register temp);
616 void LoadSConst32(FRegister r, int32_t value, Register temp);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200617 void Addiu32(Register rt, Register rs, int32_t value, Register rtmp = AT);
618
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700619 // These will generate R2 branches or R6 branches as appropriate and take care of
620 // the delay/forbidden slots.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200621 void Bind(MipsLabel* label);
622 void B(MipsLabel* label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700623 void Bal(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200624 void Beq(Register rs, Register rt, MipsLabel* label);
625 void Bne(Register rs, Register rt, MipsLabel* label);
626 void Beqz(Register rt, MipsLabel* label);
627 void Bnez(Register rt, MipsLabel* label);
628 void Bltz(Register rt, MipsLabel* label);
629 void Bgez(Register rt, MipsLabel* label);
630 void Blez(Register rt, MipsLabel* label);
631 void Bgtz(Register rt, MipsLabel* label);
632 void Blt(Register rs, Register rt, MipsLabel* label);
633 void Bge(Register rs, Register rt, MipsLabel* label);
634 void Bltu(Register rs, Register rt, MipsLabel* label);
635 void Bgeu(Register rs, Register rt, MipsLabel* label);
Chris Larsenb74353a2015-11-20 09:07:09 -0800636 void Bc1f(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800637 void Bc1f(int cc, MipsLabel* label); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800638 void Bc1t(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800639 void Bc1t(int cc, MipsLabel* label); // R2
640 void Bc1eqz(FRegister ft, MipsLabel* label); // R6
641 void Bc1nez(FRegister ft, MipsLabel* label); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700642
643 void EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset, size_t size);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700644 void AdjustBaseAndOffset(Register& base,
645 int32_t& offset,
646 bool is_doubleword,
647 bool is_float = false);
Alexey Frunze2923db72016-08-20 01:55:47 -0700648
649 private:
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100650 // This will be used as an argument for loads/stores
651 // when there is no need for implicit null checks.
Alexey Frunze2923db72016-08-20 01:55:47 -0700652 struct NoImplicitNullChecker {
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100653 void operator()() const {}
Alexey Frunze2923db72016-08-20 01:55:47 -0700654 };
655
656 public:
657 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunzef58b2482016-09-02 22:14:06 -0700658 void StoreConstToOffset(StoreOperandType type,
659 int64_t value,
660 Register base,
661 int32_t offset,
662 Register temp,
663 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
664 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
665 // in which case the `base` register may be overwritten in the process.
Alexey Frunze2923db72016-08-20 01:55:47 -0700666 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 -0700667 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Alexey Frunze2923db72016-08-20 01:55:47 -0700668 uint32_t low = Low32Bits(value);
669 uint32_t high = High32Bits(value);
Alexey Frunzef58b2482016-09-02 22:14:06 -0700670 Register reg;
671 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
672 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
673 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
674 // original `base` (that is, `base` prior to the adjustment), the original `base`
675 // register will be overwritten.
676 if (base == temp) {
677 temp = AT;
Alexey Frunze2923db72016-08-20 01:55:47 -0700678 }
Alexey Frunzef58b2482016-09-02 22:14:06 -0700679 if (low == 0) {
680 reg = ZERO;
Alexey Frunze2923db72016-08-20 01:55:47 -0700681 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -0700682 reg = temp;
683 LoadConst32(reg, low);
684 }
685 switch (type) {
686 case kStoreByte:
687 Sb(reg, base, offset);
688 break;
689 case kStoreHalfword:
690 Sh(reg, base, offset);
691 break;
692 case kStoreWord:
693 Sw(reg, base, offset);
694 break;
695 case kStoreDoubleword:
696 Sw(reg, base, offset);
697 null_checker();
698 if (high == 0) {
699 reg = ZERO;
700 } else {
701 reg = temp;
702 if (high != low) {
703 LoadConst32(reg, high);
704 }
705 }
706 Sw(reg, base, offset + kMipsWordSize);
707 break;
708 default:
709 LOG(FATAL) << "UNREACHABLE";
710 }
711 if (type != kStoreDoubleword) {
712 null_checker();
Alexey Frunze2923db72016-08-20 01:55:47 -0700713 }
714 }
715
716 template <typename ImplicitNullChecker = NoImplicitNullChecker>
717 void LoadFromOffset(LoadOperandType type,
718 Register reg,
719 Register base,
720 int32_t offset,
721 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
722 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
723 switch (type) {
724 case kLoadSignedByte:
725 Lb(reg, base, offset);
726 break;
727 case kLoadUnsignedByte:
728 Lbu(reg, base, offset);
729 break;
730 case kLoadSignedHalfword:
731 Lh(reg, base, offset);
732 break;
733 case kLoadUnsignedHalfword:
734 Lhu(reg, base, offset);
735 break;
736 case kLoadWord:
737 Lw(reg, base, offset);
738 break;
739 case kLoadDoubleword:
740 if (reg == base) {
741 // This will clobber the base when loading the lower register. Since we have to load the
742 // higher register as well, this will fail. Solution: reverse the order.
743 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
744 null_checker();
745 Lw(reg, base, offset);
746 } else {
747 Lw(reg, base, offset);
748 null_checker();
749 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
750 }
751 break;
752 default:
753 LOG(FATAL) << "UNREACHABLE";
754 }
755 if (type != kLoadDoubleword) {
756 null_checker();
757 }
758 }
759
760 template <typename ImplicitNullChecker = NoImplicitNullChecker>
761 void LoadSFromOffset(FRegister reg,
762 Register base,
763 int32_t offset,
764 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
765 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
766 Lwc1(reg, base, offset);
767 null_checker();
768 }
769
770 template <typename ImplicitNullChecker = NoImplicitNullChecker>
771 void LoadDFromOffset(FRegister reg,
772 Register base,
773 int32_t offset,
774 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
775 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
776 if (IsAligned<kMipsDoublewordSize>(offset)) {
777 Ldc1(reg, base, offset);
778 null_checker();
779 } else {
780 if (Is32BitFPU()) {
781 Lwc1(reg, base, offset);
782 null_checker();
783 Lwc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
784 } else {
785 // 64-bit FPU.
786 Lwc1(reg, base, offset);
787 null_checker();
788 Lw(T8, base, offset + kMipsWordSize);
789 Mthc1(T8, reg);
790 }
791 }
792 }
793
794 template <typename ImplicitNullChecker = NoImplicitNullChecker>
795 void StoreToOffset(StoreOperandType type,
796 Register reg,
797 Register base,
798 int32_t offset,
799 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
800 // Must not use AT as `reg`, so as not to overwrite the value being stored
801 // with the adjusted `base`.
802 CHECK_NE(reg, AT);
803 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
804 switch (type) {
805 case kStoreByte:
806 Sb(reg, base, offset);
807 break;
808 case kStoreHalfword:
809 Sh(reg, base, offset);
810 break;
811 case kStoreWord:
812 Sw(reg, base, offset);
813 break;
814 case kStoreDoubleword:
815 CHECK_NE(reg, base);
816 CHECK_NE(static_cast<Register>(reg + 1), base);
817 Sw(reg, base, offset);
818 null_checker();
819 Sw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
820 break;
821 default:
822 LOG(FATAL) << "UNREACHABLE";
823 }
824 if (type != kStoreDoubleword) {
825 null_checker();
826 }
827 }
828
829 template <typename ImplicitNullChecker = NoImplicitNullChecker>
830 void StoreSToOffset(FRegister reg,
831 Register base,
832 int32_t offset,
833 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
834 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
835 Swc1(reg, base, offset);
836 null_checker();
837 }
838
839 template <typename ImplicitNullChecker = NoImplicitNullChecker>
840 void StoreDToOffset(FRegister reg,
841 Register base,
842 int32_t offset,
843 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
844 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
845 if (IsAligned<kMipsDoublewordSize>(offset)) {
846 Sdc1(reg, base, offset);
847 null_checker();
848 } else {
849 if (Is32BitFPU()) {
850 Swc1(reg, base, offset);
851 null_checker();
852 Swc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
853 } else {
854 // 64-bit FPU.
855 Mfhc1(T8, reg);
856 Swc1(reg, base, offset);
857 null_checker();
858 Sw(T8, base, offset + kMipsWordSize);
859 }
860 }
861 }
862
jeffhao7fbee072012-08-24 17:56:54 -0700863 void LoadFromOffset(LoadOperandType type, Register reg, Register base, int32_t offset);
864 void LoadSFromOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200865 void LoadDFromOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700866 void StoreToOffset(StoreOperandType type, Register reg, Register base, int32_t offset);
Goran Jakovljevicff734982015-08-24 12:58:55 +0000867 void StoreSToOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200868 void StoreDToOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700869
jeffhao7fbee072012-08-24 17:56:54 -0700870 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200871 void Emit(uint32_t value);
872
873 // Push/pop composite routines.
874 void Push(Register rs);
875 void Pop(Register rd);
876 void PopAndReturn(Register rd, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700877
Alexey Frunzec061de12017-02-14 13:27:23 -0800878 //
879 // Heap poisoning.
880 //
881
882 // Poison a heap reference contained in `src` and store it in `dst`.
883 void PoisonHeapReference(Register dst, Register src) {
884 // dst = -src.
885 Subu(dst, ZERO, src);
886 }
887 // Poison a heap reference contained in `reg`.
888 void PoisonHeapReference(Register reg) {
889 // reg = -reg.
890 PoisonHeapReference(reg, reg);
891 }
892 // Unpoison a heap reference contained in `reg`.
893 void UnpoisonHeapReference(Register reg) {
894 // reg = -reg.
895 Subu(reg, ZERO, reg);
896 }
897 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
898 void MaybePoisonHeapReference(Register reg) {
899 if (kPoisonHeapReferences) {
900 PoisonHeapReference(reg);
901 }
902 }
903 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
904 void MaybeUnpoisonHeapReference(Register reg) {
905 if (kPoisonHeapReferences) {
906 UnpoisonHeapReference(reg);
907 }
908 }
909
Andreas Gampe85b62f22015-09-09 13:15:38 -0700910 void Bind(Label* label) OVERRIDE {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200911 Bind(down_cast<MipsLabel*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700912 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200913 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
914 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700915 }
916
Igor Murashkinae7ff922016-10-06 14:59:19 -0700917 // Don't warn about a different virtual Bind/Jump in the base class.
918 using JNIBase::Bind;
919 using JNIBase::Jump;
920
921 // Create a new label that can be used with Jump/Bind calls.
922 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
923 LOG(FATAL) << "Not implemented on MIPS32";
924 UNREACHABLE();
925 }
926 // Emit an unconditional jump to the label.
927 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
928 LOG(FATAL) << "Not implemented on MIPS32";
929 UNREACHABLE();
930 }
931 // Emit a conditional jump to the label by applying a unary condition test to the register.
932 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
933 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
934 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
935 LOG(FATAL) << "Not implemented on MIPS32";
936 UNREACHABLE();
937 }
938
939 // Code at this offset will serve as the target for the Jump call.
940 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
941 LOG(FATAL) << "Not implemented on MIPS32";
942 UNREACHABLE();
943 }
944
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700945 // Create a new literal with a given value.
946 // NOTE: Force the template parameter to be explicitly specified.
947 template <typename T>
948 Literal* NewLiteral(typename Identity<T>::type value) {
949 static_assert(std::is_integral<T>::value, "T must be an integral type.");
950 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
951 }
952
Alexey Frunze96b66822016-09-10 02:32:44 -0700953 // Load label address using the base register (for R2 only) or using PC-relative loads
954 // (for R6 only; base_reg must be ZERO). To be used with data labels in the literal /
955 // jump table area only and not with regular code labels.
956 void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label);
957
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700958 // Create a new literal with the given data.
959 Literal* NewLiteral(size_t size, const uint8_t* data);
960
961 // Load literal using the base register (for R2 only) or using PC-relative loads
962 // (for R6 only; base_reg must be ZERO).
963 void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal);
964
Alexey Frunze96b66822016-09-10 02:32:44 -0700965 // Create a jump table for the given labels that will be emitted when finalizing.
966 // When the table is emitted, offsets will be relative to the location of the table.
967 // The table location is determined by the location of its label (the label precedes
968 // the table data) and should be loaded using LoadLabelAddress().
969 JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels);
970
jeffhao7fbee072012-08-24 17:56:54 -0700971 //
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200972 // Overridden common assembler high-level functionality.
jeffhao7fbee072012-08-24 17:56:54 -0700973 //
974
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200975 // Emit code that will create an activation on the stack.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800976 void BuildFrame(size_t frame_size,
977 ManagedRegister method_reg,
Vladimir Marko32248382016-05-19 10:37:24 +0100978 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700979 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700980
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200981 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +0100982 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700983 OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700984
Ian Rogersdd7624d2014-03-14 17:43:00 -0700985 void IncreaseFrameSize(size_t adjust) OVERRIDE;
986 void DecreaseFrameSize(size_t adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700987
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200988 // Store routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700989 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
990 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
991 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700992
Ian Rogersdd7624d2014-03-14 17:43:00 -0700993 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700994
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700995 void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
996 FrameOffset fr_offs,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800997 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -0700998
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700999 void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001000
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001001 void StoreSpanning(FrameOffset dest,
1002 ManagedRegister msrc,
1003 FrameOffset in_off,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001004 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001005
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001006 // Load routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001007 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001008
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001009 void LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001010
Mathieu Chartiere401d142015-04-22 13:56:20 -07001011 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001012
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001013 void LoadRef(ManagedRegister mdest,
1014 ManagedRegister base,
1015 MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001016 bool unpoison_reference) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001017
Ian Rogersdd7624d2014-03-14 17:43:00 -07001018 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001019
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001020 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001021
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001022 // Copying routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001023 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001024
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001025 void CopyRawPtrFromThread(FrameOffset fr_offs,
1026 ThreadOffset32 thr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001027 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001028
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001029 void CopyRawPtrToThread(ThreadOffset32 thr_offs,
1030 FrameOffset fr_offs,
1031 ManagedRegister mscratch) OVERRIDE;
1032
Ian Rogersdd7624d2014-03-14 17:43:00 -07001033 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001034
Ian Rogersdd7624d2014-03-14 17:43:00 -07001035 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001036
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001037 void Copy(FrameOffset dest,
1038 ManagedRegister src_base,
1039 Offset src_offset,
1040 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001041 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001042
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001043 void Copy(ManagedRegister dest_base,
1044 Offset dest_offset,
1045 FrameOffset src,
1046 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001047 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001048
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001049 void Copy(FrameOffset dest,
1050 FrameOffset src_base,
1051 Offset src_offset,
1052 ManagedRegister mscratch,
1053 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001054
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001055 void Copy(ManagedRegister dest,
1056 Offset dest_offset,
1057 ManagedRegister src,
1058 Offset src_offset,
1059 ManagedRegister mscratch,
1060 size_t size) OVERRIDE;
1061
1062 void Copy(FrameOffset dest,
1063 Offset dest_offset,
1064 FrameOffset src,
1065 Offset src_offset,
1066 ManagedRegister mscratch,
1067 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001068
Ian Rogersdd7624d2014-03-14 17:43:00 -07001069 void MemoryBarrier(ManagedRegister) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001070
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001071 // Sign extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001072 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001073
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001074 // Zero extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001075 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001076
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001077 // Exploit fast access in managed code to Thread::Current().
Ian Rogersdd7624d2014-03-14 17:43:00 -07001078 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1079 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001080
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001081 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001082 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001083 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001084 // null.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001085 void CreateHandleScopeEntry(ManagedRegister out_reg,
1086 FrameOffset handlescope_offset,
1087 ManagedRegister in_reg,
1088 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001089
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001090 // Set up out_off to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001091 // value is null and null_allowed.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001092 void CreateHandleScopeEntry(FrameOffset out_off,
1093 FrameOffset handlescope_offset,
1094 ManagedRegister mscratch,
1095 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001096
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001097 // src holds a handle scope entry (Object**) load this into dst.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001098 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001099
1100 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1101 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001102 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1103 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001104
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001105 // Call to address held at [base+offset].
Ian Rogersdd7624d2014-03-14 17:43:00 -07001106 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1107 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001108 void CallFromThread(ThreadOffset32 offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001109
jeffhao7fbee072012-08-24 17:56:54 -07001110 // Generate code to check if Thread::Current()->exception_ is non-null
1111 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001112 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001113
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001114 // Emit slow paths queued during assembly and promote short branches to long if needed.
1115 void FinalizeCode() OVERRIDE;
1116
1117 // Emit branches and finalize all instructions.
1118 void FinalizeInstructions(const MemoryRegion& region);
1119
1120 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS,
1121 // must be used instead of MipsLabel::GetPosition()).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001122 uint32_t GetLabelLocation(const MipsLabel* label) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001123
1124 // Get the final position of a label after local fixup based on the old position
1125 // recorded before FinalizeCode().
1126 uint32_t GetAdjustedPosition(uint32_t old_position);
1127
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001128 // R2 doesn't have PC-relative addressing, which we need to access literals. We simulate it by
1129 // reading the PC value into a general-purpose register with the NAL instruction and then loading
1130 // literals through this base register. The code generator calls this method (at most once per
1131 // method being compiled) to bind a label to the location for which the PC value is acquired.
1132 // The assembler then computes literal offsets relative to this label.
1133 void BindPcRelBaseLabel();
1134
Alexey Frunze06a46c42016-07-19 15:00:40 -07001135 // Returns the location of the label bound with BindPcRelBaseLabel().
1136 uint32_t GetPcRelBaseLabelLocation() const;
1137
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001138 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1139 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1140 // to PC.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001141 enum BranchCondition {
1142 kCondLT,
1143 kCondGE,
1144 kCondLE,
1145 kCondGT,
1146 kCondLTZ,
1147 kCondGEZ,
1148 kCondLEZ,
1149 kCondGTZ,
1150 kCondEQ,
1151 kCondNE,
1152 kCondEQZ,
1153 kCondNEZ,
1154 kCondLTU,
1155 kCondGEU,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001156 kCondF, // Floating-point predicate false.
1157 kCondT, // Floating-point predicate true.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001158 kUncond,
1159 };
1160 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1161
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001162 // Enables or disables instruction reordering (IOW, automatic filling of delay slots)
1163 // similarly to ".set reorder" / ".set noreorder" in traditional MIPS assembly.
1164 // Returns the last state, which may be useful for temporary enabling/disabling of
1165 // reordering.
1166 bool SetReorder(bool enable);
1167
jeffhao7fbee072012-08-24 17:56:54 -07001168 private:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001169 // Description of the last instruction in terms of input and output registers.
1170 // Used to make the decision of moving the instruction into a delay slot.
1171 struct DelaySlot {
1172 DelaySlot();
1173 // Encoded instruction that may be used to fill the delay slot or 0
1174 // (0 conveniently represents NOP).
1175 uint32_t instruction_;
1176 // Mask of output GPRs for the instruction.
1177 uint32_t gpr_outs_mask_;
1178 // Mask of input GPRs for the instruction.
1179 uint32_t gpr_ins_mask_;
1180 // Mask of output FPRs for the instruction.
1181 uint32_t fpr_outs_mask_;
1182 // Mask of input FPRs for the instruction.
1183 uint32_t fpr_ins_mask_;
1184 // Mask of output FPU condition code flags for the instruction.
1185 uint32_t cc_outs_mask_;
1186 // Mask of input FPU condition code flags for the instruction.
1187 uint32_t cc_ins_mask_;
1188 // Branches never operate on the LO and HI registers, hence there's
1189 // no mask for LO and HI.
1190 };
1191
1192 // Delay slot finite state machine's (DS FSM's) state. The FSM state is updated
1193 // upon every new instruction and label generated. The FSM detects instructions
1194 // suitable for delay slots and immediately preceded with labels. These are target
1195 // instructions for branches. If an unconditional R2 branch does not get its delay
1196 // slot filled with the immediately preceding instruction, it may instead get the
1197 // slot filled with the target instruction (the branch will need its offset
1198 // incremented past the target instruction). We call this "absorption". The FSM
1199 // records PCs of the target instructions suitable for this optimization.
1200 enum DsFsmState {
1201 kExpectingLabel,
1202 kExpectingInstruction,
1203 kExpectingCommit
1204 };
1205 friend std::ostream& operator<<(std::ostream& os, const DsFsmState& rhs);
1206
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001207 class Branch {
1208 public:
1209 enum Type {
1210 // R2 short branches.
1211 kUncondBranch,
1212 kCondBranch,
1213 kCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001214 // R2 near label.
1215 kLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001216 // R2 near literal.
1217 kLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001218 // R2 long branches.
1219 kLongUncondBranch,
1220 kLongCondBranch,
1221 kLongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001222 // R2 far label.
1223 kFarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001224 // R2 far literal.
1225 kFarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001226 // R6 short branches.
1227 kR6UncondBranch,
1228 kR6CondBranch,
1229 kR6Call,
Alexey Frunze96b66822016-09-10 02:32:44 -07001230 // R6 near label.
1231 kR6Label,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001232 // R6 near literal.
1233 kR6Literal,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001234 // R6 long branches.
1235 kR6LongUncondBranch,
1236 kR6LongCondBranch,
1237 kR6LongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001238 // R6 far label.
1239 kR6FarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001240 // R6 far literal.
1241 kR6FarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001242 };
1243 // Bit sizes of offsets defined as enums to minimize chance of typos.
1244 enum OffsetBits {
1245 kOffset16 = 16,
1246 kOffset18 = 18,
1247 kOffset21 = 21,
1248 kOffset23 = 23,
1249 kOffset28 = 28,
1250 kOffset32 = 32,
1251 };
1252
1253 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1254 static constexpr int32_t kMaxBranchLength = 32;
1255 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001256 // The following two instruction encodings can never legally occur in branch delay
1257 // slots and are used as markers.
1258 //
1259 // kUnfilledDelaySlot means that the branch may use either the preceding or the target
1260 // instruction to fill its delay slot (the latter is only possible with unconditional
1261 // R2 branches and is termed here as "absorption").
1262 static constexpr uint32_t kUnfilledDelaySlot = 0x10000000; // beq zero, zero, 0.
1263 // kUnfillableDelaySlot means that the branch cannot use an instruction (other than NOP)
1264 // to fill its delay slot. This is only used for unconditional R2 branches to prevent
1265 // absorption of the target instruction when reordering is disabled.
1266 static constexpr uint32_t kUnfillableDelaySlot = 0x13FF0000; // beq ra, ra, 0.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001267
1268 struct BranchInfo {
1269 // Branch length as a number of 4-byte-long instructions.
1270 uint32_t length;
1271 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1272 // PC-relative offset (or its most significant 16-bit half, which goes first).
1273 uint32_t instr_offset;
1274 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1275 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1276 // instructions) from the instruction containing the offset.
1277 uint32_t pc_org;
1278 // How large (in bits) a PC-relative offset can be for a given type of branch (kR6CondBranch
1279 // is an exception: use kOffset23 for beqzc/bnezc).
1280 OffsetBits offset_size;
1281 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1282 // count.
1283 int offset_shift;
1284 };
1285 static const BranchInfo branch_info_[/* Type */];
1286
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001287 // Unconditional branch or call.
1288 Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001289 // Conditional branch.
1290 Branch(bool is_r6,
1291 uint32_t location,
1292 uint32_t target,
1293 BranchCondition condition,
1294 Register lhs_reg,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001295 Register rhs_reg);
Alexey Frunze96b66822016-09-10 02:32:44 -07001296 // Label address (in literal area) or literal.
1297 Branch(bool is_r6,
1298 uint32_t location,
1299 Register dest_reg,
1300 Register base_reg,
1301 Type label_or_literal_type);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001302
1303 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1304 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1305 // So, we need a way to identify such branches in order to emit no instructions for them
1306 // or change them to unconditional.
1307 static bool IsNop(BranchCondition condition, Register lhs, Register rhs);
1308 static bool IsUncond(BranchCondition condition, Register lhs, Register rhs);
1309
1310 static BranchCondition OppositeCondition(BranchCondition cond);
1311
1312 Type GetType() const;
1313 BranchCondition GetCondition() const;
1314 Register GetLeftRegister() const;
1315 Register GetRightRegister() const;
1316 uint32_t GetTarget() const;
1317 uint32_t GetLocation() const;
1318 uint32_t GetOldLocation() const;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001319 uint32_t GetPrecedingInstructionLength(Type type) const;
1320 uint32_t GetPrecedingInstructionSize(Type type) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001321 uint32_t GetLength() const;
1322 uint32_t GetOldLength() const;
1323 uint32_t GetSize() const;
1324 uint32_t GetOldSize() const;
1325 uint32_t GetEndLocation() const;
1326 uint32_t GetOldEndLocation() const;
1327 bool IsLong() const;
1328 bool IsResolved() const;
1329
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001330 // Various helpers for branch delay slot management.
1331 bool CanHaveDelayedInstruction(const DelaySlot& delay_slot) const;
1332 void SetDelayedInstruction(uint32_t instruction);
1333 uint32_t GetDelayedInstruction() const;
1334 void DecrementLocations();
1335
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001336 // Returns the bit size of the signed offset that the branch instruction can handle.
1337 OffsetBits GetOffsetSize() const;
1338
1339 // Calculates the distance between two byte locations in the assembler buffer and
1340 // returns the number of bits needed to represent the distance as a signed integer.
1341 //
1342 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1343 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1344 //
1345 // Composite branches (made of several instructions) with longer reach have 32-bit
1346 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001347 // The composite branches cover the range of PC + +/-2GB on MIPS32 CPUs. However,
1348 // the range is not end-to-end on MIPS64 (unless addresses are forced to zero- or
1349 // sign-extend from 32 to 64 bits by the appropriate CPU configuration).
1350 // Consider the following implementation of a long unconditional branch, for
1351 // example:
1352 //
1353 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1354 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1355 //
1356 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1357 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1358 // due to sign extension. This must be compensated for by incrementing offset_31_16
1359 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1360 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1361 // Therefore, the long branch range is something like from PC - 0x80000000 to
1362 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001363 //
1364 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1365 // case with the addiu instruction and a 16 bit offset.
1366 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1367
1368 // Resolve a branch when the target is known.
1369 void Resolve(uint32_t target);
1370
1371 // Relocate a branch by a given delta if needed due to expansion of this or another
1372 // branch at a given location by this delta (just changes location_ and target_).
1373 void Relocate(uint32_t expand_location, uint32_t delta);
1374
1375 // If the branch is short, changes its type to long.
1376 void PromoteToLong();
1377
1378 // If necessary, updates the type by promoting a short branch to a long branch
1379 // based on the branch location and target. Returns the amount (in bytes) by
1380 // which the branch size has increased.
1381 // max_short_distance caps the maximum distance between location_ and target_
1382 // that is allowed for short branches. This is for debugging/testing purposes.
1383 // max_short_distance = 0 forces all short branches to become long.
1384 // Use the implicit default argument when not debugging/testing.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001385 uint32_t PromoteIfNeeded(uint32_t location,
1386 uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001387
1388 // Returns the location of the instruction(s) containing the offset.
1389 uint32_t GetOffsetLocation() const;
1390
1391 // Calculates and returns the offset ready for encoding in the branch instruction(s).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001392 uint32_t GetOffset(uint32_t location) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001393
1394 private:
1395 // Completes branch construction by determining and recording its type.
Alexey Frunze96b66822016-09-10 02:32:44 -07001396 void InitializeType(Type initial_type, bool is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001397 // Helper for the above.
1398 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1399
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001400 uint32_t old_location_; // Offset into assembler buffer in bytes.
1401 uint32_t location_; // Offset into assembler buffer in bytes.
1402 uint32_t target_; // Offset into assembler buffer in bytes.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001403
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001404 uint32_t lhs_reg_; // Left-hand side register in conditional branches or
1405 // FPU condition code. Destination register in literals.
1406 uint32_t rhs_reg_; // Right-hand side register in conditional branches.
1407 // Base register in literals (ZERO on R6).
1408 BranchCondition condition_; // Condition for conditional branches.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001409
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001410 Type type_; // Current type of the branch.
1411 Type old_type_; // Initial type of the branch.
1412
1413 uint32_t delayed_instruction_; // Encoded instruction for the delay slot or
1414 // kUnfilledDelaySlot if none but fillable or
1415 // kUnfillableDelaySlot if none and unfillable
1416 // (the latter is only used for unconditional R2
1417 // branches).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001418 };
1419 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1420 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1421
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001422 uint32_t EmitR(int opcode, Register rs, Register rt, Register rd, int shamt, int funct);
1423 uint32_t EmitI(int opcode, Register rs, Register rt, uint16_t imm);
1424 uint32_t EmitI21(int opcode, Register rs, uint32_t imm21);
1425 uint32_t EmitI26(int opcode, uint32_t imm26);
1426 uint32_t EmitFR(int opcode, int fmt, FRegister ft, FRegister fs, FRegister fd, int funct);
1427 uint32_t EmitFI(int opcode, int fmt, FRegister rt, uint16_t imm);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001428 void EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16);
1429 void EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21);
Lena Djokic0758ae72017-05-23 11:06:23 +02001430 uint32_t EmitMsa3R(int operation,
1431 int df,
1432 VectorRegister wt,
1433 VectorRegister ws,
1434 VectorRegister wd,
1435 int minor_opcode);
1436 uint32_t EmitMsaBIT(int operation,
1437 int df_m,
1438 VectorRegister ws,
1439 VectorRegister wd,
1440 int minor_opcode);
1441 uint32_t EmitMsaELM(int operation,
1442 int df_n,
1443 VectorRegister ws,
1444 VectorRegister wd,
1445 int minor_opcode);
1446 uint32_t EmitMsaMI10(int s10, Register rs, VectorRegister wd, int minor_opcode, int df);
1447 uint32_t EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
1448 uint32_t EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1449 uint32_t EmitMsa2RF(int operation,
1450 int df,
1451 VectorRegister ws,
1452 VectorRegister wd,
1453 int minor_opcode);
jeffhao7fbee072012-08-24 17:56:54 -07001454
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001455 void Buncond(MipsLabel* label);
1456 void Bcond(MipsLabel* label, BranchCondition condition, Register lhs, Register rhs = ZERO);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001457 void Call(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001458 void FinalizeLabeledBranch(MipsLabel* label);
jeffhao7fbee072012-08-24 17:56:54 -07001459
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001460 // Various helpers for branch delay slot management.
1461 void DsFsmInstr(uint32_t instruction,
1462 uint32_t gpr_outs_mask,
1463 uint32_t gpr_ins_mask,
1464 uint32_t fpr_outs_mask,
1465 uint32_t fpr_ins_mask,
1466 uint32_t cc_outs_mask,
1467 uint32_t cc_ins_mask);
1468 void DsFsmInstrNop(uint32_t instruction);
1469 void DsFsmInstrRrr(uint32_t instruction, Register out, Register in1, Register in2);
1470 void DsFsmInstrRrrr(uint32_t instruction, Register in1_out, Register in2, Register in3);
1471 void DsFsmInstrFff(uint32_t instruction, FRegister out, FRegister in1, FRegister in2);
1472 void DsFsmInstrFfff(uint32_t instruction, FRegister in1_out, FRegister in2, FRegister in3);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001473 void DsFsmInstrFffr(uint32_t instruction, FRegister in1_out, FRegister in2, Register in3);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001474 void DsFsmInstrRf(uint32_t instruction, Register out, FRegister in);
1475 void DsFsmInstrFr(uint32_t instruction, FRegister out, Register in);
1476 void DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2);
1477 void DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2);
1478 void DsFsmInstrRrrc(uint32_t instruction, Register in1_out, Register in2, int cc_in);
1479 void DsFsmInstrFffc(uint32_t instruction, FRegister in1_out, FRegister in2, int cc_in);
1480 void DsFsmLabel();
1481 void DsFsmCommitLabel();
1482 void DsFsmDropLabel();
1483 void MoveInstructionToDelaySlot(Branch& branch);
1484 bool CanExchangeWithSlt(Register rs, Register rt) const;
1485 void ExchangeWithSlt(const DelaySlot& forwarded_slot);
1486 void GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt);
1487
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001488 Branch* GetBranch(uint32_t branch_id);
1489 const Branch* GetBranch(uint32_t branch_id) const;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001490 uint32_t GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const;
1491 uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001492
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001493 void EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -07001494 void ReserveJumpTableSpace();
1495 void EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001496 void PromoteBranches();
1497 void EmitBranch(Branch* branch);
1498 void EmitBranches();
Vladimir Marko10ef6942015-10-22 15:25:54 +01001499 void PatchCFI(size_t number_of_delayed_adjust_pcs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001500
1501 // Emits exception block.
1502 void EmitExceptionPoll(MipsExceptionSlowPath* exception);
1503
Lena Djokic0758ae72017-05-23 11:06:23 +02001504 bool HasMsa() const {
1505 return has_msa_;
1506 }
1507
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001508 bool IsR6() const {
1509 if (isa_features_ != nullptr) {
1510 return isa_features_->IsR6();
1511 } else {
1512 return false;
1513 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001514 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001515
1516 bool Is32BitFPU() const {
1517 if (isa_features_ != nullptr) {
1518 return isa_features_->Is32BitFloatingPoint();
1519 } else {
1520 return true;
1521 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001522 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001523
1524 // List of exception blocks to generate at the end of the code cache.
1525 std::vector<MipsExceptionSlowPath> exception_blocks_;
1526
1527 std::vector<Branch> branches_;
1528
1529 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1530 bool overwriting_;
1531 // The current overwrite location.
1532 uint32_t overwrite_location_;
1533
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001534 // Whether instruction reordering (IOW, automatic filling of delay slots) is enabled.
1535 bool reordering_;
1536 // Information about the last instruction that may be used to fill a branch delay slot.
1537 DelaySlot delay_slot_;
1538 // Delay slot FSM state.
1539 DsFsmState ds_fsm_state_;
1540 // PC of the current labeled target instruction.
1541 uint32_t ds_fsm_target_pc_;
1542 // PCs of labeled target instructions.
1543 std::vector<uint32_t> ds_fsm_target_pcs_;
1544
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001545 // Use std::deque<> for literal labels to allow insertions at the end
1546 // without invalidating pointers and references to existing elements.
1547 ArenaDeque<Literal> literals_;
1548
Alexey Frunze96b66822016-09-10 02:32:44 -07001549 // Jump table list.
1550 ArenaDeque<JumpTable> jump_tables_;
1551
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001552 // There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC
1553 // we get PC using the NAL instruction. This label marks the position within the assembler buffer
1554 // that PC (from NAL) points to.
1555 MipsLabel pc_rel_base_label_;
1556
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001557 // Data for GetAdjustedPosition(), see the description there.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001558 uint32_t last_position_adjustment_;
1559 uint32_t last_old_position_;
1560 uint32_t last_branch_id_;
1561
Lena Djokic0758ae72017-05-23 11:06:23 +02001562 const bool has_msa_;
1563
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001564 const MipsInstructionSetFeatures* isa_features_;
Goran Jakovljevicff734982015-08-24 12:58:55 +00001565
jeffhao7fbee072012-08-24 17:56:54 -07001566 DISALLOW_COPY_AND_ASSIGN(MipsAssembler);
1567};
1568
jeffhao7fbee072012-08-24 17:56:54 -07001569} // namespace mips
1570} // namespace art
1571
Ian Rogers166db042013-07-26 12:05:57 -07001572#endif // ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_