blob: b8b800abe3a1e23a2113d2e8efdddffbd917709a [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
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001798void Mips64Assembler::ReplicateFPToVectorRegister(VectorRegister dst,
1799 FpuRegister src,
1800 bool is_double) {
1801 // Float or double in FPU register Fx can be considered as 0th element in vector register Wx.
1802 if (is_double) {
1803 SplatiD(dst, static_cast<VectorRegister>(src), 0);
1804 } else {
1805 SplatiW(dst, static_cast<VectorRegister>(src), 0);
1806 }
1807}
1808
Alexey Frunze4dda3372015-06-01 18:31:49 -07001809void Mips64Assembler::LoadConst32(GpuRegister rd, int32_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001810 TemplateLoadConst32(this, rd, value);
1811}
1812
1813// This function is only used for testing purposes.
1814void Mips64Assembler::RecordLoadConst64Path(int value ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001815}
1816
Alexey Frunze4dda3372015-06-01 18:31:49 -07001817void Mips64Assembler::LoadConst64(GpuRegister rd, int64_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001818 TemplateLoadConst64(this, rd, value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001819}
1820
Alexey Frunze0960ac52016-12-20 17:24:59 -08001821void Mips64Assembler::Addiu32(GpuRegister rt, GpuRegister rs, int32_t value) {
1822 if (IsInt<16>(value)) {
1823 Addiu(rt, rs, value);
1824 } else {
1825 int16_t high = High16Bits(value);
1826 int16_t low = Low16Bits(value);
1827 high += (low < 0) ? 1 : 0; // Account for sign extension in addiu.
1828 Aui(rt, rs, high);
1829 if (low != 0) {
1830 Addiu(rt, rt, low);
1831 }
1832 }
1833}
1834
Alexey Frunze15958152017-02-09 19:08:30 -08001835// TODO: don't use rtmp, use daui, dahi, dati.
Alexey Frunze4dda3372015-06-01 18:31:49 -07001836void Mips64Assembler::Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp) {
Chris Larsen5863f852017-03-23 15:41:37 -07001837 CHECK_NE(rs, rtmp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001838 if (IsInt<16>(value)) {
1839 Daddiu(rt, rs, value);
1840 } else {
1841 LoadConst64(rtmp, value);
1842 Daddu(rt, rs, rtmp);
1843 }
Andreas Gampe57b34292015-01-14 15:45:59 -08001844}
1845
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001846void Mips64Assembler::Branch::InitShortOrLong(Mips64Assembler::Branch::OffsetBits offset_size,
1847 Mips64Assembler::Branch::Type short_type,
1848 Mips64Assembler::Branch::Type long_type) {
1849 type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
1850}
Alexey Frunze4dda3372015-06-01 18:31:49 -07001851
Alexey Frunze19f6c692016-11-30 19:19:55 -08001852void Mips64Assembler::Branch::InitializeType(Type initial_type) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001853 OffsetBits offset_size = GetOffsetSizeNeeded(location_, target_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08001854 switch (initial_type) {
1855 case kLabel:
1856 case kLiteral:
1857 case kLiteralUnsigned:
1858 case kLiteralLong:
1859 CHECK(!IsResolved());
1860 type_ = initial_type;
1861 break;
1862 case kCall:
1863 InitShortOrLong(offset_size, kCall, kLongCall);
1864 break;
1865 case kCondBranch:
1866 switch (condition_) {
1867 case kUncond:
1868 InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
1869 break;
1870 case kCondEQZ:
1871 case kCondNEZ:
1872 // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
1873 type_ = (offset_size <= kOffset23) ? kCondBranch : kLongCondBranch;
1874 break;
1875 default:
1876 InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
1877 break;
1878 }
1879 break;
1880 default:
1881 LOG(FATAL) << "Unexpected branch type " << initial_type;
1882 UNREACHABLE();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001883 }
1884 old_type_ = type_;
1885}
1886
1887bool Mips64Assembler::Branch::IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs) {
1888 switch (condition) {
1889 case kCondLT:
1890 case kCondGT:
1891 case kCondNE:
1892 case kCondLTU:
1893 return lhs == rhs;
1894 default:
1895 return false;
1896 }
1897}
1898
1899bool Mips64Assembler::Branch::IsUncond(BranchCondition condition,
1900 GpuRegister lhs,
1901 GpuRegister rhs) {
1902 switch (condition) {
1903 case kUncond:
1904 return true;
1905 case kCondGE:
1906 case kCondLE:
1907 case kCondEQ:
1908 case kCondGEU:
1909 return lhs == rhs;
1910 default:
1911 return false;
1912 }
1913}
1914
Alexey Frunze19f6c692016-11-30 19:19:55 -08001915Mips64Assembler::Branch::Branch(uint32_t location, uint32_t target, bool is_call)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001916 : old_location_(location),
1917 location_(location),
1918 target_(target),
1919 lhs_reg_(ZERO),
1920 rhs_reg_(ZERO),
1921 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001922 InitializeType(is_call ? kCall : kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001923}
1924
1925Mips64Assembler::Branch::Branch(uint32_t location,
1926 uint32_t target,
1927 Mips64Assembler::BranchCondition condition,
1928 GpuRegister lhs_reg,
1929 GpuRegister rhs_reg)
1930 : old_location_(location),
1931 location_(location),
1932 target_(target),
1933 lhs_reg_(lhs_reg),
1934 rhs_reg_(rhs_reg),
1935 condition_(condition) {
1936 CHECK_NE(condition, kUncond);
1937 switch (condition) {
1938 case kCondEQ:
1939 case kCondNE:
1940 case kCondLT:
1941 case kCondGE:
1942 case kCondLE:
1943 case kCondGT:
1944 case kCondLTU:
1945 case kCondGEU:
1946 CHECK_NE(lhs_reg, ZERO);
1947 CHECK_NE(rhs_reg, ZERO);
1948 break;
1949 case kCondLTZ:
1950 case kCondGEZ:
1951 case kCondLEZ:
1952 case kCondGTZ:
1953 case kCondEQZ:
1954 case kCondNEZ:
1955 CHECK_NE(lhs_reg, ZERO);
1956 CHECK_EQ(rhs_reg, ZERO);
1957 break;
Alexey Frunze299a9392015-12-08 16:08:02 -08001958 case kCondF:
1959 case kCondT:
1960 CHECK_EQ(rhs_reg, ZERO);
1961 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001962 case kUncond:
1963 UNREACHABLE();
1964 }
1965 CHECK(!IsNop(condition, lhs_reg, rhs_reg));
1966 if (IsUncond(condition, lhs_reg, rhs_reg)) {
1967 // Branch condition is always true, make the branch unconditional.
1968 condition_ = kUncond;
1969 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08001970 InitializeType(kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001971}
1972
Alexey Frunze19f6c692016-11-30 19:19:55 -08001973Mips64Assembler::Branch::Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001974 : old_location_(location),
1975 location_(location),
Alexey Frunze19f6c692016-11-30 19:19:55 -08001976 target_(kUnresolved),
1977 lhs_reg_(dest_reg),
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001978 rhs_reg_(ZERO),
1979 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08001980 CHECK_NE(dest_reg, ZERO);
1981 InitializeType(label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07001982}
1983
1984Mips64Assembler::BranchCondition Mips64Assembler::Branch::OppositeCondition(
1985 Mips64Assembler::BranchCondition cond) {
1986 switch (cond) {
1987 case kCondLT:
1988 return kCondGE;
1989 case kCondGE:
1990 return kCondLT;
1991 case kCondLE:
1992 return kCondGT;
1993 case kCondGT:
1994 return kCondLE;
1995 case kCondLTZ:
1996 return kCondGEZ;
1997 case kCondGEZ:
1998 return kCondLTZ;
1999 case kCondLEZ:
2000 return kCondGTZ;
2001 case kCondGTZ:
2002 return kCondLEZ;
2003 case kCondEQ:
2004 return kCondNE;
2005 case kCondNE:
2006 return kCondEQ;
2007 case kCondEQZ:
2008 return kCondNEZ;
2009 case kCondNEZ:
2010 return kCondEQZ;
2011 case kCondLTU:
2012 return kCondGEU;
2013 case kCondGEU:
2014 return kCondLTU;
Alexey Frunze299a9392015-12-08 16:08:02 -08002015 case kCondF:
2016 return kCondT;
2017 case kCondT:
2018 return kCondF;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002019 case kUncond:
2020 LOG(FATAL) << "Unexpected branch condition " << cond;
2021 }
2022 UNREACHABLE();
2023}
2024
2025Mips64Assembler::Branch::Type Mips64Assembler::Branch::GetType() const {
2026 return type_;
2027}
2028
2029Mips64Assembler::BranchCondition Mips64Assembler::Branch::GetCondition() const {
2030 return condition_;
2031}
2032
2033GpuRegister Mips64Assembler::Branch::GetLeftRegister() const {
2034 return lhs_reg_;
2035}
2036
2037GpuRegister Mips64Assembler::Branch::GetRightRegister() const {
2038 return rhs_reg_;
2039}
2040
2041uint32_t Mips64Assembler::Branch::GetTarget() const {
2042 return target_;
2043}
2044
2045uint32_t Mips64Assembler::Branch::GetLocation() const {
2046 return location_;
2047}
2048
2049uint32_t Mips64Assembler::Branch::GetOldLocation() const {
2050 return old_location_;
2051}
2052
2053uint32_t Mips64Assembler::Branch::GetLength() const {
2054 return branch_info_[type_].length;
2055}
2056
2057uint32_t Mips64Assembler::Branch::GetOldLength() const {
2058 return branch_info_[old_type_].length;
2059}
2060
2061uint32_t Mips64Assembler::Branch::GetSize() const {
2062 return GetLength() * sizeof(uint32_t);
2063}
2064
2065uint32_t Mips64Assembler::Branch::GetOldSize() const {
2066 return GetOldLength() * sizeof(uint32_t);
2067}
2068
2069uint32_t Mips64Assembler::Branch::GetEndLocation() const {
2070 return GetLocation() + GetSize();
2071}
2072
2073uint32_t Mips64Assembler::Branch::GetOldEndLocation() const {
2074 return GetOldLocation() + GetOldSize();
2075}
2076
2077bool Mips64Assembler::Branch::IsLong() const {
2078 switch (type_) {
2079 // Short branches.
2080 case kUncondBranch:
2081 case kCondBranch:
2082 case kCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002083 // Near label.
2084 case kLabel:
2085 // Near literals.
2086 case kLiteral:
2087 case kLiteralUnsigned:
2088 case kLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002089 return false;
2090 // Long branches.
2091 case kLongUncondBranch:
2092 case kLongCondBranch:
2093 case kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002094 // Far label.
2095 case kFarLabel:
2096 // Far literals.
2097 case kFarLiteral:
2098 case kFarLiteralUnsigned:
2099 case kFarLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002100 return true;
2101 }
2102 UNREACHABLE();
2103}
2104
2105bool Mips64Assembler::Branch::IsResolved() const {
2106 return target_ != kUnresolved;
2107}
2108
2109Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSize() const {
2110 OffsetBits offset_size =
2111 (type_ == kCondBranch && (condition_ == kCondEQZ || condition_ == kCondNEZ))
2112 ? kOffset23
2113 : branch_info_[type_].offset_size;
2114 return offset_size;
2115}
2116
2117Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSizeNeeded(uint32_t location,
2118 uint32_t target) {
2119 // For unresolved targets assume the shortest encoding
2120 // (later it will be made longer if needed).
2121 if (target == kUnresolved)
2122 return kOffset16;
2123 int64_t distance = static_cast<int64_t>(target) - location;
2124 // To simplify calculations in composite branches consisting of multiple instructions
2125 // bump up the distance by a value larger than the max byte size of a composite branch.
2126 distance += (distance >= 0) ? kMaxBranchSize : -kMaxBranchSize;
2127 if (IsInt<kOffset16>(distance))
2128 return kOffset16;
2129 else if (IsInt<kOffset18>(distance))
2130 return kOffset18;
2131 else if (IsInt<kOffset21>(distance))
2132 return kOffset21;
2133 else if (IsInt<kOffset23>(distance))
2134 return kOffset23;
2135 else if (IsInt<kOffset28>(distance))
2136 return kOffset28;
2137 return kOffset32;
2138}
2139
2140void Mips64Assembler::Branch::Resolve(uint32_t target) {
2141 target_ = target;
2142}
2143
2144void Mips64Assembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
2145 if (location_ > expand_location) {
2146 location_ += delta;
2147 }
2148 if (!IsResolved()) {
2149 return; // Don't know the target yet.
2150 }
2151 if (target_ > expand_location) {
2152 target_ += delta;
2153 }
2154}
2155
2156void Mips64Assembler::Branch::PromoteToLong() {
2157 switch (type_) {
2158 // Short branches.
2159 case kUncondBranch:
2160 type_ = kLongUncondBranch;
2161 break;
2162 case kCondBranch:
2163 type_ = kLongCondBranch;
2164 break;
2165 case kCall:
2166 type_ = kLongCall;
2167 break;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002168 // Near label.
2169 case kLabel:
2170 type_ = kFarLabel;
2171 break;
2172 // Near literals.
2173 case kLiteral:
2174 type_ = kFarLiteral;
2175 break;
2176 case kLiteralUnsigned:
2177 type_ = kFarLiteralUnsigned;
2178 break;
2179 case kLiteralLong:
2180 type_ = kFarLiteralLong;
2181 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002182 default:
2183 // Note: 'type_' is already long.
2184 break;
2185 }
2186 CHECK(IsLong());
2187}
2188
2189uint32_t Mips64Assembler::Branch::PromoteIfNeeded(uint32_t max_short_distance) {
2190 // If the branch is still unresolved or already long, nothing to do.
2191 if (IsLong() || !IsResolved()) {
2192 return 0;
2193 }
2194 // Promote the short branch to long if the offset size is too small
2195 // to hold the distance between location_ and target_.
2196 if (GetOffsetSizeNeeded(location_, target_) > GetOffsetSize()) {
2197 PromoteToLong();
2198 uint32_t old_size = GetOldSize();
2199 uint32_t new_size = GetSize();
2200 CHECK_GT(new_size, old_size);
2201 return new_size - old_size;
2202 }
2203 // The following logic is for debugging/testing purposes.
2204 // Promote some short branches to long when it's not really required.
2205 if (UNLIKELY(max_short_distance != std::numeric_limits<uint32_t>::max())) {
2206 int64_t distance = static_cast<int64_t>(target_) - location_;
2207 distance = (distance >= 0) ? distance : -distance;
2208 if (distance >= max_short_distance) {
2209 PromoteToLong();
2210 uint32_t old_size = GetOldSize();
2211 uint32_t new_size = GetSize();
2212 CHECK_GT(new_size, old_size);
2213 return new_size - old_size;
2214 }
2215 }
2216 return 0;
2217}
2218
2219uint32_t Mips64Assembler::Branch::GetOffsetLocation() const {
2220 return location_ + branch_info_[type_].instr_offset * sizeof(uint32_t);
2221}
2222
2223uint32_t Mips64Assembler::Branch::GetOffset() const {
2224 CHECK(IsResolved());
2225 uint32_t ofs_mask = 0xFFFFFFFF >> (32 - GetOffsetSize());
2226 // Calculate the byte distance between instructions and also account for
2227 // different PC-relative origins.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002228 uint32_t offset_location = GetOffsetLocation();
2229 if (type_ == kLiteralLong) {
2230 // Special case for the ldpc instruction, whose address (PC) is rounded down to
2231 // a multiple of 8 before adding the offset.
2232 // Note, branch promotion has already taken care of aligning `target_` to an
2233 // address that's a multiple of 8.
2234 offset_location = RoundDown(offset_location, sizeof(uint64_t));
2235 }
2236 uint32_t offset = target_ - offset_location - branch_info_[type_].pc_org * sizeof(uint32_t);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002237 // Prepare the offset for encoding into the instruction(s).
2238 offset = (offset & ofs_mask) >> branch_info_[type_].offset_shift;
2239 return offset;
2240}
2241
2242Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) {
2243 CHECK_LT(branch_id, branches_.size());
2244 return &branches_[branch_id];
2245}
2246
2247const Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) const {
2248 CHECK_LT(branch_id, branches_.size());
2249 return &branches_[branch_id];
2250}
2251
2252void Mips64Assembler::Bind(Mips64Label* label) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002253 CHECK(!label->IsBound());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002254 uint32_t bound_pc = buffer_.Size();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002255
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002256 // Walk the list of branches referring to and preceding this label.
2257 // Store the previously unknown target addresses in them.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002258 while (label->IsLinked()) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002259 uint32_t branch_id = label->Position();
2260 Branch* branch = GetBranch(branch_id);
2261 branch->Resolve(bound_pc);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002262
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002263 uint32_t branch_location = branch->GetLocation();
2264 // Extract the location of the previous branch in the list (walking the list backwards;
2265 // the previous branch ID was stored in the space reserved for this branch).
2266 uint32_t prev = buffer_.Load<uint32_t>(branch_location);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002267
2268 // On to the previous branch in the list...
2269 label->position_ = prev;
2270 }
2271
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002272 // Now make the label object contain its own location (relative to the end of the preceding
2273 // branch, if any; it will be used by the branches referring to and following this label).
2274 label->prev_branch_id_plus_one_ = branches_.size();
2275 if (label->prev_branch_id_plus_one_) {
2276 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2277 const Branch* branch = GetBranch(branch_id);
2278 bound_pc -= branch->GetEndLocation();
2279 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002280 label->BindTo(bound_pc);
2281}
2282
Alexey Frunze19f6c692016-11-30 19:19:55 -08002283uint32_t Mips64Assembler::GetLabelLocation(const Mips64Label* label) const {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002284 CHECK(label->IsBound());
2285 uint32_t target = label->Position();
2286 if (label->prev_branch_id_plus_one_) {
2287 // Get label location based on the branch preceding it.
2288 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2289 const Branch* branch = GetBranch(branch_id);
2290 target += branch->GetEndLocation();
2291 }
2292 return target;
2293}
2294
2295uint32_t Mips64Assembler::GetAdjustedPosition(uint32_t old_position) {
2296 // We can reconstruct the adjustment by going through all the branches from the beginning
2297 // up to the old_position. Since we expect AdjustedPosition() to be called in a loop
2298 // with increasing old_position, we can use the data from last AdjustedPosition() to
2299 // continue where we left off and the whole loop should be O(m+n) where m is the number
2300 // of positions to adjust and n is the number of branches.
2301 if (old_position < last_old_position_) {
2302 last_position_adjustment_ = 0;
2303 last_old_position_ = 0;
2304 last_branch_id_ = 0;
2305 }
2306 while (last_branch_id_ != branches_.size()) {
2307 const Branch* branch = GetBranch(last_branch_id_);
2308 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
2309 break;
2310 }
2311 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
2312 ++last_branch_id_;
2313 }
2314 last_old_position_ = old_position;
2315 return old_position + last_position_adjustment_;
2316}
2317
2318void Mips64Assembler::FinalizeLabeledBranch(Mips64Label* label) {
2319 uint32_t length = branches_.back().GetLength();
2320 if (!label->IsBound()) {
2321 // Branch forward (to a following label), distance is unknown.
2322 // The first branch forward will contain 0, serving as the terminator of
2323 // the list of forward-reaching branches.
2324 Emit(label->position_);
2325 length--;
2326 // Now make the label object point to this branch
2327 // (this forms a linked list of branches preceding this label).
2328 uint32_t branch_id = branches_.size() - 1;
2329 label->LinkTo(branch_id);
2330 }
2331 // Reserve space for the branch.
2332 while (length--) {
2333 Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002334 }
2335}
2336
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002337void Mips64Assembler::Buncond(Mips64Label* label) {
2338 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002339 branches_.emplace_back(buffer_.Size(), target, /* is_call */ false);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002340 FinalizeLabeledBranch(label);
2341}
2342
2343void Mips64Assembler::Bcond(Mips64Label* label,
2344 BranchCondition condition,
2345 GpuRegister lhs,
2346 GpuRegister rhs) {
2347 // If lhs = rhs, this can be a NOP.
2348 if (Branch::IsNop(condition, lhs, rhs)) {
2349 return;
2350 }
2351 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
2352 branches_.emplace_back(buffer_.Size(), target, condition, lhs, rhs);
2353 FinalizeLabeledBranch(label);
2354}
2355
Alexey Frunze19f6c692016-11-30 19:19:55 -08002356void Mips64Assembler::Call(Mips64Label* label) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002357 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002358 branches_.emplace_back(buffer_.Size(), target, /* is_call */ true);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002359 FinalizeLabeledBranch(label);
2360}
2361
Alexey Frunze19f6c692016-11-30 19:19:55 -08002362void Mips64Assembler::LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label) {
2363 // Label address loads are treated as pseudo branches since they require very similar handling.
2364 DCHECK(!label->IsBound());
2365 branches_.emplace_back(buffer_.Size(), dest_reg, Branch::kLabel);
2366 FinalizeLabeledBranch(label);
2367}
2368
2369Literal* Mips64Assembler::NewLiteral(size_t size, const uint8_t* data) {
2370 // We don't support byte and half-word literals.
2371 if (size == 4u) {
2372 literals_.emplace_back(size, data);
2373 return &literals_.back();
2374 } else {
2375 DCHECK_EQ(size, 8u);
2376 long_literals_.emplace_back(size, data);
2377 return &long_literals_.back();
2378 }
2379}
2380
2381void Mips64Assembler::LoadLiteral(GpuRegister dest_reg,
2382 LoadOperandType load_type,
2383 Literal* literal) {
2384 // Literal loads are treated as pseudo branches since they require very similar handling.
2385 Branch::Type literal_type;
2386 switch (load_type) {
2387 case kLoadWord:
2388 DCHECK_EQ(literal->GetSize(), 4u);
2389 literal_type = Branch::kLiteral;
2390 break;
2391 case kLoadUnsignedWord:
2392 DCHECK_EQ(literal->GetSize(), 4u);
2393 literal_type = Branch::kLiteralUnsigned;
2394 break;
2395 case kLoadDoubleword:
2396 DCHECK_EQ(literal->GetSize(), 8u);
2397 literal_type = Branch::kLiteralLong;
2398 break;
2399 default:
2400 LOG(FATAL) << "Unexpected literal load type " << load_type;
2401 UNREACHABLE();
2402 }
2403 Mips64Label* label = literal->GetLabel();
2404 DCHECK(!label->IsBound());
2405 branches_.emplace_back(buffer_.Size(), dest_reg, literal_type);
2406 FinalizeLabeledBranch(label);
2407}
2408
Alexey Frunze0960ac52016-12-20 17:24:59 -08002409JumpTable* Mips64Assembler::CreateJumpTable(std::vector<Mips64Label*>&& labels) {
2410 jump_tables_.emplace_back(std::move(labels));
2411 JumpTable* table = &jump_tables_.back();
2412 DCHECK(!table->GetLabel()->IsBound());
2413 return table;
2414}
2415
2416void Mips64Assembler::ReserveJumpTableSpace() {
2417 if (!jump_tables_.empty()) {
2418 for (JumpTable& table : jump_tables_) {
2419 Mips64Label* label = table.GetLabel();
2420 Bind(label);
2421
2422 // Bulk ensure capacity, as this may be large.
2423 size_t orig_size = buffer_.Size();
2424 size_t required_capacity = orig_size + table.GetSize();
2425 if (required_capacity > buffer_.Capacity()) {
2426 buffer_.ExtendCapacity(required_capacity);
2427 }
2428#ifndef NDEBUG
2429 buffer_.has_ensured_capacity_ = true;
2430#endif
2431
2432 // Fill the space with dummy data as the data is not final
2433 // until the branches have been promoted. And we shouldn't
2434 // be moving uninitialized data during branch promotion.
2435 for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
2436 buffer_.Emit<uint32_t>(0x1abe1234u);
2437 }
2438
2439#ifndef NDEBUG
2440 buffer_.has_ensured_capacity_ = false;
2441#endif
2442 }
2443 }
2444}
2445
2446void Mips64Assembler::EmitJumpTables() {
2447 if (!jump_tables_.empty()) {
2448 CHECK(!overwriting_);
2449 // Switch from appending instructions at the end of the buffer to overwriting
2450 // existing instructions (here, jump tables) in the buffer.
2451 overwriting_ = true;
2452
2453 for (JumpTable& table : jump_tables_) {
2454 Mips64Label* table_label = table.GetLabel();
2455 uint32_t start = GetLabelLocation(table_label);
2456 overwrite_location_ = start;
2457
2458 for (Mips64Label* target : table.GetData()) {
2459 CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
2460 // The table will contain target addresses relative to the table start.
2461 uint32_t offset = GetLabelLocation(target) - start;
2462 Emit(offset);
2463 }
2464 }
2465
2466 overwriting_ = false;
2467 }
2468}
2469
Alexey Frunze19f6c692016-11-30 19:19:55 -08002470void Mips64Assembler::EmitLiterals() {
2471 if (!literals_.empty()) {
2472 for (Literal& literal : literals_) {
2473 Mips64Label* label = literal.GetLabel();
2474 Bind(label);
2475 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2476 DCHECK_EQ(literal.GetSize(), 4u);
2477 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2478 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2479 }
2480 }
2481 }
2482 if (!long_literals_.empty()) {
2483 // Reserve 4 bytes for potential alignment. If after the branch promotion the 64-bit
2484 // literals don't end up 8-byte-aligned, they will be moved down 4 bytes.
2485 Emit(0); // NOP.
2486 for (Literal& literal : long_literals_) {
2487 Mips64Label* label = literal.GetLabel();
2488 Bind(label);
2489 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2490 DCHECK_EQ(literal.GetSize(), 8u);
2491 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2492 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2493 }
2494 }
2495 }
2496}
2497
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002498void Mips64Assembler::PromoteBranches() {
2499 // Promote short branches to long as necessary.
2500 bool changed;
2501 do {
2502 changed = false;
2503 for (auto& branch : branches_) {
2504 CHECK(branch.IsResolved());
2505 uint32_t delta = branch.PromoteIfNeeded();
2506 // If this branch has been promoted and needs to expand in size,
2507 // relocate all branches by the expansion size.
2508 if (delta) {
2509 changed = true;
2510 uint32_t expand_location = branch.GetLocation();
2511 for (auto& branch2 : branches_) {
2512 branch2.Relocate(expand_location, delta);
2513 }
2514 }
2515 }
2516 } while (changed);
2517
2518 // Account for branch expansion by resizing the code buffer
2519 // and moving the code in it to its final location.
2520 size_t branch_count = branches_.size();
2521 if (branch_count > 0) {
2522 // Resize.
2523 Branch& last_branch = branches_[branch_count - 1];
2524 uint32_t size_delta = last_branch.GetEndLocation() - last_branch.GetOldEndLocation();
2525 uint32_t old_size = buffer_.Size();
2526 buffer_.Resize(old_size + size_delta);
2527 // Move the code residing between branch placeholders.
2528 uint32_t end = old_size;
2529 for (size_t i = branch_count; i > 0; ) {
2530 Branch& branch = branches_[--i];
2531 uint32_t size = end - branch.GetOldEndLocation();
2532 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
2533 end = branch.GetOldLocation();
2534 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002535 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08002536
2537 // Align 64-bit literals by moving them down by 4 bytes if needed.
2538 // This will reduce the PC-relative distance, which should be safe for both near and far literals.
2539 if (!long_literals_.empty()) {
2540 uint32_t first_literal_location = GetLabelLocation(long_literals_.front().GetLabel());
2541 size_t lit_size = long_literals_.size() * sizeof(uint64_t);
2542 size_t buf_size = buffer_.Size();
2543 // 64-bit literals must be at the very end of the buffer.
2544 CHECK_EQ(first_literal_location + lit_size, buf_size);
2545 if (!IsAligned<sizeof(uint64_t)>(first_literal_location)) {
2546 buffer_.Move(first_literal_location - sizeof(uint32_t), first_literal_location, lit_size);
2547 // The 4 reserved bytes proved useless, reduce the buffer size.
2548 buffer_.Resize(buf_size - sizeof(uint32_t));
2549 // Reduce target addresses in literal and address loads by 4 bytes in order for correct
2550 // offsets from PC to be generated.
2551 for (auto& branch : branches_) {
2552 uint32_t target = branch.GetTarget();
2553 if (target >= first_literal_location) {
2554 branch.Resolve(target - sizeof(uint32_t));
2555 }
2556 }
2557 // If after this we ever call GetLabelLocation() to get the location of a 64-bit literal,
2558 // we need to adjust the location of the literal's label as well.
2559 for (Literal& literal : long_literals_) {
2560 // Bound label's position is negative, hence incrementing it instead of decrementing.
2561 literal.GetLabel()->position_ += sizeof(uint32_t);
2562 }
2563 }
2564 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002565}
2566
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002567// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2568const Mips64Assembler::Branch::BranchInfo Mips64Assembler::Branch::branch_info_[] = {
2569 // Short branches.
2570 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kUncondBranch
2571 { 2, 0, 1, Mips64Assembler::Branch::kOffset18, 2 }, // kCondBranch
2572 // Exception: kOffset23 for beqzc/bnezc
Alexey Frunze19f6c692016-11-30 19:19:55 -08002573 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kCall
2574 // Near label.
2575 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLabel
2576 // Near literals.
2577 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteral
2578 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteralUnsigned
2579 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 3 }, // kLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002580 // Long branches.
2581 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongUncondBranch
2582 { 3, 1, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCondBranch
Alexey Frunze19f6c692016-11-30 19:19:55 -08002583 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCall
2584 // Far label.
2585 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLabel
2586 // Far literals.
2587 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteral
2588 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralUnsigned
2589 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002590};
2591
2592// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2593void Mips64Assembler::EmitBranch(Mips64Assembler::Branch* branch) {
2594 CHECK(overwriting_);
2595 overwrite_location_ = branch->GetLocation();
2596 uint32_t offset = branch->GetOffset();
2597 BranchCondition condition = branch->GetCondition();
2598 GpuRegister lhs = branch->GetLeftRegister();
2599 GpuRegister rhs = branch->GetRightRegister();
2600 switch (branch->GetType()) {
2601 // Short branches.
2602 case Branch::kUncondBranch:
2603 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2604 Bc(offset);
2605 break;
2606 case Branch::kCondBranch:
2607 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2608 EmitBcondc(condition, lhs, rhs, offset);
Alexey Frunze299a9392015-12-08 16:08:02 -08002609 Nop(); // TODO: improve by filling the forbidden/delay slot.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002610 break;
2611 case Branch::kCall:
2612 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002613 Balc(offset);
2614 break;
2615
2616 // Near label.
2617 case Branch::kLabel:
2618 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002619 Addiupc(lhs, offset);
Alexey Frunze19f6c692016-11-30 19:19:55 -08002620 break;
2621 // Near literals.
2622 case Branch::kLiteral:
2623 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2624 Lwpc(lhs, offset);
2625 break;
2626 case Branch::kLiteralUnsigned:
2627 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2628 Lwupc(lhs, offset);
2629 break;
2630 case Branch::kLiteralLong:
2631 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2632 Ldpc(lhs, offset);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002633 break;
2634
2635 // Long branches.
2636 case Branch::kLongUncondBranch:
2637 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2638 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2639 Auipc(AT, High16Bits(offset));
2640 Jic(AT, Low16Bits(offset));
2641 break;
2642 case Branch::kLongCondBranch:
2643 EmitBcondc(Branch::OppositeCondition(condition), lhs, rhs, 2);
2644 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2645 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2646 Auipc(AT, High16Bits(offset));
2647 Jic(AT, Low16Bits(offset));
2648 break;
2649 case Branch::kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002650 offset += (offset & 0x8000) << 1; // Account for sign extension in jialc.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002651 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002652 Auipc(AT, High16Bits(offset));
2653 Jialc(AT, Low16Bits(offset));
2654 break;
2655
2656 // Far label.
2657 case Branch::kFarLabel:
Alexey Frunzef63f5692016-12-13 17:43:11 -08002658 offset += (offset & 0x8000) << 1; // Account for sign extension in daddiu.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002659 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2660 Auipc(AT, High16Bits(offset));
Alexey Frunzef63f5692016-12-13 17:43:11 -08002661 Daddiu(lhs, AT, Low16Bits(offset));
Alexey Frunze19f6c692016-11-30 19:19:55 -08002662 break;
2663 // Far literals.
2664 case Branch::kFarLiteral:
2665 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
2666 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2667 Auipc(AT, High16Bits(offset));
2668 Lw(lhs, AT, Low16Bits(offset));
2669 break;
2670 case Branch::kFarLiteralUnsigned:
2671 offset += (offset & 0x8000) << 1; // Account for sign extension in lwu.
2672 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2673 Auipc(AT, High16Bits(offset));
2674 Lwu(lhs, AT, Low16Bits(offset));
2675 break;
2676 case Branch::kFarLiteralLong:
2677 offset += (offset & 0x8000) << 1; // Account for sign extension in ld.
2678 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2679 Auipc(AT, High16Bits(offset));
2680 Ld(lhs, AT, Low16Bits(offset));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002681 break;
2682 }
2683 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
2684 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002685}
2686
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002687void Mips64Assembler::Bc(Mips64Label* label) {
2688 Buncond(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002689}
2690
Alexey Frunze19f6c692016-11-30 19:19:55 -08002691void Mips64Assembler::Balc(Mips64Label* label) {
2692 Call(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002693}
2694
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002695void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2696 Bcond(label, kCondLT, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002697}
2698
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002699void Mips64Assembler::Bltzc(GpuRegister rt, Mips64Label* label) {
2700 Bcond(label, kCondLTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002701}
2702
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002703void Mips64Assembler::Bgtzc(GpuRegister rt, Mips64Label* label) {
2704 Bcond(label, kCondGTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002705}
2706
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002707void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2708 Bcond(label, kCondGE, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002709}
2710
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002711void Mips64Assembler::Bgezc(GpuRegister rt, Mips64Label* label) {
2712 Bcond(label, kCondGEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002713}
2714
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002715void Mips64Assembler::Blezc(GpuRegister rt, Mips64Label* label) {
2716 Bcond(label, kCondLEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002717}
2718
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002719void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2720 Bcond(label, kCondLTU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002721}
2722
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002723void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2724 Bcond(label, kCondGEU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002725}
2726
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002727void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2728 Bcond(label, kCondEQ, rs, rt);
2729}
2730
2731void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2732 Bcond(label, kCondNE, rs, rt);
2733}
2734
2735void Mips64Assembler::Beqzc(GpuRegister rs, Mips64Label* label) {
2736 Bcond(label, kCondEQZ, rs);
2737}
2738
2739void Mips64Assembler::Bnezc(GpuRegister rs, Mips64Label* label) {
2740 Bcond(label, kCondNEZ, rs);
Andreas Gampe57b34292015-01-14 15:45:59 -08002741}
2742
Alexey Frunze299a9392015-12-08 16:08:02 -08002743void Mips64Assembler::Bc1eqz(FpuRegister ft, Mips64Label* label) {
2744 Bcond(label, kCondF, static_cast<GpuRegister>(ft), ZERO);
2745}
2746
2747void Mips64Assembler::Bc1nez(FpuRegister ft, Mips64Label* label) {
2748 Bcond(label, kCondT, static_cast<GpuRegister>(ft), ZERO);
2749}
2750
Chris Larsenc3fec0c2016-12-15 11:44:14 -08002751void Mips64Assembler::AdjustBaseAndOffset(GpuRegister& base,
2752 int32_t& offset,
2753 bool is_doubleword) {
2754 // This method is used to adjust the base register and offset pair
2755 // for a load/store when the offset doesn't fit into int16_t.
2756 // It is assumed that `base + offset` is sufficiently aligned for memory
2757 // operands that are machine word in size or smaller. For doubleword-sized
2758 // operands it's assumed that `base` is a multiple of 8, while `offset`
2759 // may be a multiple of 4 (e.g. 4-byte-aligned long and double arguments
2760 // and spilled variables on the stack accessed relative to the stack
2761 // pointer register).
2762 // We preserve the "alignment" of `offset` by adjusting it by a multiple of 8.
2763 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
2764
2765 bool doubleword_aligned = IsAligned<kMips64DoublewordSize>(offset);
2766 bool two_accesses = is_doubleword && !doubleword_aligned;
2767
2768 // IsInt<16> must be passed a signed value, hence the static cast below.
2769 if (IsInt<16>(offset) &&
2770 (!two_accesses || IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)))) {
2771 // Nothing to do: `offset` (and, if needed, `offset + 4`) fits into int16_t.
2772 return;
2773 }
2774
2775 // Remember the "(mis)alignment" of `offset`, it will be checked at the end.
2776 uint32_t misalignment = offset & (kMips64DoublewordSize - 1);
2777
2778 // First, see if `offset` can be represented as a sum of two 16-bit signed
2779 // offsets. This can save an instruction.
2780 // To simplify matters, only do this for a symmetric range of offsets from
2781 // about -64KB to about +64KB, allowing further addition of 4 when accessing
2782 // 64-bit variables with two 32-bit accesses.
2783 constexpr int32_t kMinOffsetForSimpleAdjustment = 0x7ff8; // Max int16_t that's a multiple of 8.
2784 constexpr int32_t kMaxOffsetForSimpleAdjustment = 2 * kMinOffsetForSimpleAdjustment;
2785
2786 if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
2787 Daddiu(AT, base, kMinOffsetForSimpleAdjustment);
2788 offset -= kMinOffsetForSimpleAdjustment;
2789 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
2790 Daddiu(AT, base, -kMinOffsetForSimpleAdjustment);
2791 offset += kMinOffsetForSimpleAdjustment;
2792 } else {
2793 // In more complex cases take advantage of the daui instruction, e.g.:
2794 // daui AT, base, offset_high
2795 // [dahi AT, 1] // When `offset` is close to +2GB.
2796 // lw reg_lo, offset_low(AT)
2797 // [lw reg_hi, (offset_low+4)(AT)] // If misaligned 64-bit load.
2798 // or when offset_low+4 overflows int16_t:
2799 // daui AT, base, offset_high
2800 // daddiu AT, AT, 8
2801 // lw reg_lo, (offset_low-8)(AT)
2802 // lw reg_hi, (offset_low-4)(AT)
2803 int16_t offset_low = Low16Bits(offset);
2804 int32_t offset_low32 = offset_low;
2805 int16_t offset_high = High16Bits(offset);
2806 bool increment_hi16 = offset_low < 0;
2807 bool overflow_hi16 = false;
2808
2809 if (increment_hi16) {
2810 offset_high++;
2811 overflow_hi16 = (offset_high == -32768);
2812 }
2813 Daui(AT, base, offset_high);
2814
2815 if (overflow_hi16) {
2816 Dahi(AT, 1);
2817 }
2818
2819 if (two_accesses && !IsInt<16>(static_cast<int32_t>(offset_low32 + kMips64WordSize))) {
2820 // Avoid overflow in the 16-bit offset of the load/store instruction when adding 4.
2821 Daddiu(AT, AT, kMips64DoublewordSize);
2822 offset_low32 -= kMips64DoublewordSize;
2823 }
2824
2825 offset = offset_low32;
2826 }
2827 base = AT;
2828
2829 CHECK(IsInt<16>(offset));
2830 if (two_accesses) {
2831 CHECK(IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)));
2832 }
2833 CHECK_EQ(misalignment, offset & (kMips64DoublewordSize - 1));
2834}
2835
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02002836void Mips64Assembler::AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
2837 int32_t& offset,
2838 int& element_size_shift) {
2839 // This method is used to adjust the base register, offset and element_size_shift
2840 // for a vector load/store when the offset doesn't fit into allowed number of bits.
2841 // MSA ld.df and st.df instructions take signed offsets as arguments, but maximum
2842 // offset is dependant on the size of the data format df (10-bit offsets for ld.b,
2843 // 11-bit for ld.h, 12-bit for ld.w and 13-bit for ld.d).
2844 // If element_size_shift is non-negative at entry, it won't be changed, but offset
2845 // will be checked for appropriate alignment. If negative at entry, it will be
2846 // adjusted based on offset for maximum fit.
2847 // It's assumed that `base` is a multiple of 8.
2848
2849 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
2850
2851 if (element_size_shift >= 0) {
2852 CHECK_LE(element_size_shift, TIMES_8);
2853 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
2854 } else if (IsAligned<kMips64DoublewordSize>(offset)) {
2855 element_size_shift = TIMES_8;
2856 } else if (IsAligned<kMips64WordSize>(offset)) {
2857 element_size_shift = TIMES_4;
2858 } else if (IsAligned<kMips64HalfwordSize>(offset)) {
2859 element_size_shift = TIMES_2;
2860 } else {
2861 element_size_shift = TIMES_1;
2862 }
2863
2864 const int low_len = 10 + element_size_shift; // How many low bits of `offset` ld.df/st.df
2865 // will take.
2866 int16_t low = offset & ((1 << low_len) - 1); // Isolate these bits.
2867 low -= (low & (1 << (low_len - 1))) << 1; // Sign-extend these bits.
2868 if (low == offset) {
2869 return; // `offset` fits into ld.df/st.df.
2870 }
2871
2872 // First, see if `offset` can be represented as a sum of two signed offsets.
2873 // This can save an instruction.
2874
2875 // Max int16_t that's a multiple of element size.
2876 const int32_t kMaxDeltaForSimpleAdjustment = 0x8000 - (1 << element_size_shift);
2877 // Max ld.df/st.df offset that's a multiple of element size.
2878 const int32_t kMaxLoadStoreOffset = 0x1ff << element_size_shift;
2879 const int32_t kMaxOffsetForSimpleAdjustment = kMaxDeltaForSimpleAdjustment + kMaxLoadStoreOffset;
2880
2881 if (IsInt<16>(offset)) {
2882 Daddiu(AT, base, offset);
2883 offset = 0;
2884 } else if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
2885 Daddiu(AT, base, kMaxDeltaForSimpleAdjustment);
2886 offset -= kMaxDeltaForSimpleAdjustment;
2887 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
2888 Daddiu(AT, base, -kMaxDeltaForSimpleAdjustment);
2889 offset += kMaxDeltaForSimpleAdjustment;
2890 } else {
2891 // Let's treat `offset` as 64-bit to simplify handling of sign
2892 // extensions in the instructions that supply its smaller signed parts.
2893 //
2894 // 16-bit or smaller parts of `offset`:
2895 // |63 top 48|47 hi 32|31 upper 16|15 mid 13-10|12-9 low 0|
2896 //
2897 // Instructions that supply each part as a signed integer addend:
2898 // |dati |dahi |daui |daddiu |ld.df/st.df |
2899 //
2900 // `top` is always 0, so dati isn't used.
2901 // `hi` is 1 when `offset` is close to +2GB and 0 otherwise.
2902 uint64_t tmp = static_cast<uint64_t>(offset) - low; // Exclude `low` from the rest of `offset`
2903 // (accounts for sign of `low`).
2904 tmp += (tmp & (UINT64_C(1) << 15)) << 1; // Account for sign extension in daddiu.
2905 tmp += (tmp & (UINT64_C(1) << 31)) << 1; // Account for sign extension in daui.
2906 int16_t mid = Low16Bits(tmp);
2907 int16_t upper = High16Bits(tmp);
2908 int16_t hi = Low16Bits(High32Bits(tmp));
2909 Daui(AT, base, upper);
2910 if (hi != 0) {
2911 CHECK_EQ(hi, 1);
2912 Dahi(AT, hi);
2913 }
2914 if (mid != 0) {
2915 Daddiu(AT, AT, mid);
2916 }
2917 offset = low;
2918 }
2919 base = AT;
2920 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
2921 CHECK(IsInt<10>(offset >> element_size_shift));
2922}
2923
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002924void Mips64Assembler::LoadFromOffset(LoadOperandType type,
2925 GpuRegister reg,
2926 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002927 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002928 LoadFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002929}
2930
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002931void Mips64Assembler::LoadFpuFromOffset(LoadOperandType type,
2932 FpuRegister reg,
2933 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002934 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002935 LoadFpuFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002936}
2937
2938void Mips64Assembler::EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset,
2939 size_t size) {
2940 Mips64ManagedRegister dst = m_dst.AsMips64();
2941 if (dst.IsNoRegister()) {
2942 CHECK_EQ(0u, size) << dst;
2943 } else if (dst.IsGpuRegister()) {
2944 if (size == 4) {
Andreas Gampe57b34292015-01-14 15:45:59 -08002945 LoadFromOffset(kLoadWord, dst.AsGpuRegister(), src_register, src_offset);
2946 } else if (size == 8) {
2947 CHECK_EQ(8u, size) << dst;
2948 LoadFromOffset(kLoadDoubleword, dst.AsGpuRegister(), src_register, src_offset);
2949 } else {
2950 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
2951 }
2952 } else if (dst.IsFpuRegister()) {
2953 if (size == 4) {
2954 CHECK_EQ(4u, size) << dst;
2955 LoadFpuFromOffset(kLoadWord, dst.AsFpuRegister(), src_register, src_offset);
2956 } else if (size == 8) {
2957 CHECK_EQ(8u, size) << dst;
2958 LoadFpuFromOffset(kLoadDoubleword, dst.AsFpuRegister(), src_register, src_offset);
2959 } else {
2960 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
2961 }
2962 }
2963}
2964
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002965void Mips64Assembler::StoreToOffset(StoreOperandType type,
2966 GpuRegister reg,
2967 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002968 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002969 StoreToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002970}
2971
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002972void Mips64Assembler::StoreFpuToOffset(StoreOperandType type,
2973 FpuRegister reg,
2974 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08002975 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01002976 StoreFpuToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002977}
2978
David Srbeckydd973932015-04-07 20:29:48 +01002979static dwarf::Reg DWARFReg(GpuRegister reg) {
2980 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
2981}
2982
Andreas Gampe57b34292015-01-14 15:45:59 -08002983constexpr size_t kFramePointerSize = 8;
2984
Vladimir Marko32248382016-05-19 10:37:24 +01002985void Mips64Assembler::BuildFrame(size_t frame_size,
2986 ManagedRegister method_reg,
2987 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08002988 const ManagedRegisterEntrySpills& entry_spills) {
2989 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002990 DCHECK(!overwriting_);
Andreas Gampe57b34292015-01-14 15:45:59 -08002991
2992 // Increase frame to required size.
2993 IncreaseFrameSize(frame_size);
2994
2995 // Push callee saves and return address
2996 int stack_offset = frame_size - kFramePointerSize;
2997 StoreToOffset(kStoreDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01002998 cfi_.RelOffset(DWARFReg(RA), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08002999 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
3000 stack_offset -= kFramePointerSize;
Vladimir Marko32248382016-05-19 10:37:24 +01003001 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08003002 StoreToOffset(kStoreDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003003 cfi_.RelOffset(DWARFReg(reg), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003004 }
3005
3006 // Write out Method*.
Mathieu Chartiere401d142015-04-22 13:56:20 -07003007 StoreToOffset(kStoreDoubleword, method_reg.AsMips64().AsGpuRegister(), SP, 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003008
3009 // Write out entry spills.
Mathieu Chartiere401d142015-04-22 13:56:20 -07003010 int32_t offset = frame_size + kFramePointerSize;
Andreas Gampe57b34292015-01-14 15:45:59 -08003011 for (size_t i = 0; i < entry_spills.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003012 Mips64ManagedRegister reg = entry_spills[i].AsMips64();
Andreas Gampe57b34292015-01-14 15:45:59 -08003013 ManagedRegisterSpill spill = entry_spills.at(i);
3014 int32_t size = spill.getSize();
3015 if (reg.IsNoRegister()) {
3016 // only increment stack offset.
3017 offset += size;
3018 } else if (reg.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003019 StoreFpuToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3020 reg.AsFpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003021 offset += size;
3022 } else if (reg.IsGpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003023 StoreToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3024 reg.AsGpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003025 offset += size;
3026 }
3027 }
3028}
3029
3030void Mips64Assembler::RemoveFrame(size_t frame_size,
Vladimir Marko32248382016-05-19 10:37:24 +01003031 ArrayRef<const ManagedRegister> callee_save_regs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003032 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003033 DCHECK(!overwriting_);
David Srbeckydd973932015-04-07 20:29:48 +01003034 cfi_.RememberState();
Andreas Gampe57b34292015-01-14 15:45:59 -08003035
3036 // Pop callee saves and return address
3037 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
3038 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003039 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08003040 LoadFromOffset(kLoadDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003041 cfi_.Restore(DWARFReg(reg));
Andreas Gampe57b34292015-01-14 15:45:59 -08003042 stack_offset += kFramePointerSize;
3043 }
3044 LoadFromOffset(kLoadDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003045 cfi_.Restore(DWARFReg(RA));
Andreas Gampe57b34292015-01-14 15:45:59 -08003046
3047 // Decrease frame to required size.
3048 DecreaseFrameSize(frame_size);
3049
3050 // Then jump to the return address.
3051 Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003052 Nop();
David Srbeckydd973932015-04-07 20:29:48 +01003053
3054 // The CFI should be restored for any code that follows the exit block.
3055 cfi_.RestoreState();
3056 cfi_.DefCFAOffset(frame_size);
Andreas Gampe57b34292015-01-14 15:45:59 -08003057}
3058
3059void Mips64Assembler::IncreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003060 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003061 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003062 Daddiu64(SP, SP, static_cast<int32_t>(-adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003063 cfi_.AdjustCFAOffset(adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003064}
3065
3066void Mips64Assembler::DecreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003067 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003068 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003069 Daddiu64(SP, SP, static_cast<int32_t>(adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003070 cfi_.AdjustCFAOffset(-adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003071}
3072
3073void Mips64Assembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
3074 Mips64ManagedRegister src = msrc.AsMips64();
3075 if (src.IsNoRegister()) {
3076 CHECK_EQ(0u, size);
3077 } else if (src.IsGpuRegister()) {
3078 CHECK(size == 4 || size == 8) << size;
3079 if (size == 8) {
3080 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3081 } else if (size == 4) {
3082 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3083 } else {
3084 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3085 }
3086 } else if (src.IsFpuRegister()) {
3087 CHECK(size == 4 || size == 8) << size;
3088 if (size == 8) {
3089 StoreFpuToOffset(kStoreDoubleword, src.AsFpuRegister(), SP, dest.Int32Value());
3090 } else if (size == 4) {
3091 StoreFpuToOffset(kStoreWord, src.AsFpuRegister(), SP, dest.Int32Value());
3092 } else {
3093 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3094 }
3095 }
3096}
3097
3098void Mips64Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
3099 Mips64ManagedRegister src = msrc.AsMips64();
3100 CHECK(src.IsGpuRegister());
3101 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3102}
3103
3104void Mips64Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
3105 Mips64ManagedRegister src = msrc.AsMips64();
3106 CHECK(src.IsGpuRegister());
3107 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3108}
3109
3110void Mips64Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
3111 ManagedRegister mscratch) {
3112 Mips64ManagedRegister scratch = mscratch.AsMips64();
3113 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003114 LoadConst32(scratch.AsGpuRegister(), imm);
Andreas Gampe57b34292015-01-14 15:45:59 -08003115 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3116}
3117
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003118void Mips64Assembler::StoreStackOffsetToThread(ThreadOffset64 thr_offs,
3119 FrameOffset fr_offs,
3120 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003121 Mips64ManagedRegister scratch = mscratch.AsMips64();
3122 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003123 Daddiu64(scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003124 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3125}
3126
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003127void Mips64Assembler::StoreStackPointerToThread(ThreadOffset64 thr_offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003128 StoreToOffset(kStoreDoubleword, SP, S1, thr_offs.Int32Value());
3129}
3130
3131void Mips64Assembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
3132 FrameOffset in_off, ManagedRegister mscratch) {
3133 Mips64ManagedRegister src = msrc.AsMips64();
3134 Mips64ManagedRegister scratch = mscratch.AsMips64();
3135 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3136 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, in_off.Int32Value());
3137 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value() + 8);
3138}
3139
3140void Mips64Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
3141 return EmitLoad(mdest, SP, src.Int32Value(), size);
3142}
3143
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003144void Mips64Assembler::LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003145 return EmitLoad(mdest, S1, src.Int32Value(), size);
3146}
3147
3148void Mips64Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
3149 Mips64ManagedRegister dest = mdest.AsMips64();
3150 CHECK(dest.IsGpuRegister());
Douglas Leungd90957f2015-04-30 19:22:49 -07003151 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(), SP, src.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003152}
3153
Mathieu Chartiere401d142015-04-22 13:56:20 -07003154void Mips64Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01003155 bool unpoison_reference) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003156 Mips64ManagedRegister dest = mdest.AsMips64();
Douglas Leungd90957f2015-04-30 19:22:49 -07003157 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
3158 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003159 base.AsMips64().AsGpuRegister(), offs.Int32Value());
Alexey Frunzec061de12017-02-14 13:27:23 -08003160 if (unpoison_reference) {
3161 MaybeUnpoisonHeapReference(dest.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003162 }
3163}
3164
3165void Mips64Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003166 Offset offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003167 Mips64ManagedRegister dest = mdest.AsMips64();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003168 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003169 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(),
3170 base.AsMips64().AsGpuRegister(), offs.Int32Value());
3171}
3172
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003173void Mips64Assembler::LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003174 Mips64ManagedRegister dest = mdest.AsMips64();
3175 CHECK(dest.IsGpuRegister());
3176 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(), S1, offs.Int32Value());
3177}
3178
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003179void Mips64Assembler::SignExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3180 size_t size ATTRIBUTE_UNUSED) {
3181 UNIMPLEMENTED(FATAL) << "No sign extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003182}
3183
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003184void Mips64Assembler::ZeroExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3185 size_t size ATTRIBUTE_UNUSED) {
3186 UNIMPLEMENTED(FATAL) << "No zero extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003187}
3188
3189void Mips64Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
3190 Mips64ManagedRegister dest = mdest.AsMips64();
3191 Mips64ManagedRegister src = msrc.AsMips64();
3192 if (!dest.Equals(src)) {
3193 if (dest.IsGpuRegister()) {
3194 CHECK(src.IsGpuRegister()) << src;
3195 Move(dest.AsGpuRegister(), src.AsGpuRegister());
3196 } else if (dest.IsFpuRegister()) {
3197 CHECK(src.IsFpuRegister()) << src;
3198 if (size == 4) {
3199 MovS(dest.AsFpuRegister(), src.AsFpuRegister());
3200 } else if (size == 8) {
3201 MovD(dest.AsFpuRegister(), src.AsFpuRegister());
3202 } else {
3203 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3204 }
3205 }
3206 }
3207}
3208
3209void Mips64Assembler::CopyRef(FrameOffset dest, FrameOffset src,
3210 ManagedRegister mscratch) {
3211 Mips64ManagedRegister scratch = mscratch.AsMips64();
3212 CHECK(scratch.IsGpuRegister()) << scratch;
3213 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
3214 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3215}
3216
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003217void Mips64Assembler::CopyRawPtrFromThread(FrameOffset fr_offs,
3218 ThreadOffset64 thr_offs,
3219 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003220 Mips64ManagedRegister scratch = mscratch.AsMips64();
3221 CHECK(scratch.IsGpuRegister()) << scratch;
3222 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3223 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
3224}
3225
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003226void Mips64Assembler::CopyRawPtrToThread(ThreadOffset64 thr_offs,
3227 FrameOffset fr_offs,
3228 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003229 Mips64ManagedRegister scratch = mscratch.AsMips64();
3230 CHECK(scratch.IsGpuRegister()) << scratch;
3231 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3232 SP, fr_offs.Int32Value());
3233 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(),
3234 S1, thr_offs.Int32Value());
3235}
3236
3237void Mips64Assembler::Copy(FrameOffset dest, FrameOffset src,
3238 ManagedRegister mscratch, size_t size) {
3239 Mips64ManagedRegister scratch = mscratch.AsMips64();
3240 CHECK(scratch.IsGpuRegister()) << scratch;
3241 CHECK(size == 4 || size == 8) << size;
3242 if (size == 4) {
3243 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003244 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003245 } else if (size == 8) {
3246 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, src.Int32Value());
3247 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
3248 } else {
3249 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3250 }
3251}
3252
3253void Mips64Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003254 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003255 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3256 CHECK(size == 4 || size == 8) << size;
3257 if (size == 4) {
3258 LoadFromOffset(kLoadWord, scratch, src_base.AsMips64().AsGpuRegister(),
3259 src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003260 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003261 } else if (size == 8) {
3262 LoadFromOffset(kLoadDoubleword, scratch, src_base.AsMips64().AsGpuRegister(),
3263 src_offset.Int32Value());
3264 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
3265 } else {
3266 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3267 }
3268}
3269
3270void Mips64Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003271 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003272 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3273 CHECK(size == 4 || size == 8) << size;
3274 if (size == 4) {
3275 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003276 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003277 dest_offset.Int32Value());
3278 } else if (size == 8) {
3279 LoadFromOffset(kLoadDoubleword, scratch, SP, src.Int32Value());
3280 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
3281 dest_offset.Int32Value());
3282 } else {
3283 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3284 }
3285}
3286
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003287void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3288 FrameOffset src_base ATTRIBUTE_UNUSED,
3289 Offset src_offset ATTRIBUTE_UNUSED,
3290 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3291 size_t size ATTRIBUTE_UNUSED) {
3292 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003293}
3294
3295void Mips64Assembler::Copy(ManagedRegister dest, Offset dest_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003296 ManagedRegister src, Offset src_offset,
3297 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003298 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3299 CHECK(size == 4 || size == 8) << size;
3300 if (size == 4) {
3301 LoadFromOffset(kLoadWord, scratch, src.AsMips64().AsGpuRegister(), src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003302 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(), dest_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003303 } else if (size == 8) {
3304 LoadFromOffset(kLoadDoubleword, scratch, src.AsMips64().AsGpuRegister(),
3305 src_offset.Int32Value());
3306 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(),
3307 dest_offset.Int32Value());
3308 } else {
3309 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3310 }
3311}
3312
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003313void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3314 Offset dest_offset ATTRIBUTE_UNUSED,
3315 FrameOffset src ATTRIBUTE_UNUSED,
3316 Offset src_offset ATTRIBUTE_UNUSED,
3317 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3318 size_t size ATTRIBUTE_UNUSED) {
3319 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003320}
3321
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003322void Mips64Assembler::MemoryBarrier(ManagedRegister mreg ATTRIBUTE_UNUSED) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003323 // TODO: sync?
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003324 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003325}
3326
3327void Mips64Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003328 FrameOffset handle_scope_offset,
3329 ManagedRegister min_reg,
3330 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003331 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3332 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3333 CHECK(in_reg.IsNoRegister() || in_reg.IsGpuRegister()) << in_reg;
3334 CHECK(out_reg.IsGpuRegister()) << out_reg;
3335 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003336 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003337 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3338 // the address in the handle scope holding the reference.
3339 // e.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset)
3340 if (in_reg.IsNoRegister()) {
Douglas Leungd90957f2015-04-30 19:22:49 -07003341 LoadFromOffset(kLoadUnsignedWord, out_reg.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003342 SP, handle_scope_offset.Int32Value());
3343 in_reg = out_reg;
3344 }
3345 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003346 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003347 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003348 Beqzc(in_reg.AsGpuRegister(), &null_arg);
3349 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3350 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003351 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003352 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003353 }
3354}
3355
3356void Mips64Assembler::CreateHandleScopeEntry(FrameOffset out_off,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003357 FrameOffset handle_scope_offset,
3358 ManagedRegister mscratch,
3359 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003360 Mips64ManagedRegister scratch = mscratch.AsMips64();
3361 CHECK(scratch.IsGpuRegister()) << scratch;
3362 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003363 Mips64Label null_arg;
Douglas Leungd90957f2015-04-30 19:22:49 -07003364 LoadFromOffset(kLoadUnsignedWord, scratch.AsGpuRegister(), SP,
Andreas Gampe57b34292015-01-14 15:45:59 -08003365 handle_scope_offset.Int32Value());
3366 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3367 // the address in the handle scope holding the reference.
3368 // e.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003369 Beqzc(scratch.AsGpuRegister(), &null_arg);
3370 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3371 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003372 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003373 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003374 }
3375 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, out_off.Int32Value());
3376}
3377
3378// Given a handle scope entry, load the associated reference.
3379void Mips64Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003380 ManagedRegister min_reg) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003381 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3382 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3383 CHECK(out_reg.IsGpuRegister()) << out_reg;
3384 CHECK(in_reg.IsGpuRegister()) << in_reg;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003385 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003386 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003387 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003388 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003389 Beqzc(in_reg.AsGpuRegister(), &null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003390 LoadFromOffset(kLoadDoubleword, out_reg.AsGpuRegister(),
3391 in_reg.AsGpuRegister(), 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003392 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003393}
3394
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003395void Mips64Assembler::VerifyObject(ManagedRegister src ATTRIBUTE_UNUSED,
3396 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003397 // TODO: not validating references
3398}
3399
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003400void Mips64Assembler::VerifyObject(FrameOffset src ATTRIBUTE_UNUSED,
3401 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003402 // TODO: not validating references
3403}
3404
3405void Mips64Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
3406 Mips64ManagedRegister base = mbase.AsMips64();
3407 Mips64ManagedRegister scratch = mscratch.AsMips64();
3408 CHECK(base.IsGpuRegister()) << base;
3409 CHECK(scratch.IsGpuRegister()) << scratch;
3410 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3411 base.AsGpuRegister(), offset.Int32Value());
3412 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003413 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003414 // TODO: place reference map on call
3415}
3416
3417void Mips64Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
3418 Mips64ManagedRegister scratch = mscratch.AsMips64();
3419 CHECK(scratch.IsGpuRegister()) << scratch;
3420 // Call *(*(SP + base) + offset)
Mathieu Chartiere401d142015-04-22 13:56:20 -07003421 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003422 SP, base.Int32Value());
3423 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3424 scratch.AsGpuRegister(), offset.Int32Value());
3425 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003426 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003427 // TODO: place reference map on call
3428}
3429
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003430void Mips64Assembler::CallFromThread(ThreadOffset64 offset ATTRIBUTE_UNUSED,
3431 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003432 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003433}
3434
3435void Mips64Assembler::GetCurrentThread(ManagedRegister tr) {
3436 Move(tr.AsMips64().AsGpuRegister(), S1);
3437}
3438
3439void Mips64Assembler::GetCurrentThread(FrameOffset offset,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003440 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003441 StoreToOffset(kStoreDoubleword, S1, SP, offset.Int32Value());
3442}
3443
3444void Mips64Assembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
3445 Mips64ManagedRegister scratch = mscratch.AsMips64();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003446 exception_blocks_.emplace_back(scratch, stack_adjust);
3447 LoadFromOffset(kLoadDoubleword,
3448 scratch.AsGpuRegister(),
3449 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003450 Thread::ExceptionOffset<kMips64PointerSize>().Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003451 Bnezc(scratch.AsGpuRegister(), exception_blocks_.back().Entry());
Andreas Gampe57b34292015-01-14 15:45:59 -08003452}
3453
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003454void Mips64Assembler::EmitExceptionPoll(Mips64ExceptionSlowPath* exception) {
3455 Bind(exception->Entry());
3456 if (exception->stack_adjust_ != 0) { // Fix up the frame.
3457 DecreaseFrameSize(exception->stack_adjust_);
Andreas Gampe57b34292015-01-14 15:45:59 -08003458 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003459 // Pass exception object as argument.
3460 // Don't care about preserving A0 as this call won't return.
3461 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3462 Move(A0, exception->scratch_.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003463 // Set up call to Thread::Current()->pDeliverException
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003464 LoadFromOffset(kLoadDoubleword,
3465 T9,
3466 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003467 QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, pDeliverException).Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003468 Jr(T9);
3469 Nop();
3470
Andreas Gampe57b34292015-01-14 15:45:59 -08003471 // Call never returns
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003472 Break();
Andreas Gampe57b34292015-01-14 15:45:59 -08003473}
3474
3475} // namespace mips64
3476} // namespace art