blob: 2cbabcfb32f6b59ebf3046adedcb0201d153ff8e [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"
Ian Rogers166db042013-07-26 12:05:57 -070021#include "entrypoints/quick/quick_entrypoints.h"
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +020022#include "entrypoints/quick/quick_entrypoints_enum.h"
jeffhao7fbee072012-08-24 17:56:54 -070023#include "memory_region.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),
45 gpr_outs_mask_(0),
46 gpr_ins_mask_(0),
47 fpr_outs_mask_(0),
48 fpr_ins_mask_(0),
49 cc_outs_mask_(0),
50 cc_ins_mask_(0) {}
51
52void MipsAssembler::DsFsmInstr(uint32_t instruction,
53 uint32_t gpr_outs_mask,
54 uint32_t gpr_ins_mask,
55 uint32_t fpr_outs_mask,
56 uint32_t fpr_ins_mask,
57 uint32_t cc_outs_mask,
58 uint32_t cc_ins_mask) {
59 if (!reordering_) {
60 CHECK_EQ(ds_fsm_state_, kExpectingLabel);
61 CHECK_EQ(delay_slot_.instruction_, 0u);
62 return;
63 }
64 switch (ds_fsm_state_) {
65 case kExpectingLabel:
66 break;
67 case kExpectingInstruction:
68 CHECK_EQ(ds_fsm_target_pc_ + sizeof(uint32_t), buffer_.Size());
69 // If the last instruction is not suitable for delay slots, drop
70 // the PC of the label preceding it so that no unconditional branch
71 // uses this instruction to fill its delay slot.
72 if (instruction == 0) {
73 DsFsmDropLabel(); // Sets ds_fsm_state_ = kExpectingLabel.
74 } else {
75 // Otherwise wait for another instruction or label before we can
76 // commit the label PC. The label PC will be dropped if instead
77 // of another instruction or label there's a call from the code
78 // generator to CodePosition() to record the buffer size.
79 // Instructions after which the buffer size is recorded cannot
80 // be moved into delay slots or anywhere else because they may
81 // trigger signals and the signal handlers expect these signals
82 // to be coming from the instructions immediately preceding the
83 // recorded buffer locations.
84 ds_fsm_state_ = kExpectingCommit;
85 }
86 break;
87 case kExpectingCommit:
88 CHECK_EQ(ds_fsm_target_pc_ + 2 * sizeof(uint32_t), buffer_.Size());
89 DsFsmCommitLabel(); // Sets ds_fsm_state_ = kExpectingLabel.
90 break;
91 }
92 delay_slot_.instruction_ = instruction;
93 delay_slot_.gpr_outs_mask_ = gpr_outs_mask & ~1u; // Ignore register ZERO.
94 delay_slot_.gpr_ins_mask_ = gpr_ins_mask & ~1u; // Ignore register ZERO.
95 delay_slot_.fpr_outs_mask_ = fpr_outs_mask;
96 delay_slot_.fpr_ins_mask_ = fpr_ins_mask;
97 delay_slot_.cc_outs_mask_ = cc_outs_mask;
98 delay_slot_.cc_ins_mask_ = cc_ins_mask;
99}
100
101void MipsAssembler::DsFsmLabel() {
102 if (!reordering_) {
103 CHECK_EQ(ds_fsm_state_, kExpectingLabel);
104 CHECK_EQ(delay_slot_.instruction_, 0u);
105 return;
106 }
107 switch (ds_fsm_state_) {
108 case kExpectingLabel:
109 ds_fsm_target_pc_ = buffer_.Size();
110 ds_fsm_state_ = kExpectingInstruction;
111 break;
112 case kExpectingInstruction:
113 // Allow consecutive labels.
114 CHECK_EQ(ds_fsm_target_pc_, buffer_.Size());
115 break;
116 case kExpectingCommit:
117 CHECK_EQ(ds_fsm_target_pc_ + sizeof(uint32_t), buffer_.Size());
118 DsFsmCommitLabel();
119 ds_fsm_target_pc_ = buffer_.Size();
120 ds_fsm_state_ = kExpectingInstruction;
121 break;
122 }
123 // We cannot move instructions into delay slots across labels.
124 delay_slot_.instruction_ = 0;
125}
126
127void MipsAssembler::DsFsmCommitLabel() {
128 if (ds_fsm_state_ == kExpectingCommit) {
129 ds_fsm_target_pcs_.emplace_back(ds_fsm_target_pc_);
130 }
131 ds_fsm_state_ = kExpectingLabel;
132}
133
134void MipsAssembler::DsFsmDropLabel() {
135 ds_fsm_state_ = kExpectingLabel;
136}
137
138bool MipsAssembler::SetReorder(bool enable) {
139 bool last_state = reordering_;
140 if (last_state != enable) {
141 DsFsmCommitLabel();
142 DsFsmInstrNop(0);
143 }
144 reordering_ = enable;
145 return last_state;
146}
147
148size_t MipsAssembler::CodePosition() {
149 // The last instruction cannot be used in a delay slot, do not commit
150 // the label before it (if any) and clear the delay slot.
151 DsFsmDropLabel();
152 DsFsmInstrNop(0);
153 size_t size = buffer_.Size();
154 // In theory we can get the following sequence:
155 // label1:
156 // instr
157 // label2: # label1 gets committed when label2 is seen
158 // CodePosition() call
159 // and we need to uncommit label1.
160 if (ds_fsm_target_pcs_.size() != 0 && ds_fsm_target_pcs_.back() + sizeof(uint32_t) == size) {
161 ds_fsm_target_pcs_.pop_back();
162 }
163 return size;
164}
165
166void MipsAssembler::DsFsmInstrNop(uint32_t instruction ATTRIBUTE_UNUSED) {
167 DsFsmInstr(0, 0, 0, 0, 0, 0, 0);
168}
169
170void MipsAssembler::DsFsmInstrRrr(uint32_t instruction, Register out, Register in1, Register in2) {
171 DsFsmInstr(instruction, (1u << out), (1u << in1) | (1u << in2), 0, 0, 0, 0);
172}
173
174void MipsAssembler::DsFsmInstrRrrr(uint32_t instruction,
175 Register in1_out,
176 Register in2,
177 Register in3) {
178 DsFsmInstr(instruction, (1u << in1_out), (1u << in1_out) | (1u << in2) | (1u << in3), 0, 0, 0, 0);
179}
180
181void MipsAssembler::DsFsmInstrFff(uint32_t instruction,
182 FRegister out,
183 FRegister in1,
184 FRegister in2) {
185 DsFsmInstr(instruction, 0, 0, (1u << out), (1u << in1) | (1u << in2), 0, 0);
186}
187
188void MipsAssembler::DsFsmInstrFfff(uint32_t instruction,
189 FRegister in1_out,
190 FRegister in2,
191 FRegister in3) {
192 DsFsmInstr(instruction, 0, 0, (1u << in1_out), (1u << in1_out) | (1u << in2) | (1u << in3), 0, 0);
193}
194
Alexey Frunze674b9ee2016-09-20 14:54:15 -0700195void MipsAssembler::DsFsmInstrFffr(uint32_t instruction,
196 FRegister in1_out,
197 FRegister in2,
198 Register in3) {
199 DsFsmInstr(instruction, 0, (1u << in3), (1u << in1_out), (1u << in1_out) | (1u << in2), 0, 0);
200}
201
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700202void MipsAssembler::DsFsmInstrRf(uint32_t instruction, Register out, FRegister in) {
203 DsFsmInstr(instruction, (1u << out), 0, 0, (1u << in), 0, 0);
204}
205
206void MipsAssembler::DsFsmInstrFr(uint32_t instruction, FRegister out, Register in) {
207 DsFsmInstr(instruction, 0, (1u << in), (1u << out), 0, 0, 0);
208}
209
210void MipsAssembler::DsFsmInstrFR(uint32_t instruction, FRegister in1, Register in2) {
211 DsFsmInstr(instruction, 0, (1u << in2), 0, (1u << in1), 0, 0);
212}
213
214void MipsAssembler::DsFsmInstrCff(uint32_t instruction, int cc_out, FRegister in1, FRegister in2) {
215 DsFsmInstr(instruction, 0, 0, 0, (1u << in1) | (1u << in2), (1 << cc_out), 0);
216}
217
218void MipsAssembler::DsFsmInstrRrrc(uint32_t instruction,
219 Register in1_out,
220 Register in2,
221 int cc_in) {
222 DsFsmInstr(instruction, (1u << in1_out), (1u << in1_out) | (1u << in2), 0, 0, 0, (1 << cc_in));
223}
224
225void MipsAssembler::DsFsmInstrFffc(uint32_t instruction,
226 FRegister in1_out,
227 FRegister in2,
228 int cc_in) {
229 DsFsmInstr(instruction, 0, 0, (1u << in1_out), (1u << in1_out) | (1u << in2), 0, (1 << cc_in));
230}
231
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200232void MipsAssembler::FinalizeCode() {
233 for (auto& exception_block : exception_blocks_) {
234 EmitExceptionPoll(&exception_block);
235 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700236 // Commit the last branch target label (if any) and disable instruction reordering.
237 DsFsmCommitLabel();
238 SetReorder(false);
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700239 EmitLiterals();
Alexey Frunze96b66822016-09-10 02:32:44 -0700240 ReserveJumpTableSpace();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200241 PromoteBranches();
242}
243
244void MipsAssembler::FinalizeInstructions(const MemoryRegion& region) {
Vladimir Marko10ef6942015-10-22 15:25:54 +0100245 size_t number_of_delayed_adjust_pcs = cfi().NumberOfDelayedAdvancePCs();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200246 EmitBranches();
Alexey Frunze96b66822016-09-10 02:32:44 -0700247 EmitJumpTables();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200248 Assembler::FinalizeInstructions(region);
Vladimir Marko10ef6942015-10-22 15:25:54 +0100249 PatchCFI(number_of_delayed_adjust_pcs);
250}
251
252void MipsAssembler::PatchCFI(size_t number_of_delayed_adjust_pcs) {
253 if (cfi().NumberOfDelayedAdvancePCs() == 0u) {
254 DCHECK_EQ(number_of_delayed_adjust_pcs, 0u);
255 return;
256 }
257
258 typedef DebugFrameOpCodeWriterForAssembler::DelayedAdvancePC DelayedAdvancePC;
259 const auto data = cfi().ReleaseStreamAndPrepareForDelayedAdvancePC();
260 const std::vector<uint8_t>& old_stream = data.first;
261 const std::vector<DelayedAdvancePC>& advances = data.second;
262
263 // PCs recorded before EmitBranches() need to be adjusted.
264 // PCs recorded during EmitBranches() are already adjusted.
265 // Both ranges are separately sorted but they may overlap.
266 if (kIsDebugBuild) {
267 auto cmp = [](const DelayedAdvancePC& lhs, const DelayedAdvancePC& rhs) {
268 return lhs.pc < rhs.pc;
269 };
270 CHECK(std::is_sorted(advances.begin(), advances.begin() + number_of_delayed_adjust_pcs, cmp));
271 CHECK(std::is_sorted(advances.begin() + number_of_delayed_adjust_pcs, advances.end(), cmp));
272 }
273
274 // Append initial CFI data if any.
275 size_t size = advances.size();
276 DCHECK_NE(size, 0u);
277 cfi().AppendRawData(old_stream, 0u, advances[0].stream_pos);
278 // Emit PC adjustments interleaved with the old CFI stream.
279 size_t adjust_pos = 0u;
280 size_t late_emit_pos = number_of_delayed_adjust_pcs;
281 while (adjust_pos != number_of_delayed_adjust_pcs || late_emit_pos != size) {
282 size_t adjusted_pc = (adjust_pos != number_of_delayed_adjust_pcs)
283 ? GetAdjustedPosition(advances[adjust_pos].pc)
284 : static_cast<size_t>(-1);
285 size_t late_emit_pc = (late_emit_pos != size)
286 ? advances[late_emit_pos].pc
287 : static_cast<size_t>(-1);
288 size_t advance_pc = std::min(adjusted_pc, late_emit_pc);
289 DCHECK_NE(advance_pc, static_cast<size_t>(-1));
290 size_t entry = (adjusted_pc <= late_emit_pc) ? adjust_pos : late_emit_pos;
291 if (adjusted_pc <= late_emit_pc) {
292 ++adjust_pos;
293 } else {
294 ++late_emit_pos;
295 }
296 cfi().AdvancePC(advance_pc);
297 size_t end_pos = (entry + 1u == size) ? old_stream.size() : advances[entry + 1u].stream_pos;
298 cfi().AppendRawData(old_stream, advances[entry].stream_pos, end_pos);
299 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200300}
301
302void MipsAssembler::EmitBranches() {
303 CHECK(!overwriting_);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700304 CHECK(!reordering_);
305 // Now that everything has its final position in the buffer (the branches have
306 // been promoted), adjust the target label PCs.
307 for (size_t cnt = ds_fsm_target_pcs_.size(), i = 0; i < cnt; i++) {
308 ds_fsm_target_pcs_[i] = GetAdjustedPosition(ds_fsm_target_pcs_[i]);
309 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200310 // Switch from appending instructions at the end of the buffer to overwriting
311 // existing instructions (branch placeholders) in the buffer.
312 overwriting_ = true;
313 for (auto& branch : branches_) {
314 EmitBranch(&branch);
315 }
316 overwriting_ = false;
317}
318
319void MipsAssembler::Emit(uint32_t value) {
320 if (overwriting_) {
321 // Branches to labels are emitted into their placeholders here.
322 buffer_.Store<uint32_t>(overwrite_location_, value);
323 overwrite_location_ += sizeof(uint32_t);
324 } else {
325 // Other instructions are simply appended at the end here.
326 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
327 buffer_.Emit<uint32_t>(value);
328 }
jeffhao7fbee072012-08-24 17:56:54 -0700329}
330
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700331uint32_t MipsAssembler::EmitR(int opcode,
332 Register rs,
333 Register rt,
334 Register rd,
335 int shamt,
336 int funct) {
jeffhao7fbee072012-08-24 17:56:54 -0700337 CHECK_NE(rs, kNoRegister);
338 CHECK_NE(rt, kNoRegister);
339 CHECK_NE(rd, kNoRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200340 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
341 static_cast<uint32_t>(rs) << kRsShift |
342 static_cast<uint32_t>(rt) << kRtShift |
343 static_cast<uint32_t>(rd) << kRdShift |
344 shamt << kShamtShift |
345 funct;
jeffhao7fbee072012-08-24 17:56:54 -0700346 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700347 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700348}
349
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700350uint32_t MipsAssembler::EmitI(int opcode, Register rs, Register rt, uint16_t imm) {
jeffhao7fbee072012-08-24 17:56:54 -0700351 CHECK_NE(rs, kNoRegister);
352 CHECK_NE(rt, kNoRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200353 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
354 static_cast<uint32_t>(rs) << kRsShift |
355 static_cast<uint32_t>(rt) << kRtShift |
356 imm;
jeffhao7fbee072012-08-24 17:56:54 -0700357 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700358 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700359}
360
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700361uint32_t MipsAssembler::EmitI21(int opcode, Register rs, uint32_t imm21) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200362 CHECK_NE(rs, kNoRegister);
363 CHECK(IsUint<21>(imm21)) << imm21;
364 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
365 static_cast<uint32_t>(rs) << kRsShift |
366 imm21;
jeffhao7fbee072012-08-24 17:56:54 -0700367 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700368 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700369}
370
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700371uint32_t MipsAssembler::EmitI26(int opcode, uint32_t imm26) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200372 CHECK(IsUint<26>(imm26)) << imm26;
373 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift | imm26;
374 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700375 return encoding;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200376}
377
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700378uint32_t MipsAssembler::EmitFR(int opcode,
379 int fmt,
380 FRegister ft,
381 FRegister fs,
382 FRegister fd,
383 int funct) {
jeffhao7fbee072012-08-24 17:56:54 -0700384 CHECK_NE(ft, kNoFRegister);
385 CHECK_NE(fs, kNoFRegister);
386 CHECK_NE(fd, kNoFRegister);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200387 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
388 fmt << kFmtShift |
389 static_cast<uint32_t>(ft) << kFtShift |
390 static_cast<uint32_t>(fs) << kFsShift |
391 static_cast<uint32_t>(fd) << kFdShift |
392 funct;
jeffhao7fbee072012-08-24 17:56:54 -0700393 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700394 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700395}
396
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700397uint32_t MipsAssembler::EmitFI(int opcode, int fmt, FRegister ft, uint16_t imm) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200398 CHECK_NE(ft, kNoFRegister);
399 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
400 fmt << kFmtShift |
401 static_cast<uint32_t>(ft) << kFtShift |
402 imm;
jeffhao7fbee072012-08-24 17:56:54 -0700403 Emit(encoding);
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700404 return encoding;
jeffhao7fbee072012-08-24 17:56:54 -0700405}
406
Lena Djokic0758ae72017-05-23 11:06:23 +0200407uint32_t MipsAssembler::EmitMsa3R(int operation,
408 int df,
409 VectorRegister wt,
410 VectorRegister ws,
411 VectorRegister wd,
412 int minor_opcode) {
413 CHECK_NE(wt, kNoVectorRegister);
414 CHECK_NE(ws, kNoVectorRegister);
415 CHECK_NE(wd, kNoVectorRegister);
416 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
417 operation << kMsaOperationShift |
418 df << kDfShift |
419 static_cast<uint32_t>(wt) << kWtShift |
420 static_cast<uint32_t>(ws) << kWsShift |
421 static_cast<uint32_t>(wd) << kWdShift |
422 minor_opcode;
423 Emit(encoding);
424 return encoding;
425}
426
427uint32_t MipsAssembler::EmitMsaBIT(int operation,
428 int df_m,
429 VectorRegister ws,
430 VectorRegister wd,
431 int minor_opcode) {
432 CHECK_NE(ws, kNoVectorRegister);
433 CHECK_NE(wd, kNoVectorRegister);
434 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
435 operation << kMsaOperationShift |
436 df_m << kDfMShift |
437 static_cast<uint32_t>(ws) << kWsShift |
438 static_cast<uint32_t>(wd) << kWdShift |
439 minor_opcode;
440 Emit(encoding);
441 return encoding;
442}
443
444uint32_t MipsAssembler::EmitMsaELM(int operation,
445 int df_n,
446 VectorRegister ws,
447 VectorRegister wd,
448 int minor_opcode) {
449 CHECK_NE(ws, kNoVectorRegister);
450 CHECK_NE(wd, kNoVectorRegister);
451 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
452 operation << kMsaELMOperationShift |
453 df_n << kDfNShift |
454 static_cast<uint32_t>(ws) << kWsShift |
455 static_cast<uint32_t>(wd) << kWdShift |
456 minor_opcode;
457 Emit(encoding);
458 return encoding;
459}
460
461uint32_t MipsAssembler::EmitMsaMI10(int s10,
462 Register rs,
463 VectorRegister wd,
464 int minor_opcode,
465 int df) {
466 CHECK_NE(rs, kNoRegister);
467 CHECK_NE(wd, kNoVectorRegister);
468 CHECK(IsUint<10>(s10)) << s10;
469 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
470 s10 << kS10Shift |
471 static_cast<uint32_t>(rs) << kWsShift |
472 static_cast<uint32_t>(wd) << kWdShift |
473 minor_opcode << kS10MinorShift |
474 df;
475 Emit(encoding);
476 return encoding;
477}
478
479uint32_t MipsAssembler::EmitMsaI10(int operation,
480 int df,
481 int i10,
482 VectorRegister wd,
483 int minor_opcode) {
484 CHECK_NE(wd, kNoVectorRegister);
485 CHECK(IsUint<10>(i10)) << i10;
486 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
487 operation << kMsaOperationShift |
488 df << kDfShift |
489 i10 << kI10Shift |
490 static_cast<uint32_t>(wd) << kWdShift |
491 minor_opcode;
492 Emit(encoding);
493 return encoding;
494}
495
496uint32_t MipsAssembler::EmitMsa2R(int operation,
497 int df,
498 VectorRegister ws,
499 VectorRegister wd,
500 int minor_opcode) {
501 CHECK_NE(ws, kNoVectorRegister);
502 CHECK_NE(wd, kNoVectorRegister);
503 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
504 operation << kMsa2ROperationShift |
505 df << kDf2RShift |
506 static_cast<uint32_t>(ws) << kWsShift |
507 static_cast<uint32_t>(wd) << kWdShift |
508 minor_opcode;
509 Emit(encoding);
510 return encoding;
511}
512
513uint32_t MipsAssembler::EmitMsa2RF(int operation,
514 int df,
515 VectorRegister ws,
516 VectorRegister wd,
517 int minor_opcode) {
518 CHECK_NE(ws, kNoVectorRegister);
519 CHECK_NE(wd, kNoVectorRegister);
520 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
521 operation << kMsa2RFOperationShift |
522 df << kDf2RShift |
523 static_cast<uint32_t>(ws) << kWsShift |
524 static_cast<uint32_t>(wd) << kWdShift |
525 minor_opcode;
526 Emit(encoding);
527 return encoding;
528}
529
jeffhao7fbee072012-08-24 17:56:54 -0700530void MipsAssembler::Addu(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700531 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x21), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700532}
533
jeffhao7fbee072012-08-24 17:56:54 -0700534void MipsAssembler::Addiu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700535 DsFsmInstrRrr(EmitI(0x9, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700536}
537
jeffhao7fbee072012-08-24 17:56:54 -0700538void MipsAssembler::Subu(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700539 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x23), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700540}
541
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200542void MipsAssembler::MultR2(Register rs, Register rt) {
543 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700544 DsFsmInstrRrr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x18), ZERO, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700545}
546
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200547void MipsAssembler::MultuR2(Register rs, Register rt) {
548 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700549 DsFsmInstrRrr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x19), ZERO, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700550}
551
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200552void MipsAssembler::DivR2(Register rs, Register rt) {
553 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700554 DsFsmInstrRrr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x1a), ZERO, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700555}
556
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200557void MipsAssembler::DivuR2(Register rs, Register rt) {
558 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700559 DsFsmInstrRrr(EmitR(0, rs, rt, static_cast<Register>(0), 0, 0x1b), ZERO, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700560}
561
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200562void MipsAssembler::MulR2(Register rd, Register rs, Register rt) {
563 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700564 DsFsmInstrRrr(EmitR(0x1c, rs, rt, rd, 0, 2), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200565}
566
567void MipsAssembler::DivR2(Register rd, Register rs, Register rt) {
568 CHECK(!IsR6());
569 DivR2(rs, rt);
570 Mflo(rd);
571}
572
573void MipsAssembler::ModR2(Register rd, Register rs, Register rt) {
574 CHECK(!IsR6());
575 DivR2(rs, rt);
576 Mfhi(rd);
577}
578
579void MipsAssembler::DivuR2(Register rd, Register rs, Register rt) {
580 CHECK(!IsR6());
581 DivuR2(rs, rt);
582 Mflo(rd);
583}
584
585void MipsAssembler::ModuR2(Register rd, Register rs, Register rt) {
586 CHECK(!IsR6());
587 DivuR2(rs, rt);
588 Mfhi(rd);
589}
590
591void MipsAssembler::MulR6(Register rd, Register rs, Register rt) {
592 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700593 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 2, 0x18), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200594}
595
Alexey Frunze7e99e052015-11-24 19:28:01 -0800596void MipsAssembler::MuhR6(Register rd, Register rs, Register rt) {
597 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700598 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 3, 0x18), rd, rs, rt);
Alexey Frunze7e99e052015-11-24 19:28:01 -0800599}
600
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200601void MipsAssembler::MuhuR6(Register rd, Register rs, Register rt) {
602 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700603 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 3, 0x19), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200604}
605
606void MipsAssembler::DivR6(Register rd, Register rs, Register rt) {
607 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700608 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 2, 0x1a), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200609}
610
611void MipsAssembler::ModR6(Register rd, Register rs, Register rt) {
612 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700613 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 3, 0x1a), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200614}
615
616void MipsAssembler::DivuR6(Register rd, Register rs, Register rt) {
617 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700618 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 2, 0x1b), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200619}
620
621void MipsAssembler::ModuR6(Register rd, Register rs, Register rt) {
622 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700623 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 3, 0x1b), rd, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200624}
625
jeffhao7fbee072012-08-24 17:56:54 -0700626void MipsAssembler::And(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700627 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x24), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700628}
629
630void MipsAssembler::Andi(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700631 DsFsmInstrRrr(EmitI(0xc, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700632}
633
634void MipsAssembler::Or(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700635 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x25), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700636}
637
638void MipsAssembler::Ori(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700639 DsFsmInstrRrr(EmitI(0xd, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700640}
641
642void MipsAssembler::Xor(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700643 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x26), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700644}
645
646void MipsAssembler::Xori(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700647 DsFsmInstrRrr(EmitI(0xe, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700648}
649
650void MipsAssembler::Nor(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700651 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x27), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700652}
653
Chris Larsene3845472015-11-18 12:27:15 -0800654void MipsAssembler::Movz(Register rd, Register rs, Register rt) {
655 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700656 DsFsmInstrRrrr(EmitR(0, rs, rt, rd, 0, 0x0A), rd, rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800657}
658
659void MipsAssembler::Movn(Register rd, Register rs, Register rt) {
660 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700661 DsFsmInstrRrrr(EmitR(0, rs, rt, rd, 0, 0x0B), rd, rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800662}
663
664void MipsAssembler::Seleqz(Register rd, Register rs, Register rt) {
665 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700666 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x35), rd, rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800667}
668
669void MipsAssembler::Selnez(Register rd, Register rs, Register rt) {
670 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700671 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x37), rd, rs, rt);
Chris Larsene3845472015-11-18 12:27:15 -0800672}
673
674void MipsAssembler::ClzR6(Register rd, Register rs) {
675 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700676 DsFsmInstrRrr(EmitR(0, rs, static_cast<Register>(0), rd, 0x01, 0x10), rd, rs, rs);
Chris Larsene3845472015-11-18 12:27:15 -0800677}
678
679void MipsAssembler::ClzR2(Register rd, Register rs) {
680 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700681 DsFsmInstrRrr(EmitR(0x1C, rs, rd, rd, 0, 0x20), rd, rs, rs);
Chris Larsene3845472015-11-18 12:27:15 -0800682}
683
684void MipsAssembler::CloR6(Register rd, Register rs) {
685 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700686 DsFsmInstrRrr(EmitR(0, rs, static_cast<Register>(0), rd, 0x01, 0x11), rd, rs, rs);
Chris Larsene3845472015-11-18 12:27:15 -0800687}
688
689void MipsAssembler::CloR2(Register rd, Register rs) {
690 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700691 DsFsmInstrRrr(EmitR(0x1C, rs, rd, rd, 0, 0x21), rd, rs, rs);
Chris Larsene3845472015-11-18 12:27:15 -0800692}
693
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200694void MipsAssembler::Seb(Register rd, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700695 DsFsmInstrRrr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x10, 0x20), rd, rt, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700696}
697
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200698void MipsAssembler::Seh(Register rd, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700699 DsFsmInstrRrr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x18, 0x20), rd, rt, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700700}
701
Chris Larsen3f8bf652015-10-28 10:08:56 -0700702void MipsAssembler::Wsbh(Register rd, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700703 DsFsmInstrRrr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 2, 0x20), rd, rt, rt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700704}
705
Chris Larsen70014c82015-11-18 12:26:08 -0800706void MipsAssembler::Bitswap(Register rd, Register rt) {
707 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700708 DsFsmInstrRrr(EmitR(0x1f, static_cast<Register>(0), rt, rd, 0x0, 0x20), rd, rt, rt);
Chris Larsen70014c82015-11-18 12:26:08 -0800709}
710
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200711void MipsAssembler::Sll(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700712 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700713 DsFsmInstrRrr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x00), rd, rt, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700714}
715
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200716void MipsAssembler::Srl(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700717 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700718 DsFsmInstrRrr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x02), rd, rt, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200719}
720
Chris Larsen3f8bf652015-10-28 10:08:56 -0700721void MipsAssembler::Rotr(Register rd, Register rt, int shamt) {
722 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700723 DsFsmInstrRrr(EmitR(0, static_cast<Register>(1), rt, rd, shamt, 0x02), rd, rt, rt);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700724}
725
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200726void MipsAssembler::Sra(Register rd, Register rt, int shamt) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700727 CHECK(IsUint<5>(shamt)) << shamt;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700728 DsFsmInstrRrr(EmitR(0, static_cast<Register>(0), rt, rd, shamt, 0x03), rd, rt, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200729}
730
731void MipsAssembler::Sllv(Register rd, Register rt, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700732 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x04), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700733}
734
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200735void MipsAssembler::Srlv(Register rd, Register rt, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700736 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x06), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700737}
738
Chris Larsene16ce5a2015-11-18 12:30:20 -0800739void MipsAssembler::Rotrv(Register rd, Register rt, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700740 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 1, 0x06), rd, rs, rt);
Chris Larsene16ce5a2015-11-18 12:30:20 -0800741}
742
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200743void MipsAssembler::Srav(Register rd, Register rt, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700744 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x07), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700745}
746
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800747void MipsAssembler::Ext(Register rd, Register rt, int pos, int size) {
748 CHECK(IsUint<5>(pos)) << pos;
749 CHECK(0 < size && size <= 32) << size;
750 CHECK(0 < pos + size && pos + size <= 32) << pos << " + " << size;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700751 DsFsmInstrRrr(EmitR(0x1f, rt, rd, static_cast<Register>(size - 1), pos, 0x00), rd, rt, rt);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800752}
753
754void MipsAssembler::Ins(Register rd, Register rt, int pos, int size) {
755 CHECK(IsUint<5>(pos)) << pos;
756 CHECK(0 < size && size <= 32) << size;
757 CHECK(0 < pos + size && pos + size <= 32) << pos << " + " << size;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700758 DsFsmInstrRrr(EmitR(0x1f, rt, rd, static_cast<Register>(pos + size - 1), pos, 0x04), rd, rd, rt);
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800759}
760
Chris Larsen692235e2016-11-21 16:04:53 -0800761void MipsAssembler::Lsa(Register rd, Register rs, Register rt, int saPlusOne) {
Lena Djokic0758ae72017-05-23 11:06:23 +0200762 CHECK(IsR6() || HasMsa());
Chris Larsen692235e2016-11-21 16:04:53 -0800763 CHECK(1 <= saPlusOne && saPlusOne <= 4) << saPlusOne;
764 int sa = saPlusOne - 1;
765 DsFsmInstrRrr(EmitR(0x0, rs, rt, rd, sa, 0x05), rd, rs, rt);
766}
767
Chris Larsencd0295d2017-03-31 15:26:54 -0700768void MipsAssembler::ShiftAndAdd(Register dst,
769 Register src_idx,
770 Register src_base,
771 int shamt,
772 Register tmp) {
773 CHECK(0 <= shamt && shamt <= 4) << shamt;
774 CHECK_NE(src_base, tmp);
775 if (shamt == TIMES_1) {
776 // Catch the special case where the shift amount is zero (0).
777 Addu(dst, src_base, src_idx);
Lena Djokic0758ae72017-05-23 11:06:23 +0200778 } else if (IsR6() || HasMsa()) {
Chris Larsencd0295d2017-03-31 15:26:54 -0700779 Lsa(dst, src_idx, src_base, shamt);
780 } else {
781 Sll(tmp, src_idx, shamt);
782 Addu(dst, src_base, tmp);
783 }
784}
785
jeffhao7fbee072012-08-24 17:56:54 -0700786void MipsAssembler::Lb(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700787 DsFsmInstrRrr(EmitI(0x20, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700788}
789
790void MipsAssembler::Lh(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700791 DsFsmInstrRrr(EmitI(0x21, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700792}
793
794void MipsAssembler::Lw(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700795 DsFsmInstrRrr(EmitI(0x23, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700796}
797
Chris Larsen3acee732015-11-18 13:31:08 -0800798void MipsAssembler::Lwl(Register rt, Register rs, uint16_t imm16) {
799 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700800 DsFsmInstrRrr(EmitI(0x22, rs, rt, imm16), rt, rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800801}
802
803void MipsAssembler::Lwr(Register rt, Register rs, uint16_t imm16) {
804 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700805 DsFsmInstrRrr(EmitI(0x26, rs, rt, imm16), rt, rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800806}
807
jeffhao7fbee072012-08-24 17:56:54 -0700808void MipsAssembler::Lbu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700809 DsFsmInstrRrr(EmitI(0x24, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700810}
811
812void MipsAssembler::Lhu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700813 DsFsmInstrRrr(EmitI(0x25, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700814}
815
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700816void MipsAssembler::Lwpc(Register rs, uint32_t imm19) {
817 CHECK(IsR6());
818 CHECK(IsUint<19>(imm19)) << imm19;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700819 DsFsmInstrNop(EmitI21(0x3B, rs, (0x01 << 19) | imm19));
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700820}
821
jeffhao7fbee072012-08-24 17:56:54 -0700822void MipsAssembler::Lui(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700823 DsFsmInstrRrr(EmitI(0xf, static_cast<Register>(0), rt, imm16), rt, ZERO, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -0700824}
825
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700826void MipsAssembler::Aui(Register rt, Register rs, uint16_t imm16) {
827 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700828 DsFsmInstrRrr(EmitI(0xf, rs, rt, imm16), rt, rt, rs);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -0700829}
830
Alexey Frunze4147fcc2017-06-17 19:57:27 -0700831void MipsAssembler::AddUpper(Register rt, Register rs, uint16_t imm16, Register tmp) {
832 bool increment = (rs == rt);
833 if (increment) {
834 CHECK_NE(rs, tmp);
835 }
836 if (IsR6()) {
837 Aui(rt, rs, imm16);
838 } else if (increment) {
839 Lui(tmp, imm16);
840 Addu(rt, rs, tmp);
841 } else {
842 Lui(rt, imm16);
843 Addu(rt, rs, rt);
844 }
845}
846
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200847void MipsAssembler::Sync(uint32_t stype) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700848 DsFsmInstrNop(EmitR(0, ZERO, ZERO, ZERO, stype & 0x1f, 0xf));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200849}
850
jeffhao7fbee072012-08-24 17:56:54 -0700851void MipsAssembler::Mfhi(Register rd) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200852 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700853 DsFsmInstrRrr(EmitR(0, ZERO, ZERO, rd, 0, 0x10), rd, ZERO, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -0700854}
855
856void MipsAssembler::Mflo(Register rd) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200857 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700858 DsFsmInstrRrr(EmitR(0, ZERO, ZERO, rd, 0, 0x12), rd, ZERO, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -0700859}
860
861void MipsAssembler::Sb(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700862 DsFsmInstrRrr(EmitI(0x28, rs, rt, imm16), ZERO, rt, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700863}
864
865void MipsAssembler::Sh(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700866 DsFsmInstrRrr(EmitI(0x29, rs, rt, imm16), ZERO, rt, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700867}
868
869void MipsAssembler::Sw(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700870 DsFsmInstrRrr(EmitI(0x2b, rs, rt, imm16), ZERO, rt, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700871}
872
Chris Larsen3acee732015-11-18 13:31:08 -0800873void MipsAssembler::Swl(Register rt, Register rs, uint16_t imm16) {
874 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700875 DsFsmInstrRrr(EmitI(0x2a, rs, rt, imm16), ZERO, rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800876}
877
878void MipsAssembler::Swr(Register rt, Register rs, uint16_t imm16) {
879 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700880 DsFsmInstrRrr(EmitI(0x2e, rs, rt, imm16), ZERO, rt, rs);
Chris Larsen3acee732015-11-18 13:31:08 -0800881}
882
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700883void MipsAssembler::LlR2(Register rt, Register base, int16_t imm16) {
884 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700885 DsFsmInstrRrr(EmitI(0x30, base, rt, imm16), rt, base, base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700886}
887
888void MipsAssembler::ScR2(Register rt, Register base, int16_t imm16) {
889 CHECK(!IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700890 DsFsmInstrRrr(EmitI(0x38, base, rt, imm16), rt, rt, base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700891}
892
893void MipsAssembler::LlR6(Register rt, Register base, int16_t imm9) {
894 CHECK(IsR6());
895 CHECK(IsInt<9>(imm9));
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700896 DsFsmInstrRrr(EmitI(0x1f, base, rt, ((imm9 & 0x1ff) << 7) | 0x36), rt, base, base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700897}
898
899void MipsAssembler::ScR6(Register rt, Register base, int16_t imm9) {
900 CHECK(IsR6());
901 CHECK(IsInt<9>(imm9));
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700902 DsFsmInstrRrr(EmitI(0x1f, base, rt, ((imm9 & 0x1ff) << 7) | 0x26), rt, rt, base);
Alexey Frunze51aff3a2016-03-17 17:21:45 -0700903}
904
jeffhao7fbee072012-08-24 17:56:54 -0700905void MipsAssembler::Slt(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700906 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x2a), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700907}
908
909void MipsAssembler::Sltu(Register rd, Register rs, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700910 DsFsmInstrRrr(EmitR(0, rs, rt, rd, 0, 0x2b), rd, rs, rt);
jeffhao7fbee072012-08-24 17:56:54 -0700911}
912
913void MipsAssembler::Slti(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700914 DsFsmInstrRrr(EmitI(0xa, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700915}
916
917void MipsAssembler::Sltiu(Register rt, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700918 DsFsmInstrRrr(EmitI(0xb, rs, rt, imm16), rt, rs, rs);
jeffhao7fbee072012-08-24 17:56:54 -0700919}
920
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200921void MipsAssembler::B(uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700922 DsFsmInstrNop(EmitI(0x4, static_cast<Register>(0), static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200923}
924
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700925void MipsAssembler::Bal(uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700926 DsFsmInstrNop(EmitI(0x1, static_cast<Register>(0), static_cast<Register>(0x11), imm16));
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700927}
928
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200929void MipsAssembler::Beq(Register rs, Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700930 DsFsmInstrNop(EmitI(0x4, rs, rt, imm16));
jeffhao7fbee072012-08-24 17:56:54 -0700931}
932
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200933void MipsAssembler::Bne(Register rs, Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700934 DsFsmInstrNop(EmitI(0x5, rs, rt, imm16));
jeffhao7fbee072012-08-24 17:56:54 -0700935}
936
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200937void MipsAssembler::Beqz(Register rt, uint16_t imm16) {
938 Beq(ZERO, rt, imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700939}
940
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200941void MipsAssembler::Bnez(Register rt, uint16_t imm16) {
942 Bne(ZERO, rt, imm16);
jeffhao7fbee072012-08-24 17:56:54 -0700943}
944
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200945void MipsAssembler::Bltz(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700946 DsFsmInstrNop(EmitI(0x1, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200947}
948
949void MipsAssembler::Bgez(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700950 DsFsmInstrNop(EmitI(0x1, rt, static_cast<Register>(0x1), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200951}
952
953void MipsAssembler::Blez(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700954 DsFsmInstrNop(EmitI(0x6, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200955}
956
957void MipsAssembler::Bgtz(Register rt, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700958 DsFsmInstrNop(EmitI(0x7, rt, static_cast<Register>(0), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200959}
960
Chris Larsenb74353a2015-11-20 09:07:09 -0800961void MipsAssembler::Bc1f(uint16_t imm16) {
962 Bc1f(0, imm16);
963}
964
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800965void MipsAssembler::Bc1f(int cc, uint16_t imm16) {
966 CHECK(!IsR6());
967 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700968 DsFsmInstrNop(EmitI(0x11, static_cast<Register>(0x8), static_cast<Register>(cc << 2), imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800969}
970
Chris Larsenb74353a2015-11-20 09:07:09 -0800971void MipsAssembler::Bc1t(uint16_t imm16) {
972 Bc1t(0, imm16);
973}
974
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800975void MipsAssembler::Bc1t(int cc, uint16_t imm16) {
976 CHECK(!IsR6());
977 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700978 DsFsmInstrNop(EmitI(0x11,
979 static_cast<Register>(0x8),
980 static_cast<Register>((cc << 2) | 1),
981 imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800982}
983
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200984void MipsAssembler::J(uint32_t addr26) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700985 DsFsmInstrNop(EmitI26(0x2, addr26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200986}
987
988void MipsAssembler::Jal(uint32_t addr26) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700989 DsFsmInstrNop(EmitI26(0x3, addr26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200990}
991
992void MipsAssembler::Jalr(Register rd, Register rs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700993 uint32_t last_instruction = delay_slot_.instruction_;
994 bool exchange = (last_instruction != 0 &&
995 (delay_slot_.gpr_outs_mask_ & (1u << rs)) == 0 &&
996 ((delay_slot_.gpr_ins_mask_ | delay_slot_.gpr_outs_mask_) & (1u << rd)) == 0);
997 if (exchange) {
998 // The last instruction cannot be used in a different delay slot,
999 // do not commit the label before it (if any).
1000 DsFsmDropLabel();
1001 }
1002 DsFsmInstrNop(EmitR(0, rs, static_cast<Register>(0), rd, 0, 0x09));
1003 if (exchange) {
1004 // Exchange the last two instructions in the assembler buffer.
1005 size_t size = buffer_.Size();
1006 CHECK_GE(size, 2 * sizeof(uint32_t));
1007 size_t pos1 = size - 2 * sizeof(uint32_t);
1008 size_t pos2 = size - sizeof(uint32_t);
1009 uint32_t instr1 = buffer_.Load<uint32_t>(pos1);
1010 uint32_t instr2 = buffer_.Load<uint32_t>(pos2);
1011 CHECK_EQ(instr1, last_instruction);
1012 buffer_.Store<uint32_t>(pos1, instr2);
1013 buffer_.Store<uint32_t>(pos2, instr1);
1014 } else if (reordering_) {
1015 Nop();
1016 }
jeffhao7fbee072012-08-24 17:56:54 -07001017}
1018
1019void MipsAssembler::Jalr(Register rs) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001020 Jalr(RA, rs);
1021}
1022
1023void MipsAssembler::Jr(Register rs) {
1024 Jalr(ZERO, rs);
1025}
1026
1027void MipsAssembler::Nal() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001028 DsFsmInstrNop(EmitI(0x1, static_cast<Register>(0), static_cast<Register>(0x10), 0));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001029}
1030
1031void MipsAssembler::Auipc(Register rs, uint16_t imm16) {
1032 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001033 DsFsmInstrNop(EmitI(0x3B, rs, static_cast<Register>(0x1E), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001034}
1035
1036void MipsAssembler::Addiupc(Register rs, uint32_t imm19) {
1037 CHECK(IsR6());
1038 CHECK(IsUint<19>(imm19)) << imm19;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001039 DsFsmInstrNop(EmitI21(0x3B, rs, imm19));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001040}
1041
1042void MipsAssembler::Bc(uint32_t imm26) {
1043 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001044 DsFsmInstrNop(EmitI26(0x32, imm26));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001045}
1046
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001047void MipsAssembler::Balc(uint32_t imm26) {
1048 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001049 DsFsmInstrNop(EmitI26(0x3A, imm26));
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001050}
1051
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001052void MipsAssembler::Jic(Register rt, uint16_t imm16) {
1053 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001054 DsFsmInstrNop(EmitI(0x36, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001055}
1056
1057void MipsAssembler::Jialc(Register rt, uint16_t imm16) {
1058 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001059 DsFsmInstrNop(EmitI(0x3E, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001060}
1061
1062void MipsAssembler::Bltc(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(0x17, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001068}
1069
1070void MipsAssembler::Bltzc(Register rt, uint16_t imm16) {
1071 CHECK(IsR6());
1072 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001073 DsFsmInstrNop(EmitI(0x17, rt, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001074}
1075
1076void MipsAssembler::Bgtzc(Register rt, uint16_t imm16) {
1077 CHECK(IsR6());
1078 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001079 DsFsmInstrNop(EmitI(0x17, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001080}
1081
1082void MipsAssembler::Bgec(Register rs, Register rt, uint16_t imm16) {
1083 CHECK(IsR6());
1084 CHECK_NE(rs, ZERO);
1085 CHECK_NE(rt, ZERO);
1086 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001087 DsFsmInstrNop(EmitI(0x16, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001088}
1089
1090void MipsAssembler::Bgezc(Register rt, uint16_t imm16) {
1091 CHECK(IsR6());
1092 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001093 DsFsmInstrNop(EmitI(0x16, rt, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001094}
1095
1096void MipsAssembler::Blezc(Register rt, uint16_t imm16) {
1097 CHECK(IsR6());
1098 CHECK_NE(rt, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001099 DsFsmInstrNop(EmitI(0x16, static_cast<Register>(0), rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001100}
1101
1102void MipsAssembler::Bltuc(Register rs, Register rt, uint16_t imm16) {
1103 CHECK(IsR6());
1104 CHECK_NE(rs, ZERO);
1105 CHECK_NE(rt, ZERO);
1106 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001107 DsFsmInstrNop(EmitI(0x7, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001108}
1109
1110void MipsAssembler::Bgeuc(Register rs, Register rt, uint16_t imm16) {
1111 CHECK(IsR6());
1112 CHECK_NE(rs, ZERO);
1113 CHECK_NE(rt, ZERO);
1114 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001115 DsFsmInstrNop(EmitI(0x6, rs, rt, imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001116}
1117
1118void MipsAssembler::Beqc(Register rs, Register rt, uint16_t imm16) {
1119 CHECK(IsR6());
1120 CHECK_NE(rs, ZERO);
1121 CHECK_NE(rt, ZERO);
1122 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001123 DsFsmInstrNop(EmitI(0x8, std::min(rs, rt), std::max(rs, rt), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001124}
1125
1126void MipsAssembler::Bnec(Register rs, Register rt, uint16_t imm16) {
1127 CHECK(IsR6());
1128 CHECK_NE(rs, ZERO);
1129 CHECK_NE(rt, ZERO);
1130 CHECK_NE(rs, rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001131 DsFsmInstrNop(EmitI(0x18, std::min(rs, rt), std::max(rs, rt), imm16));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001132}
1133
1134void MipsAssembler::Beqzc(Register rs, uint32_t imm21) {
1135 CHECK(IsR6());
1136 CHECK_NE(rs, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001137 DsFsmInstrNop(EmitI21(0x36, rs, imm21));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001138}
1139
1140void MipsAssembler::Bnezc(Register rs, uint32_t imm21) {
1141 CHECK(IsR6());
1142 CHECK_NE(rs, ZERO);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001143 DsFsmInstrNop(EmitI21(0x3E, rs, imm21));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001144}
1145
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001146void MipsAssembler::Bc1eqz(FRegister ft, uint16_t imm16) {
1147 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001148 DsFsmInstrNop(EmitFI(0x11, 0x9, ft, imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001149}
1150
1151void MipsAssembler::Bc1nez(FRegister ft, uint16_t imm16) {
1152 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001153 DsFsmInstrNop(EmitFI(0x11, 0xD, ft, imm16));
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001154}
1155
1156void MipsAssembler::EmitBcondR2(BranchCondition cond, Register rs, Register rt, uint16_t imm16) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001157 switch (cond) {
1158 case kCondLTZ:
1159 CHECK_EQ(rt, ZERO);
1160 Bltz(rs, imm16);
1161 break;
1162 case kCondGEZ:
1163 CHECK_EQ(rt, ZERO);
1164 Bgez(rs, imm16);
1165 break;
1166 case kCondLEZ:
1167 CHECK_EQ(rt, ZERO);
1168 Blez(rs, imm16);
1169 break;
1170 case kCondGTZ:
1171 CHECK_EQ(rt, ZERO);
1172 Bgtz(rs, imm16);
1173 break;
1174 case kCondEQ:
1175 Beq(rs, rt, imm16);
1176 break;
1177 case kCondNE:
1178 Bne(rs, rt, imm16);
1179 break;
1180 case kCondEQZ:
1181 CHECK_EQ(rt, ZERO);
1182 Beqz(rs, imm16);
1183 break;
1184 case kCondNEZ:
1185 CHECK_EQ(rt, ZERO);
1186 Bnez(rs, imm16);
1187 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001188 case kCondF:
1189 CHECK_EQ(rt, ZERO);
1190 Bc1f(static_cast<int>(rs), imm16);
1191 break;
1192 case kCondT:
1193 CHECK_EQ(rt, ZERO);
1194 Bc1t(static_cast<int>(rs), imm16);
1195 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001196 case kCondLT:
1197 case kCondGE:
1198 case kCondLE:
1199 case kCondGT:
1200 case kCondLTU:
1201 case kCondGEU:
1202 case kUncond:
1203 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
1204 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
1205 LOG(FATAL) << "Unexpected branch condition " << cond;
1206 UNREACHABLE();
1207 }
1208}
1209
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001210void MipsAssembler::EmitBcondR6(BranchCondition cond, Register rs, Register rt, uint32_t imm16_21) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001211 switch (cond) {
1212 case kCondLT:
1213 Bltc(rs, rt, imm16_21);
1214 break;
1215 case kCondGE:
1216 Bgec(rs, rt, imm16_21);
1217 break;
1218 case kCondLE:
1219 Bgec(rt, rs, imm16_21);
1220 break;
1221 case kCondGT:
1222 Bltc(rt, rs, imm16_21);
1223 break;
1224 case kCondLTZ:
1225 CHECK_EQ(rt, ZERO);
1226 Bltzc(rs, imm16_21);
1227 break;
1228 case kCondGEZ:
1229 CHECK_EQ(rt, ZERO);
1230 Bgezc(rs, imm16_21);
1231 break;
1232 case kCondLEZ:
1233 CHECK_EQ(rt, ZERO);
1234 Blezc(rs, imm16_21);
1235 break;
1236 case kCondGTZ:
1237 CHECK_EQ(rt, ZERO);
1238 Bgtzc(rs, imm16_21);
1239 break;
1240 case kCondEQ:
1241 Beqc(rs, rt, imm16_21);
1242 break;
1243 case kCondNE:
1244 Bnec(rs, rt, imm16_21);
1245 break;
1246 case kCondEQZ:
1247 CHECK_EQ(rt, ZERO);
1248 Beqzc(rs, imm16_21);
1249 break;
1250 case kCondNEZ:
1251 CHECK_EQ(rt, ZERO);
1252 Bnezc(rs, imm16_21);
1253 break;
1254 case kCondLTU:
1255 Bltuc(rs, rt, imm16_21);
1256 break;
1257 case kCondGEU:
1258 Bgeuc(rs, rt, imm16_21);
1259 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001260 case kCondF:
1261 CHECK_EQ(rt, ZERO);
1262 Bc1eqz(static_cast<FRegister>(rs), imm16_21);
1263 break;
1264 case kCondT:
1265 CHECK_EQ(rt, ZERO);
1266 Bc1nez(static_cast<FRegister>(rs), imm16_21);
1267 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001268 case kUncond:
1269 LOG(FATAL) << "Unexpected branch condition " << cond;
1270 UNREACHABLE();
1271 }
jeffhao7fbee072012-08-24 17:56:54 -07001272}
1273
1274void MipsAssembler::AddS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001275 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x0), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001276}
1277
1278void MipsAssembler::SubS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001279 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x1), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001280}
1281
1282void MipsAssembler::MulS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001283 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x2), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001284}
1285
1286void MipsAssembler::DivS(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001287 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x3), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001288}
1289
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001290void MipsAssembler::AddD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001291 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x0), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001292}
1293
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001294void MipsAssembler::SubD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001295 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x1), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001296}
1297
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001298void MipsAssembler::MulD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001299 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x2), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001300}
1301
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001302void MipsAssembler::DivD(FRegister fd, FRegister fs, FRegister ft) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001303 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x3), fd, fs, ft);
jeffhao7fbee072012-08-24 17:56:54 -07001304}
1305
Chris Larsenb74353a2015-11-20 09:07:09 -08001306void MipsAssembler::SqrtS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001307 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x4), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001308}
1309
1310void MipsAssembler::SqrtD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001311 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x4), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001312}
1313
1314void MipsAssembler::AbsS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001315 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x5), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001316}
1317
1318void MipsAssembler::AbsD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001319 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x5), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001320}
1321
jeffhao7fbee072012-08-24 17:56:54 -07001322void MipsAssembler::MovS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001323 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x6), fd, fs, fs);
jeffhao7fbee072012-08-24 17:56:54 -07001324}
1325
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001326void MipsAssembler::MovD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001327 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x6), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001328}
1329
1330void MipsAssembler::NegS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001331 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x7), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001332}
1333
1334void MipsAssembler::NegD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001335 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x7), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001336}
1337
Chris Larsenb74353a2015-11-20 09:07:09 -08001338void MipsAssembler::CunS(FRegister fs, FRegister ft) {
1339 CunS(0, fs, ft);
1340}
1341
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001342void MipsAssembler::CunS(int cc, FRegister fs, FRegister ft) {
1343 CHECK(!IsR6());
1344 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001345 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x31), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001346}
1347
Chris Larsenb74353a2015-11-20 09:07:09 -08001348void MipsAssembler::CeqS(FRegister fs, FRegister ft) {
1349 CeqS(0, fs, ft);
1350}
1351
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001352void MipsAssembler::CeqS(int cc, FRegister fs, FRegister ft) {
1353 CHECK(!IsR6());
1354 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001355 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x32), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001356}
1357
Chris Larsenb74353a2015-11-20 09:07:09 -08001358void MipsAssembler::CueqS(FRegister fs, FRegister ft) {
1359 CueqS(0, fs, ft);
1360}
1361
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001362void MipsAssembler::CueqS(int cc, FRegister fs, FRegister ft) {
1363 CHECK(!IsR6());
1364 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001365 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x33), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001366}
1367
Chris Larsenb74353a2015-11-20 09:07:09 -08001368void MipsAssembler::ColtS(FRegister fs, FRegister ft) {
1369 ColtS(0, fs, ft);
1370}
1371
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001372void MipsAssembler::ColtS(int cc, FRegister fs, FRegister ft) {
1373 CHECK(!IsR6());
1374 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001375 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x34), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001376}
1377
Chris Larsenb74353a2015-11-20 09:07:09 -08001378void MipsAssembler::CultS(FRegister fs, FRegister ft) {
1379 CultS(0, fs, ft);
1380}
1381
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001382void MipsAssembler::CultS(int cc, FRegister fs, FRegister ft) {
1383 CHECK(!IsR6());
1384 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001385 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x35), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001386}
1387
Chris Larsenb74353a2015-11-20 09:07:09 -08001388void MipsAssembler::ColeS(FRegister fs, FRegister ft) {
1389 ColeS(0, fs, ft);
1390}
1391
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001392void MipsAssembler::ColeS(int cc, FRegister fs, FRegister ft) {
1393 CHECK(!IsR6());
1394 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001395 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x36), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001396}
1397
Chris Larsenb74353a2015-11-20 09:07:09 -08001398void MipsAssembler::CuleS(FRegister fs, FRegister ft) {
1399 CuleS(0, fs, ft);
1400}
1401
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001402void MipsAssembler::CuleS(int cc, FRegister fs, FRegister ft) {
1403 CHECK(!IsR6());
1404 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001405 DsFsmInstrCff(EmitFR(0x11, 0x10, ft, fs, static_cast<FRegister>(cc << 2), 0x37), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001406}
1407
Chris Larsenb74353a2015-11-20 09:07:09 -08001408void MipsAssembler::CunD(FRegister fs, FRegister ft) {
1409 CunD(0, fs, ft);
1410}
1411
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001412void MipsAssembler::CunD(int cc, FRegister fs, FRegister ft) {
1413 CHECK(!IsR6());
1414 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001415 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x31), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001416}
1417
Chris Larsenb74353a2015-11-20 09:07:09 -08001418void MipsAssembler::CeqD(FRegister fs, FRegister ft) {
1419 CeqD(0, fs, ft);
1420}
1421
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001422void MipsAssembler::CeqD(int cc, FRegister fs, FRegister ft) {
1423 CHECK(!IsR6());
1424 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001425 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x32), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001426}
1427
Chris Larsenb74353a2015-11-20 09:07:09 -08001428void MipsAssembler::CueqD(FRegister fs, FRegister ft) {
1429 CueqD(0, fs, ft);
1430}
1431
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001432void MipsAssembler::CueqD(int cc, FRegister fs, FRegister ft) {
1433 CHECK(!IsR6());
1434 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001435 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x33), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001436}
1437
Chris Larsenb74353a2015-11-20 09:07:09 -08001438void MipsAssembler::ColtD(FRegister fs, FRegister ft) {
1439 ColtD(0, fs, ft);
1440}
1441
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001442void MipsAssembler::ColtD(int cc, FRegister fs, FRegister ft) {
1443 CHECK(!IsR6());
1444 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001445 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x34), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001446}
1447
Chris Larsenb74353a2015-11-20 09:07:09 -08001448void MipsAssembler::CultD(FRegister fs, FRegister ft) {
1449 CultD(0, fs, ft);
1450}
1451
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001452void MipsAssembler::CultD(int cc, FRegister fs, FRegister ft) {
1453 CHECK(!IsR6());
1454 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001455 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x35), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001456}
1457
Chris Larsenb74353a2015-11-20 09:07:09 -08001458void MipsAssembler::ColeD(FRegister fs, FRegister ft) {
1459 ColeD(0, fs, ft);
1460}
1461
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001462void MipsAssembler::ColeD(int cc, FRegister fs, FRegister ft) {
1463 CHECK(!IsR6());
1464 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001465 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x36), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001466}
1467
Chris Larsenb74353a2015-11-20 09:07:09 -08001468void MipsAssembler::CuleD(FRegister fs, FRegister ft) {
1469 CuleD(0, fs, ft);
1470}
1471
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001472void MipsAssembler::CuleD(int cc, FRegister fs, FRegister ft) {
1473 CHECK(!IsR6());
1474 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001475 DsFsmInstrCff(EmitFR(0x11, 0x11, ft, fs, static_cast<FRegister>(cc << 2), 0x37), cc, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001476}
1477
1478void MipsAssembler::CmpUnS(FRegister fd, FRegister fs, FRegister ft) {
1479 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001480 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x01), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001481}
1482
1483void MipsAssembler::CmpEqS(FRegister fd, FRegister fs, FRegister ft) {
1484 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001485 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x02), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001486}
1487
1488void MipsAssembler::CmpUeqS(FRegister fd, FRegister fs, FRegister ft) {
1489 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001490 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x03), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001491}
1492
1493void MipsAssembler::CmpLtS(FRegister fd, FRegister fs, FRegister ft) {
1494 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001495 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x04), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001496}
1497
1498void MipsAssembler::CmpUltS(FRegister fd, FRegister fs, FRegister ft) {
1499 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001500 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x05), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001501}
1502
1503void MipsAssembler::CmpLeS(FRegister fd, FRegister fs, FRegister ft) {
1504 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001505 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x06), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001506}
1507
1508void MipsAssembler::CmpUleS(FRegister fd, FRegister fs, FRegister ft) {
1509 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001510 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x07), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001511}
1512
1513void MipsAssembler::CmpOrS(FRegister fd, FRegister fs, FRegister ft) {
1514 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001515 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x11), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001516}
1517
1518void MipsAssembler::CmpUneS(FRegister fd, FRegister fs, FRegister ft) {
1519 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001520 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x12), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001521}
1522
1523void MipsAssembler::CmpNeS(FRegister fd, FRegister fs, FRegister ft) {
1524 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001525 DsFsmInstrFff(EmitFR(0x11, 0x14, ft, fs, fd, 0x13), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001526}
1527
1528void MipsAssembler::CmpUnD(FRegister fd, FRegister fs, FRegister ft) {
1529 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001530 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x01), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001531}
1532
1533void MipsAssembler::CmpEqD(FRegister fd, FRegister fs, FRegister ft) {
1534 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001535 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x02), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001536}
1537
1538void MipsAssembler::CmpUeqD(FRegister fd, FRegister fs, FRegister ft) {
1539 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001540 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x03), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001541}
1542
1543void MipsAssembler::CmpLtD(FRegister fd, FRegister fs, FRegister ft) {
1544 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001545 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x04), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001546}
1547
1548void MipsAssembler::CmpUltD(FRegister fd, FRegister fs, FRegister ft) {
1549 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001550 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x05), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001551}
1552
1553void MipsAssembler::CmpLeD(FRegister fd, FRegister fs, FRegister ft) {
1554 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001555 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x06), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001556}
1557
1558void MipsAssembler::CmpUleD(FRegister fd, FRegister fs, FRegister ft) {
1559 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001560 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x07), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001561}
1562
1563void MipsAssembler::CmpOrD(FRegister fd, FRegister fs, FRegister ft) {
1564 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001565 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x11), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001566}
1567
1568void MipsAssembler::CmpUneD(FRegister fd, FRegister fs, FRegister ft) {
1569 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001570 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x12), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001571}
1572
1573void MipsAssembler::CmpNeD(FRegister fd, FRegister fs, FRegister ft) {
1574 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001575 DsFsmInstrFff(EmitFR(0x11, 0x15, ft, fs, fd, 0x13), fd, fs, ft);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001576}
1577
1578void MipsAssembler::Movf(Register rd, Register rs, int cc) {
1579 CHECK(!IsR6());
1580 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001581 DsFsmInstrRrrc(EmitR(0, rs, static_cast<Register>(cc << 2), rd, 0, 0x01), rd, rs, cc);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001582}
1583
1584void MipsAssembler::Movt(Register rd, Register rs, int cc) {
1585 CHECK(!IsR6());
1586 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001587 DsFsmInstrRrrc(EmitR(0, rs, static_cast<Register>((cc << 2) | 1), rd, 0, 0x01), rd, rs, cc);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08001588}
1589
Chris Larsenb74353a2015-11-20 09:07:09 -08001590void MipsAssembler::MovfS(FRegister fd, FRegister fs, int cc) {
1591 CHECK(!IsR6());
1592 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001593 DsFsmInstrFffc(EmitFR(0x11, 0x10, static_cast<FRegister>(cc << 2), fs, fd, 0x11), fd, fs, cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001594}
1595
1596void MipsAssembler::MovfD(FRegister fd, FRegister fs, int cc) {
1597 CHECK(!IsR6());
1598 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001599 DsFsmInstrFffc(EmitFR(0x11, 0x11, static_cast<FRegister>(cc << 2), fs, fd, 0x11), fd, fs, cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001600}
1601
1602void MipsAssembler::MovtS(FRegister fd, FRegister fs, int cc) {
1603 CHECK(!IsR6());
1604 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001605 DsFsmInstrFffc(EmitFR(0x11, 0x10, static_cast<FRegister>((cc << 2) | 1), fs, fd, 0x11),
1606 fd,
1607 fs,
1608 cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001609}
1610
1611void MipsAssembler::MovtD(FRegister fd, FRegister fs, int cc) {
1612 CHECK(!IsR6());
1613 CHECK(IsUint<3>(cc)) << cc;
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001614 DsFsmInstrFffc(EmitFR(0x11, 0x11, static_cast<FRegister>((cc << 2) | 1), fs, fd, 0x11),
1615 fd,
1616 fs,
1617 cc);
Chris Larsenb74353a2015-11-20 09:07:09 -08001618}
1619
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001620void MipsAssembler::MovzS(FRegister fd, FRegister fs, Register rt) {
1621 CHECK(!IsR6());
1622 DsFsmInstrFffr(EmitFR(0x11, 0x10, static_cast<FRegister>(rt), fs, fd, 0x12), fd, fs, rt);
1623}
1624
1625void MipsAssembler::MovzD(FRegister fd, FRegister fs, Register rt) {
1626 CHECK(!IsR6());
1627 DsFsmInstrFffr(EmitFR(0x11, 0x11, static_cast<FRegister>(rt), fs, fd, 0x12), fd, fs, rt);
1628}
1629
1630void MipsAssembler::MovnS(FRegister fd, FRegister fs, Register rt) {
1631 CHECK(!IsR6());
1632 DsFsmInstrFffr(EmitFR(0x11, 0x10, static_cast<FRegister>(rt), fs, fd, 0x13), fd, fs, rt);
1633}
1634
1635void MipsAssembler::MovnD(FRegister fd, FRegister fs, Register rt) {
1636 CHECK(!IsR6());
1637 DsFsmInstrFffr(EmitFR(0x11, 0x11, static_cast<FRegister>(rt), fs, fd, 0x13), fd, fs, rt);
1638}
1639
Chris Larsenb74353a2015-11-20 09:07:09 -08001640void MipsAssembler::SelS(FRegister fd, FRegister fs, FRegister ft) {
1641 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001642 DsFsmInstrFfff(EmitFR(0x11, 0x10, ft, fs, fd, 0x10), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001643}
1644
1645void MipsAssembler::SelD(FRegister fd, FRegister fs, FRegister ft) {
1646 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001647 DsFsmInstrFfff(EmitFR(0x11, 0x11, ft, fs, fd, 0x10), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001648}
1649
Alexey Frunze674b9ee2016-09-20 14:54:15 -07001650void MipsAssembler::SeleqzS(FRegister fd, FRegister fs, FRegister ft) {
1651 CHECK(IsR6());
1652 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x14), fd, fs, ft);
1653}
1654
1655void MipsAssembler::SeleqzD(FRegister fd, FRegister fs, FRegister ft) {
1656 CHECK(IsR6());
1657 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x14), fd, fs, ft);
1658}
1659
1660void MipsAssembler::SelnezS(FRegister fd, FRegister fs, FRegister ft) {
1661 CHECK(IsR6());
1662 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x17), fd, fs, ft);
1663}
1664
1665void MipsAssembler::SelnezD(FRegister fd, FRegister fs, FRegister ft) {
1666 CHECK(IsR6());
1667 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x17), fd, fs, ft);
1668}
1669
Chris Larsenb74353a2015-11-20 09:07:09 -08001670void MipsAssembler::ClassS(FRegister fd, FRegister fs) {
1671 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001672 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x1b), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001673}
1674
1675void MipsAssembler::ClassD(FRegister fd, FRegister fs) {
1676 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001677 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x1b), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001678}
1679
1680void MipsAssembler::MinS(FRegister fd, FRegister fs, FRegister ft) {
1681 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001682 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x1c), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001683}
1684
1685void MipsAssembler::MinD(FRegister fd, FRegister fs, FRegister ft) {
1686 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001687 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x1c), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001688}
1689
1690void MipsAssembler::MaxS(FRegister fd, FRegister fs, FRegister ft) {
1691 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001692 DsFsmInstrFff(EmitFR(0x11, 0x10, ft, fs, fd, 0x1e), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001693}
1694
1695void MipsAssembler::MaxD(FRegister fd, FRegister fs, FRegister ft) {
1696 CHECK(IsR6());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001697 DsFsmInstrFff(EmitFR(0x11, 0x11, ft, fs, fd, 0x1e), fd, fs, ft);
Chris Larsenb74353a2015-11-20 09:07:09 -08001698}
1699
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001700void MipsAssembler::TruncLS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001701 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x09), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001702}
1703
1704void MipsAssembler::TruncLD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001705 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x09), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001706}
1707
1708void MipsAssembler::TruncWS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001709 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x0D), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001710}
1711
1712void MipsAssembler::TruncWD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001713 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x0D), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001714}
1715
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001716void MipsAssembler::Cvtsw(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001717 DsFsmInstrFff(EmitFR(0x11, 0x14, static_cast<FRegister>(0), fs, fd, 0x20), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001718}
1719
1720void MipsAssembler::Cvtdw(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001721 DsFsmInstrFff(EmitFR(0x11, 0x14, static_cast<FRegister>(0), fs, fd, 0x21), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001722}
1723
1724void MipsAssembler::Cvtsd(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001725 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0x20), fd, fs, fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001726}
1727
1728void MipsAssembler::Cvtds(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001729 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0x21), fd, fs, fs);
jeffhao7fbee072012-08-24 17:56:54 -07001730}
1731
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001732void MipsAssembler::Cvtsl(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001733 DsFsmInstrFff(EmitFR(0x11, 0x15, static_cast<FRegister>(0), fs, fd, 0x20), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001734}
1735
1736void MipsAssembler::Cvtdl(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001737 DsFsmInstrFff(EmitFR(0x11, 0x15, static_cast<FRegister>(0), fs, fd, 0x21), fd, fs, fs);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08001738}
1739
Chris Larsenb74353a2015-11-20 09:07:09 -08001740void MipsAssembler::FloorWS(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001741 DsFsmInstrFff(EmitFR(0x11, 0x10, static_cast<FRegister>(0), fs, fd, 0xf), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001742}
1743
1744void MipsAssembler::FloorWD(FRegister fd, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001745 DsFsmInstrFff(EmitFR(0x11, 0x11, static_cast<FRegister>(0), fs, fd, 0xf), fd, fs, fs);
Chris Larsenb74353a2015-11-20 09:07:09 -08001746}
1747
jeffhao7fbee072012-08-24 17:56:54 -07001748void MipsAssembler::Mfc1(Register rt, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001749 DsFsmInstrRf(EmitFR(0x11, 0x00, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0),
1750 rt,
1751 fs);
jeffhao7fbee072012-08-24 17:56:54 -07001752}
1753
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001754void MipsAssembler::Mtc1(Register rt, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001755 DsFsmInstrFr(EmitFR(0x11, 0x04, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0),
1756 fs,
1757 rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001758}
1759
1760void MipsAssembler::Mfhc1(Register rt, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001761 DsFsmInstrRf(EmitFR(0x11, 0x03, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0),
1762 rt,
1763 fs);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001764}
1765
1766void MipsAssembler::Mthc1(Register rt, FRegister fs) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001767 DsFsmInstrFr(EmitFR(0x11, 0x07, static_cast<FRegister>(rt), fs, static_cast<FRegister>(0), 0x0),
1768 fs,
1769 rt);
jeffhao7fbee072012-08-24 17:56:54 -07001770}
1771
Alexey Frunzebb9863a2016-01-11 15:51:16 -08001772void MipsAssembler::MoveFromFpuHigh(Register rt, FRegister fs) {
1773 if (Is32BitFPU()) {
1774 CHECK_EQ(fs % 2, 0) << fs;
1775 Mfc1(rt, static_cast<FRegister>(fs + 1));
1776 } else {
1777 Mfhc1(rt, fs);
1778 }
1779}
1780
1781void MipsAssembler::MoveToFpuHigh(Register rt, FRegister fs) {
1782 if (Is32BitFPU()) {
1783 CHECK_EQ(fs % 2, 0) << fs;
1784 Mtc1(rt, static_cast<FRegister>(fs + 1));
1785 } else {
1786 Mthc1(rt, fs);
1787 }
1788}
1789
jeffhao7fbee072012-08-24 17:56:54 -07001790void MipsAssembler::Lwc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001791 DsFsmInstrFr(EmitI(0x31, rs, static_cast<Register>(ft), imm16), ft, rs);
jeffhao7fbee072012-08-24 17:56:54 -07001792}
1793
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001794void MipsAssembler::Ldc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001795 DsFsmInstrFr(EmitI(0x35, rs, static_cast<Register>(ft), imm16), ft, rs);
jeffhao7fbee072012-08-24 17:56:54 -07001796}
1797
1798void MipsAssembler::Swc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001799 DsFsmInstrFR(EmitI(0x39, rs, static_cast<Register>(ft), imm16), ft, rs);
jeffhao7fbee072012-08-24 17:56:54 -07001800}
1801
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001802void MipsAssembler::Sdc1(FRegister ft, Register rs, uint16_t imm16) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001803 DsFsmInstrFR(EmitI(0x3d, rs, static_cast<Register>(ft), imm16), ft, rs);
jeffhao7fbee072012-08-24 17:56:54 -07001804}
1805
1806void MipsAssembler::Break() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001807 DsFsmInstrNop(EmitR(0, ZERO, ZERO, ZERO, 0, 0xD));
jeffhao7fbee072012-08-24 17:56:54 -07001808}
1809
jeffhao07030602012-09-26 14:33:14 -07001810void MipsAssembler::Nop() {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001811 DsFsmInstrNop(EmitR(0x0, ZERO, ZERO, ZERO, 0, 0x0));
1812}
1813
1814void MipsAssembler::NopIfNoReordering() {
1815 if (!reordering_) {
1816 Nop();
1817 }
jeffhao07030602012-09-26 14:33:14 -07001818}
1819
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001820void MipsAssembler::Move(Register rd, Register rs) {
1821 Or(rd, rs, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001822}
1823
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001824void MipsAssembler::Clear(Register rd) {
1825 Move(rd, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001826}
1827
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001828void MipsAssembler::Not(Register rd, Register rs) {
1829 Nor(rd, rs, ZERO);
jeffhao7fbee072012-08-24 17:56:54 -07001830}
1831
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001832void MipsAssembler::Push(Register rs) {
1833 IncreaseFrameSize(kMipsWordSize);
1834 Sw(rs, SP, 0);
jeffhao7fbee072012-08-24 17:56:54 -07001835}
1836
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001837void MipsAssembler::Pop(Register rd) {
1838 Lw(rd, SP, 0);
1839 DecreaseFrameSize(kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07001840}
1841
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001842void MipsAssembler::PopAndReturn(Register rd, Register rt) {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001843 bool reordering = SetReorder(false);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02001844 Lw(rd, SP, 0);
1845 Jr(rt);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001846 DecreaseFrameSize(kMipsWordSize); // Single instruction in delay slot.
1847 SetReorder(reordering);
jeffhao7fbee072012-08-24 17:56:54 -07001848}
1849
Lena Djokic0758ae72017-05-23 11:06:23 +02001850void MipsAssembler::AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1851 CHECK(HasMsa());
1852 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1e),
1853 static_cast<FRegister>(wd),
1854 static_cast<FRegister>(ws),
1855 static_cast<FRegister>(wt));
1856}
1857
1858void MipsAssembler::OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1859 CHECK(HasMsa());
1860 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1e),
1861 static_cast<FRegister>(wd),
1862 static_cast<FRegister>(ws),
1863 static_cast<FRegister>(wt));
1864}
1865
1866void MipsAssembler::NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1867 CHECK(HasMsa());
1868 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1e),
1869 static_cast<FRegister>(wd),
1870 static_cast<FRegister>(ws),
1871 static_cast<FRegister>(wt));
1872}
1873
1874void MipsAssembler::XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1875 CHECK(HasMsa());
1876 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1e),
1877 static_cast<FRegister>(wd),
1878 static_cast<FRegister>(ws),
1879 static_cast<FRegister>(wt));
1880}
1881
1882void MipsAssembler::AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1883 CHECK(HasMsa());
1884 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xe),
1885 static_cast<FRegister>(wd),
1886 static_cast<FRegister>(ws),
1887 static_cast<FRegister>(wt));
1888}
1889
1890void MipsAssembler::AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1891 CHECK(HasMsa());
1892 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xe),
1893 static_cast<FRegister>(wd),
1894 static_cast<FRegister>(ws),
1895 static_cast<FRegister>(wt));
1896}
1897
1898void MipsAssembler::AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1899 CHECK(HasMsa());
1900 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xe),
1901 static_cast<FRegister>(wd),
1902 static_cast<FRegister>(ws),
1903 static_cast<FRegister>(wt));
1904}
1905
1906void MipsAssembler::AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1907 CHECK(HasMsa());
1908 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xe),
1909 static_cast<FRegister>(wd),
1910 static_cast<FRegister>(ws),
1911 static_cast<FRegister>(wt));
1912}
1913
1914void MipsAssembler::SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1915 CHECK(HasMsa());
1916 DsFsmInstrFff(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xe),
1917 static_cast<FRegister>(wd),
1918 static_cast<FRegister>(ws),
1919 static_cast<FRegister>(wt));
1920}
1921
1922void MipsAssembler::SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1923 CHECK(HasMsa());
1924 DsFsmInstrFff(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xe),
1925 static_cast<FRegister>(wd),
1926 static_cast<FRegister>(ws),
1927 static_cast<FRegister>(wt));
1928}
1929
1930void MipsAssembler::SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1931 CHECK(HasMsa());
1932 DsFsmInstrFff(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xe),
1933 static_cast<FRegister>(wd),
1934 static_cast<FRegister>(ws),
1935 static_cast<FRegister>(wt));
1936}
1937
1938void MipsAssembler::SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1939 CHECK(HasMsa());
1940 DsFsmInstrFff(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xe),
1941 static_cast<FRegister>(wd),
1942 static_cast<FRegister>(ws),
1943 static_cast<FRegister>(wt));
1944}
1945
1946void MipsAssembler::MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1947 CHECK(HasMsa());
1948 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x12),
1949 static_cast<FRegister>(wd),
1950 static_cast<FRegister>(ws),
1951 static_cast<FRegister>(wt));
1952}
1953
1954void MipsAssembler::MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1955 CHECK(HasMsa());
1956 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x12),
1957 static_cast<FRegister>(wd),
1958 static_cast<FRegister>(ws),
1959 static_cast<FRegister>(wt));
1960}
1961
1962void MipsAssembler::MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1963 CHECK(HasMsa());
1964 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x12),
1965 static_cast<FRegister>(wd),
1966 static_cast<FRegister>(ws),
1967 static_cast<FRegister>(wt));
1968}
1969
1970void MipsAssembler::MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1971 CHECK(HasMsa());
1972 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x12),
1973 static_cast<FRegister>(wd),
1974 static_cast<FRegister>(ws),
1975 static_cast<FRegister>(wt));
1976}
1977
1978void MipsAssembler::Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1979 CHECK(HasMsa());
1980 DsFsmInstrFff(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x12),
1981 static_cast<FRegister>(wd),
1982 static_cast<FRegister>(ws),
1983 static_cast<FRegister>(wt));
1984}
1985
1986void MipsAssembler::Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1987 CHECK(HasMsa());
1988 DsFsmInstrFff(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x12),
1989 static_cast<FRegister>(wd),
1990 static_cast<FRegister>(ws),
1991 static_cast<FRegister>(wt));
1992}
1993
1994void MipsAssembler::Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1995 CHECK(HasMsa());
1996 DsFsmInstrFff(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x12),
1997 static_cast<FRegister>(wd),
1998 static_cast<FRegister>(ws),
1999 static_cast<FRegister>(wt));
2000}
2001
2002void MipsAssembler::Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2003 CHECK(HasMsa());
2004 DsFsmInstrFff(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x12),
2005 static_cast<FRegister>(wd),
2006 static_cast<FRegister>(ws),
2007 static_cast<FRegister>(wt));
2008}
2009
2010void MipsAssembler::Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2011 CHECK(HasMsa());
2012 DsFsmInstrFff(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x12),
2013 static_cast<FRegister>(wd),
2014 static_cast<FRegister>(ws),
2015 static_cast<FRegister>(wt));
2016}
2017
2018void MipsAssembler::Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2019 CHECK(HasMsa());
2020 DsFsmInstrFff(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x12),
2021 static_cast<FRegister>(wd),
2022 static_cast<FRegister>(ws),
2023 static_cast<FRegister>(wt));
2024}
2025
2026void MipsAssembler::Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2027 CHECK(HasMsa());
2028 DsFsmInstrFff(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x12),
2029 static_cast<FRegister>(wd),
2030 static_cast<FRegister>(ws),
2031 static_cast<FRegister>(wt));
2032}
2033
2034void MipsAssembler::Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2035 CHECK(HasMsa());
2036 DsFsmInstrFff(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x12),
2037 static_cast<FRegister>(wd),
2038 static_cast<FRegister>(ws),
2039 static_cast<FRegister>(wt));
2040}
2041
2042void MipsAssembler::Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2043 CHECK(HasMsa());
2044 DsFsmInstrFff(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x12),
2045 static_cast<FRegister>(wd),
2046 static_cast<FRegister>(ws),
2047 static_cast<FRegister>(wt));
2048}
2049
2050void MipsAssembler::Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2051 CHECK(HasMsa());
2052 DsFsmInstrFff(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x12),
2053 static_cast<FRegister>(wd),
2054 static_cast<FRegister>(ws),
2055 static_cast<FRegister>(wt));
2056}
2057
2058void MipsAssembler::Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2059 CHECK(HasMsa());
2060 DsFsmInstrFff(EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x12),
2061 static_cast<FRegister>(wd),
2062 static_cast<FRegister>(ws),
2063 static_cast<FRegister>(wt));
2064}
2065
2066void MipsAssembler::Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2067 CHECK(HasMsa());
2068 DsFsmInstrFff(EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x12),
2069 static_cast<FRegister>(wd),
2070 static_cast<FRegister>(ws),
2071 static_cast<FRegister>(wt));
2072}
2073
2074void MipsAssembler::Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2075 CHECK(HasMsa());
2076 DsFsmInstrFff(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x12),
2077 static_cast<FRegister>(wd),
2078 static_cast<FRegister>(ws),
2079 static_cast<FRegister>(wt));
2080}
2081
2082void MipsAssembler::Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2083 CHECK(HasMsa());
2084 DsFsmInstrFff(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x12),
2085 static_cast<FRegister>(wd),
2086 static_cast<FRegister>(ws),
2087 static_cast<FRegister>(wt));
2088}
2089
2090void MipsAssembler::Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2091 CHECK(HasMsa());
2092 DsFsmInstrFff(EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x12),
2093 static_cast<FRegister>(wd),
2094 static_cast<FRegister>(ws),
2095 static_cast<FRegister>(wt));
2096}
2097
2098void MipsAssembler::Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2099 CHECK(HasMsa());
2100 DsFsmInstrFff(EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x12),
2101 static_cast<FRegister>(wd),
2102 static_cast<FRegister>(ws),
2103 static_cast<FRegister>(wt));
2104}
2105
2106void MipsAssembler::Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2107 CHECK(HasMsa());
2108 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x10),
2109 static_cast<FRegister>(wd),
2110 static_cast<FRegister>(ws),
2111 static_cast<FRegister>(wt));
2112}
2113
2114void MipsAssembler::Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2115 CHECK(HasMsa());
2116 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x10),
2117 static_cast<FRegister>(wd),
2118 static_cast<FRegister>(ws),
2119 static_cast<FRegister>(wt));
2120}
2121
2122void MipsAssembler::Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2123 CHECK(HasMsa());
2124 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x10),
2125 static_cast<FRegister>(wd),
2126 static_cast<FRegister>(ws),
2127 static_cast<FRegister>(wt));
2128}
2129
2130void MipsAssembler::Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2131 CHECK(HasMsa());
2132 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x10),
2133 static_cast<FRegister>(wd),
2134 static_cast<FRegister>(ws),
2135 static_cast<FRegister>(wt));
2136}
2137
2138void MipsAssembler::Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2139 CHECK(HasMsa());
2140 DsFsmInstrFff(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x10),
2141 static_cast<FRegister>(wd),
2142 static_cast<FRegister>(ws),
2143 static_cast<FRegister>(wt));
2144}
2145
2146void MipsAssembler::Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2147 CHECK(HasMsa());
2148 DsFsmInstrFff(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x10),
2149 static_cast<FRegister>(wd),
2150 static_cast<FRegister>(ws),
2151 static_cast<FRegister>(wt));
2152}
2153
2154void MipsAssembler::Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2155 CHECK(HasMsa());
2156 DsFsmInstrFff(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x10),
2157 static_cast<FRegister>(wd),
2158 static_cast<FRegister>(ws),
2159 static_cast<FRegister>(wt));
2160}
2161
2162void MipsAssembler::Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2163 CHECK(HasMsa());
2164 DsFsmInstrFff(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x10),
2165 static_cast<FRegister>(wd),
2166 static_cast<FRegister>(ws),
2167 static_cast<FRegister>(wt));
2168}
2169
2170void MipsAssembler::Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2171 CHECK(HasMsa());
2172 DsFsmInstrFff(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x10),
2173 static_cast<FRegister>(wd),
2174 static_cast<FRegister>(ws),
2175 static_cast<FRegister>(wt));
2176}
2177
2178void MipsAssembler::Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2179 CHECK(HasMsa());
2180 DsFsmInstrFff(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x10),
2181 static_cast<FRegister>(wd),
2182 static_cast<FRegister>(ws),
2183 static_cast<FRegister>(wt));
2184}
2185
2186void MipsAssembler::Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2187 CHECK(HasMsa());
2188 DsFsmInstrFff(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x10),
2189 static_cast<FRegister>(wd),
2190 static_cast<FRegister>(ws),
2191 static_cast<FRegister>(wt));
2192}
2193
2194void MipsAssembler::Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2195 CHECK(HasMsa());
2196 DsFsmInstrFff(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x10),
2197 static_cast<FRegister>(wd),
2198 static_cast<FRegister>(ws),
2199 static_cast<FRegister>(wt));
2200}
2201
2202void MipsAssembler::Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2203 CHECK(HasMsa());
2204 DsFsmInstrFff(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x10),
2205 static_cast<FRegister>(wd),
2206 static_cast<FRegister>(ws),
2207 static_cast<FRegister>(wt));
2208}
2209
2210void MipsAssembler::Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2211 CHECK(HasMsa());
2212 DsFsmInstrFff(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x10),
2213 static_cast<FRegister>(wd),
2214 static_cast<FRegister>(ws),
2215 static_cast<FRegister>(wt));
2216}
2217
2218void MipsAssembler::Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2219 CHECK(HasMsa());
2220 DsFsmInstrFff(EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x10),
2221 static_cast<FRegister>(wd),
2222 static_cast<FRegister>(ws),
2223 static_cast<FRegister>(wt));
2224}
2225
2226void MipsAssembler::Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2227 CHECK(HasMsa());
2228 DsFsmInstrFff(EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x10),
2229 static_cast<FRegister>(wd),
2230 static_cast<FRegister>(ws),
2231 static_cast<FRegister>(wt));
2232}
2233
2234void MipsAssembler::Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2235 CHECK(HasMsa());
2236 DsFsmInstrFff(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x10),
2237 static_cast<FRegister>(wd),
2238 static_cast<FRegister>(ws),
2239 static_cast<FRegister>(wt));
2240}
2241
2242void MipsAssembler::Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2243 CHECK(HasMsa());
2244 DsFsmInstrFff(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x10),
2245 static_cast<FRegister>(wd),
2246 static_cast<FRegister>(ws),
2247 static_cast<FRegister>(wt));
2248}
2249
2250void MipsAssembler::Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2251 CHECK(HasMsa());
2252 DsFsmInstrFff(EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x10),
2253 static_cast<FRegister>(wd),
2254 static_cast<FRegister>(ws),
2255 static_cast<FRegister>(wt));
2256}
2257
2258void MipsAssembler::Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2259 CHECK(HasMsa());
2260 DsFsmInstrFff(EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x10),
2261 static_cast<FRegister>(wd),
2262 static_cast<FRegister>(ws),
2263 static_cast<FRegister>(wt));
2264}
2265
2266void MipsAssembler::Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2267 CHECK(HasMsa());
2268 DsFsmInstrFff(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xe),
2269 static_cast<FRegister>(wd),
2270 static_cast<FRegister>(ws),
2271 static_cast<FRegister>(wt));
2272}
2273
2274void MipsAssembler::Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2275 CHECK(HasMsa());
2276 DsFsmInstrFff(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xe),
2277 static_cast<FRegister>(wd),
2278 static_cast<FRegister>(ws),
2279 static_cast<FRegister>(wt));
2280}
2281
2282void MipsAssembler::Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2283 CHECK(HasMsa());
2284 DsFsmInstrFff(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xe),
2285 static_cast<FRegister>(wd),
2286 static_cast<FRegister>(ws),
2287 static_cast<FRegister>(wt));
2288}
2289
2290void MipsAssembler::Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2291 CHECK(HasMsa());
2292 DsFsmInstrFff(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xe),
2293 static_cast<FRegister>(wd),
2294 static_cast<FRegister>(ws),
2295 static_cast<FRegister>(wt));
2296}
2297
2298void MipsAssembler::Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2299 CHECK(HasMsa());
2300 DsFsmInstrFff(EmitMsa3R(0x3, 0x0, wt, ws, wd, 0xe),
2301 static_cast<FRegister>(wd),
2302 static_cast<FRegister>(ws),
2303 static_cast<FRegister>(wt));
2304}
2305
2306void MipsAssembler::Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2307 CHECK(HasMsa());
2308 DsFsmInstrFff(EmitMsa3R(0x3, 0x1, wt, ws, wd, 0xe),
2309 static_cast<FRegister>(wd),
2310 static_cast<FRegister>(ws),
2311 static_cast<FRegister>(wt));
2312}
2313
2314void MipsAssembler::Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2315 CHECK(HasMsa());
2316 DsFsmInstrFff(EmitMsa3R(0x3, 0x2, wt, ws, wd, 0xe),
2317 static_cast<FRegister>(wd),
2318 static_cast<FRegister>(ws),
2319 static_cast<FRegister>(wt));
2320}
2321
2322void MipsAssembler::Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2323 CHECK(HasMsa());
2324 DsFsmInstrFff(EmitMsa3R(0x3, 0x3, wt, ws, wd, 0xe),
2325 static_cast<FRegister>(wd),
2326 static_cast<FRegister>(ws),
2327 static_cast<FRegister>(wt));
2328}
2329
2330void MipsAssembler::Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2331 CHECK(HasMsa());
2332 DsFsmInstrFff(EmitMsa3R(0x4, 0x0, wt, ws, wd, 0xe),
2333 static_cast<FRegister>(wd),
2334 static_cast<FRegister>(ws),
2335 static_cast<FRegister>(wt));
2336}
2337
2338void MipsAssembler::Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2339 CHECK(HasMsa());
2340 DsFsmInstrFff(EmitMsa3R(0x4, 0x1, wt, ws, wd, 0xe),
2341 static_cast<FRegister>(wd),
2342 static_cast<FRegister>(ws),
2343 static_cast<FRegister>(wt));
2344}
2345
2346void MipsAssembler::Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2347 CHECK(HasMsa());
2348 DsFsmInstrFff(EmitMsa3R(0x4, 0x2, wt, ws, wd, 0xe),
2349 static_cast<FRegister>(wd),
2350 static_cast<FRegister>(ws),
2351 static_cast<FRegister>(wt));
2352}
2353
2354void MipsAssembler::Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2355 CHECK(HasMsa());
2356 DsFsmInstrFff(EmitMsa3R(0x4, 0x3, wt, ws, wd, 0xe),
2357 static_cast<FRegister>(wd),
2358 static_cast<FRegister>(ws),
2359 static_cast<FRegister>(wt));
2360}
2361
2362void MipsAssembler::Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2363 CHECK(HasMsa());
2364 DsFsmInstrFff(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0xe),
2365 static_cast<FRegister>(wd),
2366 static_cast<FRegister>(ws),
2367 static_cast<FRegister>(wt));
2368}
2369
2370void MipsAssembler::Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2371 CHECK(HasMsa());
2372 DsFsmInstrFff(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0xe),
2373 static_cast<FRegister>(wd),
2374 static_cast<FRegister>(ws),
2375 static_cast<FRegister>(wt));
2376}
2377
2378void MipsAssembler::Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2379 CHECK(HasMsa());
2380 DsFsmInstrFff(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0xe),
2381 static_cast<FRegister>(wd),
2382 static_cast<FRegister>(ws),
2383 static_cast<FRegister>(wt));
2384}
2385
2386void MipsAssembler::Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2387 CHECK(HasMsa());
2388 DsFsmInstrFff(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0xe),
2389 static_cast<FRegister>(wd),
2390 static_cast<FRegister>(ws),
2391 static_cast<FRegister>(wt));
2392}
2393
2394void MipsAssembler::FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2395 CHECK(HasMsa());
2396 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1b),
2397 static_cast<FRegister>(wd),
2398 static_cast<FRegister>(ws),
2399 static_cast<FRegister>(wt));
2400}
2401
2402void MipsAssembler::FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2403 CHECK(HasMsa());
2404 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1b),
2405 static_cast<FRegister>(wd),
2406 static_cast<FRegister>(ws),
2407 static_cast<FRegister>(wt));
2408}
2409
2410void MipsAssembler::FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2411 CHECK(HasMsa());
2412 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1b),
2413 static_cast<FRegister>(wd),
2414 static_cast<FRegister>(ws),
2415 static_cast<FRegister>(wt));
2416}
2417
2418void MipsAssembler::FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2419 CHECK(HasMsa());
2420 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1b),
2421 static_cast<FRegister>(wd),
2422 static_cast<FRegister>(ws),
2423 static_cast<FRegister>(wt));
2424}
2425
2426void MipsAssembler::FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2427 CHECK(HasMsa());
2428 DsFsmInstrFff(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x1b),
2429 static_cast<FRegister>(wd),
2430 static_cast<FRegister>(ws),
2431 static_cast<FRegister>(wt));
2432}
2433
2434void MipsAssembler::FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2435 CHECK(HasMsa());
2436 DsFsmInstrFff(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x1b),
2437 static_cast<FRegister>(wd),
2438 static_cast<FRegister>(ws),
2439 static_cast<FRegister>(wt));
2440}
2441
2442void MipsAssembler::FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2443 CHECK(HasMsa());
2444 DsFsmInstrFff(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x1b),
2445 static_cast<FRegister>(wd),
2446 static_cast<FRegister>(ws),
2447 static_cast<FRegister>(wt));
2448}
2449
2450void MipsAssembler::FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2451 CHECK(HasMsa());
2452 DsFsmInstrFff(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x1b),
2453 static_cast<FRegister>(wd),
2454 static_cast<FRegister>(ws),
2455 static_cast<FRegister>(wt));
2456}
2457
2458void MipsAssembler::FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2459 CHECK(HasMsa());
2460 DsFsmInstrFff(EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x1b),
2461 static_cast<FRegister>(wd),
2462 static_cast<FRegister>(ws),
2463 static_cast<FRegister>(wt));
2464}
2465
2466void MipsAssembler::FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2467 CHECK(HasMsa());
2468 DsFsmInstrFff(EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x1b),
2469 static_cast<FRegister>(wd),
2470 static_cast<FRegister>(ws),
2471 static_cast<FRegister>(wt));
2472}
2473
2474void MipsAssembler::FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2475 CHECK(HasMsa());
2476 DsFsmInstrFff(EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x1b),
2477 static_cast<FRegister>(wd),
2478 static_cast<FRegister>(ws),
2479 static_cast<FRegister>(wt));
2480}
2481
2482void MipsAssembler::FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2483 CHECK(HasMsa());
2484 DsFsmInstrFff(EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x1b),
2485 static_cast<FRegister>(wd),
2486 static_cast<FRegister>(ws),
2487 static_cast<FRegister>(wt));
2488}
2489
2490void MipsAssembler::Ffint_sW(VectorRegister wd, VectorRegister ws) {
2491 CHECK(HasMsa());
2492 DsFsmInstrFff(EmitMsa2RF(0x19e, 0x0, ws, wd, 0x1e),
2493 static_cast<FRegister>(wd),
2494 static_cast<FRegister>(ws),
2495 static_cast<FRegister>(ws));
2496}
2497
2498void MipsAssembler::Ffint_sD(VectorRegister wd, VectorRegister ws) {
2499 CHECK(HasMsa());
2500 DsFsmInstrFff(EmitMsa2RF(0x19e, 0x1, ws, wd, 0x1e),
2501 static_cast<FRegister>(wd),
2502 static_cast<FRegister>(ws),
2503 static_cast<FRegister>(ws));
2504}
2505
2506void MipsAssembler::Ftint_sW(VectorRegister wd, VectorRegister ws) {
2507 CHECK(HasMsa());
2508 DsFsmInstrFff(EmitMsa2RF(0x19c, 0x0, ws, wd, 0x1e),
2509 static_cast<FRegister>(wd),
2510 static_cast<FRegister>(ws),
2511 static_cast<FRegister>(ws));
2512}
2513
2514void MipsAssembler::Ftint_sD(VectorRegister wd, VectorRegister ws) {
2515 CHECK(HasMsa());
2516 DsFsmInstrFff(EmitMsa2RF(0x19c, 0x1, ws, wd, 0x1e),
2517 static_cast<FRegister>(wd),
2518 static_cast<FRegister>(ws),
2519 static_cast<FRegister>(ws));
2520}
2521
2522void MipsAssembler::SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2523 CHECK(HasMsa());
2524 DsFsmInstrFff(EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xd),
2525 static_cast<FRegister>(wd),
2526 static_cast<FRegister>(ws),
2527 static_cast<FRegister>(wt));
2528}
2529
2530void MipsAssembler::SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2531 CHECK(HasMsa());
2532 DsFsmInstrFff(EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xd),
2533 static_cast<FRegister>(wd),
2534 static_cast<FRegister>(ws),
2535 static_cast<FRegister>(wt));
2536}
2537
2538void MipsAssembler::SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2539 CHECK(HasMsa());
2540 DsFsmInstrFff(EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xd),
2541 static_cast<FRegister>(wd),
2542 static_cast<FRegister>(ws),
2543 static_cast<FRegister>(wt));
2544}
2545
2546void MipsAssembler::SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2547 CHECK(HasMsa());
2548 DsFsmInstrFff(EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xd),
2549 static_cast<FRegister>(wd),
2550 static_cast<FRegister>(ws),
2551 static_cast<FRegister>(wt));
2552}
2553
2554void MipsAssembler::SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2555 CHECK(HasMsa());
2556 DsFsmInstrFff(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xd),
2557 static_cast<FRegister>(wd),
2558 static_cast<FRegister>(ws),
2559 static_cast<FRegister>(wt));
2560}
2561
2562void MipsAssembler::SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2563 CHECK(HasMsa());
2564 DsFsmInstrFff(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xd),
2565 static_cast<FRegister>(wd),
2566 static_cast<FRegister>(ws),
2567 static_cast<FRegister>(wt));
2568}
2569
2570void MipsAssembler::SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2571 CHECK(HasMsa());
2572 DsFsmInstrFff(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xd),
2573 static_cast<FRegister>(wd),
2574 static_cast<FRegister>(ws),
2575 static_cast<FRegister>(wt));
2576}
2577
2578void MipsAssembler::SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2579 CHECK(HasMsa());
2580 DsFsmInstrFff(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xd),
2581 static_cast<FRegister>(wd),
2582 static_cast<FRegister>(ws),
2583 static_cast<FRegister>(wt));
2584}
2585
2586void MipsAssembler::SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2587 CHECK(HasMsa());
2588 DsFsmInstrFff(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xd),
2589 static_cast<FRegister>(wd),
2590 static_cast<FRegister>(ws),
2591 static_cast<FRegister>(wt));
2592}
2593
2594void MipsAssembler::SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2595 CHECK(HasMsa());
2596 DsFsmInstrFff(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xd),
2597 static_cast<FRegister>(wd),
2598 static_cast<FRegister>(ws),
2599 static_cast<FRegister>(wt));
2600}
2601
2602void MipsAssembler::SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2603 CHECK(HasMsa());
2604 DsFsmInstrFff(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xd),
2605 static_cast<FRegister>(wd),
2606 static_cast<FRegister>(ws),
2607 static_cast<FRegister>(wt));
2608}
2609
2610void MipsAssembler::SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2611 CHECK(HasMsa());
2612 DsFsmInstrFff(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xd),
2613 static_cast<FRegister>(wd),
2614 static_cast<FRegister>(ws),
2615 static_cast<FRegister>(wt));
2616}
2617
2618void MipsAssembler::SlliB(VectorRegister wd, VectorRegister ws, int shamt3) {
2619 CHECK(HasMsa());
2620 CHECK(IsUint<3>(shamt3)) << shamt3;
2621 DsFsmInstrFff(EmitMsaBIT(0x0, shamt3 | kMsaDfMByteMask, ws, wd, 0x9),
2622 static_cast<FRegister>(wd),
2623 static_cast<FRegister>(ws),
2624 static_cast<FRegister>(ws));
2625}
2626
2627void MipsAssembler::SlliH(VectorRegister wd, VectorRegister ws, int shamt4) {
2628 CHECK(HasMsa());
2629 CHECK(IsUint<4>(shamt4)) << shamt4;
2630 DsFsmInstrFff(EmitMsaBIT(0x0, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9),
2631 static_cast<FRegister>(wd),
2632 static_cast<FRegister>(ws),
2633 static_cast<FRegister>(ws));
2634}
2635
2636void MipsAssembler::SlliW(VectorRegister wd, VectorRegister ws, int shamt5) {
2637 CHECK(HasMsa());
2638 CHECK(IsUint<5>(shamt5)) << shamt5;
2639 DsFsmInstrFff(EmitMsaBIT(0x0, shamt5 | kMsaDfMWordMask, ws, wd, 0x9),
2640 static_cast<FRegister>(wd),
2641 static_cast<FRegister>(ws),
2642 static_cast<FRegister>(ws));
2643}
2644
2645void MipsAssembler::SlliD(VectorRegister wd, VectorRegister ws, int shamt6) {
2646 CHECK(HasMsa());
2647 CHECK(IsUint<6>(shamt6)) << shamt6;
2648 DsFsmInstrFff(EmitMsaBIT(0x0, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9),
2649 static_cast<FRegister>(wd),
2650 static_cast<FRegister>(ws),
2651 static_cast<FRegister>(ws));
2652}
2653
2654void MipsAssembler::SraiB(VectorRegister wd, VectorRegister ws, int shamt3) {
2655 CHECK(HasMsa());
2656 CHECK(IsUint<3>(shamt3)) << shamt3;
2657 DsFsmInstrFff(EmitMsaBIT(0x1, shamt3 | kMsaDfMByteMask, ws, wd, 0x9),
2658 static_cast<FRegister>(wd),
2659 static_cast<FRegister>(ws),
2660 static_cast<FRegister>(ws));
2661}
2662
2663void MipsAssembler::SraiH(VectorRegister wd, VectorRegister ws, int shamt4) {
2664 CHECK(HasMsa());
2665 CHECK(IsUint<4>(shamt4)) << shamt4;
2666 DsFsmInstrFff(EmitMsaBIT(0x1, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9),
2667 static_cast<FRegister>(wd),
2668 static_cast<FRegister>(ws),
2669 static_cast<FRegister>(ws));
2670}
2671
2672void MipsAssembler::SraiW(VectorRegister wd, VectorRegister ws, int shamt5) {
2673 CHECK(HasMsa());
2674 CHECK(IsUint<5>(shamt5)) << shamt5;
2675 DsFsmInstrFff(EmitMsaBIT(0x1, shamt5 | kMsaDfMWordMask, ws, wd, 0x9),
2676 static_cast<FRegister>(wd),
2677 static_cast<FRegister>(ws),
2678 static_cast<FRegister>(ws));
2679}
2680
2681void MipsAssembler::SraiD(VectorRegister wd, VectorRegister ws, int shamt6) {
2682 CHECK(HasMsa());
2683 CHECK(IsUint<6>(shamt6)) << shamt6;
2684 DsFsmInstrFff(EmitMsaBIT(0x1, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9),
2685 static_cast<FRegister>(wd),
2686 static_cast<FRegister>(ws),
2687 static_cast<FRegister>(ws));
2688}
2689
2690void MipsAssembler::SrliB(VectorRegister wd, VectorRegister ws, int shamt3) {
2691 CHECK(HasMsa());
2692 CHECK(IsUint<3>(shamt3)) << shamt3;
2693 DsFsmInstrFff(EmitMsaBIT(0x2, shamt3 | kMsaDfMByteMask, ws, wd, 0x9),
2694 static_cast<FRegister>(wd),
2695 static_cast<FRegister>(ws),
2696 static_cast<FRegister>(ws));
2697}
2698
2699void MipsAssembler::SrliH(VectorRegister wd, VectorRegister ws, int shamt4) {
2700 CHECK(HasMsa());
2701 CHECK(IsUint<4>(shamt4)) << shamt4;
2702 DsFsmInstrFff(EmitMsaBIT(0x2, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9),
2703 static_cast<FRegister>(wd),
2704 static_cast<FRegister>(ws),
2705 static_cast<FRegister>(ws));
2706}
2707
2708void MipsAssembler::SrliW(VectorRegister wd, VectorRegister ws, int shamt5) {
2709 CHECK(HasMsa());
2710 CHECK(IsUint<5>(shamt5)) << shamt5;
2711 DsFsmInstrFff(EmitMsaBIT(0x2, shamt5 | kMsaDfMWordMask, ws, wd, 0x9),
2712 static_cast<FRegister>(wd),
2713 static_cast<FRegister>(ws),
2714 static_cast<FRegister>(ws));
2715}
2716
2717void MipsAssembler::SrliD(VectorRegister wd, VectorRegister ws, int shamt6) {
2718 CHECK(HasMsa());
2719 CHECK(IsUint<6>(shamt6)) << shamt6;
2720 DsFsmInstrFff(EmitMsaBIT(0x2, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9),
2721 static_cast<FRegister>(wd),
2722 static_cast<FRegister>(ws),
2723 static_cast<FRegister>(ws));
2724}
2725
2726void MipsAssembler::MoveV(VectorRegister wd, VectorRegister ws) {
2727 CHECK(HasMsa());
2728 DsFsmInstrFff(EmitMsaBIT(0x1, 0x3e, ws, wd, 0x19),
2729 static_cast<FRegister>(wd),
2730 static_cast<FRegister>(ws),
2731 static_cast<FRegister>(ws));
2732}
2733
2734void MipsAssembler::SplatiB(VectorRegister wd, VectorRegister ws, int n4) {
2735 CHECK(HasMsa());
2736 CHECK(IsUint<4>(n4)) << n4;
2737 DsFsmInstrFff(EmitMsaELM(0x1, n4 | kMsaDfNByteMask, ws, wd, 0x19),
2738 static_cast<FRegister>(wd),
2739 static_cast<FRegister>(ws),
2740 static_cast<FRegister>(ws));
2741}
2742
2743void MipsAssembler::SplatiH(VectorRegister wd, VectorRegister ws, int n3) {
2744 CHECK(HasMsa());
2745 CHECK(IsUint<3>(n3)) << n3;
2746 DsFsmInstrFff(EmitMsaELM(0x1, n3 | kMsaDfNHalfwordMask, ws, wd, 0x19),
2747 static_cast<FRegister>(wd),
2748 static_cast<FRegister>(ws),
2749 static_cast<FRegister>(ws));
2750}
2751
2752void MipsAssembler::SplatiW(VectorRegister wd, VectorRegister ws, int n2) {
2753 CHECK(HasMsa());
2754 CHECK(IsUint<2>(n2)) << n2;
2755 DsFsmInstrFff(EmitMsaELM(0x1, n2 | kMsaDfNWordMask, ws, wd, 0x19),
2756 static_cast<FRegister>(wd),
2757 static_cast<FRegister>(ws),
2758 static_cast<FRegister>(ws));
2759}
2760
2761void MipsAssembler::SplatiD(VectorRegister wd, VectorRegister ws, int n1) {
2762 CHECK(HasMsa());
2763 CHECK(IsUint<1>(n1)) << n1;
2764 DsFsmInstrFff(EmitMsaELM(0x1, n1 | kMsaDfNDoublewordMask, ws, wd, 0x19),
2765 static_cast<FRegister>(wd),
2766 static_cast<FRegister>(ws),
2767 static_cast<FRegister>(ws));
2768}
2769
2770void MipsAssembler::FillB(VectorRegister wd, Register rs) {
2771 CHECK(HasMsa());
2772 DsFsmInstrFr(EmitMsa2R(0xc0, 0x0, static_cast<VectorRegister>(rs), wd, 0x1e),
2773 static_cast<FRegister>(wd),
2774 rs);
2775}
2776
2777void MipsAssembler::FillH(VectorRegister wd, Register rs) {
2778 CHECK(HasMsa());
2779 DsFsmInstrFr(EmitMsa2R(0xc0, 0x1, static_cast<VectorRegister>(rs), wd, 0x1e),
2780 static_cast<FRegister>(wd),
2781 rs);
2782}
2783
2784void MipsAssembler::FillW(VectorRegister wd, Register rs) {
2785 CHECK(HasMsa());
2786 DsFsmInstrFr(EmitMsa2R(0xc0, 0x2, static_cast<VectorRegister>(rs), wd, 0x1e),
2787 static_cast<FRegister>(wd),
2788 rs);
2789}
2790
2791void MipsAssembler::LdiB(VectorRegister wd, int imm8) {
2792 CHECK(HasMsa());
2793 CHECK(IsInt<8>(imm8)) << imm8;
2794 DsFsmInstrFr(EmitMsaI10(0x6, 0x0, imm8 & kMsaS10Mask, wd, 0x7),
2795 static_cast<FRegister>(wd),
2796 ZERO);
2797}
2798
2799void MipsAssembler::LdiH(VectorRegister wd, int imm10) {
2800 CHECK(HasMsa());
2801 CHECK(IsInt<10>(imm10)) << imm10;
2802 DsFsmInstrFr(EmitMsaI10(0x6, 0x1, imm10 & kMsaS10Mask, wd, 0x7),
2803 static_cast<FRegister>(wd),
2804 ZERO);
2805}
2806
2807void MipsAssembler::LdiW(VectorRegister wd, int imm10) {
2808 CHECK(HasMsa());
2809 CHECK(IsInt<10>(imm10)) << imm10;
2810 DsFsmInstrFr(EmitMsaI10(0x6, 0x2, imm10 & kMsaS10Mask, wd, 0x7),
2811 static_cast<FRegister>(wd),
2812 ZERO);
2813}
2814
2815void MipsAssembler::LdiD(VectorRegister wd, int imm10) {
2816 CHECK(HasMsa());
2817 CHECK(IsInt<10>(imm10)) << imm10;
2818 DsFsmInstrFr(EmitMsaI10(0x6, 0x3, imm10 & kMsaS10Mask, wd, 0x7),
2819 static_cast<FRegister>(wd),
2820 ZERO);
2821}
2822
2823void MipsAssembler::LdB(VectorRegister wd, Register rs, int offset) {
2824 CHECK(HasMsa());
2825 CHECK(IsInt<10>(offset)) << offset;
2826 DsFsmInstrFr(EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x8, 0x0),
2827 static_cast<FRegister>(wd),
2828 rs);
2829}
2830
2831void MipsAssembler::LdH(VectorRegister wd, Register rs, int offset) {
2832 CHECK(HasMsa());
2833 CHECK(IsInt<11>(offset)) << offset;
2834 CHECK_ALIGNED(offset, kMipsHalfwordSize);
2835 DsFsmInstrFr(EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x8, 0x1),
2836 static_cast<FRegister>(wd),
2837 rs);
2838}
2839
2840void MipsAssembler::LdW(VectorRegister wd, Register rs, int offset) {
2841 CHECK(HasMsa());
2842 CHECK(IsInt<12>(offset)) << offset;
2843 CHECK_ALIGNED(offset, kMipsWordSize);
2844 DsFsmInstrFr(EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x8, 0x2),
2845 static_cast<FRegister>(wd),
2846 rs);
2847}
2848
2849void MipsAssembler::LdD(VectorRegister wd, Register rs, int offset) {
2850 CHECK(HasMsa());
2851 CHECK(IsInt<13>(offset)) << offset;
2852 CHECK_ALIGNED(offset, kMipsDoublewordSize);
2853 DsFsmInstrFr(EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x8, 0x3),
2854 static_cast<FRegister>(wd),
2855 rs);
2856}
2857
2858void MipsAssembler::StB(VectorRegister wd, Register rs, int offset) {
2859 CHECK(HasMsa());
2860 CHECK(IsInt<10>(offset)) << offset;
2861 DsFsmInstrFR(EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x9, 0x0), static_cast<FRegister>(wd), rs);
2862}
2863
2864void MipsAssembler::StH(VectorRegister wd, Register rs, int offset) {
2865 CHECK(HasMsa());
2866 CHECK(IsInt<11>(offset)) << offset;
2867 CHECK_ALIGNED(offset, kMipsHalfwordSize);
2868 DsFsmInstrFR(EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x9, 0x1),
2869 static_cast<FRegister>(wd),
2870 rs);
2871}
2872
2873void MipsAssembler::StW(VectorRegister wd, Register rs, int offset) {
2874 CHECK(HasMsa());
2875 CHECK(IsInt<12>(offset)) << offset;
2876 CHECK_ALIGNED(offset, kMipsWordSize);
2877 DsFsmInstrFR(EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x9, 0x2),
2878 static_cast<FRegister>(wd),
2879 rs);
2880}
2881
2882void MipsAssembler::StD(VectorRegister wd, Register rs, int offset) {
2883 CHECK(HasMsa());
2884 CHECK(IsInt<13>(offset)) << offset;
2885 CHECK_ALIGNED(offset, kMipsDoublewordSize);
2886 DsFsmInstrFR(EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x9, 0x3),
2887 static_cast<FRegister>(wd),
2888 rs);
2889}
2890
2891void MipsAssembler::IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2892 CHECK(HasMsa());
2893 DsFsmInstrFff(EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x14),
2894 static_cast<FRegister>(wd),
2895 static_cast<FRegister>(ws),
2896 static_cast<FRegister>(wt));
2897}
2898
2899void MipsAssembler::IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2900 CHECK(HasMsa());
2901 DsFsmInstrFff(EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x14),
2902 static_cast<FRegister>(wd),
2903 static_cast<FRegister>(ws),
2904 static_cast<FRegister>(wt));
2905}
2906
2907void MipsAssembler::IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2908 CHECK(HasMsa());
2909 DsFsmInstrFff(EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x14),
2910 static_cast<FRegister>(wd),
2911 static_cast<FRegister>(ws),
2912 static_cast<FRegister>(wt));
2913}
2914
2915void MipsAssembler::IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2916 CHECK(HasMsa());
2917 DsFsmInstrFff(EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x14),
2918 static_cast<FRegister>(wd),
2919 static_cast<FRegister>(ws),
2920 static_cast<FRegister>(wt));
2921}
2922
Lena Djokicb3d79e42017-07-25 11:20:52 +02002923void MipsAssembler::MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2924 CHECK(HasMsa());
2925 DsFsmInstrFff(EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x12),
2926 static_cast<FRegister>(wd),
2927 static_cast<FRegister>(ws),
2928 static_cast<FRegister>(wt));
2929}
2930
2931void MipsAssembler::MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2932 CHECK(HasMsa());
2933 DsFsmInstrFff(EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x12),
2934 static_cast<FRegister>(wd),
2935 static_cast<FRegister>(ws),
2936 static_cast<FRegister>(wt));
2937}
2938
2939void MipsAssembler::MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2940 CHECK(HasMsa());
2941 DsFsmInstrFff(EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x12),
2942 static_cast<FRegister>(wd),
2943 static_cast<FRegister>(ws),
2944 static_cast<FRegister>(wt));
2945}
2946
2947void MipsAssembler::MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2948 CHECK(HasMsa());
2949 DsFsmInstrFff(EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x12),
2950 static_cast<FRegister>(wd),
2951 static_cast<FRegister>(ws),
2952 static_cast<FRegister>(wt));
2953}
2954
2955void MipsAssembler::MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2956 CHECK(HasMsa());
2957 DsFsmInstrFff(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x12),
2958 static_cast<FRegister>(wd),
2959 static_cast<FRegister>(ws),
2960 static_cast<FRegister>(wt));
2961}
2962
2963void MipsAssembler::MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2964 CHECK(HasMsa());
2965 DsFsmInstrFff(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x12),
2966 static_cast<FRegister>(wd),
2967 static_cast<FRegister>(ws),
2968 static_cast<FRegister>(wt));
2969}
2970
2971void MipsAssembler::MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2972 CHECK(HasMsa());
2973 DsFsmInstrFff(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x12),
2974 static_cast<FRegister>(wd),
2975 static_cast<FRegister>(ws),
2976 static_cast<FRegister>(wt));
2977}
2978
2979void MipsAssembler::MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2980 CHECK(HasMsa());
2981 DsFsmInstrFff(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x12),
2982 static_cast<FRegister>(wd),
2983 static_cast<FRegister>(ws),
2984 static_cast<FRegister>(wt));
2985}
2986
2987void MipsAssembler::FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2988 CHECK(HasMsa());
2989 DsFsmInstrFff(EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x1b),
2990 static_cast<FRegister>(wd),
2991 static_cast<FRegister>(ws),
2992 static_cast<FRegister>(wt));
2993}
2994
2995void MipsAssembler::FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
2996 CHECK(HasMsa());
2997 DsFsmInstrFff(EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x1b),
2998 static_cast<FRegister>(wd),
2999 static_cast<FRegister>(ws),
3000 static_cast<FRegister>(wt));
3001}
3002
3003void MipsAssembler::FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
3004 CHECK(HasMsa());
3005 DsFsmInstrFff(EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x1b),
3006 static_cast<FRegister>(wd),
3007 static_cast<FRegister>(ws),
3008 static_cast<FRegister>(wt));
3009}
3010
3011void MipsAssembler::FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
3012 CHECK(HasMsa());
3013 DsFsmInstrFff(EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x1b),
3014 static_cast<FRegister>(wd),
3015 static_cast<FRegister>(ws),
3016 static_cast<FRegister>(wt));
3017}
3018
Lena Djokic51765b02017-06-22 13:49:59 +02003019void MipsAssembler::ReplicateFPToVectorRegister(VectorRegister dst,
3020 FRegister src,
3021 bool is_double) {
3022 // Float or double in FPU register Fx can be considered as 0th element in vector register Wx.
3023 if (is_double) {
3024 SplatiD(dst, static_cast<VectorRegister>(src), 0);
3025 } else {
3026 SplatiW(dst, static_cast<VectorRegister>(src), 0);
3027 }
3028}
3029
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003030void MipsAssembler::LoadConst32(Register rd, int32_t value) {
3031 if (IsUint<16>(value)) {
3032 // Use OR with (unsigned) immediate to encode 16b unsigned int.
3033 Ori(rd, ZERO, value);
3034 } else if (IsInt<16>(value)) {
3035 // Use ADD with (signed) immediate to encode 16b signed int.
3036 Addiu(rd, ZERO, value);
jeffhao7fbee072012-08-24 17:56:54 -07003037 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003038 Lui(rd, High16Bits(value));
3039 if (value & 0xFFFF)
3040 Ori(rd, rd, Low16Bits(value));
3041 }
3042}
3043
3044void MipsAssembler::LoadConst64(Register reg_hi, Register reg_lo, int64_t value) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08003045 uint32_t low = Low32Bits(value);
3046 uint32_t high = High32Bits(value);
3047 LoadConst32(reg_lo, low);
3048 if (high != low) {
3049 LoadConst32(reg_hi, high);
3050 } else {
3051 Move(reg_hi, reg_lo);
3052 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003053}
3054
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003055void MipsAssembler::LoadSConst32(FRegister r, int32_t value, Register temp) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08003056 if (value == 0) {
3057 temp = ZERO;
3058 } else {
3059 LoadConst32(temp, value);
3060 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003061 Mtc1(temp, r);
3062}
3063
3064void MipsAssembler::LoadDConst64(FRegister rd, int64_t value, Register temp) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08003065 uint32_t low = Low32Bits(value);
3066 uint32_t high = High32Bits(value);
3067 if (low == 0) {
3068 Mtc1(ZERO, rd);
3069 } else {
3070 LoadConst32(temp, low);
3071 Mtc1(temp, rd);
3072 }
3073 if (high == 0) {
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003074 MoveToFpuHigh(ZERO, rd);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08003075 } else {
3076 LoadConst32(temp, high);
Alexey Frunzebb9863a2016-01-11 15:51:16 -08003077 MoveToFpuHigh(temp, rd);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08003078 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003079}
3080
3081void MipsAssembler::Addiu32(Register rt, Register rs, int32_t value, Register temp) {
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07003082 CHECK_NE(rs, temp); // Must not overwrite the register `rs` while loading `value`.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003083 if (IsInt<16>(value)) {
3084 Addiu(rt, rs, value);
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07003085 } else if (IsR6()) {
3086 int16_t high = High16Bits(value);
3087 int16_t low = Low16Bits(value);
3088 high += (low < 0) ? 1 : 0; // Account for sign extension in addiu.
3089 if (low != 0) {
3090 Aui(temp, rs, high);
3091 Addiu(rt, temp, low);
3092 } else {
3093 Aui(rt, rs, high);
3094 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003095 } else {
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07003096 // Do not load the whole 32-bit `value` if it can be represented as
3097 // a sum of two 16-bit signed values. This can save an instruction.
3098 constexpr int32_t kMinValueForSimpleAdjustment = std::numeric_limits<int16_t>::min() * 2;
3099 constexpr int32_t kMaxValueForSimpleAdjustment = std::numeric_limits<int16_t>::max() * 2;
3100 if (0 <= value && value <= kMaxValueForSimpleAdjustment) {
3101 Addiu(temp, rs, kMaxValueForSimpleAdjustment / 2);
3102 Addiu(rt, temp, value - kMaxValueForSimpleAdjustment / 2);
3103 } else if (kMinValueForSimpleAdjustment <= value && value < 0) {
3104 Addiu(temp, rs, kMinValueForSimpleAdjustment / 2);
3105 Addiu(rt, temp, value - kMinValueForSimpleAdjustment / 2);
3106 } else {
3107 // Now that all shorter options have been exhausted, load the full 32-bit value.
3108 LoadConst32(temp, value);
3109 Addu(rt, rs, temp);
3110 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003111 }
3112}
3113
3114void MipsAssembler::Branch::InitShortOrLong(MipsAssembler::Branch::OffsetBits offset_size,
3115 MipsAssembler::Branch::Type short_type,
3116 MipsAssembler::Branch::Type long_type) {
3117 type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
3118}
3119
Alexey Frunze96b66822016-09-10 02:32:44 -07003120void MipsAssembler::Branch::InitializeType(Type initial_type, bool is_r6) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003121 OffsetBits offset_size = GetOffsetSizeNeeded(location_, target_);
3122 if (is_r6) {
3123 // R6
Alexey Frunze96b66822016-09-10 02:32:44 -07003124 switch (initial_type) {
3125 case kLabel:
3126 CHECK(!IsResolved());
3127 type_ = kR6Label;
3128 break;
3129 case kLiteral:
3130 CHECK(!IsResolved());
3131 type_ = kR6Literal;
3132 break;
3133 case kCall:
3134 InitShortOrLong(offset_size, kR6Call, kR6LongCall);
3135 break;
3136 case kCondBranch:
3137 switch (condition_) {
3138 case kUncond:
3139 InitShortOrLong(offset_size, kR6UncondBranch, kR6LongUncondBranch);
3140 break;
3141 case kCondEQZ:
3142 case kCondNEZ:
3143 // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
3144 type_ = (offset_size <= kOffset23) ? kR6CondBranch : kR6LongCondBranch;
3145 break;
3146 default:
3147 InitShortOrLong(offset_size, kR6CondBranch, kR6LongCondBranch);
3148 break;
3149 }
3150 break;
3151 default:
3152 LOG(FATAL) << "Unexpected branch type " << initial_type;
3153 UNREACHABLE();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003154 }
3155 } else {
3156 // R2
Alexey Frunze96b66822016-09-10 02:32:44 -07003157 switch (initial_type) {
3158 case kLabel:
3159 CHECK(!IsResolved());
3160 type_ = kLabel;
3161 break;
3162 case kLiteral:
3163 CHECK(!IsResolved());
3164 type_ = kLiteral;
3165 break;
3166 case kCall:
3167 InitShortOrLong(offset_size, kCall, kLongCall);
3168 break;
3169 case kCondBranch:
3170 switch (condition_) {
3171 case kUncond:
3172 InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
3173 break;
3174 default:
3175 InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
3176 break;
3177 }
3178 break;
3179 default:
3180 LOG(FATAL) << "Unexpected branch type " << initial_type;
3181 UNREACHABLE();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003182 }
3183 }
3184 old_type_ = type_;
3185}
3186
3187bool MipsAssembler::Branch::IsNop(BranchCondition condition, Register lhs, Register rhs) {
3188 switch (condition) {
3189 case kCondLT:
3190 case kCondGT:
3191 case kCondNE:
3192 case kCondLTU:
3193 return lhs == rhs;
3194 default:
3195 return false;
3196 }
3197}
3198
3199bool MipsAssembler::Branch::IsUncond(BranchCondition condition, Register lhs, Register rhs) {
3200 switch (condition) {
3201 case kUncond:
3202 return true;
3203 case kCondGE:
3204 case kCondLE:
3205 case kCondEQ:
3206 case kCondGEU:
3207 return lhs == rhs;
3208 default:
3209 return false;
3210 }
3211}
3212
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003213MipsAssembler::Branch::Branch(bool is_r6, uint32_t location, uint32_t target, bool is_call)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003214 : old_location_(location),
3215 location_(location),
3216 target_(target),
3217 lhs_reg_(0),
3218 rhs_reg_(0),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003219 condition_(kUncond),
3220 delayed_instruction_(kUnfilledDelaySlot) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003221 InitializeType((is_call ? kCall : kCondBranch), is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003222}
3223
3224MipsAssembler::Branch::Branch(bool is_r6,
3225 uint32_t location,
3226 uint32_t target,
3227 MipsAssembler::BranchCondition condition,
3228 Register lhs_reg,
3229 Register rhs_reg)
3230 : old_location_(location),
3231 location_(location),
3232 target_(target),
3233 lhs_reg_(lhs_reg),
3234 rhs_reg_(rhs_reg),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003235 condition_(condition),
3236 delayed_instruction_(kUnfilledDelaySlot) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003237 CHECK_NE(condition, kUncond);
3238 switch (condition) {
3239 case kCondLT:
3240 case kCondGE:
3241 case kCondLE:
3242 case kCondGT:
3243 case kCondLTU:
3244 case kCondGEU:
3245 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
3246 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
3247 // We leave this up to the caller.
3248 CHECK(is_r6);
3249 FALLTHROUGH_INTENDED;
3250 case kCondEQ:
3251 case kCondNE:
3252 // Require registers other than 0 not only for R6, but also for R2 to catch errors.
3253 // To compare with 0, use dedicated kCond*Z conditions.
3254 CHECK_NE(lhs_reg, ZERO);
3255 CHECK_NE(rhs_reg, ZERO);
3256 break;
3257 case kCondLTZ:
3258 case kCondGEZ:
3259 case kCondLEZ:
3260 case kCondGTZ:
3261 case kCondEQZ:
3262 case kCondNEZ:
3263 // Require registers other than 0 not only for R6, but also for R2 to catch errors.
3264 CHECK_NE(lhs_reg, ZERO);
3265 CHECK_EQ(rhs_reg, ZERO);
3266 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003267 case kCondF:
3268 case kCondT:
3269 CHECK_EQ(rhs_reg, ZERO);
3270 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003271 case kUncond:
3272 UNREACHABLE();
3273 }
3274 CHECK(!IsNop(condition, lhs_reg, rhs_reg));
3275 if (IsUncond(condition, lhs_reg, rhs_reg)) {
3276 // Branch condition is always true, make the branch unconditional.
3277 condition_ = kUncond;
3278 }
Alexey Frunze96b66822016-09-10 02:32:44 -07003279 InitializeType(kCondBranch, is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003280}
3281
Alexey Frunze96b66822016-09-10 02:32:44 -07003282MipsAssembler::Branch::Branch(bool is_r6,
3283 uint32_t location,
3284 Register dest_reg,
3285 Register base_reg,
3286 Type label_or_literal_type)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003287 : old_location_(location),
3288 location_(location),
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003289 target_(kUnresolved),
3290 lhs_reg_(dest_reg),
3291 rhs_reg_(base_reg),
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003292 condition_(kUncond),
3293 delayed_instruction_(kUnfilledDelaySlot) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003294 CHECK_NE(dest_reg, ZERO);
3295 if (is_r6) {
3296 CHECK_EQ(base_reg, ZERO);
3297 } else {
3298 CHECK_NE(base_reg, ZERO);
3299 }
Alexey Frunze96b66822016-09-10 02:32:44 -07003300 InitializeType(label_or_literal_type, is_r6);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003301}
3302
3303MipsAssembler::BranchCondition MipsAssembler::Branch::OppositeCondition(
3304 MipsAssembler::BranchCondition cond) {
3305 switch (cond) {
3306 case kCondLT:
3307 return kCondGE;
3308 case kCondGE:
3309 return kCondLT;
3310 case kCondLE:
3311 return kCondGT;
3312 case kCondGT:
3313 return kCondLE;
3314 case kCondLTZ:
3315 return kCondGEZ;
3316 case kCondGEZ:
3317 return kCondLTZ;
3318 case kCondLEZ:
3319 return kCondGTZ;
3320 case kCondGTZ:
3321 return kCondLEZ;
3322 case kCondEQ:
3323 return kCondNE;
3324 case kCondNE:
3325 return kCondEQ;
3326 case kCondEQZ:
3327 return kCondNEZ;
3328 case kCondNEZ:
3329 return kCondEQZ;
3330 case kCondLTU:
3331 return kCondGEU;
3332 case kCondGEU:
3333 return kCondLTU;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003334 case kCondF:
3335 return kCondT;
3336 case kCondT:
3337 return kCondF;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003338 case kUncond:
3339 LOG(FATAL) << "Unexpected branch condition " << cond;
3340 }
3341 UNREACHABLE();
3342}
3343
3344MipsAssembler::Branch::Type MipsAssembler::Branch::GetType() const {
3345 return type_;
3346}
3347
3348MipsAssembler::BranchCondition MipsAssembler::Branch::GetCondition() const {
3349 return condition_;
3350}
3351
3352Register MipsAssembler::Branch::GetLeftRegister() const {
3353 return static_cast<Register>(lhs_reg_);
3354}
3355
3356Register MipsAssembler::Branch::GetRightRegister() const {
3357 return static_cast<Register>(rhs_reg_);
3358}
3359
3360uint32_t MipsAssembler::Branch::GetTarget() const {
3361 return target_;
3362}
3363
3364uint32_t MipsAssembler::Branch::GetLocation() const {
3365 return location_;
3366}
3367
3368uint32_t MipsAssembler::Branch::GetOldLocation() const {
3369 return old_location_;
3370}
3371
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003372uint32_t MipsAssembler::Branch::GetPrecedingInstructionLength(Type type) const {
3373 // Short branches with delay slots always consist of two instructions, the branch
3374 // and the delay slot, irrespective of whether the delay slot is filled with a
3375 // useful instruction or not.
3376 // Long composite branches may have a length longer by one instruction than
3377 // specified in branch_info_[].length. This happens when an instruction is taken
3378 // to fill the short branch delay slot, but the branch eventually becomes long
3379 // and formally has no delay slot to fill. This instruction is placed at the
3380 // beginning of the long composite branch and this needs to be accounted for in
3381 // the branch length and the location of the offset encoded in the branch.
3382 switch (type) {
3383 case kLongUncondBranch:
3384 case kLongCondBranch:
3385 case kLongCall:
3386 case kR6LongCondBranch:
3387 return (delayed_instruction_ != kUnfilledDelaySlot &&
3388 delayed_instruction_ != kUnfillableDelaySlot) ? 1 : 0;
3389 default:
3390 return 0;
3391 }
3392}
3393
3394uint32_t MipsAssembler::Branch::GetPrecedingInstructionSize(Type type) const {
3395 return GetPrecedingInstructionLength(type) * sizeof(uint32_t);
3396}
3397
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003398uint32_t MipsAssembler::Branch::GetLength() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003399 return GetPrecedingInstructionLength(type_) + branch_info_[type_].length;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003400}
3401
3402uint32_t MipsAssembler::Branch::GetOldLength() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003403 return GetPrecedingInstructionLength(old_type_) + branch_info_[old_type_].length;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003404}
3405
3406uint32_t MipsAssembler::Branch::GetSize() const {
3407 return GetLength() * sizeof(uint32_t);
3408}
3409
3410uint32_t MipsAssembler::Branch::GetOldSize() const {
3411 return GetOldLength() * sizeof(uint32_t);
3412}
3413
3414uint32_t MipsAssembler::Branch::GetEndLocation() const {
3415 return GetLocation() + GetSize();
3416}
3417
3418uint32_t MipsAssembler::Branch::GetOldEndLocation() const {
3419 return GetOldLocation() + GetOldSize();
3420}
3421
3422bool MipsAssembler::Branch::IsLong() const {
3423 switch (type_) {
3424 // R2 short branches.
3425 case kUncondBranch:
3426 case kCondBranch:
3427 case kCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003428 // R2 near label.
3429 case kLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003430 // R2 near literal.
3431 case kLiteral:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003432 // R6 short branches.
3433 case kR6UncondBranch:
3434 case kR6CondBranch:
3435 case kR6Call:
Alexey Frunze96b66822016-09-10 02:32:44 -07003436 // R6 near label.
3437 case kR6Label:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003438 // R6 near literal.
3439 case kR6Literal:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003440 return false;
3441 // R2 long branches.
3442 case kLongUncondBranch:
3443 case kLongCondBranch:
3444 case kLongCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003445 // R2 far label.
3446 case kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003447 // R2 far literal.
3448 case kFarLiteral:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003449 // R6 long branches.
3450 case kR6LongUncondBranch:
3451 case kR6LongCondBranch:
3452 case kR6LongCall:
Alexey Frunze96b66822016-09-10 02:32:44 -07003453 // R6 far label.
3454 case kR6FarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003455 // R6 far literal.
3456 case kR6FarLiteral:
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003457 return true;
3458 }
3459 UNREACHABLE();
3460}
3461
3462bool MipsAssembler::Branch::IsResolved() const {
3463 return target_ != kUnresolved;
3464}
3465
3466MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSize() const {
3467 OffsetBits offset_size =
3468 (type_ == kR6CondBranch && (condition_ == kCondEQZ || condition_ == kCondNEZ))
3469 ? kOffset23
3470 : branch_info_[type_].offset_size;
3471 return offset_size;
3472}
3473
3474MipsAssembler::Branch::OffsetBits MipsAssembler::Branch::GetOffsetSizeNeeded(uint32_t location,
3475 uint32_t target) {
3476 // For unresolved targets assume the shortest encoding
3477 // (later it will be made longer if needed).
3478 if (target == kUnresolved)
3479 return kOffset16;
3480 int64_t distance = static_cast<int64_t>(target) - location;
3481 // To simplify calculations in composite branches consisting of multiple instructions
3482 // bump up the distance by a value larger than the max byte size of a composite branch.
3483 distance += (distance >= 0) ? kMaxBranchSize : -kMaxBranchSize;
3484 if (IsInt<kOffset16>(distance))
3485 return kOffset16;
3486 else if (IsInt<kOffset18>(distance))
3487 return kOffset18;
3488 else if (IsInt<kOffset21>(distance))
3489 return kOffset21;
3490 else if (IsInt<kOffset23>(distance))
3491 return kOffset23;
3492 else if (IsInt<kOffset28>(distance))
3493 return kOffset28;
3494 return kOffset32;
3495}
3496
3497void MipsAssembler::Branch::Resolve(uint32_t target) {
3498 target_ = target;
3499}
3500
3501void MipsAssembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
3502 if (location_ > expand_location) {
3503 location_ += delta;
3504 }
3505 if (!IsResolved()) {
3506 return; // Don't know the target yet.
3507 }
3508 if (target_ > expand_location) {
3509 target_ += delta;
3510 }
3511}
3512
3513void MipsAssembler::Branch::PromoteToLong() {
3514 switch (type_) {
3515 // R2 short branches.
3516 case kUncondBranch:
3517 type_ = kLongUncondBranch;
3518 break;
3519 case kCondBranch:
3520 type_ = kLongCondBranch;
3521 break;
3522 case kCall:
3523 type_ = kLongCall;
3524 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07003525 // R2 near label.
3526 case kLabel:
3527 type_ = kFarLabel;
3528 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003529 // R2 near literal.
3530 case kLiteral:
3531 type_ = kFarLiteral;
3532 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003533 // R6 short branches.
3534 case kR6UncondBranch:
3535 type_ = kR6LongUncondBranch;
3536 break;
3537 case kR6CondBranch:
3538 type_ = kR6LongCondBranch;
3539 break;
3540 case kR6Call:
3541 type_ = kR6LongCall;
3542 break;
Alexey Frunze96b66822016-09-10 02:32:44 -07003543 // R6 near label.
3544 case kR6Label:
3545 type_ = kR6FarLabel;
3546 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003547 // R6 near literal.
3548 case kR6Literal:
3549 type_ = kR6FarLiteral;
3550 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003551 default:
3552 // Note: 'type_' is already long.
3553 break;
3554 }
3555 CHECK(IsLong());
3556}
3557
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003558uint32_t MipsAssembler::GetBranchLocationOrPcRelBase(const MipsAssembler::Branch* branch) const {
3559 switch (branch->GetType()) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003560 case Branch::kLabel:
3561 case Branch::kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003562 case Branch::kLiteral:
3563 case Branch::kFarLiteral:
3564 return GetLabelLocation(&pc_rel_base_label_);
3565 default:
3566 return branch->GetLocation();
3567 }
3568}
3569
3570uint32_t MipsAssembler::Branch::PromoteIfNeeded(uint32_t location, uint32_t max_short_distance) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003571 // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 labels/literals or
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003572 // `this->GetLocation()` for everything else.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003573 // If the branch is still unresolved or already long, nothing to do.
3574 if (IsLong() || !IsResolved()) {
3575 return 0;
3576 }
3577 // Promote the short branch to long if the offset size is too small
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003578 // to hold the distance between location and target_.
3579 if (GetOffsetSizeNeeded(location, target_) > GetOffsetSize()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003580 PromoteToLong();
3581 uint32_t old_size = GetOldSize();
3582 uint32_t new_size = GetSize();
3583 CHECK_GT(new_size, old_size);
3584 return new_size - old_size;
3585 }
3586 // The following logic is for debugging/testing purposes.
3587 // Promote some short branches to long when it's not really required.
3588 if (UNLIKELY(max_short_distance != std::numeric_limits<uint32_t>::max())) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003589 int64_t distance = static_cast<int64_t>(target_) - location;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003590 distance = (distance >= 0) ? distance : -distance;
3591 if (distance >= max_short_distance) {
3592 PromoteToLong();
3593 uint32_t old_size = GetOldSize();
3594 uint32_t new_size = GetSize();
3595 CHECK_GT(new_size, old_size);
3596 return new_size - old_size;
3597 }
3598 }
3599 return 0;
3600}
3601
3602uint32_t MipsAssembler::Branch::GetOffsetLocation() const {
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003603 return location_ + GetPrecedingInstructionSize(type_) +
3604 branch_info_[type_].instr_offset * sizeof(uint32_t);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003605}
3606
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003607uint32_t MipsAssembler::GetBranchOrPcRelBaseForEncoding(const MipsAssembler::Branch* branch) const {
3608 switch (branch->GetType()) {
Alexey Frunze96b66822016-09-10 02:32:44 -07003609 case Branch::kLabel:
3610 case Branch::kFarLabel:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003611 case Branch::kLiteral:
3612 case Branch::kFarLiteral:
3613 return GetLabelLocation(&pc_rel_base_label_);
3614 default:
3615 return branch->GetOffsetLocation() +
3616 Branch::branch_info_[branch->GetType()].pc_org * sizeof(uint32_t);
3617 }
3618}
3619
3620uint32_t MipsAssembler::Branch::GetOffset(uint32_t location) const {
Alexey Frunze96b66822016-09-10 02:32:44 -07003621 // `location` is either `GetLabelLocation(&pc_rel_base_label_)` for R2 labels/literals or
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003622 // `this->GetOffsetLocation() + branch_info_[this->GetType()].pc_org * sizeof(uint32_t)`
3623 // for everything else.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003624 CHECK(IsResolved());
3625 uint32_t ofs_mask = 0xFFFFFFFF >> (32 - GetOffsetSize());
3626 // Calculate the byte distance between instructions and also account for
3627 // different PC-relative origins.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003628 uint32_t offset = target_ - location;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003629 // Prepare the offset for encoding into the instruction(s).
3630 offset = (offset & ofs_mask) >> branch_info_[type_].offset_shift;
3631 return offset;
3632}
3633
3634MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) {
3635 CHECK_LT(branch_id, branches_.size());
3636 return &branches_[branch_id];
3637}
3638
3639const MipsAssembler::Branch* MipsAssembler::GetBranch(uint32_t branch_id) const {
3640 CHECK_LT(branch_id, branches_.size());
3641 return &branches_[branch_id];
3642}
3643
3644void MipsAssembler::Bind(MipsLabel* label) {
3645 CHECK(!label->IsBound());
3646 uint32_t bound_pc = buffer_.Size();
3647
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003648 // Make the delay slot FSM aware of the new label.
3649 DsFsmLabel();
3650
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003651 // Walk the list of branches referring to and preceding this label.
3652 // Store the previously unknown target addresses in them.
3653 while (label->IsLinked()) {
3654 uint32_t branch_id = label->Position();
3655 Branch* branch = GetBranch(branch_id);
3656 branch->Resolve(bound_pc);
3657
3658 uint32_t branch_location = branch->GetLocation();
3659 // Extract the location of the previous branch in the list (walking the list backwards;
3660 // the previous branch ID was stored in the space reserved for this branch).
3661 uint32_t prev = buffer_.Load<uint32_t>(branch_location);
3662
3663 // On to the previous branch in the list...
3664 label->position_ = prev;
3665 }
3666
3667 // Now make the label object contain its own location (relative to the end of the preceding
3668 // branch, if any; it will be used by the branches referring to and following this label).
3669 label->prev_branch_id_plus_one_ = branches_.size();
3670 if (label->prev_branch_id_plus_one_) {
3671 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
3672 const Branch* branch = GetBranch(branch_id);
3673 bound_pc -= branch->GetEndLocation();
3674 }
3675 label->BindTo(bound_pc);
3676}
3677
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003678uint32_t MipsAssembler::GetLabelLocation(const MipsLabel* label) const {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003679 CHECK(label->IsBound());
3680 uint32_t target = label->Position();
3681 if (label->prev_branch_id_plus_one_) {
3682 // Get label location based on the branch preceding it.
3683 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
3684 const Branch* branch = GetBranch(branch_id);
3685 target += branch->GetEndLocation();
3686 }
3687 return target;
3688}
3689
3690uint32_t MipsAssembler::GetAdjustedPosition(uint32_t old_position) {
3691 // We can reconstruct the adjustment by going through all the branches from the beginning
3692 // up to the old_position. Since we expect AdjustedPosition() to be called in a loop
3693 // with increasing old_position, we can use the data from last AdjustedPosition() to
3694 // continue where we left off and the whole loop should be O(m+n) where m is the number
3695 // of positions to adjust and n is the number of branches.
3696 if (old_position < last_old_position_) {
3697 last_position_adjustment_ = 0;
3698 last_old_position_ = 0;
3699 last_branch_id_ = 0;
3700 }
3701 while (last_branch_id_ != branches_.size()) {
3702 const Branch* branch = GetBranch(last_branch_id_);
3703 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
3704 break;
3705 }
3706 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
3707 ++last_branch_id_;
3708 }
3709 last_old_position_ = old_position;
3710 return old_position + last_position_adjustment_;
3711}
3712
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003713void MipsAssembler::BindPcRelBaseLabel() {
3714 Bind(&pc_rel_base_label_);
3715}
3716
Alexey Frunze06a46c42016-07-19 15:00:40 -07003717uint32_t MipsAssembler::GetPcRelBaseLabelLocation() const {
3718 return GetLabelLocation(&pc_rel_base_label_);
3719}
3720
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003721void MipsAssembler::FinalizeLabeledBranch(MipsLabel* label) {
3722 uint32_t length = branches_.back().GetLength();
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003723 // Commit the last branch target label (if any).
3724 DsFsmCommitLabel();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003725 if (!label->IsBound()) {
3726 // Branch forward (to a following label), distance is unknown.
3727 // The first branch forward will contain 0, serving as the terminator of
3728 // the list of forward-reaching branches.
3729 Emit(label->position_);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003730 // Nothing for the delay slot (yet).
3731 DsFsmInstrNop(0);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003732 length--;
3733 // Now make the label object point to this branch
3734 // (this forms a linked list of branches preceding this label).
3735 uint32_t branch_id = branches_.size() - 1;
3736 label->LinkTo(branch_id);
3737 }
3738 // Reserve space for the branch.
3739 while (length--) {
3740 Nop();
3741 }
3742}
3743
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003744bool MipsAssembler::Branch::CanHaveDelayedInstruction(const DelaySlot& delay_slot) const {
3745 if (delay_slot.instruction_ == 0) {
3746 // NOP or no instruction for the delay slot.
3747 return false;
3748 }
3749 switch (type_) {
3750 // R2 unconditional branches.
3751 case kUncondBranch:
3752 case kLongUncondBranch:
3753 // There are no register interdependencies.
3754 return true;
3755
3756 // R2 calls.
3757 case kCall:
3758 case kLongCall:
3759 // Instructions depending on or modifying RA should not be moved into delay slots
3760 // of branches modifying RA.
3761 return ((delay_slot.gpr_ins_mask_ | delay_slot.gpr_outs_mask_) & (1u << RA)) == 0;
3762
3763 // R2 conditional branches.
3764 case kCondBranch:
3765 case kLongCondBranch:
3766 switch (condition_) {
3767 // Branches with one GPR source.
3768 case kCondLTZ:
3769 case kCondGEZ:
3770 case kCondLEZ:
3771 case kCondGTZ:
3772 case kCondEQZ:
3773 case kCondNEZ:
3774 return (delay_slot.gpr_outs_mask_ & (1u << lhs_reg_)) == 0;
3775
3776 // Branches with two GPR sources.
3777 case kCondEQ:
3778 case kCondNE:
3779 return (delay_slot.gpr_outs_mask_ & ((1u << lhs_reg_) | (1u << rhs_reg_))) == 0;
3780
3781 // Branches with one FPU condition code source.
3782 case kCondF:
3783 case kCondT:
3784 return (delay_slot.cc_outs_mask_ & (1u << lhs_reg_)) == 0;
3785
3786 default:
3787 // We don't support synthetic R2 branches (preceded with slt[u]) at this level
3788 // (R2 doesn't have branches to compare 2 registers using <, <=, >=, >).
3789 LOG(FATAL) << "Unexpected branch condition " << condition_;
3790 UNREACHABLE();
3791 }
3792
3793 // R6 unconditional branches.
3794 case kR6UncondBranch:
3795 case kR6LongUncondBranch:
3796 // R6 calls.
3797 case kR6Call:
3798 case kR6LongCall:
3799 // There are no delay slots.
3800 return false;
3801
3802 // R6 conditional branches.
3803 case kR6CondBranch:
3804 case kR6LongCondBranch:
3805 switch (condition_) {
3806 // Branches with one FPU register source.
3807 case kCondF:
3808 case kCondT:
3809 return (delay_slot.fpr_outs_mask_ & (1u << lhs_reg_)) == 0;
3810 // Others have a forbidden slot instead of a delay slot.
3811 default:
3812 return false;
3813 }
3814
3815 // Literals.
3816 default:
3817 LOG(FATAL) << "Unexpected branch type " << type_;
3818 UNREACHABLE();
3819 }
3820}
3821
3822uint32_t MipsAssembler::Branch::GetDelayedInstruction() const {
3823 return delayed_instruction_;
3824}
3825
3826void MipsAssembler::Branch::SetDelayedInstruction(uint32_t instruction) {
3827 CHECK_NE(instruction, kUnfilledDelaySlot);
3828 CHECK_EQ(delayed_instruction_, kUnfilledDelaySlot);
3829 delayed_instruction_ = instruction;
3830}
3831
3832void MipsAssembler::Branch::DecrementLocations() {
3833 // We first create a branch object, which gets its type and locations initialized,
3834 // and then we check if the branch can actually have the preceding instruction moved
3835 // into its delay slot. If it can, the branch locations need to be decremented.
3836 //
3837 // We could make the check before creating the branch object and avoid the location
3838 // adjustment, but the check is cleaner when performed on an initialized branch
3839 // object.
3840 //
3841 // If the branch is backwards (to a previously bound label), reducing the locations
3842 // cannot cause a short branch to exceed its offset range because the offset reduces.
3843 // And this is not at all a problem for a long branch backwards.
3844 //
3845 // If the branch is forward (not linked to any label yet), reducing the locations
3846 // is harmless. The branch will be promoted to long if needed when the target is known.
3847 CHECK_EQ(location_, old_location_);
3848 CHECK_GE(old_location_, sizeof(uint32_t));
3849 old_location_ -= sizeof(uint32_t);
3850 location_ = old_location_;
3851}
3852
3853void MipsAssembler::MoveInstructionToDelaySlot(Branch& branch) {
3854 if (branch.CanHaveDelayedInstruction(delay_slot_)) {
3855 // The last instruction cannot be used in a different delay slot,
3856 // do not commit the label before it (if any).
3857 DsFsmDropLabel();
3858 // Remove the last emitted instruction.
3859 size_t size = buffer_.Size();
3860 CHECK_GE(size, sizeof(uint32_t));
3861 size -= sizeof(uint32_t);
3862 CHECK_EQ(buffer_.Load<uint32_t>(size), delay_slot_.instruction_);
3863 buffer_.Resize(size);
3864 // Attach it to the branch and adjust the branch locations.
3865 branch.DecrementLocations();
3866 branch.SetDelayedInstruction(delay_slot_.instruction_);
3867 } else if (!reordering_ && branch.GetType() == Branch::kUncondBranch) {
3868 // If reordefing is disabled, prevent absorption of the target instruction.
3869 branch.SetDelayedInstruction(Branch::kUnfillableDelaySlot);
3870 }
3871}
3872
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003873void MipsAssembler::Buncond(MipsLabel* label) {
3874 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003875 branches_.emplace_back(IsR6(), buffer_.Size(), target, /* is_call */ false);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003876 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003877 FinalizeLabeledBranch(label);
3878}
3879
3880void MipsAssembler::Bcond(MipsLabel* label, BranchCondition condition, Register lhs, Register rhs) {
3881 // If lhs = rhs, this can be a NOP.
3882 if (Branch::IsNop(condition, lhs, rhs)) {
3883 return;
3884 }
3885 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
3886 branches_.emplace_back(IsR6(), buffer_.Size(), target, condition, lhs, rhs);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003887 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003888 FinalizeLabeledBranch(label);
3889}
3890
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003891void MipsAssembler::Call(MipsLabel* label) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003892 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003893 branches_.emplace_back(IsR6(), buffer_.Size(), target, /* is_call */ true);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07003894 MoveInstructionToDelaySlot(branches_.back());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003895 FinalizeLabeledBranch(label);
3896}
3897
Alexey Frunze96b66822016-09-10 02:32:44 -07003898void MipsAssembler::LoadLabelAddress(Register dest_reg, Register base_reg, MipsLabel* label) {
3899 // Label address loads are treated as pseudo branches since they require very similar handling.
3900 DCHECK(!label->IsBound());
3901 branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLabel);
3902 FinalizeLabeledBranch(label);
3903}
3904
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003905Literal* MipsAssembler::NewLiteral(size_t size, const uint8_t* data) {
3906 DCHECK(size == 4u || size == 8u) << size;
3907 literals_.emplace_back(size, data);
3908 return &literals_.back();
3909}
3910
3911void MipsAssembler::LoadLiteral(Register dest_reg, Register base_reg, Literal* literal) {
3912 // Literal loads are treated as pseudo branches since they require very similar handling.
3913 DCHECK_EQ(literal->GetSize(), 4u);
3914 MipsLabel* label = literal->GetLabel();
3915 DCHECK(!label->IsBound());
Alexey Frunze96b66822016-09-10 02:32:44 -07003916 branches_.emplace_back(IsR6(), buffer_.Size(), dest_reg, base_reg, Branch::kLiteral);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003917 FinalizeLabeledBranch(label);
3918}
3919
Alexey Frunze96b66822016-09-10 02:32:44 -07003920JumpTable* MipsAssembler::CreateJumpTable(std::vector<MipsLabel*>&& labels) {
3921 jump_tables_.emplace_back(std::move(labels));
3922 JumpTable* table = &jump_tables_.back();
3923 DCHECK(!table->GetLabel()->IsBound());
3924 return table;
3925}
3926
Alexey Frunzee3fb2452016-05-10 16:08:05 -07003927void MipsAssembler::EmitLiterals() {
3928 if (!literals_.empty()) {
3929 // We don't support byte and half-word literals.
3930 // TODO: proper alignment for 64-bit literals when they're implemented.
3931 for (Literal& literal : literals_) {
3932 MipsLabel* label = literal.GetLabel();
3933 Bind(label);
3934 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
3935 DCHECK(literal.GetSize() == 4u || literal.GetSize() == 8u);
3936 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
3937 buffer_.Emit<uint8_t>(literal.GetData()[i]);
3938 }
3939 }
3940 }
3941}
3942
Alexey Frunze96b66822016-09-10 02:32:44 -07003943void MipsAssembler::ReserveJumpTableSpace() {
3944 if (!jump_tables_.empty()) {
3945 for (JumpTable& table : jump_tables_) {
3946 MipsLabel* label = table.GetLabel();
3947 Bind(label);
3948
3949 // Bulk ensure capacity, as this may be large.
3950 size_t orig_size = buffer_.Size();
3951 size_t required_capacity = orig_size + table.GetSize();
3952 if (required_capacity > buffer_.Capacity()) {
3953 buffer_.ExtendCapacity(required_capacity);
3954 }
3955#ifndef NDEBUG
3956 buffer_.has_ensured_capacity_ = true;
3957#endif
3958
3959 // Fill the space with dummy data as the data is not final
3960 // until the branches have been promoted. And we shouldn't
3961 // be moving uninitialized data during branch promotion.
3962 for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
3963 buffer_.Emit<uint32_t>(0x1abe1234u);
3964 }
3965
3966#ifndef NDEBUG
3967 buffer_.has_ensured_capacity_ = false;
3968#endif
3969 }
3970 }
3971}
3972
3973void MipsAssembler::EmitJumpTables() {
3974 if (!jump_tables_.empty()) {
3975 CHECK(!overwriting_);
3976 // Switch from appending instructions at the end of the buffer to overwriting
3977 // existing instructions (here, jump tables) in the buffer.
3978 overwriting_ = true;
3979
3980 for (JumpTable& table : jump_tables_) {
3981 MipsLabel* table_label = table.GetLabel();
3982 uint32_t start = GetLabelLocation(table_label);
3983 overwrite_location_ = start;
3984
3985 for (MipsLabel* target : table.GetData()) {
3986 CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
3987 // The table will contain target addresses relative to the table start.
3988 uint32_t offset = GetLabelLocation(target) - start;
3989 Emit(offset);
3990 }
3991 }
3992
3993 overwriting_ = false;
3994 }
3995}
3996
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02003997void MipsAssembler::PromoteBranches() {
3998 // Promote short branches to long as necessary.
3999 bool changed;
4000 do {
4001 changed = false;
4002 for (auto& branch : branches_) {
4003 CHECK(branch.IsResolved());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004004 uint32_t base = GetBranchLocationOrPcRelBase(&branch);
4005 uint32_t delta = branch.PromoteIfNeeded(base);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004006 // If this branch has been promoted and needs to expand in size,
4007 // relocate all branches by the expansion size.
4008 if (delta) {
4009 changed = true;
4010 uint32_t expand_location = branch.GetLocation();
4011 for (auto& branch2 : branches_) {
4012 branch2.Relocate(expand_location, delta);
4013 }
4014 }
4015 }
4016 } while (changed);
4017
4018 // Account for branch expansion by resizing the code buffer
4019 // and moving the code in it to its final location.
4020 size_t branch_count = branches_.size();
4021 if (branch_count > 0) {
4022 // Resize.
4023 Branch& last_branch = branches_[branch_count - 1];
4024 uint32_t size_delta = last_branch.GetEndLocation() - last_branch.GetOldEndLocation();
4025 uint32_t old_size = buffer_.Size();
4026 buffer_.Resize(old_size + size_delta);
4027 // Move the code residing between branch placeholders.
4028 uint32_t end = old_size;
4029 for (size_t i = branch_count; i > 0; ) {
4030 Branch& branch = branches_[--i];
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004031 CHECK_GE(end, branch.GetOldEndLocation());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004032 uint32_t size = end - branch.GetOldEndLocation();
4033 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
4034 end = branch.GetOldLocation();
4035 }
4036 }
4037}
4038
4039// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
4040const MipsAssembler::Branch::BranchInfo MipsAssembler::Branch::branch_info_[] = {
4041 // R2 short branches.
4042 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kUncondBranch
4043 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCondBranch
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004044 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kCall
Alexey Frunze96b66822016-09-10 02:32:44 -07004045 // R2 near label.
4046 { 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004047 // R2 near literal.
4048 { 1, 0, 0, MipsAssembler::Branch::kOffset16, 0 }, // kLiteral
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004049 // R2 long branches.
4050 { 9, 3, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongUncondBranch
4051 { 10, 4, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCondBranch
4052 { 6, 1, 1, MipsAssembler::Branch::kOffset32, 0 }, // kLongCall
Alexey Frunze96b66822016-09-10 02:32:44 -07004053 // R2 far label.
4054 { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004055 // R2 far literal.
4056 { 3, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kFarLiteral
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004057 // R6 short branches.
4058 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6UncondBranch
4059 { 2, 0, 1, MipsAssembler::Branch::kOffset18, 2 }, // kR6CondBranch
4060 // Exception: kOffset23 for beqzc/bnezc.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004061 { 1, 0, 1, MipsAssembler::Branch::kOffset28, 2 }, // kR6Call
Alexey Frunze96b66822016-09-10 02:32:44 -07004062 // R6 near label.
4063 { 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Label
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004064 // R6 near literal.
4065 { 1, 0, 0, MipsAssembler::Branch::kOffset21, 2 }, // kR6Literal
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004066 // R6 long branches.
4067 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongUncondBranch
4068 { 3, 1, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCondBranch
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004069 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6LongCall
Alexey Frunze96b66822016-09-10 02:32:44 -07004070 // R6 far label.
4071 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLabel
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004072 // R6 far literal.
4073 { 2, 0, 0, MipsAssembler::Branch::kOffset32, 0 }, // kR6FarLiteral
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004074};
4075
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004076// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004077void MipsAssembler::EmitBranch(MipsAssembler::Branch* branch) {
4078 CHECK_EQ(overwriting_, true);
4079 overwrite_location_ = branch->GetLocation();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004080 uint32_t offset = branch->GetOffset(GetBranchOrPcRelBaseForEncoding(branch));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004081 BranchCondition condition = branch->GetCondition();
4082 Register lhs = branch->GetLeftRegister();
4083 Register rhs = branch->GetRightRegister();
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004084 uint32_t delayed_instruction = branch->GetDelayedInstruction();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004085 switch (branch->GetType()) {
4086 // R2 short branches.
4087 case Branch::kUncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004088 if (delayed_instruction == Branch::kUnfillableDelaySlot) {
4089 // The branch was created when reordering was disabled, do not absorb the target
4090 // instruction.
4091 delayed_instruction = 0; // NOP.
4092 } else if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4093 // Try to absorb the target instruction into the delay slot.
4094 delayed_instruction = 0; // NOP.
4095 // Incrementing the signed 16-bit offset past the target instruction must not
4096 // cause overflow into the negative subrange, check for the max offset.
4097 if (offset != 0x7FFF) {
4098 uint32_t target = branch->GetTarget();
4099 if (std::binary_search(ds_fsm_target_pcs_.begin(), ds_fsm_target_pcs_.end(), target)) {
4100 delayed_instruction = buffer_.Load<uint32_t>(target);
4101 offset++;
4102 }
4103 }
4104 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004105 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4106 B(offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004107 Emit(delayed_instruction);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004108 break;
4109 case Branch::kCondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004110 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4111 if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4112 delayed_instruction = 0; // NOP.
4113 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004114 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004115 EmitBcondR2(condition, lhs, rhs, offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004116 Emit(delayed_instruction);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004117 break;
4118 case Branch::kCall:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004119 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4120 if (delayed_instruction == Branch::kUnfilledDelaySlot) {
4121 delayed_instruction = 0; // NOP.
4122 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004123 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004124 Bal(offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004125 Emit(delayed_instruction);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004126 break;
4127
Alexey Frunze96b66822016-09-10 02:32:44 -07004128 // R2 near label.
4129 case Branch::kLabel:
4130 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4131 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4132 Addiu(lhs, rhs, offset);
4133 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004134 // R2 near literal.
4135 case Branch::kLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004136 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004137 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4138 Lw(lhs, rhs, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004139 break;
4140
4141 // R2 long branches.
4142 case Branch::kLongUncondBranch:
4143 // To get the value of the PC register we need to use the NAL instruction.
4144 // NAL clobbers the RA register. However, RA must be preserved if the
4145 // method is compiled without the entry/exit sequences that would take care
4146 // of preserving RA (typically, leaf methods don't preserve RA explicitly).
4147 // So, we need to preserve RA in some temporary storage ourselves. The AT
4148 // register can't be used for this because we need it to load a constant
4149 // which will be added to the value that NAL stores in RA. And we can't
4150 // use T9 for this in the context of the JNI compiler, which uses it
4151 // as a scratch register (see InterproceduralScratchRegister()).
4152 // If we were to add a 32-bit constant to RA using two ADDIU instructions,
4153 // we'd also need to use the ROTR instruction, which requires no less than
4154 // MIPSR2.
4155 // Perhaps, we could use T8 or one of R2's multiplier/divider registers
4156 // (LO or HI) or even a floating-point register, but that doesn't seem
4157 // like a nice solution. We may want this to work on both R6 and pre-R6.
4158 // For now simply use the stack for RA. This should be OK since for the
4159 // vast majority of code a short PC-relative branch is sufficient.
4160 // TODO: can this be improved?
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004161 // TODO: consider generation of a shorter sequence when we know that RA
4162 // is explicitly preserved by the method entry/exit code.
4163 if (delayed_instruction != Branch::kUnfilledDelaySlot &&
4164 delayed_instruction != Branch::kUnfillableDelaySlot) {
4165 Emit(delayed_instruction);
4166 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004167 Push(RA);
4168 Nal();
4169 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4170 Lui(AT, High16Bits(offset));
4171 Ori(AT, AT, Low16Bits(offset));
4172 Addu(AT, AT, RA);
4173 Lw(RA, SP, 0);
4174 Jr(AT);
4175 DecreaseFrameSize(kMipsWordSize);
4176 break;
4177 case Branch::kLongCondBranch:
4178 // The comment on case 'Branch::kLongUncondBranch' applies here as well.
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004179 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4180 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4181 Emit(delayed_instruction);
4182 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004183 // Note: the opposite condition branch encodes 8 as the distance, which is equal to the
4184 // number of instructions skipped:
4185 // (PUSH(IncreaseFrameSize(ADDIU) + SW) + NAL + LUI + ORI + ADDU + LW + JR).
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004186 EmitBcondR2(Branch::OppositeCondition(condition), lhs, rhs, 8);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004187 Push(RA);
4188 Nal();
4189 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4190 Lui(AT, High16Bits(offset));
4191 Ori(AT, AT, Low16Bits(offset));
4192 Addu(AT, AT, RA);
4193 Lw(RA, SP, 0);
4194 Jr(AT);
4195 DecreaseFrameSize(kMipsWordSize);
4196 break;
4197 case Branch::kLongCall:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004198 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4199 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4200 Emit(delayed_instruction);
4201 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004202 Nal();
4203 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4204 Lui(AT, High16Bits(offset));
4205 Ori(AT, AT, Low16Bits(offset));
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004206 Addu(AT, AT, RA);
4207 Jalr(AT);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004208 Nop();
4209 break;
4210
Alexey Frunze96b66822016-09-10 02:32:44 -07004211 // R2 far label.
4212 case Branch::kFarLabel:
4213 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4214 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4215 Lui(AT, High16Bits(offset));
4216 Ori(AT, AT, Low16Bits(offset));
4217 Addu(lhs, AT, rhs);
4218 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004219 // R2 far literal.
4220 case Branch::kFarLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004221 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004222 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
4223 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4224 Lui(AT, High16Bits(offset));
4225 Addu(AT, AT, rhs);
4226 Lw(lhs, AT, Low16Bits(offset));
4227 break;
4228
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004229 // R6 short branches.
4230 case Branch::kR6UncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004231 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004232 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4233 Bc(offset);
4234 break;
4235 case Branch::kR6CondBranch:
4236 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004237 EmitBcondR6(condition, lhs, rhs, offset);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004238 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4239 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4240 Emit(delayed_instruction);
4241 } else {
4242 // TODO: improve by filling the forbidden slot (IFF this is
4243 // a forbidden and not a delay slot).
4244 Nop();
4245 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004246 break;
4247 case Branch::kR6Call:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004248 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004249 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004250 Balc(offset);
4251 break;
4252
Alexey Frunze96b66822016-09-10 02:32:44 -07004253 // R6 near label.
4254 case Branch::kR6Label:
4255 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4256 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4257 Addiupc(lhs, offset);
4258 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004259 // R6 near literal.
4260 case Branch::kR6Literal:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004261 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004262 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4263 Lwpc(lhs, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004264 break;
4265
4266 // R6 long branches.
4267 case Branch::kR6LongUncondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004268 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004269 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
4270 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4271 Auipc(AT, High16Bits(offset));
4272 Jic(AT, Low16Bits(offset));
4273 break;
4274 case Branch::kR6LongCondBranch:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004275 DCHECK_NE(delayed_instruction, Branch::kUnfillableDelaySlot);
4276 if (delayed_instruction != Branch::kUnfilledDelaySlot) {
4277 Emit(delayed_instruction);
4278 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004279 EmitBcondR6(Branch::OppositeCondition(condition), lhs, rhs, 2);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004280 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
4281 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4282 Auipc(AT, High16Bits(offset));
4283 Jic(AT, Low16Bits(offset));
4284 break;
4285 case Branch::kR6LongCall:
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 jialc.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004288 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004289 Auipc(AT, High16Bits(offset));
4290 Jialc(AT, Low16Bits(offset));
4291 break;
4292
Alexey Frunze96b66822016-09-10 02:32:44 -07004293 // R6 far label.
4294 case Branch::kR6FarLabel:
4295 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
4296 offset += (offset & 0x8000) << 1; // Account for sign extension in addiu.
4297 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4298 Auipc(AT, High16Bits(offset));
4299 Addiu(lhs, AT, Low16Bits(offset));
4300 break;
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004301 // R6 far literal.
4302 case Branch::kR6FarLiteral:
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004303 DCHECK_EQ(delayed_instruction, Branch::kUnfilledDelaySlot);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004304 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
4305 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
4306 Auipc(AT, High16Bits(offset));
4307 Lw(lhs, AT, Low16Bits(offset));
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004308 break;
4309 }
4310 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
4311 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
4312}
4313
4314void MipsAssembler::B(MipsLabel* label) {
4315 Buncond(label);
4316}
4317
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004318void MipsAssembler::Bal(MipsLabel* label) {
4319 Call(label);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004320}
4321
4322void MipsAssembler::Beq(Register rs, Register rt, MipsLabel* label) {
4323 Bcond(label, kCondEQ, rs, rt);
4324}
4325
4326void MipsAssembler::Bne(Register rs, Register rt, MipsLabel* label) {
4327 Bcond(label, kCondNE, rs, rt);
4328}
4329
4330void MipsAssembler::Beqz(Register rt, MipsLabel* label) {
4331 Bcond(label, kCondEQZ, rt);
4332}
4333
4334void MipsAssembler::Bnez(Register rt, MipsLabel* label) {
4335 Bcond(label, kCondNEZ, rt);
4336}
4337
4338void MipsAssembler::Bltz(Register rt, MipsLabel* label) {
4339 Bcond(label, kCondLTZ, rt);
4340}
4341
4342void MipsAssembler::Bgez(Register rt, MipsLabel* label) {
4343 Bcond(label, kCondGEZ, rt);
4344}
4345
4346void MipsAssembler::Blez(Register rt, MipsLabel* label) {
4347 Bcond(label, kCondLEZ, rt);
4348}
4349
4350void MipsAssembler::Bgtz(Register rt, MipsLabel* label) {
4351 Bcond(label, kCondGTZ, rt);
4352}
4353
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004354bool MipsAssembler::CanExchangeWithSlt(Register rs, Register rt) const {
4355 // If the instruction modifies AT, `rs` or `rt`, it can't be exchanged with the slt[u]
4356 // instruction because either slt[u] depends on `rs` or `rt` or the following
4357 // conditional branch depends on AT set by slt[u].
4358 // Likewise, if the instruction depends on AT, it can't be exchanged with slt[u]
4359 // because slt[u] changes AT.
4360 return (delay_slot_.instruction_ != 0 &&
4361 (delay_slot_.gpr_outs_mask_ & ((1u << AT) | (1u << rs) | (1u << rt))) == 0 &&
4362 (delay_slot_.gpr_ins_mask_ & (1u << AT)) == 0);
4363}
4364
4365void MipsAssembler::ExchangeWithSlt(const DelaySlot& forwarded_slot) {
4366 // Exchange the last two instructions in the assembler buffer.
4367 size_t size = buffer_.Size();
4368 CHECK_GE(size, 2 * sizeof(uint32_t));
4369 size_t pos1 = size - 2 * sizeof(uint32_t);
4370 size_t pos2 = size - sizeof(uint32_t);
4371 uint32_t instr1 = buffer_.Load<uint32_t>(pos1);
4372 uint32_t instr2 = buffer_.Load<uint32_t>(pos2);
4373 CHECK_EQ(instr1, forwarded_slot.instruction_);
4374 CHECK_EQ(instr2, delay_slot_.instruction_);
4375 buffer_.Store<uint32_t>(pos1, instr2);
4376 buffer_.Store<uint32_t>(pos2, instr1);
4377 // Set the current delay slot information to that of the last instruction
4378 // in the buffer.
4379 delay_slot_ = forwarded_slot;
4380}
4381
4382void MipsAssembler::GenerateSltForCondBranch(bool unsigned_slt, Register rs, Register rt) {
4383 // If possible, exchange the slt[u] instruction with the preceding instruction,
4384 // so it can fill the delay slot.
4385 DelaySlot forwarded_slot = delay_slot_;
4386 bool exchange = CanExchangeWithSlt(rs, rt);
4387 if (exchange) {
4388 // The last instruction cannot be used in a different delay slot,
4389 // do not commit the label before it (if any).
4390 DsFsmDropLabel();
4391 }
4392 if (unsigned_slt) {
4393 Sltu(AT, rs, rt);
4394 } else {
4395 Slt(AT, rs, rt);
4396 }
4397 if (exchange) {
4398 ExchangeWithSlt(forwarded_slot);
4399 }
4400}
4401
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004402void MipsAssembler::Blt(Register rs, Register rt, MipsLabel* label) {
4403 if (IsR6()) {
4404 Bcond(label, kCondLT, rs, rt);
4405 } else if (!Branch::IsNop(kCondLT, rs, rt)) {
4406 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004407 GenerateSltForCondBranch(/* unsigned_slt */ false, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004408 Bnez(AT, label);
4409 }
4410}
4411
4412void MipsAssembler::Bge(Register rs, Register rt, MipsLabel* label) {
4413 if (IsR6()) {
4414 Bcond(label, kCondGE, rs, rt);
4415 } else if (Branch::IsUncond(kCondGE, rs, rt)) {
4416 B(label);
4417 } else {
4418 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004419 GenerateSltForCondBranch(/* unsigned_slt */ false, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004420 Beqz(AT, label);
4421 }
4422}
4423
4424void MipsAssembler::Bltu(Register rs, Register rt, MipsLabel* label) {
4425 if (IsR6()) {
4426 Bcond(label, kCondLTU, rs, rt);
4427 } else if (!Branch::IsNop(kCondLTU, rs, rt)) {
4428 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004429 GenerateSltForCondBranch(/* unsigned_slt */ true, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004430 Bnez(AT, label);
4431 }
4432}
4433
4434void MipsAssembler::Bgeu(Register rs, Register rt, MipsLabel* label) {
4435 if (IsR6()) {
4436 Bcond(label, kCondGEU, rs, rt);
4437 } else if (Branch::IsUncond(kCondGEU, rs, rt)) {
4438 B(label);
4439 } else {
4440 // Synthesize the instruction (not available on R2).
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004441 GenerateSltForCondBranch(/* unsigned_slt */ true, rs, rt);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004442 Beqz(AT, label);
jeffhao7fbee072012-08-24 17:56:54 -07004443 }
4444}
4445
Chris Larsenb74353a2015-11-20 09:07:09 -08004446void MipsAssembler::Bc1f(MipsLabel* label) {
4447 Bc1f(0, label);
4448}
4449
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004450void MipsAssembler::Bc1f(int cc, MipsLabel* label) {
4451 CHECK(IsUint<3>(cc)) << cc;
4452 Bcond(label, kCondF, static_cast<Register>(cc), ZERO);
4453}
4454
Chris Larsenb74353a2015-11-20 09:07:09 -08004455void MipsAssembler::Bc1t(MipsLabel* label) {
4456 Bc1t(0, label);
4457}
4458
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08004459void MipsAssembler::Bc1t(int cc, MipsLabel* label) {
4460 CHECK(IsUint<3>(cc)) << cc;
4461 Bcond(label, kCondT, static_cast<Register>(cc), ZERO);
4462}
4463
4464void MipsAssembler::Bc1eqz(FRegister ft, MipsLabel* label) {
4465 Bcond(label, kCondF, static_cast<Register>(ft), ZERO);
4466}
4467
4468void MipsAssembler::Bc1nez(FRegister ft, MipsLabel* label) {
4469 Bcond(label, kCondT, static_cast<Register>(ft), ZERO);
4470}
4471
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004472void MipsAssembler::AdjustBaseAndOffset(Register& base,
4473 int32_t& offset,
4474 bool is_doubleword,
4475 bool is_float) {
4476 // This method is used to adjust the base register and offset pair
4477 // for a load/store when the offset doesn't fit into int16_t.
4478 // It is assumed that `base + offset` is sufficiently aligned for memory
4479 // operands that are machine word in size or smaller. For doubleword-sized
4480 // operands it's assumed that `base` is a multiple of 8, while `offset`
4481 // may be a multiple of 4 (e.g. 4-byte-aligned long and double arguments
4482 // and spilled variables on the stack accessed relative to the stack
4483 // pointer register).
4484 // We preserve the "alignment" of `offset` by adjusting it by a multiple of 8.
4485 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
4486
4487 bool doubleword_aligned = IsAligned<kMipsDoublewordSize>(offset);
4488 bool two_accesses = is_doubleword && (!is_float || !doubleword_aligned);
4489
4490 // IsInt<16> must be passed a signed value, hence the static cast below.
4491 if (IsInt<16>(offset) &&
4492 (!two_accesses || IsInt<16>(static_cast<int32_t>(offset + kMipsWordSize)))) {
4493 // Nothing to do: `offset` (and, if needed, `offset + 4`) fits into int16_t.
4494 return;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004495 }
4496
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004497 // Remember the "(mis)alignment" of `offset`, it will be checked at the end.
4498 uint32_t misalignment = offset & (kMipsDoublewordSize - 1);
4499
4500 // Do not load the whole 32-bit `offset` if it can be represented as
4501 // a sum of two 16-bit signed offsets. This can save an instruction or two.
4502 // To simplify matters, only do this for a symmetric range of offsets from
4503 // about -64KB to about +64KB, allowing further addition of 4 when accessing
4504 // 64-bit variables with two 32-bit accesses.
4505 constexpr int32_t kMinOffsetForSimpleAdjustment = 0x7ff8; // Max int16_t that's a multiple of 8.
4506 constexpr int32_t kMaxOffsetForSimpleAdjustment = 2 * kMinOffsetForSimpleAdjustment;
4507 if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
4508 Addiu(AT, base, kMinOffsetForSimpleAdjustment);
4509 offset -= kMinOffsetForSimpleAdjustment;
4510 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
4511 Addiu(AT, base, -kMinOffsetForSimpleAdjustment);
4512 offset += kMinOffsetForSimpleAdjustment;
4513 } else if (IsR6()) {
4514 // On R6 take advantage of the aui instruction, e.g.:
4515 // aui AT, base, offset_high
4516 // lw reg_lo, offset_low(AT)
4517 // lw reg_hi, (offset_low+4)(AT)
4518 // or when offset_low+4 overflows int16_t:
4519 // aui AT, base, offset_high
4520 // addiu AT, AT, 8
4521 // lw reg_lo, (offset_low-8)(AT)
4522 // lw reg_hi, (offset_low-4)(AT)
4523 int16_t offset_high = High16Bits(offset);
4524 int16_t offset_low = Low16Bits(offset);
4525 offset_high += (offset_low < 0) ? 1 : 0; // Account for offset sign extension in load/store.
4526 Aui(AT, base, offset_high);
4527 if (two_accesses && !IsInt<16>(static_cast<int32_t>(offset_low + kMipsWordSize))) {
4528 // Avoid overflow in the 16-bit offset of the load/store instruction when adding 4.
4529 Addiu(AT, AT, kMipsDoublewordSize);
4530 offset_low -= kMipsDoublewordSize;
4531 }
4532 offset = offset_low;
4533 } else {
4534 // Do not load the whole 32-bit `offset` if it can be represented as
4535 // a sum of three 16-bit signed offsets. This can save an instruction.
4536 // To simplify matters, only do this for a symmetric range of offsets from
4537 // about -96KB to about +96KB, allowing further addition of 4 when accessing
4538 // 64-bit variables with two 32-bit accesses.
4539 constexpr int32_t kMinOffsetForMediumAdjustment = 2 * kMinOffsetForSimpleAdjustment;
4540 constexpr int32_t kMaxOffsetForMediumAdjustment = 3 * kMinOffsetForSimpleAdjustment;
4541 if (0 <= offset && offset <= kMaxOffsetForMediumAdjustment) {
4542 Addiu(AT, base, kMinOffsetForMediumAdjustment / 2);
4543 Addiu(AT, AT, kMinOffsetForMediumAdjustment / 2);
4544 offset -= kMinOffsetForMediumAdjustment;
4545 } else if (-kMaxOffsetForMediumAdjustment <= offset && offset < 0) {
4546 Addiu(AT, base, -kMinOffsetForMediumAdjustment / 2);
4547 Addiu(AT, AT, -kMinOffsetForMediumAdjustment / 2);
4548 offset += kMinOffsetForMediumAdjustment;
4549 } else {
4550 // Now that all shorter options have been exhausted, load the full 32-bit offset.
4551 int32_t loaded_offset = RoundDown(offset, kMipsDoublewordSize);
4552 LoadConst32(AT, loaded_offset);
4553 Addu(AT, AT, base);
4554 offset -= loaded_offset;
4555 }
4556 }
4557 base = AT;
4558
4559 CHECK(IsInt<16>(offset));
4560 if (two_accesses) {
4561 CHECK(IsInt<16>(static_cast<int32_t>(offset + kMipsWordSize)));
4562 }
4563 CHECK_EQ(misalignment, offset & (kMipsDoublewordSize - 1));
4564}
4565
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004566void MipsAssembler::AdjustBaseOffsetAndElementSizeShift(Register& base,
4567 int32_t& offset,
4568 int& element_size_shift) {
4569 // This method is used to adjust the base register, offset and element_size_shift
4570 // for a vector load/store when the offset doesn't fit into allowed number of bits.
4571 // MSA ld.df and st.df instructions take signed offsets as arguments, but maximum
4572 // offset is dependant on the size of the data format df (10-bit offsets for ld.b,
4573 // 11-bit for ld.h, 12-bit for ld.w and 13-bit for ld.d).
4574 // If element_size_shift is non-negative at entry, it won't be changed, but offset
4575 // will be checked for appropriate alignment. If negative at entry, it will be
4576 // adjusted based on offset for maximum fit.
4577 // It's assumed that `base` is a multiple of 8.
4578 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
4579
4580 if (element_size_shift >= 0) {
4581 CHECK_LE(element_size_shift, TIMES_8);
4582 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
4583 } else if (IsAligned<kMipsDoublewordSize>(offset)) {
4584 element_size_shift = TIMES_8;
4585 } else if (IsAligned<kMipsWordSize>(offset)) {
4586 element_size_shift = TIMES_4;
4587 } else if (IsAligned<kMipsHalfwordSize>(offset)) {
4588 element_size_shift = TIMES_2;
4589 } else {
4590 element_size_shift = TIMES_1;
4591 }
4592
4593 const int low_len = 10 + element_size_shift; // How many low bits of `offset` ld.df/st.df
4594 // will take.
4595 int16_t low = offset & ((1 << low_len) - 1); // Isolate these bits.
4596 low -= (low & (1 << (low_len - 1))) << 1; // Sign-extend these bits.
4597 if (low == offset) {
4598 return; // `offset` fits into ld.df/st.df.
4599 }
4600
4601 // First, see if `offset` can be represented as a sum of two or three signed offsets.
4602 // This can save an instruction or two.
4603
4604 // Max int16_t that's a multiple of element size.
4605 const int32_t kMaxDeltaForSimpleAdjustment = 0x8000 - (1 << element_size_shift);
4606 // Max ld.df/st.df offset that's a multiple of element size.
4607 const int32_t kMaxLoadStoreOffset = 0x1ff << element_size_shift;
4608 const int32_t kMaxOffsetForSimpleAdjustment = kMaxDeltaForSimpleAdjustment + kMaxLoadStoreOffset;
4609 const int32_t kMinOffsetForMediumAdjustment = 2 * kMaxDeltaForSimpleAdjustment;
4610 const int32_t kMaxOffsetForMediumAdjustment = kMinOffsetForMediumAdjustment + kMaxLoadStoreOffset;
4611
4612 if (IsInt<16>(offset)) {
4613 Addiu(AT, base, offset);
4614 offset = 0;
4615 } else if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
4616 Addiu(AT, base, kMaxDeltaForSimpleAdjustment);
4617 offset -= kMaxDeltaForSimpleAdjustment;
4618 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
4619 Addiu(AT, base, -kMaxDeltaForSimpleAdjustment);
4620 offset += kMaxDeltaForSimpleAdjustment;
4621 } else if (!IsR6() && 0 <= offset && offset <= kMaxOffsetForMediumAdjustment) {
4622 Addiu(AT, base, kMaxDeltaForSimpleAdjustment);
4623 if (offset <= kMinOffsetForMediumAdjustment) {
4624 Addiu(AT, AT, offset - kMaxDeltaForSimpleAdjustment);
4625 offset = 0;
4626 } else {
4627 Addiu(AT, AT, kMaxDeltaForSimpleAdjustment);
4628 offset -= kMinOffsetForMediumAdjustment;
4629 }
4630 } else if (!IsR6() && -kMaxOffsetForMediumAdjustment <= offset && offset < 0) {
4631 Addiu(AT, base, -kMaxDeltaForSimpleAdjustment);
4632 if (-kMinOffsetForMediumAdjustment <= offset) {
4633 Addiu(AT, AT, offset + kMaxDeltaForSimpleAdjustment);
4634 offset = 0;
4635 } else {
4636 Addiu(AT, AT, -kMaxDeltaForSimpleAdjustment);
4637 offset += kMinOffsetForMediumAdjustment;
4638 }
4639 } else {
4640 // 16-bit or smaller parts of `offset`:
4641 // |31 hi 16|15 mid 13-10|12-9 low 0|
4642 //
4643 // Instructions that supply each part as a signed integer addend:
4644 // |aui |addiu |ld.df/st.df |
4645 uint32_t tmp = static_cast<uint32_t>(offset) - low; // Exclude `low` from the rest of `offset`
4646 // (accounts for sign of `low`).
4647 tmp += (tmp & (UINT32_C(1) << 15)) << 1; // Account for sign extension in addiu.
4648 int16_t mid = Low16Bits(tmp);
4649 int16_t hi = High16Bits(tmp);
4650 if (IsR6()) {
4651 Aui(AT, base, hi);
4652 } else {
4653 Lui(AT, hi);
4654 Addu(AT, AT, base);
4655 }
4656 if (mid != 0) {
4657 Addiu(AT, AT, mid);
4658 }
4659 offset = low;
4660 }
4661 base = AT;
4662 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
4663 CHECK(IsInt<10>(offset >> element_size_shift));
4664}
4665
Alexey Frunze2923db72016-08-20 01:55:47 -07004666void MipsAssembler::LoadFromOffset(LoadOperandType type,
4667 Register reg,
4668 Register base,
Alexey Frunzecad3a4c2016-06-07 23:40:37 -07004669 int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004670 LoadFromOffset<>(type, reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004671}
4672
4673void MipsAssembler::LoadSFromOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004674 LoadSFromOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004675}
4676
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004677void MipsAssembler::LoadDFromOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004678 LoadDFromOffset<>(reg, base, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004679}
4680
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004681void MipsAssembler::LoadQFromOffset(FRegister reg, Register base, int32_t offset) {
4682 LoadQFromOffset<>(reg, base, offset);
4683}
4684
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004685void MipsAssembler::EmitLoad(ManagedRegister m_dst, Register src_register, int32_t src_offset,
4686 size_t size) {
4687 MipsManagedRegister dst = m_dst.AsMips();
4688 if (dst.IsNoRegister()) {
4689 CHECK_EQ(0u, size) << dst;
4690 } else if (dst.IsCoreRegister()) {
4691 CHECK_EQ(kMipsWordSize, size) << dst;
4692 LoadFromOffset(kLoadWord, dst.AsCoreRegister(), src_register, src_offset);
4693 } else if (dst.IsRegisterPair()) {
4694 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4695 LoadFromOffset(kLoadDoubleword, dst.AsRegisterPairLow(), src_register, src_offset);
4696 } else if (dst.IsFRegister()) {
4697 if (size == kMipsWordSize) {
4698 LoadSFromOffset(dst.AsFRegister(), src_register, src_offset);
4699 } else {
4700 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4701 LoadDFromOffset(dst.AsFRegister(), src_register, src_offset);
4702 }
Alexey Frunze1b8464d2016-11-12 17:22:05 -08004703 } else if (dst.IsDRegister()) {
4704 CHECK_EQ(kMipsDoublewordSize, size) << dst;
4705 LoadDFromOffset(dst.AsOverlappingDRegisterLow(), src_register, src_offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004706 }
jeffhao7fbee072012-08-24 17:56:54 -07004707}
4708
Alexey Frunze2923db72016-08-20 01:55:47 -07004709void MipsAssembler::StoreToOffset(StoreOperandType type,
4710 Register reg,
4711 Register base,
jeffhao7fbee072012-08-24 17:56:54 -07004712 int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004713 StoreToOffset<>(type, reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004714}
4715
Goran Jakovljevicff734982015-08-24 12:58:55 +00004716void MipsAssembler::StoreSToOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004717 StoreSToOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004718}
4719
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004720void MipsAssembler::StoreDToOffset(FRegister reg, Register base, int32_t offset) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004721 StoreDToOffset<>(reg, base, offset);
jeffhao7fbee072012-08-24 17:56:54 -07004722}
4723
Lena Djokic2e0a7e52017-07-06 11:55:24 +02004724void MipsAssembler::StoreQToOffset(FRegister reg, Register base, int32_t offset) {
4725 StoreQToOffset<>(reg, base, offset);
4726}
4727
David Srbeckydd973932015-04-07 20:29:48 +01004728static dwarf::Reg DWARFReg(Register reg) {
4729 return dwarf::Reg::MipsCore(static_cast<int>(reg));
4730}
4731
Ian Rogers790a6b72014-04-01 10:36:00 -07004732constexpr size_t kFramePointerSize = 4;
4733
Vladimir Marko32248382016-05-19 10:37:24 +01004734void MipsAssembler::BuildFrame(size_t frame_size,
4735 ManagedRegister method_reg,
4736 ArrayRef<const ManagedRegister> callee_save_regs,
Dmitry Petrochenkofca82202014-03-21 11:21:37 +07004737 const ManagedRegisterEntrySpills& entry_spills) {
jeffhao7fbee072012-08-24 17:56:54 -07004738 CHECK_ALIGNED(frame_size, kStackAlignment);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004739 DCHECK(!overwriting_);
jeffhao7fbee072012-08-24 17:56:54 -07004740
4741 // Increase frame to required size.
4742 IncreaseFrameSize(frame_size);
4743
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004744 // Push callee saves and return address.
Ian Rogers790a6b72014-04-01 10:36:00 -07004745 int stack_offset = frame_size - kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004746 StoreToOffset(kStoreWord, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004747 cfi_.RelOffset(DWARFReg(RA), stack_offset);
jeffhao7fbee072012-08-24 17:56:54 -07004748 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
Ian Rogers790a6b72014-04-01 10:36:00 -07004749 stack_offset -= kFramePointerSize;
Vladimir Marko32248382016-05-19 10:37:24 +01004750 Register reg = callee_save_regs[i].AsMips().AsCoreRegister();
jeffhao7fbee072012-08-24 17:56:54 -07004751 StoreToOffset(kStoreWord, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004752 cfi_.RelOffset(DWARFReg(reg), stack_offset);
jeffhao7fbee072012-08-24 17:56:54 -07004753 }
4754
4755 // Write out Method*.
4756 StoreToOffset(kStoreWord, method_reg.AsMips().AsCoreRegister(), SP, 0);
4757
4758 // Write out entry spills.
Goran Jakovljevicff734982015-08-24 12:58:55 +00004759 int32_t offset = frame_size + kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004760 for (size_t i = 0; i < entry_spills.size(); ++i) {
Goran Jakovljevicff734982015-08-24 12:58:55 +00004761 MipsManagedRegister reg = entry_spills.at(i).AsMips();
4762 if (reg.IsNoRegister()) {
4763 ManagedRegisterSpill spill = entry_spills.at(i);
4764 offset += spill.getSize();
4765 } else if (reg.IsCoreRegister()) {
4766 StoreToOffset(kStoreWord, reg.AsCoreRegister(), SP, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004767 offset += kMipsWordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004768 } else if (reg.IsFRegister()) {
4769 StoreSToOffset(reg.AsFRegister(), SP, offset);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004770 offset += kMipsWordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004771 } else if (reg.IsDRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004772 StoreDToOffset(reg.AsOverlappingDRegisterLow(), SP, offset);
4773 offset += kMipsDoublewordSize;
Goran Jakovljevicff734982015-08-24 12:58:55 +00004774 }
jeffhao7fbee072012-08-24 17:56:54 -07004775 }
4776}
4777
4778void MipsAssembler::RemoveFrame(size_t frame_size,
Vladimir Marko32248382016-05-19 10:37:24 +01004779 ArrayRef<const ManagedRegister> callee_save_regs) {
jeffhao7fbee072012-08-24 17:56:54 -07004780 CHECK_ALIGNED(frame_size, kStackAlignment);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004781 DCHECK(!overwriting_);
David Srbeckydd973932015-04-07 20:29:48 +01004782 cfi_.RememberState();
jeffhao7fbee072012-08-24 17:56:54 -07004783
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004784 // Pop callee saves and return address.
Ian Rogers790a6b72014-04-01 10:36:00 -07004785 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004786 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01004787 Register reg = callee_save_regs[i].AsMips().AsCoreRegister();
jeffhao7fbee072012-08-24 17:56:54 -07004788 LoadFromOffset(kLoadWord, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004789 cfi_.Restore(DWARFReg(reg));
Ian Rogers790a6b72014-04-01 10:36:00 -07004790 stack_offset += kFramePointerSize;
jeffhao7fbee072012-08-24 17:56:54 -07004791 }
4792 LoadFromOffset(kLoadWord, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01004793 cfi_.Restore(DWARFReg(RA));
jeffhao7fbee072012-08-24 17:56:54 -07004794
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004795 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
4796 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
4797 bool reordering = SetReorder(false);
4798 if (exchange) {
4799 // Jump to the return address.
4800 Jr(RA);
4801 // Decrease frame to required size.
4802 DecreaseFrameSize(frame_size); // Single instruction in delay slot.
4803 } else {
4804 // Decrease frame to required size.
4805 DecreaseFrameSize(frame_size);
4806 // Jump to the return address.
4807 Jr(RA);
4808 Nop(); // In delay slot.
4809 }
4810 SetReorder(reordering);
David Srbeckydd973932015-04-07 20:29:48 +01004811
4812 // The CFI should be restored for any code that follows the exit block.
4813 cfi_.RestoreState();
4814 cfi_.DefCFAOffset(frame_size);
jeffhao7fbee072012-08-24 17:56:54 -07004815}
4816
4817void MipsAssembler::IncreaseFrameSize(size_t adjust) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004818 CHECK_ALIGNED(adjust, kFramePointerSize);
4819 Addiu32(SP, SP, -adjust);
David Srbeckydd973932015-04-07 20:29:48 +01004820 cfi_.AdjustCFAOffset(adjust);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004821 if (overwriting_) {
4822 cfi_.OverrideDelayedPC(overwrite_location_);
4823 }
jeffhao7fbee072012-08-24 17:56:54 -07004824}
4825
4826void MipsAssembler::DecreaseFrameSize(size_t adjust) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004827 CHECK_ALIGNED(adjust, kFramePointerSize);
4828 Addiu32(SP, SP, adjust);
David Srbeckydd973932015-04-07 20:29:48 +01004829 cfi_.AdjustCFAOffset(-adjust);
Vladimir Marko10ef6942015-10-22 15:25:54 +01004830 if (overwriting_) {
4831 cfi_.OverrideDelayedPC(overwrite_location_);
4832 }
jeffhao7fbee072012-08-24 17:56:54 -07004833}
4834
4835void MipsAssembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
4836 MipsManagedRegister src = msrc.AsMips();
4837 if (src.IsNoRegister()) {
4838 CHECK_EQ(0u, size);
4839 } else if (src.IsCoreRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004840 CHECK_EQ(kMipsWordSize, size);
jeffhao7fbee072012-08-24 17:56:54 -07004841 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4842 } else if (src.IsRegisterPair()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004843 CHECK_EQ(kMipsDoublewordSize, size);
jeffhao7fbee072012-08-24 17:56:54 -07004844 StoreToOffset(kStoreWord, src.AsRegisterPairLow(), SP, dest.Int32Value());
4845 StoreToOffset(kStoreWord, src.AsRegisterPairHigh(),
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004846 SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07004847 } else if (src.IsFRegister()) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004848 if (size == kMipsWordSize) {
4849 StoreSToOffset(src.AsFRegister(), SP, dest.Int32Value());
4850 } else {
4851 CHECK_EQ(kMipsDoublewordSize, size);
4852 StoreDToOffset(src.AsFRegister(), SP, dest.Int32Value());
4853 }
Alexey Frunze1b8464d2016-11-12 17:22:05 -08004854 } else if (src.IsDRegister()) {
4855 CHECK_EQ(kMipsDoublewordSize, size);
4856 StoreDToOffset(src.AsOverlappingDRegisterLow(), SP, dest.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07004857 }
4858}
4859
4860void MipsAssembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
4861 MipsManagedRegister src = msrc.AsMips();
4862 CHECK(src.IsCoreRegister());
4863 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4864}
4865
4866void MipsAssembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
4867 MipsManagedRegister src = msrc.AsMips();
4868 CHECK(src.IsCoreRegister());
4869 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4870}
4871
4872void MipsAssembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
4873 ManagedRegister mscratch) {
4874 MipsManagedRegister scratch = mscratch.AsMips();
4875 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004876 LoadConst32(scratch.AsCoreRegister(), imm);
jeffhao7fbee072012-08-24 17:56:54 -07004877 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
4878}
4879
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004880void MipsAssembler::StoreStackOffsetToThread(ThreadOffset32 thr_offs,
4881 FrameOffset fr_offs,
jeffhao7fbee072012-08-24 17:56:54 -07004882 ManagedRegister mscratch) {
4883 MipsManagedRegister scratch = mscratch.AsMips();
4884 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004885 Addiu32(scratch.AsCoreRegister(), SP, fr_offs.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07004886 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
4887 S1, thr_offs.Int32Value());
4888}
4889
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004890void MipsAssembler::StoreStackPointerToThread(ThreadOffset32 thr_offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004891 StoreToOffset(kStoreWord, SP, S1, thr_offs.Int32Value());
4892}
4893
4894void MipsAssembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
4895 FrameOffset in_off, ManagedRegister mscratch) {
4896 MipsManagedRegister src = msrc.AsMips();
4897 MipsManagedRegister scratch = mscratch.AsMips();
4898 StoreToOffset(kStoreWord, src.AsCoreRegister(), SP, dest.Int32Value());
4899 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, in_off.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004900 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07004901}
4902
4903void MipsAssembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
4904 return EmitLoad(mdest, SP, src.Int32Value(), size);
4905}
4906
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004907void MipsAssembler::LoadFromThread(ManagedRegister mdest, ThreadOffset32 src, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07004908 return EmitLoad(mdest, S1, src.Int32Value(), size);
4909}
4910
4911void MipsAssembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
4912 MipsManagedRegister dest = mdest.AsMips();
4913 CHECK(dest.IsCoreRegister());
4914 LoadFromOffset(kLoadWord, dest.AsCoreRegister(), SP, src.Int32Value());
4915}
4916
Mathieu Chartiere401d142015-04-22 13:56:20 -07004917void MipsAssembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01004918 bool unpoison_reference) {
jeffhao7fbee072012-08-24 17:56:54 -07004919 MipsManagedRegister dest = mdest.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004920 CHECK(dest.IsCoreRegister() && base.AsMips().IsCoreRegister());
jeffhao7fbee072012-08-24 17:56:54 -07004921 LoadFromOffset(kLoadWord, dest.AsCoreRegister(),
4922 base.AsMips().AsCoreRegister(), offs.Int32Value());
Alexey Frunzec061de12017-02-14 13:27:23 -08004923 if (unpoison_reference) {
4924 MaybeUnpoisonHeapReference(dest.AsCoreRegister());
Hiroshi Yamauchie63a7452014-02-27 14:44:36 -08004925 }
jeffhao7fbee072012-08-24 17:56:54 -07004926}
4927
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004928void MipsAssembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base, Offset offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004929 MipsManagedRegister dest = mdest.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004930 CHECK(dest.IsCoreRegister() && base.AsMips().IsCoreRegister());
jeffhao7fbee072012-08-24 17:56:54 -07004931 LoadFromOffset(kLoadWord, dest.AsCoreRegister(),
4932 base.AsMips().AsCoreRegister(), offs.Int32Value());
4933}
4934
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004935void MipsAssembler::LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset32 offs) {
jeffhao7fbee072012-08-24 17:56:54 -07004936 MipsManagedRegister dest = mdest.AsMips();
4937 CHECK(dest.IsCoreRegister());
4938 LoadFromOffset(kLoadWord, dest.AsCoreRegister(), S1, offs.Int32Value());
4939}
4940
4941void MipsAssembler::SignExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
4942 UNIMPLEMENTED(FATAL) << "no sign extension necessary for mips";
4943}
4944
4945void MipsAssembler::ZeroExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
4946 UNIMPLEMENTED(FATAL) << "no zero extension necessary for mips";
4947}
4948
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004949void MipsAssembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07004950 MipsManagedRegister dest = mdest.AsMips();
4951 MipsManagedRegister src = msrc.AsMips();
4952 if (!dest.Equals(src)) {
4953 if (dest.IsCoreRegister()) {
4954 CHECK(src.IsCoreRegister()) << src;
4955 Move(dest.AsCoreRegister(), src.AsCoreRegister());
4956 } else if (dest.IsFRegister()) {
4957 CHECK(src.IsFRegister()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004958 if (size == kMipsWordSize) {
4959 MovS(dest.AsFRegister(), src.AsFRegister());
4960 } else {
4961 CHECK_EQ(kMipsDoublewordSize, size);
4962 MovD(dest.AsFRegister(), src.AsFRegister());
4963 }
jeffhao7fbee072012-08-24 17:56:54 -07004964 } else if (dest.IsDRegister()) {
4965 CHECK(src.IsDRegister()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004966 MovD(dest.AsOverlappingDRegisterLow(), src.AsOverlappingDRegisterLow());
jeffhao7fbee072012-08-24 17:56:54 -07004967 } else {
4968 CHECK(dest.IsRegisterPair()) << dest;
4969 CHECK(src.IsRegisterPair()) << src;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004970 // Ensure that the first move doesn't clobber the input of the second.
jeffhao7fbee072012-08-24 17:56:54 -07004971 if (src.AsRegisterPairHigh() != dest.AsRegisterPairLow()) {
4972 Move(dest.AsRegisterPairLow(), src.AsRegisterPairLow());
4973 Move(dest.AsRegisterPairHigh(), src.AsRegisterPairHigh());
4974 } else {
4975 Move(dest.AsRegisterPairHigh(), src.AsRegisterPairHigh());
4976 Move(dest.AsRegisterPairLow(), src.AsRegisterPairLow());
4977 }
4978 }
4979 }
4980}
4981
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02004982void MipsAssembler::CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07004983 MipsManagedRegister scratch = mscratch.AsMips();
4984 CHECK(scratch.IsCoreRegister()) << scratch;
4985 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
4986 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
4987}
4988
Andreas Gampe3b165bc2016-08-01 22:07:04 -07004989void MipsAssembler::CopyRawPtrFromThread(FrameOffset fr_offs,
4990 ThreadOffset32 thr_offs,
4991 ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07004992 MipsManagedRegister scratch = mscratch.AsMips();
4993 CHECK(scratch.IsCoreRegister()) << scratch;
4994 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
4995 S1, thr_offs.Int32Value());
4996 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
4997 SP, fr_offs.Int32Value());
4998}
4999
Andreas Gampe3b165bc2016-08-01 22:07:04 -07005000void MipsAssembler::CopyRawPtrToThread(ThreadOffset32 thr_offs,
5001 FrameOffset fr_offs,
5002 ManagedRegister mscratch) {
jeffhao7fbee072012-08-24 17:56:54 -07005003 MipsManagedRegister scratch = mscratch.AsMips();
5004 CHECK(scratch.IsCoreRegister()) << scratch;
5005 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5006 SP, fr_offs.Int32Value());
5007 StoreToOffset(kStoreWord, scratch.AsCoreRegister(),
5008 S1, thr_offs.Int32Value());
5009}
5010
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005011void MipsAssembler::Copy(FrameOffset dest, FrameOffset src, ManagedRegister mscratch, size_t size) {
jeffhao7fbee072012-08-24 17:56:54 -07005012 MipsManagedRegister scratch = mscratch.AsMips();
5013 CHECK(scratch.IsCoreRegister()) << scratch;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005014 CHECK(size == kMipsWordSize || size == kMipsDoublewordSize) << size;
5015 if (size == kMipsWordSize) {
jeffhao7fbee072012-08-24 17:56:54 -07005016 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
5017 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005018 } else if (size == kMipsDoublewordSize) {
jeffhao7fbee072012-08-24 17:56:54 -07005019 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value());
5020 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005021 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, src.Int32Value() + kMipsWordSize);
5022 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, dest.Int32Value() + kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005023 }
5024}
5025
5026void MipsAssembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
5027 ManagedRegister mscratch, size_t size) {
5028 Register scratch = mscratch.AsMips().AsCoreRegister();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005029 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005030 LoadFromOffset(kLoadWord, scratch, src_base.AsMips().AsCoreRegister(), src_offset.Int32Value());
5031 StoreToOffset(kStoreWord, scratch, SP, dest.Int32Value());
5032}
5033
5034void MipsAssembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
5035 ManagedRegister mscratch, size_t size) {
5036 Register scratch = mscratch.AsMips().AsCoreRegister();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005037 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005038 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
5039 StoreToOffset(kStoreWord, scratch, dest_base.AsMips().AsCoreRegister(), dest_offset.Int32Value());
5040}
5041
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005042void MipsAssembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
5043 FrameOffset src_base ATTRIBUTE_UNUSED,
5044 Offset src_offset ATTRIBUTE_UNUSED,
5045 ManagedRegister mscratch ATTRIBUTE_UNUSED,
5046 size_t size ATTRIBUTE_UNUSED) {
5047 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005048}
5049
5050void MipsAssembler::Copy(ManagedRegister dest, Offset dest_offset,
5051 ManagedRegister src, Offset src_offset,
5052 ManagedRegister mscratch, size_t size) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005053 CHECK_EQ(size, kMipsWordSize);
jeffhao7fbee072012-08-24 17:56:54 -07005054 Register scratch = mscratch.AsMips().AsCoreRegister();
5055 LoadFromOffset(kLoadWord, scratch, src.AsMips().AsCoreRegister(), src_offset.Int32Value());
5056 StoreToOffset(kStoreWord, scratch, dest.AsMips().AsCoreRegister(), dest_offset.Int32Value());
5057}
5058
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005059void MipsAssembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
5060 Offset dest_offset ATTRIBUTE_UNUSED,
5061 FrameOffset src ATTRIBUTE_UNUSED,
5062 Offset src_offset ATTRIBUTE_UNUSED,
5063 ManagedRegister mscratch ATTRIBUTE_UNUSED,
5064 size_t size ATTRIBUTE_UNUSED) {
5065 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005066}
5067
5068void MipsAssembler::MemoryBarrier(ManagedRegister) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005069 // TODO: sync?
5070 UNIMPLEMENTED(FATAL) << "no MIPS implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005071}
5072
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005073void MipsAssembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005074 FrameOffset handle_scope_offset,
5075 ManagedRegister min_reg,
5076 bool null_allowed) {
jeffhao7fbee072012-08-24 17:56:54 -07005077 MipsManagedRegister out_reg = mout_reg.AsMips();
5078 MipsManagedRegister in_reg = min_reg.AsMips();
5079 CHECK(in_reg.IsNoRegister() || in_reg.IsCoreRegister()) << in_reg;
5080 CHECK(out_reg.IsCoreRegister()) << out_reg;
5081 if (null_allowed) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005082 MipsLabel null_arg;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005083 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
5084 // the address in the handle scope holding the reference.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005085 // E.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset).
jeffhao7fbee072012-08-24 17:56:54 -07005086 if (in_reg.IsNoRegister()) {
5087 LoadFromOffset(kLoadWord, out_reg.AsCoreRegister(),
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005088 SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005089 in_reg = out_reg;
5090 }
5091 if (!out_reg.Equals(in_reg)) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005092 LoadConst32(out_reg.AsCoreRegister(), 0);
jeffhao7fbee072012-08-24 17:56:54 -07005093 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005094 Beqz(in_reg.AsCoreRegister(), &null_arg);
5095 Addiu32(out_reg.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
5096 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005097 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005098 Addiu32(out_reg.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005099 }
5100}
5101
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005102void MipsAssembler::CreateHandleScopeEntry(FrameOffset out_off,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005103 FrameOffset handle_scope_offset,
5104 ManagedRegister mscratch,
5105 bool null_allowed) {
jeffhao7fbee072012-08-24 17:56:54 -07005106 MipsManagedRegister scratch = mscratch.AsMips();
5107 CHECK(scratch.IsCoreRegister()) << scratch;
5108 if (null_allowed) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005109 MipsLabel null_arg;
5110 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005111 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
5112 // the address in the handle scope holding the reference.
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005113 // E.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset).
5114 Beqz(scratch.AsCoreRegister(), &null_arg);
5115 Addiu32(scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
5116 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005117 } else {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005118 Addiu32(scratch.AsCoreRegister(), SP, handle_scope_offset.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005119 }
5120 StoreToOffset(kStoreWord, scratch.AsCoreRegister(), SP, out_off.Int32Value());
5121}
5122
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07005123// Given a handle scope entry, load the associated reference.
5124void MipsAssembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005125 ManagedRegister min_reg) {
jeffhao7fbee072012-08-24 17:56:54 -07005126 MipsManagedRegister out_reg = mout_reg.AsMips();
5127 MipsManagedRegister in_reg = min_reg.AsMips();
5128 CHECK(out_reg.IsCoreRegister()) << out_reg;
5129 CHECK(in_reg.IsCoreRegister()) << in_reg;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005130 MipsLabel null_arg;
jeffhao7fbee072012-08-24 17:56:54 -07005131 if (!out_reg.Equals(in_reg)) {
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005132 LoadConst32(out_reg.AsCoreRegister(), 0);
jeffhao7fbee072012-08-24 17:56:54 -07005133 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005134 Beqz(in_reg.AsCoreRegister(), &null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005135 LoadFromOffset(kLoadWord, out_reg.AsCoreRegister(),
5136 in_reg.AsCoreRegister(), 0);
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005137 Bind(&null_arg);
jeffhao7fbee072012-08-24 17:56:54 -07005138}
5139
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005140void MipsAssembler::VerifyObject(ManagedRegister src ATTRIBUTE_UNUSED,
5141 bool could_be_null ATTRIBUTE_UNUSED) {
5142 // TODO: not validating references.
jeffhao7fbee072012-08-24 17:56:54 -07005143}
5144
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005145void MipsAssembler::VerifyObject(FrameOffset src ATTRIBUTE_UNUSED,
5146 bool could_be_null ATTRIBUTE_UNUSED) {
5147 // TODO: not validating references.
jeffhao7fbee072012-08-24 17:56:54 -07005148}
5149
5150void MipsAssembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
5151 MipsManagedRegister base = mbase.AsMips();
5152 MipsManagedRegister scratch = mscratch.AsMips();
5153 CHECK(base.IsCoreRegister()) << base;
5154 CHECK(scratch.IsCoreRegister()) << scratch;
5155 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5156 base.AsCoreRegister(), offset.Int32Value());
5157 Jalr(scratch.AsCoreRegister());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005158 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005159 // TODO: place reference map on call.
jeffhao7fbee072012-08-24 17:56:54 -07005160}
5161
5162void MipsAssembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
5163 MipsManagedRegister scratch = mscratch.AsMips();
5164 CHECK(scratch.IsCoreRegister()) << scratch;
5165 // Call *(*(SP + base) + offset)
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005166 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(), SP, base.Int32Value());
jeffhao7fbee072012-08-24 17:56:54 -07005167 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
5168 scratch.AsCoreRegister(), offset.Int32Value());
5169 Jalr(scratch.AsCoreRegister());
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005170 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005171 // TODO: place reference map on call.
jeffhao7fbee072012-08-24 17:56:54 -07005172}
5173
Andreas Gampe3b165bc2016-08-01 22:07:04 -07005174void MipsAssembler::CallFromThread(ThreadOffset32 offset ATTRIBUTE_UNUSED,
5175 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Ian Rogers468532e2013-08-05 10:56:33 -07005176 UNIMPLEMENTED(FATAL) << "no mips implementation";
jeffhao7fbee072012-08-24 17:56:54 -07005177}
5178
5179void MipsAssembler::GetCurrentThread(ManagedRegister tr) {
5180 Move(tr.AsMips().AsCoreRegister(), S1);
5181}
5182
5183void MipsAssembler::GetCurrentThread(FrameOffset offset,
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005184 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
jeffhao7fbee072012-08-24 17:56:54 -07005185 StoreToOffset(kStoreWord, S1, SP, offset.Int32Value());
5186}
5187
jeffhao7fbee072012-08-24 17:56:54 -07005188void MipsAssembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
5189 MipsManagedRegister scratch = mscratch.AsMips();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005190 exception_blocks_.emplace_back(scratch, stack_adjust);
jeffhao7fbee072012-08-24 17:56:54 -07005191 LoadFromOffset(kLoadWord, scratch.AsCoreRegister(),
Andreas Gampe542451c2016-07-26 09:02:02 -07005192 S1, Thread::ExceptionOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005193 Bnez(scratch.AsCoreRegister(), exception_blocks_.back().Entry());
jeffhao7fbee072012-08-24 17:56:54 -07005194}
5195
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005196void MipsAssembler::EmitExceptionPoll(MipsExceptionSlowPath* exception) {
5197 Bind(exception->Entry());
5198 if (exception->stack_adjust_ != 0) { // Fix up the frame.
5199 DecreaseFrameSize(exception->stack_adjust_);
jeffhao7fbee072012-08-24 17:56:54 -07005200 }
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005201 // Pass exception object as argument.
5202 // Don't care about preserving A0 as this call won't return.
5203 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5204 Move(A0, exception->scratch_.AsCoreRegister());
5205 // Set up call to Thread::Current()->pDeliverException.
5206 LoadFromOffset(kLoadWord, T9, S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07005207 QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, pDeliverException).Int32Value());
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005208 Jr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005209 NopIfNoReordering();
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +02005210
5211 // Call never returns.
5212 Break();
jeffhao7fbee072012-08-24 17:56:54 -07005213}
5214
5215} // namespace mips
5216} // namespace art