blob: a7ff931e7e88ded56263f50c7e1bea0553825859 [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,
Lena Djokic2e0a7e52017-07-06 11:55:24 +020050 kLoadDoubleword,
51 kLoadQuadword
jeffhao7fbee072012-08-24 17:56:54 -070052};
53
54enum StoreOperandType {
55 kStoreByte,
56 kStoreHalfword,
57 kStoreWord,
Lena Djokic2e0a7e52017-07-06 11:55:24 +020058 kStoreDoubleword,
59 kStoreQuadword
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020060};
61
Chris Larsenb74353a2015-11-20 09:07:09 -080062// Used to test the values returned by ClassS/ClassD.
63enum FPClassMaskType {
64 kSignalingNaN = 0x001,
65 kQuietNaN = 0x002,
66 kNegativeInfinity = 0x004,
67 kNegativeNormal = 0x008,
68 kNegativeSubnormal = 0x010,
69 kNegativeZero = 0x020,
70 kPositiveInfinity = 0x040,
71 kPositiveNormal = 0x080,
72 kPositiveSubnormal = 0x100,
73 kPositiveZero = 0x200,
74};
75
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020076class MipsLabel : public Label {
77 public:
78 MipsLabel() : prev_branch_id_plus_one_(0) {}
79
80 MipsLabel(MipsLabel&& src)
81 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
82
83 private:
84 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
85
86 friend class MipsAssembler;
87 DISALLOW_COPY_AND_ASSIGN(MipsLabel);
88};
89
Alexey Frunzee3fb2452016-05-10 16:08:05 -070090// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
91class Literal {
92 public:
93 static constexpr size_t kMaxSize = 8;
94
95 Literal(uint32_t size, const uint8_t* data)
96 : label_(), size_(size) {
97 DCHECK_LE(size, Literal::kMaxSize);
98 memcpy(data_, data, size);
99 }
100
101 template <typename T>
102 T GetValue() const {
103 DCHECK_EQ(size_, sizeof(T));
104 T value;
105 memcpy(&value, data_, sizeof(T));
106 return value;
107 }
108
109 uint32_t GetSize() const {
110 return size_;
111 }
112
113 const uint8_t* GetData() const {
114 return data_;
115 }
116
117 MipsLabel* GetLabel() {
118 return &label_;
119 }
120
121 const MipsLabel* GetLabel() const {
122 return &label_;
123 }
124
125 private:
126 MipsLabel label_;
127 const uint32_t size_;
128 uint8_t data_[kMaxSize];
129
130 DISALLOW_COPY_AND_ASSIGN(Literal);
131};
132
Alexey Frunze96b66822016-09-10 02:32:44 -0700133// Jump table: table of labels emitted after the literals. Similar to literals.
134class JumpTable {
135 public:
136 explicit JumpTable(std::vector<MipsLabel*>&& labels)
137 : label_(), labels_(std::move(labels)) {
138 }
139
140 uint32_t GetSize() const {
141 return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
142 }
143
144 const std::vector<MipsLabel*>& GetData() const {
145 return labels_;
146 }
147
148 MipsLabel* GetLabel() {
149 return &label_;
150 }
151
152 const MipsLabel* GetLabel() const {
153 return &label_;
154 }
155
156 private:
157 MipsLabel label_;
158 std::vector<MipsLabel*> labels_;
159
160 DISALLOW_COPY_AND_ASSIGN(JumpTable);
161};
162
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200163// Slowpath entered when Thread::Current()->_exception is non-null.
164class MipsExceptionSlowPath {
165 public:
166 explicit MipsExceptionSlowPath(MipsManagedRegister scratch, size_t stack_adjust)
167 : scratch_(scratch), stack_adjust_(stack_adjust) {}
168
169 MipsExceptionSlowPath(MipsExceptionSlowPath&& src)
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800170 : scratch_(src.scratch_),
171 stack_adjust_(src.stack_adjust_),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200172 exception_entry_(std::move(src.exception_entry_)) {}
173
174 private:
175 MipsLabel* Entry() { return &exception_entry_; }
176 const MipsManagedRegister scratch_;
177 const size_t stack_adjust_;
178 MipsLabel exception_entry_;
179
180 friend class MipsAssembler;
181 DISALLOW_COPY_AND_ASSIGN(MipsExceptionSlowPath);
jeffhao7fbee072012-08-24 17:56:54 -0700182};
183
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700184class MipsAssembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> {
jeffhao7fbee072012-08-24 17:56:54 -0700185 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700186 using JNIBase = JNIMacroAssembler<PointerSize::k32>;
187
Vladimir Marko93205e32016-04-13 11:59:46 +0100188 explicit MipsAssembler(ArenaAllocator* arena,
189 const MipsInstructionSetFeatures* instruction_set_features = nullptr)
190 : Assembler(arena),
191 overwriting_(false),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200192 overwrite_location_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700193 reordering_(true),
194 ds_fsm_state_(kExpectingLabel),
195 ds_fsm_target_pc_(0),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700196 literals_(arena->Adapter(kArenaAllocAssembler)),
Alexey Frunze96b66822016-09-10 02:32:44 -0700197 jump_tables_(arena->Adapter(kArenaAllocAssembler)),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200198 last_position_adjustment_(0),
199 last_old_position_(0),
200 last_branch_id_(0),
Lena Djokic0758ae72017-05-23 11:06:23 +0200201 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false),
Vladimir Marko10ef6942015-10-22 15:25:54 +0100202 isa_features_(instruction_set_features) {
203 cfi().DelayEmittingAdvancePCs();
204 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200205
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700206 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700207 size_t CodePosition() OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700208 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
209
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200210 virtual ~MipsAssembler() {
211 for (auto& branch : branches_) {
212 CHECK(branch.IsResolved());
213 }
214 }
jeffhao7fbee072012-08-24 17:56:54 -0700215
216 // Emit Machine Instructions.
jeffhao7fbee072012-08-24 17:56:54 -0700217 void Addu(Register rd, Register rs, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700218 void Addiu(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700219 void Subu(Register rd, Register rs, Register rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200220
221 void MultR2(Register rs, Register rt); // R2
222 void MultuR2(Register rs, Register rt); // R2
223 void DivR2(Register rs, Register rt); // R2
224 void DivuR2(Register rs, Register rt); // R2
225 void MulR2(Register rd, Register rs, Register rt); // R2
226 void DivR2(Register rd, Register rs, Register rt); // R2
227 void ModR2(Register rd, Register rs, Register rt); // R2
228 void DivuR2(Register rd, Register rs, Register rt); // R2
229 void ModuR2(Register rd, Register rs, Register rt); // R2
230 void MulR6(Register rd, Register rs, Register rt); // R6
Alexey Frunze7e99e052015-11-24 19:28:01 -0800231 void MuhR6(Register rd, Register rs, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200232 void MuhuR6(Register rd, Register rs, Register rt); // R6
233 void DivR6(Register rd, Register rs, Register rt); // R6
234 void ModR6(Register rd, Register rs, Register rt); // R6
235 void DivuR6(Register rd, Register rs, Register rt); // R6
236 void ModuR6(Register rd, Register rs, Register rt); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700237
238 void And(Register rd, Register rs, Register rt);
239 void Andi(Register rt, Register rs, uint16_t imm16);
240 void Or(Register rd, Register rs, Register rt);
241 void Ori(Register rt, Register rs, uint16_t imm16);
242 void Xor(Register rd, Register rs, Register rt);
243 void Xori(Register rt, Register rs, uint16_t imm16);
244 void Nor(Register rd, Register rs, Register rt);
245
Chris Larsene3845472015-11-18 12:27:15 -0800246 void Movz(Register rd, Register rs, Register rt); // R2
247 void Movn(Register rd, Register rs, Register rt); // R2
248 void Seleqz(Register rd, Register rs, Register rt); // R6
249 void Selnez(Register rd, Register rs, Register rt); // R6
250 void ClzR6(Register rd, Register rs);
251 void ClzR2(Register rd, Register rs);
252 void CloR6(Register rd, Register rs);
253 void CloR2(Register rd, Register rs);
254
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200255 void Seb(Register rd, Register rt); // R2+
256 void Seh(Register rd, Register rt); // R2+
Chris Larsen3f8bf652015-10-28 10:08:56 -0700257 void Wsbh(Register rd, Register rt); // R2+
Chris Larsen70014c82015-11-18 12:26:08 -0800258 void Bitswap(Register rd, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200259
260 void Sll(Register rd, Register rt, int shamt);
261 void Srl(Register rd, Register rt, int shamt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700262 void Rotr(Register rd, Register rt, int shamt); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200263 void Sra(Register rd, Register rt, int shamt);
264 void Sllv(Register rd, Register rt, Register rs);
265 void Srlv(Register rd, Register rt, Register rs);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800266 void Rotrv(Register rd, Register rt, Register rs); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200267 void Srav(Register rd, Register rt, Register rs);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800268 void Ext(Register rd, Register rt, int pos, int size); // R2+
269 void Ins(Register rd, Register rt, int pos, int size); // R2+
Chris Larsen692235e2016-11-21 16:04:53 -0800270 void Lsa(Register rd, Register rs, Register rt, int saPlusOne); // R6
Chris Larsencd0295d2017-03-31 15:26:54 -0700271 void ShiftAndAdd(Register dst, Register src_idx, Register src_base, int shamt, Register tmp = AT);
jeffhao7fbee072012-08-24 17:56:54 -0700272
273 void Lb(Register rt, Register rs, uint16_t imm16);
274 void Lh(Register rt, Register rs, uint16_t imm16);
275 void Lw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800276 void Lwl(Register rt, Register rs, uint16_t imm16);
277 void Lwr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700278 void Lbu(Register rt, Register rs, uint16_t imm16);
279 void Lhu(Register rt, Register rs, uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700280 void Lwpc(Register rs, uint32_t imm19); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700281 void Lui(Register rt, uint16_t imm16);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700282 void Aui(Register rt, Register rs, uint16_t imm16); // R6
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700283 void AddUpper(Register rt, Register rs, uint16_t imm16, Register tmp = AT);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200284 void Sync(uint32_t stype);
285 void Mfhi(Register rd); // R2
286 void Mflo(Register rd); // R2
jeffhao7fbee072012-08-24 17:56:54 -0700287
288 void Sb(Register rt, Register rs, uint16_t imm16);
289 void Sh(Register rt, Register rs, uint16_t imm16);
290 void Sw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800291 void Swl(Register rt, Register rs, uint16_t imm16);
292 void Swr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700293
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700294 void LlR2(Register rt, Register base, int16_t imm16 = 0);
295 void ScR2(Register rt, Register base, int16_t imm16 = 0);
296 void LlR6(Register rt, Register base, int16_t imm9 = 0);
297 void ScR6(Register rt, Register base, int16_t imm9 = 0);
298
jeffhao7fbee072012-08-24 17:56:54 -0700299 void Slt(Register rd, Register rs, Register rt);
300 void Sltu(Register rd, Register rs, Register rt);
301 void Slti(Register rt, Register rs, uint16_t imm16);
302 void Sltiu(Register rt, Register rs, uint16_t imm16);
303
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700304 // Branches and jumps to immediate offsets/addresses do not take care of their
305 // delay/forbidden slots and generally should not be used directly. This applies
306 // to the following R2 and R6 branch/jump instructions with imm16, imm21, addr26
307 // offsets/addresses.
308 // Use branches/jumps to labels instead.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200309 void B(uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700310 void Bal(uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200311 void Beq(Register rs, Register rt, uint16_t imm16);
312 void Bne(Register rs, Register rt, uint16_t imm16);
313 void Beqz(Register rt, uint16_t imm16);
314 void Bnez(Register rt, uint16_t imm16);
315 void Bltz(Register rt, uint16_t imm16);
316 void Bgez(Register rt, uint16_t imm16);
317 void Blez(Register rt, uint16_t imm16);
318 void Bgtz(Register rt, uint16_t imm16);
Chris Larsenb74353a2015-11-20 09:07:09 -0800319 void Bc1f(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800320 void Bc1f(int cc, uint16_t imm16); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800321 void Bc1t(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800322 void Bc1t(int cc, uint16_t imm16); // R2
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200323 void J(uint32_t addr26);
324 void Jal(uint32_t addr26);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700325 // Jalr() and Jr() fill their delay slots when reordering is enabled.
326 // When reordering is disabled, the delay slots must be filled manually.
327 // You may use NopIfNoReordering() to fill them when reordering is disabled.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200328 void Jalr(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700329 void Jalr(Register rs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200330 void Jr(Register rs);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700331 // Nal() does not fill its delay slot. It must be filled manually.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200332 void Nal();
333 void Auipc(Register rs, uint16_t imm16); // R6
334 void Addiupc(Register rs, uint32_t imm19); // R6
335 void Bc(uint32_t imm26); // R6
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700336 void Balc(uint32_t imm26); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200337 void Jic(Register rt, uint16_t imm16); // R6
338 void Jialc(Register rt, uint16_t imm16); // R6
339 void Bltc(Register rs, Register rt, uint16_t imm16); // R6
340 void Bltzc(Register rt, uint16_t imm16); // R6
341 void Bgtzc(Register rt, uint16_t imm16); // R6
342 void Bgec(Register rs, Register rt, uint16_t imm16); // R6
343 void Bgezc(Register rt, uint16_t imm16); // R6
344 void Blezc(Register rt, uint16_t imm16); // R6
345 void Bltuc(Register rs, Register rt, uint16_t imm16); // R6
346 void Bgeuc(Register rs, Register rt, uint16_t imm16); // R6
347 void Beqc(Register rs, Register rt, uint16_t imm16); // R6
348 void Bnec(Register rs, Register rt, uint16_t imm16); // R6
349 void Beqzc(Register rs, uint32_t imm21); // R6
350 void Bnezc(Register rs, uint32_t imm21); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800351 void Bc1eqz(FRegister ft, uint16_t imm16); // R6
352 void Bc1nez(FRegister ft, uint16_t imm16); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700353
354 void AddS(FRegister fd, FRegister fs, FRegister ft);
355 void SubS(FRegister fd, FRegister fs, FRegister ft);
356 void MulS(FRegister fd, FRegister fs, FRegister ft);
357 void DivS(FRegister fd, FRegister fs, FRegister ft);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200358 void AddD(FRegister fd, FRegister fs, FRegister ft);
359 void SubD(FRegister fd, FRegister fs, FRegister ft);
360 void MulD(FRegister fd, FRegister fs, FRegister ft);
361 void DivD(FRegister fd, FRegister fs, FRegister ft);
Chris Larsenb74353a2015-11-20 09:07:09 -0800362 void SqrtS(FRegister fd, FRegister fs);
363 void SqrtD(FRegister fd, FRegister fs);
364 void AbsS(FRegister fd, FRegister fs);
365 void AbsD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700366 void MovS(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200367 void MovD(FRegister fd, FRegister fs);
368 void NegS(FRegister fd, FRegister fs);
369 void NegD(FRegister fd, FRegister fs);
370
Chris Larsenb74353a2015-11-20 09:07:09 -0800371 void CunS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800372 void CunS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800373 void CeqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800374 void CeqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800375 void CueqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800376 void CueqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800377 void ColtS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800378 void ColtS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800379 void CultS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800380 void CultS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800381 void ColeS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800382 void ColeS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800383 void CuleS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800384 void CuleS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800385 void CunD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800386 void CunD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800387 void CeqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800388 void CeqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800389 void CueqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800390 void CueqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800391 void ColtD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800392 void ColtD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800393 void CultD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800394 void CultD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800395 void ColeD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800396 void ColeD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800397 void CuleD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800398 void CuleD(int cc, FRegister fs, FRegister ft); // R2
399 void CmpUnS(FRegister fd, FRegister fs, FRegister ft); // R6
400 void CmpEqS(FRegister fd, FRegister fs, FRegister ft); // R6
401 void CmpUeqS(FRegister fd, FRegister fs, FRegister ft); // R6
402 void CmpLtS(FRegister fd, FRegister fs, FRegister ft); // R6
403 void CmpUltS(FRegister fd, FRegister fs, FRegister ft); // R6
404 void CmpLeS(FRegister fd, FRegister fs, FRegister ft); // R6
405 void CmpUleS(FRegister fd, FRegister fs, FRegister ft); // R6
406 void CmpOrS(FRegister fd, FRegister fs, FRegister ft); // R6
407 void CmpUneS(FRegister fd, FRegister fs, FRegister ft); // R6
408 void CmpNeS(FRegister fd, FRegister fs, FRegister ft); // R6
409 void CmpUnD(FRegister fd, FRegister fs, FRegister ft); // R6
410 void CmpEqD(FRegister fd, FRegister fs, FRegister ft); // R6
411 void CmpUeqD(FRegister fd, FRegister fs, FRegister ft); // R6
412 void CmpLtD(FRegister fd, FRegister fs, FRegister ft); // R6
413 void CmpUltD(FRegister fd, FRegister fs, FRegister ft); // R6
414 void CmpLeD(FRegister fd, FRegister fs, FRegister ft); // R6
415 void CmpUleD(FRegister fd, FRegister fs, FRegister ft); // R6
416 void CmpOrD(FRegister fd, FRegister fs, FRegister ft); // R6
417 void CmpUneD(FRegister fd, FRegister fs, FRegister ft); // R6
418 void CmpNeD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800419 void Movf(Register rd, Register rs, int cc = 0); // R2
420 void Movt(Register rd, Register rs, int cc = 0); // R2
421 void MovfS(FRegister fd, FRegister fs, int cc = 0); // R2
422 void MovfD(FRegister fd, FRegister fs, int cc = 0); // R2
423 void MovtS(FRegister fd, FRegister fs, int cc = 0); // R2
424 void MovtD(FRegister fd, FRegister fs, int cc = 0); // R2
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700425 void MovzS(FRegister fd, FRegister fs, Register rt); // R2
426 void MovzD(FRegister fd, FRegister fs, Register rt); // R2
427 void MovnS(FRegister fd, FRegister fs, Register rt); // R2
428 void MovnD(FRegister fd, FRegister fs, Register rt); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800429 void SelS(FRegister fd, FRegister fs, FRegister ft); // R6
430 void SelD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700431 void SeleqzS(FRegister fd, FRegister fs, FRegister ft); // R6
432 void SeleqzD(FRegister fd, FRegister fs, FRegister ft); // R6
433 void SelnezS(FRegister fd, FRegister fs, FRegister ft); // R6
434 void SelnezD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800435 void ClassS(FRegister fd, FRegister fs); // R6
436 void ClassD(FRegister fd, FRegister fs); // R6
437 void MinS(FRegister fd, FRegister fs, FRegister ft); // R6
438 void MinD(FRegister fd, FRegister fs, FRegister ft); // R6
439 void MaxS(FRegister fd, FRegister fs, FRegister ft); // R6
440 void MaxD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800441
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800442 void TruncLS(FRegister fd, FRegister fs); // R2+, FR=1
443 void TruncLD(FRegister fd, FRegister fs); // R2+, FR=1
444 void TruncWS(FRegister fd, FRegister fs);
445 void TruncWD(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200446 void Cvtsw(FRegister fd, FRegister fs);
447 void Cvtdw(FRegister fd, FRegister fs);
448 void Cvtsd(FRegister fd, FRegister fs);
449 void Cvtds(FRegister fd, FRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800450 void Cvtsl(FRegister fd, FRegister fs); // R2+, FR=1
451 void Cvtdl(FRegister fd, FRegister fs); // R2+, FR=1
Chris Larsenb74353a2015-11-20 09:07:09 -0800452 void FloorWS(FRegister fd, FRegister fs);
453 void FloorWD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700454
455 void Mfc1(Register rt, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200456 void Mtc1(Register rt, FRegister fs);
457 void Mfhc1(Register rt, FRegister fs);
458 void Mthc1(Register rt, FRegister fs);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800459 void MoveFromFpuHigh(Register rt, FRegister fs);
460 void MoveToFpuHigh(Register rt, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700461 void Lwc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200462 void Ldc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700463 void Swc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200464 void Sdc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700465
466 void Break();
jeffhao07030602012-09-26 14:33:14 -0700467 void Nop();
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700468 void NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200469 void Move(Register rd, Register rs);
470 void Clear(Register rd);
471 void Not(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700472
Lena Djokic0758ae72017-05-23 11:06:23 +0200473 // MSA instructions.
474 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
475 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
476 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
477 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
478
479 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
480 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
481 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
482 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
483 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
484 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
485 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
486 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
487 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
488 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
489 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
490 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
491 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
492 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
493 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
494 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
495 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
496 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
497 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
498 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
499 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
500 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
501 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
502 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
503 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
504 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
505 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
506 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
507 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
508 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
509 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
510 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
511 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
512 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
513 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
514 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
515 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
516 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
517 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
518 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
519 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
520 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
521 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
522 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
523 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
524 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
525 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
526 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
527 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
528 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
529 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
530 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
531 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
532 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
533 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
534 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
535 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
536 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
537 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
538 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
539 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
540 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
541 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
542 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
543
544 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
545 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
546 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
547 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
548 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
549 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
550 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
551 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
552 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
553 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
554 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
555 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
556
557 void Ffint_sW(VectorRegister wd, VectorRegister ws);
558 void Ffint_sD(VectorRegister wd, VectorRegister ws);
559 void Ftint_sW(VectorRegister wd, VectorRegister ws);
560 void Ftint_sD(VectorRegister wd, VectorRegister ws);
561
562 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
563 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
564 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
565 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
566 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
567 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
568 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
569 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
570 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
571 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
572 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
573 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
574
575 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
576 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
577 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
578 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
579 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
580 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
581 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
582 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
583 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
584 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
585 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
586 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
587 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
588
589 void MoveV(VectorRegister wd, VectorRegister ws);
590 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
591 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
592 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
593 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
594 void FillB(VectorRegister wd, Register rs);
595 void FillH(VectorRegister wd, Register rs);
596 void FillW(VectorRegister wd, Register rs);
597
598 void LdiB(VectorRegister wd, int imm8);
599 void LdiH(VectorRegister wd, int imm10);
600 void LdiW(VectorRegister wd, int imm10);
601 void LdiD(VectorRegister wd, int imm10);
602 void LdB(VectorRegister wd, Register rs, int offset);
603 void LdH(VectorRegister wd, Register rs, int offset);
604 void LdW(VectorRegister wd, Register rs, int offset);
605 void LdD(VectorRegister wd, Register rs, int offset);
606 void StB(VectorRegister wd, Register rs, int offset);
607 void StH(VectorRegister wd, Register rs, int offset);
608 void StW(VectorRegister wd, Register rs, int offset);
609 void StD(VectorRegister wd, Register rs, int offset);
610
611 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
612 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
613 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
614 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
615
Lena Djokicb3d79e42017-07-25 11:20:52 +0200616 void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
617 void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
618 void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
619 void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
620 void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
621 void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
622 void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
623 void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
624 void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
625 void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
626 void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
627 void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
628
Lena Djokic51765b02017-06-22 13:49:59 +0200629 // Helper for replicating floating point value in all destination elements.
630 void ReplicateFPToVectorRegister(VectorRegister dst, FRegister src, bool is_double);
631
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200632 // Higher level composite instructions.
633 void LoadConst32(Register rd, int32_t value);
634 void LoadConst64(Register reg_hi, Register reg_lo, int64_t value);
635 void LoadDConst64(FRegister rd, int64_t value, Register temp);
636 void LoadSConst32(FRegister r, int32_t value, Register temp);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200637 void Addiu32(Register rt, Register rs, int32_t value, Register rtmp = AT);
638
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700639 // These will generate R2 branches or R6 branches as appropriate and take care of
640 // the delay/forbidden slots.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200641 void Bind(MipsLabel* label);
642 void B(MipsLabel* label);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700643 void Bal(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200644 void Beq(Register rs, Register rt, MipsLabel* label);
645 void Bne(Register rs, Register rt, MipsLabel* label);
646 void Beqz(Register rt, MipsLabel* label);
647 void Bnez(Register rt, MipsLabel* label);
648 void Bltz(Register rt, MipsLabel* label);
649 void Bgez(Register rt, MipsLabel* label);
650 void Blez(Register rt, MipsLabel* label);
651 void Bgtz(Register rt, MipsLabel* label);
652 void Blt(Register rs, Register rt, MipsLabel* label);
653 void Bge(Register rs, Register rt, MipsLabel* label);
654 void Bltu(Register rs, Register rt, MipsLabel* label);
655 void Bgeu(Register rs, Register rt, MipsLabel* label);
Chris Larsenb74353a2015-11-20 09:07:09 -0800656 void Bc1f(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800657 void Bc1f(int cc, MipsLabel* label); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800658 void Bc1t(MipsLabel* label); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800659 void Bc1t(int cc, MipsLabel* label); // R2
660 void Bc1eqz(FRegister ft, MipsLabel* label); // R6
661 void Bc1nez(FRegister ft, MipsLabel* label); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700662
663 void EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset, size_t size);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700664 void AdjustBaseAndOffset(Register& base,
665 int32_t& offset,
666 bool is_doubleword,
667 bool is_float = false);
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200668 void AdjustBaseOffsetAndElementSizeShift(Register& base,
669 int32_t& offset,
670 int& element_size_shift);
Alexey Frunze2923db72016-08-20 01:55:47 -0700671
672 private:
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100673 // This will be used as an argument for loads/stores
674 // when there is no need for implicit null checks.
Alexey Frunze2923db72016-08-20 01:55:47 -0700675 struct NoImplicitNullChecker {
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100676 void operator()() const {}
Alexey Frunze2923db72016-08-20 01:55:47 -0700677 };
678
679 public:
680 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunzef58b2482016-09-02 22:14:06 -0700681 void StoreConstToOffset(StoreOperandType type,
682 int64_t value,
683 Register base,
684 int32_t offset,
685 Register temp,
686 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
687 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
688 // in which case the `base` register may be overwritten in the process.
Alexey Frunze2923db72016-08-20 01:55:47 -0700689 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 -0700690 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Alexey Frunze2923db72016-08-20 01:55:47 -0700691 uint32_t low = Low32Bits(value);
692 uint32_t high = High32Bits(value);
Alexey Frunzef58b2482016-09-02 22:14:06 -0700693 Register reg;
694 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
695 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
696 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
697 // original `base` (that is, `base` prior to the adjustment), the original `base`
698 // register will be overwritten.
699 if (base == temp) {
700 temp = AT;
Alexey Frunze2923db72016-08-20 01:55:47 -0700701 }
Alexey Frunzef58b2482016-09-02 22:14:06 -0700702 if (low == 0) {
703 reg = ZERO;
Alexey Frunze2923db72016-08-20 01:55:47 -0700704 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -0700705 reg = temp;
706 LoadConst32(reg, low);
707 }
708 switch (type) {
709 case kStoreByte:
710 Sb(reg, base, offset);
711 break;
712 case kStoreHalfword:
713 Sh(reg, base, offset);
714 break;
715 case kStoreWord:
716 Sw(reg, base, offset);
717 break;
718 case kStoreDoubleword:
719 Sw(reg, base, offset);
720 null_checker();
721 if (high == 0) {
722 reg = ZERO;
723 } else {
724 reg = temp;
725 if (high != low) {
726 LoadConst32(reg, high);
727 }
728 }
729 Sw(reg, base, offset + kMipsWordSize);
730 break;
731 default:
732 LOG(FATAL) << "UNREACHABLE";
733 }
734 if (type != kStoreDoubleword) {
735 null_checker();
Alexey Frunze2923db72016-08-20 01:55:47 -0700736 }
737 }
738
739 template <typename ImplicitNullChecker = NoImplicitNullChecker>
740 void LoadFromOffset(LoadOperandType type,
741 Register reg,
742 Register base,
743 int32_t offset,
744 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
745 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
746 switch (type) {
747 case kLoadSignedByte:
748 Lb(reg, base, offset);
749 break;
750 case kLoadUnsignedByte:
751 Lbu(reg, base, offset);
752 break;
753 case kLoadSignedHalfword:
754 Lh(reg, base, offset);
755 break;
756 case kLoadUnsignedHalfword:
757 Lhu(reg, base, offset);
758 break;
759 case kLoadWord:
760 Lw(reg, base, offset);
761 break;
762 case kLoadDoubleword:
763 if (reg == base) {
764 // This will clobber the base when loading the lower register. Since we have to load the
765 // higher register as well, this will fail. Solution: reverse the order.
766 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
767 null_checker();
768 Lw(reg, base, offset);
769 } else {
770 Lw(reg, base, offset);
771 null_checker();
772 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
773 }
774 break;
775 default:
776 LOG(FATAL) << "UNREACHABLE";
777 }
778 if (type != kLoadDoubleword) {
779 null_checker();
780 }
781 }
782
783 template <typename ImplicitNullChecker = NoImplicitNullChecker>
784 void LoadSFromOffset(FRegister reg,
785 Register base,
786 int32_t offset,
787 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
788 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
789 Lwc1(reg, base, offset);
790 null_checker();
791 }
792
793 template <typename ImplicitNullChecker = NoImplicitNullChecker>
794 void LoadDFromOffset(FRegister reg,
795 Register base,
796 int32_t offset,
797 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
798 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
799 if (IsAligned<kMipsDoublewordSize>(offset)) {
800 Ldc1(reg, base, offset);
801 null_checker();
802 } else {
803 if (Is32BitFPU()) {
804 Lwc1(reg, base, offset);
805 null_checker();
806 Lwc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
807 } else {
808 // 64-bit FPU.
809 Lwc1(reg, base, offset);
810 null_checker();
811 Lw(T8, base, offset + kMipsWordSize);
812 Mthc1(T8, reg);
813 }
814 }
815 }
816
817 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200818 void LoadQFromOffset(FRegister reg,
819 Register base,
820 int32_t offset,
821 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
822 int element_size_shift = -1;
823 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
824 switch (element_size_shift) {
825 case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break;
826 case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break;
827 case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break;
828 case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break;
829 default:
830 LOG(FATAL) << "UNREACHABLE";
831 }
832 null_checker();
833 }
834
835 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunze2923db72016-08-20 01:55:47 -0700836 void StoreToOffset(StoreOperandType type,
837 Register reg,
838 Register base,
839 int32_t offset,
840 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
841 // Must not use AT as `reg`, so as not to overwrite the value being stored
842 // with the adjusted `base`.
843 CHECK_NE(reg, AT);
844 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
845 switch (type) {
846 case kStoreByte:
847 Sb(reg, base, offset);
848 break;
849 case kStoreHalfword:
850 Sh(reg, base, offset);
851 break;
852 case kStoreWord:
853 Sw(reg, base, offset);
854 break;
855 case kStoreDoubleword:
856 CHECK_NE(reg, base);
857 CHECK_NE(static_cast<Register>(reg + 1), base);
858 Sw(reg, base, offset);
859 null_checker();
860 Sw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
861 break;
862 default:
863 LOG(FATAL) << "UNREACHABLE";
864 }
865 if (type != kStoreDoubleword) {
866 null_checker();
867 }
868 }
869
870 template <typename ImplicitNullChecker = NoImplicitNullChecker>
871 void StoreSToOffset(FRegister reg,
872 Register base,
873 int32_t offset,
874 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
875 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
876 Swc1(reg, base, offset);
877 null_checker();
878 }
879
880 template <typename ImplicitNullChecker = NoImplicitNullChecker>
881 void StoreDToOffset(FRegister reg,
882 Register base,
883 int32_t offset,
884 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
885 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
886 if (IsAligned<kMipsDoublewordSize>(offset)) {
887 Sdc1(reg, base, offset);
888 null_checker();
889 } else {
890 if (Is32BitFPU()) {
891 Swc1(reg, base, offset);
892 null_checker();
893 Swc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
894 } else {
895 // 64-bit FPU.
896 Mfhc1(T8, reg);
897 Swc1(reg, base, offset);
898 null_checker();
899 Sw(T8, base, offset + kMipsWordSize);
900 }
901 }
902 }
903
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200904 template <typename ImplicitNullChecker = NoImplicitNullChecker>
905 void StoreQToOffset(FRegister reg,
906 Register base,
907 int32_t offset,
908 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
909 int element_size_shift = -1;
910 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
911 switch (element_size_shift) {
912 case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break;
913 case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break;
914 case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break;
915 case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break;
916 default:
917 LOG(FATAL) << "UNREACHABLE";
918 }
919 null_checker();
920 }
921
jeffhao7fbee072012-08-24 17:56:54 -0700922 void LoadFromOffset(LoadOperandType type, Register reg, Register base, int32_t offset);
923 void LoadSFromOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200924 void LoadDFromOffset(FRegister reg, Register base, int32_t offset);
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200925 void LoadQFromOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700926 void StoreToOffset(StoreOperandType type, Register reg, Register base, int32_t offset);
Goran Jakovljevicff734982015-08-24 12:58:55 +0000927 void StoreSToOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200928 void StoreDToOffset(FRegister reg, Register base, int32_t offset);
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200929 void StoreQToOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -0700930
jeffhao7fbee072012-08-24 17:56:54 -0700931 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200932 void Emit(uint32_t value);
933
934 // Push/pop composite routines.
935 void Push(Register rs);
936 void Pop(Register rd);
937 void PopAndReturn(Register rd, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -0700938
Alexey Frunzec061de12017-02-14 13:27:23 -0800939 //
940 // Heap poisoning.
941 //
942
943 // Poison a heap reference contained in `src` and store it in `dst`.
944 void PoisonHeapReference(Register dst, Register src) {
945 // dst = -src.
946 Subu(dst, ZERO, src);
947 }
948 // Poison a heap reference contained in `reg`.
949 void PoisonHeapReference(Register reg) {
950 // reg = -reg.
951 PoisonHeapReference(reg, reg);
952 }
953 // Unpoison a heap reference contained in `reg`.
954 void UnpoisonHeapReference(Register reg) {
955 // reg = -reg.
956 Subu(reg, ZERO, reg);
957 }
958 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
959 void MaybePoisonHeapReference(Register reg) {
960 if (kPoisonHeapReferences) {
961 PoisonHeapReference(reg);
962 }
963 }
964 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
965 void MaybeUnpoisonHeapReference(Register reg) {
966 if (kPoisonHeapReferences) {
967 UnpoisonHeapReference(reg);
968 }
969 }
970
Andreas Gampe85b62f22015-09-09 13:15:38 -0700971 void Bind(Label* label) OVERRIDE {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200972 Bind(down_cast<MipsLabel*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -0700973 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200974 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
975 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS";
Andreas Gampe85b62f22015-09-09 13:15:38 -0700976 }
977
Igor Murashkinae7ff922016-10-06 14:59:19 -0700978 // Don't warn about a different virtual Bind/Jump in the base class.
979 using JNIBase::Bind;
980 using JNIBase::Jump;
981
982 // Create a new label that can be used with Jump/Bind calls.
983 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
984 LOG(FATAL) << "Not implemented on MIPS32";
985 UNREACHABLE();
986 }
987 // Emit an unconditional jump to the label.
988 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
989 LOG(FATAL) << "Not implemented on MIPS32";
990 UNREACHABLE();
991 }
992 // Emit a conditional jump to the label by applying a unary condition test to the register.
993 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
994 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
995 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
996 LOG(FATAL) << "Not implemented on MIPS32";
997 UNREACHABLE();
998 }
999
1000 // Code at this offset will serve as the target for the Jump call.
1001 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
1002 LOG(FATAL) << "Not implemented on MIPS32";
1003 UNREACHABLE();
1004 }
1005
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001006 // Create a new literal with a given value.
1007 // NOTE: Force the template parameter to be explicitly specified.
1008 template <typename T>
1009 Literal* NewLiteral(typename Identity<T>::type value) {
1010 static_assert(std::is_integral<T>::value, "T must be an integral type.");
1011 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
1012 }
1013
Alexey Frunze96b66822016-09-10 02:32:44 -07001014 // Load label address using the base register (for R2 only) or using PC-relative loads
1015 // (for R6 only; base_reg must be ZERO). To be used with data labels in the literal /
1016 // jump table area only and not with regular code labels.
1017 void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label);
1018
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001019 // Create a new literal with the given data.
1020 Literal* NewLiteral(size_t size, const uint8_t* data);
1021
1022 // Load literal using the base register (for R2 only) or using PC-relative loads
1023 // (for R6 only; base_reg must be ZERO).
1024 void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal);
1025
Alexey Frunze96b66822016-09-10 02:32:44 -07001026 // Create a jump table for the given labels that will be emitted when finalizing.
1027 // When the table is emitted, offsets will be relative to the location of the table.
1028 // The table location is determined by the location of its label (the label precedes
1029 // the table data) and should be loaded using LoadLabelAddress().
1030 JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels);
1031
jeffhao7fbee072012-08-24 17:56:54 -07001032 //
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001033 // Overridden common assembler high-level functionality.
jeffhao7fbee072012-08-24 17:56:54 -07001034 //
1035
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001036 // Emit code that will create an activation on the stack.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001037 void BuildFrame(size_t frame_size,
1038 ManagedRegister method_reg,
Vladimir Marko32248382016-05-19 10:37:24 +01001039 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001040 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001041
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001042 // Emit code that will remove an activation from the stack.
Vladimir Marko32248382016-05-19 10:37:24 +01001043 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs)
Ian Rogersdd7624d2014-03-14 17:43:00 -07001044 OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001045
Ian Rogersdd7624d2014-03-14 17:43:00 -07001046 void IncreaseFrameSize(size_t adjust) OVERRIDE;
1047 void DecreaseFrameSize(size_t adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001048
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001049 // Store routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001050 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
1051 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1052 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001053
Ian Rogersdd7624d2014-03-14 17:43:00 -07001054 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001055
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001056 void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
1057 FrameOffset fr_offs,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001058 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001059
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001060 void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001061
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001062 void StoreSpanning(FrameOffset dest,
1063 ManagedRegister msrc,
1064 FrameOffset in_off,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001065 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001066
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001067 // Load routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001068 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001069
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001070 void LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001071
Mathieu Chartiere401d142015-04-22 13:56:20 -07001072 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001073
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001074 void LoadRef(ManagedRegister mdest,
1075 ManagedRegister base,
1076 MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001077 bool unpoison_reference) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001078
Ian Rogersdd7624d2014-03-14 17:43:00 -07001079 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001080
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001081 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001082
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001083 // Copying routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001084 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001085
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001086 void CopyRawPtrFromThread(FrameOffset fr_offs,
1087 ThreadOffset32 thr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001088 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001089
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001090 void CopyRawPtrToThread(ThreadOffset32 thr_offs,
1091 FrameOffset fr_offs,
1092 ManagedRegister mscratch) OVERRIDE;
1093
Ian Rogersdd7624d2014-03-14 17:43:00 -07001094 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001095
Ian Rogersdd7624d2014-03-14 17:43:00 -07001096 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001097
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001098 void Copy(FrameOffset dest,
1099 ManagedRegister src_base,
1100 Offset src_offset,
1101 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001102 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001103
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001104 void Copy(ManagedRegister dest_base,
1105 Offset dest_offset,
1106 FrameOffset src,
1107 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001108 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001109
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001110 void Copy(FrameOffset dest,
1111 FrameOffset src_base,
1112 Offset src_offset,
1113 ManagedRegister mscratch,
1114 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001115
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001116 void Copy(ManagedRegister dest,
1117 Offset dest_offset,
1118 ManagedRegister src,
1119 Offset src_offset,
1120 ManagedRegister mscratch,
1121 size_t size) OVERRIDE;
1122
1123 void Copy(FrameOffset dest,
1124 Offset dest_offset,
1125 FrameOffset src,
1126 Offset src_offset,
1127 ManagedRegister mscratch,
1128 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001129
Ian Rogersdd7624d2014-03-14 17:43:00 -07001130 void MemoryBarrier(ManagedRegister) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001131
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001132 // Sign extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001133 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001134
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001135 // Zero extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001136 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001137
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001138 // Exploit fast access in managed code to Thread::Current().
Ian Rogersdd7624d2014-03-14 17:43:00 -07001139 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1140 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001141
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001142 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001143 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001144 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001145 // null.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001146 void CreateHandleScopeEntry(ManagedRegister out_reg,
1147 FrameOffset handlescope_offset,
1148 ManagedRegister in_reg,
1149 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001150
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001151 // Set up out_off to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001152 // value is null and null_allowed.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001153 void CreateHandleScopeEntry(FrameOffset out_off,
1154 FrameOffset handlescope_offset,
1155 ManagedRegister mscratch,
1156 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001157
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001158 // src holds a handle scope entry (Object**) load this into dst.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001159 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001160
1161 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1162 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001163 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1164 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001165
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001166 // Call to address held at [base+offset].
Ian Rogersdd7624d2014-03-14 17:43:00 -07001167 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1168 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001169 void CallFromThread(ThreadOffset32 offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001170
jeffhao7fbee072012-08-24 17:56:54 -07001171 // Generate code to check if Thread::Current()->exception_ is non-null
1172 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001173 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001174
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001175 // Emit slow paths queued during assembly and promote short branches to long if needed.
1176 void FinalizeCode() OVERRIDE;
1177
1178 // Emit branches and finalize all instructions.
1179 void FinalizeInstructions(const MemoryRegion& region);
1180
1181 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS,
1182 // must be used instead of MipsLabel::GetPosition()).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001183 uint32_t GetLabelLocation(const MipsLabel* label) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001184
1185 // Get the final position of a label after local fixup based on the old position
1186 // recorded before FinalizeCode().
1187 uint32_t GetAdjustedPosition(uint32_t old_position);
1188
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001189 // R2 doesn't have PC-relative addressing, which we need to access literals. We simulate it by
1190 // reading the PC value into a general-purpose register with the NAL instruction and then loading
1191 // literals through this base register. The code generator calls this method (at most once per
1192 // method being compiled) to bind a label to the location for which the PC value is acquired.
1193 // The assembler then computes literal offsets relative to this label.
1194 void BindPcRelBaseLabel();
1195
Alexey Frunze06a46c42016-07-19 15:00:40 -07001196 // Returns the location of the label bound with BindPcRelBaseLabel().
1197 uint32_t GetPcRelBaseLabelLocation() const;
1198
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001199 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1200 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1201 // to PC.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001202 enum BranchCondition {
1203 kCondLT,
1204 kCondGE,
1205 kCondLE,
1206 kCondGT,
1207 kCondLTZ,
1208 kCondGEZ,
1209 kCondLEZ,
1210 kCondGTZ,
1211 kCondEQ,
1212 kCondNE,
1213 kCondEQZ,
1214 kCondNEZ,
1215 kCondLTU,
1216 kCondGEU,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001217 kCondF, // Floating-point predicate false.
1218 kCondT, // Floating-point predicate true.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001219 kUncond,
1220 };
1221 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1222
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001223 // Enables or disables instruction reordering (IOW, automatic filling of delay slots)
1224 // similarly to ".set reorder" / ".set noreorder" in traditional MIPS assembly.
1225 // Returns the last state, which may be useful for temporary enabling/disabling of
1226 // reordering.
1227 bool SetReorder(bool enable);
1228
jeffhao7fbee072012-08-24 17:56:54 -07001229 private:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001230 // Description of the last instruction in terms of input and output registers.
1231 // Used to make the decision of moving the instruction into a delay slot.
1232 struct DelaySlot {
1233 DelaySlot();
1234 // Encoded instruction that may be used to fill the delay slot or 0
1235 // (0 conveniently represents NOP).
1236 uint32_t instruction_;
1237 // Mask of output GPRs for the instruction.
1238 uint32_t gpr_outs_mask_;
1239 // Mask of input GPRs for the instruction.
1240 uint32_t gpr_ins_mask_;
1241 // Mask of output FPRs for the instruction.
1242 uint32_t fpr_outs_mask_;
1243 // Mask of input FPRs for the instruction.
1244 uint32_t fpr_ins_mask_;
1245 // Mask of output FPU condition code flags for the instruction.
1246 uint32_t cc_outs_mask_;
1247 // Mask of input FPU condition code flags for the instruction.
1248 uint32_t cc_ins_mask_;
1249 // Branches never operate on the LO and HI registers, hence there's
1250 // no mask for LO and HI.
1251 };
1252
1253 // Delay slot finite state machine's (DS FSM's) state. The FSM state is updated
1254 // upon every new instruction and label generated. The FSM detects instructions
1255 // suitable for delay slots and immediately preceded with labels. These are target
1256 // instructions for branches. If an unconditional R2 branch does not get its delay
1257 // slot filled with the immediately preceding instruction, it may instead get the
1258 // slot filled with the target instruction (the branch will need its offset
1259 // incremented past the target instruction). We call this "absorption". The FSM
1260 // records PCs of the target instructions suitable for this optimization.
1261 enum DsFsmState {
1262 kExpectingLabel,
1263 kExpectingInstruction,
1264 kExpectingCommit
1265 };
1266 friend std::ostream& operator<<(std::ostream& os, const DsFsmState& rhs);
1267
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001268 class Branch {
1269 public:
1270 enum Type {
1271 // R2 short branches.
1272 kUncondBranch,
1273 kCondBranch,
1274 kCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001275 // R2 near label.
1276 kLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001277 // R2 near literal.
1278 kLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001279 // R2 long branches.
1280 kLongUncondBranch,
1281 kLongCondBranch,
1282 kLongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001283 // R2 far label.
1284 kFarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001285 // R2 far literal.
1286 kFarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001287 // R6 short branches.
1288 kR6UncondBranch,
1289 kR6CondBranch,
1290 kR6Call,
Alexey Frunze96b66822016-09-10 02:32:44 -07001291 // R6 near label.
1292 kR6Label,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001293 // R6 near literal.
1294 kR6Literal,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001295 // R6 long branches.
1296 kR6LongUncondBranch,
1297 kR6LongCondBranch,
1298 kR6LongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001299 // R6 far label.
1300 kR6FarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001301 // R6 far literal.
1302 kR6FarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001303 };
1304 // Bit sizes of offsets defined as enums to minimize chance of typos.
1305 enum OffsetBits {
1306 kOffset16 = 16,
1307 kOffset18 = 18,
1308 kOffset21 = 21,
1309 kOffset23 = 23,
1310 kOffset28 = 28,
1311 kOffset32 = 32,
1312 };
1313
1314 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1315 static constexpr int32_t kMaxBranchLength = 32;
1316 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001317 // The following two instruction encodings can never legally occur in branch delay
1318 // slots and are used as markers.
1319 //
1320 // kUnfilledDelaySlot means that the branch may use either the preceding or the target
1321 // instruction to fill its delay slot (the latter is only possible with unconditional
1322 // R2 branches and is termed here as "absorption").
1323 static constexpr uint32_t kUnfilledDelaySlot = 0x10000000; // beq zero, zero, 0.
1324 // kUnfillableDelaySlot means that the branch cannot use an instruction (other than NOP)
1325 // to fill its delay slot. This is only used for unconditional R2 branches to prevent
1326 // absorption of the target instruction when reordering is disabled.
1327 static constexpr uint32_t kUnfillableDelaySlot = 0x13FF0000; // beq ra, ra, 0.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001328
1329 struct BranchInfo {
1330 // Branch length as a number of 4-byte-long instructions.
1331 uint32_t length;
1332 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1333 // PC-relative offset (or its most significant 16-bit half, which goes first).
1334 uint32_t instr_offset;
1335 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1336 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1337 // instructions) from the instruction containing the offset.
1338 uint32_t pc_org;
1339 // How large (in bits) a PC-relative offset can be for a given type of branch (kR6CondBranch
1340 // is an exception: use kOffset23 for beqzc/bnezc).
1341 OffsetBits offset_size;
1342 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1343 // count.
1344 int offset_shift;
1345 };
1346 static const BranchInfo branch_info_[/* Type */];
1347
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001348 // Unconditional branch or call.
1349 Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001350 // Conditional branch.
1351 Branch(bool is_r6,
1352 uint32_t location,
1353 uint32_t target,
1354 BranchCondition condition,
1355 Register lhs_reg,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001356 Register rhs_reg);
Alexey Frunze96b66822016-09-10 02:32:44 -07001357 // Label address (in literal area) or literal.
1358 Branch(bool is_r6,
1359 uint32_t location,
1360 Register dest_reg,
1361 Register base_reg,
1362 Type label_or_literal_type);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001363
1364 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1365 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1366 // So, we need a way to identify such branches in order to emit no instructions for them
1367 // or change them to unconditional.
1368 static bool IsNop(BranchCondition condition, Register lhs, Register rhs);
1369 static bool IsUncond(BranchCondition condition, Register lhs, Register rhs);
1370
1371 static BranchCondition OppositeCondition(BranchCondition cond);
1372
1373 Type GetType() const;
1374 BranchCondition GetCondition() const;
1375 Register GetLeftRegister() const;
1376 Register GetRightRegister() const;
1377 uint32_t GetTarget() const;
1378 uint32_t GetLocation() const;
1379 uint32_t GetOldLocation() const;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001380 uint32_t GetPrecedingInstructionLength(Type type) const;
1381 uint32_t GetPrecedingInstructionSize(Type type) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001382 uint32_t GetLength() const;
1383 uint32_t GetOldLength() const;
1384 uint32_t GetSize() const;
1385 uint32_t GetOldSize() const;
1386 uint32_t GetEndLocation() const;
1387 uint32_t GetOldEndLocation() const;
1388 bool IsLong() const;
1389 bool IsResolved() const;
1390
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001391 // Various helpers for branch delay slot management.
1392 bool CanHaveDelayedInstruction(const DelaySlot& delay_slot) const;
1393 void SetDelayedInstruction(uint32_t instruction);
1394 uint32_t GetDelayedInstruction() const;
1395 void DecrementLocations();
1396
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001397 // Returns the bit size of the signed offset that the branch instruction can handle.
1398 OffsetBits GetOffsetSize() const;
1399
1400 // Calculates the distance between two byte locations in the assembler buffer and
1401 // returns the number of bits needed to represent the distance as a signed integer.
1402 //
1403 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1404 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1405 //
1406 // Composite branches (made of several instructions) with longer reach have 32-bit
1407 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001408 // The composite branches cover the range of PC + +/-2GB on MIPS32 CPUs. However,
1409 // the range is not end-to-end on MIPS64 (unless addresses are forced to zero- or
1410 // sign-extend from 32 to 64 bits by the appropriate CPU configuration).
1411 // Consider the following implementation of a long unconditional branch, for
1412 // example:
1413 //
1414 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1415 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1416 //
1417 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1418 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1419 // due to sign extension. This must be compensated for by incrementing offset_31_16
1420 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1421 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1422 // Therefore, the long branch range is something like from PC - 0x80000000 to
1423 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001424 //
1425 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1426 // case with the addiu instruction and a 16 bit offset.
1427 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1428
1429 // Resolve a branch when the target is known.
1430 void Resolve(uint32_t target);
1431
1432 // Relocate a branch by a given delta if needed due to expansion of this or another
1433 // branch at a given location by this delta (just changes location_ and target_).
1434 void Relocate(uint32_t expand_location, uint32_t delta);
1435
1436 // If the branch is short, changes its type to long.
1437 void PromoteToLong();
1438
1439 // If necessary, updates the type by promoting a short branch to a long branch
1440 // based on the branch location and target. Returns the amount (in bytes) by
1441 // which the branch size has increased.
1442 // max_short_distance caps the maximum distance between location_ and target_
1443 // that is allowed for short branches. This is for debugging/testing purposes.
1444 // max_short_distance = 0 forces all short branches to become long.
1445 // Use the implicit default argument when not debugging/testing.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001446 uint32_t PromoteIfNeeded(uint32_t location,
1447 uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001448
1449 // Returns the location of the instruction(s) containing the offset.
1450 uint32_t GetOffsetLocation() const;
1451
1452 // Calculates and returns the offset ready for encoding in the branch instruction(s).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001453 uint32_t GetOffset(uint32_t location) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001454
1455 private:
1456 // Completes branch construction by determining and recording its type.
Alexey Frunze96b66822016-09-10 02:32:44 -07001457 void InitializeType(Type initial_type, bool is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001458 // Helper for the above.
1459 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1460
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001461 uint32_t old_location_; // Offset into assembler buffer in bytes.
1462 uint32_t location_; // Offset into assembler buffer in bytes.
1463 uint32_t target_; // Offset into assembler buffer in bytes.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001464
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001465 uint32_t lhs_reg_; // Left-hand side register in conditional branches or
1466 // FPU condition code. Destination register in literals.
1467 uint32_t rhs_reg_; // Right-hand side register in conditional branches.
1468 // Base register in literals (ZERO on R6).
1469 BranchCondition condition_; // Condition for conditional branches.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001470
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001471 Type type_; // Current type of the branch.
1472 Type old_type_; // Initial type of the branch.
1473
1474 uint32_t delayed_instruction_; // Encoded instruction for the delay slot or
1475 // kUnfilledDelaySlot if none but fillable or
1476 // kUnfillableDelaySlot if none and unfillable
1477 // (the latter is only used for unconditional R2
1478 // branches).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001479 };
1480 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1481 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1482
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001483 uint32_t EmitR(int opcode, Register rs, Register rt, Register rd, int shamt, int funct);
1484 uint32_t EmitI(int opcode, Register rs, Register rt, uint16_t imm);
1485 uint32_t EmitI21(int opcode, Register rs, uint32_t imm21);
1486 uint32_t EmitI26(int opcode, uint32_t imm26);
1487 uint32_t EmitFR(int opcode, int fmt, FRegister ft, FRegister fs, FRegister fd, int funct);
1488 uint32_t EmitFI(int opcode, int fmt, FRegister rt, uint16_t imm);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001489 void EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16);
1490 void EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21);
Lena Djokic0758ae72017-05-23 11:06:23 +02001491 uint32_t EmitMsa3R(int operation,
1492 int df,
1493 VectorRegister wt,
1494 VectorRegister ws,
1495 VectorRegister wd,
1496 int minor_opcode);
1497 uint32_t EmitMsaBIT(int operation,
1498 int df_m,
1499 VectorRegister ws,
1500 VectorRegister wd,
1501 int minor_opcode);
1502 uint32_t EmitMsaELM(int operation,
1503 int df_n,
1504 VectorRegister ws,
1505 VectorRegister wd,
1506 int minor_opcode);
1507 uint32_t EmitMsaMI10(int s10, Register rs, VectorRegister wd, int minor_opcode, int df);
1508 uint32_t EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
1509 uint32_t EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1510 uint32_t EmitMsa2RF(int operation,
1511 int df,
1512 VectorRegister ws,
1513 VectorRegister wd,
1514 int minor_opcode);
jeffhao7fbee072012-08-24 17:56:54 -07001515
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001516 void Buncond(MipsLabel* label);
1517 void Bcond(MipsLabel* label, BranchCondition condition, Register lhs, Register rhs = ZERO);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001518 void Call(MipsLabel* label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001519 void FinalizeLabeledBranch(MipsLabel* label);
jeffhao7fbee072012-08-24 17:56:54 -07001520
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001521 // Various helpers for branch delay slot management.
1522 void DsFsmInstr(uint32_t instruction,
1523 uint32_t gpr_outs_mask,
1524 uint32_t gpr_ins_mask,
1525 uint32_t fpr_outs_mask,
1526 uint32_t fpr_ins_mask,
1527 uint32_t cc_outs_mask,
1528 uint32_t cc_ins_mask);
1529 void DsFsmInstrNop(uint32_t instruction);
1530 void DsFsmInstrRrr(uint32_t instruction, Register out, Register in1, Register in2);
1531 void DsFsmInstrRrrr(uint32_t instruction, Register in1_out, Register in2, Register in3);
1532 void DsFsmInstrFff(uint32_t instruction, FRegister out, FRegister in1, FRegister in2);
1533 void DsFsmInstrFfff(uint32_t instruction, FRegister in1_out, FRegister in2, FRegister in3);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001534 void DsFsmInstrFffr(uint32_t instruction, FRegister in1_out, FRegister in2, Register in3);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001535 void DsFsmInstrRf(uint32_t instruction, Register out, FRegister in);
1536 void DsFsmInstrFr(uint32_t instruction, FRegister out, Register in);
1537 void DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2);
1538 void DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2);
1539 void DsFsmInstrRrrc(uint32_t instruction, Register in1_out, Register in2, int cc_in);
1540 void DsFsmInstrFffc(uint32_t instruction, FRegister in1_out, FRegister in2, int cc_in);
1541 void DsFsmLabel();
1542 void DsFsmCommitLabel();
1543 void DsFsmDropLabel();
1544 void MoveInstructionToDelaySlot(Branch& branch);
1545 bool CanExchangeWithSlt(Register rs, Register rt) const;
1546 void ExchangeWithSlt(const DelaySlot& forwarded_slot);
1547 void GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt);
1548
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001549 Branch* GetBranch(uint32_t branch_id);
1550 const Branch* GetBranch(uint32_t branch_id) const;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001551 uint32_t GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const;
1552 uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001553
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001554 void EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -07001555 void ReserveJumpTableSpace();
1556 void EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001557 void PromoteBranches();
1558 void EmitBranch(Branch* branch);
1559 void EmitBranches();
Vladimir Marko10ef6942015-10-22 15:25:54 +01001560 void PatchCFI(size_t number_of_delayed_adjust_pcs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001561
1562 // Emits exception block.
1563 void EmitExceptionPoll(MipsExceptionSlowPath* exception);
1564
Lena Djokic0758ae72017-05-23 11:06:23 +02001565 bool HasMsa() const {
1566 return has_msa_;
1567 }
1568
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001569 bool IsR6() const {
1570 if (isa_features_ != nullptr) {
1571 return isa_features_->IsR6();
1572 } else {
1573 return false;
1574 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001575 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001576
1577 bool Is32BitFPU() const {
1578 if (isa_features_ != nullptr) {
1579 return isa_features_->Is32BitFloatingPoint();
1580 } else {
1581 return true;
1582 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001583 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001584
1585 // List of exception blocks to generate at the end of the code cache.
1586 std::vector<MipsExceptionSlowPath> exception_blocks_;
1587
1588 std::vector<Branch> branches_;
1589
1590 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1591 bool overwriting_;
1592 // The current overwrite location.
1593 uint32_t overwrite_location_;
1594
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001595 // Whether instruction reordering (IOW, automatic filling of delay slots) is enabled.
1596 bool reordering_;
1597 // Information about the last instruction that may be used to fill a branch delay slot.
1598 DelaySlot delay_slot_;
1599 // Delay slot FSM state.
1600 DsFsmState ds_fsm_state_;
1601 // PC of the current labeled target instruction.
1602 uint32_t ds_fsm_target_pc_;
1603 // PCs of labeled target instructions.
1604 std::vector<uint32_t> ds_fsm_target_pcs_;
1605
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001606 // Use std::deque<> for literal labels to allow insertions at the end
1607 // without invalidating pointers and references to existing elements.
1608 ArenaDeque<Literal> literals_;
1609
Alexey Frunze96b66822016-09-10 02:32:44 -07001610 // Jump table list.
1611 ArenaDeque<JumpTable> jump_tables_;
1612
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001613 // There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC
1614 // we get PC using the NAL instruction. This label marks the position within the assembler buffer
1615 // that PC (from NAL) points to.
1616 MipsLabel pc_rel_base_label_;
1617
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001618 // Data for GetAdjustedPosition(), see the description there.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001619 uint32_t last_position_adjustment_;
1620 uint32_t last_old_position_;
1621 uint32_t last_branch_id_;
1622
Lena Djokic0758ae72017-05-23 11:06:23 +02001623 const bool has_msa_;
1624
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001625 const MipsInstructionSetFeatures* isa_features_;
Goran Jakovljevicff734982015-08-24 12:58:55 +00001626
jeffhao7fbee072012-08-24 17:56:54 -07001627 DISALLOW_COPY_AND_ASSIGN(MipsAssembler);
1628};
1629
jeffhao7fbee072012-08-24 17:56:54 -07001630} // namespace mips
1631} // namespace art
1632
Ian Rogers166db042013-07-26 12:05:57 -07001633#endif // ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_