blob: 3410ecb3987e34108c44dc1856642d12b326236b [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2012 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/* This file contains codegen for the Mips ISA */
18
19#include "codegen_mips.h"
20#include "dex/quick/mir_to_lir-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070021#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "mips_lir.h"
23#include "mirror/array.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070024
25namespace art {
26
27/*
28 * Compare two 64-bit values
29 * x = y return 0
30 * x < y return -1
31 * x > y return 1
32 *
33 * slt t0, x.hi, y.hi; # (x.hi < y.hi) ? 1:0
34 * sgt t1, x.hi, y.hi; # (y.hi > x.hi) ? 1:0
35 * subu res, t0, t1 # res = -1:1:0 for [ < > = ]
36 * bnez res, finish
37 * sltu t0, x.lo, y.lo
38 * sgtu r1, x.lo, y.lo
39 * subu res, t0, t1
40 * finish:
41 *
42 */
43void MipsMir2Lir::GenCmpLong(RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070044 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070045 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
46 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
47 int t0 = AllocTemp();
48 int t1 = AllocTemp();
49 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
50 NewLIR3(kMipsSlt, t0, rl_src1.high_reg, rl_src2.high_reg);
51 NewLIR3(kMipsSlt, t1, rl_src2.high_reg, rl_src1.high_reg);
52 NewLIR3(kMipsSubu, rl_result.low_reg, t1, t0);
53 LIR* branch = OpCmpImmBranch(kCondNe, rl_result.low_reg, 0, NULL);
54 NewLIR3(kMipsSltu, t0, rl_src1.low_reg, rl_src2.low_reg);
55 NewLIR3(kMipsSltu, t1, rl_src2.low_reg, rl_src1.low_reg);
56 NewLIR3(kMipsSubu, rl_result.low_reg, t1, t0);
57 FreeTemp(t0);
58 FreeTemp(t1);
59 LIR* target = NewLIR0(kPseudoTargetLabel);
60 branch->target = target;
61 StoreValue(rl_dest, rl_result);
62}
63
64LIR* MipsMir2Lir::OpCmpBranch(ConditionCode cond, int src1, int src2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070065 LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 LIR* branch;
67 MipsOpCode slt_op;
68 MipsOpCode br_op;
69 bool cmp_zero = false;
70 bool swapped = false;
71 switch (cond) {
72 case kCondEq:
73 br_op = kMipsBeq;
74 cmp_zero = true;
75 break;
76 case kCondNe:
77 br_op = kMipsBne;
78 cmp_zero = true;
79 break;
Vladimir Marko58af1f92013-12-19 13:31:15 +000080 case kCondUlt:
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 slt_op = kMipsSltu;
82 br_op = kMipsBnez;
83 break;
Vladimir Marko58af1f92013-12-19 13:31:15 +000084 case kCondUge:
Brian Carlstrom7940e442013-07-12 13:46:57 -070085 slt_op = kMipsSltu;
86 br_op = kMipsBeqz;
87 break;
88 case kCondGe:
89 slt_op = kMipsSlt;
90 br_op = kMipsBeqz;
91 break;
92 case kCondGt:
93 slt_op = kMipsSlt;
94 br_op = kMipsBnez;
95 swapped = true;
96 break;
97 case kCondLe:
98 slt_op = kMipsSlt;
99 br_op = kMipsBeqz;
100 swapped = true;
101 break;
102 case kCondLt:
103 slt_op = kMipsSlt;
104 br_op = kMipsBnez;
105 break;
106 case kCondHi: // Gtu
107 slt_op = kMipsSltu;
108 br_op = kMipsBnez;
109 swapped = true;
110 break;
111 default:
112 LOG(FATAL) << "No support for ConditionCode: " << cond;
113 return NULL;
114 }
115 if (cmp_zero) {
116 branch = NewLIR2(br_op, src1, src2);
117 } else {
118 int t_reg = AllocTemp();
119 if (swapped) {
120 NewLIR3(slt_op, t_reg, src2, src1);
121 } else {
122 NewLIR3(slt_op, t_reg, src1, src2);
123 }
124 branch = NewLIR1(br_op, t_reg);
125 FreeTemp(t_reg);
126 }
127 branch->target = target;
128 return branch;
129}
130
131LIR* MipsMir2Lir::OpCmpImmBranch(ConditionCode cond, int reg,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700132 int check_value, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 LIR* branch;
134 if (check_value != 0) {
135 // TUNING: handle s16 & kCondLt/Mi case using slti
136 int t_reg = AllocTemp();
137 LoadConstant(t_reg, check_value);
138 branch = OpCmpBranch(cond, reg, t_reg, target);
139 FreeTemp(t_reg);
140 return branch;
141 }
142 MipsOpCode opc;
143 switch (cond) {
144 case kCondEq: opc = kMipsBeqz; break;
145 case kCondGe: opc = kMipsBgez; break;
146 case kCondGt: opc = kMipsBgtz; break;
147 case kCondLe: opc = kMipsBlez; break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700148 // case KCondMi:
Brian Carlstrom7940e442013-07-12 13:46:57 -0700149 case kCondLt: opc = kMipsBltz; break;
150 case kCondNe: opc = kMipsBnez; break;
151 default:
152 // Tuning: use slti when applicable
153 int t_reg = AllocTemp();
154 LoadConstant(t_reg, check_value);
155 branch = OpCmpBranch(cond, reg, t_reg, target);
156 FreeTemp(t_reg);
157 return branch;
158 }
159 branch = NewLIR1(opc, reg);
160 branch->target = target;
161 return branch;
162}
163
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700164LIR* MipsMir2Lir::OpRegCopyNoInsert(int r_dest, int r_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700165 if (MIPS_FPREG(r_dest) || MIPS_FPREG(r_src))
166 return OpFpRegCopy(r_dest, r_src);
167 LIR* res = RawLIR(current_dalvik_offset_, kMipsMove,
168 r_dest, r_src);
169 if (!(cu_->disable_opt & (1 << kSafeOptimizations)) && r_dest == r_src) {
170 res->flags.is_nop = true;
171 }
172 return res;
173}
174
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700175LIR* MipsMir2Lir::OpRegCopy(int r_dest, int r_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700176 LIR *res = OpRegCopyNoInsert(r_dest, r_src);
177 AppendLIR(res);
178 return res;
179}
180
181void MipsMir2Lir::OpRegCopyWide(int dest_lo, int dest_hi, int src_lo,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700182 int src_hi) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700183 bool dest_fp = MIPS_FPREG(dest_lo) && MIPS_FPREG(dest_hi);
184 bool src_fp = MIPS_FPREG(src_lo) && MIPS_FPREG(src_hi);
185 assert(MIPS_FPREG(src_lo) == MIPS_FPREG(src_hi));
186 assert(MIPS_FPREG(dest_lo) == MIPS_FPREG(dest_hi));
187 if (dest_fp) {
188 if (src_fp) {
189 OpRegCopy(S2d(dest_lo, dest_hi), S2d(src_lo, src_hi));
190 } else {
191 /* note the operands are swapped for the mtc1 instr */
192 NewLIR2(kMipsMtc1, src_lo, dest_lo);
193 NewLIR2(kMipsMtc1, src_hi, dest_hi);
194 }
195 } else {
196 if (src_fp) {
197 NewLIR2(kMipsMfc1, dest_lo, src_lo);
198 NewLIR2(kMipsMfc1, dest_hi, src_hi);
199 } else {
200 // Handle overlap
201 if (src_hi == dest_lo) {
202 OpRegCopy(dest_hi, src_hi);
203 OpRegCopy(dest_lo, src_lo);
204 } else {
205 OpRegCopy(dest_lo, src_lo);
206 OpRegCopy(dest_hi, src_hi);
207 }
208 }
209 }
210}
211
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700212void MipsMir2Lir::GenSelect(BasicBlock* bb, MIR* mir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700213 UNIMPLEMENTED(FATAL) << "Need codegen for select";
214}
215
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700216void MipsMir2Lir::GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217 UNIMPLEMENTED(FATAL) << "Need codegen for fused long cmp branch";
218}
219
220LIR* MipsMir2Lir::GenRegMemCheck(ConditionCode c_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700221 int reg1, int base, int offset, ThrowKind kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222 LOG(FATAL) << "Unexpected use of GenRegMemCheck for Arm";
223 return NULL;
224}
225
226RegLocation MipsMir2Lir::GenDivRem(RegLocation rl_dest, int reg1, int reg2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700227 bool is_div) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 NewLIR4(kMipsDiv, r_HI, r_LO, reg1, reg2);
229 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
230 if (is_div) {
231 NewLIR2(kMipsMflo, rl_result.low_reg, r_LO);
232 } else {
233 NewLIR2(kMipsMfhi, rl_result.low_reg, r_HI);
234 }
235 return rl_result;
236}
237
238RegLocation MipsMir2Lir::GenDivRemLit(RegLocation rl_dest, int reg1, int lit,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700239 bool is_div) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700240 int t_reg = AllocTemp();
241 NewLIR3(kMipsAddiu, t_reg, r_ZERO, lit);
242 NewLIR4(kMipsDiv, r_HI, r_LO, reg1, t_reg);
243 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
244 if (is_div) {
245 NewLIR2(kMipsMflo, rl_result.low_reg, r_LO);
246 } else {
247 NewLIR2(kMipsMfhi, rl_result.low_reg, r_HI);
248 }
249 FreeTemp(t_reg);
250 return rl_result;
251}
252
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700253void MipsMir2Lir::OpLea(int rBase, int reg1, int reg2, int scale, int offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700254 LOG(FATAL) << "Unexpected use of OpLea for Arm";
255}
256
Ian Rogers468532e2013-08-05 10:56:33 -0700257void MipsMir2Lir::OpTlsCmp(ThreadOffset offset, int val) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700258 LOG(FATAL) << "Unexpected use of OpTlsCmp for Arm";
259}
260
Vladimir Marko1c282e22013-11-21 14:49:47 +0000261bool MipsMir2Lir::GenInlinedCas(CallInfo* info, bool is_long, bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700262 DCHECK_NE(cu_->instruction_set, kThumb2);
263 return false;
264}
265
266bool MipsMir2Lir::GenInlinedSqrt(CallInfo* info) {
267 DCHECK_NE(cu_->instruction_set, kThumb2);
268 return false;
269}
270
Vladimir Markoe508a202013-11-04 15:24:22 +0000271bool MipsMir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) {
272 if (size != kSignedByte) {
273 // MIPS supports only aligned access. Defer unaligned access to JNI implementation.
274 return false;
275 }
276 RegLocation rl_src_address = info->args[0]; // long address
277 rl_src_address.wide = 0; // ignore high half in info->args[1]
278 RegLocation rl_dest = InlineTarget(info);
279 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
280 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
281 DCHECK(size == kSignedByte);
282 LoadBaseDisp(rl_address.low_reg, 0, rl_result.low_reg, size, INVALID_SREG);
283 StoreValue(rl_dest, rl_result);
284 return true;
285}
286
287bool MipsMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) {
288 if (size != kSignedByte) {
289 // MIPS supports only aligned access. Defer unaligned access to JNI implementation.
290 return false;
291 }
292 RegLocation rl_src_address = info->args[0]; // long address
293 rl_src_address.wide = 0; // ignore high half in info->args[1]
294 RegLocation rl_src_value = info->args[2]; // [size] value
295 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
296 DCHECK(size == kSignedByte);
297 RegLocation rl_value = LoadValue(rl_src_value, kCoreReg);
298 StoreBaseDisp(rl_address.low_reg, 0, rl_value.low_reg, size);
299 return true;
300}
301
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302LIR* MipsMir2Lir::OpPcRelLoad(int reg, LIR* target) {
303 LOG(FATAL) << "Unexpected use of OpPcRelLoad for Mips";
304 return NULL;
305}
306
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700307LIR* MipsMir2Lir::OpVldm(int rBase, int count) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700308 LOG(FATAL) << "Unexpected use of OpVldm for Mips";
309 return NULL;
310}
311
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700312LIR* MipsMir2Lir::OpVstm(int rBase, int count) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700313 LOG(FATAL) << "Unexpected use of OpVstm for Mips";
314 return NULL;
315}
316
317void MipsMir2Lir::GenMultiplyByTwoBitMultiplier(RegLocation rl_src,
318 RegLocation rl_result, int lit,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700319 int first_bit, int second_bit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700320 int t_reg = AllocTemp();
321 OpRegRegImm(kOpLsl, t_reg, rl_src.low_reg, second_bit - first_bit);
322 OpRegRegReg(kOpAdd, rl_result.low_reg, rl_src.low_reg, t_reg);
323 FreeTemp(t_reg);
324 if (first_bit != 0) {
325 OpRegRegImm(kOpLsl, rl_result.low_reg, rl_result.low_reg, first_bit);
326 }
327}
328
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700329void MipsMir2Lir::GenDivZeroCheck(int reg_lo, int reg_hi) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330 int t_reg = AllocTemp();
331 OpRegRegReg(kOpOr, t_reg, reg_lo, reg_hi);
332 GenImmedCheck(kCondEq, t_reg, 0, kThrowDivZero);
333 FreeTemp(t_reg);
334}
335
336// Test suspend flag, return target of taken suspend branch
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700337LIR* MipsMir2Lir::OpTestSuspend(LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700338 OpRegImm(kOpSub, rMIPS_SUSPEND, 1);
339 return OpCmpImmBranch((target == NULL) ? kCondEq : kCondNe, rMIPS_SUSPEND, 0, target);
340}
341
342// Decrement register and branch on condition
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700343LIR* MipsMir2Lir::OpDecAndBranch(ConditionCode c_code, int reg, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 OpRegImm(kOpSub, reg, 1);
345 return OpCmpImmBranch(c_code, reg, 0, target);
346}
347
buzbee11b63d12013-08-27 07:34:17 -0700348bool MipsMir2Lir::SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700349 RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700350 LOG(FATAL) << "Unexpected use of smallLiteralDive in Mips";
351 return false;
352}
353
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700354LIR* MipsMir2Lir::OpIT(ConditionCode cond, const char* guide) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700355 LOG(FATAL) << "Unexpected use of OpIT in Mips";
356 return NULL;
357}
358
Mark Mendelle02d48f2014-01-15 11:19:23 -0800359void MipsMir2Lir::GenMulLong(Instruction::Code opcode, RegLocation rl_dest,
360 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700361 LOG(FATAL) << "Unexpected use of GenMulLong for Mips";
362}
363
Mark Mendelle02d48f2014-01-15 11:19:23 -0800364void MipsMir2Lir::GenAddLong(Instruction::Code opcode, RegLocation rl_dest,
365 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700366 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
367 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
368 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
369 /*
370 * [v1 v0] = [a1 a0] + [a3 a2];
371 * addu v0,a2,a0
372 * addu t1,a3,a1
373 * sltu v1,v0,a2
374 * addu v1,v1,t1
375 */
376
377 OpRegRegReg(kOpAdd, rl_result.low_reg, rl_src2.low_reg, rl_src1.low_reg);
378 int t_reg = AllocTemp();
379 OpRegRegReg(kOpAdd, t_reg, rl_src2.high_reg, rl_src1.high_reg);
380 NewLIR3(kMipsSltu, rl_result.high_reg, rl_result.low_reg, rl_src2.low_reg);
381 OpRegRegReg(kOpAdd, rl_result.high_reg, rl_result.high_reg, t_reg);
382 FreeTemp(t_reg);
383 StoreValueWide(rl_dest, rl_result);
384}
385
Mark Mendelle02d48f2014-01-15 11:19:23 -0800386void MipsMir2Lir::GenSubLong(Instruction::Code opcode, RegLocation rl_dest,
387 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700388 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
389 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
390 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
391 /*
392 * [v1 v0] = [a1 a0] - [a3 a2];
393 * sltu t1,a0,a2
394 * subu v0,a0,a2
395 * subu v1,a1,a3
396 * subu v1,v1,t1
397 */
398
399 int t_reg = AllocTemp();
400 NewLIR3(kMipsSltu, t_reg, rl_src1.low_reg, rl_src2.low_reg);
401 OpRegRegReg(kOpSub, rl_result.low_reg, rl_src1.low_reg, rl_src2.low_reg);
402 OpRegRegReg(kOpSub, rl_result.high_reg, rl_src1.high_reg, rl_src2.high_reg);
403 OpRegRegReg(kOpSub, rl_result.high_reg, rl_result.high_reg, t_reg);
404 FreeTemp(t_reg);
405 StoreValueWide(rl_dest, rl_result);
406}
407
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700408void MipsMir2Lir::GenNegLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700409 rl_src = LoadValueWide(rl_src, kCoreReg);
410 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
411 /*
412 * [v1 v0] = -[a1 a0]
413 * negu v0,a0
414 * negu v1,a1
415 * sltu t1,r_zero
416 * subu v1,v1,t1
417 */
418
419 OpRegReg(kOpNeg, rl_result.low_reg, rl_src.low_reg);
420 OpRegReg(kOpNeg, rl_result.high_reg, rl_src.high_reg);
421 int t_reg = AllocTemp();
422 NewLIR3(kMipsSltu, t_reg, r_ZERO, rl_result.low_reg);
423 OpRegRegReg(kOpSub, rl_result.high_reg, rl_result.high_reg, t_reg);
424 FreeTemp(t_reg);
425 StoreValueWide(rl_dest, rl_result);
426}
427
Mark Mendelle02d48f2014-01-15 11:19:23 -0800428void MipsMir2Lir::GenAndLong(Instruction::Code opcode, RegLocation rl_dest,
429 RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700430 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700431 LOG(FATAL) << "Unexpected use of GenAndLong for Mips";
432}
433
Mark Mendelle02d48f2014-01-15 11:19:23 -0800434void MipsMir2Lir::GenOrLong(Instruction::Code opcode, RegLocation rl_dest,
435 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700436 LOG(FATAL) << "Unexpected use of GenOrLong for Mips";
437}
438
Mark Mendelle02d48f2014-01-15 11:19:23 -0800439void MipsMir2Lir::GenXorLong(Instruction::Code opcode, RegLocation rl_dest,
440 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700441 LOG(FATAL) << "Unexpected use of GenXorLong for Mips";
442}
443
444/*
445 * Generate array load
446 */
447void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700448 RegLocation rl_index, RegLocation rl_dest, int scale) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700449 RegisterClass reg_class = oat_reg_class_by_size(size);
450 int len_offset = mirror::Array::LengthOffset().Int32Value();
451 int data_offset;
452 RegLocation rl_result;
453 rl_array = LoadValue(rl_array, kCoreReg);
454 rl_index = LoadValue(rl_index, kCoreReg);
455
456 if (size == kLong || size == kDouble) {
457 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
458 } else {
459 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
460 }
461
462 /* null object? */
463 GenNullCheck(rl_array.s_reg_low, rl_array.low_reg, opt_flags);
464
465 int reg_ptr = AllocTemp();
466 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
467 int reg_len = INVALID_REG;
468 if (needs_range_check) {
469 reg_len = AllocTemp();
470 /* Get len */
471 LoadWordDisp(rl_array.low_reg, len_offset, reg_len);
472 }
473 /* reg_ptr -> array data */
474 OpRegRegImm(kOpAdd, reg_ptr, rl_array.low_reg, data_offset);
475 FreeTemp(rl_array.low_reg);
476 if ((size == kLong) || (size == kDouble)) {
477 if (scale) {
478 int r_new_index = AllocTemp();
479 OpRegRegImm(kOpLsl, r_new_index, rl_index.low_reg, scale);
480 OpRegReg(kOpAdd, reg_ptr, r_new_index);
481 FreeTemp(r_new_index);
482 } else {
483 OpRegReg(kOpAdd, reg_ptr, rl_index.low_reg);
484 }
485 FreeTemp(rl_index.low_reg);
486 rl_result = EvalLoc(rl_dest, reg_class, true);
487
488 if (needs_range_check) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000489 GenRegRegCheck(kCondUge, rl_index.low_reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700490 FreeTemp(reg_len);
491 }
492 LoadBaseDispWide(reg_ptr, 0, rl_result.low_reg, rl_result.high_reg, INVALID_SREG);
493
494 FreeTemp(reg_ptr);
495 StoreValueWide(rl_dest, rl_result);
496 } else {
497 rl_result = EvalLoc(rl_dest, reg_class, true);
498
499 if (needs_range_check) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000500 GenRegRegCheck(kCondUge, rl_index.low_reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700501 FreeTemp(reg_len);
502 }
503 LoadBaseIndexed(reg_ptr, rl_index.low_reg, rl_result.low_reg, scale, size);
504
505 FreeTemp(reg_ptr);
506 StoreValue(rl_dest, rl_result);
507 }
508}
509
510/*
511 * Generate array store
512 *
513 */
514void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -0700515 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700516 RegisterClass reg_class = oat_reg_class_by_size(size);
517 int len_offset = mirror::Array::LengthOffset().Int32Value();
518 int data_offset;
519
520 if (size == kLong || size == kDouble) {
521 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
522 } else {
523 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
524 }
525
526 rl_array = LoadValue(rl_array, kCoreReg);
527 rl_index = LoadValue(rl_index, kCoreReg);
528 int reg_ptr = INVALID_REG;
Ian Rogers773aab12013-10-14 13:50:10 -0700529 bool allocated_reg_ptr_temp = false;
Ian Rogers379067c2013-10-15 15:06:58 -0700530 if (IsTemp(rl_array.low_reg) && !card_mark) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700531 Clobber(rl_array.low_reg);
532 reg_ptr = rl_array.low_reg;
533 } else {
534 reg_ptr = AllocTemp();
535 OpRegCopy(reg_ptr, rl_array.low_reg);
Ian Rogers773aab12013-10-14 13:50:10 -0700536 allocated_reg_ptr_temp = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700537 }
538
539 /* null object? */
540 GenNullCheck(rl_array.s_reg_low, rl_array.low_reg, opt_flags);
541
542 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
543 int reg_len = INVALID_REG;
544 if (needs_range_check) {
545 reg_len = AllocTemp();
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700546 // NOTE: max live temps(4) here.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700547 /* Get len */
548 LoadWordDisp(rl_array.low_reg, len_offset, reg_len);
549 }
550 /* reg_ptr -> array data */
551 OpRegImm(kOpAdd, reg_ptr, data_offset);
552 /* at this point, reg_ptr points to array, 2 live temps */
553 if ((size == kLong) || (size == kDouble)) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700554 // TUNING: specific wide routine that can handle fp regs
Brian Carlstrom7940e442013-07-12 13:46:57 -0700555 if (scale) {
556 int r_new_index = AllocTemp();
557 OpRegRegImm(kOpLsl, r_new_index, rl_index.low_reg, scale);
558 OpRegReg(kOpAdd, reg_ptr, r_new_index);
559 FreeTemp(r_new_index);
560 } else {
561 OpRegReg(kOpAdd, reg_ptr, rl_index.low_reg);
562 }
563 rl_src = LoadValueWide(rl_src, reg_class);
564
565 if (needs_range_check) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000566 GenRegRegCheck(kCondUge, rl_index.low_reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700567 FreeTemp(reg_len);
568 }
569
570 StoreBaseDispWide(reg_ptr, 0, rl_src.low_reg, rl_src.high_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700571 } else {
572 rl_src = LoadValue(rl_src, reg_class);
573 if (needs_range_check) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000574 GenRegRegCheck(kCondUge, rl_index.low_reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700575 FreeTemp(reg_len);
576 }
577 StoreBaseIndexed(reg_ptr, rl_index.low_reg, rl_src.low_reg,
578 scale, size);
579 }
Ian Rogers773aab12013-10-14 13:50:10 -0700580 if (allocated_reg_ptr_temp) {
581 FreeTemp(reg_ptr);
582 }
Ian Rogersa9a82542013-10-04 11:17:26 -0700583 if (card_mark) {
584 MarkGCCard(rl_src.low_reg, rl_array.low_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700585 }
586}
587
588void MipsMir2Lir::GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700589 RegLocation rl_src1, RegLocation rl_shift) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700590 // Default implementation is just to ignore the constant case.
591 GenShiftOpLong(opcode, rl_dest, rl_src1, rl_shift);
592}
593
594void MipsMir2Lir::GenArithImmOpLong(Instruction::Code opcode,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700595 RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700596 // Default - bail to non-const handler.
597 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2);
598}
599
600} // namespace art