blob: c0ea29fbd73f0dcea85cde5b60655d34ba4891ef [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"
Andreas Gampe09659c22017-09-18 18:23:32 -070031#include "heap_poisoning.h"
jeffhao7fbee072012-08-24 17:56:54 -070032#include "managed_register_mips.h"
jeffhao7fbee072012-08-24 17:56:54 -070033#include "offsets.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020034#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070035#include "utils/jni_macro_assembler.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020036#include "utils/label.h"
jeffhao7fbee072012-08-24 17:56:54 -070037
38namespace art {
39namespace mips {
jeffhao7fbee072012-08-24 17:56:54 -070040
Lena Djokic0758ae72017-05-23 11:06:23 +020041static constexpr size_t kMipsHalfwordSize = 2;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020042static constexpr size_t kMipsWordSize = 4;
43static constexpr size_t kMipsDoublewordSize = 8;
44
jeffhao7fbee072012-08-24 17:56:54 -070045enum LoadOperandType {
46 kLoadSignedByte,
47 kLoadUnsignedByte,
48 kLoadSignedHalfword,
49 kLoadUnsignedHalfword,
50 kLoadWord,
Lena Djokic2e0a7e52017-07-06 11:55:24 +020051 kLoadDoubleword,
52 kLoadQuadword
jeffhao7fbee072012-08-24 17:56:54 -070053};
54
55enum StoreOperandType {
56 kStoreByte,
57 kStoreHalfword,
58 kStoreWord,
Lena Djokic2e0a7e52017-07-06 11:55:24 +020059 kStoreDoubleword,
60 kStoreQuadword
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020061};
62
Chris Larsenb74353a2015-11-20 09:07:09 -080063// Used to test the values returned by ClassS/ClassD.
64enum FPClassMaskType {
65 kSignalingNaN = 0x001,
66 kQuietNaN = 0x002,
67 kNegativeInfinity = 0x004,
68 kNegativeNormal = 0x008,
69 kNegativeSubnormal = 0x010,
70 kNegativeZero = 0x020,
71 kPositiveInfinity = 0x040,
72 kPositiveNormal = 0x080,
73 kPositiveSubnormal = 0x100,
74 kPositiveZero = 0x200,
75};
76
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020077class MipsLabel : public Label {
78 public:
79 MipsLabel() : prev_branch_id_plus_one_(0) {}
80
81 MipsLabel(MipsLabel&& src)
82 : Label(std::move(src)), prev_branch_id_plus_one_(src.prev_branch_id_plus_one_) {}
83
Alexey Frunzea663d9d2017-07-31 18:43:18 -070084 void AdjustBoundPosition(int delta) {
85 CHECK(IsBound());
86 // Bound label's position is negative, hence decrementing it.
87 position_ -= delta;
88 }
89
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020090 private:
91 uint32_t prev_branch_id_plus_one_; // To get distance from preceding branch, if any.
92
93 friend class MipsAssembler;
94 DISALLOW_COPY_AND_ASSIGN(MipsLabel);
95};
96
Alexey Frunzee3fb2452016-05-10 16:08:05 -070097// Assembler literal is a value embedded in code, retrieved using a PC-relative load.
98class Literal {
99 public:
100 static constexpr size_t kMaxSize = 8;
101
102 Literal(uint32_t size, const uint8_t* data)
103 : label_(), size_(size) {
104 DCHECK_LE(size, Literal::kMaxSize);
105 memcpy(data_, data, size);
106 }
107
108 template <typename T>
109 T GetValue() const {
110 DCHECK_EQ(size_, sizeof(T));
111 T value;
112 memcpy(&value, data_, sizeof(T));
113 return value;
114 }
115
116 uint32_t GetSize() const {
117 return size_;
118 }
119
120 const uint8_t* GetData() const {
121 return data_;
122 }
123
124 MipsLabel* GetLabel() {
125 return &label_;
126 }
127
128 const MipsLabel* GetLabel() const {
129 return &label_;
130 }
131
132 private:
133 MipsLabel label_;
134 const uint32_t size_;
135 uint8_t data_[kMaxSize];
136
137 DISALLOW_COPY_AND_ASSIGN(Literal);
138};
139
Alexey Frunze96b66822016-09-10 02:32:44 -0700140// Jump table: table of labels emitted after the literals. Similar to literals.
141class JumpTable {
142 public:
143 explicit JumpTable(std::vector<MipsLabel*>&& labels)
144 : label_(), labels_(std::move(labels)) {
145 }
146
147 uint32_t GetSize() const {
148 return static_cast<uint32_t>(labels_.size()) * sizeof(uint32_t);
149 }
150
151 const std::vector<MipsLabel*>& GetData() const {
152 return labels_;
153 }
154
155 MipsLabel* GetLabel() {
156 return &label_;
157 }
158
159 const MipsLabel* GetLabel() const {
160 return &label_;
161 }
162
163 private:
164 MipsLabel label_;
165 std::vector<MipsLabel*> labels_;
166
167 DISALLOW_COPY_AND_ASSIGN(JumpTable);
168};
169
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200170// Slowpath entered when Thread::Current()->_exception is non-null.
171class MipsExceptionSlowPath {
172 public:
173 explicit MipsExceptionSlowPath(MipsManagedRegister scratch, size_t stack_adjust)
174 : scratch_(scratch), stack_adjust_(stack_adjust) {}
175
176 MipsExceptionSlowPath(MipsExceptionSlowPath&& src)
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800177 : scratch_(src.scratch_),
178 stack_adjust_(src.stack_adjust_),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200179 exception_entry_(std::move(src.exception_entry_)) {}
180
181 private:
182 MipsLabel* Entry() { return &exception_entry_; }
183 const MipsManagedRegister scratch_;
184 const size_t stack_adjust_;
185 MipsLabel exception_entry_;
186
187 friend class MipsAssembler;
188 DISALLOW_COPY_AND_ASSIGN(MipsExceptionSlowPath);
jeffhao7fbee072012-08-24 17:56:54 -0700189};
190
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700191class MipsAssembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> {
jeffhao7fbee072012-08-24 17:56:54 -0700192 public:
Igor Murashkinae7ff922016-10-06 14:59:19 -0700193 using JNIBase = JNIMacroAssembler<PointerSize::k32>;
194
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100195 explicit MipsAssembler(ArenaAllocator* allocator,
Vladimir Marko93205e32016-04-13 11:59:46 +0100196 const MipsInstructionSetFeatures* instruction_set_features = nullptr)
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100197 : Assembler(allocator),
Vladimir Marko93205e32016-04-13 11:59:46 +0100198 overwriting_(false),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200199 overwrite_location_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700200 reordering_(true),
201 ds_fsm_state_(kExpectingLabel),
202 ds_fsm_target_pc_(0),
Vladimir Markoe764d2e2017-10-05 14:35:55 +0100203 literals_(allocator->Adapter(kArenaAllocAssembler)),
204 jump_tables_(allocator->Adapter(kArenaAllocAssembler)),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200205 last_position_adjustment_(0),
206 last_old_position_(0),
207 last_branch_id_(0),
Lena Djokic0758ae72017-05-23 11:06:23 +0200208 has_msa_(instruction_set_features != nullptr ? instruction_set_features->HasMsa() : false),
Vladimir Marko10ef6942015-10-22 15:25:54 +0100209 isa_features_(instruction_set_features) {
210 cfi().DelayEmittingAdvancePCs();
211 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200212
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700213 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700214 size_t CodePosition() OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700215 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
216
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200217 virtual ~MipsAssembler() {
218 for (auto& branch : branches_) {
219 CHECK(branch.IsResolved());
220 }
221 }
jeffhao7fbee072012-08-24 17:56:54 -0700222
223 // Emit Machine Instructions.
jeffhao7fbee072012-08-24 17:56:54 -0700224 void Addu(Register rd, Register rs, Register rt);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700225 void Addiu(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label);
jeffhao7fbee072012-08-24 17:56:54 -0700226 void Addiu(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700227 void Subu(Register rd, Register rs, Register rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200228
229 void MultR2(Register rs, Register rt); // R2
230 void MultuR2(Register rs, Register rt); // R2
231 void DivR2(Register rs, Register rt); // R2
232 void DivuR2(Register rs, Register rt); // R2
233 void MulR2(Register rd, Register rs, Register rt); // R2
234 void DivR2(Register rd, Register rs, Register rt); // R2
235 void ModR2(Register rd, Register rs, Register rt); // R2
236 void DivuR2(Register rd, Register rs, Register rt); // R2
237 void ModuR2(Register rd, Register rs, Register rt); // R2
238 void MulR6(Register rd, Register rs, Register rt); // R6
Alexey Frunze7e99e052015-11-24 19:28:01 -0800239 void MuhR6(Register rd, Register rs, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200240 void MuhuR6(Register rd, Register rs, Register rt); // R6
241 void DivR6(Register rd, Register rs, Register rt); // R6
242 void ModR6(Register rd, Register rs, Register rt); // R6
243 void DivuR6(Register rd, Register rs, Register rt); // R6
244 void ModuR6(Register rd, Register rs, Register rt); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700245
246 void And(Register rd, Register rs, Register rt);
247 void Andi(Register rt, Register rs, uint16_t imm16);
248 void Or(Register rd, Register rs, Register rt);
249 void Ori(Register rt, Register rs, uint16_t imm16);
250 void Xor(Register rd, Register rs, Register rt);
251 void Xori(Register rt, Register rs, uint16_t imm16);
252 void Nor(Register rd, Register rs, Register rt);
253
Chris Larsene3845472015-11-18 12:27:15 -0800254 void Movz(Register rd, Register rs, Register rt); // R2
255 void Movn(Register rd, Register rs, Register rt); // R2
256 void Seleqz(Register rd, Register rs, Register rt); // R6
257 void Selnez(Register rd, Register rs, Register rt); // R6
258 void ClzR6(Register rd, Register rs);
259 void ClzR2(Register rd, Register rs);
260 void CloR6(Register rd, Register rs);
261 void CloR2(Register rd, Register rs);
262
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200263 void Seb(Register rd, Register rt); // R2+
264 void Seh(Register rd, Register rt); // R2+
Chris Larsen3f8bf652015-10-28 10:08:56 -0700265 void Wsbh(Register rd, Register rt); // R2+
Chris Larsen70014c82015-11-18 12:26:08 -0800266 void Bitswap(Register rd, Register rt); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200267
268 void Sll(Register rd, Register rt, int shamt);
269 void Srl(Register rd, Register rt, int shamt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700270 void Rotr(Register rd, Register rt, int shamt); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200271 void Sra(Register rd, Register rt, int shamt);
272 void Sllv(Register rd, Register rt, Register rs);
273 void Srlv(Register rd, Register rt, Register rs);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800274 void Rotrv(Register rd, Register rt, Register rs); // R2+
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200275 void Srav(Register rd, Register rt, Register rs);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800276 void Ext(Register rd, Register rt, int pos, int size); // R2+
277 void Ins(Register rd, Register rt, int pos, int size); // R2+
Chris Larsen692235e2016-11-21 16:04:53 -0800278 void Lsa(Register rd, Register rs, Register rt, int saPlusOne); // R6
Chris Larsencd0295d2017-03-31 15:26:54 -0700279 void ShiftAndAdd(Register dst, Register src_idx, Register src_base, int shamt, Register tmp = AT);
jeffhao7fbee072012-08-24 17:56:54 -0700280
281 void Lb(Register rt, Register rs, uint16_t imm16);
282 void Lh(Register rt, Register rs, uint16_t imm16);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700283 void Lw(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label);
jeffhao7fbee072012-08-24 17:56:54 -0700284 void Lw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800285 void Lwl(Register rt, Register rs, uint16_t imm16);
286 void Lwr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700287 void Lbu(Register rt, Register rs, uint16_t imm16);
288 void Lhu(Register rt, Register rs, uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700289 void Lwpc(Register rs, uint32_t imm19); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700290 void Lui(Register rt, uint16_t imm16);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700291 void Aui(Register rt, Register rs, uint16_t imm16); // R6
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700292 void AddUpper(Register rt, Register rs, uint16_t imm16, Register tmp = AT);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200293 void Sync(uint32_t stype);
294 void Mfhi(Register rd); // R2
295 void Mflo(Register rd); // R2
jeffhao7fbee072012-08-24 17:56:54 -0700296
297 void Sb(Register rt, Register rs, uint16_t imm16);
298 void Sh(Register rt, Register rs, uint16_t imm16);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700299 void Sw(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label);
jeffhao7fbee072012-08-24 17:56:54 -0700300 void Sw(Register rt, Register rs, uint16_t imm16);
Chris Larsen3acee732015-11-18 13:31:08 -0800301 void Swl(Register rt, Register rs, uint16_t imm16);
302 void Swr(Register rt, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700303
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700304 void LlR2(Register rt, Register base, int16_t imm16 = 0);
305 void ScR2(Register rt, Register base, int16_t imm16 = 0);
306 void LlR6(Register rt, Register base, int16_t imm9 = 0);
307 void ScR6(Register rt, Register base, int16_t imm9 = 0);
308
jeffhao7fbee072012-08-24 17:56:54 -0700309 void Slt(Register rd, Register rs, Register rt);
310 void Sltu(Register rd, Register rs, Register rt);
311 void Slti(Register rt, Register rs, uint16_t imm16);
312 void Sltiu(Register rt, Register rs, uint16_t imm16);
313
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700314 // Branches and jumps to immediate offsets/addresses do not take care of their
315 // delay/forbidden slots and generally should not be used directly. This applies
316 // to the following R2 and R6 branch/jump instructions with imm16, imm21, addr26
317 // offsets/addresses.
318 // Use branches/jumps to labels instead.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200319 void B(uint16_t imm16);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700320 void Bal(uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200321 void Beq(Register rs, Register rt, uint16_t imm16);
322 void Bne(Register rs, Register rt, uint16_t imm16);
323 void Beqz(Register rt, uint16_t imm16);
324 void Bnez(Register rt, uint16_t imm16);
325 void Bltz(Register rt, uint16_t imm16);
326 void Bgez(Register rt, uint16_t imm16);
327 void Blez(Register rt, uint16_t imm16);
328 void Bgtz(Register rt, uint16_t imm16);
Chris Larsenb74353a2015-11-20 09:07:09 -0800329 void Bc1f(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800330 void Bc1f(int cc, uint16_t imm16); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800331 void Bc1t(uint16_t imm16); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800332 void Bc1t(int cc, uint16_t imm16); // R2
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200333 void J(uint32_t addr26);
334 void Jal(uint32_t addr26);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700335 // Jalr() and Jr() fill their delay slots when reordering is enabled.
336 // When reordering is disabled, the delay slots must be filled manually.
337 // You may use NopIfNoReordering() to fill them when reordering is disabled.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200338 void Jalr(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700339 void Jalr(Register rs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200340 void Jr(Register rs);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700341 // Nal() does not fill its delay slot. It must be filled manually.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200342 void Nal();
343 void Auipc(Register rs, uint16_t imm16); // R6
344 void Addiupc(Register rs, uint32_t imm19); // R6
345 void Bc(uint32_t imm26); // R6
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700346 void Balc(uint32_t imm26); // R6
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200347 void Jic(Register rt, uint16_t imm16); // R6
348 void Jialc(Register rt, uint16_t imm16); // R6
349 void Bltc(Register rs, Register rt, uint16_t imm16); // R6
350 void Bltzc(Register rt, uint16_t imm16); // R6
351 void Bgtzc(Register rt, uint16_t imm16); // R6
352 void Bgec(Register rs, Register rt, uint16_t imm16); // R6
353 void Bgezc(Register rt, uint16_t imm16); // R6
354 void Blezc(Register rt, uint16_t imm16); // R6
355 void Bltuc(Register rs, Register rt, uint16_t imm16); // R6
356 void Bgeuc(Register rs, Register rt, uint16_t imm16); // R6
357 void Beqc(Register rs, Register rt, uint16_t imm16); // R6
358 void Bnec(Register rs, Register rt, uint16_t imm16); // R6
359 void Beqzc(Register rs, uint32_t imm21); // R6
360 void Bnezc(Register rs, uint32_t imm21); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800361 void Bc1eqz(FRegister ft, uint16_t imm16); // R6
362 void Bc1nez(FRegister ft, uint16_t imm16); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700363
364 void AddS(FRegister fd, FRegister fs, FRegister ft);
365 void SubS(FRegister fd, FRegister fs, FRegister ft);
366 void MulS(FRegister fd, FRegister fs, FRegister ft);
367 void DivS(FRegister fd, FRegister fs, FRegister ft);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200368 void AddD(FRegister fd, FRegister fs, FRegister ft);
369 void SubD(FRegister fd, FRegister fs, FRegister ft);
370 void MulD(FRegister fd, FRegister fs, FRegister ft);
371 void DivD(FRegister fd, FRegister fs, FRegister ft);
Chris Larsenb74353a2015-11-20 09:07:09 -0800372 void SqrtS(FRegister fd, FRegister fs);
373 void SqrtD(FRegister fd, FRegister fs);
374 void AbsS(FRegister fd, FRegister fs);
375 void AbsD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700376 void MovS(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200377 void MovD(FRegister fd, FRegister fs);
378 void NegS(FRegister fd, FRegister fs);
379 void NegD(FRegister fd, FRegister fs);
380
Chris Larsenb74353a2015-11-20 09:07:09 -0800381 void CunS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800382 void CunS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800383 void CeqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800384 void CeqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800385 void CueqS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800386 void CueqS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800387 void ColtS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800388 void ColtS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800389 void CultS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800390 void CultS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800391 void ColeS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800392 void ColeS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800393 void CuleS(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800394 void CuleS(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800395 void CunD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800396 void CunD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800397 void CeqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800398 void CeqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800399 void CueqD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800400 void CueqD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800401 void ColtD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800402 void ColtD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800403 void CultD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800404 void CultD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800405 void ColeD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800406 void ColeD(int cc, FRegister fs, FRegister ft); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800407 void CuleD(FRegister fs, FRegister ft); // R2
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800408 void CuleD(int cc, FRegister fs, FRegister ft); // R2
409 void CmpUnS(FRegister fd, FRegister fs, FRegister ft); // R6
410 void CmpEqS(FRegister fd, FRegister fs, FRegister ft); // R6
411 void CmpUeqS(FRegister fd, FRegister fs, FRegister ft); // R6
412 void CmpLtS(FRegister fd, FRegister fs, FRegister ft); // R6
413 void CmpUltS(FRegister fd, FRegister fs, FRegister ft); // R6
414 void CmpLeS(FRegister fd, FRegister fs, FRegister ft); // R6
415 void CmpUleS(FRegister fd, FRegister fs, FRegister ft); // R6
416 void CmpOrS(FRegister fd, FRegister fs, FRegister ft); // R6
417 void CmpUneS(FRegister fd, FRegister fs, FRegister ft); // R6
418 void CmpNeS(FRegister fd, FRegister fs, FRegister ft); // R6
419 void CmpUnD(FRegister fd, FRegister fs, FRegister ft); // R6
420 void CmpEqD(FRegister fd, FRegister fs, FRegister ft); // R6
421 void CmpUeqD(FRegister fd, FRegister fs, FRegister ft); // R6
422 void CmpLtD(FRegister fd, FRegister fs, FRegister ft); // R6
423 void CmpUltD(FRegister fd, FRegister fs, FRegister ft); // R6
424 void CmpLeD(FRegister fd, FRegister fs, FRegister ft); // R6
425 void CmpUleD(FRegister fd, FRegister fs, FRegister ft); // R6
426 void CmpOrD(FRegister fd, FRegister fs, FRegister ft); // R6
427 void CmpUneD(FRegister fd, FRegister fs, FRegister ft); // R6
428 void CmpNeD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800429 void Movf(Register rd, Register rs, int cc = 0); // R2
430 void Movt(Register rd, Register rs, int cc = 0); // R2
431 void MovfS(FRegister fd, FRegister fs, int cc = 0); // R2
432 void MovfD(FRegister fd, FRegister fs, int cc = 0); // R2
433 void MovtS(FRegister fd, FRegister fs, int cc = 0); // R2
434 void MovtD(FRegister fd, FRegister fs, int cc = 0); // R2
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700435 void MovzS(FRegister fd, FRegister fs, Register rt); // R2
436 void MovzD(FRegister fd, FRegister fs, Register rt); // R2
437 void MovnS(FRegister fd, FRegister fs, Register rt); // R2
438 void MovnD(FRegister fd, FRegister fs, Register rt); // R2
Chris Larsenb74353a2015-11-20 09:07:09 -0800439 void SelS(FRegister fd, FRegister fs, FRegister ft); // R6
440 void SelD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700441 void SeleqzS(FRegister fd, FRegister fs, FRegister ft); // R6
442 void SeleqzD(FRegister fd, FRegister fs, FRegister ft); // R6
443 void SelnezS(FRegister fd, FRegister fs, FRegister ft); // R6
444 void SelnezD(FRegister fd, FRegister fs, FRegister ft); // R6
Chris Larsenb74353a2015-11-20 09:07:09 -0800445 void ClassS(FRegister fd, FRegister fs); // R6
446 void ClassD(FRegister fd, FRegister fs); // R6
447 void MinS(FRegister fd, FRegister fs, FRegister ft); // R6
448 void MinD(FRegister fd, FRegister fs, FRegister ft); // R6
449 void MaxS(FRegister fd, FRegister fs, FRegister ft); // R6
450 void MaxD(FRegister fd, FRegister fs, FRegister ft); // R6
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800451
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800452 void TruncLS(FRegister fd, FRegister fs); // R2+, FR=1
453 void TruncLD(FRegister fd, FRegister fs); // R2+, FR=1
454 void TruncWS(FRegister fd, FRegister fs);
455 void TruncWD(FRegister fd, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200456 void Cvtsw(FRegister fd, FRegister fs);
457 void Cvtdw(FRegister fd, FRegister fs);
458 void Cvtsd(FRegister fd, FRegister fs);
459 void Cvtds(FRegister fd, FRegister fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800460 void Cvtsl(FRegister fd, FRegister fs); // R2+, FR=1
461 void Cvtdl(FRegister fd, FRegister fs); // R2+, FR=1
Chris Larsenb74353a2015-11-20 09:07:09 -0800462 void FloorWS(FRegister fd, FRegister fs);
463 void FloorWD(FRegister fd, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700464
465 void Mfc1(Register rt, FRegister fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200466 void Mtc1(Register rt, FRegister fs);
467 void Mfhc1(Register rt, FRegister fs);
468 void Mthc1(Register rt, FRegister fs);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800469 void MoveFromFpuHigh(Register rt, FRegister fs);
470 void MoveToFpuHigh(Register rt, FRegister fs);
jeffhao7fbee072012-08-24 17:56:54 -0700471 void Lwc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200472 void Ldc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700473 void Swc1(FRegister ft, Register rs, uint16_t imm16);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200474 void Sdc1(FRegister ft, Register rs, uint16_t imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700475
476 void Break();
jeffhao07030602012-09-26 14:33:14 -0700477 void Nop();
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700478 void NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200479 void Move(Register rd, Register rs);
480 void Clear(Register rd);
481 void Not(Register rd, Register rs);
jeffhao7fbee072012-08-24 17:56:54 -0700482
Lena Djokic0758ae72017-05-23 11:06:23 +0200483 // MSA instructions.
484 void AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
485 void OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
486 void NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
487 void XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt);
488
489 void AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
490 void AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
491 void AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
492 void AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
493 void SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
494 void SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
495 void SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
496 void SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
497 void MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
498 void MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
499 void MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
500 void MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
501 void Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
502 void Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
503 void Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
504 void Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
505 void Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
506 void Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
507 void Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
508 void Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
509 void Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
510 void Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
511 void Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
512 void Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
513 void Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
514 void Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
515 void Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
516 void Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
517 void Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
518 void Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
519 void Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
520 void Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
521 void Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
522 void Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
523 void Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
524 void Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
525 void Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
526 void Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
527 void Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
528 void Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
529 void Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
530 void Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
531 void Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
532 void Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
533 void Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
534 void Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
535 void Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
536 void Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
537 void Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
538 void Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
539 void Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
540 void Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
541 void Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
542 void Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
543 void Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
544 void Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
545 void Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
546 void Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
547 void Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
548 void Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
549 void Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
550 void Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
551 void Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
552 void Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
553
554 void FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
555 void FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
556 void FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
557 void FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
558 void FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
559 void FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
560 void FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
561 void FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
562 void FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
563 void FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
564 void FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
565 void FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
566
567 void Ffint_sW(VectorRegister wd, VectorRegister ws);
568 void Ffint_sD(VectorRegister wd, VectorRegister ws);
569 void Ftint_sW(VectorRegister wd, VectorRegister ws);
570 void Ftint_sD(VectorRegister wd, VectorRegister ws);
571
572 void SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
573 void SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
574 void SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
575 void SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
576 void SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
577 void SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
578 void SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
579 void SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
580 void SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
581 void SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
582 void SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
583 void SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
584
585 // Immediate shift instructions, where shamtN denotes shift amount (must be between 0 and 2^N-1).
586 void SlliB(VectorRegister wd, VectorRegister ws, int shamt3);
587 void SlliH(VectorRegister wd, VectorRegister ws, int shamt4);
588 void SlliW(VectorRegister wd, VectorRegister ws, int shamt5);
589 void SlliD(VectorRegister wd, VectorRegister ws, int shamt6);
590 void SraiB(VectorRegister wd, VectorRegister ws, int shamt3);
591 void SraiH(VectorRegister wd, VectorRegister ws, int shamt4);
592 void SraiW(VectorRegister wd, VectorRegister ws, int shamt5);
593 void SraiD(VectorRegister wd, VectorRegister ws, int shamt6);
594 void SrliB(VectorRegister wd, VectorRegister ws, int shamt3);
595 void SrliH(VectorRegister wd, VectorRegister ws, int shamt4);
596 void SrliW(VectorRegister wd, VectorRegister ws, int shamt5);
597 void SrliD(VectorRegister wd, VectorRegister ws, int shamt6);
598
599 void MoveV(VectorRegister wd, VectorRegister ws);
600 void SplatiB(VectorRegister wd, VectorRegister ws, int n4);
601 void SplatiH(VectorRegister wd, VectorRegister ws, int n3);
602 void SplatiW(VectorRegister wd, VectorRegister ws, int n2);
603 void SplatiD(VectorRegister wd, VectorRegister ws, int n1);
Lena Djokic3309c012017-10-13 14:34:32 +0200604 void Copy_sB(Register rd, VectorRegister ws, int n4);
605 void Copy_sH(Register rd, VectorRegister ws, int n3);
606 void Copy_sW(Register rd, VectorRegister ws, int n2);
607 void Copy_uB(Register rd, VectorRegister ws, int n4);
608 void Copy_uH(Register rd, VectorRegister ws, int n3);
609 void InsertB(VectorRegister wd, Register rs, int n4);
610 void InsertH(VectorRegister wd, Register rs, int n3);
611 void InsertW(VectorRegister wd, Register rs, int n2);
Lena Djokic0758ae72017-05-23 11:06:23 +0200612 void FillB(VectorRegister wd, Register rs);
613 void FillH(VectorRegister wd, Register rs);
614 void FillW(VectorRegister wd, Register rs);
615
616 void LdiB(VectorRegister wd, int imm8);
617 void LdiH(VectorRegister wd, int imm10);
618 void LdiW(VectorRegister wd, int imm10);
619 void LdiD(VectorRegister wd, int imm10);
620 void LdB(VectorRegister wd, Register rs, int offset);
621 void LdH(VectorRegister wd, Register rs, int offset);
622 void LdW(VectorRegister wd, Register rs, int offset);
623 void LdD(VectorRegister wd, Register rs, int offset);
624 void StB(VectorRegister wd, Register rs, int offset);
625 void StH(VectorRegister wd, Register rs, int offset);
626 void StW(VectorRegister wd, Register rs, int offset);
627 void StD(VectorRegister wd, Register rs, int offset);
628
Lena Djokic3309c012017-10-13 14:34:32 +0200629 void IlvlB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
630 void IlvlH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
631 void IlvlW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
632 void IlvlD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Lena Djokic0758ae72017-05-23 11:06:23 +0200633 void IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
634 void IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
635 void IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
636 void IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Lena Djokic3309c012017-10-13 14:34:32 +0200637 void IlvevB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
638 void IlvevH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
639 void IlvevW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
640 void IlvevD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
641 void IlvodB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
642 void IlvodH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
643 void IlvodW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
644 void IlvodD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
Lena Djokic0758ae72017-05-23 11:06:23 +0200645
Lena Djokicb3d79e42017-07-25 11:20:52 +0200646 void MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
647 void MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
648 void MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
649 void MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
650 void MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt);
651 void MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
652 void MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
653 void MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
654 void FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
655 void FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
656 void FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
657 void FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
658
Lena Djokic3309c012017-10-13 14:34:32 +0200659 void Hadd_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
660 void Hadd_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
661 void Hadd_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
662 void Hadd_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt);
663 void Hadd_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt);
664 void Hadd_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt);
665
Lena Djokic51765b02017-06-22 13:49:59 +0200666 // Helper for replicating floating point value in all destination elements.
667 void ReplicateFPToVectorRegister(VectorRegister dst, FRegister src, bool is_double);
668
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200669 // Higher level composite instructions.
670 void LoadConst32(Register rd, int32_t value);
671 void LoadConst64(Register reg_hi, Register reg_lo, int64_t value);
672 void LoadDConst64(FRegister rd, int64_t value, Register temp);
673 void LoadSConst32(FRegister r, int32_t value, Register temp);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200674 void Addiu32(Register rt, Register rs, int32_t value, Register rtmp = AT);
675
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200676 void Bind(MipsLabel* label);
Alexey Frunze0cab6562017-07-25 15:19:36 -0700677 // When `is_bare` is false, the branches will promote to long (if the range
678 // of the individual branch instruction is insufficient) and the delay/
679 // forbidden slots will be taken care of.
680 // Use `is_bare = false` when the branch target may be out of reach of the
681 // individual branch instruction. IOW, this is for general purpose use.
682 //
683 // When `is_bare` is true, just the branch instructions will be generated
684 // leaving delay/forbidden slot filling up to the caller and the branches
685 // won't promote to long if the range is insufficient (you'll get a
686 // compilation error when the range is exceeded).
687 // Use `is_bare = true` when the branch target is known to be within reach
688 // of the individual branch instruction. This is intended for small local
689 // optimizations around delay/forbidden slots.
690 // Also prefer using `is_bare = true` if the code near the branch is to be
691 // patched or analyzed at run time (e.g. introspection) to
692 // - show the intent and
693 // - fail during compilation rather than during patching/execution if the
694 // bare branch range is insufficent but the code size and layout are
695 // expected to remain unchanged
696 //
697 // R2 branches with delay slots that are also available on R6.
698 // On R6 when `is_bare` is false these convert to equivalent R6 compact
699 // branches (to reduce code size). On R2 or when `is_bare` is true they
700 // remain R2 branches with delay slots.
701 void B(MipsLabel* label, bool is_bare = false);
702 void Bal(MipsLabel* label, bool is_bare = false);
703 void Beq(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
704 void Bne(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
705 void Beqz(Register rt, MipsLabel* label, bool is_bare = false);
706 void Bnez(Register rt, MipsLabel* label, bool is_bare = false);
707 void Bltz(Register rt, MipsLabel* label, bool is_bare = false);
708 void Bgez(Register rt, MipsLabel* label, bool is_bare = false);
709 void Blez(Register rt, MipsLabel* label, bool is_bare = false);
710 void Bgtz(Register rt, MipsLabel* label, bool is_bare = false);
711 void Blt(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
712 void Bge(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
713 void Bltu(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
714 void Bgeu(Register rs, Register rt, MipsLabel* label, bool is_bare = false);
715 // R2-only branches with delay slots.
716 void Bc1f(MipsLabel* label, bool is_bare = false); // R2
717 void Bc1f(int cc, MipsLabel* label, bool is_bare = false); // R2
718 void Bc1t(MipsLabel* label, bool is_bare = false); // R2
719 void Bc1t(int cc, MipsLabel* label, bool is_bare = false); // R2
720 // R6-only compact branches without delay/forbidden slots.
721 void Bc(MipsLabel* label, bool is_bare = false); // R6
722 void Balc(MipsLabel* label, bool is_bare = false); // R6
723 // R6-only compact branches with forbidden slots.
724 void Beqc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
725 void Bnec(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
726 void Beqzc(Register rt, MipsLabel* label, bool is_bare = false); // R6
727 void Bnezc(Register rt, MipsLabel* label, bool is_bare = false); // R6
728 void Bltzc(Register rt, MipsLabel* label, bool is_bare = false); // R6
729 void Bgezc(Register rt, MipsLabel* label, bool is_bare = false); // R6
730 void Blezc(Register rt, MipsLabel* label, bool is_bare = false); // R6
731 void Bgtzc(Register rt, MipsLabel* label, bool is_bare = false); // R6
732 void Bltc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
733 void Bgec(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
734 void Bltuc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
735 void Bgeuc(Register rs, Register rt, MipsLabel* label, bool is_bare = false); // R6
736 // R6-only branches with delay slots.
737 void Bc1eqz(FRegister ft, MipsLabel* label, bool is_bare = false); // R6
738 void Bc1nez(FRegister ft, MipsLabel* label, bool is_bare = false); // R6
jeffhao7fbee072012-08-24 17:56:54 -0700739
740 void EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset, size_t size);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700741 void AdjustBaseAndOffset(Register& base,
742 int32_t& offset,
743 bool is_doubleword,
744 bool is_float = false);
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200745 void AdjustBaseOffsetAndElementSizeShift(Register& base,
746 int32_t& offset,
747 int& element_size_shift);
Alexey Frunze2923db72016-08-20 01:55:47 -0700748
749 private:
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100750 // This will be used as an argument for loads/stores
751 // when there is no need for implicit null checks.
Alexey Frunze2923db72016-08-20 01:55:47 -0700752 struct NoImplicitNullChecker {
Tijana Jakovljevic57433862017-01-17 16:59:03 +0100753 void operator()() const {}
Alexey Frunze2923db72016-08-20 01:55:47 -0700754 };
755
756 public:
757 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunzef58b2482016-09-02 22:14:06 -0700758 void StoreConstToOffset(StoreOperandType type,
759 int64_t value,
760 Register base,
761 int32_t offset,
762 Register temp,
763 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
764 // We permit `base` and `temp` to coincide (however, we check that neither is AT),
765 // in which case the `base` register may be overwritten in the process.
Alexey Frunze2923db72016-08-20 01:55:47 -0700766 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 -0700767 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
Alexey Frunze2923db72016-08-20 01:55:47 -0700768 uint32_t low = Low32Bits(value);
769 uint32_t high = High32Bits(value);
Alexey Frunzef58b2482016-09-02 22:14:06 -0700770 Register reg;
771 // If the adjustment left `base` unchanged and equal to `temp`, we can't use `temp`
772 // to load and hold the value but we can use AT instead as AT hasn't been used yet.
773 // Otherwise, `temp` can be used for the value. And if `temp` is the same as the
774 // original `base` (that is, `base` prior to the adjustment), the original `base`
775 // register will be overwritten.
776 if (base == temp) {
777 temp = AT;
Alexey Frunze2923db72016-08-20 01:55:47 -0700778 }
Alexey Frunzef58b2482016-09-02 22:14:06 -0700779 if (low == 0) {
780 reg = ZERO;
Alexey Frunze2923db72016-08-20 01:55:47 -0700781 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -0700782 reg = temp;
783 LoadConst32(reg, low);
784 }
785 switch (type) {
786 case kStoreByte:
787 Sb(reg, base, offset);
788 break;
789 case kStoreHalfword:
790 Sh(reg, base, offset);
791 break;
792 case kStoreWord:
793 Sw(reg, base, offset);
794 break;
795 case kStoreDoubleword:
796 Sw(reg, base, offset);
797 null_checker();
798 if (high == 0) {
799 reg = ZERO;
800 } else {
801 reg = temp;
802 if (high != low) {
803 LoadConst32(reg, high);
804 }
805 }
806 Sw(reg, base, offset + kMipsWordSize);
807 break;
808 default:
809 LOG(FATAL) << "UNREACHABLE";
810 }
811 if (type != kStoreDoubleword) {
812 null_checker();
Alexey Frunze2923db72016-08-20 01:55:47 -0700813 }
814 }
815
816 template <typename ImplicitNullChecker = NoImplicitNullChecker>
817 void LoadFromOffset(LoadOperandType type,
818 Register reg,
819 Register base,
820 int32_t offset,
821 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
822 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kLoadDoubleword));
823 switch (type) {
824 case kLoadSignedByte:
825 Lb(reg, base, offset);
826 break;
827 case kLoadUnsignedByte:
828 Lbu(reg, base, offset);
829 break;
830 case kLoadSignedHalfword:
831 Lh(reg, base, offset);
832 break;
833 case kLoadUnsignedHalfword:
834 Lhu(reg, base, offset);
835 break;
836 case kLoadWord:
837 Lw(reg, base, offset);
838 break;
839 case kLoadDoubleword:
840 if (reg == base) {
841 // This will clobber the base when loading the lower register. Since we have to load the
842 // higher register as well, this will fail. Solution: reverse the order.
843 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
844 null_checker();
845 Lw(reg, base, offset);
846 } else {
847 Lw(reg, base, offset);
848 null_checker();
849 Lw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
850 }
851 break;
852 default:
853 LOG(FATAL) << "UNREACHABLE";
854 }
855 if (type != kLoadDoubleword) {
856 null_checker();
857 }
858 }
859
860 template <typename ImplicitNullChecker = NoImplicitNullChecker>
861 void LoadSFromOffset(FRegister reg,
862 Register base,
863 int32_t offset,
864 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
865 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
866 Lwc1(reg, base, offset);
867 null_checker();
868 }
869
870 template <typename ImplicitNullChecker = NoImplicitNullChecker>
871 void LoadDFromOffset(FRegister reg,
872 Register base,
873 int32_t offset,
874 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
875 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
876 if (IsAligned<kMipsDoublewordSize>(offset)) {
877 Ldc1(reg, base, offset);
878 null_checker();
879 } else {
880 if (Is32BitFPU()) {
881 Lwc1(reg, base, offset);
882 null_checker();
883 Lwc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
884 } else {
885 // 64-bit FPU.
886 Lwc1(reg, base, offset);
887 null_checker();
888 Lw(T8, base, offset + kMipsWordSize);
889 Mthc1(T8, reg);
890 }
891 }
892 }
893
894 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200895 void LoadQFromOffset(FRegister reg,
896 Register base,
897 int32_t offset,
898 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
899 int element_size_shift = -1;
900 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
901 switch (element_size_shift) {
902 case TIMES_1: LdB(static_cast<VectorRegister>(reg), base, offset); break;
903 case TIMES_2: LdH(static_cast<VectorRegister>(reg), base, offset); break;
904 case TIMES_4: LdW(static_cast<VectorRegister>(reg), base, offset); break;
905 case TIMES_8: LdD(static_cast<VectorRegister>(reg), base, offset); break;
906 default:
907 LOG(FATAL) << "UNREACHABLE";
908 }
909 null_checker();
910 }
911
912 template <typename ImplicitNullChecker = NoImplicitNullChecker>
Alexey Frunze2923db72016-08-20 01:55:47 -0700913 void StoreToOffset(StoreOperandType type,
914 Register reg,
915 Register base,
916 int32_t offset,
917 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
918 // Must not use AT as `reg`, so as not to overwrite the value being stored
919 // with the adjusted `base`.
920 CHECK_NE(reg, AT);
921 AdjustBaseAndOffset(base, offset, /* is_doubleword */ (type == kStoreDoubleword));
922 switch (type) {
923 case kStoreByte:
924 Sb(reg, base, offset);
925 break;
926 case kStoreHalfword:
927 Sh(reg, base, offset);
928 break;
929 case kStoreWord:
930 Sw(reg, base, offset);
931 break;
932 case kStoreDoubleword:
933 CHECK_NE(reg, base);
934 CHECK_NE(static_cast<Register>(reg + 1), base);
935 Sw(reg, base, offset);
936 null_checker();
937 Sw(static_cast<Register>(reg + 1), base, offset + kMipsWordSize);
938 break;
939 default:
940 LOG(FATAL) << "UNREACHABLE";
941 }
942 if (type != kStoreDoubleword) {
943 null_checker();
944 }
945 }
946
947 template <typename ImplicitNullChecker = NoImplicitNullChecker>
948 void StoreSToOffset(FRegister reg,
949 Register base,
950 int32_t offset,
951 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
952 AdjustBaseAndOffset(base, offset, /* is_doubleword */ false, /* is_float */ true);
953 Swc1(reg, base, offset);
954 null_checker();
955 }
956
957 template <typename ImplicitNullChecker = NoImplicitNullChecker>
958 void StoreDToOffset(FRegister reg,
959 Register base,
960 int32_t offset,
961 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
962 AdjustBaseAndOffset(base, offset, /* is_doubleword */ true, /* is_float */ true);
963 if (IsAligned<kMipsDoublewordSize>(offset)) {
964 Sdc1(reg, base, offset);
965 null_checker();
966 } else {
967 if (Is32BitFPU()) {
968 Swc1(reg, base, offset);
969 null_checker();
970 Swc1(static_cast<FRegister>(reg + 1), base, offset + kMipsWordSize);
971 } else {
972 // 64-bit FPU.
973 Mfhc1(T8, reg);
974 Swc1(reg, base, offset);
975 null_checker();
976 Sw(T8, base, offset + kMipsWordSize);
977 }
978 }
979 }
980
Lena Djokic2e0a7e52017-07-06 11:55:24 +0200981 template <typename ImplicitNullChecker = NoImplicitNullChecker>
982 void StoreQToOffset(FRegister reg,
983 Register base,
984 int32_t offset,
985 ImplicitNullChecker null_checker = NoImplicitNullChecker()) {
986 int element_size_shift = -1;
987 AdjustBaseOffsetAndElementSizeShift(base, offset, element_size_shift);
988 switch (element_size_shift) {
989 case TIMES_1: StB(static_cast<VectorRegister>(reg), base, offset); break;
990 case TIMES_2: StH(static_cast<VectorRegister>(reg), base, offset); break;
991 case TIMES_4: StW(static_cast<VectorRegister>(reg), base, offset); break;
992 case TIMES_8: StD(static_cast<VectorRegister>(reg), base, offset); break;
993 default:
994 LOG(FATAL) << "UNREACHABLE";
995 }
996 null_checker();
997 }
998
jeffhao7fbee072012-08-24 17:56:54 -0700999 void LoadFromOffset(LoadOperandType type, Register reg, Register base, int32_t offset);
1000 void LoadSFromOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001001 void LoadDFromOffset(FRegister reg, Register base, int32_t offset);
Lena Djokic2e0a7e52017-07-06 11:55:24 +02001002 void LoadQFromOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -07001003 void StoreToOffset(StoreOperandType type, Register reg, Register base, int32_t offset);
Goran Jakovljevicff734982015-08-24 12:58:55 +00001004 void StoreSToOffset(FRegister reg, Register base, int32_t offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001005 void StoreDToOffset(FRegister reg, Register base, int32_t offset);
Lena Djokic2e0a7e52017-07-06 11:55:24 +02001006 void StoreQToOffset(FRegister reg, Register base, int32_t offset);
jeffhao7fbee072012-08-24 17:56:54 -07001007
jeffhao7fbee072012-08-24 17:56:54 -07001008 // Emit data (e.g. encoded instruction or immediate) to the instruction stream.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001009 void Emit(uint32_t value);
1010
1011 // Push/pop composite routines.
1012 void Push(Register rs);
1013 void Pop(Register rd);
1014 void PopAndReturn(Register rd, Register rt);
jeffhao7fbee072012-08-24 17:56:54 -07001015
Alexey Frunzec061de12017-02-14 13:27:23 -08001016 //
1017 // Heap poisoning.
1018 //
1019
1020 // Poison a heap reference contained in `src` and store it in `dst`.
1021 void PoisonHeapReference(Register dst, Register src) {
1022 // dst = -src.
1023 Subu(dst, ZERO, src);
1024 }
1025 // Poison a heap reference contained in `reg`.
1026 void PoisonHeapReference(Register reg) {
1027 // reg = -reg.
1028 PoisonHeapReference(reg, reg);
1029 }
1030 // Unpoison a heap reference contained in `reg`.
1031 void UnpoisonHeapReference(Register reg) {
1032 // reg = -reg.
1033 Subu(reg, ZERO, reg);
1034 }
1035 // Poison a heap reference contained in `reg` if heap poisoning is enabled.
1036 void MaybePoisonHeapReference(Register reg) {
1037 if (kPoisonHeapReferences) {
1038 PoisonHeapReference(reg);
1039 }
1040 }
1041 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
1042 void MaybeUnpoisonHeapReference(Register reg) {
1043 if (kPoisonHeapReferences) {
1044 UnpoisonHeapReference(reg);
1045 }
1046 }
1047
Andreas Gampe85b62f22015-09-09 13:15:38 -07001048 void Bind(Label* label) OVERRIDE {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001049 Bind(down_cast<MipsLabel*>(label));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001050 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001051 void Jump(Label* label ATTRIBUTE_UNUSED) OVERRIDE {
1052 UNIMPLEMENTED(FATAL) << "Do not use Jump for MIPS";
Andreas Gampe85b62f22015-09-09 13:15:38 -07001053 }
1054
Igor Murashkinae7ff922016-10-06 14:59:19 -07001055 // Don't warn about a different virtual Bind/Jump in the base class.
1056 using JNIBase::Bind;
1057 using JNIBase::Jump;
1058
1059 // Create a new label that can be used with Jump/Bind calls.
1060 std::unique_ptr<JNIMacroLabel> CreateLabel() OVERRIDE {
1061 LOG(FATAL) << "Not implemented on MIPS32";
1062 UNREACHABLE();
1063 }
1064 // Emit an unconditional jump to the label.
1065 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
1066 LOG(FATAL) << "Not implemented on MIPS32";
1067 UNREACHABLE();
1068 }
1069 // Emit a conditional jump to the label by applying a unary condition test to the register.
1070 void Jump(JNIMacroLabel* label ATTRIBUTE_UNUSED,
1071 JNIMacroUnaryCondition cond ATTRIBUTE_UNUSED,
1072 ManagedRegister test ATTRIBUTE_UNUSED) OVERRIDE {
1073 LOG(FATAL) << "Not implemented on MIPS32";
1074 UNREACHABLE();
1075 }
1076
1077 // Code at this offset will serve as the target for the Jump call.
1078 void Bind(JNIMacroLabel* label ATTRIBUTE_UNUSED) OVERRIDE {
1079 LOG(FATAL) << "Not implemented on MIPS32";
1080 UNREACHABLE();
1081 }
1082
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001083 // Create a new literal with a given value.
1084 // NOTE: Force the template parameter to be explicitly specified.
1085 template <typename T>
1086 Literal* NewLiteral(typename Identity<T>::type value) {
1087 static_assert(std::is_integral<T>::value, "T must be an integral type.");
1088 return NewLiteral(sizeof(value), reinterpret_cast<const uint8_t*>(&value));
1089 }
1090
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07001091 // Load label address using PC-relative addressing.
1092 // To be used with data labels in the literal / jump table area only and not
1093 // with regular code labels.
1094 //
1095 // For R6 base_reg must be ZERO.
1096 //
1097 // On R2 there are two possible uses w.r.t. base_reg:
1098 //
1099 // - base_reg = ZERO:
1100 // The NAL instruction will be generated as part of the load and it will
1101 // clobber the RA register.
1102 //
1103 // - base_reg != ZERO:
1104 // The RA-clobbering NAL instruction won't be generated as part of the load.
1105 // The label pc_rel_base_label_ must be bound (with BindPcRelBaseLabel())
1106 // and base_reg must hold the address of the label. Example:
1107 // __ Nal();
1108 // __ Move(S3, RA);
1109 // __ BindPcRelBaseLabel(); // S3 holds the address of pc_rel_base_label_.
1110 // __ LoadLabelAddress(A0, S3, label1);
1111 // __ LoadLabelAddress(A1, S3, label2);
1112 // __ LoadLiteral(V0, S3, literal1);
1113 // __ LoadLiteral(V1, S3, literal2);
Alexey Frunze96b66822016-09-10 02:32:44 -07001114 void LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label);
1115
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001116 // Create a new literal with the given data.
1117 Literal* NewLiteral(size_t size, const uint8_t* data);
1118
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07001119 // Load literal using PC-relative addressing.
1120 // See the above comments for LoadLabelAddress() on the value of base_reg.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001121 void LoadLiteral(Register dest_reg, Register base_reg, Literal* literal);
1122
Alexey Frunze96b66822016-09-10 02:32:44 -07001123 // Create a jump table for the given labels that will be emitted when finalizing.
1124 // When the table is emitted, offsets will be relative to the location of the table.
1125 // The table location is determined by the location of its label (the label precedes
1126 // the table data) and should be loaded using LoadLabelAddress().
1127 JumpTable* CreateJumpTable(std::vector<MipsLabel*>&& labels);
1128
jeffhao7fbee072012-08-24 17:56:54 -07001129 //
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001130 // Overridden common assembler high-level functionality.
jeffhao7fbee072012-08-24 17:56:54 -07001131 //
1132
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001133 // Emit code that will create an activation on the stack.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001134 void BuildFrame(size_t frame_size,
1135 ManagedRegister method_reg,
Vladimir Marko32248382016-05-19 10:37:24 +01001136 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001137 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001138
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001139 // Emit code that will remove an activation from the stack.
Roland Levillain0d127e12017-07-05 17:01:11 +01001140 void RemoveFrame(size_t frame_size,
1141 ArrayRef<const ManagedRegister> callee_save_regs,
1142 bool may_suspend) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001143
Ian Rogersdd7624d2014-03-14 17:43:00 -07001144 void IncreaseFrameSize(size_t adjust) OVERRIDE;
1145 void DecreaseFrameSize(size_t adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001146
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001147 // Store routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001148 void Store(FrameOffset offs, ManagedRegister msrc, size_t size) OVERRIDE;
1149 void StoreRef(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
1150 void StoreRawPtr(FrameOffset dest, ManagedRegister msrc) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001151
Ian Rogersdd7624d2014-03-14 17:43:00 -07001152 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001153
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001154 void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
1155 FrameOffset fr_offs,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001156 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001157
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001158 void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001159
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001160 void StoreSpanning(FrameOffset dest,
1161 ManagedRegister msrc,
1162 FrameOffset in_off,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001163 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001164
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001165 // Load routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001166 void Load(ManagedRegister mdest, FrameOffset src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001167
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001168 void LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001169
Mathieu Chartiere401d142015-04-22 13:56:20 -07001170 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001171
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001172 void LoadRef(ManagedRegister mdest,
1173 ManagedRegister base,
1174 MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001175 bool unpoison_reference) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001176
Ian Rogersdd7624d2014-03-14 17:43:00 -07001177 void LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001178
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001179 void LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001180
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001181 // Copying routines.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001182 void Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001183
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001184 void CopyRawPtrFromThread(FrameOffset fr_offs,
1185 ThreadOffset32 thr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001186 ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001187
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001188 void CopyRawPtrToThread(ThreadOffset32 thr_offs,
1189 FrameOffset fr_offs,
1190 ManagedRegister mscratch) OVERRIDE;
1191
Ian Rogersdd7624d2014-03-14 17:43:00 -07001192 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001193
Ian Rogersdd7624d2014-03-14 17:43:00 -07001194 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001195
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001196 void Copy(FrameOffset dest,
1197 ManagedRegister src_base,
1198 Offset src_offset,
1199 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001200 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001201
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001202 void Copy(ManagedRegister dest_base,
1203 Offset dest_offset,
1204 FrameOffset src,
1205 ManagedRegister mscratch,
Ian Rogersdd7624d2014-03-14 17:43:00 -07001206 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001207
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001208 void Copy(FrameOffset dest,
1209 FrameOffset src_base,
1210 Offset src_offset,
1211 ManagedRegister mscratch,
1212 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001213
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001214 void Copy(ManagedRegister dest,
1215 Offset dest_offset,
1216 ManagedRegister src,
1217 Offset src_offset,
1218 ManagedRegister mscratch,
1219 size_t size) OVERRIDE;
1220
1221 void Copy(FrameOffset dest,
1222 Offset dest_offset,
1223 FrameOffset src,
1224 Offset src_offset,
1225 ManagedRegister mscratch,
1226 size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001227
Ian Rogersdd7624d2014-03-14 17:43:00 -07001228 void MemoryBarrier(ManagedRegister) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001229
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001230 // Sign extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001231 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001232
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001233 // Zero extension.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001234 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001235
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001236 // Exploit fast access in managed code to Thread::Current().
Ian Rogersdd7624d2014-03-14 17:43:00 -07001237 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
1238 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001239
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001240 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001241 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001242 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001243 // null.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001244 void CreateHandleScopeEntry(ManagedRegister out_reg,
1245 FrameOffset handlescope_offset,
1246 ManagedRegister in_reg,
1247 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001248
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001249 // Set up out_off to hold a Object** into the handle scope, or to be null if the
jeffhao7fbee072012-08-24 17:56:54 -07001250 // value is null and null_allowed.
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001251 void CreateHandleScopeEntry(FrameOffset out_off,
1252 FrameOffset handlescope_offset,
1253 ManagedRegister mscratch,
1254 bool null_allowed) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001255
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001256 // src holds a handle scope entry (Object**) load this into dst.
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001257 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001258
1259 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
1260 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001261 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
1262 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001263
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001264 // Call to address held at [base+offset].
Ian Rogersdd7624d2014-03-14 17:43:00 -07001265 void Call(ManagedRegister base, Offset offset, ManagedRegister mscratch) OVERRIDE;
1266 void Call(FrameOffset base, Offset offset, ManagedRegister mscratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001267 void CallFromThread(ThreadOffset32 offset, ManagedRegister mscratch) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001268
jeffhao7fbee072012-08-24 17:56:54 -07001269 // Generate code to check if Thread::Current()->exception_ is non-null
1270 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -07001271 void ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) OVERRIDE;
jeffhao7fbee072012-08-24 17:56:54 -07001272
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001273 // Emit slow paths queued during assembly and promote short branches to long if needed.
1274 void FinalizeCode() OVERRIDE;
1275
1276 // Emit branches and finalize all instructions.
1277 void FinalizeInstructions(const MemoryRegion& region);
1278
1279 // Returns the (always-)current location of a label (can be used in class CodeGeneratorMIPS,
1280 // must be used instead of MipsLabel::GetPosition()).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001281 uint32_t GetLabelLocation(const MipsLabel* label) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001282
1283 // Get the final position of a label after local fixup based on the old position
1284 // recorded before FinalizeCode().
1285 uint32_t GetAdjustedPosition(uint32_t old_position);
1286
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001287 // R2 doesn't have PC-relative addressing, which we need to access literals. We simulate it by
1288 // reading the PC value into a general-purpose register with the NAL instruction and then loading
1289 // literals through this base register. The code generator calls this method (at most once per
1290 // method being compiled) to bind a label to the location for which the PC value is acquired.
1291 // The assembler then computes literal offsets relative to this label.
1292 void BindPcRelBaseLabel();
1293
Alexey Frunze06a46c42016-07-19 15:00:40 -07001294 // Returns the location of the label bound with BindPcRelBaseLabel().
1295 uint32_t GetPcRelBaseLabelLocation() const;
1296
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001297 // Note that PC-relative literal loads are handled as pseudo branches because they need very
1298 // similar relocation and may similarly expand in size to accomodate for larger offsets relative
1299 // to PC.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001300 enum BranchCondition {
1301 kCondLT,
1302 kCondGE,
1303 kCondLE,
1304 kCondGT,
1305 kCondLTZ,
1306 kCondGEZ,
1307 kCondLEZ,
1308 kCondGTZ,
1309 kCondEQ,
1310 kCondNE,
1311 kCondEQZ,
1312 kCondNEZ,
1313 kCondLTU,
1314 kCondGEU,
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001315 kCondF, // Floating-point predicate false.
1316 kCondT, // Floating-point predicate true.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001317 kUncond,
1318 };
1319 friend std::ostream& operator<<(std::ostream& os, const BranchCondition& rhs);
1320
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001321 // Enables or disables instruction reordering (IOW, automatic filling of delay slots)
1322 // similarly to ".set reorder" / ".set noreorder" in traditional MIPS assembly.
1323 // Returns the last state, which may be useful for temporary enabling/disabling of
1324 // reordering.
1325 bool SetReorder(bool enable);
1326
jeffhao7fbee072012-08-24 17:56:54 -07001327 private:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001328 // Description of the last instruction in terms of input and output registers.
1329 // Used to make the decision of moving the instruction into a delay slot.
1330 struct DelaySlot {
1331 DelaySlot();
1332 // Encoded instruction that may be used to fill the delay slot or 0
1333 // (0 conveniently represents NOP).
1334 uint32_t instruction_;
1335 // Mask of output GPRs for the instruction.
1336 uint32_t gpr_outs_mask_;
1337 // Mask of input GPRs for the instruction.
1338 uint32_t gpr_ins_mask_;
1339 // Mask of output FPRs for the instruction.
1340 uint32_t fpr_outs_mask_;
1341 // Mask of input FPRs for the instruction.
1342 uint32_t fpr_ins_mask_;
1343 // Mask of output FPU condition code flags for the instruction.
1344 uint32_t cc_outs_mask_;
1345 // Mask of input FPU condition code flags for the instruction.
1346 uint32_t cc_ins_mask_;
1347 // Branches never operate on the LO and HI registers, hence there's
1348 // no mask for LO and HI.
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001349
1350 // Label for patchable instructions to allow moving them into delay slots.
1351 MipsLabel* patcher_label_;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001352 };
1353
1354 // Delay slot finite state machine's (DS FSM's) state. The FSM state is updated
1355 // upon every new instruction and label generated. The FSM detects instructions
1356 // suitable for delay slots and immediately preceded with labels. These are target
1357 // instructions for branches. If an unconditional R2 branch does not get its delay
1358 // slot filled with the immediately preceding instruction, it may instead get the
1359 // slot filled with the target instruction (the branch will need its offset
1360 // incremented past the target instruction). We call this "absorption". The FSM
1361 // records PCs of the target instructions suitable for this optimization.
1362 enum DsFsmState {
1363 kExpectingLabel,
1364 kExpectingInstruction,
1365 kExpectingCommit
1366 };
1367 friend std::ostream& operator<<(std::ostream& os, const DsFsmState& rhs);
1368
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001369 class Branch {
1370 public:
1371 enum Type {
Alexey Frunze0cab6562017-07-25 15:19:36 -07001372 // R2 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001373 kUncondBranch,
1374 kCondBranch,
1375 kCall,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001376 // R2 short branches (can't be promoted to long), delay slots filled manually.
1377 kBareUncondBranch,
1378 kBareCondBranch,
1379 kBareCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001380 // R2 near label.
1381 kLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001382 // R2 near literal.
1383 kLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001384 // R2 long branches.
1385 kLongUncondBranch,
1386 kLongCondBranch,
1387 kLongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001388 // R2 far label.
1389 kFarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001390 // R2 far literal.
1391 kFarLiteral,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001392 // R6 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001393 kR6UncondBranch,
1394 kR6CondBranch,
1395 kR6Call,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001396 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
1397 kR6BareUncondBranch,
1398 kR6BareCondBranch,
1399 kR6BareCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001400 // R6 near label.
1401 kR6Label,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001402 // R6 near literal.
1403 kR6Literal,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001404 // R6 long branches.
1405 kR6LongUncondBranch,
1406 kR6LongCondBranch,
1407 kR6LongCall,
Alexey Frunze96b66822016-09-10 02:32:44 -07001408 // R6 far label.
1409 kR6FarLabel,
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001410 // R6 far literal.
1411 kR6FarLiteral,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001412 };
1413 // Bit sizes of offsets defined as enums to minimize chance of typos.
1414 enum OffsetBits {
1415 kOffset16 = 16,
1416 kOffset18 = 18,
1417 kOffset21 = 21,
1418 kOffset23 = 23,
1419 kOffset28 = 28,
1420 kOffset32 = 32,
1421 };
1422
1423 static constexpr uint32_t kUnresolved = 0xffffffff; // Unresolved target_
1424 static constexpr int32_t kMaxBranchLength = 32;
1425 static constexpr int32_t kMaxBranchSize = kMaxBranchLength * sizeof(uint32_t);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001426 // The following two instruction encodings can never legally occur in branch delay
1427 // slots and are used as markers.
1428 //
1429 // kUnfilledDelaySlot means that the branch may use either the preceding or the target
1430 // instruction to fill its delay slot (the latter is only possible with unconditional
1431 // R2 branches and is termed here as "absorption").
1432 static constexpr uint32_t kUnfilledDelaySlot = 0x10000000; // beq zero, zero, 0.
1433 // kUnfillableDelaySlot means that the branch cannot use an instruction (other than NOP)
1434 // to fill its delay slot. This is only used for unconditional R2 branches to prevent
1435 // absorption of the target instruction when reordering is disabled.
1436 static constexpr uint32_t kUnfillableDelaySlot = 0x13FF0000; // beq ra, ra, 0.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001437
1438 struct BranchInfo {
1439 // Branch length as a number of 4-byte-long instructions.
1440 uint32_t length;
1441 // Ordinal number (0-based) of the first (or the only) instruction that contains the branch's
1442 // PC-relative offset (or its most significant 16-bit half, which goes first).
1443 uint32_t instr_offset;
1444 // Different MIPS instructions with PC-relative offsets apply said offsets to slightly
1445 // different origins, e.g. to PC or PC+4. Encode the origin distance (as a number of 4-byte
1446 // instructions) from the instruction containing the offset.
1447 uint32_t pc_org;
1448 // How large (in bits) a PC-relative offset can be for a given type of branch (kR6CondBranch
Alexey Frunze0cab6562017-07-25 15:19:36 -07001449 // and kR6BareCondBranch are an exception: use kOffset23 for beqzc/bnezc).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001450 OffsetBits offset_size;
1451 // Some MIPS instructions with PC-relative offsets shift the offset by 2. Encode the shift
1452 // count.
1453 int offset_shift;
1454 };
1455 static const BranchInfo branch_info_[/* Type */];
1456
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001457 // Unconditional branch or call.
Alexey Frunze0cab6562017-07-25 15:19:36 -07001458 Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call, bool is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001459 // Conditional branch.
1460 Branch(bool is_r6,
1461 uint32_t location,
1462 uint32_t target,
1463 BranchCondition condition,
1464 Register lhs_reg,
Alexey Frunze0cab6562017-07-25 15:19:36 -07001465 Register rhs_reg,
1466 bool is_bare);
Alexey Frunze96b66822016-09-10 02:32:44 -07001467 // Label address (in literal area) or literal.
1468 Branch(bool is_r6,
1469 uint32_t location,
1470 Register dest_reg,
1471 Register base_reg,
1472 Type label_or_literal_type);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001473
1474 // Some conditional branches with lhs = rhs are effectively NOPs, while some
1475 // others are effectively unconditional. MIPSR6 conditional branches require lhs != rhs.
1476 // So, we need a way to identify such branches in order to emit no instructions for them
1477 // or change them to unconditional.
1478 static bool IsNop(BranchCondition condition, Register lhs, Register rhs);
1479 static bool IsUncond(BranchCondition condition, Register lhs, Register rhs);
1480
1481 static BranchCondition OppositeCondition(BranchCondition cond);
1482
1483 Type GetType() const;
1484 BranchCondition GetCondition() const;
1485 Register GetLeftRegister() const;
1486 Register GetRightRegister() const;
1487 uint32_t GetTarget() const;
1488 uint32_t GetLocation() const;
1489 uint32_t GetOldLocation() const;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001490 uint32_t GetPrecedingInstructionLength(Type type) const;
1491 uint32_t GetPrecedingInstructionSize(Type type) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001492 uint32_t GetLength() const;
1493 uint32_t GetOldLength() const;
1494 uint32_t GetSize() const;
1495 uint32_t GetOldSize() const;
1496 uint32_t GetEndLocation() const;
1497 uint32_t GetOldEndLocation() const;
Alexey Frunze0cab6562017-07-25 15:19:36 -07001498 bool IsBare() const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001499 bool IsLong() const;
1500 bool IsResolved() const;
1501
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001502 // Various helpers for branch delay slot management.
1503 bool CanHaveDelayedInstruction(const DelaySlot& delay_slot) const;
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001504 void SetDelayedInstruction(uint32_t instruction, MipsLabel* patcher_label = nullptr);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001505 uint32_t GetDelayedInstruction() const;
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001506 MipsLabel* GetPatcherLabel() const;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001507 void DecrementLocations();
1508
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001509 // Returns the bit size of the signed offset that the branch instruction can handle.
1510 OffsetBits GetOffsetSize() const;
1511
1512 // Calculates the distance between two byte locations in the assembler buffer and
1513 // returns the number of bits needed to represent the distance as a signed integer.
1514 //
1515 // Branch instructions have signed offsets of 16, 19 (addiupc), 21 (beqzc/bnezc),
1516 // and 26 (bc) bits, which are additionally shifted left 2 positions at run time.
1517 //
1518 // Composite branches (made of several instructions) with longer reach have 32-bit
1519 // offsets encoded as 2 16-bit "halves" in two instructions (high half goes first).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001520 // The composite branches cover the range of PC + +/-2GB on MIPS32 CPUs. However,
1521 // the range is not end-to-end on MIPS64 (unless addresses are forced to zero- or
1522 // sign-extend from 32 to 64 bits by the appropriate CPU configuration).
1523 // Consider the following implementation of a long unconditional branch, for
1524 // example:
1525 //
1526 // auipc at, offset_31_16 // at = pc + sign_extend(offset_31_16) << 16
1527 // jic at, offset_15_0 // pc = at + sign_extend(offset_15_0)
1528 //
1529 // Both of the above instructions take 16-bit signed offsets as immediate operands.
1530 // When bit 15 of offset_15_0 is 1, it effectively causes subtraction of 0x10000
1531 // due to sign extension. This must be compensated for by incrementing offset_31_16
1532 // by 1. offset_31_16 can only be incremented by 1 if it's not 0x7FFF. If it is
1533 // 0x7FFF, adding 1 will overflow the positive offset into the negative range.
1534 // Therefore, the long branch range is something like from PC - 0x80000000 to
1535 // PC + 0x7FFF7FFF, IOW, shorter by 32KB on one side.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001536 //
1537 // The returned values are therefore: 18, 21, 23, 28 and 32. There's also a special
1538 // case with the addiu instruction and a 16 bit offset.
1539 static OffsetBits GetOffsetSizeNeeded(uint32_t location, uint32_t target);
1540
1541 // Resolve a branch when the target is known.
1542 void Resolve(uint32_t target);
1543
1544 // Relocate a branch by a given delta if needed due to expansion of this or another
1545 // branch at a given location by this delta (just changes location_ and target_).
1546 void Relocate(uint32_t expand_location, uint32_t delta);
1547
1548 // If the branch is short, changes its type to long.
1549 void PromoteToLong();
1550
1551 // If necessary, updates the type by promoting a short branch to a long branch
1552 // based on the branch location and target. Returns the amount (in bytes) by
1553 // which the branch size has increased.
1554 // max_short_distance caps the maximum distance between location_ and target_
1555 // that is allowed for short branches. This is for debugging/testing purposes.
1556 // max_short_distance = 0 forces all short branches to become long.
1557 // Use the implicit default argument when not debugging/testing.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001558 uint32_t PromoteIfNeeded(uint32_t location,
1559 uint32_t max_short_distance = std::numeric_limits<uint32_t>::max());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001560
1561 // Returns the location of the instruction(s) containing the offset.
1562 uint32_t GetOffsetLocation() const;
1563
1564 // Calculates and returns the offset ready for encoding in the branch instruction(s).
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001565 uint32_t GetOffset(uint32_t location) const;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001566
1567 private:
1568 // Completes branch construction by determining and recording its type.
Alexey Frunze96b66822016-09-10 02:32:44 -07001569 void InitializeType(Type initial_type, bool is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001570 // Helper for the above.
1571 void InitShortOrLong(OffsetBits ofs_size, Type short_type, Type long_type);
1572
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001573 uint32_t old_location_; // Offset into assembler buffer in bytes.
1574 uint32_t location_; // Offset into assembler buffer in bytes.
1575 uint32_t target_; // Offset into assembler buffer in bytes.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001576
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001577 uint32_t lhs_reg_; // Left-hand side register in conditional branches or
1578 // FPU condition code. Destination register in literals.
1579 uint32_t rhs_reg_; // Right-hand side register in conditional branches.
1580 // Base register in literals (ZERO on R6).
1581 BranchCondition condition_; // Condition for conditional branches.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001582
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001583 Type type_; // Current type of the branch.
1584 Type old_type_; // Initial type of the branch.
1585
1586 uint32_t delayed_instruction_; // Encoded instruction for the delay slot or
1587 // kUnfilledDelaySlot if none but fillable or
1588 // kUnfillableDelaySlot if none and unfillable
1589 // (the latter is only used for unconditional R2
1590 // branches).
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001591
1592 MipsLabel* patcher_label_; // Patcher label for the instruction in the delay slot.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001593 };
1594 friend std::ostream& operator<<(std::ostream& os, const Branch::Type& rhs);
1595 friend std::ostream& operator<<(std::ostream& os, const Branch::OffsetBits& rhs);
1596
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001597 uint32_t EmitR(int opcode, Register rs, Register rt, Register rd, int shamt, int funct);
1598 uint32_t EmitI(int opcode, Register rs, Register rt, uint16_t imm);
1599 uint32_t EmitI21(int opcode, Register rs, uint32_t imm21);
1600 uint32_t EmitI26(int opcode, uint32_t imm26);
1601 uint32_t EmitFR(int opcode, int fmt, FRegister ft, FRegister fs, FRegister fd, int funct);
1602 uint32_t EmitFI(int opcode, int fmt, FRegister rt, uint16_t imm);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001603 void EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16);
1604 void EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21);
Lena Djokic0758ae72017-05-23 11:06:23 +02001605 uint32_t EmitMsa3R(int operation,
1606 int df,
1607 VectorRegister wt,
1608 VectorRegister ws,
1609 VectorRegister wd,
1610 int minor_opcode);
1611 uint32_t EmitMsaBIT(int operation,
1612 int df_m,
1613 VectorRegister ws,
1614 VectorRegister wd,
1615 int minor_opcode);
1616 uint32_t EmitMsaELM(int operation,
1617 int df_n,
1618 VectorRegister ws,
1619 VectorRegister wd,
1620 int minor_opcode);
1621 uint32_t EmitMsaMI10(int s10, Register rs, VectorRegister wd, int minor_opcode, int df);
1622 uint32_t EmitMsaI10(int operation, int df, int i10, VectorRegister wd, int minor_opcode);
1623 uint32_t EmitMsa2R(int operation, int df, VectorRegister ws, VectorRegister wd, int minor_opcode);
1624 uint32_t EmitMsa2RF(int operation,
1625 int df,
1626 VectorRegister ws,
1627 VectorRegister wd,
1628 int minor_opcode);
jeffhao7fbee072012-08-24 17:56:54 -07001629
Alexey Frunze0cab6562017-07-25 15:19:36 -07001630 void Buncond(MipsLabel* label, bool is_r6, bool is_bare);
1631 void Bcond(MipsLabel* label,
1632 bool is_r6,
1633 bool is_bare,
1634 BranchCondition condition,
1635 Register lhs,
1636 Register rhs = ZERO);
1637 void Call(MipsLabel* label, bool is_r6, bool is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001638 void FinalizeLabeledBranch(MipsLabel* label);
jeffhao7fbee072012-08-24 17:56:54 -07001639
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001640 // Various helpers for branch delay slot management.
1641 void DsFsmInstr(uint32_t instruction,
1642 uint32_t gpr_outs_mask,
1643 uint32_t gpr_ins_mask,
1644 uint32_t fpr_outs_mask,
1645 uint32_t fpr_ins_mask,
1646 uint32_t cc_outs_mask,
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001647 uint32_t cc_ins_mask,
1648 MipsLabel* patcher_label = nullptr);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001649 void DsFsmInstrNop(uint32_t instruction);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001650 void DsFsmInstrRrr(uint32_t instruction,
1651 Register out,
1652 Register in1,
1653 Register in2,
1654 MipsLabel* patcher_label = nullptr);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001655 void DsFsmInstrRrrr(uint32_t instruction, Register in1_out, Register in2, Register in3);
1656 void DsFsmInstrFff(uint32_t instruction, FRegister out, FRegister in1, FRegister in2);
1657 void DsFsmInstrFfff(uint32_t instruction, FRegister in1_out, FRegister in2, FRegister in3);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001658 void DsFsmInstrFffr(uint32_t instruction, FRegister in1_out, FRegister in2, Register in3);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001659 void DsFsmInstrRf(uint32_t instruction, Register out, FRegister in);
1660 void DsFsmInstrFr(uint32_t instruction, FRegister out, Register in);
1661 void DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2);
1662 void DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2);
1663 void DsFsmInstrRrrc(uint32_t instruction, Register in1_out, Register in2, int cc_in);
1664 void DsFsmInstrFffc(uint32_t instruction, FRegister in1_out, FRegister in2, int cc_in);
1665 void DsFsmLabel();
1666 void DsFsmCommitLabel();
1667 void DsFsmDropLabel();
1668 void MoveInstructionToDelaySlot(Branch& branch);
1669 bool CanExchangeWithSlt(Register rs, Register rt) const;
1670 void ExchangeWithSlt(const DelaySlot& forwarded_slot);
1671 void GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt);
1672
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001673 Branch* GetBranch(uint32_t branch_id);
1674 const Branch* GetBranch(uint32_t branch_id) const;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001675 uint32_t GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const;
1676 uint32_t GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const;
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001677 void BindRelativeToPrecedingBranch(MipsLabel* label,
1678 uint32_t prev_branch_id_plus_one,
1679 uint32_t position);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001680
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001681 void EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -07001682 void ReserveJumpTableSpace();
1683 void EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001684 void PromoteBranches();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07001685 void EmitBranch(uint32_t branch_id);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001686 void EmitBranches();
Vladimir Marko10ef6942015-10-22 15:25:54 +01001687 void PatchCFI(size_t number_of_delayed_adjust_pcs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001688
1689 // Emits exception block.
1690 void EmitExceptionPoll(MipsExceptionSlowPath* exception);
1691
Lena Djokic0758ae72017-05-23 11:06:23 +02001692 bool HasMsa() const {
1693 return has_msa_;
1694 }
1695
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001696 bool IsR6() const {
1697 if (isa_features_ != nullptr) {
1698 return isa_features_->IsR6();
1699 } else {
1700 return false;
1701 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001702 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001703
1704 bool Is32BitFPU() const {
1705 if (isa_features_ != nullptr) {
1706 return isa_features_->Is32BitFloatingPoint();
1707 } else {
1708 return true;
1709 }
Goran Jakovljevicff734982015-08-24 12:58:55 +00001710 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001711
1712 // List of exception blocks to generate at the end of the code cache.
1713 std::vector<MipsExceptionSlowPath> exception_blocks_;
1714
1715 std::vector<Branch> branches_;
1716
1717 // Whether appending instructions at the end of the buffer or overwriting the existing ones.
1718 bool overwriting_;
1719 // The current overwrite location.
1720 uint32_t overwrite_location_;
1721
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001722 // Whether instruction reordering (IOW, automatic filling of delay slots) is enabled.
1723 bool reordering_;
1724 // Information about the last instruction that may be used to fill a branch delay slot.
1725 DelaySlot delay_slot_;
1726 // Delay slot FSM state.
1727 DsFsmState ds_fsm_state_;
1728 // PC of the current labeled target instruction.
1729 uint32_t ds_fsm_target_pc_;
1730 // PCs of labeled target instructions.
1731 std::vector<uint32_t> ds_fsm_target_pcs_;
1732
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001733 // Use std::deque<> for literal labels to allow insertions at the end
1734 // without invalidating pointers and references to existing elements.
1735 ArenaDeque<Literal> literals_;
1736
Alexey Frunze96b66822016-09-10 02:32:44 -07001737 // Jump table list.
1738 ArenaDeque<JumpTable> jump_tables_;
1739
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001740 // There's no PC-relative addressing on MIPS32R2. So, in order to access literals relative to PC
1741 // we get PC using the NAL instruction. This label marks the position within the assembler buffer
1742 // that PC (from NAL) points to.
1743 MipsLabel pc_rel_base_label_;
1744
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001745 // Data for GetAdjustedPosition(), see the description there.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001746 uint32_t last_position_adjustment_;
1747 uint32_t last_old_position_;
1748 uint32_t last_branch_id_;
1749
Lena Djokic0758ae72017-05-23 11:06:23 +02001750 const bool has_msa_;
1751
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001752 const MipsInstructionSetFeatures* isa_features_;
Goran Jakovljevicff734982015-08-24 12:58:55 +00001753
jeffhao7fbee072012-08-24 17:56:54 -07001754 DISALLOW_COPY_AND_ASSIGN(MipsAssembler);
1755};
1756
jeffhao7fbee072012-08-24 17:56:54 -07001757} // namespace mips
1758} // namespace art
1759
Ian Rogers166db042013-07-26 12:05:57 -07001760#endif // ART_COMPILER_UTILS_MIPS_ASSEMBLER_MIPS_H_