blob: 7a1beb656b0fd65250b4c38f2aaac1172ac6c069 [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 Frunze4147fcc2017-06-17 19:57:27 -0700798void Mips64Assembler::Beqz(GpuRegister rt, uint16_t imm16) {
799 EmitI(0x4, ZERO, rt, imm16);
800}
801
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700802void Mips64Assembler::EmitBcondc(BranchCondition cond,
803 GpuRegister rs,
804 GpuRegister rt,
805 uint32_t imm16_21) {
806 switch (cond) {
807 case kCondLT:
808 Bltc(rs, rt, imm16_21);
809 break;
810 case kCondGE:
811 Bgec(rs, rt, imm16_21);
812 break;
813 case kCondLE:
814 Bgec(rt, rs, imm16_21);
815 break;
816 case kCondGT:
817 Bltc(rt, rs, imm16_21);
818 break;
819 case kCondLTZ:
820 CHECK_EQ(rt, ZERO);
821 Bltzc(rs, imm16_21);
822 break;
823 case kCondGEZ:
824 CHECK_EQ(rt, ZERO);
825 Bgezc(rs, imm16_21);
826 break;
827 case kCondLEZ:
828 CHECK_EQ(rt, ZERO);
829 Blezc(rs, imm16_21);
830 break;
831 case kCondGTZ:
832 CHECK_EQ(rt, ZERO);
833 Bgtzc(rs, imm16_21);
834 break;
835 case kCondEQ:
836 Beqc(rs, rt, imm16_21);
837 break;
838 case kCondNE:
839 Bnec(rs, rt, imm16_21);
840 break;
841 case kCondEQZ:
842 CHECK_EQ(rt, ZERO);
843 Beqzc(rs, imm16_21);
844 break;
845 case kCondNEZ:
846 CHECK_EQ(rt, ZERO);
847 Bnezc(rs, imm16_21);
848 break;
849 case kCondLTU:
850 Bltuc(rs, rt, imm16_21);
851 break;
852 case kCondGEU:
853 Bgeuc(rs, rt, imm16_21);
854 break;
Alexey Frunze299a9392015-12-08 16:08:02 -0800855 case kCondF:
856 CHECK_EQ(rt, ZERO);
857 Bc1eqz(static_cast<FpuRegister>(rs), imm16_21);
858 break;
859 case kCondT:
860 CHECK_EQ(rt, ZERO);
861 Bc1nez(static_cast<FpuRegister>(rs), imm16_21);
862 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -0700863 case kUncond:
864 LOG(FATAL) << "Unexpected branch condition " << cond;
865 UNREACHABLE();
866 }
867}
868
Andreas Gampe57b34292015-01-14 15:45:59 -0800869void Mips64Assembler::AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
870 EmitFR(0x11, 0x10, ft, fs, fd, 0x0);
871}
872
873void Mips64Assembler::SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
874 EmitFR(0x11, 0x10, ft, fs, fd, 0x1);
875}
876
877void Mips64Assembler::MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
878 EmitFR(0x11, 0x10, ft, fs, fd, 0x2);
879}
880
881void Mips64Assembler::DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
882 EmitFR(0x11, 0x10, ft, fs, fd, 0x3);
883}
884
885void Mips64Assembler::AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700886 EmitFR(0x11, 0x11, ft, fs, fd, 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -0800887}
888
889void Mips64Assembler::SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700890 EmitFR(0x11, 0x11, ft, fs, fd, 0x1);
Andreas Gampe57b34292015-01-14 15:45:59 -0800891}
892
893void Mips64Assembler::MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700894 EmitFR(0x11, 0x11, ft, fs, fd, 0x2);
Andreas Gampe57b34292015-01-14 15:45:59 -0800895}
896
897void Mips64Assembler::DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700898 EmitFR(0x11, 0x11, ft, fs, fd, 0x3);
Andreas Gampe57b34292015-01-14 15:45:59 -0800899}
900
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700901void Mips64Assembler::SqrtS(FpuRegister fd, FpuRegister fs) {
902 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x4);
903}
904
905void Mips64Assembler::SqrtD(FpuRegister fd, FpuRegister fs) {
906 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x4);
907}
908
909void Mips64Assembler::AbsS(FpuRegister fd, FpuRegister fs) {
910 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x5);
911}
912
913void Mips64Assembler::AbsD(FpuRegister fd, FpuRegister fs) {
914 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x5);
915}
916
Andreas Gampe57b34292015-01-14 15:45:59 -0800917void Mips64Assembler::MovS(FpuRegister fd, FpuRegister fs) {
918 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x6);
919}
920
921void Mips64Assembler::MovD(FpuRegister fd, FpuRegister fs) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700922 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x6);
923}
924
925void Mips64Assembler::NegS(FpuRegister fd, FpuRegister fs) {
926 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x7);
927}
928
929void Mips64Assembler::NegD(FpuRegister fd, FpuRegister fs) {
930 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x7);
931}
932
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700933void Mips64Assembler::RoundLS(FpuRegister fd, FpuRegister fs) {
934 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x8);
935}
936
937void Mips64Assembler::RoundLD(FpuRegister fd, FpuRegister fs) {
938 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x8);
939}
940
941void Mips64Assembler::RoundWS(FpuRegister fd, FpuRegister fs) {
942 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xc);
943}
944
945void Mips64Assembler::RoundWD(FpuRegister fd, FpuRegister fs) {
946 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xc);
947}
948
Alexey Frunzebaf60b72015-12-22 15:15:03 -0800949void Mips64Assembler::TruncLS(FpuRegister fd, FpuRegister fs) {
950 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x9);
951}
952
953void Mips64Assembler::TruncLD(FpuRegister fd, FpuRegister fs) {
954 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x9);
955}
956
957void Mips64Assembler::TruncWS(FpuRegister fd, FpuRegister fs) {
958 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xd);
959}
960
961void Mips64Assembler::TruncWD(FpuRegister fd, FpuRegister fs) {
962 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xd);
963}
964
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700965void Mips64Assembler::CeilLS(FpuRegister fd, FpuRegister fs) {
966 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xa);
967}
968
969void Mips64Assembler::CeilLD(FpuRegister fd, FpuRegister fs) {
970 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xa);
971}
972
973void Mips64Assembler::CeilWS(FpuRegister fd, FpuRegister fs) {
974 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xe);
975}
976
977void Mips64Assembler::CeilWD(FpuRegister fd, FpuRegister fs) {
978 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xe);
979}
980
981void Mips64Assembler::FloorLS(FpuRegister fd, FpuRegister fs) {
982 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xb);
983}
984
985void Mips64Assembler::FloorLD(FpuRegister fd, FpuRegister fs) {
986 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xb);
987}
988
989void Mips64Assembler::FloorWS(FpuRegister fd, FpuRegister fs) {
990 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xf);
991}
992
993void Mips64Assembler::FloorWD(FpuRegister fd, FpuRegister fs) {
994 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xf);
995}
996
997void Mips64Assembler::SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
998 EmitFR(0x11, 0x10, ft, fs, fd, 0x10);
999}
1000
1001void Mips64Assembler::SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1002 EmitFR(0x11, 0x11, ft, fs, fd, 0x10);
1003}
1004
1005void Mips64Assembler::RintS(FpuRegister fd, FpuRegister fs) {
1006 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1a);
1007}
1008
1009void Mips64Assembler::RintD(FpuRegister fd, FpuRegister fs) {
1010 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1a);
1011}
1012
1013void Mips64Assembler::ClassS(FpuRegister fd, FpuRegister fs) {
1014 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1b);
1015}
1016
1017void Mips64Assembler::ClassD(FpuRegister fd, FpuRegister fs) {
1018 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1b);
1019}
1020
1021void Mips64Assembler::MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1022 EmitFR(0x11, 0x10, ft, fs, fd, 0x1c);
1023}
1024
1025void Mips64Assembler::MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1026 EmitFR(0x11, 0x11, ft, fs, fd, 0x1c);
1027}
1028
1029void Mips64Assembler::MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1030 EmitFR(0x11, 0x10, ft, fs, fd, 0x1e);
1031}
1032
1033void Mips64Assembler::MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1034 EmitFR(0x11, 0x11, ft, fs, fd, 0x1e);
1035}
1036
Alexey Frunze299a9392015-12-08 16:08:02 -08001037void Mips64Assembler::CmpUnS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1038 EmitFR(0x11, 0x14, ft, fs, fd, 0x01);
1039}
1040
1041void Mips64Assembler::CmpEqS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1042 EmitFR(0x11, 0x14, ft, fs, fd, 0x02);
1043}
1044
1045void Mips64Assembler::CmpUeqS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1046 EmitFR(0x11, 0x14, ft, fs, fd, 0x03);
1047}
1048
1049void Mips64Assembler::CmpLtS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1050 EmitFR(0x11, 0x14, ft, fs, fd, 0x04);
1051}
1052
1053void Mips64Assembler::CmpUltS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1054 EmitFR(0x11, 0x14, ft, fs, fd, 0x05);
1055}
1056
1057void Mips64Assembler::CmpLeS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1058 EmitFR(0x11, 0x14, ft, fs, fd, 0x06);
1059}
1060
1061void Mips64Assembler::CmpUleS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1062 EmitFR(0x11, 0x14, ft, fs, fd, 0x07);
1063}
1064
1065void Mips64Assembler::CmpOrS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1066 EmitFR(0x11, 0x14, ft, fs, fd, 0x11);
1067}
1068
1069void Mips64Assembler::CmpUneS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1070 EmitFR(0x11, 0x14, ft, fs, fd, 0x12);
1071}
1072
1073void Mips64Assembler::CmpNeS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1074 EmitFR(0x11, 0x14, ft, fs, fd, 0x13);
1075}
1076
1077void Mips64Assembler::CmpUnD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1078 EmitFR(0x11, 0x15, ft, fs, fd, 0x01);
1079}
1080
1081void Mips64Assembler::CmpEqD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1082 EmitFR(0x11, 0x15, ft, fs, fd, 0x02);
1083}
1084
1085void Mips64Assembler::CmpUeqD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1086 EmitFR(0x11, 0x15, ft, fs, fd, 0x03);
1087}
1088
1089void Mips64Assembler::CmpLtD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1090 EmitFR(0x11, 0x15, ft, fs, fd, 0x04);
1091}
1092
1093void Mips64Assembler::CmpUltD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1094 EmitFR(0x11, 0x15, ft, fs, fd, 0x05);
1095}
1096
1097void Mips64Assembler::CmpLeD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1098 EmitFR(0x11, 0x15, ft, fs, fd, 0x06);
1099}
1100
1101void Mips64Assembler::CmpUleD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1102 EmitFR(0x11, 0x15, ft, fs, fd, 0x07);
1103}
1104
1105void Mips64Assembler::CmpOrD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1106 EmitFR(0x11, 0x15, ft, fs, fd, 0x11);
1107}
1108
1109void Mips64Assembler::CmpUneD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1110 EmitFR(0x11, 0x15, ft, fs, fd, 0x12);
1111}
1112
1113void Mips64Assembler::CmpNeD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
1114 EmitFR(0x11, 0x15, ft, fs, fd, 0x13);
1115}
1116
Alexey Frunze4dda3372015-06-01 18:31:49 -07001117void Mips64Assembler::Cvtsw(FpuRegister fd, FpuRegister fs) {
1118 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x20);
1119}
1120
1121void Mips64Assembler::Cvtdw(FpuRegister fd, FpuRegister fs) {
1122 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x21);
1123}
1124
1125void Mips64Assembler::Cvtsd(FpuRegister fd, FpuRegister fs) {
1126 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x20);
1127}
1128
1129void Mips64Assembler::Cvtds(FpuRegister fd, FpuRegister fs) {
1130 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x21);
Andreas Gampe57b34292015-01-14 15:45:59 -08001131}
1132
Chris Larsen51417632015-10-02 13:24:25 -07001133void Mips64Assembler::Cvtsl(FpuRegister fd, FpuRegister fs) {
1134 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x20);
1135}
1136
Chris Larsen2fadd7b2015-08-14 14:56:10 -07001137void Mips64Assembler::Cvtdl(FpuRegister fd, FpuRegister fs) {
1138 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x21);
1139}
1140
Andreas Gampe57b34292015-01-14 15:45:59 -08001141void Mips64Assembler::Mfc1(GpuRegister rt, FpuRegister fs) {
1142 EmitFR(0x11, 0x00, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1143}
1144
Lazar Trsicd9672662015-09-03 17:33:01 +02001145void Mips64Assembler::Mfhc1(GpuRegister rt, FpuRegister fs) {
1146 EmitFR(0x11, 0x03, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1147}
1148
Alexey Frunze4dda3372015-06-01 18:31:49 -07001149void Mips64Assembler::Mtc1(GpuRegister rt, FpuRegister fs) {
1150 EmitFR(0x11, 0x04, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1151}
1152
Lazar Trsicd9672662015-09-03 17:33:01 +02001153void Mips64Assembler::Mthc1(GpuRegister rt, FpuRegister fs) {
1154 EmitFR(0x11, 0x07, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1155}
1156
Alexey Frunze4dda3372015-06-01 18:31:49 -07001157void Mips64Assembler::Dmfc1(GpuRegister rt, FpuRegister fs) {
1158 EmitFR(0x11, 0x01, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
1159}
1160
1161void Mips64Assembler::Dmtc1(GpuRegister rt, FpuRegister fs) {
1162 EmitFR(0x11, 0x05, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -08001163}
1164
1165void Mips64Assembler::Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1166 EmitI(0x31, rs, static_cast<GpuRegister>(ft), imm16);
1167}
1168
1169void Mips64Assembler::Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1170 EmitI(0x35, rs, static_cast<GpuRegister>(ft), imm16);
1171}
1172
1173void Mips64Assembler::Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1174 EmitI(0x39, rs, static_cast<GpuRegister>(ft), imm16);
1175}
1176
1177void Mips64Assembler::Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
1178 EmitI(0x3d, rs, static_cast<GpuRegister>(ft), imm16);
1179}
1180
1181void Mips64Assembler::Break() {
1182 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
1183 static_cast<GpuRegister>(0), 0, 0xD);
1184}
1185
1186void Mips64Assembler::Nop() {
1187 EmitR(0x0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
1188 static_cast<GpuRegister>(0), 0, 0x0);
1189}
1190
Alexey Frunze4dda3372015-06-01 18:31:49 -07001191void Mips64Assembler::Move(GpuRegister rd, GpuRegister rs) {
1192 Or(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001193}
1194
Alexey Frunze4dda3372015-06-01 18:31:49 -07001195void Mips64Assembler::Clear(GpuRegister rd) {
1196 Move(rd, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001197}
1198
Alexey Frunze4dda3372015-06-01 18:31:49 -07001199void Mips64Assembler::Not(GpuRegister rd, GpuRegister rs) {
1200 Nor(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -08001201}
1202
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001203void Mips64Assembler::AndV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001204 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001205 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1e);
1206}
1207
1208void Mips64Assembler::OrV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001209 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001210 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1e);
1211}
1212
1213void Mips64Assembler::NorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001214 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001215 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1e);
1216}
1217
1218void Mips64Assembler::XorV(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001219 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001220 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1e);
1221}
1222
1223void Mips64Assembler::AddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001224 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001225 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xe);
1226}
1227
1228void Mips64Assembler::AddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001229 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001230 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xe);
1231}
1232
1233void Mips64Assembler::AddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001234 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001235 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xe);
1236}
1237
1238void Mips64Assembler::AddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001239 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001240 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xe);
1241}
1242
1243void Mips64Assembler::SubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001244 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001245 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xe);
1246}
1247
1248void Mips64Assembler::SubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001249 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001250 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xe);
1251}
1252
1253void Mips64Assembler::SubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001254 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001255 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xe);
1256}
1257
1258void Mips64Assembler::SubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001259 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001260 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xe);
1261}
1262
1263void Mips64Assembler::MulvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001264 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001265 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x12);
1266}
1267
1268void Mips64Assembler::MulvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001269 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001270 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x12);
1271}
1272
1273void Mips64Assembler::MulvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001274 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001275 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x12);
1276}
1277
1278void Mips64Assembler::MulvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001279 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001280 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x12);
1281}
1282
1283void Mips64Assembler::Div_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001284 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001285 EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x12);
1286}
1287
1288void Mips64Assembler::Div_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001289 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001290 EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x12);
1291}
1292
1293void Mips64Assembler::Div_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001294 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001295 EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x12);
1296}
1297
1298void Mips64Assembler::Div_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001299 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001300 EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x12);
1301}
1302
1303void Mips64Assembler::Div_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001304 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001305 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x12);
1306}
1307
1308void Mips64Assembler::Div_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001309 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001310 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x12);
1311}
1312
1313void Mips64Assembler::Div_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001314 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001315 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x12);
1316}
1317
1318void Mips64Assembler::Div_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001319 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001320 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x12);
1321}
1322
1323void Mips64Assembler::Mod_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001324 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001325 EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x12);
1326}
1327
1328void Mips64Assembler::Mod_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001329 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001330 EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x12);
1331}
1332
1333void Mips64Assembler::Mod_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001334 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001335 EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x12);
1336}
1337
1338void Mips64Assembler::Mod_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001339 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001340 EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x12);
1341}
1342
1343void Mips64Assembler::Mod_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001344 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001345 EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x12);
1346}
1347
1348void Mips64Assembler::Mod_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001349 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001350 EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x12);
1351}
1352
1353void Mips64Assembler::Mod_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001354 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001355 EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x12);
1356}
1357
1358void Mips64Assembler::Mod_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001359 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001360 EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x12);
1361}
1362
Goran Jakovljevic80248d72017-04-20 11:55:47 +02001363void Mips64Assembler::Add_aB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1364 CHECK(HasMsa());
1365 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x10);
1366}
1367
1368void Mips64Assembler::Add_aH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1369 CHECK(HasMsa());
1370 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x10);
1371}
1372
1373void Mips64Assembler::Add_aW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1374 CHECK(HasMsa());
1375 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x10);
1376}
1377
1378void Mips64Assembler::Add_aD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1379 CHECK(HasMsa());
1380 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x10);
1381}
1382
1383void Mips64Assembler::Ave_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1384 CHECK(HasMsa());
1385 EmitMsa3R(0x4, 0x0, wt, ws, wd, 0x10);
1386}
1387
1388void Mips64Assembler::Ave_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1389 CHECK(HasMsa());
1390 EmitMsa3R(0x4, 0x1, wt, ws, wd, 0x10);
1391}
1392
1393void Mips64Assembler::Ave_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1394 CHECK(HasMsa());
1395 EmitMsa3R(0x4, 0x2, wt, ws, wd, 0x10);
1396}
1397
1398void Mips64Assembler::Ave_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1399 CHECK(HasMsa());
1400 EmitMsa3R(0x4, 0x3, wt, ws, wd, 0x10);
1401}
1402
1403void Mips64Assembler::Ave_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1404 CHECK(HasMsa());
1405 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x10);
1406}
1407
1408void Mips64Assembler::Ave_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1409 CHECK(HasMsa());
1410 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x10);
1411}
1412
1413void Mips64Assembler::Ave_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1414 CHECK(HasMsa());
1415 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x10);
1416}
1417
1418void Mips64Assembler::Ave_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1419 CHECK(HasMsa());
1420 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x10);
1421}
1422
1423void Mips64Assembler::Aver_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1424 CHECK(HasMsa());
1425 EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x10);
1426}
1427
1428void Mips64Assembler::Aver_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1429 CHECK(HasMsa());
1430 EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x10);
1431}
1432
1433void Mips64Assembler::Aver_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1434 CHECK(HasMsa());
1435 EmitMsa3R(0x6, 0x2, wt, ws, wd, 0x10);
1436}
1437
1438void Mips64Assembler::Aver_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1439 CHECK(HasMsa());
1440 EmitMsa3R(0x6, 0x3, wt, ws, wd, 0x10);
1441}
1442
1443void Mips64Assembler::Aver_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1444 CHECK(HasMsa());
1445 EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x10);
1446}
1447
1448void Mips64Assembler::Aver_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1449 CHECK(HasMsa());
1450 EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x10);
1451}
1452
1453void Mips64Assembler::Aver_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1454 CHECK(HasMsa());
1455 EmitMsa3R(0x7, 0x2, wt, ws, wd, 0x10);
1456}
1457
1458void Mips64Assembler::Aver_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1459 CHECK(HasMsa());
1460 EmitMsa3R(0x7, 0x3, wt, ws, wd, 0x10);
1461}
1462
Goran Jakovljevic658263e2017-06-07 09:35:53 +02001463void Mips64Assembler::Max_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1464 CHECK(HasMsa());
1465 EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xe);
1466}
1467
1468void Mips64Assembler::Max_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1469 CHECK(HasMsa());
1470 EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xe);
1471}
1472
1473void Mips64Assembler::Max_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1474 CHECK(HasMsa());
1475 EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xe);
1476}
1477
1478void Mips64Assembler::Max_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1479 CHECK(HasMsa());
1480 EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xe);
1481}
1482
1483void Mips64Assembler::Max_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1484 CHECK(HasMsa());
1485 EmitMsa3R(0x3, 0x0, wt, ws, wd, 0xe);
1486}
1487
1488void Mips64Assembler::Max_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1489 CHECK(HasMsa());
1490 EmitMsa3R(0x3, 0x1, wt, ws, wd, 0xe);
1491}
1492
1493void Mips64Assembler::Max_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1494 CHECK(HasMsa());
1495 EmitMsa3R(0x3, 0x2, wt, ws, wd, 0xe);
1496}
1497
1498void Mips64Assembler::Max_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1499 CHECK(HasMsa());
1500 EmitMsa3R(0x3, 0x3, wt, ws, wd, 0xe);
1501}
1502
1503void Mips64Assembler::Min_sB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1504 CHECK(HasMsa());
1505 EmitMsa3R(0x4, 0x0, wt, ws, wd, 0xe);
1506}
1507
1508void Mips64Assembler::Min_sH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1509 CHECK(HasMsa());
1510 EmitMsa3R(0x4, 0x1, wt, ws, wd, 0xe);
1511}
1512
1513void Mips64Assembler::Min_sW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1514 CHECK(HasMsa());
1515 EmitMsa3R(0x4, 0x2, wt, ws, wd, 0xe);
1516}
1517
1518void Mips64Assembler::Min_sD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1519 CHECK(HasMsa());
1520 EmitMsa3R(0x4, 0x3, wt, ws, wd, 0xe);
1521}
1522
1523void Mips64Assembler::Min_uB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1524 CHECK(HasMsa());
1525 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0xe);
1526}
1527
1528void Mips64Assembler::Min_uH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1529 CHECK(HasMsa());
1530 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0xe);
1531}
1532
1533void Mips64Assembler::Min_uW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1534 CHECK(HasMsa());
1535 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0xe);
1536}
1537
1538void Mips64Assembler::Min_uD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1539 CHECK(HasMsa());
1540 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0xe);
1541}
1542
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001543void Mips64Assembler::FaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001544 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001545 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0x1b);
1546}
1547
1548void Mips64Assembler::FaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001549 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001550 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0x1b);
1551}
1552
1553void Mips64Assembler::FsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001554 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001555 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0x1b);
1556}
1557
1558void Mips64Assembler::FsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001559 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001560 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0x1b);
1561}
1562
1563void Mips64Assembler::FmulW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001564 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001565 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x1b);
1566}
1567
1568void Mips64Assembler::FmulD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001569 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001570 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x1b);
1571}
1572
1573void Mips64Assembler::FdivW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001574 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001575 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x1b);
1576}
1577
1578void Mips64Assembler::FdivD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001579 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001580 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x1b);
1581}
1582
Goran Jakovljevic658263e2017-06-07 09:35:53 +02001583void Mips64Assembler::FmaxW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1584 CHECK(HasMsa());
1585 EmitMsa3R(0x7, 0x0, wt, ws, wd, 0x1b);
1586}
1587
1588void Mips64Assembler::FmaxD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1589 CHECK(HasMsa());
1590 EmitMsa3R(0x7, 0x1, wt, ws, wd, 0x1b);
1591}
1592
1593void Mips64Assembler::FminW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1594 CHECK(HasMsa());
1595 EmitMsa3R(0x6, 0x0, wt, ws, wd, 0x1b);
1596}
1597
1598void Mips64Assembler::FminD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1599 CHECK(HasMsa());
1600 EmitMsa3R(0x6, 0x1, wt, ws, wd, 0x1b);
1601}
1602
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001603void Mips64Assembler::Ffint_sW(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001604 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001605 EmitMsa2RF(0x19e, 0x0, ws, wd, 0x1e);
1606}
1607
1608void Mips64Assembler::Ffint_sD(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001609 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001610 EmitMsa2RF(0x19e, 0x1, ws, wd, 0x1e);
1611}
1612
1613void Mips64Assembler::Ftint_sW(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001614 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001615 EmitMsa2RF(0x19c, 0x0, ws, wd, 0x1e);
1616}
1617
1618void Mips64Assembler::Ftint_sD(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001619 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001620 EmitMsa2RF(0x19c, 0x1, ws, wd, 0x1e);
1621}
1622
1623void Mips64Assembler::SllB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001624 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001625 EmitMsa3R(0x0, 0x0, wt, ws, wd, 0xd);
1626}
1627
1628void Mips64Assembler::SllH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001629 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001630 EmitMsa3R(0x0, 0x1, wt, ws, wd, 0xd);
1631}
1632
1633void Mips64Assembler::SllW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001634 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001635 EmitMsa3R(0x0, 0x2, wt, ws, wd, 0xd);
1636}
1637
1638void Mips64Assembler::SllD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001639 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001640 EmitMsa3R(0x0, 0x3, wt, ws, wd, 0xd);
1641}
1642
1643void Mips64Assembler::SraB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001644 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001645 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0xd);
1646}
1647
1648void Mips64Assembler::SraH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001649 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001650 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0xd);
1651}
1652
1653void Mips64Assembler::SraW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001654 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001655 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0xd);
1656}
1657
1658void Mips64Assembler::SraD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001659 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001660 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0xd);
1661}
1662
1663void Mips64Assembler::SrlB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001664 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001665 EmitMsa3R(0x2, 0x0, wt, ws, wd, 0xd);
1666}
1667
1668void Mips64Assembler::SrlH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001669 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001670 EmitMsa3R(0x2, 0x1, wt, ws, wd, 0xd);
1671}
1672
1673void Mips64Assembler::SrlW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001674 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001675 EmitMsa3R(0x2, 0x2, wt, ws, wd, 0xd);
1676}
1677
1678void Mips64Assembler::SrlD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001679 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001680 EmitMsa3R(0x2, 0x3, wt, ws, wd, 0xd);
1681}
1682
1683void Mips64Assembler::SlliB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001684 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001685 CHECK(IsUint<3>(shamt3)) << shamt3;
1686 EmitMsaBIT(0x0, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1687}
1688
1689void Mips64Assembler::SlliH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001690 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001691 CHECK(IsUint<4>(shamt4)) << shamt4;
1692 EmitMsaBIT(0x0, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1693}
1694
1695void Mips64Assembler::SlliW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001696 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001697 CHECK(IsUint<5>(shamt5)) << shamt5;
1698 EmitMsaBIT(0x0, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1699}
1700
1701void Mips64Assembler::SlliD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001702 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001703 CHECK(IsUint<6>(shamt6)) << shamt6;
1704 EmitMsaBIT(0x0, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1705}
1706
1707void Mips64Assembler::SraiB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001708 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001709 CHECK(IsUint<3>(shamt3)) << shamt3;
1710 EmitMsaBIT(0x1, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1711}
1712
1713void Mips64Assembler::SraiH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001714 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001715 CHECK(IsUint<4>(shamt4)) << shamt4;
1716 EmitMsaBIT(0x1, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1717}
1718
1719void Mips64Assembler::SraiW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001720 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001721 CHECK(IsUint<5>(shamt5)) << shamt5;
1722 EmitMsaBIT(0x1, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1723}
1724
1725void Mips64Assembler::SraiD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001726 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001727 CHECK(IsUint<6>(shamt6)) << shamt6;
1728 EmitMsaBIT(0x1, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1729}
1730
1731void Mips64Assembler::SrliB(VectorRegister wd, VectorRegister ws, int shamt3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001732 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001733 CHECK(IsUint<3>(shamt3)) << shamt3;
1734 EmitMsaBIT(0x2, shamt3 | kMsaDfMByteMask, ws, wd, 0x9);
1735}
1736
1737void Mips64Assembler::SrliH(VectorRegister wd, VectorRegister ws, int shamt4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001738 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001739 CHECK(IsUint<4>(shamt4)) << shamt4;
1740 EmitMsaBIT(0x2, shamt4 | kMsaDfMHalfwordMask, ws, wd, 0x9);
1741}
1742
1743void Mips64Assembler::SrliW(VectorRegister wd, VectorRegister ws, int shamt5) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001744 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001745 CHECK(IsUint<5>(shamt5)) << shamt5;
1746 EmitMsaBIT(0x2, shamt5 | kMsaDfMWordMask, ws, wd, 0x9);
1747}
1748
1749void Mips64Assembler::SrliD(VectorRegister wd, VectorRegister ws, int shamt6) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001750 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001751 CHECK(IsUint<6>(shamt6)) << shamt6;
1752 EmitMsaBIT(0x2, shamt6 | kMsaDfMDoublewordMask, ws, wd, 0x9);
1753}
1754
1755void Mips64Assembler::MoveV(VectorRegister wd, VectorRegister ws) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001756 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001757 EmitMsaBIT(0x1, 0x3e, ws, wd, 0x19);
1758}
1759
1760void Mips64Assembler::SplatiB(VectorRegister wd, VectorRegister ws, int n4) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001761 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001762 CHECK(IsUint<4>(n4)) << n4;
1763 EmitMsaELM(0x1, n4 | kMsaDfNByteMask, ws, wd, 0x19);
1764}
1765
1766void Mips64Assembler::SplatiH(VectorRegister wd, VectorRegister ws, int n3) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001767 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001768 CHECK(IsUint<3>(n3)) << n3;
1769 EmitMsaELM(0x1, n3 | kMsaDfNHalfwordMask, ws, wd, 0x19);
1770}
1771
1772void Mips64Assembler::SplatiW(VectorRegister wd, VectorRegister ws, int n2) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001773 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001774 CHECK(IsUint<2>(n2)) << n2;
1775 EmitMsaELM(0x1, n2 | kMsaDfNWordMask, ws, wd, 0x19);
1776}
1777
1778void Mips64Assembler::SplatiD(VectorRegister wd, VectorRegister ws, int n1) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001779 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001780 CHECK(IsUint<1>(n1)) << n1;
1781 EmitMsaELM(0x1, n1 | kMsaDfNDoublewordMask, ws, wd, 0x19);
1782}
1783
1784void Mips64Assembler::FillB(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001785 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001786 EmitMsa2R(0xc0, 0x0, static_cast<VectorRegister>(rs), wd, 0x1e);
1787}
1788
1789void Mips64Assembler::FillH(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001790 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001791 EmitMsa2R(0xc0, 0x1, static_cast<VectorRegister>(rs), wd, 0x1e);
1792}
1793
1794void Mips64Assembler::FillW(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001795 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001796 EmitMsa2R(0xc0, 0x2, static_cast<VectorRegister>(rs), wd, 0x1e);
1797}
1798
1799void Mips64Assembler::FillD(VectorRegister wd, GpuRegister rs) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001800 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001801 EmitMsa2R(0xc0, 0x3, static_cast<VectorRegister>(rs), wd, 0x1e);
1802}
1803
Goran Jakovljevic3f444032017-03-31 14:38:20 +02001804void Mips64Assembler::LdiB(VectorRegister wd, int imm8) {
1805 CHECK(HasMsa());
1806 CHECK(IsInt<8>(imm8)) << imm8;
1807 EmitMsaI10(0x6, 0x0, imm8 & kMsaS10Mask, wd, 0x7);
1808}
1809
1810void Mips64Assembler::LdiH(VectorRegister wd, int imm10) {
1811 CHECK(HasMsa());
1812 CHECK(IsInt<10>(imm10)) << imm10;
1813 EmitMsaI10(0x6, 0x1, imm10 & kMsaS10Mask, wd, 0x7);
1814}
1815
1816void Mips64Assembler::LdiW(VectorRegister wd, int imm10) {
1817 CHECK(HasMsa());
1818 CHECK(IsInt<10>(imm10)) << imm10;
1819 EmitMsaI10(0x6, 0x2, imm10 & kMsaS10Mask, wd, 0x7);
1820}
1821
1822void Mips64Assembler::LdiD(VectorRegister wd, int imm10) {
1823 CHECK(HasMsa());
1824 CHECK(IsInt<10>(imm10)) << imm10;
1825 EmitMsaI10(0x6, 0x3, imm10 & kMsaS10Mask, wd, 0x7);
1826}
1827
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001828void Mips64Assembler::LdB(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001829 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001830 CHECK(IsInt<10>(offset)) << offset;
1831 EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x8, 0x0);
1832}
1833
1834void Mips64Assembler::LdH(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001835 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001836 CHECK(IsInt<11>(offset)) << offset;
1837 CHECK_ALIGNED(offset, kMips64HalfwordSize);
1838 EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x8, 0x1);
1839}
1840
1841void Mips64Assembler::LdW(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001842 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001843 CHECK(IsInt<12>(offset)) << offset;
1844 CHECK_ALIGNED(offset, kMips64WordSize);
1845 EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x8, 0x2);
1846}
1847
1848void Mips64Assembler::LdD(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001849 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001850 CHECK(IsInt<13>(offset)) << offset;
1851 CHECK_ALIGNED(offset, kMips64DoublewordSize);
1852 EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x8, 0x3);
1853}
1854
1855void Mips64Assembler::StB(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001856 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001857 CHECK(IsInt<10>(offset)) << offset;
1858 EmitMsaMI10(offset & kMsaS10Mask, rs, wd, 0x9, 0x0);
1859}
1860
1861void Mips64Assembler::StH(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001862 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001863 CHECK(IsInt<11>(offset)) << offset;
1864 CHECK_ALIGNED(offset, kMips64HalfwordSize);
1865 EmitMsaMI10((offset >> TIMES_2) & kMsaS10Mask, rs, wd, 0x9, 0x1);
1866}
1867
1868void Mips64Assembler::StW(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001869 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001870 CHECK(IsInt<12>(offset)) << offset;
1871 CHECK_ALIGNED(offset, kMips64WordSize);
1872 EmitMsaMI10((offset >> TIMES_4) & kMsaS10Mask, rs, wd, 0x9, 0x2);
1873}
1874
1875void Mips64Assembler::StD(VectorRegister wd, GpuRegister rs, int offset) {
Goran Jakovljevic27af9372017-03-15 15:31:34 +01001876 CHECK(HasMsa());
Goran Jakovljevic5a9e51d2017-03-16 16:11:43 +00001877 CHECK(IsInt<13>(offset)) << offset;
1878 CHECK_ALIGNED(offset, kMips64DoublewordSize);
1879 EmitMsaMI10((offset >> TIMES_8) & kMsaS10Mask, rs, wd, 0x9, 0x3);
1880}
1881
Goran Jakovljevic38370112017-05-10 14:30:28 +02001882void Mips64Assembler::IlvrB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1883 CHECK(HasMsa());
1884 EmitMsa3R(0x5, 0x0, wt, ws, wd, 0x14);
1885}
1886
1887void Mips64Assembler::IlvrH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1888 CHECK(HasMsa());
1889 EmitMsa3R(0x5, 0x1, wt, ws, wd, 0x14);
1890}
1891
1892void Mips64Assembler::IlvrW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1893 CHECK(HasMsa());
1894 EmitMsa3R(0x5, 0x2, wt, ws, wd, 0x14);
1895}
1896
1897void Mips64Assembler::IlvrD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1898 CHECK(HasMsa());
1899 EmitMsa3R(0x5, 0x3, wt, ws, wd, 0x14);
1900}
1901
Lena Djokicb3d79e42017-07-25 11:20:52 +02001902void Mips64Assembler::MaddvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1903 CHECK(HasMsa());
1904 EmitMsa3R(0x1, 0x0, wt, ws, wd, 0x12);
1905}
1906
1907void Mips64Assembler::MaddvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1908 CHECK(HasMsa());
1909 EmitMsa3R(0x1, 0x1, wt, ws, wd, 0x12);
1910}
1911
1912void Mips64Assembler::MaddvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1913 CHECK(HasMsa());
1914 EmitMsa3R(0x1, 0x2, wt, ws, wd, 0x12);
1915}
1916
1917void Mips64Assembler::MaddvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1918 CHECK(HasMsa());
1919 EmitMsa3R(0x1, 0x3, wt, ws, wd, 0x12);
1920}
1921
1922void Mips64Assembler::MsubvB(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1923 CHECK(HasMsa());
1924 EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x12);
1925}
1926
1927void Mips64Assembler::MsubvH(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1928 CHECK(HasMsa());
1929 EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x12);
1930}
1931
1932void Mips64Assembler::MsubvW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1933 CHECK(HasMsa());
1934 EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x12);
1935}
1936
1937void Mips64Assembler::MsubvD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1938 CHECK(HasMsa());
1939 EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x12);
1940}
1941
1942void Mips64Assembler::FmaddW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1943 CHECK(HasMsa());
1944 EmitMsa3R(0x2, 0x0, wt, ws, wd, 0x1b);
1945}
1946
1947void Mips64Assembler::FmaddD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1948 CHECK(HasMsa());
1949 EmitMsa3R(0x2, 0x1, wt, ws, wd, 0x1b);
1950}
1951
1952void Mips64Assembler::FmsubW(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1953 CHECK(HasMsa());
1954 EmitMsa3R(0x2, 0x2, wt, ws, wd, 0x1b);
1955}
1956
1957void Mips64Assembler::FmsubD(VectorRegister wd, VectorRegister ws, VectorRegister wt) {
1958 CHECK(HasMsa());
1959 EmitMsa3R(0x2, 0x3, wt, ws, wd, 0x1b);
1960}
1961
Goran Jakovljevic19680d32017-05-11 10:38:36 +02001962void Mips64Assembler::ReplicateFPToVectorRegister(VectorRegister dst,
1963 FpuRegister src,
1964 bool is_double) {
1965 // Float or double in FPU register Fx can be considered as 0th element in vector register Wx.
1966 if (is_double) {
1967 SplatiD(dst, static_cast<VectorRegister>(src), 0);
1968 } else {
1969 SplatiW(dst, static_cast<VectorRegister>(src), 0);
1970 }
1971}
1972
Alexey Frunze4dda3372015-06-01 18:31:49 -07001973void Mips64Assembler::LoadConst32(GpuRegister rd, int32_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001974 TemplateLoadConst32(this, rd, value);
1975}
1976
1977// This function is only used for testing purposes.
1978void Mips64Assembler::RecordLoadConst64Path(int value ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001979}
1980
Alexey Frunze4dda3372015-06-01 18:31:49 -07001981void Mips64Assembler::LoadConst64(GpuRegister rd, int64_t value) {
Chris Larsenc733dca2016-05-13 16:11:47 -07001982 TemplateLoadConst64(this, rd, value);
Andreas Gampe57b34292015-01-14 15:45:59 -08001983}
1984
Alexey Frunze0960ac52016-12-20 17:24:59 -08001985void Mips64Assembler::Addiu32(GpuRegister rt, GpuRegister rs, int32_t value) {
1986 if (IsInt<16>(value)) {
1987 Addiu(rt, rs, value);
1988 } else {
1989 int16_t high = High16Bits(value);
1990 int16_t low = Low16Bits(value);
1991 high += (low < 0) ? 1 : 0; // Account for sign extension in addiu.
1992 Aui(rt, rs, high);
1993 if (low != 0) {
1994 Addiu(rt, rt, low);
1995 }
1996 }
1997}
1998
Alexey Frunze15958152017-02-09 19:08:30 -08001999// TODO: don't use rtmp, use daui, dahi, dati.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002000void Mips64Assembler::Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp) {
Chris Larsen5863f852017-03-23 15:41:37 -07002001 CHECK_NE(rs, rtmp);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002002 if (IsInt<16>(value)) {
2003 Daddiu(rt, rs, value);
2004 } else {
2005 LoadConst64(rtmp, value);
2006 Daddu(rt, rs, rtmp);
2007 }
Andreas Gampe57b34292015-01-14 15:45:59 -08002008}
2009
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002010void Mips64Assembler::Branch::InitShortOrLong(Mips64Assembler::Branch::OffsetBits offset_size,
2011 Mips64Assembler::Branch::Type short_type,
2012 Mips64Assembler::Branch::Type long_type) {
2013 type_ = (offset_size <= branch_info_[short_type].offset_size) ? short_type : long_type;
2014}
Alexey Frunze4dda3372015-06-01 18:31:49 -07002015
Alexey Frunze19f6c692016-11-30 19:19:55 -08002016void Mips64Assembler::Branch::InitializeType(Type initial_type) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002017 OffsetBits offset_size = GetOffsetSizeNeeded(location_, target_);
Alexey Frunze19f6c692016-11-30 19:19:55 -08002018 switch (initial_type) {
2019 case kLabel:
2020 case kLiteral:
2021 case kLiteralUnsigned:
2022 case kLiteralLong:
2023 CHECK(!IsResolved());
2024 type_ = initial_type;
2025 break;
2026 case kCall:
2027 InitShortOrLong(offset_size, kCall, kLongCall);
2028 break;
2029 case kCondBranch:
2030 switch (condition_) {
2031 case kUncond:
2032 InitShortOrLong(offset_size, kUncondBranch, kLongUncondBranch);
2033 break;
2034 case kCondEQZ:
2035 case kCondNEZ:
2036 // Special case for beqzc/bnezc with longer offset than in other b<cond>c instructions.
2037 type_ = (offset_size <= kOffset23) ? kCondBranch : kLongCondBranch;
2038 break;
2039 default:
2040 InitShortOrLong(offset_size, kCondBranch, kLongCondBranch);
2041 break;
2042 }
2043 break;
2044 default:
2045 LOG(FATAL) << "Unexpected branch type " << initial_type;
2046 UNREACHABLE();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002047 }
2048 old_type_ = type_;
2049}
2050
2051bool Mips64Assembler::Branch::IsNop(BranchCondition condition, GpuRegister lhs, GpuRegister rhs) {
2052 switch (condition) {
2053 case kCondLT:
2054 case kCondGT:
2055 case kCondNE:
2056 case kCondLTU:
2057 return lhs == rhs;
2058 default:
2059 return false;
2060 }
2061}
2062
2063bool Mips64Assembler::Branch::IsUncond(BranchCondition condition,
2064 GpuRegister lhs,
2065 GpuRegister rhs) {
2066 switch (condition) {
2067 case kUncond:
2068 return true;
2069 case kCondGE:
2070 case kCondLE:
2071 case kCondEQ:
2072 case kCondGEU:
2073 return lhs == rhs;
2074 default:
2075 return false;
2076 }
2077}
2078
Alexey Frunze19f6c692016-11-30 19:19:55 -08002079Mips64Assembler::Branch::Branch(uint32_t location, uint32_t target, bool is_call)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002080 : old_location_(location),
2081 location_(location),
2082 target_(target),
2083 lhs_reg_(ZERO),
2084 rhs_reg_(ZERO),
2085 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08002086 InitializeType(is_call ? kCall : kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002087}
2088
2089Mips64Assembler::Branch::Branch(uint32_t location,
2090 uint32_t target,
2091 Mips64Assembler::BranchCondition condition,
2092 GpuRegister lhs_reg,
2093 GpuRegister rhs_reg)
2094 : old_location_(location),
2095 location_(location),
2096 target_(target),
2097 lhs_reg_(lhs_reg),
2098 rhs_reg_(rhs_reg),
2099 condition_(condition) {
2100 CHECK_NE(condition, kUncond);
2101 switch (condition) {
2102 case kCondEQ:
2103 case kCondNE:
2104 case kCondLT:
2105 case kCondGE:
2106 case kCondLE:
2107 case kCondGT:
2108 case kCondLTU:
2109 case kCondGEU:
2110 CHECK_NE(lhs_reg, ZERO);
2111 CHECK_NE(rhs_reg, ZERO);
2112 break;
2113 case kCondLTZ:
2114 case kCondGEZ:
2115 case kCondLEZ:
2116 case kCondGTZ:
2117 case kCondEQZ:
2118 case kCondNEZ:
2119 CHECK_NE(lhs_reg, ZERO);
2120 CHECK_EQ(rhs_reg, ZERO);
2121 break;
Alexey Frunze299a9392015-12-08 16:08:02 -08002122 case kCondF:
2123 case kCondT:
2124 CHECK_EQ(rhs_reg, ZERO);
2125 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002126 case kUncond:
2127 UNREACHABLE();
2128 }
2129 CHECK(!IsNop(condition, lhs_reg, rhs_reg));
2130 if (IsUncond(condition, lhs_reg, rhs_reg)) {
2131 // Branch condition is always true, make the branch unconditional.
2132 condition_ = kUncond;
2133 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08002134 InitializeType(kCondBranch);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002135}
2136
Alexey Frunze19f6c692016-11-30 19:19:55 -08002137Mips64Assembler::Branch::Branch(uint32_t location, GpuRegister dest_reg, Type label_or_literal_type)
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002138 : old_location_(location),
2139 location_(location),
Alexey Frunze19f6c692016-11-30 19:19:55 -08002140 target_(kUnresolved),
2141 lhs_reg_(dest_reg),
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002142 rhs_reg_(ZERO),
2143 condition_(kUncond) {
Alexey Frunze19f6c692016-11-30 19:19:55 -08002144 CHECK_NE(dest_reg, ZERO);
2145 InitializeType(label_or_literal_type);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002146}
2147
2148Mips64Assembler::BranchCondition Mips64Assembler::Branch::OppositeCondition(
2149 Mips64Assembler::BranchCondition cond) {
2150 switch (cond) {
2151 case kCondLT:
2152 return kCondGE;
2153 case kCondGE:
2154 return kCondLT;
2155 case kCondLE:
2156 return kCondGT;
2157 case kCondGT:
2158 return kCondLE;
2159 case kCondLTZ:
2160 return kCondGEZ;
2161 case kCondGEZ:
2162 return kCondLTZ;
2163 case kCondLEZ:
2164 return kCondGTZ;
2165 case kCondGTZ:
2166 return kCondLEZ;
2167 case kCondEQ:
2168 return kCondNE;
2169 case kCondNE:
2170 return kCondEQ;
2171 case kCondEQZ:
2172 return kCondNEZ;
2173 case kCondNEZ:
2174 return kCondEQZ;
2175 case kCondLTU:
2176 return kCondGEU;
2177 case kCondGEU:
2178 return kCondLTU;
Alexey Frunze299a9392015-12-08 16:08:02 -08002179 case kCondF:
2180 return kCondT;
2181 case kCondT:
2182 return kCondF;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002183 case kUncond:
2184 LOG(FATAL) << "Unexpected branch condition " << cond;
2185 }
2186 UNREACHABLE();
2187}
2188
2189Mips64Assembler::Branch::Type Mips64Assembler::Branch::GetType() const {
2190 return type_;
2191}
2192
2193Mips64Assembler::BranchCondition Mips64Assembler::Branch::GetCondition() const {
2194 return condition_;
2195}
2196
2197GpuRegister Mips64Assembler::Branch::GetLeftRegister() const {
2198 return lhs_reg_;
2199}
2200
2201GpuRegister Mips64Assembler::Branch::GetRightRegister() const {
2202 return rhs_reg_;
2203}
2204
2205uint32_t Mips64Assembler::Branch::GetTarget() const {
2206 return target_;
2207}
2208
2209uint32_t Mips64Assembler::Branch::GetLocation() const {
2210 return location_;
2211}
2212
2213uint32_t Mips64Assembler::Branch::GetOldLocation() const {
2214 return old_location_;
2215}
2216
2217uint32_t Mips64Assembler::Branch::GetLength() const {
2218 return branch_info_[type_].length;
2219}
2220
2221uint32_t Mips64Assembler::Branch::GetOldLength() const {
2222 return branch_info_[old_type_].length;
2223}
2224
2225uint32_t Mips64Assembler::Branch::GetSize() const {
2226 return GetLength() * sizeof(uint32_t);
2227}
2228
2229uint32_t Mips64Assembler::Branch::GetOldSize() const {
2230 return GetOldLength() * sizeof(uint32_t);
2231}
2232
2233uint32_t Mips64Assembler::Branch::GetEndLocation() const {
2234 return GetLocation() + GetSize();
2235}
2236
2237uint32_t Mips64Assembler::Branch::GetOldEndLocation() const {
2238 return GetOldLocation() + GetOldSize();
2239}
2240
2241bool Mips64Assembler::Branch::IsLong() const {
2242 switch (type_) {
2243 // Short branches.
2244 case kUncondBranch:
2245 case kCondBranch:
2246 case kCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002247 // Near label.
2248 case kLabel:
2249 // Near literals.
2250 case kLiteral:
2251 case kLiteralUnsigned:
2252 case kLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002253 return false;
2254 // Long branches.
2255 case kLongUncondBranch:
2256 case kLongCondBranch:
2257 case kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002258 // Far label.
2259 case kFarLabel:
2260 // Far literals.
2261 case kFarLiteral:
2262 case kFarLiteralUnsigned:
2263 case kFarLiteralLong:
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002264 return true;
2265 }
2266 UNREACHABLE();
2267}
2268
2269bool Mips64Assembler::Branch::IsResolved() const {
2270 return target_ != kUnresolved;
2271}
2272
2273Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSize() const {
2274 OffsetBits offset_size =
2275 (type_ == kCondBranch && (condition_ == kCondEQZ || condition_ == kCondNEZ))
2276 ? kOffset23
2277 : branch_info_[type_].offset_size;
2278 return offset_size;
2279}
2280
2281Mips64Assembler::Branch::OffsetBits Mips64Assembler::Branch::GetOffsetSizeNeeded(uint32_t location,
2282 uint32_t target) {
2283 // For unresolved targets assume the shortest encoding
2284 // (later it will be made longer if needed).
2285 if (target == kUnresolved)
2286 return kOffset16;
2287 int64_t distance = static_cast<int64_t>(target) - location;
2288 // To simplify calculations in composite branches consisting of multiple instructions
2289 // bump up the distance by a value larger than the max byte size of a composite branch.
2290 distance += (distance >= 0) ? kMaxBranchSize : -kMaxBranchSize;
2291 if (IsInt<kOffset16>(distance))
2292 return kOffset16;
2293 else if (IsInt<kOffset18>(distance))
2294 return kOffset18;
2295 else if (IsInt<kOffset21>(distance))
2296 return kOffset21;
2297 else if (IsInt<kOffset23>(distance))
2298 return kOffset23;
2299 else if (IsInt<kOffset28>(distance))
2300 return kOffset28;
2301 return kOffset32;
2302}
2303
2304void Mips64Assembler::Branch::Resolve(uint32_t target) {
2305 target_ = target;
2306}
2307
2308void Mips64Assembler::Branch::Relocate(uint32_t expand_location, uint32_t delta) {
2309 if (location_ > expand_location) {
2310 location_ += delta;
2311 }
2312 if (!IsResolved()) {
2313 return; // Don't know the target yet.
2314 }
2315 if (target_ > expand_location) {
2316 target_ += delta;
2317 }
2318}
2319
2320void Mips64Assembler::Branch::PromoteToLong() {
2321 switch (type_) {
2322 // Short branches.
2323 case kUncondBranch:
2324 type_ = kLongUncondBranch;
2325 break;
2326 case kCondBranch:
2327 type_ = kLongCondBranch;
2328 break;
2329 case kCall:
2330 type_ = kLongCall;
2331 break;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002332 // Near label.
2333 case kLabel:
2334 type_ = kFarLabel;
2335 break;
2336 // Near literals.
2337 case kLiteral:
2338 type_ = kFarLiteral;
2339 break;
2340 case kLiteralUnsigned:
2341 type_ = kFarLiteralUnsigned;
2342 break;
2343 case kLiteralLong:
2344 type_ = kFarLiteralLong;
2345 break;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002346 default:
2347 // Note: 'type_' is already long.
2348 break;
2349 }
2350 CHECK(IsLong());
2351}
2352
2353uint32_t Mips64Assembler::Branch::PromoteIfNeeded(uint32_t max_short_distance) {
2354 // If the branch is still unresolved or already long, nothing to do.
2355 if (IsLong() || !IsResolved()) {
2356 return 0;
2357 }
2358 // Promote the short branch to long if the offset size is too small
2359 // to hold the distance between location_ and target_.
2360 if (GetOffsetSizeNeeded(location_, target_) > GetOffsetSize()) {
2361 PromoteToLong();
2362 uint32_t old_size = GetOldSize();
2363 uint32_t new_size = GetSize();
2364 CHECK_GT(new_size, old_size);
2365 return new_size - old_size;
2366 }
2367 // The following logic is for debugging/testing purposes.
2368 // Promote some short branches to long when it's not really required.
2369 if (UNLIKELY(max_short_distance != std::numeric_limits<uint32_t>::max())) {
2370 int64_t distance = static_cast<int64_t>(target_) - location_;
2371 distance = (distance >= 0) ? distance : -distance;
2372 if (distance >= max_short_distance) {
2373 PromoteToLong();
2374 uint32_t old_size = GetOldSize();
2375 uint32_t new_size = GetSize();
2376 CHECK_GT(new_size, old_size);
2377 return new_size - old_size;
2378 }
2379 }
2380 return 0;
2381}
2382
2383uint32_t Mips64Assembler::Branch::GetOffsetLocation() const {
2384 return location_ + branch_info_[type_].instr_offset * sizeof(uint32_t);
2385}
2386
2387uint32_t Mips64Assembler::Branch::GetOffset() const {
2388 CHECK(IsResolved());
2389 uint32_t ofs_mask = 0xFFFFFFFF >> (32 - GetOffsetSize());
2390 // Calculate the byte distance between instructions and also account for
2391 // different PC-relative origins.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002392 uint32_t offset_location = GetOffsetLocation();
2393 if (type_ == kLiteralLong) {
2394 // Special case for the ldpc instruction, whose address (PC) is rounded down to
2395 // a multiple of 8 before adding the offset.
2396 // Note, branch promotion has already taken care of aligning `target_` to an
2397 // address that's a multiple of 8.
2398 offset_location = RoundDown(offset_location, sizeof(uint64_t));
2399 }
2400 uint32_t offset = target_ - offset_location - branch_info_[type_].pc_org * sizeof(uint32_t);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002401 // Prepare the offset for encoding into the instruction(s).
2402 offset = (offset & ofs_mask) >> branch_info_[type_].offset_shift;
2403 return offset;
2404}
2405
2406Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) {
2407 CHECK_LT(branch_id, branches_.size());
2408 return &branches_[branch_id];
2409}
2410
2411const Mips64Assembler::Branch* Mips64Assembler::GetBranch(uint32_t branch_id) const {
2412 CHECK_LT(branch_id, branches_.size());
2413 return &branches_[branch_id];
2414}
2415
2416void Mips64Assembler::Bind(Mips64Label* label) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07002417 CHECK(!label->IsBound());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002418 uint32_t bound_pc = buffer_.Size();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002419
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002420 // Walk the list of branches referring to and preceding this label.
2421 // Store the previously unknown target addresses in them.
Alexey Frunze4dda3372015-06-01 18:31:49 -07002422 while (label->IsLinked()) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002423 uint32_t branch_id = label->Position();
2424 Branch* branch = GetBranch(branch_id);
2425 branch->Resolve(bound_pc);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002426
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002427 uint32_t branch_location = branch->GetLocation();
2428 // Extract the location of the previous branch in the list (walking the list backwards;
2429 // the previous branch ID was stored in the space reserved for this branch).
2430 uint32_t prev = buffer_.Load<uint32_t>(branch_location);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002431
2432 // On to the previous branch in the list...
2433 label->position_ = prev;
2434 }
2435
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002436 // Now make the label object contain its own location (relative to the end of the preceding
2437 // branch, if any; it will be used by the branches referring to and following this label).
2438 label->prev_branch_id_plus_one_ = branches_.size();
2439 if (label->prev_branch_id_plus_one_) {
2440 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2441 const Branch* branch = GetBranch(branch_id);
2442 bound_pc -= branch->GetEndLocation();
2443 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002444 label->BindTo(bound_pc);
2445}
2446
Alexey Frunze19f6c692016-11-30 19:19:55 -08002447uint32_t Mips64Assembler::GetLabelLocation(const Mips64Label* label) const {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002448 CHECK(label->IsBound());
2449 uint32_t target = label->Position();
2450 if (label->prev_branch_id_plus_one_) {
2451 // Get label location based on the branch preceding it.
2452 uint32_t branch_id = label->prev_branch_id_plus_one_ - 1;
2453 const Branch* branch = GetBranch(branch_id);
2454 target += branch->GetEndLocation();
2455 }
2456 return target;
2457}
2458
2459uint32_t Mips64Assembler::GetAdjustedPosition(uint32_t old_position) {
2460 // We can reconstruct the adjustment by going through all the branches from the beginning
2461 // up to the old_position. Since we expect AdjustedPosition() to be called in a loop
2462 // with increasing old_position, we can use the data from last AdjustedPosition() to
2463 // continue where we left off and the whole loop should be O(m+n) where m is the number
2464 // of positions to adjust and n is the number of branches.
2465 if (old_position < last_old_position_) {
2466 last_position_adjustment_ = 0;
2467 last_old_position_ = 0;
2468 last_branch_id_ = 0;
2469 }
2470 while (last_branch_id_ != branches_.size()) {
2471 const Branch* branch = GetBranch(last_branch_id_);
2472 if (branch->GetLocation() >= old_position + last_position_adjustment_) {
2473 break;
2474 }
2475 last_position_adjustment_ += branch->GetSize() - branch->GetOldSize();
2476 ++last_branch_id_;
2477 }
2478 last_old_position_ = old_position;
2479 return old_position + last_position_adjustment_;
2480}
2481
2482void Mips64Assembler::FinalizeLabeledBranch(Mips64Label* label) {
2483 uint32_t length = branches_.back().GetLength();
2484 if (!label->IsBound()) {
2485 // Branch forward (to a following label), distance is unknown.
2486 // The first branch forward will contain 0, serving as the terminator of
2487 // the list of forward-reaching branches.
2488 Emit(label->position_);
2489 length--;
2490 // Now make the label object point to this branch
2491 // (this forms a linked list of branches preceding this label).
2492 uint32_t branch_id = branches_.size() - 1;
2493 label->LinkTo(branch_id);
2494 }
2495 // Reserve space for the branch.
2496 while (length--) {
2497 Nop();
Alexey Frunze4dda3372015-06-01 18:31:49 -07002498 }
2499}
2500
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002501void Mips64Assembler::Buncond(Mips64Label* label) {
2502 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002503 branches_.emplace_back(buffer_.Size(), target, /* is_call */ false);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002504 FinalizeLabeledBranch(label);
2505}
2506
2507void Mips64Assembler::Bcond(Mips64Label* label,
2508 BranchCondition condition,
2509 GpuRegister lhs,
2510 GpuRegister rhs) {
2511 // If lhs = rhs, this can be a NOP.
2512 if (Branch::IsNop(condition, lhs, rhs)) {
2513 return;
2514 }
2515 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
2516 branches_.emplace_back(buffer_.Size(), target, condition, lhs, rhs);
2517 FinalizeLabeledBranch(label);
2518}
2519
Alexey Frunze19f6c692016-11-30 19:19:55 -08002520void Mips64Assembler::Call(Mips64Label* label) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002521 uint32_t target = label->IsBound() ? GetLabelLocation(label) : Branch::kUnresolved;
Alexey Frunze19f6c692016-11-30 19:19:55 -08002522 branches_.emplace_back(buffer_.Size(), target, /* is_call */ true);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002523 FinalizeLabeledBranch(label);
2524}
2525
Alexey Frunze19f6c692016-11-30 19:19:55 -08002526void Mips64Assembler::LoadLabelAddress(GpuRegister dest_reg, Mips64Label* label) {
2527 // Label address loads are treated as pseudo branches since they require very similar handling.
2528 DCHECK(!label->IsBound());
2529 branches_.emplace_back(buffer_.Size(), dest_reg, Branch::kLabel);
2530 FinalizeLabeledBranch(label);
2531}
2532
2533Literal* Mips64Assembler::NewLiteral(size_t size, const uint8_t* data) {
2534 // We don't support byte and half-word literals.
2535 if (size == 4u) {
2536 literals_.emplace_back(size, data);
2537 return &literals_.back();
2538 } else {
2539 DCHECK_EQ(size, 8u);
2540 long_literals_.emplace_back(size, data);
2541 return &long_literals_.back();
2542 }
2543}
2544
2545void Mips64Assembler::LoadLiteral(GpuRegister dest_reg,
2546 LoadOperandType load_type,
2547 Literal* literal) {
2548 // Literal loads are treated as pseudo branches since they require very similar handling.
2549 Branch::Type literal_type;
2550 switch (load_type) {
2551 case kLoadWord:
2552 DCHECK_EQ(literal->GetSize(), 4u);
2553 literal_type = Branch::kLiteral;
2554 break;
2555 case kLoadUnsignedWord:
2556 DCHECK_EQ(literal->GetSize(), 4u);
2557 literal_type = Branch::kLiteralUnsigned;
2558 break;
2559 case kLoadDoubleword:
2560 DCHECK_EQ(literal->GetSize(), 8u);
2561 literal_type = Branch::kLiteralLong;
2562 break;
2563 default:
2564 LOG(FATAL) << "Unexpected literal load type " << load_type;
2565 UNREACHABLE();
2566 }
2567 Mips64Label* label = literal->GetLabel();
2568 DCHECK(!label->IsBound());
2569 branches_.emplace_back(buffer_.Size(), dest_reg, literal_type);
2570 FinalizeLabeledBranch(label);
2571}
2572
Alexey Frunze0960ac52016-12-20 17:24:59 -08002573JumpTable* Mips64Assembler::CreateJumpTable(std::vector<Mips64Label*>&& labels) {
2574 jump_tables_.emplace_back(std::move(labels));
2575 JumpTable* table = &jump_tables_.back();
2576 DCHECK(!table->GetLabel()->IsBound());
2577 return table;
2578}
2579
2580void Mips64Assembler::ReserveJumpTableSpace() {
2581 if (!jump_tables_.empty()) {
2582 for (JumpTable& table : jump_tables_) {
2583 Mips64Label* label = table.GetLabel();
2584 Bind(label);
2585
2586 // Bulk ensure capacity, as this may be large.
2587 size_t orig_size = buffer_.Size();
2588 size_t required_capacity = orig_size + table.GetSize();
2589 if (required_capacity > buffer_.Capacity()) {
2590 buffer_.ExtendCapacity(required_capacity);
2591 }
2592#ifndef NDEBUG
2593 buffer_.has_ensured_capacity_ = true;
2594#endif
2595
2596 // Fill the space with dummy data as the data is not final
2597 // until the branches have been promoted. And we shouldn't
2598 // be moving uninitialized data during branch promotion.
2599 for (size_t cnt = table.GetData().size(), i = 0; i < cnt; i++) {
2600 buffer_.Emit<uint32_t>(0x1abe1234u);
2601 }
2602
2603#ifndef NDEBUG
2604 buffer_.has_ensured_capacity_ = false;
2605#endif
2606 }
2607 }
2608}
2609
2610void Mips64Assembler::EmitJumpTables() {
2611 if (!jump_tables_.empty()) {
2612 CHECK(!overwriting_);
2613 // Switch from appending instructions at the end of the buffer to overwriting
2614 // existing instructions (here, jump tables) in the buffer.
2615 overwriting_ = true;
2616
2617 for (JumpTable& table : jump_tables_) {
2618 Mips64Label* table_label = table.GetLabel();
2619 uint32_t start = GetLabelLocation(table_label);
2620 overwrite_location_ = start;
2621
2622 for (Mips64Label* target : table.GetData()) {
2623 CHECK_EQ(buffer_.Load<uint32_t>(overwrite_location_), 0x1abe1234u);
2624 // The table will contain target addresses relative to the table start.
2625 uint32_t offset = GetLabelLocation(target) - start;
2626 Emit(offset);
2627 }
2628 }
2629
2630 overwriting_ = false;
2631 }
2632}
2633
Alexey Frunze19f6c692016-11-30 19:19:55 -08002634void Mips64Assembler::EmitLiterals() {
2635 if (!literals_.empty()) {
2636 for (Literal& literal : literals_) {
2637 Mips64Label* label = literal.GetLabel();
2638 Bind(label);
2639 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2640 DCHECK_EQ(literal.GetSize(), 4u);
2641 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2642 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2643 }
2644 }
2645 }
2646 if (!long_literals_.empty()) {
2647 // Reserve 4 bytes for potential alignment. If after the branch promotion the 64-bit
2648 // literals don't end up 8-byte-aligned, they will be moved down 4 bytes.
2649 Emit(0); // NOP.
2650 for (Literal& literal : long_literals_) {
2651 Mips64Label* label = literal.GetLabel();
2652 Bind(label);
2653 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
2654 DCHECK_EQ(literal.GetSize(), 8u);
2655 for (size_t i = 0, size = literal.GetSize(); i != size; ++i) {
2656 buffer_.Emit<uint8_t>(literal.GetData()[i]);
2657 }
2658 }
2659 }
2660}
2661
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002662void Mips64Assembler::PromoteBranches() {
2663 // Promote short branches to long as necessary.
2664 bool changed;
2665 do {
2666 changed = false;
2667 for (auto& branch : branches_) {
2668 CHECK(branch.IsResolved());
2669 uint32_t delta = branch.PromoteIfNeeded();
2670 // If this branch has been promoted and needs to expand in size,
2671 // relocate all branches by the expansion size.
2672 if (delta) {
2673 changed = true;
2674 uint32_t expand_location = branch.GetLocation();
2675 for (auto& branch2 : branches_) {
2676 branch2.Relocate(expand_location, delta);
2677 }
2678 }
2679 }
2680 } while (changed);
2681
2682 // Account for branch expansion by resizing the code buffer
2683 // and moving the code in it to its final location.
2684 size_t branch_count = branches_.size();
2685 if (branch_count > 0) {
2686 // Resize.
2687 Branch& last_branch = branches_[branch_count - 1];
2688 uint32_t size_delta = last_branch.GetEndLocation() - last_branch.GetOldEndLocation();
2689 uint32_t old_size = buffer_.Size();
2690 buffer_.Resize(old_size + size_delta);
2691 // Move the code residing between branch placeholders.
2692 uint32_t end = old_size;
2693 for (size_t i = branch_count; i > 0; ) {
2694 Branch& branch = branches_[--i];
2695 uint32_t size = end - branch.GetOldEndLocation();
2696 buffer_.Move(branch.GetEndLocation(), branch.GetOldEndLocation(), size);
2697 end = branch.GetOldLocation();
2698 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002699 }
Alexey Frunze19f6c692016-11-30 19:19:55 -08002700
2701 // Align 64-bit literals by moving them down by 4 bytes if needed.
2702 // This will reduce the PC-relative distance, which should be safe for both near and far literals.
2703 if (!long_literals_.empty()) {
2704 uint32_t first_literal_location = GetLabelLocation(long_literals_.front().GetLabel());
2705 size_t lit_size = long_literals_.size() * sizeof(uint64_t);
2706 size_t buf_size = buffer_.Size();
2707 // 64-bit literals must be at the very end of the buffer.
2708 CHECK_EQ(first_literal_location + lit_size, buf_size);
2709 if (!IsAligned<sizeof(uint64_t)>(first_literal_location)) {
2710 buffer_.Move(first_literal_location - sizeof(uint32_t), first_literal_location, lit_size);
2711 // The 4 reserved bytes proved useless, reduce the buffer size.
2712 buffer_.Resize(buf_size - sizeof(uint32_t));
2713 // Reduce target addresses in literal and address loads by 4 bytes in order for correct
2714 // offsets from PC to be generated.
2715 for (auto& branch : branches_) {
2716 uint32_t target = branch.GetTarget();
2717 if (target >= first_literal_location) {
2718 branch.Resolve(target - sizeof(uint32_t));
2719 }
2720 }
2721 // If after this we ever call GetLabelLocation() to get the location of a 64-bit literal,
2722 // we need to adjust the location of the literal's label as well.
2723 for (Literal& literal : long_literals_) {
2724 // Bound label's position is negative, hence incrementing it instead of decrementing.
2725 literal.GetLabel()->position_ += sizeof(uint32_t);
2726 }
2727 }
2728 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07002729}
2730
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002731// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2732const Mips64Assembler::Branch::BranchInfo Mips64Assembler::Branch::branch_info_[] = {
2733 // Short branches.
2734 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kUncondBranch
2735 { 2, 0, 1, Mips64Assembler::Branch::kOffset18, 2 }, // kCondBranch
2736 // Exception: kOffset23 for beqzc/bnezc
Alexey Frunze19f6c692016-11-30 19:19:55 -08002737 { 1, 0, 1, Mips64Assembler::Branch::kOffset28, 2 }, // kCall
2738 // Near label.
2739 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLabel
2740 // Near literals.
2741 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteral
2742 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 2 }, // kLiteralUnsigned
2743 { 1, 0, 0, Mips64Assembler::Branch::kOffset21, 3 }, // kLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002744 // Long branches.
2745 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongUncondBranch
2746 { 3, 1, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCondBranch
Alexey Frunze19f6c692016-11-30 19:19:55 -08002747 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kLongCall
2748 // Far label.
2749 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLabel
2750 // Far literals.
2751 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteral
2752 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralUnsigned
2753 { 2, 0, 0, Mips64Assembler::Branch::kOffset32, 0 }, // kFarLiteralLong
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002754};
2755
2756// Note: make sure branch_info_[] and EmitBranch() are kept synchronized.
2757void Mips64Assembler::EmitBranch(Mips64Assembler::Branch* branch) {
2758 CHECK(overwriting_);
2759 overwrite_location_ = branch->GetLocation();
2760 uint32_t offset = branch->GetOffset();
2761 BranchCondition condition = branch->GetCondition();
2762 GpuRegister lhs = branch->GetLeftRegister();
2763 GpuRegister rhs = branch->GetRightRegister();
2764 switch (branch->GetType()) {
2765 // Short branches.
2766 case Branch::kUncondBranch:
2767 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2768 Bc(offset);
2769 break;
2770 case Branch::kCondBranch:
2771 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2772 EmitBcondc(condition, lhs, rhs, offset);
Alexey Frunze299a9392015-12-08 16:08:02 -08002773 Nop(); // TODO: improve by filling the forbidden/delay slot.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002774 break;
2775 case Branch::kCall:
2776 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002777 Balc(offset);
2778 break;
2779
2780 // Near label.
2781 case Branch::kLabel:
2782 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002783 Addiupc(lhs, offset);
Alexey Frunze19f6c692016-11-30 19:19:55 -08002784 break;
2785 // Near literals.
2786 case Branch::kLiteral:
2787 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2788 Lwpc(lhs, offset);
2789 break;
2790 case Branch::kLiteralUnsigned:
2791 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2792 Lwupc(lhs, offset);
2793 break;
2794 case Branch::kLiteralLong:
2795 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2796 Ldpc(lhs, offset);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002797 break;
2798
2799 // Long branches.
2800 case Branch::kLongUncondBranch:
2801 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2802 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2803 Auipc(AT, High16Bits(offset));
2804 Jic(AT, Low16Bits(offset));
2805 break;
2806 case Branch::kLongCondBranch:
2807 EmitBcondc(Branch::OppositeCondition(condition), lhs, rhs, 2);
2808 offset += (offset & 0x8000) << 1; // Account for sign extension in jic.
2809 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2810 Auipc(AT, High16Bits(offset));
2811 Jic(AT, Low16Bits(offset));
2812 break;
2813 case Branch::kLongCall:
Alexey Frunze19f6c692016-11-30 19:19:55 -08002814 offset += (offset & 0x8000) << 1; // Account for sign extension in jialc.
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002815 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
Alexey Frunze19f6c692016-11-30 19:19:55 -08002816 Auipc(AT, High16Bits(offset));
2817 Jialc(AT, Low16Bits(offset));
2818 break;
2819
2820 // Far label.
2821 case Branch::kFarLabel:
Alexey Frunzef63f5692016-12-13 17:43:11 -08002822 offset += (offset & 0x8000) << 1; // Account for sign extension in daddiu.
Alexey Frunze19f6c692016-11-30 19:19:55 -08002823 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2824 Auipc(AT, High16Bits(offset));
Alexey Frunzef63f5692016-12-13 17:43:11 -08002825 Daddiu(lhs, AT, Low16Bits(offset));
Alexey Frunze19f6c692016-11-30 19:19:55 -08002826 break;
2827 // Far literals.
2828 case Branch::kFarLiteral:
2829 offset += (offset & 0x8000) << 1; // Account for sign extension in lw.
2830 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2831 Auipc(AT, High16Bits(offset));
2832 Lw(lhs, AT, Low16Bits(offset));
2833 break;
2834 case Branch::kFarLiteralUnsigned:
2835 offset += (offset & 0x8000) << 1; // Account for sign extension in lwu.
2836 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2837 Auipc(AT, High16Bits(offset));
2838 Lwu(lhs, AT, Low16Bits(offset));
2839 break;
2840 case Branch::kFarLiteralLong:
2841 offset += (offset & 0x8000) << 1; // Account for sign extension in ld.
2842 CHECK_EQ(overwrite_location_, branch->GetOffsetLocation());
2843 Auipc(AT, High16Bits(offset));
2844 Ld(lhs, AT, Low16Bits(offset));
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002845 break;
2846 }
2847 CHECK_EQ(overwrite_location_, branch->GetEndLocation());
2848 CHECK_LT(branch->GetSize(), static_cast<uint32_t>(Branch::kMaxBranchSize));
Alexey Frunze4dda3372015-06-01 18:31:49 -07002849}
2850
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002851void Mips64Assembler::Bc(Mips64Label* label) {
2852 Buncond(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002853}
2854
Alexey Frunze19f6c692016-11-30 19:19:55 -08002855void Mips64Assembler::Balc(Mips64Label* label) {
2856 Call(label);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002857}
2858
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002859void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2860 Bcond(label, kCondLT, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002861}
2862
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002863void Mips64Assembler::Bltzc(GpuRegister rt, Mips64Label* label) {
2864 Bcond(label, kCondLTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002865}
2866
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002867void Mips64Assembler::Bgtzc(GpuRegister rt, Mips64Label* label) {
2868 Bcond(label, kCondGTZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002869}
2870
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002871void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2872 Bcond(label, kCondGE, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002873}
2874
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002875void Mips64Assembler::Bgezc(GpuRegister rt, Mips64Label* label) {
2876 Bcond(label, kCondGEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002877}
2878
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002879void Mips64Assembler::Blezc(GpuRegister rt, Mips64Label* label) {
2880 Bcond(label, kCondLEZ, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002881}
2882
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002883void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2884 Bcond(label, kCondLTU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002885}
2886
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002887void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2888 Bcond(label, kCondGEU, rs, rt);
Alexey Frunze4dda3372015-06-01 18:31:49 -07002889}
2890
Alexey Frunzea0e87b02015-09-24 22:57:20 -07002891void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2892 Bcond(label, kCondEQ, rs, rt);
2893}
2894
2895void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, Mips64Label* label) {
2896 Bcond(label, kCondNE, rs, rt);
2897}
2898
2899void Mips64Assembler::Beqzc(GpuRegister rs, Mips64Label* label) {
2900 Bcond(label, kCondEQZ, rs);
2901}
2902
2903void Mips64Assembler::Bnezc(GpuRegister rs, Mips64Label* label) {
2904 Bcond(label, kCondNEZ, rs);
Andreas Gampe57b34292015-01-14 15:45:59 -08002905}
2906
Alexey Frunze299a9392015-12-08 16:08:02 -08002907void Mips64Assembler::Bc1eqz(FpuRegister ft, Mips64Label* label) {
2908 Bcond(label, kCondF, static_cast<GpuRegister>(ft), ZERO);
2909}
2910
2911void Mips64Assembler::Bc1nez(FpuRegister ft, Mips64Label* label) {
2912 Bcond(label, kCondT, static_cast<GpuRegister>(ft), ZERO);
2913}
2914
Chris Larsenc3fec0c2016-12-15 11:44:14 -08002915void Mips64Assembler::AdjustBaseAndOffset(GpuRegister& base,
2916 int32_t& offset,
2917 bool is_doubleword) {
2918 // This method is used to adjust the base register and offset pair
2919 // for a load/store when the offset doesn't fit into int16_t.
2920 // It is assumed that `base + offset` is sufficiently aligned for memory
2921 // operands that are machine word in size or smaller. For doubleword-sized
2922 // operands it's assumed that `base` is a multiple of 8, while `offset`
2923 // may be a multiple of 4 (e.g. 4-byte-aligned long and double arguments
2924 // and spilled variables on the stack accessed relative to the stack
2925 // pointer register).
2926 // We preserve the "alignment" of `offset` by adjusting it by a multiple of 8.
2927 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
2928
2929 bool doubleword_aligned = IsAligned<kMips64DoublewordSize>(offset);
2930 bool two_accesses = is_doubleword && !doubleword_aligned;
2931
2932 // IsInt<16> must be passed a signed value, hence the static cast below.
2933 if (IsInt<16>(offset) &&
2934 (!two_accesses || IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)))) {
2935 // Nothing to do: `offset` (and, if needed, `offset + 4`) fits into int16_t.
2936 return;
2937 }
2938
2939 // Remember the "(mis)alignment" of `offset`, it will be checked at the end.
2940 uint32_t misalignment = offset & (kMips64DoublewordSize - 1);
2941
2942 // First, see if `offset` can be represented as a sum of two 16-bit signed
2943 // offsets. This can save an instruction.
2944 // To simplify matters, only do this for a symmetric range of offsets from
2945 // about -64KB to about +64KB, allowing further addition of 4 when accessing
2946 // 64-bit variables with two 32-bit accesses.
2947 constexpr int32_t kMinOffsetForSimpleAdjustment = 0x7ff8; // Max int16_t that's a multiple of 8.
2948 constexpr int32_t kMaxOffsetForSimpleAdjustment = 2 * kMinOffsetForSimpleAdjustment;
2949
2950 if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
2951 Daddiu(AT, base, kMinOffsetForSimpleAdjustment);
2952 offset -= kMinOffsetForSimpleAdjustment;
2953 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
2954 Daddiu(AT, base, -kMinOffsetForSimpleAdjustment);
2955 offset += kMinOffsetForSimpleAdjustment;
2956 } else {
2957 // In more complex cases take advantage of the daui instruction, e.g.:
2958 // daui AT, base, offset_high
2959 // [dahi AT, 1] // When `offset` is close to +2GB.
2960 // lw reg_lo, offset_low(AT)
2961 // [lw reg_hi, (offset_low+4)(AT)] // If misaligned 64-bit load.
2962 // or when offset_low+4 overflows int16_t:
2963 // daui AT, base, offset_high
2964 // daddiu AT, AT, 8
2965 // lw reg_lo, (offset_low-8)(AT)
2966 // lw reg_hi, (offset_low-4)(AT)
2967 int16_t offset_low = Low16Bits(offset);
2968 int32_t offset_low32 = offset_low;
2969 int16_t offset_high = High16Bits(offset);
2970 bool increment_hi16 = offset_low < 0;
2971 bool overflow_hi16 = false;
2972
2973 if (increment_hi16) {
2974 offset_high++;
2975 overflow_hi16 = (offset_high == -32768);
2976 }
2977 Daui(AT, base, offset_high);
2978
2979 if (overflow_hi16) {
2980 Dahi(AT, 1);
2981 }
2982
2983 if (two_accesses && !IsInt<16>(static_cast<int32_t>(offset_low32 + kMips64WordSize))) {
2984 // Avoid overflow in the 16-bit offset of the load/store instruction when adding 4.
2985 Daddiu(AT, AT, kMips64DoublewordSize);
2986 offset_low32 -= kMips64DoublewordSize;
2987 }
2988
2989 offset = offset_low32;
2990 }
2991 base = AT;
2992
2993 CHECK(IsInt<16>(offset));
2994 if (two_accesses) {
2995 CHECK(IsInt<16>(static_cast<int32_t>(offset + kMips64WordSize)));
2996 }
2997 CHECK_EQ(misalignment, offset & (kMips64DoublewordSize - 1));
2998}
2999
Goran Jakovljevicd8b6a532017-04-20 11:42:30 +02003000void Mips64Assembler::AdjustBaseOffsetAndElementSizeShift(GpuRegister& base,
3001 int32_t& offset,
3002 int& element_size_shift) {
3003 // This method is used to adjust the base register, offset and element_size_shift
3004 // for a vector load/store when the offset doesn't fit into allowed number of bits.
3005 // MSA ld.df and st.df instructions take signed offsets as arguments, but maximum
3006 // offset is dependant on the size of the data format df (10-bit offsets for ld.b,
3007 // 11-bit for ld.h, 12-bit for ld.w and 13-bit for ld.d).
3008 // If element_size_shift is non-negative at entry, it won't be changed, but offset
3009 // will be checked for appropriate alignment. If negative at entry, it will be
3010 // adjusted based on offset for maximum fit.
3011 // It's assumed that `base` is a multiple of 8.
3012
3013 CHECK_NE(base, AT); // Must not overwrite the register `base` while loading `offset`.
3014
3015 if (element_size_shift >= 0) {
3016 CHECK_LE(element_size_shift, TIMES_8);
3017 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
3018 } else if (IsAligned<kMips64DoublewordSize>(offset)) {
3019 element_size_shift = TIMES_8;
3020 } else if (IsAligned<kMips64WordSize>(offset)) {
3021 element_size_shift = TIMES_4;
3022 } else if (IsAligned<kMips64HalfwordSize>(offset)) {
3023 element_size_shift = TIMES_2;
3024 } else {
3025 element_size_shift = TIMES_1;
3026 }
3027
3028 const int low_len = 10 + element_size_shift; // How many low bits of `offset` ld.df/st.df
3029 // will take.
3030 int16_t low = offset & ((1 << low_len) - 1); // Isolate these bits.
3031 low -= (low & (1 << (low_len - 1))) << 1; // Sign-extend these bits.
3032 if (low == offset) {
3033 return; // `offset` fits into ld.df/st.df.
3034 }
3035
3036 // First, see if `offset` can be represented as a sum of two signed offsets.
3037 // This can save an instruction.
3038
3039 // Max int16_t that's a multiple of element size.
3040 const int32_t kMaxDeltaForSimpleAdjustment = 0x8000 - (1 << element_size_shift);
3041 // Max ld.df/st.df offset that's a multiple of element size.
3042 const int32_t kMaxLoadStoreOffset = 0x1ff << element_size_shift;
3043 const int32_t kMaxOffsetForSimpleAdjustment = kMaxDeltaForSimpleAdjustment + kMaxLoadStoreOffset;
3044
3045 if (IsInt<16>(offset)) {
3046 Daddiu(AT, base, offset);
3047 offset = 0;
3048 } else if (0 <= offset && offset <= kMaxOffsetForSimpleAdjustment) {
3049 Daddiu(AT, base, kMaxDeltaForSimpleAdjustment);
3050 offset -= kMaxDeltaForSimpleAdjustment;
3051 } else if (-kMaxOffsetForSimpleAdjustment <= offset && offset < 0) {
3052 Daddiu(AT, base, -kMaxDeltaForSimpleAdjustment);
3053 offset += kMaxDeltaForSimpleAdjustment;
3054 } else {
3055 // Let's treat `offset` as 64-bit to simplify handling of sign
3056 // extensions in the instructions that supply its smaller signed parts.
3057 //
3058 // 16-bit or smaller parts of `offset`:
3059 // |63 top 48|47 hi 32|31 upper 16|15 mid 13-10|12-9 low 0|
3060 //
3061 // Instructions that supply each part as a signed integer addend:
3062 // |dati |dahi |daui |daddiu |ld.df/st.df |
3063 //
3064 // `top` is always 0, so dati isn't used.
3065 // `hi` is 1 when `offset` is close to +2GB and 0 otherwise.
3066 uint64_t tmp = static_cast<uint64_t>(offset) - low; // Exclude `low` from the rest of `offset`
3067 // (accounts for sign of `low`).
3068 tmp += (tmp & (UINT64_C(1) << 15)) << 1; // Account for sign extension in daddiu.
3069 tmp += (tmp & (UINT64_C(1) << 31)) << 1; // Account for sign extension in daui.
3070 int16_t mid = Low16Bits(tmp);
3071 int16_t upper = High16Bits(tmp);
3072 int16_t hi = Low16Bits(High32Bits(tmp));
3073 Daui(AT, base, upper);
3074 if (hi != 0) {
3075 CHECK_EQ(hi, 1);
3076 Dahi(AT, hi);
3077 }
3078 if (mid != 0) {
3079 Daddiu(AT, AT, mid);
3080 }
3081 offset = low;
3082 }
3083 base = AT;
3084 CHECK_GE(JAVASTYLE_CTZ(offset), element_size_shift);
3085 CHECK(IsInt<10>(offset >> element_size_shift));
3086}
3087
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003088void Mips64Assembler::LoadFromOffset(LoadOperandType type,
3089 GpuRegister reg,
3090 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08003091 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003092 LoadFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003093}
3094
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003095void Mips64Assembler::LoadFpuFromOffset(LoadOperandType type,
3096 FpuRegister reg,
3097 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08003098 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003099 LoadFpuFromOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003100}
3101
3102void Mips64Assembler::EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset,
3103 size_t size) {
3104 Mips64ManagedRegister dst = m_dst.AsMips64();
3105 if (dst.IsNoRegister()) {
3106 CHECK_EQ(0u, size) << dst;
3107 } else if (dst.IsGpuRegister()) {
3108 if (size == 4) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003109 LoadFromOffset(kLoadWord, dst.AsGpuRegister(), src_register, src_offset);
3110 } else if (size == 8) {
3111 CHECK_EQ(8u, size) << dst;
3112 LoadFromOffset(kLoadDoubleword, dst.AsGpuRegister(), src_register, src_offset);
3113 } else {
3114 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
3115 }
3116 } else if (dst.IsFpuRegister()) {
3117 if (size == 4) {
3118 CHECK_EQ(4u, size) << dst;
3119 LoadFpuFromOffset(kLoadWord, dst.AsFpuRegister(), src_register, src_offset);
3120 } else if (size == 8) {
3121 CHECK_EQ(8u, size) << dst;
3122 LoadFpuFromOffset(kLoadDoubleword, dst.AsFpuRegister(), src_register, src_offset);
3123 } else {
3124 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
3125 }
3126 }
3127}
3128
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003129void Mips64Assembler::StoreToOffset(StoreOperandType type,
3130 GpuRegister reg,
3131 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08003132 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003133 StoreToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003134}
3135
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003136void Mips64Assembler::StoreFpuToOffset(StoreOperandType type,
3137 FpuRegister reg,
3138 GpuRegister base,
Andreas Gampe57b34292015-01-14 15:45:59 -08003139 int32_t offset) {
Tijana Jakovljevic57433862017-01-17 16:59:03 +01003140 StoreFpuToOffset<>(type, reg, base, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003141}
3142
David Srbeckydd973932015-04-07 20:29:48 +01003143static dwarf::Reg DWARFReg(GpuRegister reg) {
3144 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
3145}
3146
Andreas Gampe57b34292015-01-14 15:45:59 -08003147constexpr size_t kFramePointerSize = 8;
3148
Vladimir Marko32248382016-05-19 10:37:24 +01003149void Mips64Assembler::BuildFrame(size_t frame_size,
3150 ManagedRegister method_reg,
3151 ArrayRef<const ManagedRegister> callee_save_regs,
Andreas Gampe57b34292015-01-14 15:45:59 -08003152 const ManagedRegisterEntrySpills& entry_spills) {
3153 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003154 DCHECK(!overwriting_);
Andreas Gampe57b34292015-01-14 15:45:59 -08003155
3156 // Increase frame to required size.
3157 IncreaseFrameSize(frame_size);
3158
3159 // Push callee saves and return address
3160 int stack_offset = frame_size - kFramePointerSize;
3161 StoreToOffset(kStoreDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003162 cfi_.RelOffset(DWARFReg(RA), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003163 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
3164 stack_offset -= kFramePointerSize;
Vladimir Marko32248382016-05-19 10:37:24 +01003165 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08003166 StoreToOffset(kStoreDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003167 cfi_.RelOffset(DWARFReg(reg), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003168 }
3169
3170 // Write out Method*.
Mathieu Chartiere401d142015-04-22 13:56:20 -07003171 StoreToOffset(kStoreDoubleword, method_reg.AsMips64().AsGpuRegister(), SP, 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003172
3173 // Write out entry spills.
Mathieu Chartiere401d142015-04-22 13:56:20 -07003174 int32_t offset = frame_size + kFramePointerSize;
Andreas Gampe57b34292015-01-14 15:45:59 -08003175 for (size_t i = 0; i < entry_spills.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003176 Mips64ManagedRegister reg = entry_spills[i].AsMips64();
Andreas Gampe57b34292015-01-14 15:45:59 -08003177 ManagedRegisterSpill spill = entry_spills.at(i);
3178 int32_t size = spill.getSize();
3179 if (reg.IsNoRegister()) {
3180 // only increment stack offset.
3181 offset += size;
3182 } else if (reg.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003183 StoreFpuToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3184 reg.AsFpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003185 offset += size;
3186 } else if (reg.IsGpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003187 StoreToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
3188 reg.AsGpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08003189 offset += size;
3190 }
3191 }
3192}
3193
3194void Mips64Assembler::RemoveFrame(size_t frame_size,
Vladimir Marko32248382016-05-19 10:37:24 +01003195 ArrayRef<const ManagedRegister> callee_save_regs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003196 CHECK_ALIGNED(frame_size, kStackAlignment);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003197 DCHECK(!overwriting_);
David Srbeckydd973932015-04-07 20:29:48 +01003198 cfi_.RememberState();
Andreas Gampe57b34292015-01-14 15:45:59 -08003199
3200 // Pop callee saves and return address
3201 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
3202 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
Vladimir Marko32248382016-05-19 10:37:24 +01003203 GpuRegister reg = callee_save_regs[i].AsMips64().AsGpuRegister();
Andreas Gampe57b34292015-01-14 15:45:59 -08003204 LoadFromOffset(kLoadDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003205 cfi_.Restore(DWARFReg(reg));
Andreas Gampe57b34292015-01-14 15:45:59 -08003206 stack_offset += kFramePointerSize;
3207 }
3208 LoadFromOffset(kLoadDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01003209 cfi_.Restore(DWARFReg(RA));
Andreas Gampe57b34292015-01-14 15:45:59 -08003210
3211 // Decrease frame to required size.
3212 DecreaseFrameSize(frame_size);
3213
3214 // Then jump to the return address.
3215 Jr(RA);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003216 Nop();
David Srbeckydd973932015-04-07 20:29:48 +01003217
3218 // The CFI should be restored for any code that follows the exit block.
3219 cfi_.RestoreState();
3220 cfi_.DefCFAOffset(frame_size);
Andreas Gampe57b34292015-01-14 15:45:59 -08003221}
3222
3223void Mips64Assembler::IncreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003224 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003225 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003226 Daddiu64(SP, SP, static_cast<int32_t>(-adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003227 cfi_.AdjustCFAOffset(adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003228}
3229
3230void Mips64Assembler::DecreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003231 CHECK_ALIGNED(adjust, kFramePointerSize);
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003232 DCHECK(!overwriting_);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003233 Daddiu64(SP, SP, static_cast<int32_t>(adjust));
David Srbeckydd973932015-04-07 20:29:48 +01003234 cfi_.AdjustCFAOffset(-adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08003235}
3236
3237void Mips64Assembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
3238 Mips64ManagedRegister src = msrc.AsMips64();
3239 if (src.IsNoRegister()) {
3240 CHECK_EQ(0u, size);
3241 } else if (src.IsGpuRegister()) {
3242 CHECK(size == 4 || size == 8) << size;
3243 if (size == 8) {
3244 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3245 } else if (size == 4) {
3246 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3247 } else {
3248 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3249 }
3250 } else if (src.IsFpuRegister()) {
3251 CHECK(size == 4 || size == 8) << size;
3252 if (size == 8) {
3253 StoreFpuToOffset(kStoreDoubleword, src.AsFpuRegister(), SP, dest.Int32Value());
3254 } else if (size == 4) {
3255 StoreFpuToOffset(kStoreWord, src.AsFpuRegister(), SP, dest.Int32Value());
3256 } else {
3257 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
3258 }
3259 }
3260}
3261
3262void Mips64Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
3263 Mips64ManagedRegister src = msrc.AsMips64();
3264 CHECK(src.IsGpuRegister());
3265 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
3266}
3267
3268void Mips64Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
3269 Mips64ManagedRegister src = msrc.AsMips64();
3270 CHECK(src.IsGpuRegister());
3271 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3272}
3273
3274void Mips64Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
3275 ManagedRegister mscratch) {
3276 Mips64ManagedRegister scratch = mscratch.AsMips64();
3277 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003278 LoadConst32(scratch.AsGpuRegister(), imm);
Andreas Gampe57b34292015-01-14 15:45:59 -08003279 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3280}
3281
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003282void Mips64Assembler::StoreStackOffsetToThread(ThreadOffset64 thr_offs,
3283 FrameOffset fr_offs,
3284 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003285 Mips64ManagedRegister scratch = mscratch.AsMips64();
3286 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07003287 Daddiu64(scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003288 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3289}
3290
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003291void Mips64Assembler::StoreStackPointerToThread(ThreadOffset64 thr_offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003292 StoreToOffset(kStoreDoubleword, SP, S1, thr_offs.Int32Value());
3293}
3294
3295void Mips64Assembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
3296 FrameOffset in_off, ManagedRegister mscratch) {
3297 Mips64ManagedRegister src = msrc.AsMips64();
3298 Mips64ManagedRegister scratch = mscratch.AsMips64();
3299 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
3300 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, in_off.Int32Value());
3301 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value() + 8);
3302}
3303
3304void Mips64Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
3305 return EmitLoad(mdest, SP, src.Int32Value(), size);
3306}
3307
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003308void Mips64Assembler::LoadFromThread(ManagedRegister mdest, ThreadOffset64 src, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003309 return EmitLoad(mdest, S1, src.Int32Value(), size);
3310}
3311
3312void Mips64Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
3313 Mips64ManagedRegister dest = mdest.AsMips64();
3314 CHECK(dest.IsGpuRegister());
Douglas Leungd90957f2015-04-30 19:22:49 -07003315 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(), SP, src.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003316}
3317
Mathieu Chartiere401d142015-04-22 13:56:20 -07003318void Mips64Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01003319 bool unpoison_reference) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003320 Mips64ManagedRegister dest = mdest.AsMips64();
Douglas Leungd90957f2015-04-30 19:22:49 -07003321 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
3322 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003323 base.AsMips64().AsGpuRegister(), offs.Int32Value());
Alexey Frunzec061de12017-02-14 13:27:23 -08003324 if (unpoison_reference) {
3325 MaybeUnpoisonHeapReference(dest.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003326 }
3327}
3328
3329void Mips64Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003330 Offset offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003331 Mips64ManagedRegister dest = mdest.AsMips64();
Alexey Frunze4dda3372015-06-01 18:31:49 -07003332 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003333 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(),
3334 base.AsMips64().AsGpuRegister(), offs.Int32Value());
3335}
3336
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003337void Mips64Assembler::LoadRawPtrFromThread(ManagedRegister mdest, ThreadOffset64 offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003338 Mips64ManagedRegister dest = mdest.AsMips64();
3339 CHECK(dest.IsGpuRegister());
3340 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(), S1, offs.Int32Value());
3341}
3342
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003343void Mips64Assembler::SignExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3344 size_t size ATTRIBUTE_UNUSED) {
3345 UNIMPLEMENTED(FATAL) << "No sign extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003346}
3347
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003348void Mips64Assembler::ZeroExtend(ManagedRegister mreg ATTRIBUTE_UNUSED,
3349 size_t size ATTRIBUTE_UNUSED) {
3350 UNIMPLEMENTED(FATAL) << "No zero extension necessary for MIPS64";
Andreas Gampe57b34292015-01-14 15:45:59 -08003351}
3352
3353void Mips64Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
3354 Mips64ManagedRegister dest = mdest.AsMips64();
3355 Mips64ManagedRegister src = msrc.AsMips64();
3356 if (!dest.Equals(src)) {
3357 if (dest.IsGpuRegister()) {
3358 CHECK(src.IsGpuRegister()) << src;
3359 Move(dest.AsGpuRegister(), src.AsGpuRegister());
3360 } else if (dest.IsFpuRegister()) {
3361 CHECK(src.IsFpuRegister()) << src;
3362 if (size == 4) {
3363 MovS(dest.AsFpuRegister(), src.AsFpuRegister());
3364 } else if (size == 8) {
3365 MovD(dest.AsFpuRegister(), src.AsFpuRegister());
3366 } else {
3367 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3368 }
3369 }
3370 }
3371}
3372
3373void Mips64Assembler::CopyRef(FrameOffset dest, FrameOffset src,
3374 ManagedRegister mscratch) {
3375 Mips64ManagedRegister scratch = mscratch.AsMips64();
3376 CHECK(scratch.IsGpuRegister()) << scratch;
3377 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
3378 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
3379}
3380
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003381void Mips64Assembler::CopyRawPtrFromThread(FrameOffset fr_offs,
3382 ThreadOffset64 thr_offs,
3383 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003384 Mips64ManagedRegister scratch = mscratch.AsMips64();
3385 CHECK(scratch.IsGpuRegister()) << scratch;
3386 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
3387 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
3388}
3389
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003390void Mips64Assembler::CopyRawPtrToThread(ThreadOffset64 thr_offs,
3391 FrameOffset fr_offs,
3392 ManagedRegister mscratch) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003393 Mips64ManagedRegister scratch = mscratch.AsMips64();
3394 CHECK(scratch.IsGpuRegister()) << scratch;
3395 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3396 SP, fr_offs.Int32Value());
3397 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(),
3398 S1, thr_offs.Int32Value());
3399}
3400
3401void Mips64Assembler::Copy(FrameOffset dest, FrameOffset src,
3402 ManagedRegister mscratch, size_t size) {
3403 Mips64ManagedRegister scratch = mscratch.AsMips64();
3404 CHECK(scratch.IsGpuRegister()) << scratch;
3405 CHECK(size == 4 || size == 8) << size;
3406 if (size == 4) {
3407 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003408 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003409 } else if (size == 8) {
3410 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, src.Int32Value());
3411 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
3412 } else {
3413 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3414 }
3415}
3416
3417void Mips64Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003418 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003419 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3420 CHECK(size == 4 || size == 8) << size;
3421 if (size == 4) {
3422 LoadFromOffset(kLoadWord, scratch, src_base.AsMips64().AsGpuRegister(),
3423 src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003424 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003425 } else if (size == 8) {
3426 LoadFromOffset(kLoadDoubleword, scratch, src_base.AsMips64().AsGpuRegister(),
3427 src_offset.Int32Value());
3428 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
3429 } else {
3430 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3431 }
3432}
3433
3434void Mips64Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003435 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003436 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3437 CHECK(size == 4 || size == 8) << size;
3438 if (size == 4) {
3439 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003440 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003441 dest_offset.Int32Value());
3442 } else if (size == 8) {
3443 LoadFromOffset(kLoadDoubleword, scratch, SP, src.Int32Value());
3444 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
3445 dest_offset.Int32Value());
3446 } else {
3447 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3448 }
3449}
3450
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003451void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3452 FrameOffset src_base ATTRIBUTE_UNUSED,
3453 Offset src_offset ATTRIBUTE_UNUSED,
3454 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3455 size_t size ATTRIBUTE_UNUSED) {
3456 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003457}
3458
3459void Mips64Assembler::Copy(ManagedRegister dest, Offset dest_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003460 ManagedRegister src, Offset src_offset,
3461 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003462 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
3463 CHECK(size == 4 || size == 8) << size;
3464 if (size == 4) {
3465 LoadFromOffset(kLoadWord, scratch, src.AsMips64().AsGpuRegister(), src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02003466 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(), dest_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003467 } else if (size == 8) {
3468 LoadFromOffset(kLoadDoubleword, scratch, src.AsMips64().AsGpuRegister(),
3469 src_offset.Int32Value());
3470 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(),
3471 dest_offset.Int32Value());
3472 } else {
3473 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
3474 }
3475}
3476
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003477void Mips64Assembler::Copy(FrameOffset dest ATTRIBUTE_UNUSED,
3478 Offset dest_offset ATTRIBUTE_UNUSED,
3479 FrameOffset src ATTRIBUTE_UNUSED,
3480 Offset src_offset ATTRIBUTE_UNUSED,
3481 ManagedRegister mscratch ATTRIBUTE_UNUSED,
3482 size_t size ATTRIBUTE_UNUSED) {
3483 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003484}
3485
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003486void Mips64Assembler::MemoryBarrier(ManagedRegister mreg ATTRIBUTE_UNUSED) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003487 // TODO: sync?
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003488 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003489}
3490
3491void Mips64Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003492 FrameOffset handle_scope_offset,
3493 ManagedRegister min_reg,
3494 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003495 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3496 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3497 CHECK(in_reg.IsNoRegister() || in_reg.IsGpuRegister()) << in_reg;
3498 CHECK(out_reg.IsGpuRegister()) << out_reg;
3499 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003500 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003501 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3502 // the address in the handle scope holding the reference.
3503 // e.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset)
3504 if (in_reg.IsNoRegister()) {
Douglas Leungd90957f2015-04-30 19:22:49 -07003505 LoadFromOffset(kLoadUnsignedWord, out_reg.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003506 SP, handle_scope_offset.Int32Value());
3507 in_reg = out_reg;
3508 }
3509 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003510 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003511 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003512 Beqzc(in_reg.AsGpuRegister(), &null_arg);
3513 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3514 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003515 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003516 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003517 }
3518}
3519
3520void Mips64Assembler::CreateHandleScopeEntry(FrameOffset out_off,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003521 FrameOffset handle_scope_offset,
3522 ManagedRegister mscratch,
3523 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003524 Mips64ManagedRegister scratch = mscratch.AsMips64();
3525 CHECK(scratch.IsGpuRegister()) << scratch;
3526 if (null_allowed) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003527 Mips64Label null_arg;
Douglas Leungd90957f2015-04-30 19:22:49 -07003528 LoadFromOffset(kLoadUnsignedWord, scratch.AsGpuRegister(), SP,
Andreas Gampe57b34292015-01-14 15:45:59 -08003529 handle_scope_offset.Int32Value());
3530 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
3531 // the address in the handle scope holding the reference.
3532 // e.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset)
Alexey Frunze4dda3372015-06-01 18:31:49 -07003533 Beqzc(scratch.AsGpuRegister(), &null_arg);
3534 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
3535 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003536 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003537 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08003538 }
3539 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, out_off.Int32Value());
3540}
3541
3542// Given a handle scope entry, load the associated reference.
3543void Mips64Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07003544 ManagedRegister min_reg) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003545 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
3546 Mips64ManagedRegister in_reg = min_reg.AsMips64();
3547 CHECK(out_reg.IsGpuRegister()) << out_reg;
3548 CHECK(in_reg.IsGpuRegister()) << in_reg;
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003549 Mips64Label null_arg;
Andreas Gampe57b34292015-01-14 15:45:59 -08003550 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07003551 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08003552 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07003553 Beqzc(in_reg.AsGpuRegister(), &null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003554 LoadFromOffset(kLoadDoubleword, out_reg.AsGpuRegister(),
3555 in_reg.AsGpuRegister(), 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07003556 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08003557}
3558
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003559void Mips64Assembler::VerifyObject(ManagedRegister src ATTRIBUTE_UNUSED,
3560 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003561 // TODO: not validating references
3562}
3563
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003564void Mips64Assembler::VerifyObject(FrameOffset src ATTRIBUTE_UNUSED,
3565 bool could_be_null ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003566 // TODO: not validating references
3567}
3568
3569void Mips64Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
3570 Mips64ManagedRegister base = mbase.AsMips64();
3571 Mips64ManagedRegister scratch = mscratch.AsMips64();
3572 CHECK(base.IsGpuRegister()) << base;
3573 CHECK(scratch.IsGpuRegister()) << scratch;
3574 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3575 base.AsGpuRegister(), offset.Int32Value());
3576 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003577 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003578 // TODO: place reference map on call
3579}
3580
3581void Mips64Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
3582 Mips64ManagedRegister scratch = mscratch.AsMips64();
3583 CHECK(scratch.IsGpuRegister()) << scratch;
3584 // Call *(*(SP + base) + offset)
Mathieu Chartiere401d142015-04-22 13:56:20 -07003585 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08003586 SP, base.Int32Value());
3587 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
3588 scratch.AsGpuRegister(), offset.Int32Value());
3589 Jalr(scratch.AsGpuRegister());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003590 Nop();
Andreas Gampe57b34292015-01-14 15:45:59 -08003591 // TODO: place reference map on call
3592}
3593
Andreas Gampe3b165bc2016-08-01 22:07:04 -07003594void Mips64Assembler::CallFromThread(ThreadOffset64 offset ATTRIBUTE_UNUSED,
3595 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003596 UNIMPLEMENTED(FATAL) << "No MIPS64 implementation";
Andreas Gampe57b34292015-01-14 15:45:59 -08003597}
3598
3599void Mips64Assembler::GetCurrentThread(ManagedRegister tr) {
3600 Move(tr.AsMips64().AsGpuRegister(), S1);
3601}
3602
3603void Mips64Assembler::GetCurrentThread(FrameOffset offset,
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003604 ManagedRegister mscratch ATTRIBUTE_UNUSED) {
Andreas Gampe57b34292015-01-14 15:45:59 -08003605 StoreToOffset(kStoreDoubleword, S1, SP, offset.Int32Value());
3606}
3607
3608void Mips64Assembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
3609 Mips64ManagedRegister scratch = mscratch.AsMips64();
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003610 exception_blocks_.emplace_back(scratch, stack_adjust);
3611 LoadFromOffset(kLoadDoubleword,
3612 scratch.AsGpuRegister(),
3613 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003614 Thread::ExceptionOffset<kMips64PointerSize>().Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003615 Bnezc(scratch.AsGpuRegister(), exception_blocks_.back().Entry());
Andreas Gampe57b34292015-01-14 15:45:59 -08003616}
3617
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003618void Mips64Assembler::EmitExceptionPoll(Mips64ExceptionSlowPath* exception) {
3619 Bind(exception->Entry());
3620 if (exception->stack_adjust_ != 0) { // Fix up the frame.
3621 DecreaseFrameSize(exception->stack_adjust_);
Andreas Gampe57b34292015-01-14 15:45:59 -08003622 }
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003623 // Pass exception object as argument.
3624 // Don't care about preserving A0 as this call won't return.
3625 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
3626 Move(A0, exception->scratch_.AsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08003627 // Set up call to Thread::Current()->pDeliverException
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003628 LoadFromOffset(kLoadDoubleword,
3629 T9,
3630 S1,
Andreas Gampe542451c2016-07-26 09:02:02 -07003631 QUICK_ENTRYPOINT_OFFSET(kMips64PointerSize, pDeliverException).Int32Value());
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003632 Jr(T9);
3633 Nop();
3634
Andreas Gampe57b34292015-01-14 15:45:59 -08003635 // Call never returns
Alexey Frunzea0e87b02015-09-24 22:57:20 -07003636 Break();
Andreas Gampe57b34292015-01-14 15:45:59 -08003637}
3638
3639} // namespace mips64
3640} // namespace art