blob: c03b98c5c27062fda3f4ba1770121708187c24e5 [file] [log] [blame]
Andreas Gampe57b34292015-01-14 15:45:59 -08001/*
2 * Copyright (C) 2014 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_mips64.h"
18
Vladimir Marko80afd022015-05-19 18:08:00 +010019#include "base/bit_utils.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080020#include "base/casts.h"
21#include "entrypoints/quick/quick_entrypoints.h"
Alexey Frunzea0e87b02015-09-24 22:57:20 -070022#include "entrypoints/quick/quick_entrypoints_enum.h"
Andreas Gampe57b34292015-01-14 15:45:59 -080023#include "memory_region.h"
24#include "thread.h"
25
26namespace art {
27namespace mips64 {
28
Andreas Gampe542451c2016-07-26 09:02:02 -070029static_assert(static_cast<size_t>(kMips64PointerSize) == kMips64DoublewordSize,
30 "Unexpected Mips64 pointer size.");
31static_assert(kMips64PointerSize == PointerSize::k64, "Unexpected Mips64 pointer size.");
32
33
Alexey Frunzea0e87b02015-09-24 22:57:20 -070034void Mips64Assembler::FinalizeCode() {
35 for (auto& exception_block : exception_blocks_) {
36 EmitExceptionPoll(&exception_block);
37 }
Alexey Frunze0960ac52016-12-20 17:24:59 -080038 ReserveJumpTableSpace();
Alexey Frunze19f6c692016-11-30 19:19:55 -080039 EmitLiterals();
Alexey Frunzea0e87b02015-09-24 22:57:20 -070040 PromoteBranches();
41}
42
43void Mips64Assembler::FinalizeInstructions(const MemoryRegion& region) {
44 EmitBranches();
Alexey Frunze0960ac52016-12-20 17:24:59 -080045 EmitJumpTables();
Alexey Frunzea0e87b02015-09-24 22:57:20 -070046 Assembler::FinalizeInstructions(region);
47 PatchCFI();
48}
49
50void Mips64Assembler::PatchCFI() {
51 if (cfi().NumberOfDelayedAdvancePCs() == 0u) {
52 return;
53 }
54
55 typedef DebugFrameOpCodeWriterForAssembler::DelayedAdvancePC DelayedAdvancePC;
56 const auto data = cfi().ReleaseStreamAndPrepareForDelayedAdvancePC();
57 const std::vector<uint8_t>& old_stream = data.first;
58 const std::vector<DelayedAdvancePC>& advances = data.second;
59
60 // Refill our data buffer with patched opcodes.
61 cfi().ReserveCFIStream(old_stream.size() + advances.size() + 16);
62 size_t stream_pos = 0;
63 for (const DelayedAdvancePC& advance : advances) {
64 DCHECK_GE(advance.stream_pos, stream_pos);
65 // Copy old data up to the point where advance was issued.
66 cfi().AppendRawData(old_stream, stream_pos, advance.stream_pos);
67 stream_pos = advance.stream_pos;
68 // Insert the advance command with its final offset.
69 size_t final_pc = GetAdjustedPosition(advance.pc);
70 cfi().AdvancePC(final_pc);
71 }
72 // Copy the final segment if any.
73 cfi().AppendRawData(old_stream, stream_pos, old_stream.size());
74}
75
76void Mips64Assembler::EmitBranches() {
77 CHECK(!overwriting_);
78 // Switch from appending instructions at the end of the buffer to overwriting
79 // existing instructions (branch placeholders) in the buffer.
80 overwriting_ = true;
81 for (auto& branch : branches_) {
82 EmitBranch(&branch);
83 }
84 overwriting_ = false;
85}
86
Alexey Frunze4dda3372015-06-01 18:31:49 -070087void Mips64Assembler::Emit(uint32_t value) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -070088 if (overwriting_) {
89 // Branches to labels are emitted into their placeholders here.
90 buffer_.Store<uint32_t>(overwrite_location_, value);
91 overwrite_location_ += sizeof(uint32_t);
92 } else {
93 // Other instructions are simply appended at the end here.
94 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
95 buffer_.Emit<uint32_t>(value);
96 }
Andreas Gampe57b34292015-01-14 15:45:59 -080097}
98
99void Mips64Assembler::EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd,
100 int shamt, int funct) {
101 CHECK_NE(rs, kNoGpuRegister);
102 CHECK_NE(rt, kNoGpuRegister);
103 CHECK_NE(rd, kNoGpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700104 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
105 static_cast<uint32_t>(rs) << kRsShift |
106 static_cast<uint32_t>(rt) << kRtShift |
107 static_cast<uint32_t>(rd) << kRdShift |
108 shamt << kShamtShift |
109 funct;
Andreas Gampe57b34292015-01-14 15:45:59 -0800110 Emit(encoding);
111}
112
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700113void Mips64Assembler::EmitRsd(int opcode, GpuRegister rs, GpuRegister rd,
114 int shamt, int funct) {
115 CHECK_NE(rs, kNoGpuRegister);
116 CHECK_NE(rd, kNoGpuRegister);
117 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
118 static_cast<uint32_t>(rs) << kRsShift |
119 static_cast<uint32_t>(ZERO) << kRtShift |
120 static_cast<uint32_t>(rd) << kRdShift |
121 shamt << kShamtShift |
122 funct;
123 Emit(encoding);
124}
125
126void Mips64Assembler::EmitRtd(int opcode, GpuRegister rt, GpuRegister rd,
127 int shamt, int funct) {
128 CHECK_NE(rt, kNoGpuRegister);
129 CHECK_NE(rd, kNoGpuRegister);
130 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
131 static_cast<uint32_t>(ZERO) << kRsShift |
132 static_cast<uint32_t>(rt) << kRtShift |
133 static_cast<uint32_t>(rd) << kRdShift |
134 shamt << kShamtShift |
135 funct;
136 Emit(encoding);
137}
138
Andreas Gampe57b34292015-01-14 15:45:59 -0800139void Mips64Assembler::EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm) {
140 CHECK_NE(rs, kNoGpuRegister);
141 CHECK_NE(rt, kNoGpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700142 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
143 static_cast<uint32_t>(rs) << kRsShift |
144 static_cast<uint32_t>(rt) << kRtShift |
145 imm;
Andreas Gampe57b34292015-01-14 15:45:59 -0800146 Emit(encoding);
147}
148
Alexey Frunze4dda3372015-06-01 18:31:49 -0700149void Mips64Assembler::EmitI21(int opcode, GpuRegister rs, uint32_t imm21) {
150 CHECK_NE(rs, kNoGpuRegister);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700151 CHECK(IsUint<21>(imm21)) << imm21;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700152 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
153 static_cast<uint32_t>(rs) << kRsShift |
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700154 imm21;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700155 Emit(encoding);
156}
157
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700158void Mips64Assembler::EmitI26(int opcode, uint32_t imm26) {
159 CHECK(IsUint<26>(imm26)) << imm26;
160 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift | imm26;
Andreas Gampe57b34292015-01-14 15:45:59 -0800161 Emit(encoding);
162}
163
164void Mips64Assembler::EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd,
Alexey Frunze4dda3372015-06-01 18:31:49 -0700165 int funct) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800166 CHECK_NE(ft, kNoFpuRegister);
167 CHECK_NE(fs, kNoFpuRegister);
168 CHECK_NE(fd, kNoFpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700169 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
170 fmt << kFmtShift |
171 static_cast<uint32_t>(ft) << kFtShift |
172 static_cast<uint32_t>(fs) << kFsShift |
173 static_cast<uint32_t>(fd) << kFdShift |
174 funct;
Andreas Gampe57b34292015-01-14 15:45:59 -0800175 Emit(encoding);
176}
177
Alexey Frunze4dda3372015-06-01 18:31:49 -0700178void Mips64Assembler::EmitFI(int opcode, int fmt, FpuRegister ft, uint16_t imm) {
179 CHECK_NE(ft, kNoFpuRegister);
180 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
181 fmt << kFmtShift |
182 static_cast<uint32_t>(ft) << kFtShift |
183 imm;
Andreas Gampe57b34292015-01-14 15:45:59 -0800184 Emit(encoding);
185}
186
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000187void Mips64Assembler::EmitMsa3R(int operation,
188 int df,
189 VectorRegister wt,
190 VectorRegister ws,
191 VectorRegister wd,
192 int minor_opcode) {
193 CHECK_NE(wt, kNoVectorRegister);
194 CHECK_NE(ws, kNoVectorRegister);
195 CHECK_NE(wd, kNoVectorRegister);
196 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
197 operation << kMsaOperationShift |
198 df << kDfShift |
199 static_cast<uint32_t>(wt) << kWtShift |
200 static_cast<uint32_t>(ws) << kWsShift |
201 static_cast<uint32_t>(wd) << kWdShift |
202 minor_opcode;
203 Emit(encoding);
204}
205
206void Mips64Assembler::EmitMsaBIT(int operation,
207 int df_m,
208 VectorRegister ws,
209 VectorRegister wd,
210 int minor_opcode) {
211 CHECK_NE(ws, kNoVectorRegister);
212 CHECK_NE(wd, kNoVectorRegister);
213 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
214 operation << kMsaOperationShift |
215 df_m << kDfMShift |
216 static_cast<uint32_t>(ws) << kWsShift |
217 static_cast<uint32_t>(wd) << kWdShift |
218 minor_opcode;
219 Emit(encoding);
220}
221
222void Mips64Assembler::EmitMsaELM(int operation,
223 int df_n,
224 VectorRegister ws,
225 VectorRegister wd,
226 int minor_opcode) {
227 CHECK_NE(ws, kNoVectorRegister);
228 CHECK_NE(wd, kNoVectorRegister);
229 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
230 operation << kMsaELMOperationShift |
231 df_n << kDfNShift |
232 static_cast<uint32_t>(ws) << kWsShift |
233 static_cast<uint32_t>(wd) << kWdShift |
234 minor_opcode;
235 Emit(encoding);
236}
237
238void Mips64Assembler::EmitMsaMI10(int s10,
239 GpuRegister rs,
240 VectorRegister wd,
241 int minor_opcode,
242 int df) {
243 CHECK_NE(rs, kNoGpuRegister);
244 CHECK_NE(wd, kNoVectorRegister);
245 CHECK(IsUint<10>(s10)) << s10;
246 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
247 s10 << kS10Shift |
248 static_cast<uint32_t>(rs) << kWsShift |
249 static_cast<uint32_t>(wd) << kWdShift |
250 minor_opcode << kS10MinorShift |
251 df;
252 Emit(encoding);
253}
254
Goran Jakovljevic3f444032017-03-31 14:38:20 +0200255void Mips64Assembler::EmitMsaI10(int operation,
256 int df,
257 int i10,
258 VectorRegister wd,
259 int minor_opcode) {
260 CHECK_NE(wd, kNoVectorRegister);
261 CHECK(IsUint<10>(i10)) << i10;
262 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
263 operation << kMsaOperationShift |
264 df << kDfShift |
265 i10 << kI10Shift |
266 static_cast<uint32_t>(wd) << kWdShift |
267 minor_opcode;
268 Emit(encoding);
269}
270
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +0000271void Mips64Assembler::EmitMsa2R(int operation,
272 int df,
273 VectorRegister ws,
274 VectorRegister wd,
275 int minor_opcode) {
276 CHECK_NE(ws, kNoVectorRegister);
277 CHECK_NE(wd, kNoVectorRegister);
278 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
279 operation << kMsa2ROperationShift |
280 df << kDf2RShift |
281 static_cast<uint32_t>(ws) << kWsShift |
282 static_cast<uint32_t>(wd) << kWdShift |
283 minor_opcode;
284 Emit(encoding);
285}
286
287void Mips64Assembler::EmitMsa2RF(int operation,
288 int df,
289 VectorRegister ws,
290 VectorRegister wd,
291 int minor_opcode) {
292 CHECK_NE(ws, kNoVectorRegister);
293 CHECK_NE(wd, kNoVectorRegister);
294 uint32_t encoding = static_cast<uint32_t>(kMsaMajorOpcode) << kOpcodeShift |
295 operation << kMsa2RFOperationShift |
296 df << kDf2RShift |
297 static_cast<uint32_t>(ws) << kWsShift |
298 static_cast<uint32_t>(wd) << kWdShift |
299 minor_opcode;
300 Emit(encoding);
301}
302
Andreas Gampe57b34292015-01-14 15:45:59 -0800303void Mips64Assembler::Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
304 EmitR(0, rs, rt, rd, 0, 0x21);
305}
306
307void Mips64Assembler::Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
308 EmitI(0x9, rs, rt, imm16);
309}
310
Alexey Frunze4dda3372015-06-01 18:31:49 -0700311void Mips64Assembler::Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
312 EmitR(0, rs, rt, rd, 0, 0x2d);
313}
314
Andreas Gampe57b34292015-01-14 15:45:59 -0800315void Mips64Assembler::Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
316 EmitI(0x19, rs, rt, imm16);
317}
318
Andreas Gampe57b34292015-01-14 15:45:59 -0800319void Mips64Assembler::Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
320 EmitR(0, rs, rt, rd, 0, 0x23);
321}
322
Alexey Frunze4dda3372015-06-01 18:31:49 -0700323void Mips64Assembler::Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
324 EmitR(0, rs, rt, rd, 0, 0x2f);
325}
326
Alexey Frunze4dda3372015-06-01 18:31:49 -0700327void Mips64Assembler::MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
328 EmitR(0, rs, rt, rd, 2, 0x18);
329}
330
Alexey Frunzec857c742015-09-23 15:12:39 -0700331void Mips64Assembler::MuhR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
332 EmitR(0, rs, rt, rd, 3, 0x18);
333}
334
Alexey Frunze4dda3372015-06-01 18:31:49 -0700335void Mips64Assembler::DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
336 EmitR(0, rs, rt, rd, 2, 0x1a);
337}
338
339void Mips64Assembler::ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
340 EmitR(0, rs, rt, rd, 3, 0x1a);
341}
342
343void Mips64Assembler::DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
344 EmitR(0, rs, rt, rd, 2, 0x1b);
345}
346
347void Mips64Assembler::ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
348 EmitR(0, rs, rt, rd, 3, 0x1b);
349}
350
351void Mips64Assembler::Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
352 EmitR(0, rs, rt, rd, 2, 0x1c);
353}
354
Alexey Frunzec857c742015-09-23 15:12:39 -0700355void Mips64Assembler::Dmuh(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
356 EmitR(0, rs, rt, rd, 3, 0x1c);
357}
358
Alexey Frunze4dda3372015-06-01 18:31:49 -0700359void Mips64Assembler::Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
360 EmitR(0, rs, rt, rd, 2, 0x1e);
361}
362
363void Mips64Assembler::Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
364 EmitR(0, rs, rt, rd, 3, 0x1e);
365}
366
367void Mips64Assembler::Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
368 EmitR(0, rs, rt, rd, 2, 0x1f);
369}
370
371void Mips64Assembler::Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
372 EmitR(0, rs, rt, rd, 3, 0x1f);
373}
374
Andreas Gampe57b34292015-01-14 15:45:59 -0800375void Mips64Assembler::And(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
376 EmitR(0, rs, rt, rd, 0, 0x24);
377}
378
379void Mips64Assembler::Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
380 EmitI(0xc, rs, rt, imm16);
381}
382
383void Mips64Assembler::Or(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
384 EmitR(0, rs, rt, rd, 0, 0x25);
385}
386
387void Mips64Assembler::Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
388 EmitI(0xd, rs, rt, imm16);
389}
390
391void Mips64Assembler::Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
392 EmitR(0, rs, rt, rd, 0, 0x26);
393}
394
395void Mips64Assembler::Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
396 EmitI(0xe, rs, rt, imm16);
397}
398
399void Mips64Assembler::Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
400 EmitR(0, rs, rt, rd, 0, 0x27);
401}
402
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700403void Mips64Assembler::Bitswap(GpuRegister rd, GpuRegister rt) {
404 EmitRtd(0x1f, rt, rd, 0x0, 0x20);
405}
406
407void Mips64Assembler::Dbitswap(GpuRegister rd, GpuRegister rt) {
408 EmitRtd(0x1f, rt, rd, 0x0, 0x24);
409}
410
Alexey Frunze4dda3372015-06-01 18:31:49 -0700411void Mips64Assembler::Seb(GpuRegister rd, GpuRegister rt) {
412 EmitR(0x1f, static_cast<GpuRegister>(0), rt, rd, 0x10, 0x20);
Andreas Gampe57b34292015-01-14 15:45:59 -0800413}
414
Alexey Frunze4dda3372015-06-01 18:31:49 -0700415void Mips64Assembler::Seh(GpuRegister rd, GpuRegister rt) {
416 EmitR(0x1f, static_cast<GpuRegister>(0), rt, rd, 0x18, 0x20);
Andreas Gampe57b34292015-01-14 15:45:59 -0800417}
418
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700419void Mips64Assembler::Dsbh(GpuRegister rd, GpuRegister rt) {
420 EmitRtd(0x1f, rt, rd, 0x2, 0x24);
421}
422
423void Mips64Assembler::Dshd(GpuRegister rd, GpuRegister rt) {
424 EmitRtd(0x1f, rt, rd, 0x5, 0x24);
425}
426
Lazar Trsicd9672662015-09-03 17:33:01 +0200427void Mips64Assembler::Dext(GpuRegister rt, GpuRegister rs, int pos, int size) {
428 CHECK(IsUint<5>(pos)) << pos;
429 CHECK(IsUint<5>(size - 1)) << size;
430 EmitR(0x1f, rs, rt, static_cast<GpuRegister>(size - 1), pos, 0x3);
431}
432
433void Mips64Assembler::Dinsu(GpuRegister rt, GpuRegister rs, int pos, int size) {
434 CHECK(IsUint<5>(pos - 32)) << pos;
435 CHECK(IsUint<5>(size - 1)) << size;
436 CHECK(IsUint<5>(pos + size - 33)) << pos << " + " << size;
437 EmitR(0x1f, rs, rt, static_cast<GpuRegister>(pos + size - 33), pos - 32, 0x6);
Andreas Gampe57b34292015-01-14 15:45:59 -0800438}
439
Chris Larsene3660592016-11-09 11:13:42 -0800440void Mips64Assembler::Lsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne) {
441 CHECK(1 <= saPlusOne && saPlusOne <= 4) << saPlusOne;
442 int sa = saPlusOne - 1;
443 EmitR(0x0, rs, rt, rd, sa, 0x05);
444}
445
446void Mips64Assembler::Dlsa(GpuRegister rd, GpuRegister rs, GpuRegister rt, int saPlusOne) {
447 CHECK(1 <= saPlusOne && saPlusOne <= 4) << saPlusOne;
448 int sa = saPlusOne - 1;
449 EmitR(0x0, rs, rt, rd, sa, 0x15);
450}
451
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700452void Mips64Assembler::Wsbh(GpuRegister rd, GpuRegister rt) {
453 EmitRtd(0x1f, rt, rd, 2, 0x20);
454}
455
456void Mips64Assembler::Sc(GpuRegister rt, GpuRegister base, int16_t imm9) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200457 CHECK(IsInt<9>(imm9));
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700458 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x26);
459}
460
461void Mips64Assembler::Scd(GpuRegister rt, GpuRegister base, int16_t imm9) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200462 CHECK(IsInt<9>(imm9));
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700463 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x27);
464}
465
466void Mips64Assembler::Ll(GpuRegister rt, GpuRegister base, int16_t imm9) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200467 CHECK(IsInt<9>(imm9));
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700468 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x36);
469}
470
471void Mips64Assembler::Lld(GpuRegister rt, GpuRegister base, int16_t imm9) {
Lazar Trsicd9672662015-09-03 17:33:01 +0200472 CHECK(IsInt<9>(imm9));
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700473 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x37);
474}
475
Alexey Frunze4dda3372015-06-01 18:31:49 -0700476void Mips64Assembler::Sll(GpuRegister rd, GpuRegister rt, int shamt) {
477 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x00);
478}
479
480void Mips64Assembler::Srl(GpuRegister rd, GpuRegister rt, int shamt) {
481 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x02);
482}
483
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700484void Mips64Assembler::Rotr(GpuRegister rd, GpuRegister rt, int shamt) {
485 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x02);
486}
487
Alexey Frunze4dda3372015-06-01 18:31:49 -0700488void Mips64Assembler::Sra(GpuRegister rd, GpuRegister rt, int shamt) {
489 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x03);
490}
491
492void Mips64Assembler::Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800493 EmitR(0, rs, rt, rd, 0, 0x04);
494}
495
Chris Larsen9aebff22015-09-22 17:54:15 -0700496void Mips64Assembler::Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
497 EmitR(0, rs, rt, rd, 1, 0x06);
498}
499
Alexey Frunze4dda3372015-06-01 18:31:49 -0700500void Mips64Assembler::Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800501 EmitR(0, rs, rt, rd, 0, 0x06);
502}
503
Alexey Frunze4dda3372015-06-01 18:31:49 -0700504void Mips64Assembler::Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800505 EmitR(0, rs, rt, rd, 0, 0x07);
506}
507
Alexey Frunze4dda3372015-06-01 18:31:49 -0700508void Mips64Assembler::Dsll(GpuRegister rd, GpuRegister rt, int shamt) {
509 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x38);
510}
511
512void Mips64Assembler::Dsrl(GpuRegister rd, GpuRegister rt, int shamt) {
513 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3a);
514}
515
Chris Larsen9aebff22015-09-22 17:54:15 -0700516void Mips64Assembler::Drotr(GpuRegister rd, GpuRegister rt, int shamt) {
517 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x3a);
518}
519
Alexey Frunze4dda3372015-06-01 18:31:49 -0700520void Mips64Assembler::Dsra(GpuRegister rd, GpuRegister rt, int shamt) {
521 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3b);
522}
523
524void Mips64Assembler::Dsll32(GpuRegister rd, GpuRegister rt, int shamt) {
525 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3c);
526}
527
528void Mips64Assembler::Dsrl32(GpuRegister rd, GpuRegister rt, int shamt) {
529 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3e);
530}
531
Chris Larsen9aebff22015-09-22 17:54:15 -0700532void Mips64Assembler::Drotr32(GpuRegister rd, GpuRegister rt, int shamt) {
533 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x3e);
534}
535
Alexey Frunze4dda3372015-06-01 18:31:49 -0700536void Mips64Assembler::Dsra32(GpuRegister rd, GpuRegister rt, int shamt) {
537 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3f);
538}
539
540void Mips64Assembler::Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
541 EmitR(0, rs, rt, rd, 0, 0x14);
542}
543
544void Mips64Assembler::Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
545 EmitR(0, rs, rt, rd, 0, 0x16);
546}
547
Chris Larsen9aebff22015-09-22 17:54:15 -0700548void Mips64Assembler::Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
549 EmitR(0, rs, rt, rd, 1, 0x16);
550}
551
Alexey Frunze4dda3372015-06-01 18:31:49 -0700552void Mips64Assembler::Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
553 EmitR(0, rs, rt, rd, 0, 0x17);
554}
555
Andreas Gampe57b34292015-01-14 15:45:59 -0800556void Mips64Assembler::Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
557 EmitI(0x20, rs, rt, imm16);
558}
559
560void Mips64Assembler::Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
561 EmitI(0x21, rs, rt, imm16);
562}
563
564void Mips64Assembler::Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
565 EmitI(0x23, rs, rt, imm16);
566}
567
568void Mips64Assembler::Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
569 EmitI(0x37, rs, rt, imm16);
570}
571
572void Mips64Assembler::Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
573 EmitI(0x24, rs, rt, imm16);
574}
575
576void Mips64Assembler::Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
577 EmitI(0x25, rs, rt, imm16);
578}
579
Douglas Leungd90957f2015-04-30 19:22:49 -0700580void Mips64Assembler::Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
581 EmitI(0x27, rs, rt, imm16);
582}
583
Alexey Frunze19f6c692016-11-30 19:19:55 -0800584void Mips64Assembler::Lwpc(GpuRegister rs, uint32_t imm19) {
585 CHECK(IsUint<19>(imm19)) << imm19;
586 EmitI21(0x3B, rs, (0x01 << 19) | imm19);
587}
588
589void Mips64Assembler::Lwupc(GpuRegister rs, uint32_t imm19) {
590 CHECK(IsUint<19>(imm19)) << imm19;
591 EmitI21(0x3B, rs, (0x02 << 19) | imm19);
592}
593
594void Mips64Assembler::Ldpc(GpuRegister rs, uint32_t imm18) {
595 CHECK(IsUint<18>(imm18)) << imm18;
596 EmitI21(0x3B, rs, (0x06 << 18) | imm18);
597}
598
Andreas Gampe57b34292015-01-14 15:45:59 -0800599void Mips64Assembler::Lui(GpuRegister rt, uint16_t imm16) {
600 EmitI(0xf, static_cast<GpuRegister>(0), rt, imm16);
601}
602
Alexey Frunze0960ac52016-12-20 17:24:59 -0800603void Mips64Assembler::Aui(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
604 EmitI(0xf, rs, rt, imm16);
605}
606
Alexey Frunzec061de12017-02-14 13:27:23 -0800607void Mips64Assembler::Daui(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
608 CHECK_NE(rs, ZERO);
609 EmitI(0x1d, rs, rt, imm16);
610}
611
Alexey Frunze4dda3372015-06-01 18:31:49 -0700612void Mips64Assembler::Dahi(GpuRegister rs, uint16_t imm16) {
613 EmitI(1, rs, static_cast<GpuRegister>(6), imm16);
614}
615
616void Mips64Assembler::Dati(GpuRegister rs, uint16_t imm16) {
617 EmitI(1, rs, static_cast<GpuRegister>(0x1e), imm16);
618}
619
620void Mips64Assembler::Sync(uint32_t stype) {
621 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
622 static_cast<GpuRegister>(0), stype & 0x1f, 0xf);
623}
624
Andreas Gampe57b34292015-01-14 15:45:59 -0800625void Mips64Assembler::Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
626 EmitI(0x28, rs, rt, imm16);
627}
628
629void Mips64Assembler::Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
630 EmitI(0x29, rs, rt, imm16);
631}
632
633void Mips64Assembler::Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
634 EmitI(0x2b, rs, rt, imm16);
635}
636
637void Mips64Assembler::Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
638 EmitI(0x3f, rs, rt, imm16);
639}
640
641void Mips64Assembler::Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
642 EmitR(0, rs, rt, rd, 0, 0x2a);
643}
644
645void Mips64Assembler::Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
646 EmitR(0, rs, rt, rd, 0, 0x2b);
647}
648
649void Mips64Assembler::Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
650 EmitI(0xa, rs, rt, imm16);
651}
652
653void Mips64Assembler::Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
654 EmitI(0xb, rs, rt, imm16);
655}
656
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700657void Mips64Assembler::Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
658 EmitR(0, rs, rt, rd, 0, 0x35);
659}
660
661void Mips64Assembler::Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
662 EmitR(0, rs, rt, rd, 0, 0x37);
663}
664
665void Mips64Assembler::Clz(GpuRegister rd, GpuRegister rs) {
666 EmitRsd(0, rs, rd, 0x01, 0x10);
667}
668
669void Mips64Assembler::Clo(GpuRegister rd, GpuRegister rs) {
670 EmitRsd(0, rs, rd, 0x01, 0x11);
671}
672
673void Mips64Assembler::Dclz(GpuRegister rd, GpuRegister rs) {
674 EmitRsd(0, rs, rd, 0x01, 0x12);
675}
676
677void Mips64Assembler::Dclo(GpuRegister rd, GpuRegister rs) {
678 EmitRsd(0, rs, rd, 0x01, 0x13);
679}
680
Alexey Frunze4dda3372015-06-01 18:31:49 -0700681void Mips64Assembler::Jalr(GpuRegister rd, GpuRegister rs) {
682 EmitR(0, rs, static_cast<GpuRegister>(0), rd, 0, 0x09);
Andreas Gampe57b34292015-01-14 15:45:59 -0800683}
684
685void Mips64Assembler::Jalr(GpuRegister rs) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700686 Jalr(RA, rs);
687}
688
689void Mips64Assembler::Jr(GpuRegister rs) {
690 Jalr(ZERO, rs);
691}
692
693void Mips64Assembler::Auipc(GpuRegister rs, uint16_t imm16) {
694 EmitI(0x3B, rs, static_cast<GpuRegister>(0x1E), imm16);
695}
696
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700697void Mips64Assembler::Addiupc(GpuRegister rs, uint32_t imm19) {
698 CHECK(IsUint<19>(imm19)) << imm19;
699 EmitI21(0x3B, rs, imm19);
700}
701
702void Mips64Assembler::Bc(uint32_t imm26) {
703 EmitI26(0x32, imm26);
704}
705
Alexey Frunze19f6c692016-11-30 19:19:55 -0800706void Mips64Assembler::Balc(uint32_t imm26) {
707 EmitI26(0x3A, imm26);
708}
709
Alexey Frunze4dda3372015-06-01 18:31:49 -0700710void Mips64Assembler::Jic(GpuRegister rt, uint16_t imm16) {
711 EmitI(0x36, static_cast<GpuRegister>(0), rt, imm16);
712}
713
714void Mips64Assembler::Jialc(GpuRegister rt, uint16_t imm16) {
715 EmitI(0x3E, static_cast<GpuRegister>(0), rt, imm16);
716}
717
718void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
719 CHECK_NE(rs, ZERO);
720 CHECK_NE(rt, ZERO);
721 CHECK_NE(rs, rt);
722 EmitI(0x17, rs, rt, imm16);
723}
724
725void Mips64Assembler::Bltzc(GpuRegister rt, uint16_t imm16) {
726 CHECK_NE(rt, ZERO);
727 EmitI(0x17, rt, rt, imm16);
728}
729
730void Mips64Assembler::Bgtzc(GpuRegister rt, uint16_t imm16) {
731 CHECK_NE(rt, ZERO);
732 EmitI(0x17, static_cast<GpuRegister>(0), rt, imm16);
733}
734
735void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
736 CHECK_NE(rs, ZERO);
737 CHECK_NE(rt, ZERO);
738 CHECK_NE(rs, rt);
739 EmitI(0x16, rs, rt, imm16);
740}
741
742void Mips64Assembler::Bgezc(GpuRegister rt, uint16_t imm16) {
743 CHECK_NE(rt, ZERO);
744 EmitI(0x16, rt, rt, imm16);
745}
746
747void Mips64Assembler::Blezc(GpuRegister rt, uint16_t imm16) {
748 CHECK_NE(rt, ZERO);
749 EmitI(0x16, static_cast<GpuRegister>(0), rt, imm16);
750}
751
752void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
753 CHECK_NE(rs, ZERO);
754 CHECK_NE(rt, ZERO);
755 CHECK_NE(rs, rt);
756 EmitI(0x7, rs, rt, imm16);
757}
758
759void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
760 CHECK_NE(rs, ZERO);
761 CHECK_NE(rt, ZERO);
762 CHECK_NE(rs, rt);
763 EmitI(0x6, rs, rt, imm16);
764}
765
766void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
767 CHECK_NE(rs, ZERO);
768 CHECK_NE(rt, ZERO);
769 CHECK_NE(rs, rt);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700770 EmitI(0x8, std::min(rs, rt), std::max(rs, rt), imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700771}
772
773void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
774 CHECK_NE(rs, ZERO);
775 CHECK_NE(rt, ZERO);
776 CHECK_NE(rs, rt);
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700777 EmitI(0x18, std::min(rs, rt), std::max(rs, rt), imm16);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700778}
779
780void Mips64Assembler::Beqzc(GpuRegister rs, uint32_t imm21) {
781 CHECK_NE(rs, ZERO);
782 EmitI21(0x36, rs, imm21);
783}
784
785void Mips64Assembler::Bnezc(GpuRegister rs, uint32_t imm21) {
786 CHECK_NE(rs, ZERO);
787 EmitI21(0x3E, rs, imm21);
Andreas Gampe57b34292015-01-14 15:45:59 -0800788}
789
Alexey Frunze299a9392015-12-08 16:08:02 -0800790void Mips64Assembler::Bc1eqz(FpuRegister ft, uint16_t imm16) {
791 EmitFI(0x11, 0x9, ft, imm16);
792}
793
794void Mips64Assembler::Bc1nez(FpuRegister ft, uint16_t imm16) {
795 EmitFI(0x11, 0xD, ft, imm16);
796}
797
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700798void Mips64Assembler::EmitBcondc(BranchCondition cond,
799 GpuRegister rs,
800 GpuRegister rt,
801 uint32_t imm16_21) {
802 switch (cond) {
803 case kCondLT:
804 Bltc(rs, rt, imm16_21);
805 break;
806 case kCondGE:
807 Bgec(rs, rt, imm16_21);
808 break;
809 case kCondLE:
810 Bgec(rt, rs, imm16_21);
811 break;
812 case kCondGT:
813 Bltc(rt, rs, imm16_21);
814 break;
815 case kCondLTZ:
816 CHECK_EQ(rt, ZERO);
817 Bltzc(rs, imm16_21);
818 break;
819 case kCondGEZ:
820 CHECK_EQ(rt, ZERO);
821 Bgezc(rs, imm16_21);
822 break;
823 case kCondLEZ:
824 CHECK_EQ(rt, ZERO);
825 Blezc(rs, imm16_21);
826 break;
827 case kCondGTZ:
828 CHECK_EQ(rt, ZERO);
829 Bgtzc(rs, imm16_21);
830 break;
831 case kCondEQ:
832 Beqc(rs, rt, imm16_21);
833 break;
834 case kCondNE:
835 Bnec(rs, rt, imm16_21);
836 break;
837 case kCondEQZ:
838 CHECK_EQ(rt, ZERO);
839 Beqzc(rs, imm16_21);
840 break;
841 case kCondNEZ:
842 CHECK_EQ(rt, ZERO);
843 Bnezc(rs, imm16_21);
844 break;
845 case kCondLTU:
846 Bltuc(rs, rt, imm16_21);
847 break;
848 case kCondGEU:
849 Bgeuc(rs, rt, imm16_21);
850 break;
Alexey Frunze299a9392015-12-08 16:08:02 -0800851 case kCondF:
852 CHECK_EQ(rt, ZERO);
853 Bc1eqz(static_cast<FpuRegister>(rs), imm16_21);
854 break;
855 case kCondT:
856 CHECK_EQ(rt, ZERO);
857 Bc1nez(static_cast<FpuRegister>(rs), imm16_21);
858 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700859 case kUncond:
860 LOG(FATAL) << "Unexpected branch condition " << cond;
861 UNREACHABLE();
862 }
863}
864
Andreas Gampe57b34292015-01-14 15:45:59 -0800865void Mips64Assembler::AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
866 EmitFR(0x11, 0x10, ft, fs, fd, 0x0);
867}
868
869void Mips64Assembler::SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
870 EmitFR(0x11, 0x10, ft, fs, fd, 0x1);
871}
872
873void Mips64Assembler::MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
874 EmitFR(0x11, 0x10, ft, fs, fd, 0x2);
875}
876
877void Mips64Assembler::DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
878 EmitFR(0x11, 0x10, ft, fs, fd, 0x3);
879}
880
881void Mips64Assembler::AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700882 EmitFR(0x11, 0x11, ft, fs, fd, 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -0800883}
884
885void Mips64Assembler::SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700886 EmitFR(0x11, 0x11, ft, fs, fd, 0x1);
Andreas Gampe57b34292015-01-14 15:45:59 -0800887}
888
889void Mips64Assembler::MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700890 EmitFR(0x11, 0x11, ft, fs, fd, 0x2);
Andreas Gampe57b34292015-01-14 15:45:59 -0800891}
892
893void Mips64Assembler::DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700894 EmitFR(0x11, 0x11, ft, fs, fd, 0x3);
Andreas Gampe57b34292015-01-14 15:45:59 -0800895}
896
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700897void Mips64Assembler::SqrtS(FpuRegister fd, FpuRegister fs) {
898 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x4);
899}
900
901void Mips64Assembler::SqrtD(FpuRegister fd, FpuRegister fs) {
902 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x4);
903}
904
905void Mips64Assembler::AbsS(FpuRegister fd, FpuRegister fs) {
906 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x5);
907}
908
909void Mips64Assembler::AbsD(FpuRegister fd, FpuRegister fs) {
910 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x5);
911}
912
Andreas Gampe57b34292015-01-14 15:45:59 -0800913void Mips64Assembler::MovS(FpuRegister fd, FpuRegister fs) {
914 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x6);
915}
916
917void Mips64Assembler::MovD(FpuRegister fd, FpuRegister fs) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700918 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x6);
919}
920
921void Mips64Assembler::NegS(FpuRegister fd, FpuRegister fs) {
922 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x7);
923}
924
925void Mips64Assembler::NegD(FpuRegister fd, FpuRegister fs) {
926 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x7);
927}
928
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700929void Mips64Assembler::RoundLS(FpuRegister fd, FpuRegister fs) {
930 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x8);
931}
932
933void Mips64Assembler::RoundLD(FpuRegister fd, FpuRegister fs) {
934 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x8);
935}
936
937void Mips64Assembler::RoundWS(FpuRegister fd, FpuRegister fs) {
938 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xc);
939}
940
941void Mips64Assembler::RoundWD(FpuRegister fd, FpuRegister fs) {
942 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xc);
943}
944
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800945void Mips64Assembler::TruncLS(FpuRegister fd, FpuRegister fs) {
946 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x9);
947}
948
949void Mips64Assembler::TruncLD(FpuRegister fd, FpuRegister fs) {
950 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x9);
951}
952
953void Mips64Assembler::TruncWS(FpuRegister fd, FpuRegister fs) {
954 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xd);
955}
956
957void Mips64Assembler::TruncWD(FpuRegister fd, FpuRegister fs) {
958 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xd);
959}
960
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700961void Mips64Assembler::CeilLS(FpuRegister fd, FpuRegister fs) {
962 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xa);
963}
964
965void Mips64Assembler::CeilLD(FpuRegister fd, FpuRegister fs) {
966 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xa);
967}
968
969void Mips64Assembler::CeilWS(FpuRegister fd, FpuRegister fs) {
970 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xe);
971}
972
973void Mips64Assembler::CeilWD(FpuRegister fd, FpuRegister fs) {
974 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xe);
975}
976
977void Mips64Assembler::FloorLS(FpuRegister fd, FpuRegister fs) {
978 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xb);
979}
980
981void Mips64Assembler::FloorLD(FpuRegister fd, FpuRegister fs) {
982 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xb);
983}
984
985void Mips64Assembler::FloorWS(FpuRegister fd, FpuRegister fs) {
986 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xf);
987}
988
989void Mips64Assembler::FloorWD(FpuRegister fd, FpuRegister fs) {
990 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xf);
991}
992
993void Mips64Assembler::SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
994 EmitFR(0x11, 0x10, ft, fs, fd, 0x10);
995}
996
997void Mips64Assembler::SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
998 EmitFR(0x11, 0x11, ft, fs, fd, 0x10);
999}
1000
1001void Mips64Assembler::RintS(FpuRegister fd, FpuRegister fs) {
1002 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1a);
1003}
1004
1005void Mips64Assembler::RintD(FpuRegister fd, FpuRegister fs) {
1006 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1a);
1007}
1008
1009void Mips64Assembler::ClassS(FpuRegister fd, FpuRegister fs) {
1010 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1b);
1011}
1012
1013void Mips64Assembler::ClassD(FpuRegister fd, FpuRegister fs) {
1014 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1b);
1015}
1016
1017void Mips64Assembler::MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1018 EmitFR(0x11, 0x10, ft, fs, fd, 0x1c);
1019}
1020
1021void Mips64Assembler::MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1022 EmitFR(0x11, 0x11, ft, fs, fd, 0x1c);
1023}
1024
1025void Mips64Assembler::MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1026 EmitFR(0x11, 0x10, ft, fs, fd, 0x1e);
1027}
1028
1029void Mips64Assembler::MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1030 EmitFR(0x11, 0x11, ft, fs, fd, 0x1e);
1031}
1032
Alexey Frunze299a9392015-12-08 16:08:02 -08001033void Mips64Assembler::CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1034 EmitFR(0x11, 0x14, ft, fs, fd, 0x01);
1035}
1036
1037void Mips64Assembler::CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1038 EmitFR(0x11, 0x14, ft, fs, fd, 0x02);
1039}
1040
1041void Mips64Assembler::CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1042 EmitFR(0x11, 0x14, ft, fs, fd, 0x03);
1043}
1044
1045void Mips64Assembler::CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1046 EmitFR(0x11, 0x14, ft, fs, fd, 0x04);
1047}
1048
1049void Mips64Assembler::CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1050 EmitFR(0x11, 0x14, ft, fs, fd, 0x05);
1051}
1052
1053void Mips64Assembler::CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1054 EmitFR(0x11, 0x14, ft, fs, fd, 0x06);
1055}
1056
1057void Mips64Assembler::CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1058 EmitFR(0x11, 0x14, ft, fs, fd, 0x07);
1059}
1060
1061void Mips64Assembler::CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1062 EmitFR(0x11, 0x14, ft, fs, fd, 0x11);
1063}
1064
1065void Mips64Assembler::CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1066 EmitFR(0x11, 0x14, ft, fs, fd, 0x12);
1067}
1068
1069void Mips64Assembler::CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1070 EmitFR(0x11, 0x14, ft, fs, fd, 0x13);
1071}
1072
1073void Mips64Assembler::CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1074 EmitFR(0x11, 0x15, ft, fs, fd, 0x01);
1075}
1076
1077void Mips64Assembler::CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1078 EmitFR(0x11, 0x15, ft, fs, fd, 0x02);
1079}
1080
1081void Mips64Assembler::CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1082 EmitFR(0x11, 0x15, ft, fs, fd, 0x03);
1083}
1084
1085void Mips64Assembler::CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1086 EmitFR(0x11, 0x15, ft, fs, fd, 0x04);
1087}
1088
1089void Mips64Assembler::CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1090 EmitFR(0x11, 0x15, ft, fs, fd, 0x05);
1091}
1092
1093void Mips64Assembler::CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1094 EmitFR(0x11, 0x15, ft, fs, fd, 0x06);
1095}
1096
1097void Mips64Assembler::CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1098 EmitFR(0x11, 0x15, ft, fs, fd, 0x07);
1099}
1100
1101void Mips64Assembler::CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1102 EmitFR(0x11, 0x15, ft, fs, fd, 0x11);
1103}
1104
1105void Mips64Assembler::CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1106 EmitFR(0x11, 0x15, ft, fs, fd, 0x12);
1107}
1108
1109void Mips64Assembler::CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1110 EmitFR(0x11, 0x15, ft, fs, fd, 0x13);
1111}
1112
Alexey Frunze4dda3372015-06-01 18:31:49 -07001113void Mips64Assembler::Cvtsw(FpuRegister fd, FpuRegister fs) {
1114 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x20);
1115}
1116
1117void Mips64Assembler::Cvtdw(FpuRegister fd, FpuRegister fs) {
1118 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x21);
1119}
1120
1121void Mips64Assembler::Cvtsd(FpuRegister fd, FpuRegister fs) {
1122 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x20);
1123}
1124
1125void Mips64Assembler::Cvtds(FpuRegister fd, FpuRegister fs) {
1126 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x21);
Andreas Gampe57b34292015-01-14 15:45:59 -08001127}
1128
Chris Larsen51417632015-10-02 13:24:25 -07001129void Mips64Assembler::Cvtsl(FpuRegister fd, FpuRegister fs) {
1130 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x20);
1131}
1132
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001133void Mips64Assembler::Cvtdl(FpuRegister fd, FpuRegister fs) {
1134 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x21);
1135}
1136
Andreas Gampe57b34292015-01-14 15:45:59 -08001137void Mips64Assembler::Mfc1(GpuRegister rt, FpuRegister fs) {
1138 EmitFR(0x11, 0x00, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1139}
1140
Lazar Trsicd9672662015-09-03 17:33:01 +02001141void Mips64Assembler::Mfhc1(GpuRegister rt, FpuRegister fs) {
1142 EmitFR(0x11, 0x03, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1143}
1144
Alexey Frunze4dda3372015-06-01 18:31:49 -07001145void Mips64Assembler::Mtc1(GpuRegister rt, FpuRegister fs) {
1146 EmitFR(0x11, 0x04, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1147}
1148
Lazar Trsicd9672662015-09-03 17:33:01 +02001149void Mips64Assembler::Mthc1(GpuRegister rt, FpuRegister fs) {
1150 EmitFR(0x11, 0x07, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1151}
1152
Alexey Frunze4dda3372015-06-01 18:31:49 -07001153void Mips64Assembler::Dmfc1(GpuRegister rt, FpuRegister fs) {
1154 EmitFR(0x11, 0x01, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1155}
1156
1157void Mips64Assembler::Dmtc1(GpuRegister rt, FpuRegister fs) {
1158 EmitFR(0x11, 0x05, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -08001159}
1160
1161void Mips64Assembler::Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1162 EmitI(0x31, rs, static_cast<GpuRegister>(ft), imm16);
1163}
1164
1165void Mips64Assembler::Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1166 EmitI(0x35, rs, static_cast<GpuRegister>(ft), imm16);
1167}
1168
1169void Mips64Assembler::Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1170 EmitI(0x39, rs, static_cast<GpuRegister>(ft), imm16);
1171}
1172
1173void Mips64Assembler::Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1174 EmitI(0x3d, rs, static_cast<GpuRegister>(ft), imm16);
1175}
1176
1177void Mips64Assembler::Break() {
1178 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
1179 static_cast<GpuRegister>(0), 0, 0xD);
1180}
1181
1182void Mips64Assembler::Nop() {
1183 EmitR(0x0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
1184 static_cast<GpuRegister>(0), 0, 0x0);
1185}
1186
Alexey Frunze4dda3372015-06-01 18:31:49 -07001187void Mips64Assembler::Move(GpuRegister rd, GpuRegister rs) {
1188 Or(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001189}
1190
Alexey Frunze4dda3372015-06-01 18:31:49 -07001191void Mips64Assembler::Clear(GpuRegister rd) {
1192 Move(rd, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001193}
1194
Alexey Frunze4dda3372015-06-01 18:31:49 -07001195void Mips64Assembler::Not(GpuRegister rd, GpuRegister rs) {
1196 Nor(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001197}
1198
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001199void Mips64Assembler::AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001200 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001201 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1e);
1202}
1203
1204void Mips64Assembler::OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001205 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001206 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1e);
1207}
1208
1209void Mips64Assembler::NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001210 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001211 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1e);
1212}
1213
1214void Mips64Assembler::XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001215 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001216 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1e);
1217}
1218
1219void Mips64Assembler::AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001220 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001221 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xe);
1222}
1223
1224void Mips64Assembler::AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001225 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001226 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xe);
1227}
1228
1229void Mips64Assembler::AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001230 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001231 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xe);
1232}
1233
1234void Mips64Assembler::AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001235 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001236 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xe);
1237}
1238
1239void Mips64Assembler::SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001240 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001241 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xe);
1242}
1243
1244void Mips64Assembler::SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001245 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001246 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xe);
1247}
1248
1249void Mips64Assembler::SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001250 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001251 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xe);
1252}
1253
1254void Mips64Assembler::SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001255 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001256 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xe);
1257}
1258
1259void Mips64Assembler::MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001260 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001261 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x12);
1262}
1263
1264void Mips64Assembler::MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001265 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001266 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x12);
1267}
1268
1269void Mips64Assembler::MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001270 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001271 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x12);
1272}
1273
1274void Mips64Assembler::MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001275 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001276 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x12);
1277}
1278
1279void Mips64Assembler::Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001280 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001281 EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x12);
1282}
1283
1284void Mips64Assembler::Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001285 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001286 EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x12);
1287}
1288
1289void Mips64Assembler::Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001290 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001291 EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x12);
1292}
1293
1294void Mips64Assembler::Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001295 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001296 EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x12);
1297}
1298
1299void Mips64Assembler::Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001300 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001301 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x12);
1302}
1303
1304void Mips64Assembler::Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001305 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001306 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x12);
1307}
1308
1309void Mips64Assembler::Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001310 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001311 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x12);
1312}
1313
1314void Mips64Assembler::Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001315 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001316 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x12);
1317}
1318
1319void Mips64Assembler::Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001320 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001321 EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x12);
1322}
1323
1324void Mips64Assembler::Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001325 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001326 EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x12);
1327}
1328
1329void Mips64Assembler::Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001330 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001331 EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x12);
1332}
1333
1334void Mips64Assembler::Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001335 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001336 EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x12);
1337}
1338
1339void Mips64Assembler::Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001340 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001341 EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x12);
1342}
1343
1344void Mips64Assembler::Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001345 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001346 EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x12);
1347}
1348
1349void Mips64Assembler::Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001350 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001351 EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x12);
1352}
1353
1354void Mips64Assembler::Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001355 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001356 EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x12);
1357}
1358
Goran Jakovljevic80248d72017-04-20 11:55:47 +02001359void Mips64Assembler::Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1360 CHECK(HasMsa());
1361 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x10);
1362}
1363
1364void Mips64Assembler::Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1365 CHECK(HasMsa());
1366 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x10);
1367}
1368
1369void Mips64Assembler::Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1370 CHECK(HasMsa());
1371 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x10);
1372}
1373
1374void Mips64Assembler::Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1375 CHECK(HasMsa());
1376 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x10);
1377}
1378
1379void Mips64Assembler::Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1380 CHECK(HasMsa());
1381 EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x10);
1382}
1383
1384void Mips64Assembler::Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1385 CHECK(HasMsa());
1386 EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x10);
1387}
1388
1389void Mips64Assembler::Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1390 CHECK(HasMsa());
1391 EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x10);
1392}
1393
1394void Mips64Assembler::Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1395 CHECK(HasMsa());
1396 EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x10);
1397}
1398
1399void Mips64Assembler::Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1400 CHECK(HasMsa());
1401 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x10);
1402}
1403
1404void Mips64Assembler::Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1405 CHECK(HasMsa());
1406 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x10);
1407}
1408
1409void Mips64Assembler::Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1410 CHECK(HasMsa());
1411 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x10);
1412}
1413
1414void Mips64Assembler::Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1415 CHECK(HasMsa());
1416 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x10);
1417}
1418
1419void Mips64Assembler::Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1420 CHECK(HasMsa());
1421 EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x10);
1422}
1423
1424void Mips64Assembler::Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1425 CHECK(HasMsa());
1426 EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x10);
1427}
1428
1429void Mips64Assembler::Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1430 CHECK(HasMsa());
1431 EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x10);
1432}
1433
1434void Mips64Assembler::Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1435 CHECK(HasMsa());
1436 EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x10);
1437}
1438
1439void Mips64Assembler::Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1440 CHECK(HasMsa());
1441 EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x10);
1442}
1443
1444void Mips64Assembler::Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1445 CHECK(HasMsa());
1446 EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x10);
1447}
1448
1449void Mips64Assembler::Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1450 CHECK(HasMsa());
1451 EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x10);
1452}
1453
1454void Mips64Assembler::Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1455 CHECK(HasMsa());
1456 EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x10);
1457}
1458
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001459void Mips64Assembler::FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001460 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001461 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1b);
1462}
1463
1464void Mips64Assembler::FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001465 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001466 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1b);
1467}
1468
1469void Mips64Assembler::FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001470 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001471 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1b);
1472}
1473
1474void Mips64Assembler::FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001475 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001476 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1b);
1477}
1478
1479void Mips64Assembler::FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001480 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001481 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x1b);
1482}
1483
1484void Mips64Assembler::FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001485 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001486 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x1b);
1487}
1488
1489void Mips64Assembler::FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001490 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001491 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x1b);
1492}
1493
1494void Mips64Assembler::FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001495 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001496 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x1b);
1497}
1498
1499void Mips64Assembler::Ffint_sW(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001500 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001501 EmitMsa2RF(0x19e, 0x0, ws, wd, 0x1e);
1502}
1503
1504void Mips64Assembler::Ffint_sD(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001505 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001506 EmitMsa2RF(0x19e, 0x1, ws, wd, 0x1e);
1507}
1508
1509void Mips64Assembler::Ftint_sW(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001510 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001511 EmitMsa2RF(0x19c, 0x0, ws, wd, 0x1e);
1512}
1513
1514void Mips64Assembler::Ftint_sD(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001515 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001516 EmitMsa2RF(0x19c, 0x1, ws, wd, 0x1e);
1517}
1518
1519void Mips64Assembler::SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001520 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001521 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xd);
1522}
1523
1524void Mips64Assembler::SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001525 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001526 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xd);
1527}
1528
1529void Mips64Assembler::SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001530 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001531 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xd);
1532}
1533
1534void Mips64Assembler::SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001535 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001536 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xd);
1537}
1538
1539void Mips64Assembler::SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001540 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001541 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xd);
1542}
1543
1544void Mips64Assembler::SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001545 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001546 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xd);
1547}
1548
1549void Mips64Assembler::SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001550 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001551 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xd);
1552}
1553
1554void Mips64Assembler::SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001555 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001556 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xd);
1557}
1558
1559void Mips64Assembler::SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001560 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001561 EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xd);
1562}
1563
1564void Mips64Assembler::SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001565 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001566 EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xd);
1567}
1568
1569void Mips64Assembler::SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001570 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001571 EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xd);
1572}
1573
1574void Mips64Assembler::SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001575 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001576 EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xd);
1577}
1578
1579void Mips64Assembler::SlliB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001580 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001581 CHECK(IsUint<3>(shamt3)) << shamt3;
1582 EmitMsaBIT(0x0, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1583}
1584
1585void Mips64Assembler::SlliH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001586 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001587 CHECK(IsUint<4>(shamt4)) << shamt4;
1588 EmitMsaBIT(0x0, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1589}
1590
1591void Mips64Assembler::SlliW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001592 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001593 CHECK(IsUint<5>(shamt5)) << shamt5;
1594 EmitMsaBIT(0x0, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1595}
1596
1597void Mips64Assembler::SlliD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001598 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001599 CHECK(IsUint<6>(shamt6)) << shamt6;
1600 EmitMsaBIT(0x0, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1601}
1602
1603void Mips64Assembler::SraiB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001604 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001605 CHECK(IsUint<3>(shamt3)) << shamt3;
1606 EmitMsaBIT(0x1, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1607}
1608
1609void Mips64Assembler::SraiH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001610 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001611 CHECK(IsUint<4>(shamt4)) << shamt4;
1612 EmitMsaBIT(0x1, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1613}
1614
1615void Mips64Assembler::SraiW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001616 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001617 CHECK(IsUint<5>(shamt5)) << shamt5;
1618 EmitMsaBIT(0x1, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1619}
1620
1621void Mips64Assembler::SraiD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001622 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001623 CHECK(IsUint<6>(shamt6)) << shamt6;
1624 EmitMsaBIT(0x1, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1625}
1626
1627void Mips64Assembler::SrliB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001628 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001629 CHECK(IsUint<3>(shamt3)) << shamt3;
1630 EmitMsaBIT(0x2, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1631}
1632
1633void Mips64Assembler::SrliH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001634 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001635 CHECK(IsUint<4>(shamt4)) << shamt4;
1636 EmitMsaBIT(0x2, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1637}
1638
1639void Mips64Assembler::SrliW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001640 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001641 CHECK(IsUint<5>(shamt5)) << shamt5;
1642 EmitMsaBIT(0x2, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1643}
1644
1645void Mips64Assembler::SrliD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001646 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001647 CHECK(IsUint<6>(shamt6)) << shamt6;
1648 EmitMsaBIT(0x2, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1649}
1650
1651void Mips64Assembler::MoveV(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001652 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001653 EmitMsaBIT(0x1, 0x3e, ws, wd, 0x19);
1654}
1655
1656void Mips64Assembler::SplatiB(VectorRegister wd, VectorRegister ws, int n4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001657 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001658 CHECK(IsUint<4>(n4)) << n4;
1659 EmitMsaELM(0x1, n4 | kMsaDfNByteMask, ws, wd, 0x19);
1660}
1661
1662void Mips64Assembler::SplatiH(VectorRegister wd, VectorRegister ws, int n3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001663 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001664 CHECK(IsUint<3>(n3)) << n3;
1665 EmitMsaELM(0x1, n3 | kMsaDfNHalfwordMask, ws, wd, 0x19);
1666}
1667
1668void Mips64Assembler::SplatiW(VectorRegister wd, VectorRegister ws, int n2) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001669 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001670 CHECK(IsUint<2>(n2)) << n2;
1671 EmitMsaELM(0x1, n2 | kMsaDfNWordMask, ws, wd, 0x19);
1672}
1673
1674void Mips64Assembler::SplatiD(VectorRegister wd, VectorRegister ws, int n1) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001675 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001676 CHECK(IsUint<1>(n1)) << n1;
1677 EmitMsaELM(0x1, n1 | kMsaDfNDoublewordMask, ws, wd, 0x19);
1678}
1679
1680void Mips64Assembler::FillB(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001681 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001682 EmitMsa2R(0xc0, 0x0, static_cast<VectorRegister>(rs), wd, 0x1e);
1683}
1684
1685void Mips64Assembler::FillH(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001686 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001687 EmitMsa2R(0xc0, 0x1, static_cast<VectorRegister>(rs), wd, 0x1e);
1688}
1689
1690void Mips64Assembler::FillW(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001691 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001692 EmitMsa2R(0xc0, 0x2, static_cast<VectorRegister>(rs), wd, 0x1e);
1693}
1694
1695void Mips64Assembler::FillD(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001696 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001697 EmitMsa2R(0xc0, 0x3, static_cast<VectorRegister>(rs), wd, 0x1e);
1698}
1699
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001700void Mips64Assembler::LdiB(VectorRegister wd, int imm8) {
1701 CHECK(HasMsa());
1702 CHECK(IsInt<8>(imm8)) << imm8;
1703 EmitMsaI10(0x6, 0x0, imm8 & kMsaS10Mask, wd, 0x7);
1704}
1705
1706void Mips64Assembler::LdiH(VectorRegister wd, int imm10) {
1707 CHECK(HasMsa());
1708 CHECK(IsInt<10>(imm10)) << imm10;
1709 EmitMsaI10(0x6, 0x1, imm10 & kMsaS10Mask, wd, 0x7);
1710}
1711
1712void Mips64Assembler::LdiW(VectorRegister wd, int imm10) {
1713 CHECK(HasMsa());
1714 CHECK(IsInt<10>(imm10)) << imm10;
1715 EmitMsaI10(0x6, 0x2, imm10 & kMsaS10Mask, wd, 0x7);
1716}
1717
1718void Mips64Assembler::LdiD(VectorRegister wd, int imm10) {
1719 CHECK(HasMsa());
1720 CHECK(IsInt<10>(imm10)) << imm10;
1721 EmitMsaI10(0x6, 0x3, imm10 & kMsaS10Mask, wd, 0x7);
1722}
1723
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001724void Mips64Assembler::LdB(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001725 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001726 CHECK(IsInt<10>(offset)) << offset;
1727 EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x8, 0x0);
1728}
1729
1730void Mips64Assembler::LdH(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001731 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001732 CHECK(IsInt<11>(offset)) << offset;
1733 CHECK_ALIGNED(offset, kMips64HalfwordSize);
1734 EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x8, 0x1);
1735}
1736
1737void Mips64Assembler::LdW(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001738 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001739 CHECK(IsInt<12>(offset)) << offset;
1740 CHECK_ALIGNED(offset, kMips64WordSize);
1741 EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x8, 0x2);
1742}
1743
1744void Mips64Assembler::LdD(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001745 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001746 CHECK(IsInt<13>(offset)) << offset;
1747 CHECK_ALIGNED(offset, kMips64DoublewordSize);
1748 EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x8, 0x3);
1749}
1750
1751void Mips64Assembler::StB(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001752 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001753 CHECK(IsInt<10>(offset)) << offset;
1754 EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x9, 0x0);
1755}
1756
1757void Mips64Assembler::StH(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001758 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001759 CHECK(IsInt<11>(offset)) << offset;
1760 CHECK_ALIGNED(offset, kMips64HalfwordSize);
1761 EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x9, 0x1);
1762}
1763
1764void Mips64Assembler::StW(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001765 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001766 CHECK(IsInt<12>(offset)) << offset;
1767 CHECK_ALIGNED(offset, kMips64WordSize);
1768 EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x9, 0x2);
1769}
1770
1771void Mips64Assembler::StD(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001772 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001773 CHECK(IsInt<13>(offset)) << offset;
1774 CHECK_ALIGNED(offset, kMips64DoublewordSize);
1775 EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x9, 0x3);
1776}
1777
Goran Jakovljevic38370112017-05-10 14:30:28 +02001778void Mips64Assembler::IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1779 CHECK(HasMsa());
1780 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x14);
1781}
1782
1783void Mips64Assembler::IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1784 CHECK(HasMsa());
1785 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x14);
1786}
1787
1788void Mips64Assembler::IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1789 CHECK(HasMsa());
1790 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x14);
1791}
1792
1793void Mips64Assembler::IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1794 CHECK(HasMsa());
1795 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x14);
1796}
1797
Alexey Frunze4dda3372015-06-01 18:31:49 -07001798void Mips64Assembler::LoadConst32(GpuRegister rd, int32_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001799 TemplateLoadConst32(this, rd, value);
1800}
1801
1802// This function is only used for testing purposes.
1803void Mips64Assembler::RecordLoadConst64Path(int value ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001804}
1805
Alexey Frunze4dda3372015-06-01 18:31:49 -07001806void Mips64Assembler::LoadConst64(GpuRegister rd, int64_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001807 TemplateLoadConst64(this, rd, value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001808}
1809
Alexey Frunze0960ac52016-12-20 17:24:59 -08001810void Mips64Assembler::Addiu32(GpuRegister rt, GpuRegister rs, int32_t value) {
1811 if (IsInt<16>(value)) {
1812 Addiu(rt, rs, value);
1813 } else {
1814 int16_t high = High16Bits(value);
1815 int16_t low = Low16Bits(value);
1816 high += (low < 0) ? 1 : 0; // Account for sign extension in addiu.
1817 Aui(rt, rs, high);
1818 if (low != 0) {
1819 Addiu(rt, rt, low);
1820 }
1821 }
1822}
1823
Alexey Frunze15958152017-02-09 19:08:30 -08001824// TODO: don't use rtmp, use daui, dahi, dati.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001825void Mips64Assembler::Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp) {
Chris Larsen5863f852017-03-23 15:41:37 -07001826 CHECK_NE(rs, rtmp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001827 if (IsInt<16>(value)) {
1828 Daddiu(rt, rs, value);
1829 } else {
1830 LoadConst64(rtmp, value);
1831 Daddu(rt, rs, rtmp);
1832 }
Andreas Gampe57b34292015-01-14 15:45:59 -08001833}
1834
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001835void Mips64Assembler::Branch::InitShortOrLong(Mips64Assembler::Branch::OffsetBits offset_size,
1836 Mips64Assembler::Branch::Type short_type,
1837 Mips64Assembler::Branch::Type long_type) {
1838 type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
1839}
Alexey Frunze4dda3372015-06-01 18:31:49 -07001840
Alexey Frunze19f6c692016-11-30 19:19:55 -08001841void Mips64Assembler::Branch::InitializeType(Type initial_type) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001842 OffsetBits offset_size = GetOffsetSizeNeeded(location_, target_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001843 switch (initial_type) {
1844 case kLabel:
1845 case kLiteral:
1846 case kLiteralUnsigned:
1847 case kLiteralLong:
1848 CHECK(!IsResolved());
1849 type_ = initial_type;
1850 break;
1851 case kCall:
1852 InitShortOrLong(offset_size, kCall, kLongCall);
1853 break;
1854 case kCondBranch:
1855 switch (condition_) {
1856 case kUncond:
1857 InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
1858 break;
1859 case kCondEQZ:
1860 case kCondNEZ:
1861 // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
1862 type_ = (offset_size <= kOffset23) ? kCondBranch : kLongCondBranch;
1863 break;
1864 default:
1865 InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
1866 break;
1867 }
1868 break;
1869 default:
1870 LOG(FATAL) << "Unexpected branch type " << initial_type;
1871 UNREACHABLE();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001872 }
1873 old_type_ = type_;
1874}
1875
1876bool Mips64Assembler::Branch::IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs) {
1877 switch (condition) {
1878 case kCondLT:
1879 case kCondGT:
1880 case kCondNE:
1881 case kCondLTU:
1882 return lhs == rhs;
1883 default:
1884 return false;
1885 }
1886}
1887
1888bool Mips64Assembler::Branch::IsUncond(BranchCondition condition,
1889 GpuRegister lhs,
1890 GpuRegister rhs) {
1891 switch (condition) {
1892 case kUncond:
1893 return true;
1894 case kCondGE:
1895 case kCondLE:
1896 case kCondEQ:
1897 case kCondGEU:
1898 return lhs == rhs;
1899 default:
1900 return false;
1901 }
1902}
1903
Alexey Frunze19f6c692016-11-30 19:19:55 -08001904Mips64Assembler::Branch::Branch(uint32_t location, uint32_t target, bool is_call)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001905 : old_location_(location),
1906 location_(location),
1907 target_(target),
1908 lhs_reg_(ZERO),
1909 rhs_reg_(ZERO),
1910 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001911 InitializeType(is_call ? kCall : kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001912}
1913
1914Mips64Assembler::Branch::Branch(uint32_t location,
1915 uint32_t target,
1916 Mips64Assembler::BranchCondition condition,
1917 GpuRegister lhs_reg,
1918 GpuRegister rhs_reg)
1919 : old_location_(location),
1920 location_(location),
1921 target_(target),
1922 lhs_reg_(lhs_reg),
1923 rhs_reg_(rhs_reg),
1924 condition_(condition) {
1925 CHECK_NE(condition, kUncond);
1926 switch (condition) {
1927 case kCondEQ:
1928 case kCondNE:
1929 case kCondLT:
1930 case kCondGE:
1931 case kCondLE:
1932 case kCondGT:
1933 case kCondLTU:
1934 case kCondGEU:
1935 CHECK_NE(lhs_reg, ZERO);
1936 CHECK_NE(rhs_reg, ZERO);
1937 break;
1938 case kCondLTZ:
1939 case kCondGEZ:
1940 case kCondLEZ:
1941 case kCondGTZ:
1942 case kCondEQZ:
1943 case kCondNEZ:
1944 CHECK_NE(lhs_reg, ZERO);
1945 CHECK_EQ(rhs_reg, ZERO);
1946 break;
Alexey Frunze299a9392015-12-08 16:08:02 -08001947 case kCondF:
1948 case kCondT:
1949 CHECK_EQ(rhs_reg, ZERO);
1950 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001951 case kUncond:
1952 UNREACHABLE();
1953 }
1954 CHECK(!IsNop(condition, lhs_reg, rhs_reg));
1955 if (IsUncond(condition, lhs_reg, rhs_reg)) {
1956 // Branch condition is always true, make the branch unconditional.
1957 condition_ = kUncond;
1958 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08001959 InitializeType(kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001960}
1961
Alexey Frunze19f6c692016-11-30 19:19:55 -08001962Mips64Assembler::Branch::Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001963 : old_location_(location),
1964 location_(location),
Alexey Frunze19f6c692016-11-30 19:19:55 -08001965 target_(kUnresolved),
1966 lhs_reg_(dest_reg),
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001967 rhs_reg_(ZERO),
1968 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001969 CHECK_NE(dest_reg, ZERO);
1970 InitializeType(label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001971}
1972
1973Mips64Assembler::BranchCondition Mips64Assembler::Branch::OppositeCondition(
1974 Mips64Assembler::BranchCondition cond) {
1975 switch (cond) {
1976 case kCondLT:
1977 return kCondGE;
1978 case kCondGE:
1979 return kCondLT;
1980 case kCondLE:
1981 return kCondGT;
1982 case kCondGT:
1983 return kCondLE;
1984 case kCondLTZ:
1985 return kCondGEZ;
1986 case kCondGEZ:
1987 return kCondLTZ;
1988 case kCondLEZ:
1989 return kCondGTZ;
1990 case kCondGTZ:
1991 return kCondLEZ;
1992 case kCondEQ:
1993 return kCondNE;
1994 case kCondNE:
1995 return kCondEQ;
1996 case kCondEQZ:
1997 return kCondNEZ;
1998 case kCondNEZ:
1999 return kCondEQZ;
2000 case kCondLTU:
2001 return kCondGEU;
2002 case kCondGEU:
2003 return kCondLTU;
Alexey Frunze299a9392015-12-08 16:08:02 -08002004 case kCondF:
2005 return kCondT;
2006 case kCondT:
2007 return kCondF;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002008 case kUncond:
2009 LOG(FATAL) << "Unexpected branch condition " << cond;
2010 }
2011 UNREACHABLE();
2012}
2013
2014Mips64Assembler::Branch::Type Mips64Assembler::Branch::GetType() const {
2015 return type_;
2016}
2017
2018Mips64Assembler::BranchCondition Mips64Assembler::Branch::GetCondition() const {
2019 return condition_;
2020}
2021
2022GpuRegister Mips64Assembler::Branch::GetLeftRegister() const {
2023 return lhs_reg_;
2024}
2025
2026GpuRegister Mips64Assembler::Branch::GetRightRegister() const {
2027 return rhs_reg_;
2028}
2029
2030uint32_t Mips64Assembler::Branch::GetTarget() const {
2031 return target_;
2032}
2033
2034uint32_t Mips64Assembler::Branch::GetLocation() const {
2035 return location_;
2036}
2037
2038uint32_t Mips64Assembler::Branch::GetOldLocation() const {
2039 return old_location_;
2040}
2041
2042uint32_t Mips64Assembler::Branch::GetLength() const {
2043 return branch_info_[type_].length;
2044}
2045
2046uint32_t Mips64Assembler::Branch::GetOldLength() const {
2047 return branch_info_[old_type_].length;
2048}
2049
2050uint32_t Mips64Assembler::Branch::GetSize() const {
2051 return GetLength() * sizeof(uint32_t);
2052}
2053
2054uint32_t Mips64Assembler::Branch::GetOldSize() const {
2055 return GetOldLength() * sizeof(uint32_t);
2056}
2057
2058uint32_t Mips64Assembler::Branch::GetEndLocation() const {
2059 return GetLocation() + GetSize();
2060}
2061
2062uint32_t Mips64Assembler::Branch::GetOldEndLocation() const {
2063 return GetOldLocation() + GetOldSize();
2064}
2065
2066bool Mips64Assembler::Branch::IsLong() const {
2067 switch (type_) {
2068 // Short branches.
2069 case kUncondBranch:
2070 case kCondBranch:
2071 case kCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002072 // Near label.
2073 case kLabel:
2074 // Near literals.
2075 case kLiteral:
2076 case kLiteralUnsigned:
2077 case kLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002078 return false;
2079 // Long branches.
2080 case kLongUncondBranch:
2081 case kLongCondBranch:
2082 case kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002083 // Far label.
2084 case kFarLabel:
2085 // Far literals.
2086 case kFarLiteral:
2087 case kFarLiteralUnsigned:
2088 case kFarLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002089 return true;
2090 }
2091 UNREACHABLE();
2092}
2093
2094bool Mips64Assembler::Branch::IsResolved() const {
2095 return target_ != kUnresolved;
2096}
2097
2098Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSize() const {
2099 OffsetBits offset_size =
2100 (type_ == kCondBranch && (condition_ == kCondEQZ || condition_ == kCondNEZ))
2101 ? kOffset23
2102 : branch_info_[type_].offset_size;
2103 return offset_size;
2104}
2105
2106Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSizeNeeded(uint32_t location,
2107 uint32_t target) {
2108 // For unresolved targets assume the shortest encoding
2109 // (later it will be made longer if needed).
2110 if (target == kUnresolved)
2111 return kOffset16;
2112 int64_t distance = static_cast<int64_t>(target) - location;
2113 // To simplify calculations in composite branches consisting of multiple instructions
2114 // bump up the distance by a value larger than the max byte size of a composite branch.
2115 distance += (distance >= 0) ? kMaxBranchSize : -kMaxBranchSize;
2116 if (IsInt<kOffset16>(distance))
2117 return kOffset16;
2118 else if (IsInt<kOffset18>(distance))
2119 return kOffset18;
2120 else if (IsInt<kOffset21>(distance))
2121 return kOffset21;
2122 else if (IsInt<kOffset23>(distance))
2123 return kOffset23;
2124 else if (IsInt<kOffset28>(distance))
2125 return kOffset28;
2126 return kOffset32;
2127}
2128
2129void Mips64Assembler::Branch::Resolve(uint32_t target) {
2130 target_ = target;
2131}
2132
2133void Mips64Assembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
2134 if (location_ > expand_location) {
2135 location_ += delta;
2136 }
2137 if (!IsResolved()) {
2138 return; // Don't know the target yet.
2139 }
2140 if (target_ > expand_location) {
2141 target_ += delta;
2142 }
2143}
2144
2145void Mips64Assembler::Branch::PromoteToLong() {
2146 switch (type_) {
2147 // Short branches.
2148 case kUncondBranch:
2149 type_ = kLongUncondBranch;
2150 break;
2151 case kCondBranch:
2152 type_ = kLongCondBranch;
2153 break;
2154 case kCall:
2155 type_ = kLongCall;
2156 break;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002157 // Near label.
2158 case kLabel:
2159 type_ = kFarLabel;
2160 break;
2161 // Near literals.
2162 case kLiteral:
2163 type_ = kFarLiteral;
2164 break;
2165 case kLiteralUnsigned:
2166 type_ = kFarLiteralUnsigned;
2167 break;
2168 case kLiteralLong:
2169 type_ = kFarLiteralLong;
2170 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002171 default:
2172 // Note: 'type_' is already long.
2173 break;
2174 }
2175 CHECK(IsLong());
2176}
2177
2178uint32_t Mips64Assembler::Branch::PromoteIfNeeded(uint32_t max_short_distance) {
2179 // If the branch is still unresolved or already long, nothing to do.
2180 if (IsLong() || !IsResolved()) {
2181 return 0;
2182 }
2183 // Promote the short branch to long if the offset size is too small
2184 // to hold the distance between location_ and target_.
2185 if (GetOffsetSizeNeeded(location_, target_) > GetOffsetSize()) {
2186 PromoteToLong();
2187 uint32_t old_size = GetOldSize();
2188 uint32_t new_size = GetSize();
2189 CHECK_GT(new_size, old_size);
2190 return new_size - old_size;
2191 }
2192 // The following logic is for debugging/testing purposes.
2193 // Promote some short branches to long when it's not really required.
2194 if (UNLIKELY(max_short_distance != std::numeric_limits<uint32_t>::max())) {
2195 int64_t distance = static_cast<int64_t>(target_) - location_;
2196 distance = (distance >= 0) ? distance : -distance;
2197 if (distance >= max_short_distance) {
2198 PromoteToLong();
2199 uint32_t old_size = GetOldSize();
2200 uint32_t new_size = GetSize();
2201 CHECK_GT(new_size, old_size);
2202 return new_size - old_size;
2203 }
2204 }
2205 return 0;
2206}
2207
2208uint32_t Mips64Assembler::Branch::GetOffsetLocation() const {
2209 return location_ + branch_info_[type_].instr_offset * sizeof(uint32_t);
2210}
2211
2212uint32_t Mips64Assembler::Branch::GetOffset() const {
2213 CHECK(IsResolved());
2214 uint32_t ofs_mask = 0xFFFFFFFF >> (32 - GetOffsetSize());
2215 // Calculate the byte distance between instructions and also account for
2216 // different PC-relative origins.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002217 uint32_t offset_location = GetOffsetLocation();
2218 if (type_ == kLiteralLong) {
2219 // Special case for the ldpc instruction, whose address (PC) is rounded down to
2220 // a multiple of 8 before adding the offset.
2221 // Note, branch promotion has already taken care of aligning `target_` to an
2222 // address that's a multiple of 8.
2223 offset_location = RoundDown(offset_location, sizeof(uint64_t));
2224 }
2225 uint32_t offset = target_ - offset_location - branch_info_[type_].pc_org * sizeof(uint32_t);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002226 // Prepare the offset for encoding into the instruction(s).
2227 offset = (offset & ofs_mask) >> branch_info_[type_].offset_shift;
2228 return offset;
2229}
2230
2231Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) {
2232 CHECK_LT(branch_id, branches_.size());
2233 return &branches_[branch_id];
2234}
2235
2236const Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) const {
2237 CHECK_LT(branch_id, branches_.size());
2238 return &branches_[branch_id];
2239}
2240
2241void Mips64Assembler::Bind(Mips64Label* label) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002242 CHECK(!label->IsBound());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002243 uint32_t bound_pc = buffer_.Size();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002244
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002245 // Walk the list of branches referring to and preceding this label.
2246 // Store the previously unknown target addresses in them.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002247 while (label->IsLinked()) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002248 uint32_t branch_id = label->Position();
2249 Branch* branch = GetBranch(branch_id);
2250 branch->Resolve(bound_pc);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002251
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002252 uint32_t branch_location = branch->GetLocation();
2253 // Extract the location of the previous branch in the list (walking the list backwards;
2254 // the previous branch ID was stored in the space reserved for this branch).
2255 uint32_t prev = buffer_.Load<uint32_t>(branch_location);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002256
2257 // On to the previous branch in the list...
2258 label->position_ = prev;
2259 }
2260
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002261 // Now make the label object contain its own location (relative to the end of the preceding
2262 // branch, if any; it will be used by the branches referring to and following this label).
2263 label->prev_branch_id_plus_one_ = branches_.size();
2264 if (label->prev_branch_id_plus_one_) {
2265 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2266 const Branch* branch = GetBranch(branch_id);
2267 bound_pc -= branch->GetEndLocation();
2268 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002269 label->BindTo(bound_pc);
2270}
2271
Alexey Frunze19f6c692016-11-30 19:19:55 -08002272uint32_t Mips64Assembler::GetLabelLocation(const Mips64Label* label) const {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002273 CHECK(label->IsBound());
2274 uint32_t target = label->Position();
2275 if (label->prev_branch_id_plus_one_) {
2276 // Get label location based on the branch preceding it.
2277 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2278 const Branch* branch = GetBranch(branch_id);
2279 target += branch->GetEndLocation();
2280 }
2281 return target;
2282}
2283
2284uint32_t Mips64Assembler::GetAdjustedPosition(uint32_t old_position) {
2285 // We can reconstruct the adjustment by going through all the branches from the beginning
2286 // up to the old_position. Since we expect AdjustedPosition() to be called in a loop
2287 // with increasing old_position, we can use the data from last AdjustedPosition() to
2288 // continue where we left off and the whole loop should be O(m+n) where m is the number
2289 // of positions to adjust and n is the number of branches.
2290 if (old_position < last_old_position_) {
2291 last_position_adjustment_ = 0;
2292 last_old_position_ = 0;
2293 last_branch_id_ = 0;
2294 }
2295 while (last_branch_id_ != branches_.size()) {
2296 const Branch* branch = GetBranch(last_branch_id_);
2297 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
2298 break;
2299 }
2300 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
2301 ++last_branch_id_;
2302 }
2303 last_old_position_ = old_position;
2304 return old_position + last_position_adjustment_;
2305}
2306
2307void Mips64Assembler::FinalizeLabeledBranch(Mips64Label* label) {
2308 uint32_t length = branches_.back().GetLength();
2309 if (!label->IsBound()) {
2310 // Branch forward (to a following label), distance is unknown.
2311 // The first branch forward will contain 0, serving as the terminator of
2312 // the list of forward-reaching branches.
2313 Emit(label->position_);
2314 length--;
2315 // Now make the label object point to this branch
2316 // (this forms a linked list of branches preceding this label).
2317 uint32_t branch_id = branches_.size() - 1;
2318 label->LinkTo(branch_id);
2319 }
2320 // Reserve space for the branch.
2321 while (length--) {
2322 Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002323 }
2324}
2325
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002326void Mips64Assembler::Buncond(Mips64Label* label) {
2327 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002328 branches_.emplace_back(buffer_.Size(), target, /* is_call */ false);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002329 FinalizeLabeledBranch(label);
2330}
2331
2332void Mips64Assembler::Bcond(Mips64Label* label,
2333 BranchCondition condition,
2334 GpuRegister lhs,
2335 GpuRegister rhs) {
2336 // If lhs = rhs, this can be a NOP.
2337 if (Branch::IsNop(condition, lhs, rhs)) {
2338 return;
2339 }
2340 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
2341 branches_.emplace_back(buffer_.Size(), target, condition, lhs, rhs);
2342 FinalizeLabeledBranch(label);
2343}
2344
Alexey Frunze19f6c692016-11-30 19:19:55 -08002345void Mips64Assembler::Call(Mips64Label* label) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002346 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002347 branches_.emplace_back(buffer_.Size(), target, /* is_call */ true);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002348 FinalizeLabeledBranch(label);
2349}
2350
Alexey Frunze19f6c692016-11-30 19:19:55 -08002351void Mips64Assembler::LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label) {
2352 // Label address loads are treated as pseudo branches since they require very similar handling.
2353 DCHECK(!label->IsBound());
2354 branches_.emplace_back(buffer_.Size(), dest_reg, Branch::kLabel);
2355 FinalizeLabeledBranch(label);
2356}
2357
2358Literal* Mips64Assembler::NewLiteral(size_t size, const uint8_t* data) {
2359 // We don't support byte and half-word literals.
2360 if (size == 4u) {
2361 literals_.emplace_back(size, data);
2362 return &literals_.back();
2363 } else {
2364 DCHECK_EQ(size, 8u);
2365 long_literals_.emplace_back(size, data);
2366 return &long_literals_.back();
2367 }
2368}
2369
2370void Mips64Assembler::LoadLiteral(GpuRegister dest_reg,
2371 LoadOperandType load_type,
2372 Literal* literal) {
2373 // Literal loads are treated as pseudo branches since they require very similar handling.
2374 Branch::Type literal_type;
2375 switch (load_type) {
2376 case kLoadWord:
2377 DCHECK_EQ(literal->GetSize(), 4u);
2378 literal_type = Branch::kLiteral;
2379 break;
2380 case kLoadUnsignedWord:
2381 DCHECK_EQ(literal->GetSize(), 4u);
2382 literal_type = Branch::kLiteralUnsigned;
2383 break;
2384 case kLoadDoubleword:
2385 DCHECK_EQ(literal->GetSize(), 8u);
2386 literal_type = Branch::kLiteralLong;
2387 break;
2388 default:
2389 LOG(FATAL) << "Unexpected literal load type " << load_type;
2390 UNREACHABLE();
2391 }
2392 Mips64Label* label = literal->GetLabel();
2393 DCHECK(!label->IsBound());
2394 branches_.emplace_back(buffer_.Size(), dest_reg, literal_type);
2395 FinalizeLabeledBranch(label);
2396}
2397
Alexey Frunze0960ac52016-12-20 17:24:59 -08002398JumpTable* Mips64Assembler::CreateJumpTable(std::vector<Mips64Label*>&& labels) {
2399 jump_tables_.emplace_back(std::move(labels));
2400 JumpTable* table = &jump_tables_.back();
2401 DCHECK(!table->GetLabel()->IsBound());
2402 return table;
2403}
2404
2405void Mips64Assembler::ReserveJumpTableSpace() {
2406 if (!jump_tables_.empty()) {
2407 for (JumpTable& table : jump_tables_) {
2408 Mips64Label* label = table.GetLabel();
2409 Bind(label);
2410
2411 // Bulk ensure capacity, as this may be large.
2412 size_t orig_size = buffer_.Size();
2413 size_t required_capacity = orig_size + table.GetSize();
2414 if (required_capacity > buffer_.Capacity()) {
2415 buffer_.ExtendCapacity(required_capacity);
2416 }
2417#ifndef NDEBUG
2418 buffer_.has_ensured_capacity_ = true;
2419#endif
2420
2421 // Fill the space with dummy data as the data is not final
2422 // until the branches have been promoted. And we shouldn't
2423 // be moving uninitialized data during branch promotion.
2424 for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
2425 buffer_.Emit<uint32_t>(0x1abe1234u);
2426 }
2427
2428#ifndef NDEBUG
2429 buffer_.has_ensured_capacity_ = false;
2430#endif
2431 }
2432 }
2433}
2434
2435void Mips64Assembler::EmitJumpTables() {
2436 if (!jump_tables_.empty()) {
2437 CHECK(!overwriting_);
2438 // Switch from appending instructions at the end of the buffer to overwriting
2439 // existing instructions (here, jump tables) in the buffer.
2440 overwriting_ = true;
2441
2442 for (JumpTable& table : jump_tables_) {
2443 Mips64Label* table_label = table.GetLabel();
2444 uint32_t start = GetLabelLocation(table_label);
2445 overwrite_location_ = start;
2446
2447 for (Mips64Label* target : table.GetData()) {
2448 CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
2449 // The table will contain target addresses relative to the table start.
2450 uint32_t offset = GetLabelLocation(target) - start;
2451 Emit(offset);
2452 }
2453 }
2454
2455 overwriting_ = false;
2456 }
2457}
2458
Alexey Frunze19f6c692016-11-30 19:19:55 -08002459void Mips64Assembler::EmitLiterals() {
2460 if (!literals_.empty()) {
2461 for (Literal& literal : literals_) {
2462 Mips64Label* label = literal.GetLabel();
2463 Bind(label);
2464 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2465 DCHECK_EQ(literal.GetSize(), 4u);
2466 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2467 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2468 }
2469 }
2470 }
2471 if (!long_literals_.empty()) {
2472 // Reserve 4 bytes for potential alignment. If after the branch promotion the 64-bit
2473 // literals don't end up 8-byte-aligned, they will be moved down 4 bytes.
2474 Emit(0); // NOP.
2475 for (Literal& literal : long_literals_) {
2476 Mips64Label* label = literal.GetLabel();
2477 Bind(label);
2478 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2479 DCHECK_EQ(literal.GetSize(), 8u);
2480 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2481 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2482 }
2483 }
2484 }
2485}
2486
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002487void Mips64Assembler::PromoteBranches() {
2488 // Promote short branches to long as necessary.
2489 bool changed;
2490 do {
2491 changed = false;
2492 for (auto& branch : branches_) {
2493 CHECK(branch.IsResolved());
2494 uint32_t delta = branch.PromoteIfNeeded();
2495 // If this branch has been promoted and needs to expand in size,
2496 // relocate all branches by the expansion size.
2497 if (delta) {
2498 changed = true;
2499 uint32_t expand_location = branch.GetLocation();
2500 for (auto& branch2 : branches_) {
2501 branch2.Relocate(expand_location, delta);
2502 }
2503 }
2504 }
2505 } while (changed);
2506
2507 // Account for branch expansion by resizing the code buffer
2508 // and moving the code in it to its final location.
2509 size_t branch_count = branches_.size();
2510 if (branch_count > 0) {
2511 // Resize.
2512 Branch& last_branch = branches_[branch_count - 1];
2513 uint32_t size_delta = last_branch.GetEndLocation() - last_branch.GetOldEndLocation();
2514 uint32_t old_size = buffer_.Size();
2515 buffer_.Resize(old_size + size_delta);
2516 // Move the code residing between branch placeholders.
2517 uint32_t end = old_size;
2518 for (size_t i = branch_count; i > 0; ) {
2519 Branch& branch = branches_[--i];
2520 uint32_t size = end - branch.GetOldEndLocation();
2521 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
2522 end = branch.GetOldLocation();
2523 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002524 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08002525
2526 // Align 64-bit literals by moving them down by 4 bytes if needed.
2527 // This will reduce the PC-relative distance, which should be safe for both near and far literals.
2528 if (!long_literals_.empty()) {
2529 uint32_t first_literal_location = GetLabelLocation(long_literals_.front().GetLabel());
2530 size_t lit_size = long_literals_.size() * sizeof(uint64_t);
2531 size_t buf_size = buffer_.Size();
2532 // 64-bit literals must be at the very end of the buffer.
2533 CHECK_EQ(first_literal_location + lit_size, buf_size);
2534 if (!IsAligned<sizeof(uint64_t)>(first_literal_location)) {
2535 buffer_.Move(first_literal_location - sizeof(uint32_t), first_literal_location, lit_size);
2536 // The 4 reserved bytes proved useless, reduce the buffer size.
2537 buffer_.Resize(buf_size - sizeof(uint32_t));
2538 // Reduce target addresses in literal and address loads by 4 bytes in order for correct
2539 // offsets from PC to be generated.
2540 for (auto& branch : branches_) {
2541 uint32_t target = branch.GetTarget();
2542 if (target >= first_literal_location) {
2543 branch.Resolve(target - sizeof(uint32_t));
2544 }
2545 }
2546 // If after this we ever call GetLabelLocation() to get the location of a 64-bit literal,
2547 // we need to adjust the location of the literal's label as well.
2548 for (Literal& literal : long_literals_) {
2549 // Bound label's position is negative, hence incrementing it instead of decrementing.
2550 literal.GetLabel()->position_ += sizeof(uint32_t);
2551 }
2552 }
2553 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002554}
2555
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002556// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2557const Mips64Assembler::Branch::BranchInfo Mips64Assembler::Branch::branch_info_[] = {
2558 // Short branches.
2559 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kUncondBranch
2560 { 2, 0, 1, Mips64Assembler::Branch::kOffset18, 2 }, // kCondBranch
2561 // Exception: kOffset23 for beqzc/bnezc
Alexey Frunze19f6c692016-11-30 19:19:55 -08002562 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kCall
2563 // Near label.
2564 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLabel
2565 // Near literals.
2566 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteral
2567 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteralUnsigned
2568 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 3 }, // kLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002569 // Long branches.
2570 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongUncondBranch
2571 { 3, 1, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCondBranch
Alexey Frunze19f6c692016-11-30 19:19:55 -08002572 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCall
2573 // Far label.
2574 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLabel
2575 // Far literals.
2576 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteral
2577 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralUnsigned
2578 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002579};
2580
2581// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2582void Mips64Assembler::EmitBranch(Mips64Assembler::Branch* branch) {
2583 CHECK(overwriting_);
2584 overwrite_location_ = branch->GetLocation();
2585 uint32_t offset = branch->GetOffset();
2586 BranchCondition condition = branch->GetCondition();
2587 GpuRegister lhs = branch->GetLeftRegister();
2588 GpuRegister rhs = branch->GetRightRegister();
2589 switch (branch->GetType()) {
2590 // Short branches.
2591 case Branch::kUncondBranch:
2592 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2593 Bc(offset);
2594 break;
2595 case Branch::kCondBranch:
2596 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2597 EmitBcondc(condition, lhs, rhs, offset);
Alexey Frunze299a9392015-12-08 16:08:02 -08002598 Nop(); // TODO: improve by filling the forbidden/delay slot.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002599 break;
2600 case Branch::kCall:
2601 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002602 Balc(offset);
2603 break;
2604
2605 // Near label.
2606 case Branch::kLabel:
2607 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002608 Addiupc(lhs, offset);
Alexey Frunze19f6c692016-11-30 19:19:55 -08002609 break;
2610 // Near literals.
2611 case Branch::kLiteral:
2612 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2613 Lwpc(lhs, offset);
2614 break;
2615 case Branch::kLiteralUnsigned:
2616 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2617 Lwupc(lhs, offset);
2618 break;
2619 case Branch::kLiteralLong:
2620 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2621 Ldpc(lhs, offset);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002622 break;
2623
2624 // Long branches.
2625 case Branch::kLongUncondBranch:
2626 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2627 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2628 Auipc(AT, High16Bits(offset));
2629 Jic(AT, Low16Bits(offset));
2630 break;
2631 case Branch::kLongCondBranch:
2632 EmitBcondc(Branch::OppositeCondition(condition), lhs, rhs, 2);
2633 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2634 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2635 Auipc(AT, High16Bits(offset));
2636 Jic(AT, Low16Bits(offset));
2637 break;
2638 case Branch::kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002639 offset += (offset & 0x8000) << 1; // Account for sign extension in jialc.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002640 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002641 Auipc(AT, High16Bits(offset));
2642 Jialc(AT, Low16Bits(offset));
2643 break;
2644
2645 // Far label.
2646 case Branch::kFarLabel:
Alexey Frunzef63f5692016-12-13 17:43:11 -08002647 offset += (offset & 0x8000) << 1; // Account for sign extension in daddiu.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002648 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2649 Auipc(AT, High16Bits(offset));
Alexey Frunzef63f5692016-12-13 17:43:11 -08002650 Daddiu(lhs, AT, Low16Bits(offset));
Alexey Frunze19f6c692016-11-30 19:19:55 -08002651 break;
2652 // Far literals.
2653 case Branch::kFarLiteral:
2654 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
2655 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2656 Auipc(AT, High16Bits(offset));
2657 Lw(lhs, AT, Low16Bits(offset));
2658 break;
2659 case Branch::kFarLiteralUnsigned:
2660 offset += (offset & 0x8000) << 1; // Account for sign extension in lwu.
2661 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2662 Auipc(AT, High16Bits(offset));
2663 Lwu(lhs, AT, Low16Bits(offset));
2664 break;
2665 case Branch::kFarLiteralLong:
2666 offset += (offset & 0x8000) << 1; // Account for sign extension in ld.
2667 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2668 Auipc(AT, High16Bits(offset));
2669 Ld(lhs, AT, Low16Bits(offset));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002670 break;
2671 }
2672 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
2673 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002674}
2675
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002676void Mips64Assembler::Bc(Mips64Label* label) {
2677 Buncond(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002678}
2679
Alexey Frunze19f6c692016-11-30 19:19:55 -08002680void Mips64Assembler::Balc(Mips64Label* label) {
2681 Call(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002682}
2683
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002684void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2685 Bcond(label, kCondLT, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002686}
2687
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002688void Mips64Assembler::Bltzc(GpuRegister rt, Mips64Label* label) {
2689 Bcond(label, kCondLTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002690}
2691
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002692void Mips64Assembler::Bgtzc(GpuRegister rt, Mips64Label* label) {
2693 Bcond(label, kCondGTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002694}
2695
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002696void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2697 Bcond(label, kCondGE, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002698}
2699
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002700void Mips64Assembler::Bgezc(GpuRegister rt, Mips64Label* label) {
2701 Bcond(label, kCondGEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002702}
2703
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002704void Mips64Assembler::Blezc(GpuRegister rt, Mips64Label* label) {
2705 Bcond(label, kCondLEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002706}
2707
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002708void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2709 Bcond(label, kCondLTU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002710}
2711
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002712void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2713 Bcond(label, kCondGEU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002714}
2715
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002716void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2717 Bcond(label, kCondEQ, rs, rt);
2718}
2719
2720void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2721 Bcond(label, kCondNE, rs, rt);
2722}
2723
2724void Mips64Assembler::Beqzc(GpuRegister rs, Mips64Label* label) {
2725 Bcond(label, kCondEQZ, rs);
2726}
2727
2728void Mips64Assembler::Bnezc(GpuRegister rs, Mips64Label* label) {
2729 Bcond(label, kCondNEZ, rs);
Andreas Gampe57b34292015-01-14 15:45:59 -08002730}
2731
Alexey Frunze299a9392015-12-08 16:08:02 -08002732void Mips64Assembler::Bc1eqz(FpuRegister ft, Mips64Label* label) {
2733 Bcond(label, kCondF, static_cast<GpuRegister>(ft), ZERO);
2734}
2735
2736void Mips64Assembler::Bc1nez(FpuRegister ft, Mips64Label* label) {
2737 Bcond(label, kCondT, static_cast<GpuRegister>(ft), ZERO);
2738}
2739
Chris Larsenc3fec0c2016-12-15 11:44:14 -08002740void Mips64Assembler::AdjustBaseAndOffset(GpuRegister& base,
2741 int32_t& offset,
2742 bool is_doubleword) {
2743 // This method is used to adjust the base register and offset pair
2744 // for a load/store when the offset doesn't fit into int16_t.
2745 // It is assumed that `base + offset` is sufficiently aligned for memory
2746 // operands that are machine word in size or smaller. For doubleword-sized
2747 // operands it's assumed that `base` is a multiple of 8, while `offset`
2748 // may be a multiple of 4 (e.g. 4-byte-aligned long and double arguments
2749 // and spilled variables on the stack accessed relative to the stack
2750 // pointer register).
2751 // We preserve the "alignment" of `offset` by adjusting it by a multiple of 8.
2752 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
2753
2754 bool doubleword_aligned = IsAligned<kMips64DoublewordSize>(offset);
2755 bool two_accesses = is_doubleword && !doubleword_aligned;
2756
2757 // IsInt<16> must be passed a signed value, hence the static cast below.
2758 if (IsInt<16>(offset) &&
2759 (!two_accesses || IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)))) {
2760 // Nothing to do: `offset` (and, if needed, `offset + 4`) fits into int16_t.
2761 return;
2762 }
2763
2764 // Remember the "(mis)alignment" of `offset`, it will be checked at the end.
2765 uint32_t misalignment = offset & (kMips64DoublewordSize - 1);
2766
2767 // First, see if `offset` can be represented as a sum of two 16-bit signed
2768 // offsets. This can save an instruction.
2769 // To simplify matters, only do this for a symmetric range of offsets from
2770 // about -64KB to about +64KB, allowing further addition of 4 when accessing
2771 // 64-bit variables with two 32-bit accesses.
2772 constexpr int32_t kMinOffsetForSimpleAdjustment = 0x7ff8; // Max int16_t that's a multiple of 8.
2773 constexpr int32_t kMaxOffsetForSimpleAdjustment = 2 * kMinOffsetForSimpleAdjustment;
2774
2775 if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
2776 Daddiu(AT, base, kMinOffsetForSimpleAdjustment);
2777 offset -= kMinOffsetForSimpleAdjustment;
2778 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
2779 Daddiu(AT, base, -kMinOffsetForSimpleAdjustment);
2780 offset += kMinOffsetForSimpleAdjustment;
2781 } else {
2782 // In more complex cases take advantage of the daui instruction, e.g.:
2783 // daui AT, base, offset_high
2784 // [dahi AT, 1] // When `offset` is close to +2GB.
2785 // lw reg_lo, offset_low(AT)
2786 // [lw reg_hi, (offset_low+4)(AT)] // If misaligned 64-bit load.
2787 // or when offset_low+4 overflows int16_t:
2788 // daui AT, base, offset_high
2789 // daddiu AT, AT, 8
2790 // lw reg_lo, (offset_low-8)(AT)
2791 // lw reg_hi, (offset_low-4)(AT)
2792 int16_t offset_low = Low16Bits(offset);
2793 int32_t offset_low32 = offset_low;
2794 int16_t offset_high = High16Bits(offset);
2795 bool increment_hi16 = offset_low < 0;
2796 bool overflow_hi16 = false;
2797
2798 if (increment_hi16) {
2799 offset_high++;
2800 overflow_hi16 = (offset_high == -32768);
2801 }
2802 Daui(AT, base, offset_high);
2803
2804 if (overflow_hi16) {
2805 Dahi(AT, 1);
2806 }
2807
2808 if (two_accesses && !IsInt<16>(static_cast<int32_t>(offset_low32 + kMips64WordSize))) {
2809 // Avoid overflow in the 16-bit offset of the load/store instruction when adding 4.
2810 Daddiu(AT, AT, kMips64DoublewordSize);
2811 offset_low32 -= kMips64DoublewordSize;
2812 }
2813
2814 offset = offset_low32;
2815 }
2816 base = AT;
2817
2818 CHECK(IsInt<16>(offset));
2819 if (two_accesses) {
2820 CHECK(IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)));
2821 }
2822 CHECK_EQ(misalignment, offset & (kMips64DoublewordSize - 1));
2823}
2824
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02002825void Mips64Assembler::AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
2826 int32_t& offset,
2827 int& element_size_shift) {
2828 // This method is used to adjust the base register, offset and element_size_shift
2829 // for a vector load/store when the offset doesn't fit into allowed number of bits.
2830 // MSA ld.df and st.df instructions take signed offsets as arguments, but maximum
2831 // offset is dependant on the size of the data format df (10-bit offsets for ld.b,
2832 // 11-bit for ld.h, 12-bit for ld.w and 13-bit for ld.d).
2833 // If element_size_shift is non-negative at entry, it won't be changed, but offset
2834 // will be checked for appropriate alignment. If negative at entry, it will be
2835 // adjusted based on offset for maximum fit.
2836 // It's assumed that `base` is a multiple of 8.
2837
2838 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
2839
2840 if (element_size_shift >= 0) {
2841 CHECK_LE(element_size_shift, TIMES_8);
2842 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
2843 } else if (IsAligned<kMips64DoublewordSize>(offset)) {
2844 element_size_shift = TIMES_8;
2845 } else if (IsAligned<kMips64WordSize>(offset)) {
2846 element_size_shift = TIMES_4;
2847 } else if (IsAligned<kMips64HalfwordSize>(offset)) {
2848 element_size_shift = TIMES_2;
2849 } else {
2850 element_size_shift = TIMES_1;
2851 }
2852
2853 const int low_len = 10 + element_size_shift; // How many low bits of `offset` ld.df/st.df
2854 // will take.
2855 int16_t low = offset & ((1 << low_len) - 1); // Isolate these bits.
2856 low -= (low & (1 << (low_len - 1))) << 1; // Sign-extend these bits.
2857 if (low == offset) {
2858 return; // `offset` fits into ld.df/st.df.
2859 }
2860
2861 // First, see if `offset` can be represented as a sum of two signed offsets.
2862 // This can save an instruction.
2863
2864 // Max int16_t that's a multiple of element size.
2865 const int32_t kMaxDeltaForSimpleAdjustment = 0x8000 - (1 << element_size_shift);
2866 // Max ld.df/st.df offset that's a multiple of element size.
2867 const int32_t kMaxLoadStoreOffset = 0x1ff << element_size_shift;
2868 const int32_t kMaxOffsetForSimpleAdjustment = kMaxDeltaForSimpleAdjustment + kMaxLoadStoreOffset;
2869
2870 if (IsInt<16>(offset)) {
2871 Daddiu(AT, base, offset);
2872 offset = 0;
2873 } else if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
2874 Daddiu(AT, base, kMaxDeltaForSimpleAdjustment);
2875 offset -= kMaxDeltaForSimpleAdjustment;
2876 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
2877 Daddiu(AT, base, -kMaxDeltaForSimpleAdjustment);
2878 offset += kMaxDeltaForSimpleAdjustment;
2879 } else {
2880 // Let's treat `offset` as 64-bit to simplify handling of sign
2881 // extensions in the instructions that supply its smaller signed parts.
2882 //
2883 // 16-bit or smaller parts of `offset`:
2884 // |63 top 48|47 hi 32|31 upper 16|15 mid 13-10|12-9 low 0|
2885 //
2886 // Instructions that supply each part as a signed integer addend:
2887 // |dati |dahi |daui |daddiu |ld.df/st.df |
2888 //
2889 // `top` is always 0, so dati isn't used.
2890 // `hi` is 1 when `offset` is close to +2GB and 0 otherwise.
2891 uint64_t tmp = static_cast<uint64_t>(offset) - low; // Exclude `low` from the rest of `offset`
2892 // (accounts for sign of `low`).
2893 tmp += (tmp & (UINT64_C(1) << 15)) << 1; // Account for sign extension in daddiu.
2894 tmp += (tmp & (UINT64_C(1) << 31)) << 1; // Account for sign extension in daui.
2895 int16_t mid = Low16Bits(tmp);
2896 int16_t upper = High16Bits(tmp);
2897 int16_t hi = Low16Bits(High32Bits(tmp));
2898 Daui(AT, base, upper);
2899 if (hi != 0) {
2900 CHECK_EQ(hi, 1);
2901 Dahi(AT, hi);
2902 }
2903 if (mid != 0) {
2904 Daddiu(AT, AT, mid);
2905 }
2906 offset = low;
2907 }
2908 base = AT;
2909 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
2910 CHECK(IsInt<10>(offset >> element_size_shift));
2911}
2912
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002913void Mips64Assembler::LoadFromOffset(LoadOperandType type,
2914 GpuRegister reg,
2915 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002916 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002917 LoadFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002918}
2919
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002920void Mips64Assembler::LoadFpuFromOffset(LoadOperandType type,
2921 FpuRegister reg,
2922 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002923 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002924 LoadFpuFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002925}
2926
2927void Mips64Assembler::EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset,
2928 size_t size) {
2929 Mips64ManagedRegister dst = m_dst.AsMips64();
2930 if (dst.IsNoRegister()) {
2931 CHECK_EQ(0u, size) << dst;
2932 } else if (dst.IsGpuRegister()) {
2933 if (size == 4) {
Andreas Gampe57b34292015-01-14 15:45:59 -08002934 LoadFromOffset(kLoadWord, dst.AsGpuRegister(), src_register, src_offset);
2935 } else if (size == 8) {
2936 CHECK_EQ(8u, size) << dst;
2937 LoadFromOffset(kLoadDoubleword, dst.AsGpuRegister(), src_register, src_offset);
2938 } else {
2939 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
2940 }
2941 } else if (dst.IsFpuRegister()) {
2942 if (size == 4) {
2943 CHECK_EQ(4u, size) << dst;
2944 LoadFpuFromOffset(kLoadWord, dst.AsFpuRegister(), src_register, src_offset);
2945 } else if (size == 8) {
2946 CHECK_EQ(8u, size) << dst;
2947 LoadFpuFromOffset(kLoadDoubleword, dst.AsFpuRegister(), src_register, src_offset);
2948 } else {
2949 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
2950 }
2951 }
2952}
2953
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002954void Mips64Assembler::StoreToOffset(StoreOperandType type,
2955 GpuRegister reg,
2956 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002957 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002958 StoreToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002959}
2960
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002961void Mips64Assembler::StoreFpuToOffset(StoreOperandType type,
2962 FpuRegister reg,
2963 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002964 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002965 StoreFpuToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002966}
2967
David Srbeckydd973932015-04-07 20:29:48 +01002968static dwarf::Reg DWARFReg(GpuRegister reg) {
2969 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
2970}
2971
Andreas Gampe57b34292015-01-14 15:45:59 -08002972constexpr size_t kFramePointerSize = 8;
2973
Vladimir Marko32248382016-05-19 10:37:24 +01002974void Mips64Assembler::BuildFrame(size_t frame_size,
2975 ManagedRegister method_reg,
2976 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08002977 const ManagedRegisterEntrySpills& entry_spills) {
2978 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002979 DCHECK(!overwriting_);
Andreas Gampe57b34292015-01-14 15:45:59 -08002980
2981 // Increase frame to required size.
2982 IncreaseFrameSize(frame_size);
2983
2984 // Push callee saves and return address
2985 int stack_offset = frame_size - kFramePointerSize;
2986 StoreToOffset(kStoreDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01002987 cfi_.RelOffset(DWARFReg(RA), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002988 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
2989 stack_offset -= kFramePointerSize;
Vladimir Marko32248382016-05-19 10:37:24 +01002990 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08002991 StoreToOffset(kStoreDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01002992 cfi_.RelOffset(DWARFReg(reg), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002993 }
2994
2995 // Write out Method*.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002996 StoreToOffset(kStoreDoubleword, method_reg.AsMips64().AsGpuRegister(), SP, 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08002997
2998 // Write out entry spills.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002999 int32_t offset = frame_size + kFramePointerSize;
Andreas Gampe57b34292015-01-14 15:45:59 -08003000 for (size_t i = 0; i < entry_spills.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003001 Mips64ManagedRegister reg = entry_spills[i].AsMips64();
Andreas Gampe57b34292015-01-14 15:45:59 -08003002 ManagedRegisterSpill spill = entry_spills.at(i);
3003 int32_t size = spill.getSize();
3004 if (reg.IsNoRegister()) {
3005 // only increment stack offset.
3006 offset += size;
3007 } else if (reg.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003008 StoreFpuToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3009 reg.AsFpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003010 offset += size;
3011 } else if (reg.IsGpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003012 StoreToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3013 reg.AsGpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003014 offset += size;
3015 }
3016 }
3017}
3018
3019void Mips64Assembler::RemoveFrame(size_t frame_size,
Vladimir Marko32248382016-05-19 10:37:24 +01003020 ArrayRef<const ManagedRegister> callee_save_regs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003021 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003022 DCHECK(!overwriting_);
David Srbeckydd973932015-04-07 20:29:48 +01003023 cfi_.RememberState();
Andreas Gampe57b34292015-01-14 15:45:59 -08003024
3025 // Pop callee saves and return address
3026 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
3027 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003028 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08003029 LoadFromOffset(kLoadDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003030 cfi_.Restore(DWARFReg(reg));
Andreas Gampe57b34292015-01-14 15:45:59 -08003031 stack_offset += kFramePointerSize;
3032 }
3033 LoadFromOffset(kLoadDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003034 cfi_.Restore(DWARFReg(RA));
Andreas Gampe57b34292015-01-14 15:45:59 -08003035
3036 // Decrease frame to required size.
3037 DecreaseFrameSize(frame_size);
3038
3039 // Then jump to the return address.
3040 Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003041 Nop();
David Srbeckydd973932015-04-07 20:29:48 +01003042
3043 // The CFI should be restored for any code that follows the exit block.
3044 cfi_.RestoreState();
3045 cfi_.DefCFAOffset(frame_size);
Andreas Gampe57b34292015-01-14 15:45:59 -08003046}
3047
3048void Mips64Assembler::IncreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003049 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003050 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003051 Daddiu64(SP, SP, static_cast<int32_t>(-adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003052 cfi_.AdjustCFAOffset(adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003053}
3054
3055void Mips64Assembler::DecreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003056 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003057 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003058 Daddiu64(SP, SP, static_cast<int32_t>(adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003059 cfi_.AdjustCFAOffset(-adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003060}
3061
3062void Mips64Assembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
3063 Mips64ManagedRegister src = msrc.AsMips64();
3064 if (src.IsNoRegister()) {
3065 CHECK_EQ(0u, size);
3066 } else if (src.IsGpuRegister()) {
3067 CHECK(size == 4 || size == 8) << size;
3068 if (size == 8) {
3069 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3070 } else if (size == 4) {
3071 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3072 } else {
3073 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3074 }
3075 } else if (src.IsFpuRegister()) {
3076 CHECK(size == 4 || size == 8) << size;
3077 if (size == 8) {
3078 StoreFpuToOffset(kStoreDoubleword, src.AsFpuRegister(), SP, dest.Int32Value());
3079 } else if (size == 4) {
3080 StoreFpuToOffset(kStoreWord, src.AsFpuRegister(), SP, dest.Int32Value());
3081 } else {
3082 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3083 }
3084 }
3085}
3086
3087void Mips64Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
3088 Mips64ManagedRegister src = msrc.AsMips64();
3089 CHECK(src.IsGpuRegister());
3090 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3091}
3092
3093void Mips64Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
3094 Mips64ManagedRegister src = msrc.AsMips64();
3095 CHECK(src.IsGpuRegister());
3096 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3097}
3098
3099void Mips64Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
3100 ManagedRegister mscratch) {
3101 Mips64ManagedRegister scratch = mscratch.AsMips64();
3102 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003103 LoadConst32(scratch.AsGpuRegister(), imm);
Andreas Gampe57b34292015-01-14 15:45:59 -08003104 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3105}
3106
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003107void Mips64Assembler::StoreStackOffsetToThread(ThreadOffset64 thr_offs,
3108 FrameOffset fr_offs,
3109 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003110 Mips64ManagedRegister scratch = mscratch.AsMips64();
3111 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003112 Daddiu64(scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003113 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3114}
3115
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003116void Mips64Assembler::StoreStackPointerToThread(ThreadOffset64 thr_offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003117 StoreToOffset(kStoreDoubleword, SP, S1, thr_offs.Int32Value());
3118}
3119
3120void Mips64Assembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
3121 FrameOffset in_off, ManagedRegister mscratch) {
3122 Mips64ManagedRegister src = msrc.AsMips64();
3123 Mips64ManagedRegister scratch = mscratch.AsMips64();
3124 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3125 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, in_off.Int32Value());
3126 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value() + 8);
3127}
3128
3129void Mips64Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
3130 return EmitLoad(mdest, SP, src.Int32Value(), size);
3131}
3132
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003133void Mips64Assembler::LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003134 return EmitLoad(mdest, S1, src.Int32Value(), size);
3135}
3136
3137void Mips64Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
3138 Mips64ManagedRegister dest = mdest.AsMips64();
3139 CHECK(dest.IsGpuRegister());
Douglas Leungd90957f2015-04-30 19:22:49 -07003140 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(), SP, src.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003141}
3142
Mathieu Chartiere401d142015-04-22 13:56:20 -07003143void Mips64Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01003144 bool unpoison_reference) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003145 Mips64ManagedRegister dest = mdest.AsMips64();
Douglas Leungd90957f2015-04-30 19:22:49 -07003146 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
3147 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003148 base.AsMips64().AsGpuRegister(), offs.Int32Value());
Alexey Frunzec061de12017-02-14 13:27:23 -08003149 if (unpoison_reference) {
3150 MaybeUnpoisonHeapReference(dest.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003151 }
3152}
3153
3154void Mips64Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003155 Offset offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003156 Mips64ManagedRegister dest = mdest.AsMips64();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003157 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003158 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(),
3159 base.AsMips64().AsGpuRegister(), offs.Int32Value());
3160}
3161
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003162void Mips64Assembler::LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003163 Mips64ManagedRegister dest = mdest.AsMips64();
3164 CHECK(dest.IsGpuRegister());
3165 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(), S1, offs.Int32Value());
3166}
3167
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003168void Mips64Assembler::SignExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3169 size_t size ATTRIBUTE_UNUSED) {
3170 UNIMPLEMENTED(FATAL) << "No sign extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003171}
3172
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003173void Mips64Assembler::ZeroExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3174 size_t size ATTRIBUTE_UNUSED) {
3175 UNIMPLEMENTED(FATAL) << "No zero extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003176}
3177
3178void Mips64Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
3179 Mips64ManagedRegister dest = mdest.AsMips64();
3180 Mips64ManagedRegister src = msrc.AsMips64();
3181 if (!dest.Equals(src)) {
3182 if (dest.IsGpuRegister()) {
3183 CHECK(src.IsGpuRegister()) << src;
3184 Move(dest.AsGpuRegister(), src.AsGpuRegister());
3185 } else if (dest.IsFpuRegister()) {
3186 CHECK(src.IsFpuRegister()) << src;
3187 if (size == 4) {
3188 MovS(dest.AsFpuRegister(), src.AsFpuRegister());
3189 } else if (size == 8) {
3190 MovD(dest.AsFpuRegister(), src.AsFpuRegister());
3191 } else {
3192 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3193 }
3194 }
3195 }
3196}
3197
3198void Mips64Assembler::CopyRef(FrameOffset dest, FrameOffset src,
3199 ManagedRegister mscratch) {
3200 Mips64ManagedRegister scratch = mscratch.AsMips64();
3201 CHECK(scratch.IsGpuRegister()) << scratch;
3202 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
3203 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3204}
3205
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003206void Mips64Assembler::CopyRawPtrFromThread(FrameOffset fr_offs,
3207 ThreadOffset64 thr_offs,
3208 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003209 Mips64ManagedRegister scratch = mscratch.AsMips64();
3210 CHECK(scratch.IsGpuRegister()) << scratch;
3211 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3212 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
3213}
3214
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003215void Mips64Assembler::CopyRawPtrToThread(ThreadOffset64 thr_offs,
3216 FrameOffset fr_offs,
3217 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003218 Mips64ManagedRegister scratch = mscratch.AsMips64();
3219 CHECK(scratch.IsGpuRegister()) << scratch;
3220 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3221 SP, fr_offs.Int32Value());
3222 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(),
3223 S1, thr_offs.Int32Value());
3224}
3225
3226void Mips64Assembler::Copy(FrameOffset dest, FrameOffset src,
3227 ManagedRegister mscratch, size_t size) {
3228 Mips64ManagedRegister scratch = mscratch.AsMips64();
3229 CHECK(scratch.IsGpuRegister()) << scratch;
3230 CHECK(size == 4 || size == 8) << size;
3231 if (size == 4) {
3232 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003233 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003234 } else if (size == 8) {
3235 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, src.Int32Value());
3236 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
3237 } else {
3238 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3239 }
3240}
3241
3242void Mips64Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003243 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003244 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3245 CHECK(size == 4 || size == 8) << size;
3246 if (size == 4) {
3247 LoadFromOffset(kLoadWord, scratch, src_base.AsMips64().AsGpuRegister(),
3248 src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003249 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003250 } else if (size == 8) {
3251 LoadFromOffset(kLoadDoubleword, scratch, src_base.AsMips64().AsGpuRegister(),
3252 src_offset.Int32Value());
3253 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
3254 } else {
3255 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3256 }
3257}
3258
3259void Mips64Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003260 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003261 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3262 CHECK(size == 4 || size == 8) << size;
3263 if (size == 4) {
3264 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003265 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003266 dest_offset.Int32Value());
3267 } else if (size == 8) {
3268 LoadFromOffset(kLoadDoubleword, scratch, SP, src.Int32Value());
3269 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
3270 dest_offset.Int32Value());
3271 } else {
3272 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3273 }
3274}
3275
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003276void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3277 FrameOffset src_base ATTRIBUTE_UNUSED,
3278 Offset src_offset ATTRIBUTE_UNUSED,
3279 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3280 size_t size ATTRIBUTE_UNUSED) {
3281 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003282}
3283
3284void Mips64Assembler::Copy(ManagedRegister dest, Offset dest_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003285 ManagedRegister src, Offset src_offset,
3286 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003287 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3288 CHECK(size == 4 || size == 8) << size;
3289 if (size == 4) {
3290 LoadFromOffset(kLoadWord, scratch, src.AsMips64().AsGpuRegister(), src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003291 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(), dest_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003292 } else if (size == 8) {
3293 LoadFromOffset(kLoadDoubleword, scratch, src.AsMips64().AsGpuRegister(),
3294 src_offset.Int32Value());
3295 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(),
3296 dest_offset.Int32Value());
3297 } else {
3298 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3299 }
3300}
3301
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003302void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3303 Offset dest_offset ATTRIBUTE_UNUSED,
3304 FrameOffset src ATTRIBUTE_UNUSED,
3305 Offset src_offset ATTRIBUTE_UNUSED,
3306 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3307 size_t size ATTRIBUTE_UNUSED) {
3308 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003309}
3310
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003311void Mips64Assembler::MemoryBarrier(ManagedRegister mreg ATTRIBUTE_UNUSED) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003312 // TODO: sync?
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003313 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003314}
3315
3316void Mips64Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003317 FrameOffset handle_scope_offset,
3318 ManagedRegister min_reg,
3319 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003320 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3321 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3322 CHECK(in_reg.IsNoRegister() || in_reg.IsGpuRegister()) << in_reg;
3323 CHECK(out_reg.IsGpuRegister()) << out_reg;
3324 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003325 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003326 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3327 // the address in the handle scope holding the reference.
3328 // e.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset)
3329 if (in_reg.IsNoRegister()) {
Douglas Leungd90957f2015-04-30 19:22:49 -07003330 LoadFromOffset(kLoadUnsignedWord, out_reg.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003331 SP, handle_scope_offset.Int32Value());
3332 in_reg = out_reg;
3333 }
3334 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003335 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003336 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003337 Beqzc(in_reg.AsGpuRegister(), &null_arg);
3338 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3339 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003340 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003341 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003342 }
3343}
3344
3345void Mips64Assembler::CreateHandleScopeEntry(FrameOffset out_off,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003346 FrameOffset handle_scope_offset,
3347 ManagedRegister mscratch,
3348 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003349 Mips64ManagedRegister scratch = mscratch.AsMips64();
3350 CHECK(scratch.IsGpuRegister()) << scratch;
3351 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003352 Mips64Label null_arg;
Douglas Leungd90957f2015-04-30 19:22:49 -07003353 LoadFromOffset(kLoadUnsignedWord, scratch.AsGpuRegister(), SP,
Andreas Gampe57b34292015-01-14 15:45:59 -08003354 handle_scope_offset.Int32Value());
3355 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3356 // the address in the handle scope holding the reference.
3357 // e.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003358 Beqzc(scratch.AsGpuRegister(), &null_arg);
3359 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3360 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003361 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003362 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003363 }
3364 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, out_off.Int32Value());
3365}
3366
3367// Given a handle scope entry, load the associated reference.
3368void Mips64Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003369 ManagedRegister min_reg) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003370 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3371 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3372 CHECK(out_reg.IsGpuRegister()) << out_reg;
3373 CHECK(in_reg.IsGpuRegister()) << in_reg;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003374 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003375 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003376 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003377 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003378 Beqzc(in_reg.AsGpuRegister(), &null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003379 LoadFromOffset(kLoadDoubleword, out_reg.AsGpuRegister(),
3380 in_reg.AsGpuRegister(), 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003381 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003382}
3383
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003384void Mips64Assembler::VerifyObject(ManagedRegister src ATTRIBUTE_UNUSED,
3385 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003386 // TODO: not validating references
3387}
3388
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003389void Mips64Assembler::VerifyObject(FrameOffset src ATTRIBUTE_UNUSED,
3390 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003391 // TODO: not validating references
3392}
3393
3394void Mips64Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
3395 Mips64ManagedRegister base = mbase.AsMips64();
3396 Mips64ManagedRegister scratch = mscratch.AsMips64();
3397 CHECK(base.IsGpuRegister()) << base;
3398 CHECK(scratch.IsGpuRegister()) << scratch;
3399 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3400 base.AsGpuRegister(), offset.Int32Value());
3401 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003402 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003403 // TODO: place reference map on call
3404}
3405
3406void Mips64Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
3407 Mips64ManagedRegister scratch = mscratch.AsMips64();
3408 CHECK(scratch.IsGpuRegister()) << scratch;
3409 // Call *(*(SP + base) + offset)
Mathieu Chartiere401d142015-04-22 13:56:20 -07003410 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003411 SP, base.Int32Value());
3412 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3413 scratch.AsGpuRegister(), offset.Int32Value());
3414 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003415 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003416 // TODO: place reference map on call
3417}
3418
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003419void Mips64Assembler::CallFromThread(ThreadOffset64 offset ATTRIBUTE_UNUSED,
3420 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003421 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003422}
3423
3424void Mips64Assembler::GetCurrentThread(ManagedRegister tr) {
3425 Move(tr.AsMips64().AsGpuRegister(), S1);
3426}
3427
3428void Mips64Assembler::GetCurrentThread(FrameOffset offset,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003429 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003430 StoreToOffset(kStoreDoubleword, S1, SP, offset.Int32Value());
3431}
3432
3433void Mips64Assembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
3434 Mips64ManagedRegister scratch = mscratch.AsMips64();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003435 exception_blocks_.emplace_back(scratch, stack_adjust);
3436 LoadFromOffset(kLoadDoubleword,
3437 scratch.AsGpuRegister(),
3438 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003439 Thread::ExceptionOffset<kMips64PointerSize>().Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003440 Bnezc(scratch.AsGpuRegister(), exception_blocks_.back().Entry());
Andreas Gampe57b34292015-01-14 15:45:59 -08003441}
3442
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003443void Mips64Assembler::EmitExceptionPoll(Mips64ExceptionSlowPath* exception) {
3444 Bind(exception->Entry());
3445 if (exception->stack_adjust_ != 0) { // Fix up the frame.
3446 DecreaseFrameSize(exception->stack_adjust_);
Andreas Gampe57b34292015-01-14 15:45:59 -08003447 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003448 // Pass exception object as argument.
3449 // Don't care about preserving A0 as this call won't return.
3450 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3451 Move(A0, exception->scratch_.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003452 // Set up call to Thread::Current()->pDeliverException
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003453 LoadFromOffset(kLoadDoubleword,
3454 T9,
3455 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003456 QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, pDeliverException).Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003457 Jr(T9);
3458 Nop();
3459
Andreas Gampe57b34292015-01-14 15:45:59 -08003460 // Call never returns
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003461 Break();
Andreas Gampe57b34292015-01-14 15:45:59 -08003462}
3463
3464} // namespace mips64
3465} // namespace art