blob: a673e3210c38c9ae2aff0ccc235167a1cb35c479 [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
17#include "assembler_mips.h"
18
Vladimir Marko80afd022015-05-19 18:08:00 +010019#include "base/bit_utils.h"
Elliott Hughes1aa246d2012-12-13 09:29:36 -080020#include "base/casts.h"
David Sehr1ce2b3b2018-04-05 11:02:03 -070021#include "base/memory_region.h"
Ian Rogers166db042013-07-26 12:05:57 -070022#include "entrypoints/quick/quick_entrypoints.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020023#include "entrypoints/quick/quick_entrypoints_enum.h"
jeffhao7fbee072012-08-24 17:56:54 -070024#include "thread.h"
25
26namespace art {
27namespace mips {
jeffhao7fbee072012-08-24 17:56:54 -070028
Andreas Gampe542451c2016-07-26 09:02:02 -070029static_assert(static_cast<size_t>(kMipsPointerSize) == kMipsWordSize,
30 "Unexpected Mips pointer size.");
31static_assert(kMipsPointerSize == PointerSize::k32, "Unexpected Mips pointer size.");
32
33
jeffhao7fbee072012-08-24 17:56:54 -070034std::ostream& operator<<(std::ostream& os, const DRegister& rhs) {
35 if (rhs >= D0 && rhs < kNumberOfDRegisters) {
36 os << "d" << static_cast<int>(rhs);
37 } else {
38 os << "DRegister[" << static_cast<int>(rhs) << "]";
39 }
40 return os;
41}
42
Alexey Frunze57eb0f52016-07-29 22:04:46 -070043MipsAssembler::DelaySlot::DelaySlot()
44 : instruction_(0),
Alexey Frunzea663d9d2017-07-31 18:43:18 -070045 patcher_label_(nullptr) {}
Alexey Frunze57eb0f52016-07-29 22:04:46 -070046
Alexey Frunzea247dea2017-11-03 18:43:04 -070047InOutRegMasks& MipsAssembler::DsFsmInstr(uint32_t instruction, MipsLabel* patcher_label) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -070048 if (!reordering_) {
49 CHECK_EQ(ds_fsm_state_, kExpectingLabel);
50 CHECK_EQ(delay_slot_.instruction_, 0u);
Alexey Frunzea247dea2017-11-03 18:43:04 -070051 return delay_slot_.masks_;
Alexey Frunze57eb0f52016-07-29 22:04:46 -070052 }
53 switch (ds_fsm_state_) {
54 case kExpectingLabel:
55 break;
56 case kExpectingInstruction:
57 CHECK_EQ(ds_fsm_target_pc_ + sizeof(uint32_t), buffer_.Size());
58 // If the last instruction is not suitable for delay slots, drop
59 // the PC of the label preceding it so that no unconditional branch
60 // uses this instruction to fill its delay slot.
61 if (instruction == 0) {
62 DsFsmDropLabel(); // Sets ds_fsm_state_ = kExpectingLabel.
63 } else {
64 // Otherwise wait for another instruction or label before we can
65 // commit the label PC. The label PC will be dropped if instead
66 // of another instruction or label there's a call from the code
67 // generator to CodePosition() to record the buffer size.
68 // Instructions after which the buffer size is recorded cannot
69 // be moved into delay slots or anywhere else because they may
70 // trigger signals and the signal handlers expect these signals
71 // to be coming from the instructions immediately preceding the
72 // recorded buffer locations.
73 ds_fsm_state_ = kExpectingCommit;
74 }
75 break;
76 case kExpectingCommit:
77 CHECK_EQ(ds_fsm_target_pc_ + 2 * sizeof(uint32_t), buffer_.Size());
78 DsFsmCommitLabel(); // Sets ds_fsm_state_ = kExpectingLabel.
79 break;
80 }
81 delay_slot_.instruction_ = instruction;
Alexey Frunzea247dea2017-11-03 18:43:04 -070082 delay_slot_.masks_ = InOutRegMasks();
Alexey Frunzea663d9d2017-07-31 18:43:18 -070083 delay_slot_.patcher_label_ = patcher_label;
Alexey Frunzea247dea2017-11-03 18:43:04 -070084 return delay_slot_.masks_;
Alexey Frunze57eb0f52016-07-29 22:04:46 -070085}
86
87void MipsAssembler::DsFsmLabel() {
88 if (!reordering_) {
89 CHECK_EQ(ds_fsm_state_, kExpectingLabel);
90 CHECK_EQ(delay_slot_.instruction_, 0u);
91 return;
92 }
93 switch (ds_fsm_state_) {
94 case kExpectingLabel:
95 ds_fsm_target_pc_ = buffer_.Size();
96 ds_fsm_state_ = kExpectingInstruction;
97 break;
98 case kExpectingInstruction:
99 // Allow consecutive labels.
100 CHECK_EQ(ds_fsm_target_pc_, buffer_.Size());
101 break;
102 case kExpectingCommit:
103 CHECK_EQ(ds_fsm_target_pc_ + sizeof(uint32_t), buffer_.Size());
104 DsFsmCommitLabel();
105 ds_fsm_target_pc_ = buffer_.Size();
106 ds_fsm_state_ = kExpectingInstruction;
107 break;
108 }
109 // We cannot move instructions into delay slots across labels.
110 delay_slot_.instruction_ = 0;
111}
112
113void MipsAssembler::DsFsmCommitLabel() {
114 if (ds_fsm_state_ == kExpectingCommit) {
115 ds_fsm_target_pcs_.emplace_back(ds_fsm_target_pc_);
116 }
117 ds_fsm_state_ = kExpectingLabel;
118}
119
120void MipsAssembler::DsFsmDropLabel() {
121 ds_fsm_state_ = kExpectingLabel;
122}
123
124bool MipsAssembler::SetReorder(bool enable) {
125 bool last_state = reordering_;
126 if (last_state != enable) {
127 DsFsmCommitLabel();
128 DsFsmInstrNop(0);
129 }
130 reordering_ = enable;
131 return last_state;
132}
133
134size_t MipsAssembler::CodePosition() {
135 // The last instruction cannot be used in a delay slot, do not commit
136 // the label before it (if any) and clear the delay slot.
137 DsFsmDropLabel();
138 DsFsmInstrNop(0);
139 size_t size = buffer_.Size();
140 // In theory we can get the following sequence:
141 // label1:
142 // instr
143 // label2: # label1 gets committed when label2 is seen
144 // CodePosition() call
145 // and we need to uncommit label1.
146 if (ds_fsm_target_pcs_.size() != 0 && ds_fsm_target_pcs_.back() + sizeof(uint32_t) == size) {
147 ds_fsm_target_pcs_.pop_back();
148 }
149 return size;
150}
151
152void MipsAssembler::DsFsmInstrNop(uint32_t instruction ATTRIBUTE_UNUSED) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700153 DsFsmInstr(0);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700154}
155
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200156void MipsAssembler::FinalizeCode() {
157 for (auto& exception_block : exception_blocks_) {
158 EmitExceptionPoll(&exception_block);
159 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700160 // Commit the last branch target label (if any) and disable instruction reordering.
161 DsFsmCommitLabel();
162 SetReorder(false);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700163 EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -0700164 ReserveJumpTableSpace();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200165 PromoteBranches();
166}
167
168void MipsAssembler::FinalizeInstructions(const MemoryRegion& region) {
Vladimir Marko10ef6942015-10-22 15:25:54 +0100169 size_t number_of_delayed_adjust_pcs = cfi().NumberOfDelayedAdvancePCs();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200170 EmitBranches();
Alexey Frunze96b66822016-09-10 02:32:44 -0700171 EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200172 Assembler::FinalizeInstructions(region);
Vladimir Marko10ef6942015-10-22 15:25:54 +0100173 PatchCFI(number_of_delayed_adjust_pcs);
174}
175
176void MipsAssembler::PatchCFI(size_t number_of_delayed_adjust_pcs) {
177 if (cfi().NumberOfDelayedAdvancePCs() == 0u) {
178 DCHECK_EQ(number_of_delayed_adjust_pcs, 0u);
179 return;
180 }
181
Andreas Gampec55bb392018-09-21 00:02:02 +0000182 using DelayedAdvancePC = DebugFrameOpCodeWriterForAssembler::DelayedAdvancePC;
Vladimir Marko10ef6942015-10-22 15:25:54 +0100183 const auto data = cfi().ReleaseStreamAndPrepareForDelayedAdvancePC();
184 const std::vector<uint8_t>& old_stream = data.first;
185 const std::vector<DelayedAdvancePC>& advances = data.second;
186
187 // PCs recorded before EmitBranches() need to be adjusted.
188 // PCs recorded during EmitBranches() are already adjusted.
189 // Both ranges are separately sorted but they may overlap.
190 if (kIsDebugBuild) {
191 auto cmp = [](const DelayedAdvancePC& lhs, const DelayedAdvancePC& rhs) {
192 return lhs.pc < rhs.pc;
193 };
194 CHECK(std::is_sorted(advances.begin(), advances.begin() + number_of_delayed_adjust_pcs, cmp));
195 CHECK(std::is_sorted(advances.begin() + number_of_delayed_adjust_pcs, advances.end(), cmp));
196 }
197
198 // Append initial CFI data if any.
199 size_t size = advances.size();
200 DCHECK_NE(size, 0u);
201 cfi().AppendRawData(old_stream, 0u, advances[0].stream_pos);
202 // Emit PC adjustments interleaved with the old CFI stream.
203 size_t adjust_pos = 0u;
204 size_t late_emit_pos = number_of_delayed_adjust_pcs;
205 while (adjust_pos != number_of_delayed_adjust_pcs || late_emit_pos != size) {
206 size_t adjusted_pc = (adjust_pos != number_of_delayed_adjust_pcs)
207 ? GetAdjustedPosition(advances[adjust_pos].pc)
208 : static_cast<size_t>(-1);
209 size_t late_emit_pc = (late_emit_pos != size)
210 ? advances[late_emit_pos].pc
211 : static_cast<size_t>(-1);
212 size_t advance_pc = std::min(adjusted_pc, late_emit_pc);
213 DCHECK_NE(advance_pc, static_cast<size_t>(-1));
214 size_t entry = (adjusted_pc <= late_emit_pc) ? adjust_pos : late_emit_pos;
215 if (adjusted_pc <= late_emit_pc) {
216 ++adjust_pos;
217 } else {
218 ++late_emit_pos;
219 }
220 cfi().AdvancePC(advance_pc);
221 size_t end_pos = (entry + 1u == size) ? old_stream.size() : advances[entry + 1u].stream_pos;
222 cfi().AppendRawData(old_stream, advances[entry].stream_pos, end_pos);
223 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200224}
225
226void MipsAssembler::EmitBranches() {
227 CHECK(!overwriting_);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700228 CHECK(!reordering_);
229 // Now that everything has its final position in the buffer (the branches have
230 // been promoted), adjust the target label PCs.
231 for (size_t cnt = ds_fsm_target_pcs_.size(), i = 0; i < cnt; i++) {
232 ds_fsm_target_pcs_[i] = GetAdjustedPosition(ds_fsm_target_pcs_[i]);
233 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200234 // Switch from appending instructions at the end of the buffer to overwriting
235 // existing instructions (branch placeholders) in the buffer.
236 overwriting_ = true;
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700237 for (size_t id = 0; id < branches_.size(); id++) {
238 EmitBranch(id);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200239 }
240 overwriting_ = false;
241}
242
243void MipsAssembler::Emit(uint32_t value) {
244 if (overwriting_) {
245 // Branches to labels are emitted into their placeholders here.
246 buffer_.Store<uint32_t>(overwrite_location_, value);
247 overwrite_location_ += sizeof(uint32_t);
248 } else {
249 // Other instructions are simply appended at the end here.
250 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
251 buffer_.Emit<uint32_t>(value);
252 }
jeffhao7fbee072012-08-24 17:56:54 -0700253}
254
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700255uint32_t MipsAssembler::EmitR(int opcode,
256 Register rs,
257 Register rt,
258 Register rd,
259 int shamt,
260 int funct) {
jeffhao7fbee072012-08-24 17:56:54 -0700261 CHECK_NE(rs, kNoRegister);
262 CHECK_NE(rt, kNoRegister);
263 CHECK_NE(rd, kNoRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200264 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
265 static_cast<uint32_t>(rs) << kRsShift |
266 static_cast<uint32_t>(rt) << kRtShift |
267 static_cast<uint32_t>(rd) << kRdShift |
268 shamt << kShamtShift |
269 funct;
jeffhao7fbee072012-08-24 17:56:54 -0700270 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700271 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700272}
273
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700274uint32_t MipsAssembler::EmitI(int opcode, Register rs, Register rt, uint16_t imm) {
jeffhao7fbee072012-08-24 17:56:54 -0700275 CHECK_NE(rs, kNoRegister);
276 CHECK_NE(rt, kNoRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200277 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
278 static_cast<uint32_t>(rs) << kRsShift |
279 static_cast<uint32_t>(rt) << kRtShift |
280 imm;
jeffhao7fbee072012-08-24 17:56:54 -0700281 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700282 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700283}
284
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700285uint32_t MipsAssembler::EmitI21(int opcode, Register rs, uint32_t imm21) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200286 CHECK_NE(rs, kNoRegister);
287 CHECK(IsUint<21>(imm21)) << imm21;
288 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
289 static_cast<uint32_t>(rs) << kRsShift |
290 imm21;
jeffhao7fbee072012-08-24 17:56:54 -0700291 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700292 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700293}
294
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700295uint32_t MipsAssembler::EmitI26(int opcode, uint32_t imm26) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200296 CHECK(IsUint<26>(imm26)) << imm26;
297 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift | imm26;
298 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700299 return encoding;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200300}
301
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700302uint32_t MipsAssembler::EmitFR(int opcode,
303 int fmt,
304 FRegister ft,
305 FRegister fs,
306 FRegister fd,
307 int funct) {
jeffhao7fbee072012-08-24 17:56:54 -0700308 CHECK_NE(ft, kNoFRegister);
309 CHECK_NE(fs, kNoFRegister);
310 CHECK_NE(fd, kNoFRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200311 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
312 fmt << kFmtShift |
313 static_cast<uint32_t>(ft) << kFtShift |
314 static_cast<uint32_t>(fs) << kFsShift |
315 static_cast<uint32_t>(fd) << kFdShift |
316 funct;
jeffhao7fbee072012-08-24 17:56:54 -0700317 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700318 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700319}
320
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700321uint32_t MipsAssembler::EmitFI(int opcode, int fmt, FRegister ft, uint16_t imm) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200322 CHECK_NE(ft, kNoFRegister);
323 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
324 fmt << kFmtShift |
325 static_cast<uint32_t>(ft) << kFtShift |
326 imm;
jeffhao7fbee072012-08-24 17:56:54 -0700327 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700328 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700329}
330
Lena Djokic0758ae72017-05-23 11:06:23 +0200331uint32_t MipsAssembler::EmitMsa3R(int operation,
332 int df,
333 VectorRegister wt,
334 VectorRegister ws,
335 VectorRegister wd,
336 int minor_opcode) {
337 CHECK_NE(wt, kNoVectorRegister);
338 CHECK_NE(ws, kNoVectorRegister);
339 CHECK_NE(wd, kNoVectorRegister);
340 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
341 operation << kMsaOperationShift |
342 df << kDfShift |
343 static_cast<uint32_t>(wt) << kWtShift |
344 static_cast<uint32_t>(ws) << kWsShift |
345 static_cast<uint32_t>(wd) << kWdShift |
346 minor_opcode;
347 Emit(encoding);
348 return encoding;
349}
350
351uint32_t MipsAssembler::EmitMsaBIT(int operation,
352 int df_m,
353 VectorRegister ws,
354 VectorRegister wd,
355 int minor_opcode) {
356 CHECK_NE(ws, kNoVectorRegister);
357 CHECK_NE(wd, kNoVectorRegister);
358 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
359 operation << kMsaOperationShift |
360 df_m << kDfMShift |
361 static_cast<uint32_t>(ws) << kWsShift |
362 static_cast<uint32_t>(wd) << kWdShift |
363 minor_opcode;
364 Emit(encoding);
365 return encoding;
366}
367
368uint32_t MipsAssembler::EmitMsaELM(int operation,
369 int df_n,
370 VectorRegister ws,
371 VectorRegister wd,
372 int minor_opcode) {
373 CHECK_NE(ws, kNoVectorRegister);
374 CHECK_NE(wd, kNoVectorRegister);
375 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
376 operation << kMsaELMOperationShift |
377 df_n << kDfNShift |
378 static_cast<uint32_t>(ws) << kWsShift |
379 static_cast<uint32_t>(wd) << kWdShift |
380 minor_opcode;
381 Emit(encoding);
382 return encoding;
383}
384
385uint32_t MipsAssembler::EmitMsaMI10(int s10,
386 Register rs,
387 VectorRegister wd,
388 int minor_opcode,
389 int df) {
390 CHECK_NE(rs, kNoRegister);
391 CHECK_NE(wd, kNoVectorRegister);
392 CHECK(IsUint<10>(s10)) << s10;
393 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
394 s10 << kS10Shift |
395 static_cast<uint32_t>(rs) << kWsShift |
396 static_cast<uint32_t>(wd) << kWdShift |
397 minor_opcode << kS10MinorShift |
398 df;
399 Emit(encoding);
400 return encoding;
401}
402
403uint32_t MipsAssembler::EmitMsaI10(int operation,
404 int df,
405 int i10,
406 VectorRegister wd,
407 int minor_opcode) {
408 CHECK_NE(wd, kNoVectorRegister);
409 CHECK(IsUint<10>(i10)) << i10;
410 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
411 operation << kMsaOperationShift |
412 df << kDfShift |
413 i10 << kI10Shift |
414 static_cast<uint32_t>(wd) << kWdShift |
415 minor_opcode;
416 Emit(encoding);
417 return encoding;
418}
419
420uint32_t MipsAssembler::EmitMsa2R(int operation,
421 int df,
422 VectorRegister ws,
423 VectorRegister wd,
424 int minor_opcode) {
425 CHECK_NE(ws, kNoVectorRegister);
426 CHECK_NE(wd, kNoVectorRegister);
427 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
428 operation << kMsa2ROperationShift |
429 df << kDf2RShift |
430 static_cast<uint32_t>(ws) << kWsShift |
431 static_cast<uint32_t>(wd) << kWdShift |
432 minor_opcode;
433 Emit(encoding);
434 return encoding;
435}
436
437uint32_t MipsAssembler::EmitMsa2RF(int operation,
438 int df,
439 VectorRegister ws,
440 VectorRegister wd,
441 int minor_opcode) {
442 CHECK_NE(ws, kNoVectorRegister);
443 CHECK_NE(wd, kNoVectorRegister);
444 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
445 operation << kMsa2RFOperationShift |
446 df << kDf2RShift |
447 static_cast<uint32_t>(ws) << kWsShift |
448 static_cast<uint32_t>(wd) << kWdShift |
449 minor_opcode;
450 Emit(encoding);
451 return encoding;
452}
453
jeffhao7fbee072012-08-24 17:56:54 -0700454void MipsAssembler::Addu(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700455 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x21)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700456}
457
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700458void MipsAssembler::Addiu(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label) {
459 if (patcher_label != nullptr) {
460 Bind(patcher_label);
461 }
Alexey Frunzea247dea2017-11-03 18:43:04 -0700462 DsFsmInstr(EmitI(0x9, rs, rt, imm16), patcher_label).GprOuts(rt).GprIns(rs);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700463}
464
jeffhao7fbee072012-08-24 17:56:54 -0700465void MipsAssembler::Addiu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700466 Addiu(rt, rs, imm16, /* patcher_label */ nullptr);
jeffhao7fbee072012-08-24 17:56:54 -0700467}
468
jeffhao7fbee072012-08-24 17:56:54 -0700469void MipsAssembler::Subu(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700470 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x23)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700471}
472
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200473void MipsAssembler::MultR2(Register rs, Register rt) {
474 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700475 DsFsmInstr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x18)).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700476}
477
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200478void MipsAssembler::MultuR2(Register rs, Register rt) {
479 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700480 DsFsmInstr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x19)).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700481}
482
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200483void MipsAssembler::DivR2(Register rs, Register rt) {
484 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700485 DsFsmInstr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x1a)).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700486}
487
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200488void MipsAssembler::DivuR2(Register rs, Register rt) {
489 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700490 DsFsmInstr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x1b)).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700491}
492
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200493void MipsAssembler::MulR2(Register rd, Register rs, Register rt) {
494 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700495 DsFsmInstr(EmitR(0x1c, rs, rt, rd, 0, 2)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200496}
497
498void MipsAssembler::DivR2(Register rd, Register rs, Register rt) {
499 CHECK(!IsR6());
500 DivR2(rs, rt);
501 Mflo(rd);
502}
503
504void MipsAssembler::ModR2(Register rd, Register rs, Register rt) {
505 CHECK(!IsR6());
506 DivR2(rs, rt);
507 Mfhi(rd);
508}
509
510void MipsAssembler::DivuR2(Register rd, Register rs, Register rt) {
511 CHECK(!IsR6());
512 DivuR2(rs, rt);
513 Mflo(rd);
514}
515
516void MipsAssembler::ModuR2(Register rd, Register rs, Register rt) {
517 CHECK(!IsR6());
518 DivuR2(rs, rt);
519 Mfhi(rd);
520}
521
522void MipsAssembler::MulR6(Register rd, Register rs, Register rt) {
523 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700524 DsFsmInstr(EmitR(0, rs, rt, rd, 2, 0x18)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200525}
526
Alexey Frunze7e99e052015-11-24 19:28:01 -0800527void MipsAssembler::MuhR6(Register rd, Register rs, Register rt) {
528 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700529 DsFsmInstr(EmitR(0, rs, rt, rd, 3, 0x18)).GprOuts(rd).GprIns(rs, rt);
Alexey Frunze7e99e052015-11-24 19:28:01 -0800530}
531
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200532void MipsAssembler::MuhuR6(Register rd, Register rs, Register rt) {
533 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700534 DsFsmInstr(EmitR(0, rs, rt, rd, 3, 0x19)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200535}
536
537void MipsAssembler::DivR6(Register rd, Register rs, Register rt) {
538 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700539 DsFsmInstr(EmitR(0, rs, rt, rd, 2, 0x1a)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200540}
541
542void MipsAssembler::ModR6(Register rd, Register rs, Register rt) {
543 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700544 DsFsmInstr(EmitR(0, rs, rt, rd, 3, 0x1a)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200545}
546
547void MipsAssembler::DivuR6(Register rd, Register rs, Register rt) {
548 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700549 DsFsmInstr(EmitR(0, rs, rt, rd, 2, 0x1b)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200550}
551
552void MipsAssembler::ModuR6(Register rd, Register rs, Register rt) {
553 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700554 DsFsmInstr(EmitR(0, rs, rt, rd, 3, 0x1b)).GprOuts(rd).GprIns(rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200555}
556
jeffhao7fbee072012-08-24 17:56:54 -0700557void MipsAssembler::And(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700558 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x24)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700559}
560
561void MipsAssembler::Andi(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700562 DsFsmInstr(EmitI(0xc, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700563}
564
565void MipsAssembler::Or(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700566 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x25)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700567}
568
569void MipsAssembler::Ori(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700570 DsFsmInstr(EmitI(0xd, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700571}
572
573void MipsAssembler::Xor(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700574 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x26)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700575}
576
577void MipsAssembler::Xori(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700578 DsFsmInstr(EmitI(0xe, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700579}
580
581void MipsAssembler::Nor(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700582 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x27)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700583}
584
Chris Larsene3845472015-11-18 12:27:15 -0800585void MipsAssembler::Movz(Register rd, Register rs, Register rt) {
586 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700587 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x0A)).GprInOuts(rd).GprIns(rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800588}
589
590void MipsAssembler::Movn(Register rd, Register rs, Register rt) {
591 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700592 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x0B)).GprInOuts(rd).GprIns(rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800593}
594
595void MipsAssembler::Seleqz(Register rd, Register rs, Register rt) {
596 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700597 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x35)).GprOuts(rd).GprIns(rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800598}
599
600void MipsAssembler::Selnez(Register rd, Register rs, Register rt) {
601 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700602 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x37)).GprOuts(rd).GprIns(rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800603}
604
605void MipsAssembler::ClzR6(Register rd, Register rs) {
606 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700607 DsFsmInstr(EmitR(0, rs, static_cast<Register>(0), rd, 0x01, 0x10)).GprOuts(rd).GprIns(rs);
Chris Larsene3845472015-11-18 12:27:15 -0800608}
609
610void MipsAssembler::ClzR2(Register rd, Register rs) {
611 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700612 DsFsmInstr(EmitR(0x1C, rs, rd, rd, 0, 0x20)).GprOuts(rd).GprIns(rs);
Chris Larsene3845472015-11-18 12:27:15 -0800613}
614
615void MipsAssembler::CloR6(Register rd, Register rs) {
616 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700617 DsFsmInstr(EmitR(0, rs, static_cast<Register>(0), rd, 0x01, 0x11)).GprOuts(rd).GprIns(rs);
Chris Larsene3845472015-11-18 12:27:15 -0800618}
619
620void MipsAssembler::CloR2(Register rd, Register rs) {
621 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700622 DsFsmInstr(EmitR(0x1C, rs, rd, rd, 0, 0x21)).GprOuts(rd).GprIns(rs);
Chris Larsene3845472015-11-18 12:27:15 -0800623}
624
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200625void MipsAssembler::Seb(Register rd, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700626 DsFsmInstr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x10, 0x20)).GprOuts(rd).GprIns(rt);
jeffhao7fbee072012-08-24 17:56:54 -0700627}
628
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200629void MipsAssembler::Seh(Register rd, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700630 DsFsmInstr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x18, 0x20)).GprOuts(rd).GprIns(rt);
jeffhao7fbee072012-08-24 17:56:54 -0700631}
632
Chris Larsen3f8bf652015-10-28 10:08:56 -0700633void MipsAssembler::Wsbh(Register rd, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700634 DsFsmInstr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 2, 0x20)).GprOuts(rd).GprIns(rt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700635}
636
Chris Larsen70014c82015-11-18 12:26:08 -0800637void MipsAssembler::Bitswap(Register rd, Register rt) {
638 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700639 DsFsmInstr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x0, 0x20)).GprOuts(rd).GprIns(rt);
Chris Larsen70014c82015-11-18 12:26:08 -0800640}
641
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200642void MipsAssembler::Sll(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700643 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700644 DsFsmInstr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x00)).GprOuts(rd).GprIns(rt);
jeffhao7fbee072012-08-24 17:56:54 -0700645}
646
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200647void MipsAssembler::Srl(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700648 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700649 DsFsmInstr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x02)).GprOuts(rd).GprIns(rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200650}
651
Chris Larsen3f8bf652015-10-28 10:08:56 -0700652void MipsAssembler::Rotr(Register rd, Register rt, int shamt) {
653 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700654 DsFsmInstr(EmitR(0, static_cast<Register>(1), rt, rd, shamt, 0x02)).GprOuts(rd).GprIns(rt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700655}
656
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200657void MipsAssembler::Sra(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700658 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700659 DsFsmInstr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x03)).GprOuts(rd).GprIns(rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200660}
661
662void MipsAssembler::Sllv(Register rd, Register rt, Register rs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700663 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x04)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700664}
665
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200666void MipsAssembler::Srlv(Register rd, Register rt, Register rs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700667 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x06)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700668}
669
Chris Larsene16ce5a2015-11-18 12:30:20 -0800670void MipsAssembler::Rotrv(Register rd, Register rt, Register rs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700671 DsFsmInstr(EmitR(0, rs, rt, rd, 1, 0x06)).GprOuts(rd).GprIns(rs, rt);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800672}
673
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200674void MipsAssembler::Srav(Register rd, Register rt, Register rs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700675 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x07)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700676}
677
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800678void MipsAssembler::Ext(Register rd, Register rt, int pos, int size) {
679 CHECK(IsUint<5>(pos)) << pos;
680 CHECK(0 < size && size <= 32) << size;
681 CHECK(0 < pos + size && pos + size <= 32) << pos << " + " << size;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700682 DsFsmInstr(EmitR(0x1f, rt, rd, static_cast<Register>(size - 1), pos, 0x00))
683 .GprOuts(rd).GprIns(rt);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800684}
685
686void MipsAssembler::Ins(Register rd, Register rt, int pos, int size) {
687 CHECK(IsUint<5>(pos)) << pos;
688 CHECK(0 < size && size <= 32) << size;
689 CHECK(0 < pos + size && pos + size <= 32) << pos << " + " << size;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700690 DsFsmInstr(EmitR(0x1f, rt, rd, static_cast<Register>(pos + size - 1), pos, 0x04))
691 .GprInOuts(rd).GprIns(rt);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800692}
693
Chris Larsen692235e2016-11-21 16:04:53 -0800694void MipsAssembler::Lsa(Register rd, Register rs, Register rt, int saPlusOne) {
Lena Djokic0758ae72017-05-23 11:06:23 +0200695 CHECK(IsR6() || HasMsa());
Chris Larsen692235e2016-11-21 16:04:53 -0800696 CHECK(1 <= saPlusOne && saPlusOne <= 4) << saPlusOne;
697 int sa = saPlusOne - 1;
Alexey Frunzea247dea2017-11-03 18:43:04 -0700698 DsFsmInstr(EmitR(0x0, rs, rt, rd, sa, 0x05)).GprOuts(rd).GprIns(rs, rt);
Chris Larsen692235e2016-11-21 16:04:53 -0800699}
700
Chris Larsencd0295d2017-03-31 15:26:54 -0700701void MipsAssembler::ShiftAndAdd(Register dst,
702 Register src_idx,
703 Register src_base,
704 int shamt,
705 Register tmp) {
706 CHECK(0 <= shamt && shamt <= 4) << shamt;
707 CHECK_NE(src_base, tmp);
708 if (shamt == TIMES_1) {
709 // Catch the special case where the shift amount is zero (0).
710 Addu(dst, src_base, src_idx);
Lena Djokic0758ae72017-05-23 11:06:23 +0200711 } else if (IsR6() || HasMsa()) {
Chris Larsencd0295d2017-03-31 15:26:54 -0700712 Lsa(dst, src_idx, src_base, shamt);
713 } else {
714 Sll(tmp, src_idx, shamt);
715 Addu(dst, src_base, tmp);
716 }
717}
718
jeffhao7fbee072012-08-24 17:56:54 -0700719void MipsAssembler::Lb(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700720 DsFsmInstr(EmitI(0x20, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700721}
722
723void MipsAssembler::Lh(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700724 DsFsmInstr(EmitI(0x21, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700725}
726
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700727void MipsAssembler::Lw(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label) {
728 if (patcher_label != nullptr) {
729 Bind(patcher_label);
730 }
Alexey Frunzea247dea2017-11-03 18:43:04 -0700731 DsFsmInstr(EmitI(0x23, rs, rt, imm16), patcher_label).GprOuts(rt).GprIns(rs);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700732}
733
jeffhao7fbee072012-08-24 17:56:54 -0700734void MipsAssembler::Lw(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700735 Lw(rt, rs, imm16, /* patcher_label */ nullptr);
jeffhao7fbee072012-08-24 17:56:54 -0700736}
737
Chris Larsen3acee732015-11-18 13:31:08 -0800738void MipsAssembler::Lwl(Register rt, Register rs, uint16_t imm16) {
739 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700740 DsFsmInstr(EmitI(0x22, rs, rt, imm16)).GprInOuts(rt).GprIns(rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800741}
742
743void MipsAssembler::Lwr(Register rt, Register rs, uint16_t imm16) {
744 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700745 DsFsmInstr(EmitI(0x26, rs, rt, imm16)).GprInOuts(rt).GprIns(rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800746}
747
jeffhao7fbee072012-08-24 17:56:54 -0700748void MipsAssembler::Lbu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700749 DsFsmInstr(EmitI(0x24, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700750}
751
752void MipsAssembler::Lhu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700753 DsFsmInstr(EmitI(0x25, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700754}
755
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700756void MipsAssembler::Lwpc(Register rs, uint32_t imm19) {
757 CHECK(IsR6());
758 CHECK(IsUint<19>(imm19)) << imm19;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700759 DsFsmInstrNop(EmitI21(0x3B, rs, (0x01 << 19) | imm19));
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700760}
761
jeffhao7fbee072012-08-24 17:56:54 -0700762void MipsAssembler::Lui(Register rt, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700763 DsFsmInstr(EmitI(0xf, static_cast<Register>(0), rt, imm16)).GprOuts(rt);
jeffhao7fbee072012-08-24 17:56:54 -0700764}
765
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700766void MipsAssembler::Aui(Register rt, Register rs, uint16_t imm16) {
767 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700768 DsFsmInstr(EmitI(0xf, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700769}
770
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700771void MipsAssembler::AddUpper(Register rt, Register rs, uint16_t imm16, Register tmp) {
772 bool increment = (rs == rt);
773 if (increment) {
774 CHECK_NE(rs, tmp);
775 }
776 if (IsR6()) {
777 Aui(rt, rs, imm16);
778 } else if (increment) {
779 Lui(tmp, imm16);
780 Addu(rt, rs, tmp);
781 } else {
782 Lui(rt, imm16);
783 Addu(rt, rs, rt);
784 }
785}
786
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200787void MipsAssembler::Sync(uint32_t stype) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700788 DsFsmInstrNop(EmitR(0, ZERO, ZERO, ZERO, stype & 0x1f, 0xf));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200789}
790
jeffhao7fbee072012-08-24 17:56:54 -0700791void MipsAssembler::Mfhi(Register rd) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200792 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700793 DsFsmInstr(EmitR(0, ZERO, ZERO, rd, 0, 0x10)).GprOuts(rd);
jeffhao7fbee072012-08-24 17:56:54 -0700794}
795
796void MipsAssembler::Mflo(Register rd) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200797 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700798 DsFsmInstr(EmitR(0, ZERO, ZERO, rd, 0, 0x12)).GprOuts(rd);
jeffhao7fbee072012-08-24 17:56:54 -0700799}
800
801void MipsAssembler::Sb(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700802 DsFsmInstr(EmitI(0x28, rs, rt, imm16)).GprIns(rt, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700803}
804
805void MipsAssembler::Sh(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700806 DsFsmInstr(EmitI(0x29, rs, rt, imm16)).GprIns(rt, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700807}
808
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700809void MipsAssembler::Sw(Register rt, Register rs, uint16_t imm16, MipsLabel* patcher_label) {
810 if (patcher_label != nullptr) {
811 Bind(patcher_label);
812 }
Alexey Frunzea247dea2017-11-03 18:43:04 -0700813 DsFsmInstr(EmitI(0x2b, rs, rt, imm16), patcher_label).GprIns(rt, rs);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700814}
815
jeffhao7fbee072012-08-24 17:56:54 -0700816void MipsAssembler::Sw(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700817 Sw(rt, rs, imm16, /* patcher_label */ nullptr);
jeffhao7fbee072012-08-24 17:56:54 -0700818}
819
Chris Larsen3acee732015-11-18 13:31:08 -0800820void MipsAssembler::Swl(Register rt, Register rs, uint16_t imm16) {
821 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700822 DsFsmInstr(EmitI(0x2a, rs, rt, imm16)).GprIns(rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800823}
824
825void MipsAssembler::Swr(Register rt, Register rs, uint16_t imm16) {
826 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700827 DsFsmInstr(EmitI(0x2e, rs, rt, imm16)).GprIns(rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800828}
829
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700830void MipsAssembler::LlR2(Register rt, Register base, int16_t imm16) {
831 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700832 DsFsmInstr(EmitI(0x30, base, rt, imm16)).GprOuts(rt).GprIns(base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700833}
834
835void MipsAssembler::ScR2(Register rt, Register base, int16_t imm16) {
836 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -0700837 DsFsmInstr(EmitI(0x38, base, rt, imm16)).GprInOuts(rt).GprIns(base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700838}
839
840void MipsAssembler::LlR6(Register rt, Register base, int16_t imm9) {
841 CHECK(IsR6());
842 CHECK(IsInt<9>(imm9));
Alexey Frunzea247dea2017-11-03 18:43:04 -0700843 DsFsmInstr(EmitI(0x1f, base, rt, ((imm9 & 0x1ff) << 7) | 0x36)).GprOuts(rt).GprIns(base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700844}
845
846void MipsAssembler::ScR6(Register rt, Register base, int16_t imm9) {
847 CHECK(IsR6());
848 CHECK(IsInt<9>(imm9));
Alexey Frunzea247dea2017-11-03 18:43:04 -0700849 DsFsmInstr(EmitI(0x1f, base, rt, ((imm9 & 0x1ff) << 7) | 0x26)).GprInOuts(rt).GprIns(base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700850}
851
jeffhao7fbee072012-08-24 17:56:54 -0700852void MipsAssembler::Slt(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700853 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x2a)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700854}
855
856void MipsAssembler::Sltu(Register rd, Register rs, Register rt) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700857 DsFsmInstr(EmitR(0, rs, rt, rd, 0, 0x2b)).GprOuts(rd).GprIns(rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700858}
859
860void MipsAssembler::Slti(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700861 DsFsmInstr(EmitI(0xa, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700862}
863
864void MipsAssembler::Sltiu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -0700865 DsFsmInstr(EmitI(0xb, rs, rt, imm16)).GprOuts(rt).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -0700866}
867
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200868void MipsAssembler::B(uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700869 DsFsmInstrNop(EmitI(0x4, static_cast<Register>(0), static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200870}
871
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700872void MipsAssembler::Bal(uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700873 DsFsmInstrNop(EmitI(0x1, static_cast<Register>(0), static_cast<Register>(0x11), imm16));
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700874}
875
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200876void MipsAssembler::Beq(Register rs, Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700877 DsFsmInstrNop(EmitI(0x4, rs, rt, imm16));
jeffhao7fbee072012-08-24 17:56:54 -0700878}
879
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200880void MipsAssembler::Bne(Register rs, Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700881 DsFsmInstrNop(EmitI(0x5, rs, rt, imm16));
jeffhao7fbee072012-08-24 17:56:54 -0700882}
883
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200884void MipsAssembler::Beqz(Register rt, uint16_t imm16) {
Alexey Frunze0cab6562017-07-25 15:19:36 -0700885 Beq(rt, ZERO, imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700886}
887
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200888void MipsAssembler::Bnez(Register rt, uint16_t imm16) {
Alexey Frunze0cab6562017-07-25 15:19:36 -0700889 Bne(rt, ZERO, imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700890}
891
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200892void MipsAssembler::Bltz(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700893 DsFsmInstrNop(EmitI(0x1, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200894}
895
896void MipsAssembler::Bgez(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700897 DsFsmInstrNop(EmitI(0x1, rt, static_cast<Register>(0x1), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200898}
899
900void MipsAssembler::Blez(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700901 DsFsmInstrNop(EmitI(0x6, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200902}
903
904void MipsAssembler::Bgtz(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700905 DsFsmInstrNop(EmitI(0x7, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200906}
907
Chris Larsenb74353a2015-11-20 09:07:09 -0800908void MipsAssembler::Bc1f(uint16_t imm16) {
909 Bc1f(0, imm16);
910}
911
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800912void MipsAssembler::Bc1f(int cc, uint16_t imm16) {
913 CHECK(!IsR6());
914 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700915 DsFsmInstrNop(EmitI(0x11, static_cast<Register>(0x8), static_cast<Register>(cc << 2), imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800916}
917
Chris Larsenb74353a2015-11-20 09:07:09 -0800918void MipsAssembler::Bc1t(uint16_t imm16) {
919 Bc1t(0, imm16);
920}
921
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800922void MipsAssembler::Bc1t(int cc, uint16_t imm16) {
923 CHECK(!IsR6());
924 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700925 DsFsmInstrNop(EmitI(0x11,
926 static_cast<Register>(0x8),
927 static_cast<Register>((cc << 2) | 1),
928 imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800929}
930
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200931void MipsAssembler::J(uint32_t addr26) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700932 DsFsmInstrNop(EmitI26(0x2, addr26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200933}
934
935void MipsAssembler::Jal(uint32_t addr26) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700936 DsFsmInstrNop(EmitI26(0x3, addr26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200937}
938
939void MipsAssembler::Jalr(Register rd, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700940 uint32_t last_instruction = delay_slot_.instruction_;
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700941 MipsLabel* patcher_label = delay_slot_.patcher_label_;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700942 bool exchange = (last_instruction != 0 &&
Alexey Frunzea247dea2017-11-03 18:43:04 -0700943 (delay_slot_.masks_.gpr_outs_ & (1u << rs)) == 0 &&
944 ((delay_slot_.masks_.gpr_ins_ | delay_slot_.masks_.gpr_outs_) & (1u << rd)) == 0);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700945 if (exchange) {
946 // The last instruction cannot be used in a different delay slot,
947 // do not commit the label before it (if any).
948 DsFsmDropLabel();
949 }
950 DsFsmInstrNop(EmitR(0, rs, static_cast<Register>(0), rd, 0, 0x09));
951 if (exchange) {
952 // Exchange the last two instructions in the assembler buffer.
953 size_t size = buffer_.Size();
954 CHECK_GE(size, 2 * sizeof(uint32_t));
955 size_t pos1 = size - 2 * sizeof(uint32_t);
956 size_t pos2 = size - sizeof(uint32_t);
957 uint32_t instr1 = buffer_.Load<uint32_t>(pos1);
958 uint32_t instr2 = buffer_.Load<uint32_t>(pos2);
959 CHECK_EQ(instr1, last_instruction);
960 buffer_.Store<uint32_t>(pos1, instr2);
961 buffer_.Store<uint32_t>(pos2, instr1);
Alexey Frunzea663d9d2017-07-31 18:43:18 -0700962 // Move the patcher label along with the patched instruction.
963 if (patcher_label != nullptr) {
964 patcher_label->AdjustBoundPosition(sizeof(uint32_t));
965 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700966 } else if (reordering_) {
967 Nop();
968 }
jeffhao7fbee072012-08-24 17:56:54 -0700969}
970
971void MipsAssembler::Jalr(Register rs) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200972 Jalr(RA, rs);
973}
974
975void MipsAssembler::Jr(Register rs) {
976 Jalr(ZERO, rs);
977}
978
979void MipsAssembler::Nal() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700980 DsFsmInstrNop(EmitI(0x1, static_cast<Register>(0), static_cast<Register>(0x10), 0));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200981}
982
983void MipsAssembler::Auipc(Register rs, uint16_t imm16) {
984 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700985 DsFsmInstrNop(EmitI(0x3B, rs, static_cast<Register>(0x1E), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200986}
987
988void MipsAssembler::Addiupc(Register rs, uint32_t imm19) {
989 CHECK(IsR6());
990 CHECK(IsUint<19>(imm19)) << imm19;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700991 DsFsmInstrNop(EmitI21(0x3B, rs, imm19));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200992}
993
994void MipsAssembler::Bc(uint32_t imm26) {
995 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700996 DsFsmInstrNop(EmitI26(0x32, imm26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200997}
998
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700999void MipsAssembler::Balc(uint32_t imm26) {
1000 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001001 DsFsmInstrNop(EmitI26(0x3A, imm26));
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001002}
1003
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001004void MipsAssembler::Jic(Register rt, uint16_t imm16) {
1005 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001006 DsFsmInstrNop(EmitI(0x36, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001007}
1008
1009void MipsAssembler::Jialc(Register rt, uint16_t imm16) {
1010 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001011 DsFsmInstrNop(EmitI(0x3E, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001012}
1013
1014void MipsAssembler::Bltc(Register rs, Register rt, uint16_t imm16) {
1015 CHECK(IsR6());
1016 CHECK_NE(rs, ZERO);
1017 CHECK_NE(rt, ZERO);
1018 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001019 DsFsmInstrNop(EmitI(0x17, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001020}
1021
1022void MipsAssembler::Bltzc(Register rt, uint16_t imm16) {
1023 CHECK(IsR6());
1024 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001025 DsFsmInstrNop(EmitI(0x17, rt, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001026}
1027
1028void MipsAssembler::Bgtzc(Register rt, uint16_t imm16) {
1029 CHECK(IsR6());
1030 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001031 DsFsmInstrNop(EmitI(0x17, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001032}
1033
1034void MipsAssembler::Bgec(Register rs, Register rt, uint16_t imm16) {
1035 CHECK(IsR6());
1036 CHECK_NE(rs, ZERO);
1037 CHECK_NE(rt, ZERO);
1038 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001039 DsFsmInstrNop(EmitI(0x16, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001040}
1041
1042void MipsAssembler::Bgezc(Register rt, uint16_t imm16) {
1043 CHECK(IsR6());
1044 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001045 DsFsmInstrNop(EmitI(0x16, rt, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001046}
1047
1048void MipsAssembler::Blezc(Register rt, uint16_t imm16) {
1049 CHECK(IsR6());
1050 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001051 DsFsmInstrNop(EmitI(0x16, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001052}
1053
1054void MipsAssembler::Bltuc(Register rs, Register rt, uint16_t imm16) {
1055 CHECK(IsR6());
1056 CHECK_NE(rs, ZERO);
1057 CHECK_NE(rt, ZERO);
1058 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001059 DsFsmInstrNop(EmitI(0x7, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001060}
1061
1062void MipsAssembler::Bgeuc(Register rs, Register rt, uint16_t imm16) {
1063 CHECK(IsR6());
1064 CHECK_NE(rs, ZERO);
1065 CHECK_NE(rt, ZERO);
1066 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001067 DsFsmInstrNop(EmitI(0x6, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001068}
1069
1070void MipsAssembler::Beqc(Register rs, Register rt, uint16_t imm16) {
1071 CHECK(IsR6());
1072 CHECK_NE(rs, ZERO);
1073 CHECK_NE(rt, ZERO);
1074 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001075 DsFsmInstrNop(EmitI(0x8, std::min(rs, rt), std::max(rs, rt), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001076}
1077
1078void MipsAssembler::Bnec(Register rs, Register rt, uint16_t imm16) {
1079 CHECK(IsR6());
1080 CHECK_NE(rs, ZERO);
1081 CHECK_NE(rt, ZERO);
1082 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001083 DsFsmInstrNop(EmitI(0x18, std::min(rs, rt), std::max(rs, rt), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001084}
1085
1086void MipsAssembler::Beqzc(Register rs, uint32_t imm21) {
1087 CHECK(IsR6());
1088 CHECK_NE(rs, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001089 DsFsmInstrNop(EmitI21(0x36, rs, imm21));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001090}
1091
1092void MipsAssembler::Bnezc(Register rs, uint32_t imm21) {
1093 CHECK(IsR6());
1094 CHECK_NE(rs, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001095 DsFsmInstrNop(EmitI21(0x3E, rs, imm21));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001096}
1097
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001098void MipsAssembler::Bc1eqz(FRegister ft, uint16_t imm16) {
1099 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001100 DsFsmInstrNop(EmitFI(0x11, 0x9, ft, imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001101}
1102
1103void MipsAssembler::Bc1nez(FRegister ft, uint16_t imm16) {
1104 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001105 DsFsmInstrNop(EmitFI(0x11, 0xD, ft, imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001106}
1107
1108void MipsAssembler::EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001109 switch (cond) {
1110 case kCondLTZ:
1111 CHECK_EQ(rt, ZERO);
1112 Bltz(rs, imm16);
1113 break;
1114 case kCondGEZ:
1115 CHECK_EQ(rt, ZERO);
1116 Bgez(rs, imm16);
1117 break;
1118 case kCondLEZ:
1119 CHECK_EQ(rt, ZERO);
1120 Blez(rs, imm16);
1121 break;
1122 case kCondGTZ:
1123 CHECK_EQ(rt, ZERO);
1124 Bgtz(rs, imm16);
1125 break;
1126 case kCondEQ:
1127 Beq(rs, rt, imm16);
1128 break;
1129 case kCondNE:
1130 Bne(rs, rt, imm16);
1131 break;
1132 case kCondEQZ:
1133 CHECK_EQ(rt, ZERO);
1134 Beqz(rs, imm16);
1135 break;
1136 case kCondNEZ:
1137 CHECK_EQ(rt, ZERO);
1138 Bnez(rs, imm16);
1139 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001140 case kCondF:
1141 CHECK_EQ(rt, ZERO);
1142 Bc1f(static_cast<int>(rs), imm16);
1143 break;
1144 case kCondT:
1145 CHECK_EQ(rt, ZERO);
1146 Bc1t(static_cast<int>(rs), imm16);
1147 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001148 case kCondLT:
1149 case kCondGE:
1150 case kCondLE:
1151 case kCondGT:
1152 case kCondLTU:
1153 case kCondGEU:
1154 case kUncond:
1155 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
1156 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
1157 LOG(FATAL) << "Unexpected branch condition " << cond;
1158 UNREACHABLE();
1159 }
1160}
1161
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001162void MipsAssembler::EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001163 switch (cond) {
1164 case kCondLT:
1165 Bltc(rs, rt, imm16_21);
1166 break;
1167 case kCondGE:
1168 Bgec(rs, rt, imm16_21);
1169 break;
1170 case kCondLE:
1171 Bgec(rt, rs, imm16_21);
1172 break;
1173 case kCondGT:
1174 Bltc(rt, rs, imm16_21);
1175 break;
1176 case kCondLTZ:
1177 CHECK_EQ(rt, ZERO);
1178 Bltzc(rs, imm16_21);
1179 break;
1180 case kCondGEZ:
1181 CHECK_EQ(rt, ZERO);
1182 Bgezc(rs, imm16_21);
1183 break;
1184 case kCondLEZ:
1185 CHECK_EQ(rt, ZERO);
1186 Blezc(rs, imm16_21);
1187 break;
1188 case kCondGTZ:
1189 CHECK_EQ(rt, ZERO);
1190 Bgtzc(rs, imm16_21);
1191 break;
1192 case kCondEQ:
1193 Beqc(rs, rt, imm16_21);
1194 break;
1195 case kCondNE:
1196 Bnec(rs, rt, imm16_21);
1197 break;
1198 case kCondEQZ:
1199 CHECK_EQ(rt, ZERO);
1200 Beqzc(rs, imm16_21);
1201 break;
1202 case kCondNEZ:
1203 CHECK_EQ(rt, ZERO);
1204 Bnezc(rs, imm16_21);
1205 break;
1206 case kCondLTU:
1207 Bltuc(rs, rt, imm16_21);
1208 break;
1209 case kCondGEU:
1210 Bgeuc(rs, rt, imm16_21);
1211 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001212 case kCondF:
1213 CHECK_EQ(rt, ZERO);
1214 Bc1eqz(static_cast<FRegister>(rs), imm16_21);
1215 break;
1216 case kCondT:
1217 CHECK_EQ(rt, ZERO);
1218 Bc1nez(static_cast<FRegister>(rs), imm16_21);
1219 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001220 case kUncond:
1221 LOG(FATAL) << "Unexpected branch condition " << cond;
1222 UNREACHABLE();
1223 }
jeffhao7fbee072012-08-24 17:56:54 -07001224}
1225
1226void MipsAssembler::AddS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001227 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x0)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001228}
1229
1230void MipsAssembler::SubS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001231 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x1)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001232}
1233
1234void MipsAssembler::MulS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001235 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x2)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001236}
1237
1238void MipsAssembler::DivS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001239 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x3)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001240}
1241
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001242void MipsAssembler::AddD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001243 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x0)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001244}
1245
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001246void MipsAssembler::SubD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001247 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x1)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001248}
1249
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001250void MipsAssembler::MulD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001251 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x2)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001252}
1253
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001254void MipsAssembler::DivD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001255 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x3)).FprOuts(fd).FprIns(fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001256}
1257
Chris Larsenb74353a2015-11-20 09:07:09 -08001258void MipsAssembler::SqrtS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001259 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x4)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001260}
1261
1262void MipsAssembler::SqrtD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001263 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x4)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001264}
1265
1266void MipsAssembler::AbsS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001267 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x5)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001268}
1269
1270void MipsAssembler::AbsD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001271 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x5)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001272}
1273
jeffhao7fbee072012-08-24 17:56:54 -07001274void MipsAssembler::MovS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001275 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x6)).FprOuts(fd).FprIns(fs);
jeffhao7fbee072012-08-24 17:56:54 -07001276}
1277
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001278void MipsAssembler::MovD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001279 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x6)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001280}
1281
1282void MipsAssembler::NegS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001283 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x7)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001284}
1285
1286void MipsAssembler::NegD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001287 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x7)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001288}
1289
Chris Larsenb74353a2015-11-20 09:07:09 -08001290void MipsAssembler::CunS(FRegister fs, FRegister ft) {
1291 CunS(0, fs, ft);
1292}
1293
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001294void MipsAssembler::CunS(int cc, FRegister fs, FRegister ft) {
1295 CHECK(!IsR6());
1296 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001297 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x31))
1298 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001299}
1300
Chris Larsenb74353a2015-11-20 09:07:09 -08001301void MipsAssembler::CeqS(FRegister fs, FRegister ft) {
1302 CeqS(0, fs, ft);
1303}
1304
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001305void MipsAssembler::CeqS(int cc, FRegister fs, FRegister ft) {
1306 CHECK(!IsR6());
1307 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001308 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x32))
1309 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001310}
1311
Chris Larsenb74353a2015-11-20 09:07:09 -08001312void MipsAssembler::CueqS(FRegister fs, FRegister ft) {
1313 CueqS(0, fs, ft);
1314}
1315
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001316void MipsAssembler::CueqS(int cc, FRegister fs, FRegister ft) {
1317 CHECK(!IsR6());
1318 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001319 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x33))
1320 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001321}
1322
Chris Larsenb74353a2015-11-20 09:07:09 -08001323void MipsAssembler::ColtS(FRegister fs, FRegister ft) {
1324 ColtS(0, fs, ft);
1325}
1326
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001327void MipsAssembler::ColtS(int cc, FRegister fs, FRegister ft) {
1328 CHECK(!IsR6());
1329 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001330 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x34))
1331 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001332}
1333
Chris Larsenb74353a2015-11-20 09:07:09 -08001334void MipsAssembler::CultS(FRegister fs, FRegister ft) {
1335 CultS(0, fs, ft);
1336}
1337
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001338void MipsAssembler::CultS(int cc, FRegister fs, FRegister ft) {
1339 CHECK(!IsR6());
1340 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001341 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x35))
1342 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001343}
1344
Chris Larsenb74353a2015-11-20 09:07:09 -08001345void MipsAssembler::ColeS(FRegister fs, FRegister ft) {
1346 ColeS(0, fs, ft);
1347}
1348
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001349void MipsAssembler::ColeS(int cc, FRegister fs, FRegister ft) {
1350 CHECK(!IsR6());
1351 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001352 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x36))
1353 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001354}
1355
Chris Larsenb74353a2015-11-20 09:07:09 -08001356void MipsAssembler::CuleS(FRegister fs, FRegister ft) {
1357 CuleS(0, fs, ft);
1358}
1359
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001360void MipsAssembler::CuleS(int cc, FRegister fs, FRegister ft) {
1361 CHECK(!IsR6());
1362 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001363 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x37))
1364 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001365}
1366
Chris Larsenb74353a2015-11-20 09:07:09 -08001367void MipsAssembler::CunD(FRegister fs, FRegister ft) {
1368 CunD(0, fs, ft);
1369}
1370
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001371void MipsAssembler::CunD(int cc, FRegister fs, FRegister ft) {
1372 CHECK(!IsR6());
1373 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001374 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x31))
1375 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001376}
1377
Chris Larsenb74353a2015-11-20 09:07:09 -08001378void MipsAssembler::CeqD(FRegister fs, FRegister ft) {
1379 CeqD(0, fs, ft);
1380}
1381
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001382void MipsAssembler::CeqD(int cc, FRegister fs, FRegister ft) {
1383 CHECK(!IsR6());
1384 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001385 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x32))
1386 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001387}
1388
Chris Larsenb74353a2015-11-20 09:07:09 -08001389void MipsAssembler::CueqD(FRegister fs, FRegister ft) {
1390 CueqD(0, fs, ft);
1391}
1392
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001393void MipsAssembler::CueqD(int cc, FRegister fs, FRegister ft) {
1394 CHECK(!IsR6());
1395 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001396 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x33))
1397 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001398}
1399
Chris Larsenb74353a2015-11-20 09:07:09 -08001400void MipsAssembler::ColtD(FRegister fs, FRegister ft) {
1401 ColtD(0, fs, ft);
1402}
1403
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001404void MipsAssembler::ColtD(int cc, FRegister fs, FRegister ft) {
1405 CHECK(!IsR6());
1406 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001407 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x34))
1408 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001409}
1410
Chris Larsenb74353a2015-11-20 09:07:09 -08001411void MipsAssembler::CultD(FRegister fs, FRegister ft) {
1412 CultD(0, fs, ft);
1413}
1414
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001415void MipsAssembler::CultD(int cc, FRegister fs, FRegister ft) {
1416 CHECK(!IsR6());
1417 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001418 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x35))
1419 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001420}
1421
Chris Larsenb74353a2015-11-20 09:07:09 -08001422void MipsAssembler::ColeD(FRegister fs, FRegister ft) {
1423 ColeD(0, fs, ft);
1424}
1425
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001426void MipsAssembler::ColeD(int cc, FRegister fs, FRegister ft) {
1427 CHECK(!IsR6());
1428 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001429 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x36))
1430 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001431}
1432
Chris Larsenb74353a2015-11-20 09:07:09 -08001433void MipsAssembler::CuleD(FRegister fs, FRegister ft) {
1434 CuleD(0, fs, ft);
1435}
1436
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001437void MipsAssembler::CuleD(int cc, FRegister fs, FRegister ft) {
1438 CHECK(!IsR6());
1439 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001440 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x37))
1441 .CcOuts(cc).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001442}
1443
1444void MipsAssembler::CmpUnS(FRegister fd, FRegister fs, FRegister ft) {
1445 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001446 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x01)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001447}
1448
1449void MipsAssembler::CmpEqS(FRegister fd, FRegister fs, FRegister ft) {
1450 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001451 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x02)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001452}
1453
1454void MipsAssembler::CmpUeqS(FRegister fd, FRegister fs, FRegister ft) {
1455 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001456 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x03)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001457}
1458
1459void MipsAssembler::CmpLtS(FRegister fd, FRegister fs, FRegister ft) {
1460 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001461 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x04)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001462}
1463
1464void MipsAssembler::CmpUltS(FRegister fd, FRegister fs, FRegister ft) {
1465 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001466 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x05)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001467}
1468
1469void MipsAssembler::CmpLeS(FRegister fd, FRegister fs, FRegister ft) {
1470 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001471 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x06)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001472}
1473
1474void MipsAssembler::CmpUleS(FRegister fd, FRegister fs, FRegister ft) {
1475 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001476 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x07)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001477}
1478
1479void MipsAssembler::CmpOrS(FRegister fd, FRegister fs, FRegister ft) {
1480 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001481 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x11)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001482}
1483
1484void MipsAssembler::CmpUneS(FRegister fd, FRegister fs, FRegister ft) {
1485 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001486 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x12)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001487}
1488
1489void MipsAssembler::CmpNeS(FRegister fd, FRegister fs, FRegister ft) {
1490 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001491 DsFsmInstr(EmitFR(0x11, 0x14, ft, fs, fd, 0x13)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001492}
1493
1494void MipsAssembler::CmpUnD(FRegister fd, FRegister fs, FRegister ft) {
1495 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001496 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x01)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001497}
1498
1499void MipsAssembler::CmpEqD(FRegister fd, FRegister fs, FRegister ft) {
1500 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001501 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x02)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001502}
1503
1504void MipsAssembler::CmpUeqD(FRegister fd, FRegister fs, FRegister ft) {
1505 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001506 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x03)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001507}
1508
1509void MipsAssembler::CmpLtD(FRegister fd, FRegister fs, FRegister ft) {
1510 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001511 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x04)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001512}
1513
1514void MipsAssembler::CmpUltD(FRegister fd, FRegister fs, FRegister ft) {
1515 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001516 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x05)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001517}
1518
1519void MipsAssembler::CmpLeD(FRegister fd, FRegister fs, FRegister ft) {
1520 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001521 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x06)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001522}
1523
1524void MipsAssembler::CmpUleD(FRegister fd, FRegister fs, FRegister ft) {
1525 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001526 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x07)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001527}
1528
1529void MipsAssembler::CmpOrD(FRegister fd, FRegister fs, FRegister ft) {
1530 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001531 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x11)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001532}
1533
1534void MipsAssembler::CmpUneD(FRegister fd, FRegister fs, FRegister ft) {
1535 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001536 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x12)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001537}
1538
1539void MipsAssembler::CmpNeD(FRegister fd, FRegister fs, FRegister ft) {
1540 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001541 DsFsmInstr(EmitFR(0x11, 0x15, ft, fs, fd, 0x13)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001542}
1543
1544void MipsAssembler::Movf(Register rd, Register rs, int cc) {
1545 CHECK(!IsR6());
1546 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001547 DsFsmInstr(EmitR(0, rs, static_cast<Register>(cc << 2), rd, 0, 0x01))
1548 .GprInOuts(rd).GprIns(rs).CcIns(cc);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001549}
1550
1551void MipsAssembler::Movt(Register rd, Register rs, int cc) {
1552 CHECK(!IsR6());
1553 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001554 DsFsmInstr(EmitR(0, rs, static_cast<Register>((cc << 2) | 1), rd, 0, 0x01))
1555 .GprInOuts(rd).GprIns(rs).CcIns(cc);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001556}
1557
Chris Larsenb74353a2015-11-20 09:07:09 -08001558void MipsAssembler::MovfS(FRegister fd, FRegister fs, int cc) {
1559 CHECK(!IsR6());
1560 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001561 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(cc << 2), fs, fd, 0x11))
1562 .FprInOuts(fd).FprIns(fs).CcIns(cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001563}
1564
1565void MipsAssembler::MovfD(FRegister fd, FRegister fs, int cc) {
1566 CHECK(!IsR6());
1567 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001568 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(cc << 2), fs, fd, 0x11))
1569 .FprInOuts(fd).FprIns(fs).CcIns(cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001570}
1571
1572void MipsAssembler::MovtS(FRegister fd, FRegister fs, int cc) {
1573 CHECK(!IsR6());
1574 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001575 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>((cc << 2) | 1), fs, fd, 0x11))
1576 .FprInOuts(fd).FprIns(fs).CcIns(cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001577}
1578
1579void MipsAssembler::MovtD(FRegister fd, FRegister fs, int cc) {
1580 CHECK(!IsR6());
1581 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunzea247dea2017-11-03 18:43:04 -07001582 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>((cc << 2) | 1), fs, fd, 0x11))
1583 .FprInOuts(fd).FprIns(fs).CcIns(cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001584}
1585
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001586void MipsAssembler::MovzS(FRegister fd, FRegister fs, Register rt) {
1587 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001588 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(rt), fs, fd, 0x12))
1589 .FprInOuts(fd).FprIns(fs).GprIns(rt);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001590}
1591
1592void MipsAssembler::MovzD(FRegister fd, FRegister fs, Register rt) {
1593 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001594 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(rt), fs, fd, 0x12))
1595 .FprInOuts(fd).FprIns(fs).GprIns(rt);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001596}
1597
1598void MipsAssembler::MovnS(FRegister fd, FRegister fs, Register rt) {
1599 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001600 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(rt), fs, fd, 0x13))
1601 .FprInOuts(fd).FprIns(fs).GprIns(rt);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001602}
1603
1604void MipsAssembler::MovnD(FRegister fd, FRegister fs, Register rt) {
1605 CHECK(!IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001606 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(rt), fs, fd, 0x13))
1607 .FprInOuts(fd).FprIns(fs).GprIns(rt);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001608}
1609
Chris Larsenb74353a2015-11-20 09:07:09 -08001610void MipsAssembler::SelS(FRegister fd, FRegister fs, FRegister ft) {
1611 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001612 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x10)).FprInOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001613}
1614
1615void MipsAssembler::SelD(FRegister fd, FRegister fs, FRegister ft) {
1616 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001617 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x10)).FprInOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001618}
1619
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001620void MipsAssembler::SeleqzS(FRegister fd, FRegister fs, FRegister ft) {
1621 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001622 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x14)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001623}
1624
1625void MipsAssembler::SeleqzD(FRegister fd, FRegister fs, FRegister ft) {
1626 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001627 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x14)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001628}
1629
1630void MipsAssembler::SelnezS(FRegister fd, FRegister fs, FRegister ft) {
1631 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001632 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x17)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001633}
1634
1635void MipsAssembler::SelnezD(FRegister fd, FRegister fs, FRegister ft) {
1636 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001637 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x17)).FprOuts(fd).FprIns(fs, ft);
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001638}
1639
Chris Larsenb74353a2015-11-20 09:07:09 -08001640void MipsAssembler::ClassS(FRegister fd, FRegister fs) {
1641 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001642 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x1b)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001643}
1644
1645void MipsAssembler::ClassD(FRegister fd, FRegister fs) {
1646 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001647 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x1b)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001648}
1649
1650void MipsAssembler::MinS(FRegister fd, FRegister fs, FRegister ft) {
1651 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001652 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x1c)).FprOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001653}
1654
1655void MipsAssembler::MinD(FRegister fd, FRegister fs, FRegister ft) {
1656 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001657 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x1c)).FprOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001658}
1659
1660void MipsAssembler::MaxS(FRegister fd, FRegister fs, FRegister ft) {
1661 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001662 DsFsmInstr(EmitFR(0x11, 0x10, ft, fs, fd, 0x1e)).FprOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001663}
1664
1665void MipsAssembler::MaxD(FRegister fd, FRegister fs, FRegister ft) {
1666 CHECK(IsR6());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001667 DsFsmInstr(EmitFR(0x11, 0x11, ft, fs, fd, 0x1e)).FprOuts(fd).FprIns(fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001668}
1669
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001670void MipsAssembler::TruncLS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001671 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x09)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001672}
1673
1674void MipsAssembler::TruncLD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001675 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x09)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001676}
1677
1678void MipsAssembler::TruncWS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001679 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x0D)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001680}
1681
1682void MipsAssembler::TruncWD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001683 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x0D)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001684}
1685
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001686void MipsAssembler::Cvtsw(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001687 DsFsmInstr(EmitFR(0x11, 0x14, static_cast<FRegister>(0), fs, fd, 0x20)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001688}
1689
1690void MipsAssembler::Cvtdw(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001691 DsFsmInstr(EmitFR(0x11, 0x14, static_cast<FRegister>(0), fs, fd, 0x21)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001692}
1693
1694void MipsAssembler::Cvtsd(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001695 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x20)).FprOuts(fd).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001696}
1697
1698void MipsAssembler::Cvtds(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001699 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x21)).FprOuts(fd).FprIns(fs);
jeffhao7fbee072012-08-24 17:56:54 -07001700}
1701
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001702void MipsAssembler::Cvtsl(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001703 DsFsmInstr(EmitFR(0x11, 0x15, static_cast<FRegister>(0), fs, fd, 0x20)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001704}
1705
1706void MipsAssembler::Cvtdl(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001707 DsFsmInstr(EmitFR(0x11, 0x15, static_cast<FRegister>(0), fs, fd, 0x21)).FprOuts(fd).FprIns(fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001708}
1709
Chris Larsenb74353a2015-11-20 09:07:09 -08001710void MipsAssembler::FloorWS(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001711 DsFsmInstr(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0xf)).FprOuts(fd).FprIns(fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001712}
1713
1714void MipsAssembler::FloorWD(FRegister fd, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001715 DsFsmInstr(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0xf)).FprOuts(fd).FprIns(fs);
1716}
1717
1718FRegister MipsAssembler::GetFpuRegLow(FRegister reg) {
1719 // If FPRs are 32-bit (and get paired to hold 64-bit values), accesses to
1720 // odd-numbered FPRs are reattributed to even-numbered FPRs. This lets us
1721 // use only even-numbered FPRs irrespective of whether we're doing single-
1722 // or double-precision arithmetic. (We don't use odd-numbered 32-bit FPRs
1723 // to hold single-precision values).
1724 return Is32BitFPU() ? static_cast<FRegister>(reg & ~1u) : reg;
Chris Larsenb74353a2015-11-20 09:07:09 -08001725}
1726
jeffhao7fbee072012-08-24 17:56:54 -07001727void MipsAssembler::Mfc1(Register rt, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001728 DsFsmInstr(EmitFR(0x11, 0x00, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0))
1729 .GprOuts(rt).FprIns(GetFpuRegLow(fs));
jeffhao7fbee072012-08-24 17:56:54 -07001730}
1731
Alexey Frunzea247dea2017-11-03 18:43:04 -07001732// Note, the 32 LSBs of a 64-bit value must be loaded into an FPR before the 32 MSBs
1733// when loading the value as 32-bit halves.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001734void MipsAssembler::Mtc1(Register rt, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001735 uint32_t encoding =
1736 EmitFR(0x11, 0x04, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0);
1737 if (Is32BitFPU() && (fs % 2 != 0)) {
1738 // If mtc1 is used to simulate mthc1 by writing to the odd-numbered FPR in
1739 // a pair of 32-bit FPRs, the associated even-numbered FPR is an in/out.
1740 DsFsmInstr(encoding).FprInOuts(GetFpuRegLow(fs)).GprIns(rt);
1741 } else {
1742 // Otherwise (the FPR is 64-bit or even-numbered), the FPR is an out.
1743 DsFsmInstr(encoding).FprOuts(fs).GprIns(rt);
1744 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001745}
1746
1747void MipsAssembler::Mfhc1(Register rt, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001748 DsFsmInstr(EmitFR(0x11, 0x03, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0))
1749 .GprOuts(rt).FprIns(fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001750}
1751
Alexey Frunzea247dea2017-11-03 18:43:04 -07001752// Note, the 32 LSBs of a 64-bit value must be loaded into an FPR before the 32 MSBs
1753// when loading the value as 32-bit halves.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001754void MipsAssembler::Mthc1(Register rt, FRegister fs) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001755 DsFsmInstr(EmitFR(0x11, 0x07, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0))
1756 .FprInOuts(fs).GprIns(rt);
jeffhao7fbee072012-08-24 17:56:54 -07001757}
1758
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001759void MipsAssembler::MoveFromFpuHigh(Register rt, FRegister fs) {
1760 if (Is32BitFPU()) {
1761 CHECK_EQ(fs % 2, 0) << fs;
1762 Mfc1(rt, static_cast<FRegister>(fs + 1));
1763 } else {
1764 Mfhc1(rt, fs);
1765 }
1766}
1767
1768void MipsAssembler::MoveToFpuHigh(Register rt, FRegister fs) {
1769 if (Is32BitFPU()) {
1770 CHECK_EQ(fs % 2, 0) << fs;
1771 Mtc1(rt, static_cast<FRegister>(fs + 1));
1772 } else {
1773 Mthc1(rt, fs);
1774 }
1775}
1776
Alexey Frunzea247dea2017-11-03 18:43:04 -07001777// Note, the 32 LSBs of a 64-bit value must be loaded into an FPR before the 32 MSBs
1778// when loading the value as 32-bit halves.
jeffhao7fbee072012-08-24 17:56:54 -07001779void MipsAssembler::Lwc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001780 uint32_t encoding = EmitI(0x31, rs, static_cast<Register>(ft), imm16);
1781 if (Is32BitFPU() && (ft % 2 != 0)) {
1782 // If lwc1 is used to load the odd-numbered FPR in a pair of 32-bit FPRs,
1783 // the associated even-numbered FPR is an in/out.
1784 DsFsmInstr(encoding).FprInOuts(GetFpuRegLow(ft)).GprIns(rs);
1785 } else {
1786 // Otherwise (the FPR is 64-bit or even-numbered), the FPR is an out.
1787 DsFsmInstr(encoding).FprOuts(ft).GprIns(rs);
1788 }
jeffhao7fbee072012-08-24 17:56:54 -07001789}
1790
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001791void MipsAssembler::Ldc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001792 DsFsmInstr(EmitI(0x35, rs, static_cast<Register>(ft), imm16)).FprOuts(ft).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -07001793}
1794
1795void MipsAssembler::Swc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001796 DsFsmInstr(EmitI(0x39, rs, static_cast<Register>(ft), imm16)).FprIns(GetFpuRegLow(ft)).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -07001797}
1798
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001799void MipsAssembler::Sdc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunzea247dea2017-11-03 18:43:04 -07001800 DsFsmInstr(EmitI(0x3d, rs, static_cast<Register>(ft), imm16)).FprIns(ft).GprIns(rs);
jeffhao7fbee072012-08-24 17:56:54 -07001801}
1802
1803void MipsAssembler::Break() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001804 DsFsmInstrNop(EmitR(0, ZERO, ZERO, ZERO, 0, 0xD));
jeffhao7fbee072012-08-24 17:56:54 -07001805}
1806
jeffhao07030602012-09-26 14:33:14 -07001807void MipsAssembler::Nop() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001808 DsFsmInstrNop(EmitR(0x0, ZERO, ZERO, ZERO, 0, 0x0));
1809}
1810
1811void MipsAssembler::NopIfNoReordering() {
1812 if (!reordering_) {
1813 Nop();
1814 }
jeffhao07030602012-09-26 14:33:14 -07001815}
1816
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001817void MipsAssembler::Move(Register rd, Register rs) {
1818 Or(rd, rs, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001819}
1820
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001821void MipsAssembler::Clear(Register rd) {
1822 Move(rd, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001823}
1824
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001825void MipsAssembler::Not(Register rd, Register rs) {
1826 Nor(rd, rs, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001827}
1828
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001829void MipsAssembler::Push(Register rs) {
Chris Larsen715f43e2017-10-23 11:00:32 -07001830 IncreaseFrameSize(kStackAlignment);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001831 Sw(rs, SP, 0);
jeffhao7fbee072012-08-24 17:56:54 -07001832}
1833
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001834void MipsAssembler::Pop(Register rd) {
1835 Lw(rd, SP, 0);
Chris Larsen715f43e2017-10-23 11:00:32 -07001836 DecreaseFrameSize(kStackAlignment);
jeffhao7fbee072012-08-24 17:56:54 -07001837}
1838
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001839void MipsAssembler::PopAndReturn(Register rd, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001840 bool reordering = SetReorder(false);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001841 Lw(rd, SP, 0);
1842 Jr(rt);
Chris Larsen715f43e2017-10-23 11:00:32 -07001843 DecreaseFrameSize(kStackAlignment); // Single instruction in delay slot.
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001844 SetReorder(reordering);
jeffhao7fbee072012-08-24 17:56:54 -07001845}
1846
Lena Djokic0758ae72017-05-23 11:06:23 +02001847void MipsAssembler::AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1848 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001849 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001850}
1851
1852void MipsAssembler::OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1853 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001854 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001855}
1856
1857void MipsAssembler::NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1858 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001859 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001860}
1861
1862void MipsAssembler::XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1863 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001864 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001865}
1866
1867void MipsAssembler::AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1868 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001869 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001870}
1871
1872void MipsAssembler::AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1873 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001874 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001875}
1876
1877void MipsAssembler::AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1878 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001879 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001880}
1881
1882void MipsAssembler::AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1883 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001884 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001885}
1886
1887void MipsAssembler::SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1888 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001889 DsFsmInstr(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001890}
1891
1892void MipsAssembler::SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1893 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001894 DsFsmInstr(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001895}
1896
1897void MipsAssembler::SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1898 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001899 DsFsmInstr(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001900}
1901
1902void MipsAssembler::SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1903 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001904 DsFsmInstr(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001905}
1906
1907void MipsAssembler::MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1908 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001909 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001910}
1911
1912void MipsAssembler::MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1913 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001914 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001915}
1916
1917void MipsAssembler::MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1918 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001919 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001920}
1921
1922void MipsAssembler::MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1923 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001924 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001925}
1926
1927void MipsAssembler::Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1928 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001929 DsFsmInstr(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001930}
1931
1932void MipsAssembler::Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1933 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001934 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001935}
1936
1937void MipsAssembler::Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1938 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001939 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001940}
1941
1942void MipsAssembler::Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1943 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001944 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001945}
1946
1947void MipsAssembler::Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1948 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001949 DsFsmInstr(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001950}
1951
1952void MipsAssembler::Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1953 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001954 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001955}
1956
1957void MipsAssembler::Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1958 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001959 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001960}
1961
1962void MipsAssembler::Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1963 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001964 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001965}
1966
1967void MipsAssembler::Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1968 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001969 DsFsmInstr(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001970}
1971
1972void MipsAssembler::Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1973 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001974 DsFsmInstr(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001975}
1976
1977void MipsAssembler::Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1978 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001979 DsFsmInstr(EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001980}
1981
1982void MipsAssembler::Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1983 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001984 DsFsmInstr(EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001985}
1986
1987void MipsAssembler::Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1988 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001989 DsFsmInstr(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001990}
1991
1992void MipsAssembler::Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1993 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001994 DsFsmInstr(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02001995}
1996
1997void MipsAssembler::Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1998 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07001999 DsFsmInstr(EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002000}
2001
2002void MipsAssembler::Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2003 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002004 DsFsmInstr(EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x12)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002005}
2006
2007void MipsAssembler::Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2008 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002009 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002010}
2011
2012void MipsAssembler::Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2013 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002014 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002015}
2016
2017void MipsAssembler::Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2018 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002019 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002020}
2021
2022void MipsAssembler::Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2023 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002024 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002025}
2026
2027void MipsAssembler::Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2028 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002029 DsFsmInstr(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002030}
2031
2032void MipsAssembler::Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2033 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002034 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002035}
2036
2037void MipsAssembler::Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2038 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002039 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002040}
2041
2042void MipsAssembler::Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2043 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002044 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002045}
2046
2047void MipsAssembler::Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2048 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002049 DsFsmInstr(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002050}
2051
2052void MipsAssembler::Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2053 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002054 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002055}
2056
2057void MipsAssembler::Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2058 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002059 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002060}
2061
2062void MipsAssembler::Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2063 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002064 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002065}
2066
2067void MipsAssembler::Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2068 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002069 DsFsmInstr(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002070}
2071
2072void MipsAssembler::Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2073 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002074 DsFsmInstr(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002075}
2076
2077void MipsAssembler::Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2078 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002079 DsFsmInstr(EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002080}
2081
2082void MipsAssembler::Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2083 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002084 DsFsmInstr(EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002085}
2086
2087void MipsAssembler::Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2088 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002089 DsFsmInstr(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002090}
2091
2092void MipsAssembler::Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2093 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002094 DsFsmInstr(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002095}
2096
2097void MipsAssembler::Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2098 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002099 DsFsmInstr(EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002100}
2101
2102void MipsAssembler::Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2103 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002104 DsFsmInstr(EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x10)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002105}
2106
2107void MipsAssembler::Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2108 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002109 DsFsmInstr(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002110}
2111
2112void MipsAssembler::Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2113 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002114 DsFsmInstr(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002115}
2116
2117void MipsAssembler::Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2118 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002119 DsFsmInstr(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002120}
2121
2122void MipsAssembler::Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2123 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002124 DsFsmInstr(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002125}
2126
2127void MipsAssembler::Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2128 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002129 DsFsmInstr(EmitMsa3R(0x3, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002130}
2131
2132void MipsAssembler::Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2133 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002134 DsFsmInstr(EmitMsa3R(0x3, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002135}
2136
2137void MipsAssembler::Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2138 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002139 DsFsmInstr(EmitMsa3R(0x3, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002140}
2141
2142void MipsAssembler::Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2143 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002144 DsFsmInstr(EmitMsa3R(0x3, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002145}
2146
2147void MipsAssembler::Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2148 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002149 DsFsmInstr(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002150}
2151
2152void MipsAssembler::Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2153 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002154 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002155}
2156
2157void MipsAssembler::Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2158 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002159 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002160}
2161
2162void MipsAssembler::Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2163 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002164 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002165}
2166
2167void MipsAssembler::Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2168 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002169 DsFsmInstr(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002170}
2171
2172void MipsAssembler::Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2173 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002174 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002175}
2176
2177void MipsAssembler::Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2178 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002179 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002180}
2181
2182void MipsAssembler::Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2183 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002184 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0xe)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002185}
2186
2187void MipsAssembler::FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2188 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002189 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002190}
2191
2192void MipsAssembler::FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2193 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002194 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002195}
2196
2197void MipsAssembler::FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2198 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002199 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002200}
2201
2202void MipsAssembler::FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2203 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002204 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002205}
2206
2207void MipsAssembler::FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2208 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002209 DsFsmInstr(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002210}
2211
2212void MipsAssembler::FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2213 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002214 DsFsmInstr(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002215}
2216
2217void MipsAssembler::FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2218 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002219 DsFsmInstr(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002220}
2221
2222void MipsAssembler::FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2223 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002224 DsFsmInstr(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002225}
2226
2227void MipsAssembler::FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2228 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002229 DsFsmInstr(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002230}
2231
2232void MipsAssembler::FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2233 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002234 DsFsmInstr(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002235}
2236
2237void MipsAssembler::FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2238 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002239 DsFsmInstr(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002240}
2241
2242void MipsAssembler::FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2243 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002244 DsFsmInstr(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x1b)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002245}
2246
2247void MipsAssembler::Ffint_sW(VectorRegister wd, VectorRegister ws) {
2248 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002249 DsFsmInstr(EmitMsa2RF(0x19e, 0x0, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002250}
2251
2252void MipsAssembler::Ffint_sD(VectorRegister wd, VectorRegister ws) {
2253 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002254 DsFsmInstr(EmitMsa2RF(0x19e, 0x1, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002255}
2256
2257void MipsAssembler::Ftint_sW(VectorRegister wd, VectorRegister ws) {
2258 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002259 DsFsmInstr(EmitMsa2RF(0x19c, 0x0, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002260}
2261
2262void MipsAssembler::Ftint_sD(VectorRegister wd, VectorRegister ws) {
2263 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002264 DsFsmInstr(EmitMsa2RF(0x19c, 0x1, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002265}
2266
2267void MipsAssembler::SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2268 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002269 DsFsmInstr(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002270}
2271
2272void MipsAssembler::SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2273 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002274 DsFsmInstr(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002275}
2276
2277void MipsAssembler::SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2278 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002279 DsFsmInstr(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002280}
2281
2282void MipsAssembler::SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2283 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002284 DsFsmInstr(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002285}
2286
2287void MipsAssembler::SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2288 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002289 DsFsmInstr(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002290}
2291
2292void MipsAssembler::SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2293 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002294 DsFsmInstr(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002295}
2296
2297void MipsAssembler::SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2298 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002299 DsFsmInstr(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002300}
2301
2302void MipsAssembler::SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2303 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002304 DsFsmInstr(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002305}
2306
2307void MipsAssembler::SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2308 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002309 DsFsmInstr(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002310}
2311
2312void MipsAssembler::SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2313 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002314 DsFsmInstr(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002315}
2316
2317void MipsAssembler::SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2318 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002319 DsFsmInstr(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002320}
2321
2322void MipsAssembler::SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2323 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002324 DsFsmInstr(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xd)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002325}
2326
2327void MipsAssembler::SlliB(VectorRegister wd, VectorRegister ws, int shamt3) {
2328 CHECK(HasMsa());
2329 CHECK(IsUint<3>(shamt3)) << shamt3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002330 DsFsmInstr(EmitMsaBIT(0x0, shamt3 | kMsaDfMByteMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002331}
2332
2333void MipsAssembler::SlliH(VectorRegister wd, VectorRegister ws, int shamt4) {
2334 CHECK(HasMsa());
2335 CHECK(IsUint<4>(shamt4)) << shamt4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002336 DsFsmInstr(EmitMsaBIT(0x0, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002337}
2338
2339void MipsAssembler::SlliW(VectorRegister wd, VectorRegister ws, int shamt5) {
2340 CHECK(HasMsa());
2341 CHECK(IsUint<5>(shamt5)) << shamt5;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002342 DsFsmInstr(EmitMsaBIT(0x0, shamt5 | kMsaDfMWordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002343}
2344
2345void MipsAssembler::SlliD(VectorRegister wd, VectorRegister ws, int shamt6) {
2346 CHECK(HasMsa());
2347 CHECK(IsUint<6>(shamt6)) << shamt6;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002348 DsFsmInstr(EmitMsaBIT(0x0, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002349}
2350
2351void MipsAssembler::SraiB(VectorRegister wd, VectorRegister ws, int shamt3) {
2352 CHECK(HasMsa());
2353 CHECK(IsUint<3>(shamt3)) << shamt3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002354 DsFsmInstr(EmitMsaBIT(0x1, shamt3 | kMsaDfMByteMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002355}
2356
2357void MipsAssembler::SraiH(VectorRegister wd, VectorRegister ws, int shamt4) {
2358 CHECK(HasMsa());
2359 CHECK(IsUint<4>(shamt4)) << shamt4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002360 DsFsmInstr(EmitMsaBIT(0x1, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002361}
2362
2363void MipsAssembler::SraiW(VectorRegister wd, VectorRegister ws, int shamt5) {
2364 CHECK(HasMsa());
2365 CHECK(IsUint<5>(shamt5)) << shamt5;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002366 DsFsmInstr(EmitMsaBIT(0x1, shamt5 | kMsaDfMWordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002367}
2368
2369void MipsAssembler::SraiD(VectorRegister wd, VectorRegister ws, int shamt6) {
2370 CHECK(HasMsa());
2371 CHECK(IsUint<6>(shamt6)) << shamt6;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002372 DsFsmInstr(EmitMsaBIT(0x1, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002373}
2374
2375void MipsAssembler::SrliB(VectorRegister wd, VectorRegister ws, int shamt3) {
2376 CHECK(HasMsa());
2377 CHECK(IsUint<3>(shamt3)) << shamt3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002378 DsFsmInstr(EmitMsaBIT(0x2, shamt3 | kMsaDfMByteMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002379}
2380
2381void MipsAssembler::SrliH(VectorRegister wd, VectorRegister ws, int shamt4) {
2382 CHECK(HasMsa());
2383 CHECK(IsUint<4>(shamt4)) << shamt4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002384 DsFsmInstr(EmitMsaBIT(0x2, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002385}
2386
2387void MipsAssembler::SrliW(VectorRegister wd, VectorRegister ws, int shamt5) {
2388 CHECK(HasMsa());
2389 CHECK(IsUint<5>(shamt5)) << shamt5;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002390 DsFsmInstr(EmitMsaBIT(0x2, shamt5 | kMsaDfMWordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002391}
2392
2393void MipsAssembler::SrliD(VectorRegister wd, VectorRegister ws, int shamt6) {
2394 CHECK(HasMsa());
2395 CHECK(IsUint<6>(shamt6)) << shamt6;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002396 DsFsmInstr(EmitMsaBIT(0x2, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002397}
2398
2399void MipsAssembler::MoveV(VectorRegister wd, VectorRegister ws) {
2400 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002401 DsFsmInstr(EmitMsaBIT(0x1, 0x3e, ws, wd, 0x19)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002402}
2403
2404void MipsAssembler::SplatiB(VectorRegister wd, VectorRegister ws, int n4) {
2405 CHECK(HasMsa());
2406 CHECK(IsUint<4>(n4)) << n4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002407 DsFsmInstr(EmitMsaELM(0x1, n4 | kMsaDfNByteMask, ws, wd, 0x19)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002408}
2409
2410void MipsAssembler::SplatiH(VectorRegister wd, VectorRegister ws, int n3) {
2411 CHECK(HasMsa());
2412 CHECK(IsUint<3>(n3)) << n3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002413 DsFsmInstr(EmitMsaELM(0x1, n3 | kMsaDfNHalfwordMask, ws, wd, 0x19)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002414}
2415
2416void MipsAssembler::SplatiW(VectorRegister wd, VectorRegister ws, int n2) {
2417 CHECK(HasMsa());
2418 CHECK(IsUint<2>(n2)) << n2;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002419 DsFsmInstr(EmitMsaELM(0x1, n2 | kMsaDfNWordMask, ws, wd, 0x19)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002420}
2421
2422void MipsAssembler::SplatiD(VectorRegister wd, VectorRegister ws, int n1) {
2423 CHECK(HasMsa());
2424 CHECK(IsUint<1>(n1)) << n1;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002425 DsFsmInstr(EmitMsaELM(0x1, n1 | kMsaDfNDoublewordMask, ws, wd, 0x19)).FprOuts(wd).FprIns(ws);
Lena Djokic0758ae72017-05-23 11:06:23 +02002426}
2427
Lena Djokic3309c012017-10-13 14:34:32 +02002428void MipsAssembler::Copy_sB(Register rd, VectorRegister ws, int n4) {
2429 CHECK(HasMsa());
2430 CHECK(IsUint<4>(n4)) << n4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002431 DsFsmInstr(EmitMsaELM(0x2, n4 | kMsaDfNByteMask, ws, static_cast<VectorRegister>(rd), 0x19))
2432 .GprOuts(rd).FprIns(ws);
Lena Djokic3309c012017-10-13 14:34:32 +02002433}
2434
2435void MipsAssembler::Copy_sH(Register rd, VectorRegister ws, int n3) {
2436 CHECK(HasMsa());
2437 CHECK(IsUint<3>(n3)) << n3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002438 DsFsmInstr(EmitMsaELM(0x2, n3 | kMsaDfNHalfwordMask, ws, static_cast<VectorRegister>(rd), 0x19))
2439 .GprOuts(rd).FprIns(ws);
Lena Djokic3309c012017-10-13 14:34:32 +02002440}
2441
2442void MipsAssembler::Copy_sW(Register rd, VectorRegister ws, int n2) {
2443 CHECK(HasMsa());
2444 CHECK(IsUint<2>(n2)) << n2;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002445 DsFsmInstr(EmitMsaELM(0x2, n2 | kMsaDfNWordMask, ws, static_cast<VectorRegister>(rd), 0x19))
2446 .GprOuts(rd).FprIns(ws);
Lena Djokic3309c012017-10-13 14:34:32 +02002447}
2448
2449void MipsAssembler::Copy_uB(Register rd, VectorRegister ws, int n4) {
2450 CHECK(HasMsa());
2451 CHECK(IsUint<4>(n4)) << n4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002452 DsFsmInstr(EmitMsaELM(0x3, n4 | kMsaDfNByteMask, ws, static_cast<VectorRegister>(rd), 0x19))
2453 .GprOuts(rd).FprIns(ws);
Lena Djokic3309c012017-10-13 14:34:32 +02002454}
2455
2456void MipsAssembler::Copy_uH(Register rd, VectorRegister ws, int n3) {
2457 CHECK(HasMsa());
2458 CHECK(IsUint<3>(n3)) << n3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002459 DsFsmInstr(EmitMsaELM(0x3, n3 | kMsaDfNHalfwordMask, ws, static_cast<VectorRegister>(rd), 0x19))
2460 .GprOuts(rd).FprIns(ws);
Lena Djokic3309c012017-10-13 14:34:32 +02002461}
2462
2463void MipsAssembler::InsertB(VectorRegister wd, Register rs, int n4) {
2464 CHECK(HasMsa());
2465 CHECK(IsUint<4>(n4)) << n4;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002466 DsFsmInstr(EmitMsaELM(0x4, n4 | kMsaDfNByteMask, static_cast<VectorRegister>(rs), wd, 0x19))
2467 .FprInOuts(wd).GprIns(rs);
Lena Djokic3309c012017-10-13 14:34:32 +02002468}
2469
2470void MipsAssembler::InsertH(VectorRegister wd, Register rs, int n3) {
2471 CHECK(HasMsa());
2472 CHECK(IsUint<3>(n3)) << n3;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002473 DsFsmInstr(EmitMsaELM(0x4, n3 | kMsaDfNHalfwordMask, static_cast<VectorRegister>(rs), wd, 0x19))
2474 .FprInOuts(wd).GprIns(rs);
Lena Djokic3309c012017-10-13 14:34:32 +02002475}
2476
2477void MipsAssembler::InsertW(VectorRegister wd, Register rs, int n2) {
2478 CHECK(HasMsa());
2479 CHECK(IsUint<2>(n2)) << n2;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002480 DsFsmInstr(EmitMsaELM(0x4, n2 | kMsaDfNWordMask, static_cast<VectorRegister>(rs), wd, 0x19))
2481 .FprInOuts(wd).GprIns(rs);
Lena Djokic3309c012017-10-13 14:34:32 +02002482}
2483
Lena Djokic0758ae72017-05-23 11:06:23 +02002484void MipsAssembler::FillB(VectorRegister wd, Register rs) {
2485 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002486 DsFsmInstr(EmitMsa2R(0xc0, 0x0, static_cast<VectorRegister>(rs), wd, 0x1e))
2487 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002488}
2489
2490void MipsAssembler::FillH(VectorRegister wd, Register rs) {
2491 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002492 DsFsmInstr(EmitMsa2R(0xc0, 0x1, static_cast<VectorRegister>(rs), wd, 0x1e))
2493 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002494}
2495
2496void MipsAssembler::FillW(VectorRegister wd, Register rs) {
2497 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002498 DsFsmInstr(EmitMsa2R(0xc0, 0x2, static_cast<VectorRegister>(rs), wd, 0x1e))
2499 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002500}
2501
2502void MipsAssembler::LdiB(VectorRegister wd, int imm8) {
2503 CHECK(HasMsa());
2504 CHECK(IsInt<8>(imm8)) << imm8;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002505 DsFsmInstr(EmitMsaI10(0x6, 0x0, imm8 & kMsaS10Mask, wd, 0x7)).FprOuts(wd);
Lena Djokic0758ae72017-05-23 11:06:23 +02002506}
2507
2508void MipsAssembler::LdiH(VectorRegister wd, int imm10) {
2509 CHECK(HasMsa());
2510 CHECK(IsInt<10>(imm10)) << imm10;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002511 DsFsmInstr(EmitMsaI10(0x6, 0x1, imm10 & kMsaS10Mask, wd, 0x7)).FprOuts(wd);
Lena Djokic0758ae72017-05-23 11:06:23 +02002512}
2513
2514void MipsAssembler::LdiW(VectorRegister wd, int imm10) {
2515 CHECK(HasMsa());
2516 CHECK(IsInt<10>(imm10)) << imm10;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002517 DsFsmInstr(EmitMsaI10(0x6, 0x2, imm10 & kMsaS10Mask, wd, 0x7)).FprOuts(wd);
Lena Djokic0758ae72017-05-23 11:06:23 +02002518}
2519
2520void MipsAssembler::LdiD(VectorRegister wd, int imm10) {
2521 CHECK(HasMsa());
2522 CHECK(IsInt<10>(imm10)) << imm10;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002523 DsFsmInstr(EmitMsaI10(0x6, 0x3, imm10 & kMsaS10Mask, wd, 0x7)).FprOuts(wd);
Lena Djokic0758ae72017-05-23 11:06:23 +02002524}
2525
2526void MipsAssembler::LdB(VectorRegister wd, Register rs, int offset) {
2527 CHECK(HasMsa());
2528 CHECK(IsInt<10>(offset)) << offset;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002529 DsFsmInstr(EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x8, 0x0)).FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002530}
2531
2532void MipsAssembler::LdH(VectorRegister wd, Register rs, int offset) {
2533 CHECK(HasMsa());
2534 CHECK(IsInt<11>(offset)) << offset;
2535 CHECK_ALIGNED(offset, kMipsHalfwordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002536 DsFsmInstr(EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x8, 0x1))
2537 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002538}
2539
2540void MipsAssembler::LdW(VectorRegister wd, Register rs, int offset) {
2541 CHECK(HasMsa());
2542 CHECK(IsInt<12>(offset)) << offset;
2543 CHECK_ALIGNED(offset, kMipsWordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002544 DsFsmInstr(EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x8, 0x2))
2545 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002546}
2547
2548void MipsAssembler::LdD(VectorRegister wd, Register rs, int offset) {
2549 CHECK(HasMsa());
2550 CHECK(IsInt<13>(offset)) << offset;
2551 CHECK_ALIGNED(offset, kMipsDoublewordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002552 DsFsmInstr(EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x8, 0x3))
2553 .FprOuts(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002554}
2555
2556void MipsAssembler::StB(VectorRegister wd, Register rs, int offset) {
2557 CHECK(HasMsa());
2558 CHECK(IsInt<10>(offset)) << offset;
Alexey Frunzea247dea2017-11-03 18:43:04 -07002559 DsFsmInstr(EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x9, 0x0)).FprIns(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002560}
2561
2562void MipsAssembler::StH(VectorRegister wd, Register rs, int offset) {
2563 CHECK(HasMsa());
2564 CHECK(IsInt<11>(offset)) << offset;
2565 CHECK_ALIGNED(offset, kMipsHalfwordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002566 DsFsmInstr(EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x9, 0x1))
2567 .FprIns(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002568}
2569
2570void MipsAssembler::StW(VectorRegister wd, Register rs, int offset) {
2571 CHECK(HasMsa());
2572 CHECK(IsInt<12>(offset)) << offset;
2573 CHECK_ALIGNED(offset, kMipsWordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002574 DsFsmInstr(EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x9, 0x2))
2575 .FprIns(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002576}
2577
2578void MipsAssembler::StD(VectorRegister wd, Register rs, int offset) {
2579 CHECK(HasMsa());
2580 CHECK(IsInt<13>(offset)) << offset;
2581 CHECK_ALIGNED(offset, kMipsDoublewordSize);
Alexey Frunzea247dea2017-11-03 18:43:04 -07002582 DsFsmInstr(EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x9, 0x3))
2583 .FprIns(wd).GprIns(rs);
Lena Djokic0758ae72017-05-23 11:06:23 +02002584}
2585
Lena Djokic3309c012017-10-13 14:34:32 +02002586void MipsAssembler::IlvlB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2587 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002588 DsFsmInstr(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002589}
2590
2591void MipsAssembler::IlvlH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2592 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002593 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002594}
2595
2596void MipsAssembler::IlvlW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2597 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002598 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002599}
2600
2601void MipsAssembler::IlvlD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2602 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002603 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002604}
2605
Lena Djokic0758ae72017-05-23 11:06:23 +02002606void MipsAssembler::IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2607 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002608 DsFsmInstr(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002609}
2610
2611void MipsAssembler::IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2612 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002613 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002614}
2615
2616void MipsAssembler::IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2617 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002618 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002619}
2620
2621void MipsAssembler::IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2622 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002623 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic0758ae72017-05-23 11:06:23 +02002624}
2625
Lena Djokic3309c012017-10-13 14:34:32 +02002626void MipsAssembler::IlvevB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2627 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002628 DsFsmInstr(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002629}
2630
2631void MipsAssembler::IlvevH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2632 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002633 DsFsmInstr(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002634}
2635
2636void MipsAssembler::IlvevW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2637 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002638 DsFsmInstr(EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002639}
2640
2641void MipsAssembler::IlvevD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2642 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002643 DsFsmInstr(EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002644}
2645
2646void MipsAssembler::IlvodB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2647 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002648 DsFsmInstr(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002649}
2650
2651void MipsAssembler::IlvodH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2652 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002653 DsFsmInstr(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002654}
2655
2656void MipsAssembler::IlvodW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2657 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002658 DsFsmInstr(EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002659}
2660
2661void MipsAssembler::IlvodD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2662 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002663 DsFsmInstr(EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x14)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002664}
2665
Lena Djokicb3d79e42017-07-25 11:20:52 +02002666void MipsAssembler::MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2667 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002668 DsFsmInstr(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002669}
2670
2671void MipsAssembler::MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2672 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002673 DsFsmInstr(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002674}
2675
2676void MipsAssembler::MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2677 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002678 DsFsmInstr(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002679}
2680
2681void MipsAssembler::MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2682 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002683 DsFsmInstr(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002684}
2685
2686void MipsAssembler::MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2687 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002688 DsFsmInstr(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002689}
2690
2691void MipsAssembler::MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2692 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002693 DsFsmInstr(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002694}
2695
2696void MipsAssembler::MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2697 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002698 DsFsmInstr(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002699}
2700
2701void MipsAssembler::MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2702 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002703 DsFsmInstr(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x12)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002704}
2705
Lena Djokic72aba712017-10-30 15:47:20 +01002706void MipsAssembler::Asub_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2707 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002708 DsFsmInstr(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002709}
2710
2711void MipsAssembler::Asub_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2712 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002713 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002714}
2715
2716void MipsAssembler::Asub_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2717 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002718 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002719}
2720
2721void MipsAssembler::Asub_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2722 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002723 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002724}
2725
2726void MipsAssembler::Asub_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2727 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002728 DsFsmInstr(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002729}
2730
2731void MipsAssembler::Asub_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2732 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002733 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002734}
2735
2736void MipsAssembler::Asub_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2737 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002738 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002739}
2740
2741void MipsAssembler::Asub_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2742 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002743 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x11)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic72aba712017-10-30 15:47:20 +01002744}
2745
Lena Djokicb3d79e42017-07-25 11:20:52 +02002746void MipsAssembler::FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2747 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002748 DsFsmInstr(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x1b)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002749}
2750
2751void MipsAssembler::FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2752 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002753 DsFsmInstr(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x1b)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002754}
2755
2756void MipsAssembler::FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2757 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002758 DsFsmInstr(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x1b)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002759}
2760
2761void MipsAssembler::FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2762 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002763 DsFsmInstr(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x1b)).FprInOuts(wd).FprIns(ws, wt);
Lena Djokicb3d79e42017-07-25 11:20:52 +02002764}
2765
Lena Djokic3309c012017-10-13 14:34:32 +02002766void MipsAssembler::Hadd_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2767 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002768 DsFsmInstr(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002769}
2770
2771void MipsAssembler::Hadd_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2772 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002773 DsFsmInstr(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002774}
2775
2776void MipsAssembler::Hadd_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2777 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002778 DsFsmInstr(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002779}
2780
2781void MipsAssembler::Hadd_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2782 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002783 DsFsmInstr(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002784}
2785
2786void MipsAssembler::Hadd_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2787 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002788 DsFsmInstr(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002789}
2790
2791void MipsAssembler::Hadd_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2792 CHECK(HasMsa());
Alexey Frunzea247dea2017-11-03 18:43:04 -07002793 DsFsmInstr(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x15)).FprOuts(wd).FprIns(ws, wt);
Lena Djokic3309c012017-10-13 14:34:32 +02002794}
2795
Lena Djokic0d2cab52018-03-06 15:20:45 +01002796void MipsAssembler::PcntB(VectorRegister wd, VectorRegister ws) {
2797 CHECK(HasMsa());
2798 DsFsmInstr(EmitMsa2R(0xc1, 0x0, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
2799}
2800
2801void MipsAssembler::PcntH(VectorRegister wd, VectorRegister ws) {
2802 CHECK(HasMsa());
2803 DsFsmInstr(EmitMsa2R(0xc1, 0x1, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
2804}
2805
2806void MipsAssembler::PcntW(VectorRegister wd, VectorRegister ws) {
2807 CHECK(HasMsa());
2808 DsFsmInstr(EmitMsa2R(0xc1, 0x2, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
2809}
2810
2811void MipsAssembler::PcntD(VectorRegister wd, VectorRegister ws) {
2812 CHECK(HasMsa());
2813 DsFsmInstr(EmitMsa2R(0xc1, 0x3, ws, wd, 0x1e)).FprOuts(wd).FprIns(ws);
2814}
2815
Lena Djokic51765b02017-06-22 13:49:59 +02002816void MipsAssembler::ReplicateFPToVectorRegister(VectorRegister dst,
2817 FRegister src,
2818 bool is_double) {
2819 // Float or double in FPU register Fx can be considered as 0th element in vector register Wx.
2820 if (is_double) {
2821 SplatiD(dst, static_cast<VectorRegister>(src), 0);
2822 } else {
2823 SplatiW(dst, static_cast<VectorRegister>(src), 0);
2824 }
2825}
2826
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002827void MipsAssembler::LoadConst32(Register rd, int32_t value) {
2828 if (IsUint<16>(value)) {
2829 // Use OR with (unsigned) immediate to encode 16b unsigned int.
2830 Ori(rd, ZERO, value);
2831 } else if (IsInt<16>(value)) {
2832 // Use ADD with (signed) immediate to encode 16b signed int.
2833 Addiu(rd, ZERO, value);
jeffhao7fbee072012-08-24 17:56:54 -07002834 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002835 Lui(rd, High16Bits(value));
2836 if (value & 0xFFFF)
2837 Ori(rd, rd, Low16Bits(value));
2838 }
2839}
2840
2841void MipsAssembler::LoadConst64(Register reg_hi, Register reg_lo, int64_t value) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002842 uint32_t low = Low32Bits(value);
2843 uint32_t high = High32Bits(value);
2844 LoadConst32(reg_lo, low);
2845 if (high != low) {
2846 LoadConst32(reg_hi, high);
2847 } else {
2848 Move(reg_hi, reg_lo);
2849 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002850}
2851
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002852void MipsAssembler::LoadSConst32(FRegister r, int32_t value, Register temp) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002853 if (value == 0) {
2854 temp = ZERO;
2855 } else {
2856 LoadConst32(temp, value);
2857 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002858 Mtc1(temp, r);
2859}
2860
2861void MipsAssembler::LoadDConst64(FRegister rd, int64_t value, Register temp) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002862 uint32_t low = Low32Bits(value);
2863 uint32_t high = High32Bits(value);
2864 if (low == 0) {
2865 Mtc1(ZERO, rd);
2866 } else {
2867 LoadConst32(temp, low);
2868 Mtc1(temp, rd);
2869 }
2870 if (high == 0) {
Alexey Frunzebb9863a2016-01-11 15:51:16 -08002871 MoveToFpuHigh(ZERO, rd);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002872 } else {
2873 LoadConst32(temp, high);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08002874 MoveToFpuHigh(temp, rd);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08002875 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002876}
2877
2878void MipsAssembler::Addiu32(Register rt, Register rs, int32_t value, Register temp) {
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07002879 CHECK_NE(rs, temp); // Must not overwrite the register `rs` while loading `value`.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002880 if (IsInt<16>(value)) {
2881 Addiu(rt, rs, value);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07002882 } else if (IsR6()) {
2883 int16_t high = High16Bits(value);
2884 int16_t low = Low16Bits(value);
2885 high += (low < 0) ? 1 : 0; // Account for sign extension in addiu.
2886 if (low != 0) {
2887 Aui(temp, rs, high);
2888 Addiu(rt, temp, low);
2889 } else {
2890 Aui(rt, rs, high);
2891 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002892 } else {
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07002893 // Do not load the whole 32-bit `value` if it can be represented as
2894 // a sum of two 16-bit signed values. This can save an instruction.
2895 constexpr int32_t kMinValueForSimpleAdjustment = std::numeric_limits<int16_t>::min() * 2;
2896 constexpr int32_t kMaxValueForSimpleAdjustment = std::numeric_limits<int16_t>::max() * 2;
2897 if (0 <= value && value <= kMaxValueForSimpleAdjustment) {
2898 Addiu(temp, rs, kMaxValueForSimpleAdjustment / 2);
2899 Addiu(rt, temp, value - kMaxValueForSimpleAdjustment / 2);
2900 } else if (kMinValueForSimpleAdjustment <= value && value < 0) {
2901 Addiu(temp, rs, kMinValueForSimpleAdjustment / 2);
2902 Addiu(rt, temp, value - kMinValueForSimpleAdjustment / 2);
2903 } else {
2904 // Now that all shorter options have been exhausted, load the full 32-bit value.
2905 LoadConst32(temp, value);
2906 Addu(rt, rs, temp);
2907 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002908 }
2909}
2910
2911void MipsAssembler::Branch::InitShortOrLong(MipsAssembler::Branch::OffsetBits offset_size,
2912 MipsAssembler::Branch::Type short_type,
2913 MipsAssembler::Branch::Type long_type) {
2914 type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
2915}
2916
Alexey Frunze96b66822016-09-10 02:32:44 -07002917void MipsAssembler::Branch::InitializeType(Type initial_type, bool is_r6) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07002918 OffsetBits offset_size_needed = GetOffsetSizeNeeded(location_, target_);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002919 if (is_r6) {
2920 // R6
Alexey Frunze96b66822016-09-10 02:32:44 -07002921 switch (initial_type) {
2922 case kLabel:
2923 CHECK(!IsResolved());
2924 type_ = kR6Label;
2925 break;
2926 case kLiteral:
2927 CHECK(!IsResolved());
2928 type_ = kR6Literal;
2929 break;
2930 case kCall:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002931 InitShortOrLong(offset_size_needed, kR6Call, kR6LongCall);
Alexey Frunze96b66822016-09-10 02:32:44 -07002932 break;
2933 case kCondBranch:
2934 switch (condition_) {
2935 case kUncond:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002936 InitShortOrLong(offset_size_needed, kR6UncondBranch, kR6LongUncondBranch);
Alexey Frunze96b66822016-09-10 02:32:44 -07002937 break;
2938 case kCondEQZ:
2939 case kCondNEZ:
2940 // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
Alexey Frunze0cab6562017-07-25 15:19:36 -07002941 type_ = (offset_size_needed <= kOffset23) ? kR6CondBranch : kR6LongCondBranch;
Alexey Frunze96b66822016-09-10 02:32:44 -07002942 break;
2943 default:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002944 InitShortOrLong(offset_size_needed, kR6CondBranch, kR6LongCondBranch);
Alexey Frunze96b66822016-09-10 02:32:44 -07002945 break;
2946 }
2947 break;
Alexey Frunze0cab6562017-07-25 15:19:36 -07002948 case kBareCall:
2949 type_ = kR6BareCall;
2950 CHECK_LE(offset_size_needed, GetOffsetSize());
2951 break;
2952 case kBareCondBranch:
2953 type_ = (condition_ == kUncond) ? kR6BareUncondBranch : kR6BareCondBranch;
2954 CHECK_LE(offset_size_needed, GetOffsetSize());
2955 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07002956 default:
2957 LOG(FATAL) << "Unexpected branch type " << initial_type;
2958 UNREACHABLE();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002959 }
2960 } else {
2961 // R2
Alexey Frunze96b66822016-09-10 02:32:44 -07002962 switch (initial_type) {
2963 case kLabel:
2964 CHECK(!IsResolved());
2965 type_ = kLabel;
2966 break;
2967 case kLiteral:
2968 CHECK(!IsResolved());
2969 type_ = kLiteral;
2970 break;
2971 case kCall:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002972 InitShortOrLong(offset_size_needed, kCall, kLongCall);
Alexey Frunze96b66822016-09-10 02:32:44 -07002973 break;
2974 case kCondBranch:
2975 switch (condition_) {
2976 case kUncond:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002977 InitShortOrLong(offset_size_needed, kUncondBranch, kLongUncondBranch);
Alexey Frunze96b66822016-09-10 02:32:44 -07002978 break;
2979 default:
Alexey Frunze0cab6562017-07-25 15:19:36 -07002980 InitShortOrLong(offset_size_needed, kCondBranch, kLongCondBranch);
Alexey Frunze96b66822016-09-10 02:32:44 -07002981 break;
2982 }
2983 break;
Alexey Frunze0cab6562017-07-25 15:19:36 -07002984 case kBareCall:
2985 type_ = kBareCall;
2986 CHECK_LE(offset_size_needed, GetOffsetSize());
2987 break;
2988 case kBareCondBranch:
2989 type_ = (condition_ == kUncond) ? kBareUncondBranch : kBareCondBranch;
2990 CHECK_LE(offset_size_needed, GetOffsetSize());
2991 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07002992 default:
2993 LOG(FATAL) << "Unexpected branch type " << initial_type;
2994 UNREACHABLE();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02002995 }
2996 }
2997 old_type_ = type_;
2998}
2999
3000bool MipsAssembler::Branch::IsNop(BranchCondition condition, Register lhs, Register rhs) {
3001 switch (condition) {
3002 case kCondLT:
3003 case kCondGT:
3004 case kCondNE:
3005 case kCondLTU:
3006 return lhs == rhs;
3007 default:
3008 return false;
3009 }
3010}
3011
3012bool MipsAssembler::Branch::IsUncond(BranchCondition condition, Register lhs, Register rhs) {
3013 switch (condition) {
3014 case kUncond:
3015 return true;
3016 case kCondGE:
3017 case kCondLE:
3018 case kCondEQ:
3019 case kCondGEU:
3020 return lhs == rhs;
3021 default:
3022 return false;
3023 }
3024}
3025
Alexey Frunze0cab6562017-07-25 15:19:36 -07003026MipsAssembler::Branch::Branch(bool is_r6,
3027 uint32_t location,
3028 uint32_t target,
3029 bool is_call,
3030 bool is_bare)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003031 : old_location_(location),
3032 location_(location),
3033 target_(target),
3034 lhs_reg_(0),
3035 rhs_reg_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003036 condition_(kUncond),
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003037 delayed_instruction_(kUnfilledDelaySlot),
3038 patcher_label_(nullptr) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003039 InitializeType(
3040 (is_call ? (is_bare ? kBareCall : kCall) : (is_bare ? kBareCondBranch : kCondBranch)),
3041 is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003042}
3043
3044MipsAssembler::Branch::Branch(bool is_r6,
3045 uint32_t location,
3046 uint32_t target,
3047 MipsAssembler::BranchCondition condition,
3048 Register lhs_reg,
Alexey Frunze0cab6562017-07-25 15:19:36 -07003049 Register rhs_reg,
3050 bool is_bare)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003051 : old_location_(location),
3052 location_(location),
3053 target_(target),
3054 lhs_reg_(lhs_reg),
3055 rhs_reg_(rhs_reg),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003056 condition_(condition),
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003057 delayed_instruction_(kUnfilledDelaySlot),
3058 patcher_label_(nullptr) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003059 CHECK_NE(condition, kUncond);
3060 switch (condition) {
3061 case kCondLT:
3062 case kCondGE:
3063 case kCondLE:
3064 case kCondGT:
3065 case kCondLTU:
3066 case kCondGEU:
3067 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
3068 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
3069 // We leave this up to the caller.
3070 CHECK(is_r6);
3071 FALLTHROUGH_INTENDED;
3072 case kCondEQ:
3073 case kCondNE:
3074 // Require registers other than 0 not only for R6, but also for R2 to catch errors.
3075 // To compare with 0, use dedicated kCond*Z conditions.
3076 CHECK_NE(lhs_reg, ZERO);
3077 CHECK_NE(rhs_reg, ZERO);
3078 break;
3079 case kCondLTZ:
3080 case kCondGEZ:
3081 case kCondLEZ:
3082 case kCondGTZ:
3083 case kCondEQZ:
3084 case kCondNEZ:
3085 // Require registers other than 0 not only for R6, but also for R2 to catch errors.
3086 CHECK_NE(lhs_reg, ZERO);
3087 CHECK_EQ(rhs_reg, ZERO);
3088 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003089 case kCondF:
3090 case kCondT:
3091 CHECK_EQ(rhs_reg, ZERO);
3092 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003093 case kUncond:
3094 UNREACHABLE();
3095 }
3096 CHECK(!IsNop(condition, lhs_reg, rhs_reg));
3097 if (IsUncond(condition, lhs_reg, rhs_reg)) {
3098 // Branch condition is always true, make the branch unconditional.
3099 condition_ = kUncond;
3100 }
Alexey Frunze0cab6562017-07-25 15:19:36 -07003101 InitializeType((is_bare ? kBareCondBranch : kCondBranch), is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003102}
3103
Alexey Frunze96b66822016-09-10 02:32:44 -07003104MipsAssembler::Branch::Branch(bool is_r6,
3105 uint32_t location,
3106 Register dest_reg,
3107 Register base_reg,
3108 Type label_or_literal_type)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003109 : old_location_(location),
3110 location_(location),
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003111 target_(kUnresolved),
3112 lhs_reg_(dest_reg),
3113 rhs_reg_(base_reg),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003114 condition_(kUncond),
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003115 delayed_instruction_(kUnfilledDelaySlot),
3116 patcher_label_(nullptr) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003117 CHECK_NE(dest_reg, ZERO);
3118 if (is_r6) {
3119 CHECK_EQ(base_reg, ZERO);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003120 }
Alexey Frunze96b66822016-09-10 02:32:44 -07003121 InitializeType(label_or_literal_type, is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003122}
3123
3124MipsAssembler::BranchCondition MipsAssembler::Branch::OppositeCondition(
3125 MipsAssembler::BranchCondition cond) {
3126 switch (cond) {
3127 case kCondLT:
3128 return kCondGE;
3129 case kCondGE:
3130 return kCondLT;
3131 case kCondLE:
3132 return kCondGT;
3133 case kCondGT:
3134 return kCondLE;
3135 case kCondLTZ:
3136 return kCondGEZ;
3137 case kCondGEZ:
3138 return kCondLTZ;
3139 case kCondLEZ:
3140 return kCondGTZ;
3141 case kCondGTZ:
3142 return kCondLEZ;
3143 case kCondEQ:
3144 return kCondNE;
3145 case kCondNE:
3146 return kCondEQ;
3147 case kCondEQZ:
3148 return kCondNEZ;
3149 case kCondNEZ:
3150 return kCondEQZ;
3151 case kCondLTU:
3152 return kCondGEU;
3153 case kCondGEU:
3154 return kCondLTU;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003155 case kCondF:
3156 return kCondT;
3157 case kCondT:
3158 return kCondF;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003159 case kUncond:
3160 LOG(FATAL) << "Unexpected branch condition " << cond;
3161 }
3162 UNREACHABLE();
3163}
3164
3165MipsAssembler::Branch::Type MipsAssembler::Branch::GetType() const {
3166 return type_;
3167}
3168
3169MipsAssembler::BranchCondition MipsAssembler::Branch::GetCondition() const {
3170 return condition_;
3171}
3172
3173Register MipsAssembler::Branch::GetLeftRegister() const {
3174 return static_cast<Register>(lhs_reg_);
3175}
3176
3177Register MipsAssembler::Branch::GetRightRegister() const {
3178 return static_cast<Register>(rhs_reg_);
3179}
3180
3181uint32_t MipsAssembler::Branch::GetTarget() const {
3182 return target_;
3183}
3184
3185uint32_t MipsAssembler::Branch::GetLocation() const {
3186 return location_;
3187}
3188
3189uint32_t MipsAssembler::Branch::GetOldLocation() const {
3190 return old_location_;
3191}
3192
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003193uint32_t MipsAssembler::Branch::GetPrecedingInstructionLength(Type type) const {
3194 // Short branches with delay slots always consist of two instructions, the branch
3195 // and the delay slot, irrespective of whether the delay slot is filled with a
3196 // useful instruction or not.
3197 // Long composite branches may have a length longer by one instruction than
3198 // specified in branch_info_[].length. This happens when an instruction is taken
3199 // to fill the short branch delay slot, but the branch eventually becomes long
3200 // and formally has no delay slot to fill. This instruction is placed at the
3201 // beginning of the long composite branch and this needs to be accounted for in
3202 // the branch length and the location of the offset encoded in the branch.
3203 switch (type) {
3204 case kLongUncondBranch:
3205 case kLongCondBranch:
3206 case kLongCall:
3207 case kR6LongCondBranch:
3208 return (delayed_instruction_ != kUnfilledDelaySlot &&
3209 delayed_instruction_ != kUnfillableDelaySlot) ? 1 : 0;
3210 default:
3211 return 0;
3212 }
3213}
3214
3215uint32_t MipsAssembler::Branch::GetPrecedingInstructionSize(Type type) const {
3216 return GetPrecedingInstructionLength(type) * sizeof(uint32_t);
3217}
3218
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003219uint32_t MipsAssembler::Branch::GetLength() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003220 return GetPrecedingInstructionLength(type_) + branch_info_[type_].length;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003221}
3222
3223uint32_t MipsAssembler::Branch::GetOldLength() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003224 return GetPrecedingInstructionLength(old_type_) + branch_info_[old_type_].length;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003225}
3226
3227uint32_t MipsAssembler::Branch::GetSize() const {
3228 return GetLength() * sizeof(uint32_t);
3229}
3230
3231uint32_t MipsAssembler::Branch::GetOldSize() const {
3232 return GetOldLength() * sizeof(uint32_t);
3233}
3234
3235uint32_t MipsAssembler::Branch::GetEndLocation() const {
3236 return GetLocation() + GetSize();
3237}
3238
3239uint32_t MipsAssembler::Branch::GetOldEndLocation() const {
3240 return GetOldLocation() + GetOldSize();
3241}
3242
Alexey Frunze0cab6562017-07-25 15:19:36 -07003243bool MipsAssembler::Branch::IsBare() const {
3244 switch (type_) {
3245 // R2 short branches (can't be promoted to long), delay slots filled manually.
3246 case kBareUncondBranch:
3247 case kBareCondBranch:
3248 case kBareCall:
3249 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
3250 case kR6BareUncondBranch:
3251 case kR6BareCondBranch:
3252 case kR6BareCall:
3253 return true;
3254 default:
3255 return false;
3256 }
3257}
3258
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003259bool MipsAssembler::Branch::IsLong() const {
3260 switch (type_) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003261 // R2 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003262 case kUncondBranch:
3263 case kCondBranch:
3264 case kCall:
Alexey Frunze0cab6562017-07-25 15:19:36 -07003265 // R2 short branches (can't be promoted to long), delay slots filled manually.
3266 case kBareUncondBranch:
3267 case kBareCondBranch:
3268 case kBareCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003269 // R2 near label.
3270 case kLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003271 // R2 near literal.
3272 case kLiteral:
Alexey Frunze0cab6562017-07-25 15:19:36 -07003273 // R6 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003274 case kR6UncondBranch:
3275 case kR6CondBranch:
3276 case kR6Call:
Alexey Frunze0cab6562017-07-25 15:19:36 -07003277 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
3278 case kR6BareUncondBranch:
3279 case kR6BareCondBranch:
3280 case kR6BareCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003281 // R6 near label.
3282 case kR6Label:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003283 // R6 near literal.
3284 case kR6Literal:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003285 return false;
3286 // R2 long branches.
3287 case kLongUncondBranch:
3288 case kLongCondBranch:
3289 case kLongCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003290 // R2 far label.
3291 case kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003292 // R2 far literal.
3293 case kFarLiteral:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003294 // R6 long branches.
3295 case kR6LongUncondBranch:
3296 case kR6LongCondBranch:
3297 case kR6LongCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003298 // R6 far label.
3299 case kR6FarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003300 // R6 far literal.
3301 case kR6FarLiteral:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003302 return true;
3303 }
3304 UNREACHABLE();
3305}
3306
3307bool MipsAssembler::Branch::IsResolved() const {
3308 return target_ != kUnresolved;
3309}
3310
3311MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSize() const {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003312 bool r6_cond_branch = (type_ == kR6CondBranch || type_ == kR6BareCondBranch);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003313 OffsetBits offset_size =
Alexey Frunze0cab6562017-07-25 15:19:36 -07003314 (r6_cond_branch && (condition_ == kCondEQZ || condition_ == kCondNEZ))
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003315 ? kOffset23
3316 : branch_info_[type_].offset_size;
3317 return offset_size;
3318}
3319
3320MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSizeNeeded(uint32_t location,
3321 uint32_t target) {
3322 // For unresolved targets assume the shortest encoding
3323 // (later it will be made longer if needed).
3324 if (target == kUnresolved)
3325 return kOffset16;
3326 int64_t distance = static_cast<int64_t>(target) - location;
3327 // To simplify calculations in composite branches consisting of multiple instructions
3328 // bump up the distance by a value larger than the max byte size of a composite branch.
3329 distance += (distance >= 0) ? kMaxBranchSize : -kMaxBranchSize;
3330 if (IsInt<kOffset16>(distance))
3331 return kOffset16;
3332 else if (IsInt<kOffset18>(distance))
3333 return kOffset18;
3334 else if (IsInt<kOffset21>(distance))
3335 return kOffset21;
3336 else if (IsInt<kOffset23>(distance))
3337 return kOffset23;
3338 else if (IsInt<kOffset28>(distance))
3339 return kOffset28;
3340 return kOffset32;
3341}
3342
3343void MipsAssembler::Branch::Resolve(uint32_t target) {
3344 target_ = target;
3345}
3346
3347void MipsAssembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
3348 if (location_ > expand_location) {
3349 location_ += delta;
3350 }
3351 if (!IsResolved()) {
3352 return; // Don't know the target yet.
3353 }
3354 if (target_ > expand_location) {
3355 target_ += delta;
3356 }
3357}
3358
3359void MipsAssembler::Branch::PromoteToLong() {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003360 CHECK(!IsBare()); // Bare branches do not promote.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003361 switch (type_) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003362 // R2 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003363 case kUncondBranch:
3364 type_ = kLongUncondBranch;
3365 break;
3366 case kCondBranch:
3367 type_ = kLongCondBranch;
3368 break;
3369 case kCall:
3370 type_ = kLongCall;
3371 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07003372 // R2 near label.
3373 case kLabel:
3374 type_ = kFarLabel;
3375 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003376 // R2 near literal.
3377 case kLiteral:
3378 type_ = kFarLiteral;
3379 break;
Alexey Frunze0cab6562017-07-25 15:19:36 -07003380 // R6 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003381 case kR6UncondBranch:
3382 type_ = kR6LongUncondBranch;
3383 break;
3384 case kR6CondBranch:
3385 type_ = kR6LongCondBranch;
3386 break;
3387 case kR6Call:
3388 type_ = kR6LongCall;
3389 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07003390 // R6 near label.
3391 case kR6Label:
3392 type_ = kR6FarLabel;
3393 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003394 // R6 near literal.
3395 case kR6Literal:
3396 type_ = kR6FarLiteral;
3397 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003398 default:
3399 // Note: 'type_' is already long.
3400 break;
3401 }
3402 CHECK(IsLong());
3403}
3404
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003405uint32_t MipsAssembler::GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const {
3406 switch (branch->GetType()) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003407 case Branch::kLabel:
3408 case Branch::kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003409 case Branch::kLiteral:
3410 case Branch::kFarLiteral:
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003411 if (branch->GetRightRegister() != ZERO) {
3412 return GetLabelLocation(&pc_rel_base_label_);
3413 }
3414 // For those label/literal loads which come with their own NAL instruction
3415 // and don't depend on `pc_rel_base_label_` we can simply use the location
3416 // of the "branch" (the NAL precedes the "branch" immediately). The location
3417 // is close enough for the user of the returned location, PromoteIfNeeded(),
3418 // to not miss needed promotion to a far load.
3419 // (GetOffsetSizeNeeded() provides a little leeway by means of kMaxBranchSize,
3420 // which is larger than all composite branches and label/literal loads: it's
3421 // OK to promote a bit earlier than strictly necessary, it makes things
3422 // simpler.)
3423 FALLTHROUGH_INTENDED;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003424 default:
3425 return branch->GetLocation();
3426 }
3427}
3428
3429uint32_t MipsAssembler::Branch::PromoteIfNeeded(uint32_t location, uint32_t max_short_distance) {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003430 // `location` comes from GetBranchLocationOrPcRelBase() and is either the location
3431 // of the PC-relative branch or (for some R2 label and literal loads) the location
3432 // of `pc_rel_base_label_`. The PC-relative offset of the branch/load is relative
3433 // to this location.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003434 // If the branch is still unresolved or already long, nothing to do.
3435 if (IsLong() || !IsResolved()) {
3436 return 0;
3437 }
3438 // Promote the short branch to long if the offset size is too small
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003439 // to hold the distance between location and target_.
3440 if (GetOffsetSizeNeeded(location, target_) > GetOffsetSize()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003441 PromoteToLong();
3442 uint32_t old_size = GetOldSize();
3443 uint32_t new_size = GetSize();
3444 CHECK_GT(new_size, old_size);
3445 return new_size - old_size;
3446 }
3447 // The following logic is for debugging/testing purposes.
3448 // Promote some short branches to long when it's not really required.
Alexey Frunze0cab6562017-07-25 15:19:36 -07003449 if (UNLIKELY(max_short_distance != std::numeric_limits<uint32_t>::max() && !IsBare())) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003450 int64_t distance = static_cast<int64_t>(target_) - location;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003451 distance = (distance >= 0) ? distance : -distance;
3452 if (distance >= max_short_distance) {
3453 PromoteToLong();
3454 uint32_t old_size = GetOldSize();
3455 uint32_t new_size = GetSize();
3456 CHECK_GT(new_size, old_size);
3457 return new_size - old_size;
3458 }
3459 }
3460 return 0;
3461}
3462
3463uint32_t MipsAssembler::Branch::GetOffsetLocation() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003464 return location_ + GetPrecedingInstructionSize(type_) +
3465 branch_info_[type_].instr_offset * sizeof(uint32_t);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003466}
3467
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003468uint32_t MipsAssembler::GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const {
3469 switch (branch->GetType()) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003470 case Branch::kLabel:
3471 case Branch::kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003472 case Branch::kLiteral:
3473 case Branch::kFarLiteral:
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003474 if (branch->GetRightRegister() == ZERO) {
3475 // These loads don't use `pc_rel_base_label_` and instead rely on their own
3476 // NAL instruction (it immediately precedes the "branch"). Therefore the
3477 // effective PC-relative base register is RA and it corresponds to the 2nd
3478 // instruction after the NAL.
3479 return branch->GetLocation() + sizeof(uint32_t);
3480 } else {
3481 return GetLabelLocation(&pc_rel_base_label_);
3482 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003483 default:
3484 return branch->GetOffsetLocation() +
3485 Branch::branch_info_[branch->GetType()].pc_org * sizeof(uint32_t);
3486 }
3487}
3488
3489uint32_t MipsAssembler::Branch::GetOffset(uint32_t location) const {
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003490 // `location` comes from GetBranchOrPcRelBaseForEncoding() and is either a location
3491 // within/near the PC-relative branch or (for some R2 label and literal loads) the
3492 // location of `pc_rel_base_label_`. The PC-relative offset of the branch/load is
3493 // relative to this location.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003494 CHECK(IsResolved());
3495 uint32_t ofs_mask = 0xFFFFFFFF >> (32 - GetOffsetSize());
3496 // Calculate the byte distance between instructions and also account for
3497 // different PC-relative origins.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003498 uint32_t offset = target_ - location;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003499 // Prepare the offset for encoding into the instruction(s).
3500 offset = (offset & ofs_mask) >> branch_info_[type_].offset_shift;
3501 return offset;
3502}
3503
3504MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) {
3505 CHECK_LT(branch_id, branches_.size());
3506 return &branches_[branch_id];
3507}
3508
3509const MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) const {
3510 CHECK_LT(branch_id, branches_.size());
3511 return &branches_[branch_id];
3512}
3513
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003514void MipsAssembler::BindRelativeToPrecedingBranch(MipsLabel* label,
3515 uint32_t prev_branch_id_plus_one,
3516 uint32_t position) {
3517 if (prev_branch_id_plus_one != 0) {
3518 const Branch* branch = GetBranch(prev_branch_id_plus_one - 1);
3519 position -= branch->GetEndLocation();
3520 }
3521 label->prev_branch_id_plus_one_ = prev_branch_id_plus_one;
3522 label->BindTo(position);
3523}
3524
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003525void MipsAssembler::Bind(MipsLabel* label) {
3526 CHECK(!label->IsBound());
3527 uint32_t bound_pc = buffer_.Size();
3528
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003529 // Make the delay slot FSM aware of the new label.
3530 DsFsmLabel();
3531
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003532 // Walk the list of branches referring to and preceding this label.
3533 // Store the previously unknown target addresses in them.
3534 while (label->IsLinked()) {
3535 uint32_t branch_id = label->Position();
3536 Branch* branch = GetBranch(branch_id);
3537 branch->Resolve(bound_pc);
3538
3539 uint32_t branch_location = branch->GetLocation();
3540 // Extract the location of the previous branch in the list (walking the list backwards;
3541 // the previous branch ID was stored in the space reserved for this branch).
3542 uint32_t prev = buffer_.Load<uint32_t>(branch_location);
3543
3544 // On to the previous branch in the list...
3545 label->position_ = prev;
3546 }
3547
3548 // Now make the label object contain its own location (relative to the end of the preceding
3549 // branch, if any; it will be used by the branches referring to and following this label).
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003550 BindRelativeToPrecedingBranch(label, branches_.size(), bound_pc);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003551}
3552
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003553uint32_t MipsAssembler::GetLabelLocation(const MipsLabel* label) const {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003554 CHECK(label->IsBound());
3555 uint32_t target = label->Position();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003556 if (label->prev_branch_id_plus_one_ != 0) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003557 // Get label location based on the branch preceding it.
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003558 const Branch* branch = GetBranch(label->prev_branch_id_plus_one_ - 1);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003559 target += branch->GetEndLocation();
3560 }
3561 return target;
3562}
3563
3564uint32_t MipsAssembler::GetAdjustedPosition(uint32_t old_position) {
3565 // We can reconstruct the adjustment by going through all the branches from the beginning
3566 // up to the old_position. Since we expect AdjustedPosition() to be called in a loop
3567 // with increasing old_position, we can use the data from last AdjustedPosition() to
3568 // continue where we left off and the whole loop should be O(m+n) where m is the number
3569 // of positions to adjust and n is the number of branches.
3570 if (old_position < last_old_position_) {
3571 last_position_adjustment_ = 0;
3572 last_old_position_ = 0;
3573 last_branch_id_ = 0;
3574 }
3575 while (last_branch_id_ != branches_.size()) {
3576 const Branch* branch = GetBranch(last_branch_id_);
3577 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
3578 break;
3579 }
3580 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
3581 ++last_branch_id_;
3582 }
3583 last_old_position_ = old_position;
3584 return old_position + last_position_adjustment_;
3585}
3586
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003587void MipsAssembler::BindPcRelBaseLabel() {
3588 Bind(&pc_rel_base_label_);
3589}
3590
Alexey Frunze06a46c42016-07-19 15:00:40 -07003591uint32_t MipsAssembler::GetPcRelBaseLabelLocation() const {
3592 return GetLabelLocation(&pc_rel_base_label_);
3593}
3594
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003595void MipsAssembler::FinalizeLabeledBranch(MipsLabel* label) {
3596 uint32_t length = branches_.back().GetLength();
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003597 // Commit the last branch target label (if any).
3598 DsFsmCommitLabel();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003599 if (!label->IsBound()) {
3600 // Branch forward (to a following label), distance is unknown.
3601 // The first branch forward will contain 0, serving as the terminator of
3602 // the list of forward-reaching branches.
3603 Emit(label->position_);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003604 // Nothing for the delay slot (yet).
3605 DsFsmInstrNop(0);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003606 length--;
3607 // Now make the label object point to this branch
3608 // (this forms a linked list of branches preceding this label).
3609 uint32_t branch_id = branches_.size() - 1;
3610 label->LinkTo(branch_id);
3611 }
3612 // Reserve space for the branch.
Andreas Gampec74d9cb2018-09-20 13:44:44 -07003613 for (; length != 0u; --length) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003614 Nop();
3615 }
3616}
3617
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003618bool MipsAssembler::Branch::CanHaveDelayedInstruction(const DelaySlot& delay_slot) const {
3619 if (delay_slot.instruction_ == 0) {
3620 // NOP or no instruction for the delay slot.
3621 return false;
3622 }
3623 switch (type_) {
3624 // R2 unconditional branches.
3625 case kUncondBranch:
3626 case kLongUncondBranch:
3627 // There are no register interdependencies.
3628 return true;
3629
3630 // R2 calls.
3631 case kCall:
3632 case kLongCall:
3633 // Instructions depending on or modifying RA should not be moved into delay slots
3634 // of branches modifying RA.
Alexey Frunzea247dea2017-11-03 18:43:04 -07003635 return ((delay_slot.masks_.gpr_ins_ | delay_slot.masks_.gpr_outs_) & (1u << RA)) == 0;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003636
3637 // R2 conditional branches.
3638 case kCondBranch:
3639 case kLongCondBranch:
3640 switch (condition_) {
3641 // Branches with one GPR source.
3642 case kCondLTZ:
3643 case kCondGEZ:
3644 case kCondLEZ:
3645 case kCondGTZ:
3646 case kCondEQZ:
3647 case kCondNEZ:
Alexey Frunzea247dea2017-11-03 18:43:04 -07003648 return (delay_slot.masks_.gpr_outs_ & (1u << lhs_reg_)) == 0;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003649
3650 // Branches with two GPR sources.
3651 case kCondEQ:
3652 case kCondNE:
Alexey Frunzea247dea2017-11-03 18:43:04 -07003653 return (delay_slot.masks_.gpr_outs_ & ((1u << lhs_reg_) | (1u << rhs_reg_))) == 0;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003654
3655 // Branches with one FPU condition code source.
3656 case kCondF:
3657 case kCondT:
Alexey Frunzea247dea2017-11-03 18:43:04 -07003658 return (delay_slot.masks_.cc_outs_ & (1u << lhs_reg_)) == 0;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003659
3660 default:
3661 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
3662 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
3663 LOG(FATAL) << "Unexpected branch condition " << condition_;
3664 UNREACHABLE();
3665 }
3666
3667 // R6 unconditional branches.
3668 case kR6UncondBranch:
3669 case kR6LongUncondBranch:
3670 // R6 calls.
3671 case kR6Call:
3672 case kR6LongCall:
3673 // There are no delay slots.
3674 return false;
3675
3676 // R6 conditional branches.
3677 case kR6CondBranch:
3678 case kR6LongCondBranch:
3679 switch (condition_) {
3680 // Branches with one FPU register source.
3681 case kCondF:
3682 case kCondT:
Alexey Frunzea247dea2017-11-03 18:43:04 -07003683 return (delay_slot.masks_.fpr_outs_ & (1u << lhs_reg_)) == 0;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003684 // Others have a forbidden slot instead of a delay slot.
3685 default:
3686 return false;
3687 }
3688
3689 // Literals.
3690 default:
3691 LOG(FATAL) << "Unexpected branch type " << type_;
3692 UNREACHABLE();
3693 }
3694}
3695
3696uint32_t MipsAssembler::Branch::GetDelayedInstruction() const {
3697 return delayed_instruction_;
3698}
3699
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003700MipsLabel* MipsAssembler::Branch::GetPatcherLabel() const {
3701 return patcher_label_;
3702}
3703
3704void MipsAssembler::Branch::SetDelayedInstruction(uint32_t instruction, MipsLabel* patcher_label) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003705 CHECK_NE(instruction, kUnfilledDelaySlot);
3706 CHECK_EQ(delayed_instruction_, kUnfilledDelaySlot);
3707 delayed_instruction_ = instruction;
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003708 patcher_label_ = patcher_label;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003709}
3710
3711void MipsAssembler::Branch::DecrementLocations() {
3712 // We first create a branch object, which gets its type and locations initialized,
3713 // and then we check if the branch can actually have the preceding instruction moved
3714 // into its delay slot. If it can, the branch locations need to be decremented.
3715 //
3716 // We could make the check before creating the branch object and avoid the location
3717 // adjustment, but the check is cleaner when performed on an initialized branch
3718 // object.
3719 //
3720 // If the branch is backwards (to a previously bound label), reducing the locations
3721 // cannot cause a short branch to exceed its offset range because the offset reduces.
3722 // And this is not at all a problem for a long branch backwards.
3723 //
3724 // If the branch is forward (not linked to any label yet), reducing the locations
3725 // is harmless. The branch will be promoted to long if needed when the target is known.
3726 CHECK_EQ(location_, old_location_);
3727 CHECK_GE(old_location_, sizeof(uint32_t));
3728 old_location_ -= sizeof(uint32_t);
3729 location_ = old_location_;
3730}
3731
3732void MipsAssembler::MoveInstructionToDelaySlot(Branch& branch) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003733 if (branch.IsBare()) {
3734 // Delay slots are filled manually in bare branches.
3735 return;
3736 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003737 if (branch.CanHaveDelayedInstruction(delay_slot_)) {
3738 // The last instruction cannot be used in a different delay slot,
3739 // do not commit the label before it (if any).
3740 DsFsmDropLabel();
3741 // Remove the last emitted instruction.
3742 size_t size = buffer_.Size();
3743 CHECK_GE(size, sizeof(uint32_t));
3744 size -= sizeof(uint32_t);
3745 CHECK_EQ(buffer_.Load<uint32_t>(size), delay_slot_.instruction_);
3746 buffer_.Resize(size);
3747 // Attach it to the branch and adjust the branch locations.
3748 branch.DecrementLocations();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003749 branch.SetDelayedInstruction(delay_slot_.instruction_, delay_slot_.patcher_label_);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003750 } else if (!reordering_ && branch.GetType() == Branch::kUncondBranch) {
3751 // If reordefing is disabled, prevent absorption of the target instruction.
3752 branch.SetDelayedInstruction(Branch::kUnfillableDelaySlot);
3753 }
3754}
3755
Alexey Frunze0cab6562017-07-25 15:19:36 -07003756void MipsAssembler::Buncond(MipsLabel* label, bool is_r6, bool is_bare) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003757 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze0cab6562017-07-25 15:19:36 -07003758 branches_.emplace_back(is_r6, buffer_.Size(), target, /* is_call */ false, is_bare);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003759 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003760 FinalizeLabeledBranch(label);
3761}
3762
Alexey Frunze0cab6562017-07-25 15:19:36 -07003763void MipsAssembler::Bcond(MipsLabel* label,
3764 bool is_r6,
3765 bool is_bare,
3766 BranchCondition condition,
3767 Register lhs,
3768 Register rhs) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003769 // If lhs = rhs, this can be a NOP.
3770 if (Branch::IsNop(condition, lhs, rhs)) {
3771 return;
3772 }
3773 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze0cab6562017-07-25 15:19:36 -07003774 branches_.emplace_back(is_r6, buffer_.Size(), target, condition, lhs, rhs, is_bare);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003775 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003776 FinalizeLabeledBranch(label);
3777}
3778
Alexey Frunze0cab6562017-07-25 15:19:36 -07003779void MipsAssembler::Call(MipsLabel* label, bool is_r6, bool is_bare) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003780 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze0cab6562017-07-25 15:19:36 -07003781 branches_.emplace_back(is_r6, buffer_.Size(), target, /* is_call */ true, is_bare);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003782 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003783 FinalizeLabeledBranch(label);
3784}
3785
Alexey Frunze96b66822016-09-10 02:32:44 -07003786void MipsAssembler::LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label) {
3787 // Label address loads are treated as pseudo branches since they require very similar handling.
3788 DCHECK(!label->IsBound());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003789 // If `pc_rel_base_label_` isn't bound or none of registers contains its address, we
3790 // may generate an individual NAL instruction to simulate PC-relative addressing on R2
3791 // by specifying `base_reg` of `ZERO`. Check for it.
3792 if (base_reg == ZERO && !IsR6()) {
3793 Nal();
3794 }
Alexey Frunze96b66822016-09-10 02:32:44 -07003795 branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLabel);
3796 FinalizeLabeledBranch(label);
3797}
3798
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003799Literal* MipsAssembler::NewLiteral(size_t size, const uint8_t* data) {
3800 DCHECK(size == 4u || size == 8u) << size;
3801 literals_.emplace_back(size, data);
3802 return &literals_.back();
3803}
3804
3805void MipsAssembler::LoadLiteral(Register dest_reg, Register base_reg, Literal* literal) {
3806 // Literal loads are treated as pseudo branches since they require very similar handling.
3807 DCHECK_EQ(literal->GetSize(), 4u);
3808 MipsLabel* label = literal->GetLabel();
3809 DCHECK(!label->IsBound());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07003810 // If `pc_rel_base_label_` isn't bound or none of registers contains its address, we
3811 // may generate an individual NAL instruction to simulate PC-relative addressing on R2
3812 // by specifying `base_reg` of `ZERO`. Check for it.
3813 if (base_reg == ZERO && !IsR6()) {
3814 Nal();
3815 }
Alexey Frunze96b66822016-09-10 02:32:44 -07003816 branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLiteral);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003817 FinalizeLabeledBranch(label);
3818}
3819
Alexey Frunze96b66822016-09-10 02:32:44 -07003820JumpTable* MipsAssembler::CreateJumpTable(std::vector<MipsLabel*>&& labels) {
3821 jump_tables_.emplace_back(std::move(labels));
3822 JumpTable* table = &jump_tables_.back();
3823 DCHECK(!table->GetLabel()->IsBound());
3824 return table;
3825}
3826
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003827void MipsAssembler::EmitLiterals() {
3828 if (!literals_.empty()) {
3829 // We don't support byte and half-word literals.
3830 // TODO: proper alignment for 64-bit literals when they're implemented.
3831 for (Literal& literal : literals_) {
3832 MipsLabel* label = literal.GetLabel();
3833 Bind(label);
3834 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
3835 DCHECK(literal.GetSize() == 4u || literal.GetSize() == 8u);
3836 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
3837 buffer_.Emit<uint8_t>(literal.GetData()[i]);
3838 }
3839 }
3840 }
3841}
3842
Alexey Frunze96b66822016-09-10 02:32:44 -07003843void MipsAssembler::ReserveJumpTableSpace() {
3844 if (!jump_tables_.empty()) {
3845 for (JumpTable& table : jump_tables_) {
3846 MipsLabel* label = table.GetLabel();
3847 Bind(label);
3848
3849 // Bulk ensure capacity, as this may be large.
3850 size_t orig_size = buffer_.Size();
3851 size_t required_capacity = orig_size + table.GetSize();
3852 if (required_capacity > buffer_.Capacity()) {
3853 buffer_.ExtendCapacity(required_capacity);
3854 }
3855#ifndef NDEBUG
3856 buffer_.has_ensured_capacity_ = true;
3857#endif
3858
3859 // Fill the space with dummy data as the data is not final
3860 // until the branches have been promoted. And we shouldn't
3861 // be moving uninitialized data during branch promotion.
3862 for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
3863 buffer_.Emit<uint32_t>(0x1abe1234u);
3864 }
3865
3866#ifndef NDEBUG
3867 buffer_.has_ensured_capacity_ = false;
3868#endif
3869 }
3870 }
3871}
3872
3873void MipsAssembler::EmitJumpTables() {
3874 if (!jump_tables_.empty()) {
3875 CHECK(!overwriting_);
3876 // Switch from appending instructions at the end of the buffer to overwriting
3877 // existing instructions (here, jump tables) in the buffer.
3878 overwriting_ = true;
3879
3880 for (JumpTable& table : jump_tables_) {
3881 MipsLabel* table_label = table.GetLabel();
3882 uint32_t start = GetLabelLocation(table_label);
3883 overwrite_location_ = start;
3884
3885 for (MipsLabel* target : table.GetData()) {
3886 CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
3887 // The table will contain target addresses relative to the table start.
3888 uint32_t offset = GetLabelLocation(target) - start;
3889 Emit(offset);
3890 }
3891 }
3892
3893 overwriting_ = false;
3894 }
3895}
3896
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003897void MipsAssembler::PromoteBranches() {
3898 // Promote short branches to long as necessary.
3899 bool changed;
3900 do {
3901 changed = false;
3902 for (auto& branch : branches_) {
3903 CHECK(branch.IsResolved());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003904 uint32_t base = GetBranchLocationOrPcRelBase(&branch);
3905 uint32_t delta = branch.PromoteIfNeeded(base);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003906 // If this branch has been promoted and needs to expand in size,
3907 // relocate all branches by the expansion size.
3908 if (delta) {
3909 changed = true;
3910 uint32_t expand_location = branch.GetLocation();
3911 for (auto& branch2 : branches_) {
3912 branch2.Relocate(expand_location, delta);
3913 }
3914 }
3915 }
3916 } while (changed);
3917
3918 // Account for branch expansion by resizing the code buffer
3919 // and moving the code in it to its final location.
3920 size_t branch_count = branches_.size();
3921 if (branch_count > 0) {
3922 // Resize.
3923 Branch& last_branch = branches_[branch_count - 1];
3924 uint32_t size_delta = last_branch.GetEndLocation() - last_branch.GetOldEndLocation();
3925 uint32_t old_size = buffer_.Size();
3926 buffer_.Resize(old_size + size_delta);
3927 // Move the code residing between branch placeholders.
3928 uint32_t end = old_size;
3929 for (size_t i = branch_count; i > 0; ) {
3930 Branch& branch = branches_[--i];
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003931 CHECK_GE(end, branch.GetOldEndLocation());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003932 uint32_t size = end - branch.GetOldEndLocation();
3933 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
3934 end = branch.GetOldLocation();
3935 }
3936 }
3937}
3938
3939// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
3940const MipsAssembler::Branch::BranchInfo MipsAssembler::Branch::branch_info_[] = {
Alexey Frunze0cab6562017-07-25 15:19:36 -07003941 // R2 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003942 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kUncondBranch
3943 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCondBranch
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003944 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCall
Alexey Frunze0cab6562017-07-25 15:19:36 -07003945 // R2 short branches (can't be promoted to long), delay slots filled manually.
3946 { 1, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kBareUncondBranch
3947 { 1, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kBareCondBranch
3948 { 1, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kBareCall
Alexey Frunze96b66822016-09-10 02:32:44 -07003949 // R2 near label.
3950 { 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003951 // R2 near literal.
3952 { 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLiteral
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003953 // R2 long branches.
3954 { 9, 3, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongUncondBranch
3955 { 10, 4, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCondBranch
3956 { 6, 1, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCall
Alexey Frunze96b66822016-09-10 02:32:44 -07003957 // R2 far label.
3958 { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003959 // R2 far literal.
3960 { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLiteral
Alexey Frunze0cab6562017-07-25 15:19:36 -07003961 // R6 short branches (can be promoted to long).
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003962 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6UncondBranch
3963 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kR6CondBranch
3964 // Exception: kOffset23 for beqzc/bnezc.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003965 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6Call
Alexey Frunze0cab6562017-07-25 15:19:36 -07003966 // R6 short branches (can't be promoted to long), forbidden/delay slots filled manually.
3967 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6BareUncondBranch
3968 { 1, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kR6BareCondBranch
3969 // Exception: kOffset23 for beqzc/bnezc.
3970 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6BareCall
Alexey Frunze96b66822016-09-10 02:32:44 -07003971 // R6 near label.
3972 { 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Label
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003973 // R6 near literal.
3974 { 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Literal
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003975 // R6 long branches.
3976 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongUncondBranch
3977 { 3, 1, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCondBranch
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003978 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCall
Alexey Frunze96b66822016-09-10 02:32:44 -07003979 // R6 far label.
3980 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003981 // R6 far literal.
3982 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLiteral
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003983};
3984
Alexey Frunzea663d9d2017-07-31 18:43:18 -07003985static inline bool IsAbsorbableInstruction(uint32_t instruction) {
3986 // The relative patcher patches addiu, lw and sw with an immediate operand of 0x5678.
3987 // We want to make sure that these instructions do not get absorbed into delay slots
3988 // of unconditional branches on R2. Absorption would otherwise make copies of
3989 // unpatched instructions.
3990 if ((instruction & 0xFFFF) != 0x5678) {
3991 return true;
3992 }
3993 switch (instruction >> kOpcodeShift) {
3994 case 0x09: // Addiu.
3995 case 0x23: // Lw.
3996 case 0x2B: // Sw.
3997 return false;
3998 default:
3999 return true;
4000 }
4001}
4002
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07004003static inline Register GetR2PcRelBaseRegister(Register reg) {
4004 // LoadLabelAddress() and LoadLiteral() generate individual NAL
4005 // instructions on R2 when the specified base register is ZERO
4006 // and so the effective PC-relative base register is RA, not ZERO.
4007 return (reg == ZERO) ? RA : reg;
4008}
4009
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004010// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
Alexey Frunzea663d9d2017-07-31 18:43:18 -07004011void MipsAssembler::EmitBranch(uint32_t branch_id) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004012 CHECK_EQ(overwriting_, true);
Alexey Frunzea663d9d2017-07-31 18:43:18 -07004013 Branch* branch = GetBranch(branch_id);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004014 overwrite_location_ = branch->GetLocation();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004015 uint32_t offset = branch->GetOffset(GetBranchOrPcRelBaseForEncoding(branch));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004016 BranchCondition condition = branch->GetCondition();
4017 Register lhs = branch->GetLeftRegister();
4018 Register rhs = branch->GetRightRegister();
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004019 uint32_t delayed_instruction = branch->GetDelayedInstruction();
Alexey Frunzea663d9d2017-07-31 18:43:18 -07004020 MipsLabel* patcher_label = branch->GetPatcherLabel();
4021 if (patcher_label != nullptr) {
4022 // Update the patcher label location to account for branch promotion and
4023 // delay slot filling.
4024 CHECK(patcher_label->IsBound());
4025 uint32_t bound_pc = branch->GetLocation();
4026 if (!branch->IsLong()) {
4027 // Short branches precede delay slots.
4028 // Long branches follow "delay slots".
4029 bound_pc += sizeof(uint32_t);
4030 }
4031 // Rebind the label.
4032 patcher_label->Reinitialize();
4033 BindRelativeToPrecedingBranch(patcher_label, branch_id, bound_pc);
4034 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004035 switch (branch->GetType()) {
4036 // R2 short branches.
4037 case Branch::kUncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004038 if (delayed_instruction == Branch::kUnfillableDelaySlot) {
4039 // The branch was created when reordering was disabled, do not absorb the target
4040 // instruction.
4041 delayed_instruction = 0; // NOP.
4042 } else if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4043 // Try to absorb the target instruction into the delay slot.
4044 delayed_instruction = 0; // NOP.
4045 // Incrementing the signed 16-bit offset past the target instruction must not
4046 // cause overflow into the negative subrange, check for the max offset.
4047 if (offset != 0x7FFF) {
4048 uint32_t target = branch->GetTarget();
4049 if (std::binary_search(ds_fsm_target_pcs_.begin(), ds_fsm_target_pcs_.end(), target)) {
Alexey Frunzea663d9d2017-07-31 18:43:18 -07004050 uint32_t target_instruction = buffer_.Load<uint32_t>(target);
4051 if (IsAbsorbableInstruction(target_instruction)) {
4052 delayed_instruction = target_instruction;
4053 offset++;
4054 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004055 }
4056 }
4057 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004058 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4059 B(offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004060 Emit(delayed_instruction);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004061 break;
4062 case Branch::kCondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004063 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4064 if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4065 delayed_instruction = 0; // NOP.
4066 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004067 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004068 EmitBcondR2(condition, lhs, rhs, offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004069 Emit(delayed_instruction);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004070 break;
4071 case Branch::kCall:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004072 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4073 if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4074 delayed_instruction = 0; // NOP.
4075 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004076 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004077 Bal(offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004078 Emit(delayed_instruction);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004079 break;
Alexey Frunze0cab6562017-07-25 15:19:36 -07004080 case Branch::kBareUncondBranch:
4081 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4082 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4083 B(offset);
4084 break;
4085 case Branch::kBareCondBranch:
4086 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4087 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4088 EmitBcondR2(condition, lhs, rhs, offset);
4089 break;
4090 case Branch::kBareCall:
4091 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4092 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4093 Bal(offset);
4094 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004095
Alexey Frunze96b66822016-09-10 02:32:44 -07004096 // R2 near label.
4097 case Branch::kLabel:
4098 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4099 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07004100 Addiu(lhs, GetR2PcRelBaseRegister(rhs), offset);
Alexey Frunze96b66822016-09-10 02:32:44 -07004101 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004102 // R2 near literal.
4103 case Branch::kLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004104 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004105 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07004106 Lw(lhs, GetR2PcRelBaseRegister(rhs), offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004107 break;
4108
4109 // R2 long branches.
4110 case Branch::kLongUncondBranch:
4111 // To get the value of the PC register we need to use the NAL instruction.
4112 // NAL clobbers the RA register. However, RA must be preserved if the
4113 // method is compiled without the entry/exit sequences that would take care
4114 // of preserving RA (typically, leaf methods don't preserve RA explicitly).
4115 // So, we need to preserve RA in some temporary storage ourselves. The AT
4116 // register can't be used for this because we need it to load a constant
4117 // which will be added to the value that NAL stores in RA. And we can't
4118 // use T9 for this in the context of the JNI compiler, which uses it
4119 // as a scratch register (see InterproceduralScratchRegister()).
4120 // If we were to add a 32-bit constant to RA using two ADDIU instructions,
4121 // we'd also need to use the ROTR instruction, which requires no less than
4122 // MIPSR2.
4123 // Perhaps, we could use T8 or one of R2's multiplier/divider registers
4124 // (LO or HI) or even a floating-point register, but that doesn't seem
4125 // like a nice solution. We may want this to work on both R6 and pre-R6.
4126 // For now simply use the stack for RA. This should be OK since for the
4127 // vast majority of code a short PC-relative branch is sufficient.
4128 // TODO: can this be improved?
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004129 // TODO: consider generation of a shorter sequence when we know that RA
4130 // is explicitly preserved by the method entry/exit code.
4131 if (delayed_instruction != Branch::kUnfilledDelaySlot &&
4132 delayed_instruction != Branch::kUnfillableDelaySlot) {
4133 Emit(delayed_instruction);
4134 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004135 Push(RA);
4136 Nal();
4137 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4138 Lui(AT, High16Bits(offset));
4139 Ori(AT, AT, Low16Bits(offset));
4140 Addu(AT, AT, RA);
4141 Lw(RA, SP, 0);
4142 Jr(AT);
Chris Larsen715f43e2017-10-23 11:00:32 -07004143 DecreaseFrameSize(kStackAlignment);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004144 break;
4145 case Branch::kLongCondBranch:
4146 // The comment on case 'Branch::kLongUncondBranch' applies here as well.
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004147 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4148 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4149 Emit(delayed_instruction);
4150 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004151 // Note: the opposite condition branch encodes 8 as the distance, which is equal to the
4152 // number of instructions skipped:
4153 // (PUSH(IncreaseFrameSize(ADDIU) + SW) + NAL + LUI + ORI + ADDU + LW + JR).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004154 EmitBcondR2(Branch::OppositeCondition(condition), lhs, rhs, 8);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004155 Push(RA);
4156 Nal();
4157 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4158 Lui(AT, High16Bits(offset));
4159 Ori(AT, AT, Low16Bits(offset));
4160 Addu(AT, AT, RA);
4161 Lw(RA, SP, 0);
4162 Jr(AT);
Chris Larsen715f43e2017-10-23 11:00:32 -07004163 DecreaseFrameSize(kStackAlignment);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004164 break;
4165 case Branch::kLongCall:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004166 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4167 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4168 Emit(delayed_instruction);
4169 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004170 Nal();
4171 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4172 Lui(AT, High16Bits(offset));
4173 Ori(AT, AT, Low16Bits(offset));
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004174 Addu(AT, AT, RA);
4175 Jalr(AT);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004176 Nop();
4177 break;
4178
Alexey Frunze96b66822016-09-10 02:32:44 -07004179 // R2 far label.
4180 case Branch::kFarLabel:
4181 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4182 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4183 Lui(AT, High16Bits(offset));
4184 Ori(AT, AT, Low16Bits(offset));
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07004185 Addu(lhs, AT, GetR2PcRelBaseRegister(rhs));
Alexey Frunze96b66822016-09-10 02:32:44 -07004186 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004187 // R2 far literal.
4188 case Branch::kFarLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004189 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004190 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
4191 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4192 Lui(AT, High16Bits(offset));
Alexey Frunze3b8c82f2017-10-10 23:01:34 -07004193 Addu(AT, AT, GetR2PcRelBaseRegister(rhs));
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004194 Lw(lhs, AT, Low16Bits(offset));
4195 break;
4196
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004197 // R6 short branches.
4198 case Branch::kR6UncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004199 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004200 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4201 Bc(offset);
4202 break;
4203 case Branch::kR6CondBranch:
4204 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004205 EmitBcondR6(condition, lhs, rhs, offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004206 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4207 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4208 Emit(delayed_instruction);
4209 } else {
4210 // TODO: improve by filling the forbidden slot (IFF this is
4211 // a forbidden and not a delay slot).
4212 Nop();
4213 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004214 break;
4215 case Branch::kR6Call:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004216 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004217 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004218 Balc(offset);
4219 break;
Alexey Frunze0cab6562017-07-25 15:19:36 -07004220 case Branch::kR6BareUncondBranch:
4221 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4222 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4223 Bc(offset);
4224 break;
4225 case Branch::kR6BareCondBranch:
4226 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4227 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4228 EmitBcondR6(condition, lhs, rhs, offset);
4229 break;
4230 case Branch::kR6BareCall:
4231 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4232 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4233 Balc(offset);
4234 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004235
Alexey Frunze96b66822016-09-10 02:32:44 -07004236 // R6 near label.
4237 case Branch::kR6Label:
4238 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4239 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4240 Addiupc(lhs, offset);
4241 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004242 // R6 near literal.
4243 case Branch::kR6Literal:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004244 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004245 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4246 Lwpc(lhs, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004247 break;
4248
4249 // R6 long branches.
4250 case Branch::kR6LongUncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004251 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004252 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
4253 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4254 Auipc(AT, High16Bits(offset));
4255 Jic(AT, Low16Bits(offset));
4256 break;
4257 case Branch::kR6LongCondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004258 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4259 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4260 Emit(delayed_instruction);
4261 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004262 EmitBcondR6(Branch::OppositeCondition(condition), lhs, rhs, 2);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004263 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
4264 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4265 Auipc(AT, High16Bits(offset));
4266 Jic(AT, Low16Bits(offset));
4267 break;
4268 case Branch::kR6LongCall:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004269 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004270 offset += (offset & 0x8000) << 1; // Account for sign extension in jialc.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004271 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004272 Auipc(AT, High16Bits(offset));
4273 Jialc(AT, Low16Bits(offset));
4274 break;
4275
Alexey Frunze96b66822016-09-10 02:32:44 -07004276 // R6 far label.
4277 case Branch::kR6FarLabel:
4278 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4279 offset += (offset & 0x8000) << 1; // Account for sign extension in addiu.
4280 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4281 Auipc(AT, High16Bits(offset));
4282 Addiu(lhs, AT, Low16Bits(offset));
4283 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004284 // R6 far literal.
4285 case Branch::kR6FarLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004286 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004287 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
4288 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4289 Auipc(AT, High16Bits(offset));
4290 Lw(lhs, AT, Low16Bits(offset));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004291 break;
4292 }
4293 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
4294 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
Alexey Frunzea663d9d2017-07-31 18:43:18 -07004295 if (patcher_label != nullptr) {
4296 // The patched instruction should look like one.
4297 uint32_t patched_instruction = buffer_.Load<uint32_t>(GetLabelLocation(patcher_label));
4298 CHECK(!IsAbsorbableInstruction(patched_instruction));
4299 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004300}
4301
Alexey Frunze0cab6562017-07-25 15:19:36 -07004302void MipsAssembler::B(MipsLabel* label, bool is_bare) {
4303 Buncond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004304}
4305
Alexey Frunze0cab6562017-07-25 15:19:36 -07004306void MipsAssembler::Bal(MipsLabel* label, bool is_bare) {
4307 Call(label, /* is_r6 */ (IsR6() && !is_bare), is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004308}
4309
Alexey Frunze0cab6562017-07-25 15:19:36 -07004310void MipsAssembler::Beq(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4311 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondEQ, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004312}
4313
Alexey Frunze0cab6562017-07-25 15:19:36 -07004314void MipsAssembler::Bne(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4315 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondNE, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004316}
4317
Alexey Frunze0cab6562017-07-25 15:19:36 -07004318void MipsAssembler::Beqz(Register rt, MipsLabel* label, bool is_bare) {
4319 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondEQZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004320}
4321
Alexey Frunze0cab6562017-07-25 15:19:36 -07004322void MipsAssembler::Bnez(Register rt, MipsLabel* label, bool is_bare) {
4323 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondNEZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004324}
4325
Alexey Frunze0cab6562017-07-25 15:19:36 -07004326void MipsAssembler::Bltz(Register rt, MipsLabel* label, bool is_bare) {
4327 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondLTZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004328}
4329
Alexey Frunze0cab6562017-07-25 15:19:36 -07004330void MipsAssembler::Bgez(Register rt, MipsLabel* label, bool is_bare) {
4331 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondGEZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004332}
4333
Alexey Frunze0cab6562017-07-25 15:19:36 -07004334void MipsAssembler::Blez(Register rt, MipsLabel* label, bool is_bare) {
4335 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondLEZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004336}
4337
Alexey Frunze0cab6562017-07-25 15:19:36 -07004338void MipsAssembler::Bgtz(Register rt, MipsLabel* label, bool is_bare) {
4339 Bcond(label, /* is_r6 */ (IsR6() && !is_bare), is_bare, kCondGTZ, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004340}
4341
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004342bool MipsAssembler::CanExchangeWithSlt(Register rs, Register rt) const {
4343 // If the instruction modifies AT, `rs` or `rt`, it can't be exchanged with the slt[u]
4344 // instruction because either slt[u] depends on `rs` or `rt` or the following
4345 // conditional branch depends on AT set by slt[u].
4346 // Likewise, if the instruction depends on AT, it can't be exchanged with slt[u]
4347 // because slt[u] changes AT.
4348 return (delay_slot_.instruction_ != 0 &&
Alexey Frunzea247dea2017-11-03 18:43:04 -07004349 (delay_slot_.masks_.gpr_outs_ & ((1u << AT) | (1u << rs) | (1u << rt))) == 0 &&
4350 (delay_slot_.masks_.gpr_ins_ & (1u << AT)) == 0);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004351}
4352
4353void MipsAssembler::ExchangeWithSlt(const DelaySlot& forwarded_slot) {
4354 // Exchange the last two instructions in the assembler buffer.
4355 size_t size = buffer_.Size();
4356 CHECK_GE(size, 2 * sizeof(uint32_t));
4357 size_t pos1 = size - 2 * sizeof(uint32_t);
4358 size_t pos2 = size - sizeof(uint32_t);
4359 uint32_t instr1 = buffer_.Load<uint32_t>(pos1);
4360 uint32_t instr2 = buffer_.Load<uint32_t>(pos2);
4361 CHECK_EQ(instr1, forwarded_slot.instruction_);
4362 CHECK_EQ(instr2, delay_slot_.instruction_);
4363 buffer_.Store<uint32_t>(pos1, instr2);
4364 buffer_.Store<uint32_t>(pos2, instr1);
4365 // Set the current delay slot information to that of the last instruction
4366 // in the buffer.
4367 delay_slot_ = forwarded_slot;
4368}
4369
4370void MipsAssembler::GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt) {
4371 // If possible, exchange the slt[u] instruction with the preceding instruction,
4372 // so it can fill the delay slot.
4373 DelaySlot forwarded_slot = delay_slot_;
4374 bool exchange = CanExchangeWithSlt(rs, rt);
4375 if (exchange) {
4376 // The last instruction cannot be used in a different delay slot,
4377 // do not commit the label before it (if any).
4378 DsFsmDropLabel();
4379 }
4380 if (unsigned_slt) {
4381 Sltu(AT, rs, rt);
4382 } else {
4383 Slt(AT, rs, rt);
4384 }
4385 if (exchange) {
4386 ExchangeWithSlt(forwarded_slot);
4387 }
4388}
4389
Alexey Frunze0cab6562017-07-25 15:19:36 -07004390void MipsAssembler::Blt(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4391 if (IsR6() && !is_bare) {
4392 Bcond(label, IsR6(), is_bare, kCondLT, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004393 } else if (!Branch::IsNop(kCondLT, rs, rt)) {
4394 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004395 GenerateSltForCondBranch(/* unsigned_slt */ false, rs, rt);
Alexey Frunze0cab6562017-07-25 15:19:36 -07004396 Bnez(AT, label, is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004397 }
4398}
4399
Alexey Frunze0cab6562017-07-25 15:19:36 -07004400void MipsAssembler::Bge(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4401 if (IsR6() && !is_bare) {
4402 Bcond(label, IsR6(), is_bare, kCondGE, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004403 } else if (Branch::IsUncond(kCondGE, rs, rt)) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07004404 B(label, is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004405 } else {
4406 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004407 GenerateSltForCondBranch(/* unsigned_slt */ false, rs, rt);
Alexey Frunze0cab6562017-07-25 15:19:36 -07004408 Beqz(AT, label, is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004409 }
4410}
4411
Alexey Frunze0cab6562017-07-25 15:19:36 -07004412void MipsAssembler::Bltu(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4413 if (IsR6() && !is_bare) {
4414 Bcond(label, IsR6(), is_bare, kCondLTU, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004415 } else if (!Branch::IsNop(kCondLTU, rs, rt)) {
4416 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004417 GenerateSltForCondBranch(/* unsigned_slt */ true, rs, rt);
Alexey Frunze0cab6562017-07-25 15:19:36 -07004418 Bnez(AT, label, is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004419 }
4420}
4421
Alexey Frunze0cab6562017-07-25 15:19:36 -07004422void MipsAssembler::Bgeu(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4423 if (IsR6() && !is_bare) {
4424 Bcond(label, IsR6(), is_bare, kCondGEU, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004425 } else if (Branch::IsUncond(kCondGEU, rs, rt)) {
Alexey Frunze0cab6562017-07-25 15:19:36 -07004426 B(label, is_bare);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004427 } else {
4428 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004429 GenerateSltForCondBranch(/* unsigned_slt */ true, rs, rt);
Alexey Frunze0cab6562017-07-25 15:19:36 -07004430 Beqz(AT, label, is_bare);
jeffhao7fbee072012-08-24 17:56:54 -07004431 }
4432}
4433
Alexey Frunze0cab6562017-07-25 15:19:36 -07004434void MipsAssembler::Bc1f(MipsLabel* label, bool is_bare) {
4435 Bc1f(0, label, is_bare);
Chris Larsenb74353a2015-11-20 09:07:09 -08004436}
4437
Alexey Frunze0cab6562017-07-25 15:19:36 -07004438void MipsAssembler::Bc1f(int cc, MipsLabel* label, bool is_bare) {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004439 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze0cab6562017-07-25 15:19:36 -07004440 Bcond(label, /* is_r6 */ false, is_bare, kCondF, static_cast<Register>(cc), ZERO);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004441}
4442
Alexey Frunze0cab6562017-07-25 15:19:36 -07004443void MipsAssembler::Bc1t(MipsLabel* label, bool is_bare) {
4444 Bc1t(0, label, is_bare);
Chris Larsenb74353a2015-11-20 09:07:09 -08004445}
4446
Alexey Frunze0cab6562017-07-25 15:19:36 -07004447void MipsAssembler::Bc1t(int cc, MipsLabel* label, bool is_bare) {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004448 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze0cab6562017-07-25 15:19:36 -07004449 Bcond(label, /* is_r6 */ false, is_bare, kCondT, static_cast<Register>(cc), ZERO);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004450}
4451
Alexey Frunze0cab6562017-07-25 15:19:36 -07004452void MipsAssembler::Bc(MipsLabel* label, bool is_bare) {
4453 Buncond(label, /* is_r6 */ true, is_bare);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004454}
4455
Alexey Frunze0cab6562017-07-25 15:19:36 -07004456void MipsAssembler::Balc(MipsLabel* label, bool is_bare) {
4457 Call(label, /* is_r6 */ true, is_bare);
4458}
4459
4460void MipsAssembler::Beqc(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4461 Bcond(label, /* is_r6 */ true, is_bare, kCondEQ, rs, rt);
4462}
4463
4464void MipsAssembler::Bnec(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4465 Bcond(label, /* is_r6 */ true, is_bare, kCondNE, rs, rt);
4466}
4467
4468void MipsAssembler::Beqzc(Register rt, MipsLabel* label, bool is_bare) {
4469 Bcond(label, /* is_r6 */ true, is_bare, kCondEQZ, rt);
4470}
4471
4472void MipsAssembler::Bnezc(Register rt, MipsLabel* label, bool is_bare) {
4473 Bcond(label, /* is_r6 */ true, is_bare, kCondNEZ, rt);
4474}
4475
4476void MipsAssembler::Bltzc(Register rt, MipsLabel* label, bool is_bare) {
4477 Bcond(label, /* is_r6 */ true, is_bare, kCondLTZ, rt);
4478}
4479
4480void MipsAssembler::Bgezc(Register rt, MipsLabel* label, bool is_bare) {
4481 Bcond(label, /* is_r6 */ true, is_bare, kCondGEZ, rt);
4482}
4483
4484void MipsAssembler::Blezc(Register rt, MipsLabel* label, bool is_bare) {
4485 Bcond(label, /* is_r6 */ true, is_bare, kCondLEZ, rt);
4486}
4487
4488void MipsAssembler::Bgtzc(Register rt, MipsLabel* label, bool is_bare) {
4489 Bcond(label, /* is_r6 */ true, is_bare, kCondGTZ, rt);
4490}
4491
4492void MipsAssembler::Bltc(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4493 Bcond(label, /* is_r6 */ true, is_bare, kCondLT, rs, rt);
4494}
4495
4496void MipsAssembler::Bgec(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4497 Bcond(label, /* is_r6 */ true, is_bare, kCondGE, rs, rt);
4498}
4499
4500void MipsAssembler::Bltuc(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4501 Bcond(label, /* is_r6 */ true, is_bare, kCondLTU, rs, rt);
4502}
4503
4504void MipsAssembler::Bgeuc(Register rs, Register rt, MipsLabel* label, bool is_bare) {
4505 Bcond(label, /* is_r6 */ true, is_bare, kCondGEU, rs, rt);
4506}
4507
4508void MipsAssembler::Bc1eqz(FRegister ft, MipsLabel* label, bool is_bare) {
4509 Bcond(label, /* is_r6 */ true, is_bare, kCondF, static_cast<Register>(ft), ZERO);
4510}
4511
4512void MipsAssembler::Bc1nez(FRegister ft, MipsLabel* label, bool is_bare) {
4513 Bcond(label, /* is_r6 */ true, is_bare, kCondT, static_cast<Register>(ft), ZERO);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004514}
4515
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004516void MipsAssembler::AdjustBaseAndOffset(Register& base,
4517 int32_t& offset,
4518 bool is_doubleword,
4519 bool is_float) {
4520 // This method is used to adjust the base register and offset pair
4521 // for a load/store when the offset doesn't fit into int16_t.
4522 // It is assumed that `base + offset` is sufficiently aligned for memory
4523 // operands that are machine word in size or smaller. For doubleword-sized
4524 // operands it's assumed that `base` is a multiple of 8, while `offset`
4525 // may be a multiple of 4 (e.g. 4-byte-aligned long and double arguments
4526 // and spilled variables on the stack accessed relative to the stack
4527 // pointer register).
4528 // We preserve the "alignment" of `offset` by adjusting it by a multiple of 8.
4529 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
4530
4531 bool doubleword_aligned = IsAligned<kMipsDoublewordSize>(offset);
4532 bool two_accesses = is_doubleword && (!is_float || !doubleword_aligned);
4533
4534 // IsInt<16> must be passed a signed value, hence the static cast below.
4535 if (IsInt<16>(offset) &&
4536 (!two_accesses || IsInt<16>(static_cast<int32_t>(offset + kMipsWordSize)))) {
4537 // Nothing to do: `offset` (and, if needed, `offset + 4`) fits into int16_t.
4538 return;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004539 }
4540
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004541 // Remember the "(mis)alignment" of `offset`, it will be checked at the end.
4542 uint32_t misalignment = offset & (kMipsDoublewordSize - 1);
4543
4544 // Do not load the whole 32-bit `offset` if it can be represented as
4545 // a sum of two 16-bit signed offsets. This can save an instruction or two.
4546 // To simplify matters, only do this for a symmetric range of offsets from
4547 // about -64KB to about +64KB, allowing further addition of 4 when accessing
4548 // 64-bit variables with two 32-bit accesses.
4549 constexpr int32_t kMinOffsetForSimpleAdjustment = 0x7ff8; // Max int16_t that's a multiple of 8.
4550 constexpr int32_t kMaxOffsetForSimpleAdjustment = 2 * kMinOffsetForSimpleAdjustment;
4551 if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
4552 Addiu(AT, base, kMinOffsetForSimpleAdjustment);
4553 offset -= kMinOffsetForSimpleAdjustment;
4554 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
4555 Addiu(AT, base, -kMinOffsetForSimpleAdjustment);
4556 offset += kMinOffsetForSimpleAdjustment;
4557 } else if (IsR6()) {
4558 // On R6 take advantage of the aui instruction, e.g.:
4559 // aui AT, base, offset_high
4560 // lw reg_lo, offset_low(AT)
4561 // lw reg_hi, (offset_low+4)(AT)
4562 // or when offset_low+4 overflows int16_t:
4563 // aui AT, base, offset_high
4564 // addiu AT, AT, 8
4565 // lw reg_lo, (offset_low-8)(AT)
4566 // lw reg_hi, (offset_low-4)(AT)
4567 int16_t offset_high = High16Bits(offset);
4568 int16_t offset_low = Low16Bits(offset);
4569 offset_high += (offset_low < 0) ? 1 : 0; // Account for offset sign extension in load/store.
4570 Aui(AT, base, offset_high);
4571 if (two_accesses && !IsInt<16>(static_cast<int32_t>(offset_low + kMipsWordSize))) {
4572 // Avoid overflow in the 16-bit offset of the load/store instruction when adding 4.
4573 Addiu(AT, AT, kMipsDoublewordSize);
4574 offset_low -= kMipsDoublewordSize;
4575 }
4576 offset = offset_low;
4577 } else {
4578 // Do not load the whole 32-bit `offset` if it can be represented as
4579 // a sum of three 16-bit signed offsets. This can save an instruction.
4580 // To simplify matters, only do this for a symmetric range of offsets from
4581 // about -96KB to about +96KB, allowing further addition of 4 when accessing
4582 // 64-bit variables with two 32-bit accesses.
4583 constexpr int32_t kMinOffsetForMediumAdjustment = 2 * kMinOffsetForSimpleAdjustment;
4584 constexpr int32_t kMaxOffsetForMediumAdjustment = 3 * kMinOffsetForSimpleAdjustment;
4585 if (0 <= offset && offset <= kMaxOffsetForMediumAdjustment) {
4586 Addiu(AT, base, kMinOffsetForMediumAdjustment / 2);
4587 Addiu(AT, AT, kMinOffsetForMediumAdjustment / 2);
4588 offset -= kMinOffsetForMediumAdjustment;
4589 } else if (-kMaxOffsetForMediumAdjustment <= offset && offset < 0) {
4590 Addiu(AT, base, -kMinOffsetForMediumAdjustment / 2);
4591 Addiu(AT, AT, -kMinOffsetForMediumAdjustment / 2);
4592 offset += kMinOffsetForMediumAdjustment;
4593 } else {
4594 // Now that all shorter options have been exhausted, load the full 32-bit offset.
4595 int32_t loaded_offset = RoundDown(offset, kMipsDoublewordSize);
4596 LoadConst32(AT, loaded_offset);
4597 Addu(AT, AT, base);
4598 offset -= loaded_offset;
4599 }
4600 }
4601 base = AT;
4602
4603 CHECK(IsInt<16>(offset));
4604 if (two_accesses) {
4605 CHECK(IsInt<16>(static_cast<int32_t>(offset + kMipsWordSize)));
4606 }
4607 CHECK_EQ(misalignment, offset & (kMipsDoublewordSize - 1));
4608}
4609
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004610void MipsAssembler::AdjustBaseOffsetAndElementSizeShift(Register& base,
4611 int32_t& offset,
4612 int& element_size_shift) {
4613 // This method is used to adjust the base register, offset and element_size_shift
4614 // for a vector load/store when the offset doesn't fit into allowed number of bits.
4615 // MSA ld.df and st.df instructions take signed offsets as arguments, but maximum
4616 // offset is dependant on the size of the data format df (10-bit offsets for ld.b,
4617 // 11-bit for ld.h, 12-bit for ld.w and 13-bit for ld.d).
4618 // If element_size_shift is non-negative at entry, it won't be changed, but offset
4619 // will be checked for appropriate alignment. If negative at entry, it will be
4620 // adjusted based on offset for maximum fit.
4621 // It's assumed that `base` is a multiple of 8.
4622 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
4623
4624 if (element_size_shift >= 0) {
4625 CHECK_LE(element_size_shift, TIMES_8);
4626 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
4627 } else if (IsAligned<kMipsDoublewordSize>(offset)) {
4628 element_size_shift = TIMES_8;
4629 } else if (IsAligned<kMipsWordSize>(offset)) {
4630 element_size_shift = TIMES_4;
4631 } else if (IsAligned<kMipsHalfwordSize>(offset)) {
4632 element_size_shift = TIMES_2;
4633 } else {
4634 element_size_shift = TIMES_1;
4635 }
4636
4637 const int low_len = 10 + element_size_shift; // How many low bits of `offset` ld.df/st.df
4638 // will take.
4639 int16_t low = offset & ((1 << low_len) - 1); // Isolate these bits.
4640 low -= (low & (1 << (low_len - 1))) << 1; // Sign-extend these bits.
4641 if (low == offset) {
4642 return; // `offset` fits into ld.df/st.df.
4643 }
4644
4645 // First, see if `offset` can be represented as a sum of two or three signed offsets.
4646 // This can save an instruction or two.
4647
4648 // Max int16_t that's a multiple of element size.
4649 const int32_t kMaxDeltaForSimpleAdjustment = 0x8000 - (1 << element_size_shift);
4650 // Max ld.df/st.df offset that's a multiple of element size.
4651 const int32_t kMaxLoadStoreOffset = 0x1ff << element_size_shift;
4652 const int32_t kMaxOffsetForSimpleAdjustment = kMaxDeltaForSimpleAdjustment + kMaxLoadStoreOffset;
4653 const int32_t kMinOffsetForMediumAdjustment = 2 * kMaxDeltaForSimpleAdjustment;
4654 const int32_t kMaxOffsetForMediumAdjustment = kMinOffsetForMediumAdjustment + kMaxLoadStoreOffset;
4655
4656 if (IsInt<16>(offset)) {
4657 Addiu(AT, base, offset);
4658 offset = 0;
4659 } else if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
4660 Addiu(AT, base, kMaxDeltaForSimpleAdjustment);
4661 offset -= kMaxDeltaForSimpleAdjustment;
4662 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
4663 Addiu(AT, base, -kMaxDeltaForSimpleAdjustment);
4664 offset += kMaxDeltaForSimpleAdjustment;
4665 } else if (!IsR6() && 0 <= offset && offset <= kMaxOffsetForMediumAdjustment) {
4666 Addiu(AT, base, kMaxDeltaForSimpleAdjustment);
4667 if (offset <= kMinOffsetForMediumAdjustment) {
4668 Addiu(AT, AT, offset - kMaxDeltaForSimpleAdjustment);
4669 offset = 0;
4670 } else {
4671 Addiu(AT, AT, kMaxDeltaForSimpleAdjustment);
4672 offset -= kMinOffsetForMediumAdjustment;
4673 }
4674 } else if (!IsR6() && -kMaxOffsetForMediumAdjustment <= offset && offset < 0) {
4675 Addiu(AT, base, -kMaxDeltaForSimpleAdjustment);
4676 if (-kMinOffsetForMediumAdjustment <= offset) {
4677 Addiu(AT, AT, offset + kMaxDeltaForSimpleAdjustment);
4678 offset = 0;
4679 } else {
4680 Addiu(AT, AT, -kMaxDeltaForSimpleAdjustment);
4681 offset += kMinOffsetForMediumAdjustment;
4682 }
4683 } else {
4684 // 16-bit or smaller parts of `offset`:
4685 // |31 hi 16|15 mid 13-10|12-9 low 0|
4686 //
4687 // Instructions that supply each part as a signed integer addend:
4688 // |aui |addiu |ld.df/st.df |
4689 uint32_t tmp = static_cast<uint32_t>(offset) - low; // Exclude `low` from the rest of `offset`
4690 // (accounts for sign of `low`).
4691 tmp += (tmp & (UINT32_C(1) << 15)) << 1; // Account for sign extension in addiu.
4692 int16_t mid = Low16Bits(tmp);
4693 int16_t hi = High16Bits(tmp);
4694 if (IsR6()) {
4695 Aui(AT, base, hi);
4696 } else {
4697 Lui(AT, hi);
4698 Addu(AT, AT, base);
4699 }
4700 if (mid != 0) {
4701 Addiu(AT, AT, mid);
4702 }
4703 offset = low;
4704 }
4705 base = AT;
4706 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
4707 CHECK(IsInt<10>(offset >> element_size_shift));
4708}
4709
Alexey Frunze2923db72016-08-20 01:55:47 -07004710void MipsAssembler::LoadFromOffset(LoadOperandType type,
4711 Register reg,
4712 Register base,
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004713 int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004714 LoadFromOffset<>(type, reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004715}
4716
4717void MipsAssembler::LoadSFromOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004718 LoadSFromOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004719}
4720
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004721void MipsAssembler::LoadDFromOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004722 LoadDFromOffset<>(reg, base, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004723}
4724
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004725void MipsAssembler::LoadQFromOffset(FRegister reg, Register base, int32_t offset) {
4726 LoadQFromOffset<>(reg, base, offset);
4727}
4728
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004729void MipsAssembler::EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset,
4730 size_t size) {
4731 MipsManagedRegister dst = m_dst.AsMips();
4732 if (dst.IsNoRegister()) {
4733 CHECK_EQ(0u, size) << dst;
4734 } else if (dst.IsCoreRegister()) {
4735 CHECK_EQ(kMipsWordSize, size) << dst;
4736 LoadFromOffset(kLoadWord, dst.AsCoreRegister(), src_register, src_offset);
4737 } else if (dst.IsRegisterPair()) {
4738 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4739 LoadFromOffset(kLoadDoubleword, dst.AsRegisterPairLow(), src_register, src_offset);
4740 } else if (dst.IsFRegister()) {
4741 if (size == kMipsWordSize) {
4742 LoadSFromOffset(dst.AsFRegister(), src_register, src_offset);
4743 } else {
4744 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4745 LoadDFromOffset(dst.AsFRegister(), src_register, src_offset);
4746 }
Alexey Frunze1b8464d2016-11-12 17:22:05 -08004747 } else if (dst.IsDRegister()) {
4748 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4749 LoadDFromOffset(dst.AsOverlappingDRegisterLow(), src_register, src_offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004750 }
jeffhao7fbee072012-08-24 17:56:54 -07004751}
4752
Alexey Frunze2923db72016-08-20 01:55:47 -07004753void MipsAssembler::StoreToOffset(StoreOperandType type,
4754 Register reg,
4755 Register base,
jeffhao7fbee072012-08-24 17:56:54 -07004756 int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004757 StoreToOffset<>(type, reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004758}
4759
Goran Jakovljevicff734982015-08-24 12:58:55 +00004760void MipsAssembler::StoreSToOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004761 StoreSToOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004762}
4763
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004764void MipsAssembler::StoreDToOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004765 StoreDToOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004766}
4767
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004768void MipsAssembler::StoreQToOffset(FRegister reg, Register base, int32_t offset) {
4769 StoreQToOffset<>(reg, base, offset);
4770}
4771
David Srbeckydd973932015-04-07 20:29:48 +01004772static dwarf::Reg DWARFReg(Register reg) {
4773 return dwarf::Reg::MipsCore(static_cast<int>(reg));
4774}
4775
Ian Rogers790a6b72014-04-01 10:36:00 -07004776constexpr size_t kFramePointerSize = 4;
4777
Vladimir Marko32248382016-05-19 10:37:24 +01004778void MipsAssembler::BuildFrame(size_t frame_size,
4779 ManagedRegister method_reg,
4780 ArrayRef<const ManagedRegister> callee_save_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +07004781 const ManagedRegisterEntrySpills& entry_spills) {
jeffhao7fbee072012-08-24 17:56:54 -07004782 CHECK_ALIGNED(frame_size, kStackAlignment);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004783 DCHECK(!overwriting_);
jeffhao7fbee072012-08-24 17:56:54 -07004784
4785 // Increase frame to required size.
4786 IncreaseFrameSize(frame_size);
4787
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004788 // Push callee saves and return address.
Ian Rogers790a6b72014-04-01 10:36:00 -07004789 int stack_offset = frame_size - kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004790 StoreToOffset(kStoreWord, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004791 cfi_.RelOffset(DWARFReg(RA), stack_offset);
jeffhao7fbee072012-08-24 17:56:54 -07004792 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
Ian Rogers790a6b72014-04-01 10:36:00 -07004793 stack_offset -= kFramePointerSize;
Vladimir Marko32248382016-05-19 10:37:24 +01004794 Register reg = callee_save_regs[i].AsMips().AsCoreRegister();
jeffhao7fbee072012-08-24 17:56:54 -07004795 StoreToOffset(kStoreWord, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004796 cfi_.RelOffset(DWARFReg(reg), stack_offset);
jeffhao7fbee072012-08-24 17:56:54 -07004797 }
4798
4799 // Write out Method*.
4800 StoreToOffset(kStoreWord, method_reg.AsMips().AsCoreRegister(), SP, 0);
4801
4802 // Write out entry spills.
Goran Jakovljevicff734982015-08-24 12:58:55 +00004803 int32_t offset = frame_size + kFramePointerSize;
Vladimir Marko35d5b8a2018-07-03 09:18:32 +01004804 for (const ManagedRegisterSpill& spill : entry_spills) {
4805 MipsManagedRegister reg = spill.AsMips();
Goran Jakovljevicff734982015-08-24 12:58:55 +00004806 if (reg.IsNoRegister()) {
Goran Jakovljevicff734982015-08-24 12:58:55 +00004807 offset += spill.getSize();
4808 } else if (reg.IsCoreRegister()) {
4809 StoreToOffset(kStoreWord, reg.AsCoreRegister(), SP, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004810 offset += kMipsWordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004811 } else if (reg.IsFRegister()) {
4812 StoreSToOffset(reg.AsFRegister(), SP, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004813 offset += kMipsWordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004814 } else if (reg.IsDRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004815 StoreDToOffset(reg.AsOverlappingDRegisterLow(), SP, offset);
4816 offset += kMipsDoublewordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004817 }
jeffhao7fbee072012-08-24 17:56:54 -07004818 }
4819}
4820
4821void MipsAssembler::RemoveFrame(size_t frame_size,
Roland Levillain0d127e12017-07-05 17:01:11 +01004822 ArrayRef<const ManagedRegister> callee_save_regs,
4823 bool may_suspend ATTRIBUTE_UNUSED) {
jeffhao7fbee072012-08-24 17:56:54 -07004824 CHECK_ALIGNED(frame_size, kStackAlignment);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004825 DCHECK(!overwriting_);
David Srbeckydd973932015-04-07 20:29:48 +01004826 cfi_.RememberState();
jeffhao7fbee072012-08-24 17:56:54 -07004827
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004828 // Pop callee saves and return address.
Ian Rogers790a6b72014-04-01 10:36:00 -07004829 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004830 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01004831 Register reg = callee_save_regs[i].AsMips().AsCoreRegister();
jeffhao7fbee072012-08-24 17:56:54 -07004832 LoadFromOffset(kLoadWord, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004833 cfi_.Restore(DWARFReg(reg));
Ian Rogers790a6b72014-04-01 10:36:00 -07004834 stack_offset += kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004835 }
4836 LoadFromOffset(kLoadWord, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004837 cfi_.Restore(DWARFReg(RA));
jeffhao7fbee072012-08-24 17:56:54 -07004838
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004839 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
4840 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
4841 bool reordering = SetReorder(false);
4842 if (exchange) {
4843 // Jump to the return address.
4844 Jr(RA);
4845 // Decrease frame to required size.
4846 DecreaseFrameSize(frame_size); // Single instruction in delay slot.
4847 } else {
4848 // Decrease frame to required size.
4849 DecreaseFrameSize(frame_size);
4850 // Jump to the return address.
4851 Jr(RA);
4852 Nop(); // In delay slot.
4853 }
4854 SetReorder(reordering);
David Srbeckydd973932015-04-07 20:29:48 +01004855
4856 // The CFI should be restored for any code that follows the exit block.
4857 cfi_.RestoreState();
4858 cfi_.DefCFAOffset(frame_size);
jeffhao7fbee072012-08-24 17:56:54 -07004859}
4860
4861void MipsAssembler::IncreaseFrameSize(size_t adjust) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004862 CHECK_ALIGNED(adjust, kFramePointerSize);
4863 Addiu32(SP, SP, -adjust);
David Srbeckydd973932015-04-07 20:29:48 +01004864 cfi_.AdjustCFAOffset(adjust);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004865 if (overwriting_) {
4866 cfi_.OverrideDelayedPC(overwrite_location_);
4867 }
jeffhao7fbee072012-08-24 17:56:54 -07004868}
4869
4870void MipsAssembler::DecreaseFrameSize(size_t adjust) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004871 CHECK_ALIGNED(adjust, kFramePointerSize);
4872 Addiu32(SP, SP, adjust);
David Srbeckydd973932015-04-07 20:29:48 +01004873 cfi_.AdjustCFAOffset(-adjust);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004874 if (overwriting_) {
4875 cfi_.OverrideDelayedPC(overwrite_location_);
4876 }
jeffhao7fbee072012-08-24 17:56:54 -07004877}
4878
4879void MipsAssembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
4880 MipsManagedRegister src = msrc.AsMips();
4881 if (src.IsNoRegister()) {
4882 CHECK_EQ(0u, size);
4883 } else if (src.IsCoreRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004884 CHECK_EQ(kMipsWordSize, size);
jeffhao7fbee072012-08-24 17:56:54 -07004885 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4886 } else if (src.IsRegisterPair()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004887 CHECK_EQ(kMipsDoublewordSize, size);
jeffhao7fbee072012-08-24 17:56:54 -07004888 StoreToOffset(kStoreWord, src.AsRegisterPairLow(), SP, dest.Int32Value());
4889 StoreToOffset(kStoreWord, src.AsRegisterPairHigh(),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004890 SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07004891 } else if (src.IsFRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004892 if (size == kMipsWordSize) {
4893 StoreSToOffset(src.AsFRegister(), SP, dest.Int32Value());
4894 } else {
4895 CHECK_EQ(kMipsDoublewordSize, size);
4896 StoreDToOffset(src.AsFRegister(), SP, dest.Int32Value());
4897 }
Alexey Frunze1b8464d2016-11-12 17:22:05 -08004898 } else if (src.IsDRegister()) {
4899 CHECK_EQ(kMipsDoublewordSize, size);
4900 StoreDToOffset(src.AsOverlappingDRegisterLow(), SP, dest.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07004901 }
4902}
4903
4904void MipsAssembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
4905 MipsManagedRegister src = msrc.AsMips();
4906 CHECK(src.IsCoreRegister());
4907 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4908}
4909
4910void MipsAssembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
4911 MipsManagedRegister src = msrc.AsMips();
4912 CHECK(src.IsCoreRegister());
4913 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4914}
4915
4916void MipsAssembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
4917 ManagedRegister mscratch) {
4918 MipsManagedRegister scratch = mscratch.AsMips();
4919 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004920 LoadConst32(scratch.AsCoreRegister(), imm);
jeffhao7fbee072012-08-24 17:56:54 -07004921 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
4922}
4923
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004924void MipsAssembler::StoreStackOffsetToThread(ThreadOffset32 thr_offs,
4925 FrameOffset fr_offs,
jeffhao7fbee072012-08-24 17:56:54 -07004926 ManagedRegister mscratch) {
4927 MipsManagedRegister scratch = mscratch.AsMips();
4928 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004929 Addiu32(scratch.AsCoreRegister(), SP, fr_offs.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07004930 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
4931 S1, thr_offs.Int32Value());
4932}
4933
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004934void MipsAssembler::StoreStackPointerToThread(ThreadOffset32 thr_offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004935 StoreToOffset(kStoreWord, SP, S1, thr_offs.Int32Value());
4936}
4937
4938void MipsAssembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
4939 FrameOffset in_off, ManagedRegister mscratch) {
4940 MipsManagedRegister src = msrc.AsMips();
4941 MipsManagedRegister scratch = mscratch.AsMips();
4942 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4943 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, in_off.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004944 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07004945}
4946
4947void MipsAssembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
4948 return EmitLoad(mdest, SP, src.Int32Value(), size);
4949}
4950
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004951void MipsAssembler::LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07004952 return EmitLoad(mdest, S1, src.Int32Value(), size);
4953}
4954
4955void MipsAssembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
4956 MipsManagedRegister dest = mdest.AsMips();
4957 CHECK(dest.IsCoreRegister());
4958 LoadFromOffset(kLoadWord, dest.AsCoreRegister(), SP, src.Int32Value());
4959}
4960
Mathieu Chartiere401d142015-04-22 13:56:20 -07004961void MipsAssembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01004962 bool unpoison_reference) {
jeffhao7fbee072012-08-24 17:56:54 -07004963 MipsManagedRegister dest = mdest.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004964 CHECK(dest.IsCoreRegister() && base.AsMips().IsCoreRegister());
jeffhao7fbee072012-08-24 17:56:54 -07004965 LoadFromOffset(kLoadWord, dest.AsCoreRegister(),
4966 base.AsMips().AsCoreRegister(), offs.Int32Value());
Alexey Frunzec061de12017-02-14 13:27:23 -08004967 if (unpoison_reference) {
4968 MaybeUnpoisonHeapReference(dest.AsCoreRegister());
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -08004969 }
jeffhao7fbee072012-08-24 17:56:54 -07004970}
4971
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004972void MipsAssembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004973 MipsManagedRegister dest = mdest.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004974 CHECK(dest.IsCoreRegister() && base.AsMips().IsCoreRegister());
jeffhao7fbee072012-08-24 17:56:54 -07004975 LoadFromOffset(kLoadWord, dest.AsCoreRegister(),
4976 base.AsMips().AsCoreRegister(), offs.Int32Value());
4977}
4978
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004979void MipsAssembler::LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004980 MipsManagedRegister dest = mdest.AsMips();
4981 CHECK(dest.IsCoreRegister());
4982 LoadFromOffset(kLoadWord, dest.AsCoreRegister(), S1, offs.Int32Value());
4983}
4984
4985void MipsAssembler::SignExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
4986 UNIMPLEMENTED(FATAL) << "no sign extension necessary for mips";
4987}
4988
4989void MipsAssembler::ZeroExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
4990 UNIMPLEMENTED(FATAL) << "no zero extension necessary for mips";
4991}
4992
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004993void MipsAssembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07004994 MipsManagedRegister dest = mdest.AsMips();
4995 MipsManagedRegister src = msrc.AsMips();
4996 if (!dest.Equals(src)) {
4997 if (dest.IsCoreRegister()) {
4998 CHECK(src.IsCoreRegister()) << src;
4999 Move(dest.AsCoreRegister(), src.AsCoreRegister());
5000 } else if (dest.IsFRegister()) {
5001 CHECK(src.IsFRegister()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005002 if (size == kMipsWordSize) {
5003 MovS(dest.AsFRegister(), src.AsFRegister());
5004 } else {
5005 CHECK_EQ(kMipsDoublewordSize, size);
5006 MovD(dest.AsFRegister(), src.AsFRegister());
5007 }
jeffhao7fbee072012-08-24 17:56:54 -07005008 } else if (dest.IsDRegister()) {
5009 CHECK(src.IsDRegister()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005010 MovD(dest.AsOverlappingDRegisterLow(), src.AsOverlappingDRegisterLow());
jeffhao7fbee072012-08-24 17:56:54 -07005011 } else {
5012 CHECK(dest.IsRegisterPair()) << dest;
5013 CHECK(src.IsRegisterPair()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005014 // Ensure that the first move doesn't clobber the input of the second.
jeffhao7fbee072012-08-24 17:56:54 -07005015 if (src.AsRegisterPairHigh() != dest.AsRegisterPairLow()) {
5016 Move(dest.AsRegisterPairLow(), src.AsRegisterPairLow());
5017 Move(dest.AsRegisterPairHigh(), src.AsRegisterPairHigh());
5018 } else {
5019 Move(dest.AsRegisterPairHigh(), src.AsRegisterPairHigh());
5020 Move(dest.AsRegisterPairLow(), src.AsRegisterPairLow());
5021 }
5022 }
5023 }
5024}
5025
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005026void MipsAssembler::CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07005027 MipsManagedRegister scratch = mscratch.AsMips();
5028 CHECK(scratch.IsCoreRegister()) << scratch;
5029 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
5030 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
5031}
5032
Andreas Gampe3b165bc2016-08-01 22:07:04 -07005033void MipsAssembler::CopyRawPtrFromThread(FrameOffset fr_offs,
5034 ThreadOffset32 thr_offs,
5035 ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07005036 MipsManagedRegister scratch = mscratch.AsMips();
5037 CHECK(scratch.IsCoreRegister()) << scratch;
5038 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5039 S1, thr_offs.Int32Value());
5040 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
5041 SP, fr_offs.Int32Value());
5042}
5043
Andreas Gampe3b165bc2016-08-01 22:07:04 -07005044void MipsAssembler::CopyRawPtrToThread(ThreadOffset32 thr_offs,
5045 FrameOffset fr_offs,
5046 ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07005047 MipsManagedRegister scratch = mscratch.AsMips();
5048 CHECK(scratch.IsCoreRegister()) << scratch;
5049 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5050 SP, fr_offs.Int32Value());
5051 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
5052 S1, thr_offs.Int32Value());
5053}
5054
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005055void MipsAssembler::Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07005056 MipsManagedRegister scratch = mscratch.AsMips();
5057 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005058 CHECK(size == kMipsWordSize || size == kMipsDoublewordSize) << size;
5059 if (size == kMipsWordSize) {
jeffhao7fbee072012-08-24 17:56:54 -07005060 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
5061 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005062 } else if (size == kMipsDoublewordSize) {
jeffhao7fbee072012-08-24 17:56:54 -07005063 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
5064 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005065 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value() + kMipsWordSize);
5066 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005067 }
5068}
5069
5070void MipsAssembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
5071 ManagedRegister mscratch, size_t size) {
5072 Register scratch = mscratch.AsMips().AsCoreRegister();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005073 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005074 LoadFromOffset(kLoadWord, scratch, src_base.AsMips().AsCoreRegister(), src_offset.Int32Value());
5075 StoreToOffset(kStoreWord, scratch, SP, dest.Int32Value());
5076}
5077
5078void MipsAssembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
5079 ManagedRegister mscratch, size_t size) {
5080 Register scratch = mscratch.AsMips().AsCoreRegister();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005081 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005082 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
5083 StoreToOffset(kStoreWord, scratch, dest_base.AsMips().AsCoreRegister(), dest_offset.Int32Value());
5084}
5085
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005086void MipsAssembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
5087 FrameOffset src_base ATTRIBUTE_UNUSED,
5088 Offset src_offset ATTRIBUTE_UNUSED,
5089 ManagedRegister mscratch ATTRIBUTE_UNUSED,
5090 size_t size ATTRIBUTE_UNUSED) {
5091 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005092}
5093
5094void MipsAssembler::Copy(ManagedRegister dest, Offset dest_offset,
5095 ManagedRegister src, Offset src_offset,
5096 ManagedRegister mscratch, size_t size) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005097 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005098 Register scratch = mscratch.AsMips().AsCoreRegister();
5099 LoadFromOffset(kLoadWord, scratch, src.AsMips().AsCoreRegister(), src_offset.Int32Value());
5100 StoreToOffset(kStoreWord, scratch, dest.AsMips().AsCoreRegister(), dest_offset.Int32Value());
5101}
5102
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005103void MipsAssembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
5104 Offset dest_offset ATTRIBUTE_UNUSED,
5105 FrameOffset src ATTRIBUTE_UNUSED,
5106 Offset src_offset ATTRIBUTE_UNUSED,
5107 ManagedRegister mscratch ATTRIBUTE_UNUSED,
5108 size_t size ATTRIBUTE_UNUSED) {
5109 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005110}
5111
5112void MipsAssembler::MemoryBarrier(ManagedRegister) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005113 // TODO: sync?
5114 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005115}
5116
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005117void MipsAssembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005118 FrameOffset handle_scope_offset,
5119 ManagedRegister min_reg,
5120 bool null_allowed) {
jeffhao7fbee072012-08-24 17:56:54 -07005121 MipsManagedRegister out_reg = mout_reg.AsMips();
5122 MipsManagedRegister in_reg = min_reg.AsMips();
5123 CHECK(in_reg.IsNoRegister() || in_reg.IsCoreRegister()) << in_reg;
5124 CHECK(out_reg.IsCoreRegister()) << out_reg;
5125 if (null_allowed) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005126 MipsLabel null_arg;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005127 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
5128 // the address in the handle scope holding the reference.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005129 // E.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset).
jeffhao7fbee072012-08-24 17:56:54 -07005130 if (in_reg.IsNoRegister()) {
5131 LoadFromOffset(kLoadWord, out_reg.AsCoreRegister(),
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005132 SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005133 in_reg = out_reg;
5134 }
5135 if (!out_reg.Equals(in_reg)) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005136 LoadConst32(out_reg.AsCoreRegister(), 0);
jeffhao7fbee072012-08-24 17:56:54 -07005137 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005138 Beqz(in_reg.AsCoreRegister(), &null_arg);
5139 Addiu32(out_reg.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
5140 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005141 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005142 Addiu32(out_reg.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005143 }
5144}
5145
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005146void MipsAssembler::CreateHandleScopeEntry(FrameOffset out_off,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005147 FrameOffset handle_scope_offset,
5148 ManagedRegister mscratch,
5149 bool null_allowed) {
jeffhao7fbee072012-08-24 17:56:54 -07005150 MipsManagedRegister scratch = mscratch.AsMips();
5151 CHECK(scratch.IsCoreRegister()) << scratch;
5152 if (null_allowed) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005153 MipsLabel null_arg;
5154 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005155 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
5156 // the address in the handle scope holding the reference.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005157 // E.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset).
5158 Beqz(scratch.AsCoreRegister(), &null_arg);
5159 Addiu32(scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
5160 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005161 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005162 Addiu32(scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005163 }
5164 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, out_off.Int32Value());
5165}
5166
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005167// Given a handle scope entry, load the associated reference.
5168void MipsAssembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005169 ManagedRegister min_reg) {
jeffhao7fbee072012-08-24 17:56:54 -07005170 MipsManagedRegister out_reg = mout_reg.AsMips();
5171 MipsManagedRegister in_reg = min_reg.AsMips();
5172 CHECK(out_reg.IsCoreRegister()) << out_reg;
5173 CHECK(in_reg.IsCoreRegister()) << in_reg;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005174 MipsLabel null_arg;
jeffhao7fbee072012-08-24 17:56:54 -07005175 if (!out_reg.Equals(in_reg)) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005176 LoadConst32(out_reg.AsCoreRegister(), 0);
jeffhao7fbee072012-08-24 17:56:54 -07005177 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005178 Beqz(in_reg.AsCoreRegister(), &null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005179 LoadFromOffset(kLoadWord, out_reg.AsCoreRegister(),
5180 in_reg.AsCoreRegister(), 0);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005181 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005182}
5183
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005184void MipsAssembler::VerifyObject(ManagedRegister src ATTRIBUTE_UNUSED,
5185 bool could_be_null ATTRIBUTE_UNUSED) {
5186 // TODO: not validating references.
jeffhao7fbee072012-08-24 17:56:54 -07005187}
5188
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005189void MipsAssembler::VerifyObject(FrameOffset src ATTRIBUTE_UNUSED,
5190 bool could_be_null ATTRIBUTE_UNUSED) {
5191 // TODO: not validating references.
jeffhao7fbee072012-08-24 17:56:54 -07005192}
5193
5194void MipsAssembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
5195 MipsManagedRegister base = mbase.AsMips();
5196 MipsManagedRegister scratch = mscratch.AsMips();
5197 CHECK(base.IsCoreRegister()) << base;
5198 CHECK(scratch.IsCoreRegister()) << scratch;
5199 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5200 base.AsCoreRegister(), offset.Int32Value());
5201 Jalr(scratch.AsCoreRegister());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005202 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005203 // TODO: place reference map on call.
jeffhao7fbee072012-08-24 17:56:54 -07005204}
5205
5206void MipsAssembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
5207 MipsManagedRegister scratch = mscratch.AsMips();
5208 CHECK(scratch.IsCoreRegister()) << scratch;
5209 // Call *(*(SP + base) + offset)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005210 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, base.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005211 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5212 scratch.AsCoreRegister(), offset.Int32Value());
5213 Jalr(scratch.AsCoreRegister());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005214 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005215 // TODO: place reference map on call.
jeffhao7fbee072012-08-24 17:56:54 -07005216}
5217
Andreas Gampe3b165bc2016-08-01 22:07:04 -07005218void MipsAssembler::CallFromThread(ThreadOffset32 offset ATTRIBUTE_UNUSED,
5219 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Ian Rogers468532e2013-08-05 10:56:33 -07005220 UNIMPLEMENTED(FATAL) << "no mips implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005221}
5222
5223void MipsAssembler::GetCurrentThread(ManagedRegister tr) {
5224 Move(tr.AsMips().AsCoreRegister(), S1);
5225}
5226
5227void MipsAssembler::GetCurrentThread(FrameOffset offset,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005228 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
jeffhao7fbee072012-08-24 17:56:54 -07005229 StoreToOffset(kStoreWord, S1, SP, offset.Int32Value());
5230}
5231
jeffhao7fbee072012-08-24 17:56:54 -07005232void MipsAssembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
5233 MipsManagedRegister scratch = mscratch.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005234 exception_blocks_.emplace_back(scratch, stack_adjust);
jeffhao7fbee072012-08-24 17:56:54 -07005235 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
Andreas Gampe542451c2016-07-26 09:02:02 -07005236 S1, Thread::ExceptionOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005237 Bnez(scratch.AsCoreRegister(), exception_blocks_.back().Entry());
jeffhao7fbee072012-08-24 17:56:54 -07005238}
5239
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005240void MipsAssembler::EmitExceptionPoll(MipsExceptionSlowPath* exception) {
5241 Bind(exception->Entry());
5242 if (exception->stack_adjust_ != 0) { // Fix up the frame.
5243 DecreaseFrameSize(exception->stack_adjust_);
jeffhao7fbee072012-08-24 17:56:54 -07005244 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005245 // Pass exception object as argument.
5246 // Don't care about preserving A0 as this call won't return.
5247 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5248 Move(A0, exception->scratch_.AsCoreRegister());
5249 // Set up call to Thread::Current()->pDeliverException.
5250 LoadFromOffset(kLoadWord, T9, S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07005251 QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, pDeliverException).Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005252 Jr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005253 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005254
5255 // Call never returns.
5256 Break();
jeffhao7fbee072012-08-24 17:56:54 -07005257}
5258
5259} // namespace mips
5260} // namespace art