blob: cedbedbc2416a57ce18c42d263cd9b745436a04f [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"
22#include "memory_region.h"
23#include "thread.h"
24
25namespace art {
26namespace mips64 {
27
Alexey Frunze4dda3372015-06-01 18:31:49 -070028void Mips64Assembler::Emit(uint32_t value) {
Andreas Gampe57b34292015-01-14 15:45:59 -080029 AssemblerBuffer::EnsureCapacity ensured(&buffer_);
Alexey Frunze4dda3372015-06-01 18:31:49 -070030 buffer_.Emit<uint32_t>(value);
Andreas Gampe57b34292015-01-14 15:45:59 -080031}
32
33void Mips64Assembler::EmitR(int opcode, GpuRegister rs, GpuRegister rt, GpuRegister rd,
34 int shamt, int funct) {
35 CHECK_NE(rs, kNoGpuRegister);
36 CHECK_NE(rt, kNoGpuRegister);
37 CHECK_NE(rd, kNoGpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -070038 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
39 static_cast<uint32_t>(rs) << kRsShift |
40 static_cast<uint32_t>(rt) << kRtShift |
41 static_cast<uint32_t>(rd) << kRdShift |
42 shamt << kShamtShift |
43 funct;
Andreas Gampe57b34292015-01-14 15:45:59 -080044 Emit(encoding);
45}
46
Chris Larsen2fadd7b2015-08-14 14:56:10 -070047void Mips64Assembler::EmitRsd(int opcode, GpuRegister rs, GpuRegister rd,
48 int shamt, int funct) {
49 CHECK_NE(rs, kNoGpuRegister);
50 CHECK_NE(rd, kNoGpuRegister);
51 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
52 static_cast<uint32_t>(rs) << kRsShift |
53 static_cast<uint32_t>(ZERO) << kRtShift |
54 static_cast<uint32_t>(rd) << kRdShift |
55 shamt << kShamtShift |
56 funct;
57 Emit(encoding);
58}
59
60void Mips64Assembler::EmitRtd(int opcode, GpuRegister rt, GpuRegister rd,
61 int shamt, int funct) {
62 CHECK_NE(rt, kNoGpuRegister);
63 CHECK_NE(rd, kNoGpuRegister);
64 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
65 static_cast<uint32_t>(ZERO) << kRsShift |
66 static_cast<uint32_t>(rt) << kRtShift |
67 static_cast<uint32_t>(rd) << kRdShift |
68 shamt << kShamtShift |
69 funct;
70 Emit(encoding);
71}
72
Andreas Gampe57b34292015-01-14 15:45:59 -080073void Mips64Assembler::EmitI(int opcode, GpuRegister rs, GpuRegister rt, uint16_t imm) {
74 CHECK_NE(rs, kNoGpuRegister);
75 CHECK_NE(rt, kNoGpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -070076 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
77 static_cast<uint32_t>(rs) << kRsShift |
78 static_cast<uint32_t>(rt) << kRtShift |
79 imm;
Andreas Gampe57b34292015-01-14 15:45:59 -080080 Emit(encoding);
81}
82
Alexey Frunze4dda3372015-06-01 18:31:49 -070083void Mips64Assembler::EmitI21(int opcode, GpuRegister rs, uint32_t imm21) {
84 CHECK_NE(rs, kNoGpuRegister);
85 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
86 static_cast<uint32_t>(rs) << kRsShift |
87 (imm21 & 0x1FFFFF);
88 Emit(encoding);
89}
90
91void Mips64Assembler::EmitJ(int opcode, uint32_t addr26) {
92 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
93 (addr26 & 0x3FFFFFF);
Andreas Gampe57b34292015-01-14 15:45:59 -080094 Emit(encoding);
95}
96
97void Mips64Assembler::EmitFR(int opcode, int fmt, FpuRegister ft, FpuRegister fs, FpuRegister fd,
Alexey Frunze4dda3372015-06-01 18:31:49 -070098 int funct) {
Andreas Gampe57b34292015-01-14 15:45:59 -080099 CHECK_NE(ft, kNoFpuRegister);
100 CHECK_NE(fs, kNoFpuRegister);
101 CHECK_NE(fd, kNoFpuRegister);
Alexey Frunze4dda3372015-06-01 18:31:49 -0700102 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
103 fmt << kFmtShift |
104 static_cast<uint32_t>(ft) << kFtShift |
105 static_cast<uint32_t>(fs) << kFsShift |
106 static_cast<uint32_t>(fd) << kFdShift |
107 funct;
Andreas Gampe57b34292015-01-14 15:45:59 -0800108 Emit(encoding);
109}
110
Alexey Frunze4dda3372015-06-01 18:31:49 -0700111void Mips64Assembler::EmitFI(int opcode, int fmt, FpuRegister ft, uint16_t imm) {
112 CHECK_NE(ft, kNoFpuRegister);
113 uint32_t encoding = static_cast<uint32_t>(opcode) << kOpcodeShift |
114 fmt << kFmtShift |
115 static_cast<uint32_t>(ft) << kFtShift |
116 imm;
Andreas Gampe57b34292015-01-14 15:45:59 -0800117 Emit(encoding);
118}
119
Andreas Gampe57b34292015-01-14 15:45:59 -0800120void Mips64Assembler::Add(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
121 EmitR(0, rs, rt, rd, 0, 0x20);
122}
123
124void Mips64Assembler::Addi(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
125 EmitI(0x8, rs, rt, imm16);
126}
127
128void Mips64Assembler::Addu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
129 EmitR(0, rs, rt, rd, 0, 0x21);
130}
131
132void Mips64Assembler::Addiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
133 EmitI(0x9, rs, rt, imm16);
134}
135
Alexey Frunze4dda3372015-06-01 18:31:49 -0700136void Mips64Assembler::Daddu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
137 EmitR(0, rs, rt, rd, 0, 0x2d);
138}
139
Andreas Gampe57b34292015-01-14 15:45:59 -0800140void Mips64Assembler::Daddiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
141 EmitI(0x19, rs, rt, imm16);
142}
143
144void Mips64Assembler::Sub(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
145 EmitR(0, rs, rt, rd, 0, 0x22);
146}
147
148void Mips64Assembler::Subu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
149 EmitR(0, rs, rt, rd, 0, 0x23);
150}
151
Alexey Frunze4dda3372015-06-01 18:31:49 -0700152void Mips64Assembler::Dsubu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
153 EmitR(0, rs, rt, rd, 0, 0x2f);
154}
155
156void Mips64Assembler::MultR2(GpuRegister rs, GpuRegister rt) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800157 EmitR(0, rs, rt, static_cast<GpuRegister>(0), 0, 0x18);
158}
159
Alexey Frunze4dda3372015-06-01 18:31:49 -0700160void Mips64Assembler::MultuR2(GpuRegister rs, GpuRegister rt) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800161 EmitR(0, rs, rt, static_cast<GpuRegister>(0), 0, 0x19);
162}
163
Alexey Frunze4dda3372015-06-01 18:31:49 -0700164void Mips64Assembler::DivR2(GpuRegister rs, GpuRegister rt) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800165 EmitR(0, rs, rt, static_cast<GpuRegister>(0), 0, 0x1a);
166}
167
Alexey Frunze4dda3372015-06-01 18:31:49 -0700168void Mips64Assembler::DivuR2(GpuRegister rs, GpuRegister rt) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800169 EmitR(0, rs, rt, static_cast<GpuRegister>(0), 0, 0x1b);
170}
171
Alexey Frunze4dda3372015-06-01 18:31:49 -0700172void Mips64Assembler::MulR2(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
173 EmitR(0x1c, rs, rt, rd, 0, 2);
174}
175
176void Mips64Assembler::DivR2(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
177 DivR2(rs, rt);
178 Mflo(rd);
179}
180
181void Mips64Assembler::ModR2(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
182 DivR2(rs, rt);
183 Mfhi(rd);
184}
185
186void Mips64Assembler::DivuR2(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
187 DivuR2(rs, rt);
188 Mflo(rd);
189}
190
191void Mips64Assembler::ModuR2(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
192 DivuR2(rs, rt);
193 Mfhi(rd);
194}
195
196void Mips64Assembler::MulR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
197 EmitR(0, rs, rt, rd, 2, 0x18);
198}
199
200void Mips64Assembler::DivR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
201 EmitR(0, rs, rt, rd, 2, 0x1a);
202}
203
204void Mips64Assembler::ModR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
205 EmitR(0, rs, rt, rd, 3, 0x1a);
206}
207
208void Mips64Assembler::DivuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
209 EmitR(0, rs, rt, rd, 2, 0x1b);
210}
211
212void Mips64Assembler::ModuR6(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
213 EmitR(0, rs, rt, rd, 3, 0x1b);
214}
215
216void Mips64Assembler::Dmul(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
217 EmitR(0, rs, rt, rd, 2, 0x1c);
218}
219
220void Mips64Assembler::Ddiv(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
221 EmitR(0, rs, rt, rd, 2, 0x1e);
222}
223
224void Mips64Assembler::Dmod(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
225 EmitR(0, rs, rt, rd, 3, 0x1e);
226}
227
228void Mips64Assembler::Ddivu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
229 EmitR(0, rs, rt, rd, 2, 0x1f);
230}
231
232void Mips64Assembler::Dmodu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
233 EmitR(0, rs, rt, rd, 3, 0x1f);
234}
235
Andreas Gampe57b34292015-01-14 15:45:59 -0800236void Mips64Assembler::And(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
237 EmitR(0, rs, rt, rd, 0, 0x24);
238}
239
240void Mips64Assembler::Andi(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
241 EmitI(0xc, rs, rt, imm16);
242}
243
244void Mips64Assembler::Or(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
245 EmitR(0, rs, rt, rd, 0, 0x25);
246}
247
248void Mips64Assembler::Ori(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
249 EmitI(0xd, rs, rt, imm16);
250}
251
252void Mips64Assembler::Xor(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
253 EmitR(0, rs, rt, rd, 0, 0x26);
254}
255
256void Mips64Assembler::Xori(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
257 EmitI(0xe, rs, rt, imm16);
258}
259
260void Mips64Assembler::Nor(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
261 EmitR(0, rs, rt, rd, 0, 0x27);
262}
263
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700264void Mips64Assembler::Bitswap(GpuRegister rd, GpuRegister rt) {
265 EmitRtd(0x1f, rt, rd, 0x0, 0x20);
266}
267
268void Mips64Assembler::Dbitswap(GpuRegister rd, GpuRegister rt) {
269 EmitRtd(0x1f, rt, rd, 0x0, 0x24);
270}
271
Alexey Frunze4dda3372015-06-01 18:31:49 -0700272void Mips64Assembler::Seb(GpuRegister rd, GpuRegister rt) {
273 EmitR(0x1f, static_cast<GpuRegister>(0), rt, rd, 0x10, 0x20);
Andreas Gampe57b34292015-01-14 15:45:59 -0800274}
275
Alexey Frunze4dda3372015-06-01 18:31:49 -0700276void Mips64Assembler::Seh(GpuRegister rd, GpuRegister rt) {
277 EmitR(0x1f, static_cast<GpuRegister>(0), rt, rd, 0x18, 0x20);
Andreas Gampe57b34292015-01-14 15:45:59 -0800278}
279
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700280void Mips64Assembler::Dsbh(GpuRegister rd, GpuRegister rt) {
281 EmitRtd(0x1f, rt, rd, 0x2, 0x24);
282}
283
284void Mips64Assembler::Dshd(GpuRegister rd, GpuRegister rt) {
285 EmitRtd(0x1f, rt, rd, 0x5, 0x24);
286}
287
Alexey Frunze4dda3372015-06-01 18:31:49 -0700288void Mips64Assembler::Dext(GpuRegister rt, GpuRegister rs, int pos, int size_less_one) {
289 DCHECK(0 <= pos && pos < 32) << pos;
290 DCHECK(0 <= size_less_one && size_less_one < 32) << size_less_one;
291 EmitR(0x1f, rs, rt, static_cast<GpuRegister>(size_less_one), pos, 3);
Andreas Gampe57b34292015-01-14 15:45:59 -0800292}
293
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700294void Mips64Assembler::Wsbh(GpuRegister rd, GpuRegister rt) {
295 EmitRtd(0x1f, rt, rd, 2, 0x20);
296}
297
298void Mips64Assembler::Sc(GpuRegister rt, GpuRegister base, int16_t imm9) {
299 DCHECK((-256 <= imm9) && (imm9 < 256));
300 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x26);
301}
302
303void Mips64Assembler::Scd(GpuRegister rt, GpuRegister base, int16_t imm9) {
304 DCHECK((-256 <= imm9) && (imm9 < 256));
305 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x27);
306}
307
308void Mips64Assembler::Ll(GpuRegister rt, GpuRegister base, int16_t imm9) {
309 DCHECK((-256 <= imm9) && (imm9 < 256));
310 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x36);
311}
312
313void Mips64Assembler::Lld(GpuRegister rt, GpuRegister base, int16_t imm9) {
314 DCHECK((-256 <= imm9) && (imm9 < 256));
315 EmitI(0x1f, base, rt, ((imm9 & 0x1FF) << 7) | 0x37);
316}
317
Alexey Frunze4dda3372015-06-01 18:31:49 -0700318void Mips64Assembler::Sll(GpuRegister rd, GpuRegister rt, int shamt) {
319 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x00);
320}
321
322void Mips64Assembler::Srl(GpuRegister rd, GpuRegister rt, int shamt) {
323 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x02);
324}
325
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700326void Mips64Assembler::Rotr(GpuRegister rd, GpuRegister rt, int shamt) {
327 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x02);
328}
329
Alexey Frunze4dda3372015-06-01 18:31:49 -0700330void Mips64Assembler::Sra(GpuRegister rd, GpuRegister rt, int shamt) {
331 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x03);
332}
333
334void Mips64Assembler::Sllv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800335 EmitR(0, rs, rt, rd, 0, 0x04);
336}
337
Chris Larsen9aebff22015-09-22 17:54:15 -0700338void Mips64Assembler::Rotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
339 EmitR(0, rs, rt, rd, 1, 0x06);
340}
341
Alexey Frunze4dda3372015-06-01 18:31:49 -0700342void Mips64Assembler::Srlv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800343 EmitR(0, rs, rt, rd, 0, 0x06);
344}
345
Alexey Frunze4dda3372015-06-01 18:31:49 -0700346void Mips64Assembler::Srav(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800347 EmitR(0, rs, rt, rd, 0, 0x07);
348}
349
Alexey Frunze4dda3372015-06-01 18:31:49 -0700350void Mips64Assembler::Dsll(GpuRegister rd, GpuRegister rt, int shamt) {
351 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x38);
352}
353
354void Mips64Assembler::Dsrl(GpuRegister rd, GpuRegister rt, int shamt) {
355 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3a);
356}
357
Chris Larsen9aebff22015-09-22 17:54:15 -0700358void Mips64Assembler::Drotr(GpuRegister rd, GpuRegister rt, int shamt) {
359 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x3a);
360}
361
Alexey Frunze4dda3372015-06-01 18:31:49 -0700362void Mips64Assembler::Dsra(GpuRegister rd, GpuRegister rt, int shamt) {
363 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3b);
364}
365
366void Mips64Assembler::Dsll32(GpuRegister rd, GpuRegister rt, int shamt) {
367 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3c);
368}
369
370void Mips64Assembler::Dsrl32(GpuRegister rd, GpuRegister rt, int shamt) {
371 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3e);
372}
373
Chris Larsen9aebff22015-09-22 17:54:15 -0700374void Mips64Assembler::Drotr32(GpuRegister rd, GpuRegister rt, int shamt) {
375 EmitR(0, static_cast<GpuRegister>(1), rt, rd, shamt, 0x3e);
376}
377
Alexey Frunze4dda3372015-06-01 18:31:49 -0700378void Mips64Assembler::Dsra32(GpuRegister rd, GpuRegister rt, int shamt) {
379 EmitR(0, static_cast<GpuRegister>(0), rt, rd, shamt, 0x3f);
380}
381
382void Mips64Assembler::Dsllv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
383 EmitR(0, rs, rt, rd, 0, 0x14);
384}
385
386void Mips64Assembler::Dsrlv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
387 EmitR(0, rs, rt, rd, 0, 0x16);
388}
389
Chris Larsen9aebff22015-09-22 17:54:15 -0700390void Mips64Assembler::Drotrv(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
391 EmitR(0, rs, rt, rd, 1, 0x16);
392}
393
Alexey Frunze4dda3372015-06-01 18:31:49 -0700394void Mips64Assembler::Dsrav(GpuRegister rd, GpuRegister rt, GpuRegister rs) {
395 EmitR(0, rs, rt, rd, 0, 0x17);
396}
397
Andreas Gampe57b34292015-01-14 15:45:59 -0800398void Mips64Assembler::Lb(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
399 EmitI(0x20, rs, rt, imm16);
400}
401
402void Mips64Assembler::Lh(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
403 EmitI(0x21, rs, rt, imm16);
404}
405
406void Mips64Assembler::Lw(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
407 EmitI(0x23, rs, rt, imm16);
408}
409
410void Mips64Assembler::Ld(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
411 EmitI(0x37, rs, rt, imm16);
412}
413
414void Mips64Assembler::Lbu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
415 EmitI(0x24, rs, rt, imm16);
416}
417
418void Mips64Assembler::Lhu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
419 EmitI(0x25, rs, rt, imm16);
420}
421
Douglas Leungd90957f2015-04-30 19:22:49 -0700422void Mips64Assembler::Lwu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
423 EmitI(0x27, rs, rt, imm16);
424}
425
Andreas Gampe57b34292015-01-14 15:45:59 -0800426void Mips64Assembler::Lui(GpuRegister rt, uint16_t imm16) {
427 EmitI(0xf, static_cast<GpuRegister>(0), rt, imm16);
428}
429
Alexey Frunze4dda3372015-06-01 18:31:49 -0700430void Mips64Assembler::Dahi(GpuRegister rs, uint16_t imm16) {
431 EmitI(1, rs, static_cast<GpuRegister>(6), imm16);
432}
433
434void Mips64Assembler::Dati(GpuRegister rs, uint16_t imm16) {
435 EmitI(1, rs, static_cast<GpuRegister>(0x1e), imm16);
436}
437
438void Mips64Assembler::Sync(uint32_t stype) {
439 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
440 static_cast<GpuRegister>(0), stype & 0x1f, 0xf);
441}
442
Andreas Gampe57b34292015-01-14 15:45:59 -0800443void Mips64Assembler::Mfhi(GpuRegister rd) {
444 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0), rd, 0, 0x10);
445}
446
447void Mips64Assembler::Mflo(GpuRegister rd) {
448 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0), rd, 0, 0x12);
449}
450
451void Mips64Assembler::Sb(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
452 EmitI(0x28, rs, rt, imm16);
453}
454
455void Mips64Assembler::Sh(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
456 EmitI(0x29, rs, rt, imm16);
457}
458
459void Mips64Assembler::Sw(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
460 EmitI(0x2b, rs, rt, imm16);
461}
462
463void Mips64Assembler::Sd(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
464 EmitI(0x3f, rs, rt, imm16);
465}
466
467void Mips64Assembler::Slt(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
468 EmitR(0, rs, rt, rd, 0, 0x2a);
469}
470
471void Mips64Assembler::Sltu(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
472 EmitR(0, rs, rt, rd, 0, 0x2b);
473}
474
475void Mips64Assembler::Slti(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
476 EmitI(0xa, rs, rt, imm16);
477}
478
479void Mips64Assembler::Sltiu(GpuRegister rt, GpuRegister rs, uint16_t imm16) {
480 EmitI(0xb, rs, rt, imm16);
481}
482
Alexey Frunze4dda3372015-06-01 18:31:49 -0700483void Mips64Assembler::Beq(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800484 EmitI(0x4, rs, rt, imm16);
485 Nop();
486}
487
Alexey Frunze4dda3372015-06-01 18:31:49 -0700488void Mips64Assembler::Bne(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
Andreas Gampe57b34292015-01-14 15:45:59 -0800489 EmitI(0x5, rs, rt, imm16);
490 Nop();
491}
492
Alexey Frunze4dda3372015-06-01 18:31:49 -0700493void Mips64Assembler::J(uint32_t addr26) {
494 EmitJ(0x2, addr26);
Andreas Gampe57b34292015-01-14 15:45:59 -0800495 Nop();
496}
497
Alexey Frunze4dda3372015-06-01 18:31:49 -0700498void Mips64Assembler::Jal(uint32_t addr26) {
499 EmitJ(0x3, addr26);
Andreas Gampe57b34292015-01-14 15:45:59 -0800500 Nop();
501}
502
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700503void Mips64Assembler::Seleqz(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
504 EmitR(0, rs, rt, rd, 0, 0x35);
505}
506
507void Mips64Assembler::Selnez(GpuRegister rd, GpuRegister rs, GpuRegister rt) {
508 EmitR(0, rs, rt, rd, 0, 0x37);
509}
510
511void Mips64Assembler::Clz(GpuRegister rd, GpuRegister rs) {
512 EmitRsd(0, rs, rd, 0x01, 0x10);
513}
514
515void Mips64Assembler::Clo(GpuRegister rd, GpuRegister rs) {
516 EmitRsd(0, rs, rd, 0x01, 0x11);
517}
518
519void Mips64Assembler::Dclz(GpuRegister rd, GpuRegister rs) {
520 EmitRsd(0, rs, rd, 0x01, 0x12);
521}
522
523void Mips64Assembler::Dclo(GpuRegister rd, GpuRegister rs) {
524 EmitRsd(0, rs, rd, 0x01, 0x13);
525}
526
Alexey Frunze4dda3372015-06-01 18:31:49 -0700527void Mips64Assembler::Jalr(GpuRegister rd, GpuRegister rs) {
528 EmitR(0, rs, static_cast<GpuRegister>(0), rd, 0, 0x09);
Andreas Gampe57b34292015-01-14 15:45:59 -0800529 Nop();
530}
531
532void Mips64Assembler::Jalr(GpuRegister rs) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700533 Jalr(RA, rs);
534}
535
536void Mips64Assembler::Jr(GpuRegister rs) {
537 Jalr(ZERO, rs);
538}
539
540void Mips64Assembler::Auipc(GpuRegister rs, uint16_t imm16) {
541 EmitI(0x3B, rs, static_cast<GpuRegister>(0x1E), imm16);
542}
543
544void Mips64Assembler::Jic(GpuRegister rt, uint16_t imm16) {
545 EmitI(0x36, static_cast<GpuRegister>(0), rt, imm16);
546}
547
548void Mips64Assembler::Jialc(GpuRegister rt, uint16_t imm16) {
549 EmitI(0x3E, static_cast<GpuRegister>(0), rt, imm16);
550}
551
552void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
553 CHECK_NE(rs, ZERO);
554 CHECK_NE(rt, ZERO);
555 CHECK_NE(rs, rt);
556 EmitI(0x17, rs, rt, imm16);
557}
558
559void Mips64Assembler::Bltzc(GpuRegister rt, uint16_t imm16) {
560 CHECK_NE(rt, ZERO);
561 EmitI(0x17, rt, rt, imm16);
562}
563
564void Mips64Assembler::Bgtzc(GpuRegister rt, uint16_t imm16) {
565 CHECK_NE(rt, ZERO);
566 EmitI(0x17, static_cast<GpuRegister>(0), rt, imm16);
567}
568
569void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
570 CHECK_NE(rs, ZERO);
571 CHECK_NE(rt, ZERO);
572 CHECK_NE(rs, rt);
573 EmitI(0x16, rs, rt, imm16);
574}
575
576void Mips64Assembler::Bgezc(GpuRegister rt, uint16_t imm16) {
577 CHECK_NE(rt, ZERO);
578 EmitI(0x16, rt, rt, imm16);
579}
580
581void Mips64Assembler::Blezc(GpuRegister rt, uint16_t imm16) {
582 CHECK_NE(rt, ZERO);
583 EmitI(0x16, static_cast<GpuRegister>(0), rt, imm16);
584}
585
586void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
587 CHECK_NE(rs, ZERO);
588 CHECK_NE(rt, ZERO);
589 CHECK_NE(rs, rt);
590 EmitI(0x7, rs, rt, imm16);
591}
592
593void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
594 CHECK_NE(rs, ZERO);
595 CHECK_NE(rt, ZERO);
596 CHECK_NE(rs, rt);
597 EmitI(0x6, rs, rt, imm16);
598}
599
600void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
601 CHECK_NE(rs, ZERO);
602 CHECK_NE(rt, ZERO);
603 CHECK_NE(rs, rt);
604 EmitI(0x8, (rs < rt) ? rs : rt, (rs < rt) ? rt : rs, imm16);
605}
606
607void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, uint16_t imm16) {
608 CHECK_NE(rs, ZERO);
609 CHECK_NE(rt, ZERO);
610 CHECK_NE(rs, rt);
611 EmitI(0x18, (rs < rt) ? rs : rt, (rs < rt) ? rt : rs, imm16);
612}
613
614void Mips64Assembler::Beqzc(GpuRegister rs, uint32_t imm21) {
615 CHECK_NE(rs, ZERO);
616 EmitI21(0x36, rs, imm21);
617}
618
619void Mips64Assembler::Bnezc(GpuRegister rs, uint32_t imm21) {
620 CHECK_NE(rs, ZERO);
621 EmitI21(0x3E, rs, imm21);
Andreas Gampe57b34292015-01-14 15:45:59 -0800622}
623
624void Mips64Assembler::AddS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
625 EmitFR(0x11, 0x10, ft, fs, fd, 0x0);
626}
627
628void Mips64Assembler::SubS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
629 EmitFR(0x11, 0x10, ft, fs, fd, 0x1);
630}
631
632void Mips64Assembler::MulS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
633 EmitFR(0x11, 0x10, ft, fs, fd, 0x2);
634}
635
636void Mips64Assembler::DivS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
637 EmitFR(0x11, 0x10, ft, fs, fd, 0x3);
638}
639
640void Mips64Assembler::AddD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700641 EmitFR(0x11, 0x11, ft, fs, fd, 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -0800642}
643
644void Mips64Assembler::SubD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700645 EmitFR(0x11, 0x11, ft, fs, fd, 0x1);
Andreas Gampe57b34292015-01-14 15:45:59 -0800646}
647
648void Mips64Assembler::MulD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700649 EmitFR(0x11, 0x11, ft, fs, fd, 0x2);
Andreas Gampe57b34292015-01-14 15:45:59 -0800650}
651
652void Mips64Assembler::DivD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700653 EmitFR(0x11, 0x11, ft, fs, fd, 0x3);
Andreas Gampe57b34292015-01-14 15:45:59 -0800654}
655
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700656void Mips64Assembler::SqrtS(FpuRegister fd, FpuRegister fs) {
657 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x4);
658}
659
660void Mips64Assembler::SqrtD(FpuRegister fd, FpuRegister fs) {
661 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x4);
662}
663
664void Mips64Assembler::AbsS(FpuRegister fd, FpuRegister fs) {
665 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x5);
666}
667
668void Mips64Assembler::AbsD(FpuRegister fd, FpuRegister fs) {
669 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x5);
670}
671
Andreas Gampe57b34292015-01-14 15:45:59 -0800672void Mips64Assembler::MovS(FpuRegister fd, FpuRegister fs) {
673 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x6);
674}
675
676void Mips64Assembler::MovD(FpuRegister fd, FpuRegister fs) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700677 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x6);
678}
679
680void Mips64Assembler::NegS(FpuRegister fd, FpuRegister fs) {
681 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x7);
682}
683
684void Mips64Assembler::NegD(FpuRegister fd, FpuRegister fs) {
685 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x7);
686}
687
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700688void Mips64Assembler::RoundLS(FpuRegister fd, FpuRegister fs) {
689 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x8);
690}
691
692void Mips64Assembler::RoundLD(FpuRegister fd, FpuRegister fs) {
693 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x8);
694}
695
696void Mips64Assembler::RoundWS(FpuRegister fd, FpuRegister fs) {
697 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xc);
698}
699
700void Mips64Assembler::RoundWD(FpuRegister fd, FpuRegister fs) {
701 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xc);
702}
703
704void Mips64Assembler::CeilLS(FpuRegister fd, FpuRegister fs) {
705 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xa);
706}
707
708void Mips64Assembler::CeilLD(FpuRegister fd, FpuRegister fs) {
709 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xa);
710}
711
712void Mips64Assembler::CeilWS(FpuRegister fd, FpuRegister fs) {
713 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xe);
714}
715
716void Mips64Assembler::CeilWD(FpuRegister fd, FpuRegister fs) {
717 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xe);
718}
719
720void Mips64Assembler::FloorLS(FpuRegister fd, FpuRegister fs) {
721 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xb);
722}
723
724void Mips64Assembler::FloorLD(FpuRegister fd, FpuRegister fs) {
725 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xb);
726}
727
728void Mips64Assembler::FloorWS(FpuRegister fd, FpuRegister fs) {
729 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0xf);
730}
731
732void Mips64Assembler::FloorWD(FpuRegister fd, FpuRegister fs) {
733 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0xf);
734}
735
736void Mips64Assembler::SelS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
737 EmitFR(0x11, 0x10, ft, fs, fd, 0x10);
738}
739
740void Mips64Assembler::SelD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
741 EmitFR(0x11, 0x11, ft, fs, fd, 0x10);
742}
743
744void Mips64Assembler::RintS(FpuRegister fd, FpuRegister fs) {
745 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1a);
746}
747
748void Mips64Assembler::RintD(FpuRegister fd, FpuRegister fs) {
749 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1a);
750}
751
752void Mips64Assembler::ClassS(FpuRegister fd, FpuRegister fs) {
753 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x1b);
754}
755
756void Mips64Assembler::ClassD(FpuRegister fd, FpuRegister fs) {
757 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x1b);
758}
759
760void Mips64Assembler::MinS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
761 EmitFR(0x11, 0x10, ft, fs, fd, 0x1c);
762}
763
764void Mips64Assembler::MinD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
765 EmitFR(0x11, 0x11, ft, fs, fd, 0x1c);
766}
767
768void Mips64Assembler::MaxS(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
769 EmitFR(0x11, 0x10, ft, fs, fd, 0x1e);
770}
771
772void Mips64Assembler::MaxD(FpuRegister fd, FpuRegister fs, FpuRegister ft) {
773 EmitFR(0x11, 0x11, ft, fs, fd, 0x1e);
774}
775
Alexey Frunze4dda3372015-06-01 18:31:49 -0700776void Mips64Assembler::Cvtsw(FpuRegister fd, FpuRegister fs) {
777 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x20);
778}
779
780void Mips64Assembler::Cvtdw(FpuRegister fd, FpuRegister fs) {
781 EmitFR(0x11, 0x14, static_cast<FpuRegister>(0), fs, fd, 0x21);
782}
783
784void Mips64Assembler::Cvtsd(FpuRegister fd, FpuRegister fs) {
785 EmitFR(0x11, 0x11, static_cast<FpuRegister>(0), fs, fd, 0x20);
786}
787
788void Mips64Assembler::Cvtds(FpuRegister fd, FpuRegister fs) {
789 EmitFR(0x11, 0x10, static_cast<FpuRegister>(0), fs, fd, 0x21);
Andreas Gampe57b34292015-01-14 15:45:59 -0800790}
791
Chris Larsen51417632015-10-02 13:24:25 -0700792void Mips64Assembler::Cvtsl(FpuRegister fd, FpuRegister fs) {
793 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x20);
794}
795
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700796void Mips64Assembler::Cvtdl(FpuRegister fd, FpuRegister fs) {
797 EmitFR(0x11, 0x15, static_cast<FpuRegister>(0), fs, fd, 0x21);
798}
799
Andreas Gampe57b34292015-01-14 15:45:59 -0800800void Mips64Assembler::Mfc1(GpuRegister rt, FpuRegister fs) {
801 EmitFR(0x11, 0x00, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
802}
803
Alexey Frunze4dda3372015-06-01 18:31:49 -0700804void Mips64Assembler::Mtc1(GpuRegister rt, FpuRegister fs) {
805 EmitFR(0x11, 0x04, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
806}
807
808void Mips64Assembler::Dmfc1(GpuRegister rt, FpuRegister fs) {
809 EmitFR(0x11, 0x01, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
810}
811
812void Mips64Assembler::Dmtc1(GpuRegister rt, FpuRegister fs) {
813 EmitFR(0x11, 0x05, static_cast<FpuRegister>(rt), fs, static_cast<FpuRegister>(0), 0x0);
Andreas Gampe57b34292015-01-14 15:45:59 -0800814}
815
816void Mips64Assembler::Lwc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
817 EmitI(0x31, rs, static_cast<GpuRegister>(ft), imm16);
818}
819
820void Mips64Assembler::Ldc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
821 EmitI(0x35, rs, static_cast<GpuRegister>(ft), imm16);
822}
823
824void Mips64Assembler::Swc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
825 EmitI(0x39, rs, static_cast<GpuRegister>(ft), imm16);
826}
827
828void Mips64Assembler::Sdc1(FpuRegister ft, GpuRegister rs, uint16_t imm16) {
829 EmitI(0x3d, rs, static_cast<GpuRegister>(ft), imm16);
830}
831
832void Mips64Assembler::Break() {
833 EmitR(0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
834 static_cast<GpuRegister>(0), 0, 0xD);
835}
836
837void Mips64Assembler::Nop() {
838 EmitR(0x0, static_cast<GpuRegister>(0), static_cast<GpuRegister>(0),
839 static_cast<GpuRegister>(0), 0, 0x0);
840}
841
Alexey Frunze4dda3372015-06-01 18:31:49 -0700842void Mips64Assembler::Move(GpuRegister rd, GpuRegister rs) {
843 Or(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -0800844}
845
Alexey Frunze4dda3372015-06-01 18:31:49 -0700846void Mips64Assembler::Clear(GpuRegister rd) {
847 Move(rd, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -0800848}
849
Alexey Frunze4dda3372015-06-01 18:31:49 -0700850void Mips64Assembler::Not(GpuRegister rd, GpuRegister rs) {
851 Nor(rd, rs, ZERO);
Andreas Gampe57b34292015-01-14 15:45:59 -0800852}
853
Alexey Frunze4dda3372015-06-01 18:31:49 -0700854void Mips64Assembler::LoadConst32(GpuRegister rd, int32_t value) {
855 if (IsUint<16>(value)) {
856 // Use OR with (unsigned) immediate to encode 16b unsigned int.
857 Ori(rd, ZERO, value);
858 } else if (IsInt<16>(value)) {
859 // Use ADD with (signed) immediate to encode 16b signed int.
860 Addiu(rd, ZERO, value);
861 } else {
862 Lui(rd, value >> 16);
863 if (value & 0xFFFF)
864 Ori(rd, rd, value);
865 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800866}
867
Alexey Frunze4dda3372015-06-01 18:31:49 -0700868void Mips64Assembler::LoadConst64(GpuRegister rd, int64_t value) {
869 int bit31 = (value & UINT64_C(0x80000000)) != 0;
870
871 // Loads with 1 instruction.
872 if (IsUint<16>(value)) {
873 Ori(rd, ZERO, value);
874 } else if (IsInt<16>(value)) {
875 Daddiu(rd, ZERO, value);
876 } else if ((value & 0xFFFF) == 0 && IsInt<16>(value >> 16)) {
877 Lui(rd, value >> 16);
878 } else if (IsInt<32>(value)) {
879 // Loads with 2 instructions.
880 Lui(rd, value >> 16);
881 Ori(rd, rd, value);
882 } else if ((value & 0xFFFF0000) == 0 && IsInt<16>(value >> 32)) {
883 Ori(rd, ZERO, value);
884 Dahi(rd, value >> 32);
885 } else if ((value & UINT64_C(0xFFFFFFFF0000)) == 0) {
886 Ori(rd, ZERO, value);
887 Dati(rd, value >> 48);
888 } else if ((value & 0xFFFF) == 0 &&
889 (-32768 - bit31) <= (value >> 32) && (value >> 32) <= (32767 - bit31)) {
890 Lui(rd, value >> 16);
891 Dahi(rd, (value >> 32) + bit31);
892 } else if ((value & 0xFFFF) == 0 && ((value >> 31) & 0x1FFFF) == ((0x20000 - bit31) & 0x1FFFF)) {
893 Lui(rd, value >> 16);
894 Dati(rd, (value >> 48) + bit31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700895 } else if (IsPowerOfTwo(value + UINT64_C(1))) {
896 int shift_cnt = 64 - CTZ(value + UINT64_C(1));
897 Daddiu(rd, ZERO, -1);
898 if (shift_cnt < 32) {
899 Dsrl(rd, rd, shift_cnt);
900 } else {
901 Dsrl32(rd, rd, shift_cnt & 31);
902 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700903 } else {
904 int shift_cnt = CTZ(value);
905 int64_t tmp = value >> shift_cnt;
906 if (IsUint<16>(tmp)) {
907 Ori(rd, ZERO, tmp);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700908 if (shift_cnt < 32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700909 Dsll(rd, rd, shift_cnt);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700910 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700911 Dsll32(rd, rd, shift_cnt & 31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700912 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700913 } else if (IsInt<16>(tmp)) {
914 Daddiu(rd, ZERO, tmp);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700915 if (shift_cnt < 32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700916 Dsll(rd, rd, shift_cnt);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700917 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700918 Dsll32(rd, rd, shift_cnt & 31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700919 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700920 } else if (IsInt<32>(tmp)) {
921 // Loads with 3 instructions.
922 Lui(rd, tmp >> 16);
923 Ori(rd, rd, tmp);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700924 if (shift_cnt < 32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700925 Dsll(rd, rd, shift_cnt);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700926 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700927 Dsll32(rd, rd, shift_cnt & 31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700928 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700929 } else {
930 shift_cnt = 16 + CTZ(value >> 16);
931 tmp = value >> shift_cnt;
932 if (IsUint<16>(tmp)) {
933 Ori(rd, ZERO, tmp);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700934 if (shift_cnt < 32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700935 Dsll(rd, rd, shift_cnt);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700936 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700937 Dsll32(rd, rd, shift_cnt & 31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700938 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700939 Ori(rd, rd, value);
940 } else if (IsInt<16>(tmp)) {
941 Daddiu(rd, ZERO, tmp);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700942 if (shift_cnt < 32) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700943 Dsll(rd, rd, shift_cnt);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700944 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700945 Dsll32(rd, rd, shift_cnt & 31);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700946 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700947 Ori(rd, rd, value);
948 } else {
949 // Loads with 3-4 instructions.
950 uint64_t tmp2 = value;
951 bool used_lui = false;
952 if (((tmp2 >> 16) & 0xFFFF) != 0 || (tmp2 & 0xFFFFFFFF) == 0) {
953 Lui(rd, tmp2 >> 16);
954 used_lui = true;
955 }
956 if ((tmp2 & 0xFFFF) != 0) {
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700957 if (used_lui) {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700958 Ori(rd, rd, tmp2);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700959 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -0700960 Ori(rd, ZERO, tmp2);
Alexey Frunze5c75ffa2015-09-24 14:41:59 -0700961 }
Alexey Frunze4dda3372015-06-01 18:31:49 -0700962 }
963 if (bit31) {
964 tmp2 += UINT64_C(0x100000000);
965 }
966 if (((tmp2 >> 32) & 0xFFFF) != 0) {
967 Dahi(rd, tmp2 >> 32);
968 }
969 if (tmp2 & UINT64_C(0x800000000000)) {
970 tmp2 += UINT64_C(0x1000000000000);
971 }
972 if ((tmp2 >> 48) != 0) {
973 Dati(rd, tmp2 >> 48);
974 }
975 }
976 }
977 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800978}
979
Alexey Frunze4dda3372015-06-01 18:31:49 -0700980void Mips64Assembler::Addiu32(GpuRegister rt, GpuRegister rs, int32_t value, GpuRegister rtmp) {
981 if (IsInt<16>(value)) {
982 Addiu(rt, rs, value);
983 } else {
984 LoadConst32(rtmp, value);
985 Addu(rt, rs, rtmp);
986 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800987}
988
Alexey Frunze4dda3372015-06-01 18:31:49 -0700989void Mips64Assembler::Daddiu64(GpuRegister rt, GpuRegister rs, int64_t value, GpuRegister rtmp) {
990 if (IsInt<16>(value)) {
991 Daddiu(rt, rs, value);
992 } else {
993 LoadConst64(rtmp, value);
994 Daddu(rt, rs, rtmp);
995 }
Andreas Gampe57b34292015-01-14 15:45:59 -0800996}
997
Alexey Frunze4dda3372015-06-01 18:31:49 -0700998//
999// MIPS64R6 branches
1000//
1001//
1002// Unconditional (pc + 32-bit signed offset):
1003//
1004// auipc at, ofs_high
1005// jic at, ofs_low
1006// // no delay/forbidden slot
1007//
1008//
1009// Conditional (pc + 32-bit signed offset):
1010//
1011// b<cond>c reg, +2 // skip next 2 instructions
1012// auipc at, ofs_high
1013// jic at, ofs_low
1014// // no delay/forbidden slot
1015//
1016//
1017// Unconditional (pc + 32-bit signed offset) and link:
1018//
1019// auipc reg, ofs_high
1020// daddiu reg, ofs_low
1021// jialc reg, 0
1022// // no delay/forbidden slot
1023//
1024//
1025// TODO: use shorter instruction sequences whenever possible.
1026//
1027
1028void Mips64Assembler::Bind(Label* label) {
1029 CHECK(!label->IsBound());
1030 int32_t bound_pc = buffer_.Size();
1031
1032 // Walk the list of the branches (auipc + jic pairs) referring to and preceding this label.
1033 // Embed the previously unknown pc-relative addresses in them.
1034 while (label->IsLinked()) {
1035 int32_t position = label->Position();
1036 // Extract the branch (instruction pair)
1037 uint32_t auipc = buffer_.Load<uint32_t>(position);
1038 uint32_t jic = buffer_.Load<uint32_t>(position + 4); // actually, jic or daddiu
1039
1040 // Extract the location of the previous pair in the list (walking the list backwards;
1041 // the previous pair location was stored in the immediate operands of the instructions)
1042 int32_t prev = (auipc << 16) | (jic & 0xFFFF);
1043
1044 // Get the pc-relative address
1045 uint32_t offset = bound_pc - position;
1046 offset += (offset & 0x8000) << 1; // account for sign extension in jic/daddiu
1047
1048 // Embed it in the two instructions
1049 auipc = (auipc & 0xFFFF0000) | (offset >> 16);
1050 jic = (jic & 0xFFFF0000) | (offset & 0xFFFF);
1051
1052 // Save the adjusted instructions
1053 buffer_.Store<uint32_t>(position, auipc);
1054 buffer_.Store<uint32_t>(position + 4, jic);
1055
1056 // On to the previous branch in the list...
1057 label->position_ = prev;
1058 }
1059
1060 // Now make the label object contain its own location
1061 // (it will be used by the branches referring to and following this label)
1062 label->BindTo(bound_pc);
1063}
1064
1065void Mips64Assembler::B(Label* label) {
1066 if (label->IsBound()) {
1067 // Branch backwards (to a preceding label), distance is known
1068 uint32_t offset = label->Position() - buffer_.Size();
1069 CHECK_LE(static_cast<int32_t>(offset), 0);
1070 offset += (offset & 0x8000) << 1; // account for sign extension in jic
1071 Auipc(AT, offset >> 16);
1072 Jic(AT, offset);
1073 } else {
1074 // Branch forward (to a following label), distance is unknown
1075 int32_t position = buffer_.Size();
1076 // The first branch forward will have 0 in its pc-relative address (copied from label's
1077 // position). It will be the terminator of the list of forward-reaching branches.
1078 uint32_t prev = label->position_;
1079 Auipc(AT, prev >> 16);
1080 Jic(AT, prev);
1081 // Now make the link object point to the location of this branch
1082 // (this forms a linked list of branches preceding this label)
1083 label->LinkTo(position);
1084 }
1085}
1086
1087void Mips64Assembler::Jalr(Label* label, GpuRegister indirect_reg) {
1088 if (label->IsBound()) {
1089 // Branch backwards (to a preceding label), distance is known
1090 uint32_t offset = label->Position() - buffer_.Size();
1091 CHECK_LE(static_cast<int32_t>(offset), 0);
1092 offset += (offset & 0x8000) << 1; // account for sign extension in daddiu
1093 Auipc(indirect_reg, offset >> 16);
1094 Daddiu(indirect_reg, indirect_reg, offset);
1095 Jialc(indirect_reg, 0);
1096 } else {
1097 // Branch forward (to a following label), distance is unknown
1098 int32_t position = buffer_.Size();
1099 // The first branch forward will have 0 in its pc-relative address (copied from label's
1100 // position). It will be the terminator of the list of forward-reaching branches.
1101 uint32_t prev = label->position_;
1102 Auipc(indirect_reg, prev >> 16);
1103 Daddiu(indirect_reg, indirect_reg, prev);
1104 Jialc(indirect_reg, 0);
1105 // Now make the link object point to the location of this branch
1106 // (this forms a linked list of branches preceding this label)
1107 label->LinkTo(position);
1108 }
1109}
1110
1111void Mips64Assembler::Bltc(GpuRegister rs, GpuRegister rt, Label* label) {
1112 Bgec(rs, rt, 2);
1113 B(label);
1114}
1115
1116void Mips64Assembler::Bltzc(GpuRegister rt, Label* label) {
1117 Bgezc(rt, 2);
1118 B(label);
1119}
1120
1121void Mips64Assembler::Bgtzc(GpuRegister rt, Label* label) {
1122 Blezc(rt, 2);
1123 B(label);
1124}
1125
1126void Mips64Assembler::Bgec(GpuRegister rs, GpuRegister rt, Label* label) {
1127 Bltc(rs, rt, 2);
1128 B(label);
1129}
1130
1131void Mips64Assembler::Bgezc(GpuRegister rt, Label* label) {
1132 Bltzc(rt, 2);
1133 B(label);
1134}
1135
1136void Mips64Assembler::Blezc(GpuRegister rt, Label* label) {
1137 Bgtzc(rt, 2);
1138 B(label);
1139}
1140
1141void Mips64Assembler::Bltuc(GpuRegister rs, GpuRegister rt, Label* label) {
1142 Bgeuc(rs, rt, 2);
1143 B(label);
1144}
1145
1146void Mips64Assembler::Bgeuc(GpuRegister rs, GpuRegister rt, Label* label) {
1147 Bltuc(rs, rt, 2);
1148 B(label);
1149}
1150
1151void Mips64Assembler::Beqc(GpuRegister rs, GpuRegister rt, Label* label) {
1152 Bnec(rs, rt, 2);
1153 B(label);
1154}
1155
1156void Mips64Assembler::Bnec(GpuRegister rs, GpuRegister rt, Label* label) {
1157 Beqc(rs, rt, 2);
1158 B(label);
1159}
1160
1161void Mips64Assembler::Beqzc(GpuRegister rs, Label* label) {
1162 Bnezc(rs, 2);
1163 B(label);
1164}
1165
1166void Mips64Assembler::Bnezc(GpuRegister rs, Label* label) {
1167 Beqzc(rs, 2);
1168 B(label);
Andreas Gampe57b34292015-01-14 15:45:59 -08001169}
1170
1171void Mips64Assembler::LoadFromOffset(LoadOperandType type, GpuRegister reg, GpuRegister base,
1172 int32_t offset) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001173 if (!IsInt<16>(offset)) {
1174 LoadConst32(AT, offset);
1175 Daddu(AT, AT, base);
1176 base = AT;
1177 offset = 0;
1178 }
1179
Andreas Gampe57b34292015-01-14 15:45:59 -08001180 switch (type) {
1181 case kLoadSignedByte:
1182 Lb(reg, base, offset);
1183 break;
1184 case kLoadUnsignedByte:
1185 Lbu(reg, base, offset);
1186 break;
1187 case kLoadSignedHalfword:
1188 Lh(reg, base, offset);
1189 break;
1190 case kLoadUnsignedHalfword:
1191 Lhu(reg, base, offset);
1192 break;
1193 case kLoadWord:
1194 Lw(reg, base, offset);
1195 break;
Douglas Leungd90957f2015-04-30 19:22:49 -07001196 case kLoadUnsignedWord:
1197 Lwu(reg, base, offset);
1198 break;
Andreas Gampe57b34292015-01-14 15:45:59 -08001199 case kLoadDoubleword:
Andreas Gampe57b34292015-01-14 15:45:59 -08001200 Ld(reg, base, offset);
1201 break;
Andreas Gampe57b34292015-01-14 15:45:59 -08001202 }
1203}
1204
1205void Mips64Assembler::LoadFpuFromOffset(LoadOperandType type, FpuRegister reg, GpuRegister base,
1206 int32_t offset) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001207 if (!IsInt<16>(offset)) {
1208 LoadConst32(AT, offset);
1209 Daddu(AT, AT, base);
1210 base = AT;
1211 offset = 0;
1212 }
1213
Andreas Gampe57b34292015-01-14 15:45:59 -08001214 switch (type) {
1215 case kLoadWord:
1216 Lwc1(reg, base, offset);
1217 break;
1218 case kLoadDoubleword:
Andreas Gampe57b34292015-01-14 15:45:59 -08001219 Ldc1(reg, base, offset);
1220 break;
1221 default:
1222 LOG(FATAL) << "UNREACHABLE";
1223 }
1224}
1225
1226void Mips64Assembler::EmitLoad(ManagedRegister m_dst, GpuRegister src_register, int32_t src_offset,
1227 size_t size) {
1228 Mips64ManagedRegister dst = m_dst.AsMips64();
1229 if (dst.IsNoRegister()) {
1230 CHECK_EQ(0u, size) << dst;
1231 } else if (dst.IsGpuRegister()) {
1232 if (size == 4) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001233 LoadFromOffset(kLoadWord, dst.AsGpuRegister(), src_register, src_offset);
1234 } else if (size == 8) {
1235 CHECK_EQ(8u, size) << dst;
1236 LoadFromOffset(kLoadDoubleword, dst.AsGpuRegister(), src_register, src_offset);
1237 } else {
1238 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
1239 }
1240 } else if (dst.IsFpuRegister()) {
1241 if (size == 4) {
1242 CHECK_EQ(4u, size) << dst;
1243 LoadFpuFromOffset(kLoadWord, dst.AsFpuRegister(), src_register, src_offset);
1244 } else if (size == 8) {
1245 CHECK_EQ(8u, size) << dst;
1246 LoadFpuFromOffset(kLoadDoubleword, dst.AsFpuRegister(), src_register, src_offset);
1247 } else {
1248 UNIMPLEMENTED(FATAL) << "We only support Load() of size 4 and 8";
1249 }
1250 }
1251}
1252
1253void Mips64Assembler::StoreToOffset(StoreOperandType type, GpuRegister reg, GpuRegister base,
1254 int32_t offset) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001255 if (!IsInt<16>(offset)) {
1256 LoadConst32(AT, offset);
1257 Daddu(AT, AT, base);
1258 base = AT;
1259 offset = 0;
1260 }
1261
Andreas Gampe57b34292015-01-14 15:45:59 -08001262 switch (type) {
1263 case kStoreByte:
1264 Sb(reg, base, offset);
1265 break;
1266 case kStoreHalfword:
1267 Sh(reg, base, offset);
1268 break;
1269 case kStoreWord:
1270 Sw(reg, base, offset);
1271 break;
1272 case kStoreDoubleword:
Andreas Gampe57b34292015-01-14 15:45:59 -08001273 Sd(reg, base, offset);
1274 break;
1275 default:
1276 LOG(FATAL) << "UNREACHABLE";
1277 }
1278}
1279
1280void Mips64Assembler::StoreFpuToOffset(StoreOperandType type, FpuRegister reg, GpuRegister base,
1281 int32_t offset) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001282 if (!IsInt<16>(offset)) {
1283 LoadConst32(AT, offset);
1284 Daddu(AT, AT, base);
1285 base = AT;
1286 offset = 0;
1287 }
1288
Andreas Gampe57b34292015-01-14 15:45:59 -08001289 switch (type) {
1290 case kStoreWord:
1291 Swc1(reg, base, offset);
1292 break;
1293 case kStoreDoubleword:
1294 Sdc1(reg, base, offset);
1295 break;
1296 default:
1297 LOG(FATAL) << "UNREACHABLE";
1298 }
1299}
1300
David Srbeckydd973932015-04-07 20:29:48 +01001301static dwarf::Reg DWARFReg(GpuRegister reg) {
1302 return dwarf::Reg::Mips64Core(static_cast<int>(reg));
1303}
1304
Andreas Gampe57b34292015-01-14 15:45:59 -08001305constexpr size_t kFramePointerSize = 8;
1306
1307void Mips64Assembler::BuildFrame(size_t frame_size, ManagedRegister method_reg,
1308 const std::vector<ManagedRegister>& callee_save_regs,
1309 const ManagedRegisterEntrySpills& entry_spills) {
1310 CHECK_ALIGNED(frame_size, kStackAlignment);
1311
1312 // Increase frame to required size.
1313 IncreaseFrameSize(frame_size);
1314
1315 // Push callee saves and return address
1316 int stack_offset = frame_size - kFramePointerSize;
1317 StoreToOffset(kStoreDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01001318 cfi_.RelOffset(DWARFReg(RA), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08001319 for (int i = callee_save_regs.size() - 1; i >= 0; --i) {
1320 stack_offset -= kFramePointerSize;
1321 GpuRegister reg = callee_save_regs.at(i).AsMips64().AsGpuRegister();
1322 StoreToOffset(kStoreDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01001323 cfi_.RelOffset(DWARFReg(reg), stack_offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08001324 }
1325
1326 // Write out Method*.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001327 StoreToOffset(kStoreDoubleword, method_reg.AsMips64().AsGpuRegister(), SP, 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08001328
1329 // Write out entry spills.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001330 int32_t offset = frame_size + kFramePointerSize;
Andreas Gampe57b34292015-01-14 15:45:59 -08001331 for (size_t i = 0; i < entry_spills.size(); ++i) {
1332 Mips64ManagedRegister reg = entry_spills.at(i).AsMips64();
1333 ManagedRegisterSpill spill = entry_spills.at(i);
1334 int32_t size = spill.getSize();
1335 if (reg.IsNoRegister()) {
1336 // only increment stack offset.
1337 offset += size;
1338 } else if (reg.IsFpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001339 StoreFpuToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
1340 reg.AsFpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08001341 offset += size;
1342 } else if (reg.IsGpuRegister()) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001343 StoreToOffset((size == 4) ? kStoreWord : kStoreDoubleword,
1344 reg.AsGpuRegister(), SP, offset);
Andreas Gampe57b34292015-01-14 15:45:59 -08001345 offset += size;
1346 }
1347 }
1348}
1349
1350void Mips64Assembler::RemoveFrame(size_t frame_size,
1351 const std::vector<ManagedRegister>& callee_save_regs) {
1352 CHECK_ALIGNED(frame_size, kStackAlignment);
David Srbeckydd973932015-04-07 20:29:48 +01001353 cfi_.RememberState();
Andreas Gampe57b34292015-01-14 15:45:59 -08001354
1355 // Pop callee saves and return address
1356 int stack_offset = frame_size - (callee_save_regs.size() * kFramePointerSize) - kFramePointerSize;
1357 for (size_t i = 0; i < callee_save_regs.size(); ++i) {
1358 GpuRegister reg = callee_save_regs.at(i).AsMips64().AsGpuRegister();
1359 LoadFromOffset(kLoadDoubleword, reg, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01001360 cfi_.Restore(DWARFReg(reg));
Andreas Gampe57b34292015-01-14 15:45:59 -08001361 stack_offset += kFramePointerSize;
1362 }
1363 LoadFromOffset(kLoadDoubleword, RA, SP, stack_offset);
David Srbeckydd973932015-04-07 20:29:48 +01001364 cfi_.Restore(DWARFReg(RA));
Andreas Gampe57b34292015-01-14 15:45:59 -08001365
1366 // Decrease frame to required size.
1367 DecreaseFrameSize(frame_size);
1368
1369 // Then jump to the return address.
1370 Jr(RA);
David Srbeckydd973932015-04-07 20:29:48 +01001371
1372 // The CFI should be restored for any code that follows the exit block.
1373 cfi_.RestoreState();
1374 cfi_.DefCFAOffset(frame_size);
Andreas Gampe57b34292015-01-14 15:45:59 -08001375}
1376
1377void Mips64Assembler::IncreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001378 CHECK_ALIGNED(adjust, kFramePointerSize);
1379 Daddiu64(SP, SP, static_cast<int32_t>(-adjust));
David Srbeckydd973932015-04-07 20:29:48 +01001380 cfi_.AdjustCFAOffset(adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08001381}
1382
1383void Mips64Assembler::DecreaseFrameSize(size_t adjust) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001384 CHECK_ALIGNED(adjust, kFramePointerSize);
1385 Daddiu64(SP, SP, static_cast<int32_t>(adjust));
David Srbeckydd973932015-04-07 20:29:48 +01001386 cfi_.AdjustCFAOffset(-adjust);
Andreas Gampe57b34292015-01-14 15:45:59 -08001387}
1388
1389void Mips64Assembler::Store(FrameOffset dest, ManagedRegister msrc, size_t size) {
1390 Mips64ManagedRegister src = msrc.AsMips64();
1391 if (src.IsNoRegister()) {
1392 CHECK_EQ(0u, size);
1393 } else if (src.IsGpuRegister()) {
1394 CHECK(size == 4 || size == 8) << size;
1395 if (size == 8) {
1396 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
1397 } else if (size == 4) {
1398 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
1399 } else {
1400 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
1401 }
1402 } else if (src.IsFpuRegister()) {
1403 CHECK(size == 4 || size == 8) << size;
1404 if (size == 8) {
1405 StoreFpuToOffset(kStoreDoubleword, src.AsFpuRegister(), SP, dest.Int32Value());
1406 } else if (size == 4) {
1407 StoreFpuToOffset(kStoreWord, src.AsFpuRegister(), SP, dest.Int32Value());
1408 } else {
1409 UNIMPLEMENTED(FATAL) << "We only support Store() of size 4 and 8";
1410 }
1411 }
1412}
1413
1414void Mips64Assembler::StoreRef(FrameOffset dest, ManagedRegister msrc) {
1415 Mips64ManagedRegister src = msrc.AsMips64();
1416 CHECK(src.IsGpuRegister());
1417 StoreToOffset(kStoreWord, src.AsGpuRegister(), SP, dest.Int32Value());
1418}
1419
1420void Mips64Assembler::StoreRawPtr(FrameOffset dest, ManagedRegister msrc) {
1421 Mips64ManagedRegister src = msrc.AsMips64();
1422 CHECK(src.IsGpuRegister());
1423 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
1424}
1425
1426void Mips64Assembler::StoreImmediateToFrame(FrameOffset dest, uint32_t imm,
1427 ManagedRegister mscratch) {
1428 Mips64ManagedRegister scratch = mscratch.AsMips64();
1429 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001430 LoadConst32(scratch.AsGpuRegister(), imm);
Andreas Gampe57b34292015-01-14 15:45:59 -08001431 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
1432}
1433
1434void Mips64Assembler::StoreImmediateToThread64(ThreadOffset<8> dest, uint32_t imm,
1435 ManagedRegister mscratch) {
1436 Mips64ManagedRegister scratch = mscratch.AsMips64();
1437 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001438 // TODO: it's unclear wether 32 or 64 bits need to be stored (Arm64 and x86/x64 disagree?).
1439 // Is this function even referenced anywhere else in the code?
1440 LoadConst32(scratch.AsGpuRegister(), imm);
Andreas Gampe57b34292015-01-14 15:45:59 -08001441 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), S1, dest.Int32Value());
1442}
1443
1444void Mips64Assembler::StoreStackOffsetToThread64(ThreadOffset<8> thr_offs,
1445 FrameOffset fr_offs,
1446 ManagedRegister mscratch) {
1447 Mips64ManagedRegister scratch = mscratch.AsMips64();
1448 CHECK(scratch.IsGpuRegister()) << scratch;
Alexey Frunze4dda3372015-06-01 18:31:49 -07001449 Daddiu64(scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001450 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
1451}
1452
1453void Mips64Assembler::StoreStackPointerToThread64(ThreadOffset<8> thr_offs) {
1454 StoreToOffset(kStoreDoubleword, SP, S1, thr_offs.Int32Value());
1455}
1456
1457void Mips64Assembler::StoreSpanning(FrameOffset dest, ManagedRegister msrc,
1458 FrameOffset in_off, ManagedRegister mscratch) {
1459 Mips64ManagedRegister src = msrc.AsMips64();
1460 Mips64ManagedRegister scratch = mscratch.AsMips64();
1461 StoreToOffset(kStoreDoubleword, src.AsGpuRegister(), SP, dest.Int32Value());
1462 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, in_off.Int32Value());
1463 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value() + 8);
1464}
1465
1466void Mips64Assembler::Load(ManagedRegister mdest, FrameOffset src, size_t size) {
1467 return EmitLoad(mdest, SP, src.Int32Value(), size);
1468}
1469
1470void Mips64Assembler::LoadFromThread64(ManagedRegister mdest, ThreadOffset<8> src, size_t size) {
1471 return EmitLoad(mdest, S1, src.Int32Value(), size);
1472}
1473
1474void Mips64Assembler::LoadRef(ManagedRegister mdest, FrameOffset src) {
1475 Mips64ManagedRegister dest = mdest.AsMips64();
1476 CHECK(dest.IsGpuRegister());
Douglas Leungd90957f2015-04-30 19:22:49 -07001477 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(), SP, src.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001478}
1479
Mathieu Chartiere401d142015-04-22 13:56:20 -07001480void Mips64Assembler::LoadRef(ManagedRegister mdest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +01001481 bool unpoison_reference) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001482 Mips64ManagedRegister dest = mdest.AsMips64();
Douglas Leungd90957f2015-04-30 19:22:49 -07001483 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
1484 LoadFromOffset(kLoadUnsignedWord, dest.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08001485 base.AsMips64().AsGpuRegister(), offs.Int32Value());
Roland Levillain4d027112015-07-01 15:41:14 +01001486 if (kPoisonHeapReferences && unpoison_reference) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001487 // TODO: review
1488 // Negate the 32-bit ref
1489 Dsubu(dest.AsGpuRegister(), ZERO, dest.AsGpuRegister());
1490 // And constrain it to 32 bits (zero-extend into bits 32 through 63) as on Arm64 and x86/64
1491 Dext(dest.AsGpuRegister(), dest.AsGpuRegister(), 0, 31);
Andreas Gampe57b34292015-01-14 15:45:59 -08001492 }
1493}
1494
1495void Mips64Assembler::LoadRawPtr(ManagedRegister mdest, ManagedRegister base,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001496 Offset offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001497 Mips64ManagedRegister dest = mdest.AsMips64();
Alexey Frunze4dda3372015-06-01 18:31:49 -07001498 CHECK(dest.IsGpuRegister() && base.AsMips64().IsGpuRegister());
Andreas Gampe57b34292015-01-14 15:45:59 -08001499 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(),
1500 base.AsMips64().AsGpuRegister(), offs.Int32Value());
1501}
1502
1503void Mips64Assembler::LoadRawPtrFromThread64(ManagedRegister mdest,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001504 ThreadOffset<8> offs) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001505 Mips64ManagedRegister dest = mdest.AsMips64();
1506 CHECK(dest.IsGpuRegister());
1507 LoadFromOffset(kLoadDoubleword, dest.AsGpuRegister(), S1, offs.Int32Value());
1508}
1509
1510void Mips64Assembler::SignExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
1511 UNIMPLEMENTED(FATAL) << "no sign extension necessary for mips";
1512}
1513
1514void Mips64Assembler::ZeroExtend(ManagedRegister /*mreg*/, size_t /*size*/) {
1515 UNIMPLEMENTED(FATAL) << "no zero extension necessary for mips";
1516}
1517
1518void Mips64Assembler::Move(ManagedRegister mdest, ManagedRegister msrc, size_t size) {
1519 Mips64ManagedRegister dest = mdest.AsMips64();
1520 Mips64ManagedRegister src = msrc.AsMips64();
1521 if (!dest.Equals(src)) {
1522 if (dest.IsGpuRegister()) {
1523 CHECK(src.IsGpuRegister()) << src;
1524 Move(dest.AsGpuRegister(), src.AsGpuRegister());
1525 } else if (dest.IsFpuRegister()) {
1526 CHECK(src.IsFpuRegister()) << src;
1527 if (size == 4) {
1528 MovS(dest.AsFpuRegister(), src.AsFpuRegister());
1529 } else if (size == 8) {
1530 MovD(dest.AsFpuRegister(), src.AsFpuRegister());
1531 } else {
1532 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
1533 }
1534 }
1535 }
1536}
1537
1538void Mips64Assembler::CopyRef(FrameOffset dest, FrameOffset src,
1539 ManagedRegister mscratch) {
1540 Mips64ManagedRegister scratch = mscratch.AsMips64();
1541 CHECK(scratch.IsGpuRegister()) << scratch;
1542 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
1543 StoreToOffset(kStoreWord, scratch.AsGpuRegister(), SP, dest.Int32Value());
1544}
1545
1546void Mips64Assembler::CopyRawPtrFromThread64(FrameOffset fr_offs,
1547 ThreadOffset<8> thr_offs,
1548 ManagedRegister mscratch) {
1549 Mips64ManagedRegister scratch = mscratch.AsMips64();
1550 CHECK(scratch.IsGpuRegister()) << scratch;
1551 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), S1, thr_offs.Int32Value());
1552 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, fr_offs.Int32Value());
1553}
1554
1555void Mips64Assembler::CopyRawPtrToThread64(ThreadOffset<8> thr_offs,
1556 FrameOffset fr_offs,
1557 ManagedRegister mscratch) {
1558 Mips64ManagedRegister scratch = mscratch.AsMips64();
1559 CHECK(scratch.IsGpuRegister()) << scratch;
1560 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
1561 SP, fr_offs.Int32Value());
1562 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(),
1563 S1, thr_offs.Int32Value());
1564}
1565
1566void Mips64Assembler::Copy(FrameOffset dest, FrameOffset src,
1567 ManagedRegister mscratch, size_t size) {
1568 Mips64ManagedRegister scratch = mscratch.AsMips64();
1569 CHECK(scratch.IsGpuRegister()) << scratch;
1570 CHECK(size == 4 || size == 8) << size;
1571 if (size == 4) {
1572 LoadFromOffset(kLoadWord, scratch.AsGpuRegister(), SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02001573 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001574 } else if (size == 8) {
1575 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(), SP, src.Int32Value());
1576 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, dest.Int32Value());
1577 } else {
1578 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
1579 }
1580}
1581
1582void Mips64Assembler::Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001583 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001584 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
1585 CHECK(size == 4 || size == 8) << size;
1586 if (size == 4) {
1587 LoadFromOffset(kLoadWord, scratch, src_base.AsMips64().AsGpuRegister(),
1588 src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02001589 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001590 } else if (size == 8) {
1591 LoadFromOffset(kLoadDoubleword, scratch, src_base.AsMips64().AsGpuRegister(),
1592 src_offset.Int32Value());
1593 StoreToOffset(kStoreDoubleword, scratch, SP, dest.Int32Value());
1594 } else {
1595 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
1596 }
1597}
1598
1599void Mips64Assembler::Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001600 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001601 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
1602 CHECK(size == 4 || size == 8) << size;
1603 if (size == 4) {
1604 LoadFromOffset(kLoadWord, scratch, SP, src.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02001605 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08001606 dest_offset.Int32Value());
1607 } else if (size == 8) {
1608 LoadFromOffset(kLoadDoubleword, scratch, SP, src.Int32Value());
1609 StoreToOffset(kStoreDoubleword, scratch, dest_base.AsMips64().AsGpuRegister(),
1610 dest_offset.Int32Value());
1611 } else {
1612 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
1613 }
1614}
1615
1616void Mips64Assembler::Copy(FrameOffset /*dest*/, FrameOffset /*src_base*/, Offset /*src_offset*/,
1617 ManagedRegister /*mscratch*/, size_t /*size*/) {
1618 UNIMPLEMENTED(FATAL) << "no mips64 implementation";
1619}
1620
1621void Mips64Assembler::Copy(ManagedRegister dest, Offset dest_offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001622 ManagedRegister src, Offset src_offset,
1623 ManagedRegister mscratch, size_t size) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001624 GpuRegister scratch = mscratch.AsMips64().AsGpuRegister();
1625 CHECK(size == 4 || size == 8) << size;
1626 if (size == 4) {
1627 LoadFromOffset(kLoadWord, scratch, src.AsMips64().AsGpuRegister(), src_offset.Int32Value());
Lazar Trsicf652d602015-06-24 16:30:21 +02001628 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(), dest_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001629 } else if (size == 8) {
1630 LoadFromOffset(kLoadDoubleword, scratch, src.AsMips64().AsGpuRegister(),
1631 src_offset.Int32Value());
1632 StoreToOffset(kStoreDoubleword, scratch, dest.AsMips64().AsGpuRegister(),
1633 dest_offset.Int32Value());
1634 } else {
1635 UNIMPLEMENTED(FATAL) << "We only support Copy() of size 4 and 8";
1636 }
1637}
1638
1639void Mips64Assembler::Copy(FrameOffset /*dest*/, Offset /*dest_offset*/, FrameOffset /*src*/, Offset
1640/*src_offset*/,
1641 ManagedRegister /*mscratch*/, size_t /*size*/) {
1642 UNIMPLEMENTED(FATAL) << "no mips64 implementation";
1643}
1644
1645void Mips64Assembler::MemoryBarrier(ManagedRegister) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001646 // TODO: sync?
Andreas Gampe57b34292015-01-14 15:45:59 -08001647 UNIMPLEMENTED(FATAL) << "no mips64 implementation";
1648}
1649
1650void Mips64Assembler::CreateHandleScopeEntry(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001651 FrameOffset handle_scope_offset,
1652 ManagedRegister min_reg,
1653 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001654 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
1655 Mips64ManagedRegister in_reg = min_reg.AsMips64();
1656 CHECK(in_reg.IsNoRegister() || in_reg.IsGpuRegister()) << in_reg;
1657 CHECK(out_reg.IsGpuRegister()) << out_reg;
1658 if (null_allowed) {
1659 Label null_arg;
1660 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
1661 // the address in the handle scope holding the reference.
1662 // e.g. out_reg = (handle == 0) ? 0 : (SP+handle_offset)
1663 if (in_reg.IsNoRegister()) {
Douglas Leungd90957f2015-04-30 19:22:49 -07001664 LoadFromOffset(kLoadUnsignedWord, out_reg.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08001665 SP, handle_scope_offset.Int32Value());
1666 in_reg = out_reg;
1667 }
1668 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001669 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08001670 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001671 Beqzc(in_reg.AsGpuRegister(), &null_arg);
1672 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
1673 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08001674 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001675 Daddiu64(out_reg.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001676 }
1677}
1678
1679void Mips64Assembler::CreateHandleScopeEntry(FrameOffset out_off,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001680 FrameOffset handle_scope_offset,
1681 ManagedRegister mscratch,
1682 bool null_allowed) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001683 Mips64ManagedRegister scratch = mscratch.AsMips64();
1684 CHECK(scratch.IsGpuRegister()) << scratch;
1685 if (null_allowed) {
1686 Label null_arg;
Douglas Leungd90957f2015-04-30 19:22:49 -07001687 LoadFromOffset(kLoadUnsignedWord, scratch.AsGpuRegister(), SP,
Andreas Gampe57b34292015-01-14 15:45:59 -08001688 handle_scope_offset.Int32Value());
1689 // Null values get a handle scope entry value of 0. Otherwise, the handle scope entry is
1690 // the address in the handle scope holding the reference.
1691 // e.g. scratch = (scratch == 0) ? 0 : (SP+handle_scope_offset)
Alexey Frunze4dda3372015-06-01 18:31:49 -07001692 Beqzc(scratch.AsGpuRegister(), &null_arg);
1693 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
1694 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08001695 } else {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001696 Daddiu64(scratch.AsGpuRegister(), SP, handle_scope_offset.Int32Value());
Andreas Gampe57b34292015-01-14 15:45:59 -08001697 }
1698 StoreToOffset(kStoreDoubleword, scratch.AsGpuRegister(), SP, out_off.Int32Value());
1699}
1700
1701// Given a handle scope entry, load the associated reference.
1702void Mips64Assembler::LoadReferenceFromHandleScope(ManagedRegister mout_reg,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001703 ManagedRegister min_reg) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001704 Mips64ManagedRegister out_reg = mout_reg.AsMips64();
1705 Mips64ManagedRegister in_reg = min_reg.AsMips64();
1706 CHECK(out_reg.IsGpuRegister()) << out_reg;
1707 CHECK(in_reg.IsGpuRegister()) << in_reg;
1708 Label null_arg;
1709 if (!out_reg.Equals(in_reg)) {
Alexey Frunze4dda3372015-06-01 18:31:49 -07001710 LoadConst32(out_reg.AsGpuRegister(), 0);
Andreas Gampe57b34292015-01-14 15:45:59 -08001711 }
Alexey Frunze4dda3372015-06-01 18:31:49 -07001712 Beqzc(in_reg.AsGpuRegister(), &null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08001713 LoadFromOffset(kLoadDoubleword, out_reg.AsGpuRegister(),
1714 in_reg.AsGpuRegister(), 0);
Alexey Frunze4dda3372015-06-01 18:31:49 -07001715 Bind(&null_arg);
Andreas Gampe57b34292015-01-14 15:45:59 -08001716}
1717
1718void Mips64Assembler::VerifyObject(ManagedRegister /*src*/, bool /*could_be_null*/) {
1719 // TODO: not validating references
1720}
1721
1722void Mips64Assembler::VerifyObject(FrameOffset /*src*/, bool /*could_be_null*/) {
1723 // TODO: not validating references
1724}
1725
1726void Mips64Assembler::Call(ManagedRegister mbase, Offset offset, ManagedRegister mscratch) {
1727 Mips64ManagedRegister base = mbase.AsMips64();
1728 Mips64ManagedRegister scratch = mscratch.AsMips64();
1729 CHECK(base.IsGpuRegister()) << base;
1730 CHECK(scratch.IsGpuRegister()) << scratch;
1731 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
1732 base.AsGpuRegister(), offset.Int32Value());
1733 Jalr(scratch.AsGpuRegister());
1734 // TODO: place reference map on call
1735}
1736
1737void Mips64Assembler::Call(FrameOffset base, Offset offset, ManagedRegister mscratch) {
1738 Mips64ManagedRegister scratch = mscratch.AsMips64();
1739 CHECK(scratch.IsGpuRegister()) << scratch;
1740 // Call *(*(SP + base) + offset)
Mathieu Chartiere401d142015-04-22 13:56:20 -07001741 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
Andreas Gampe57b34292015-01-14 15:45:59 -08001742 SP, base.Int32Value());
1743 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
1744 scratch.AsGpuRegister(), offset.Int32Value());
1745 Jalr(scratch.AsGpuRegister());
1746 // TODO: place reference map on call
1747}
1748
1749void Mips64Assembler::CallFromThread64(ThreadOffset<8> /*offset*/, ManagedRegister /*mscratch*/) {
1750 UNIMPLEMENTED(FATAL) << "no mips64 implementation";
1751}
1752
1753void Mips64Assembler::GetCurrentThread(ManagedRegister tr) {
1754 Move(tr.AsMips64().AsGpuRegister(), S1);
1755}
1756
1757void Mips64Assembler::GetCurrentThread(FrameOffset offset,
Alexey Frunze4dda3372015-06-01 18:31:49 -07001758 ManagedRegister /*mscratch*/) {
Andreas Gampe57b34292015-01-14 15:45:59 -08001759 StoreToOffset(kStoreDoubleword, S1, SP, offset.Int32Value());
1760}
1761
1762void Mips64Assembler::ExceptionPoll(ManagedRegister mscratch, size_t stack_adjust) {
1763 Mips64ManagedRegister scratch = mscratch.AsMips64();
1764 Mips64ExceptionSlowPath* slow = new Mips64ExceptionSlowPath(scratch, stack_adjust);
1765 buffer_.EnqueueSlowPath(slow);
1766 LoadFromOffset(kLoadDoubleword, scratch.AsGpuRegister(),
1767 S1, Thread::ExceptionOffset<8>().Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001768 Bnezc(scratch.AsGpuRegister(), slow->Entry());
Andreas Gampe57b34292015-01-14 15:45:59 -08001769}
1770
1771void Mips64ExceptionSlowPath::Emit(Assembler* sasm) {
1772 Mips64Assembler* sp_asm = down_cast<Mips64Assembler*>(sasm);
1773#define __ sp_asm->
Alexey Frunze4dda3372015-06-01 18:31:49 -07001774 __ Bind(&entry_);
Andreas Gampe57b34292015-01-14 15:45:59 -08001775 if (stack_adjust_ != 0) { // Fix up the frame.
1776 __ DecreaseFrameSize(stack_adjust_);
1777 }
1778 // Pass exception object as argument
1779 // Don't care about preserving A0 as this call won't return
1780 __ Move(A0, scratch_.AsGpuRegister());
1781 // Set up call to Thread::Current()->pDeliverException
1782 __ LoadFromOffset(kLoadDoubleword, T9, S1,
Goran Jakovljevic75c40d42015-04-03 15:45:21 +02001783 QUICK_ENTRYPOINT_OFFSET(8, pDeliverException).Int32Value());
Alexey Frunze4dda3372015-06-01 18:31:49 -07001784 // TODO: check T9 usage
Andreas Gampe57b34292015-01-14 15:45:59 -08001785 __ Jr(T9);
1786 // Call never returns
1787 __ Break();
1788#undef __
1789}
1790
1791} // namespace mips64
1792} // namespace art