blob: 2a4d27ba57c9478c45d122a4cc9f8d29b952ba29 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2011 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 Thumb2 ISA. */
18
Andreas Gampe0b9203e2015-01-22 20:39:27 -080019#include "codegen_arm.h"
20
Elliott Hughes8366ca02014-11-17 12:02:05 -080021#include "arch/instruction_set_features.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "arm_lir.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080023#include "base/logging.h"
24#include "dex/compiler_ir.h"
25#include "dex/mir_graph.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070026#include "dex/quick/mir_to_lir-inl.h"
buzbeeb5860fb2014-06-21 15:31:01 -070027#include "dex/reg_storage_eq.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080028#include "driver/compiler_driver.h"
Ian Rogers166db042013-07-26 12:05:57 -070029#include "entrypoints/quick/quick_entrypoints.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070030#include "mirror/array-inl.h"
Andreas Gampe7e499922015-01-06 08:28:12 -080031#include "utils.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032
33namespace art {
34
buzbee2700f7e2014-03-07 09:46:20 -080035LIR* ArmMir2Lir::OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070036 OpRegReg(kOpCmp, src1, src2);
37 return OpCondBranch(cond, target);
38}
39
40/*
41 * Generate a Thumb2 IT instruction, which can nullify up to
42 * four subsequent instructions based on a condition and its
43 * inverse. The condition applies to the first instruction, which
44 * is executed if the condition is met. The string "guide" consists
45 * of 0 to 3 chars, and applies to the 2nd through 4th instruction.
46 * A "T" means the instruction is executed if the condition is
47 * met, and an "E" means the instruction is executed if the condition
48 * is not met.
49 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070050LIR* ArmMir2Lir::OpIT(ConditionCode ccode, const char* guide) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070051 int mask;
52 int mask3 = 0;
53 int mask2 = 0;
54 int mask1 = 0;
55 ArmConditionCode code = ArmConditionEncoding(ccode);
56 int cond_bit = code & 1;
57 int alt_bit = cond_bit ^ 1;
58
Brian Carlstrom7940e442013-07-12 13:46:57 -070059 switch (strlen(guide)) {
60 case 3:
61 mask1 = (guide[2] == 'T') ? cond_bit : alt_bit;
Ian Rogersfc787ec2014-10-09 21:56:44 -070062 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -070063 case 2:
64 mask2 = (guide[1] == 'T') ? cond_bit : alt_bit;
Ian Rogersfc787ec2014-10-09 21:56:44 -070065 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 case 1:
67 mask3 = (guide[0] == 'T') ? cond_bit : alt_bit;
68 break;
69 case 0:
70 break;
71 default:
72 LOG(FATAL) << "OAT: bad case in OpIT";
Ian Rogersfc787ec2014-10-09 21:56:44 -070073 UNREACHABLE();
Brian Carlstrom7940e442013-07-12 13:46:57 -070074 }
75 mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) |
76 (1 << (3 - strlen(guide)));
77 return NewLIR2(kThumb2It, code, mask);
78}
79
Andreas Gampeb14329f2014-05-15 11:16:06 -070080void ArmMir2Lir::UpdateIT(LIR* it, const char* new_guide) {
81 int mask;
82 int mask3 = 0;
83 int mask2 = 0;
84 int mask1 = 0;
85 ArmConditionCode code = static_cast<ArmConditionCode>(it->operands[0]);
86 int cond_bit = code & 1;
87 int alt_bit = cond_bit ^ 1;
88
Andreas Gampeb14329f2014-05-15 11:16:06 -070089 switch (strlen(new_guide)) {
90 case 3:
91 mask1 = (new_guide[2] == 'T') ? cond_bit : alt_bit;
Ian Rogersfc787ec2014-10-09 21:56:44 -070092 FALLTHROUGH_INTENDED;
Andreas Gampeb14329f2014-05-15 11:16:06 -070093 case 2:
94 mask2 = (new_guide[1] == 'T') ? cond_bit : alt_bit;
Ian Rogersfc787ec2014-10-09 21:56:44 -070095 FALLTHROUGH_INTENDED;
Andreas Gampeb14329f2014-05-15 11:16:06 -070096 case 1:
97 mask3 = (new_guide[0] == 'T') ? cond_bit : alt_bit;
98 break;
99 case 0:
100 break;
101 default:
102 LOG(FATAL) << "OAT: bad case in UpdateIT";
Ian Rogersfc787ec2014-10-09 21:56:44 -0700103 UNREACHABLE();
Andreas Gampeb14329f2014-05-15 11:16:06 -0700104 }
105 mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) |
106 (1 << (3 - strlen(new_guide)));
107 it->operands[1] = mask;
108}
109
Dave Allison3da67a52014-04-02 17:03:45 -0700110void ArmMir2Lir::OpEndIT(LIR* it) {
111 // TODO: use the 'it' pointer to do some checks with the LIR, for example
112 // we could check that the number of instructions matches the mask
113 // in the IT instruction.
114 CHECK(it != nullptr);
115 GenBarrier();
116}
117
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118/*
119 * 64-bit 3way compare function.
120 * mov rX, #-1
121 * cmp op1hi, op2hi
122 * blt done
123 * bgt flip
124 * sub rX, op1lo, op2lo (treat as unsigned)
125 * beq done
126 * ite hi
127 * mov(hi) rX, #-1
128 * mov(!hi) rX, #1
129 * flip:
130 * neg rX
131 * done:
132 */
buzbeea1983d42014-04-07 12:35:39 -0700133void ArmMir2Lir::GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134 LIR* target1;
135 LIR* target2;
136 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
137 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800138 RegStorage t_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139 LoadConstant(t_reg, -1);
buzbee2700f7e2014-03-07 09:46:20 -0800140 OpRegReg(kOpCmp, rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141 LIR* branch1 = OpCondBranch(kCondLt, NULL);
142 LIR* branch2 = OpCondBranch(kCondGt, NULL);
buzbeea1983d42014-04-07 12:35:39 -0700143 OpRegRegReg(kOpSub, t_reg, rl_src1.reg.GetLow(), rl_src2.reg.GetLow());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700144 LIR* branch3 = OpCondBranch(kCondEq, NULL);
145
Dave Allison3da67a52014-04-02 17:03:45 -0700146 LIR* it = OpIT(kCondHi, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800147 NewLIR2(kThumb2MovI8M, t_reg.GetReg(), ModifiedImmediate(-1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 LoadConstant(t_reg, 1);
Dave Allison3da67a52014-04-02 17:03:45 -0700149 OpEndIT(it);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150
151 target2 = NewLIR0(kPseudoTargetLabel);
152 OpRegReg(kOpNeg, t_reg, t_reg);
153
154 target1 = NewLIR0(kPseudoTargetLabel);
155
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700156 RegLocation rl_temp = LocCReturn(); // Just using as template, will change
buzbee2700f7e2014-03-07 09:46:20 -0800157 rl_temp.reg.SetReg(t_reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700158 StoreValue(rl_dest, rl_temp);
159 FreeTemp(t_reg);
160
161 branch1->target = target1;
162 branch2->target = target2;
163 branch3->target = branch1->target;
164}
165
166void ArmMir2Lir::GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700167 int64_t val, ConditionCode ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168 int32_t val_lo = Low32Bits(val);
169 int32_t val_hi = High32Bits(val);
Brian Carlstrom42748892013-07-18 18:04:08 -0700170 DCHECK_GE(ModifiedImmediate(val_lo), 0);
171 DCHECK_GE(ModifiedImmediate(val_hi), 0);
buzbee0d829482013-10-11 15:24:55 -0700172 LIR* taken = &block_label_list_[bb->taken];
173 LIR* not_taken = &block_label_list_[bb->fall_through];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800175 RegStorage low_reg = rl_src1.reg.GetLow();
176 RegStorage high_reg = rl_src1.reg.GetHigh();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700177
Vladimir Marko58af1f92013-12-19 13:31:15 +0000178 if (val == 0 && (ccode == kCondEq || ccode == kCondNe)) {
buzbee2700f7e2014-03-07 09:46:20 -0800179 RegStorage t_reg = AllocTemp();
180 NewLIR4(kThumb2OrrRRRs, t_reg.GetReg(), low_reg.GetReg(), high_reg.GetReg(), 0);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000181 FreeTemp(t_reg);
182 OpCondBranch(ccode, taken);
183 return;
184 }
185
Brian Carlstromdf629502013-07-17 22:39:56 -0700186 switch (ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700187 case kCondEq:
188 case kCondNe:
Vladimir Marko58af1f92013-12-19 13:31:15 +0000189 OpCmpImmBranch(kCondNe, high_reg, val_hi, (ccode == kCondEq) ? not_taken : taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700190 break;
191 case kCondLt:
192 OpCmpImmBranch(kCondLt, high_reg, val_hi, taken);
193 OpCmpImmBranch(kCondGt, high_reg, val_hi, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000194 ccode = kCondUlt;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700195 break;
196 case kCondLe:
197 OpCmpImmBranch(kCondLt, high_reg, val_hi, taken);
198 OpCmpImmBranch(kCondGt, high_reg, val_hi, not_taken);
199 ccode = kCondLs;
200 break;
201 case kCondGt:
202 OpCmpImmBranch(kCondGt, high_reg, val_hi, taken);
203 OpCmpImmBranch(kCondLt, high_reg, val_hi, not_taken);
204 ccode = kCondHi;
205 break;
206 case kCondGe:
207 OpCmpImmBranch(kCondGt, high_reg, val_hi, taken);
208 OpCmpImmBranch(kCondLt, high_reg, val_hi, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000209 ccode = kCondUge;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700210 break;
211 default:
212 LOG(FATAL) << "Unexpected ccode: " << ccode;
213 }
214 OpCmpImmBranch(ccode, low_reg, val_lo, taken);
215}
216
Andreas Gampe90969af2014-07-15 23:02:11 -0700217void ArmMir2Lir::GenSelectConst32(RegStorage left_op, RegStorage right_op, ConditionCode code,
218 int32_t true_val, int32_t false_val, RegStorage rs_dest,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700219 RegisterClass dest_reg_class) {
220 UNUSED(dest_reg_class);
Andreas Gampe90969af2014-07-15 23:02:11 -0700221 // TODO: Generalize the IT below to accept more than one-instruction loads.
222 DCHECK(InexpensiveConstantInt(true_val));
223 DCHECK(InexpensiveConstantInt(false_val));
224
225 if ((true_val == 0 && code == kCondEq) ||
226 (false_val == 0 && code == kCondNe)) {
227 OpRegRegReg(kOpSub, rs_dest, left_op, right_op);
228 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
229 LIR* it = OpIT(kCondNe, "");
230 LoadConstant(rs_dest, code == kCondEq ? false_val : true_val);
231 OpEndIT(it);
232 return;
233 }
234
235 OpRegReg(kOpCmp, left_op, right_op); // Same?
236 LIR* it = OpIT(code, "E"); // if-convert the test
237 LoadConstant(rs_dest, true_val); // .eq case - load true
238 LoadConstant(rs_dest, false_val); // .eq case - load true
239 OpEndIT(it);
240}
241
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700242void ArmMir2Lir::GenSelect(BasicBlock* bb, MIR* mir) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700243 UNUSED(bb);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244 RegLocation rl_result;
245 RegLocation rl_src = mir_graph_->GetSrc(mir, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700246 RegLocation rl_dest = mir_graph_->GetDest(mir);
buzbeea0cd2d72014-06-01 09:33:49 -0700247 // Avoid using float regs here.
248 RegisterClass src_reg_class = rl_src.ref ? kRefReg : kCoreReg;
249 RegisterClass result_reg_class = rl_dest.ref ? kRefReg : kCoreReg;
250 rl_src = LoadValue(rl_src, src_reg_class);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000251 ConditionCode ccode = mir->meta.ccode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700252 if (mir->ssa_rep->num_uses == 1) {
253 // CONST case
254 int true_val = mir->dalvikInsn.vB;
255 int false_val = mir->dalvikInsn.vC;
buzbeea0cd2d72014-06-01 09:33:49 -0700256 rl_result = EvalLoc(rl_dest, result_reg_class, true);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000257 // Change kCondNe to kCondEq for the special cases below.
258 if (ccode == kCondNe) {
259 ccode = kCondEq;
260 std::swap(true_val, false_val);
261 }
262 bool cheap_false_val = InexpensiveConstantInt(false_val);
263 if (cheap_false_val && ccode == kCondEq && (true_val == 0 || true_val == -1)) {
buzbee2700f7e2014-03-07 09:46:20 -0800264 OpRegRegImm(kOpSub, rl_result.reg, rl_src.reg, -true_val);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100265 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Dave Allison3da67a52014-04-02 17:03:45 -0700266 LIR* it = OpIT(true_val == 0 ? kCondNe : kCondUge, "");
buzbee2700f7e2014-03-07 09:46:20 -0800267 LoadConstant(rl_result.reg, false_val);
Dave Allison3da67a52014-04-02 17:03:45 -0700268 OpEndIT(it); // Add a scheduling barrier to keep the IT shadow intact
Vladimir Markoa1a70742014-03-03 10:28:05 +0000269 } else if (cheap_false_val && ccode == kCondEq && true_val == 1) {
buzbee2700f7e2014-03-07 09:46:20 -0800270 OpRegRegImm(kOpRsub, rl_result.reg, rl_src.reg, 1);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100271 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Dave Allison3da67a52014-04-02 17:03:45 -0700272 LIR* it = OpIT(kCondLs, "");
buzbee2700f7e2014-03-07 09:46:20 -0800273 LoadConstant(rl_result.reg, false_val);
Dave Allison3da67a52014-04-02 17:03:45 -0700274 OpEndIT(it); // Add a scheduling barrier to keep the IT shadow intact
Vladimir Markoa1a70742014-03-03 10:28:05 +0000275 } else if (cheap_false_val && InexpensiveConstantInt(true_val)) {
buzbee2700f7e2014-03-07 09:46:20 -0800276 OpRegImm(kOpCmp, rl_src.reg, 0);
Dave Allison3da67a52014-04-02 17:03:45 -0700277 LIR* it = OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800278 LoadConstant(rl_result.reg, true_val);
279 LoadConstant(rl_result.reg, false_val);
Dave Allison3da67a52014-04-02 17:03:45 -0700280 OpEndIT(it); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700281 } else {
282 // Unlikely case - could be tuned.
buzbeea0cd2d72014-06-01 09:33:49 -0700283 RegStorage t_reg1 = AllocTypedTemp(false, result_reg_class);
284 RegStorage t_reg2 = AllocTypedTemp(false, result_reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700285 LoadConstant(t_reg1, true_val);
286 LoadConstant(t_reg2, false_val);
buzbee2700f7e2014-03-07 09:46:20 -0800287 OpRegImm(kOpCmp, rl_src.reg, 0);
Dave Allison3da67a52014-04-02 17:03:45 -0700288 LIR* it = OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800289 OpRegCopy(rl_result.reg, t_reg1);
290 OpRegCopy(rl_result.reg, t_reg2);
Dave Allison3da67a52014-04-02 17:03:45 -0700291 OpEndIT(it); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700292 }
293 } else {
294 // MOVE case
295 RegLocation rl_true = mir_graph_->reg_location_[mir->ssa_rep->uses[1]];
296 RegLocation rl_false = mir_graph_->reg_location_[mir->ssa_rep->uses[2]];
buzbeea0cd2d72014-06-01 09:33:49 -0700297 rl_true = LoadValue(rl_true, result_reg_class);
298 rl_false = LoadValue(rl_false, result_reg_class);
299 rl_result = EvalLoc(rl_dest, result_reg_class, true);
buzbee2700f7e2014-03-07 09:46:20 -0800300 OpRegImm(kOpCmp, rl_src.reg, 0);
Dave Allison3da67a52014-04-02 17:03:45 -0700301 LIR* it = nullptr;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000302 if (rl_result.reg.GetReg() == rl_true.reg.GetReg()) { // Is the "true" case already in place?
Dave Allison3da67a52014-04-02 17:03:45 -0700303 it = OpIT(NegateComparison(ccode), "");
buzbee2700f7e2014-03-07 09:46:20 -0800304 OpRegCopy(rl_result.reg, rl_false.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000305 } else if (rl_result.reg.GetReg() == rl_false.reg.GetReg()) { // False case in place?
Dave Allison3da67a52014-04-02 17:03:45 -0700306 it = OpIT(ccode, "");
buzbee2700f7e2014-03-07 09:46:20 -0800307 OpRegCopy(rl_result.reg, rl_true.reg);
buzbee252254b2013-09-08 16:20:53 -0700308 } else { // Normal - select between the two.
Dave Allison3da67a52014-04-02 17:03:45 -0700309 it = OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800310 OpRegCopy(rl_result.reg, rl_true.reg);
311 OpRegCopy(rl_result.reg, rl_false.reg);
buzbee252254b2013-09-08 16:20:53 -0700312 }
Dave Allison3da67a52014-04-02 17:03:45 -0700313 OpEndIT(it); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 }
315 StoreValue(rl_dest, rl_result);
316}
317
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700318void ArmMir2Lir::GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700319 RegLocation rl_src1 = mir_graph_->GetSrcWide(mir, 0);
320 RegLocation rl_src2 = mir_graph_->GetSrcWide(mir, 2);
321 // Normalize such that if either operand is constant, src2 will be constant.
Vladimir Markoa8946072014-01-22 10:30:44 +0000322 ConditionCode ccode = mir->meta.ccode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700323 if (rl_src1.is_const) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000324 std::swap(rl_src1, rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700325 ccode = FlipComparisonOrder(ccode);
326 }
327 if (rl_src2.is_const) {
buzbee082833c2014-05-17 23:16:26 -0700328 rl_src2 = UpdateLocWide(rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700329 // Do special compare/branch against simple const operand if not already in registers.
330 int64_t val = mir_graph_->ConstantValueWide(rl_src2);
buzbee082833c2014-05-17 23:16:26 -0700331 if ((rl_src2.location != kLocPhysReg) &&
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332 ((ModifiedImmediate(Low32Bits(val)) >= 0) && (ModifiedImmediate(High32Bits(val)) >= 0))) {
333 GenFusedLongCmpImmBranch(bb, rl_src1, val, ccode);
334 return;
335 }
336 }
buzbee0d829482013-10-11 15:24:55 -0700337 LIR* taken = &block_label_list_[bb->taken];
338 LIR* not_taken = &block_label_list_[bb->fall_through];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700339 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
340 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800341 OpRegReg(kOpCmp, rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstromdf629502013-07-17 22:39:56 -0700342 switch (ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700343 case kCondEq:
344 OpCondBranch(kCondNe, not_taken);
345 break;
346 case kCondNe:
347 OpCondBranch(kCondNe, taken);
348 break;
349 case kCondLt:
350 OpCondBranch(kCondLt, taken);
351 OpCondBranch(kCondGt, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000352 ccode = kCondUlt;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700353 break;
354 case kCondLe:
355 OpCondBranch(kCondLt, taken);
356 OpCondBranch(kCondGt, not_taken);
357 ccode = kCondLs;
358 break;
359 case kCondGt:
360 OpCondBranch(kCondGt, taken);
361 OpCondBranch(kCondLt, not_taken);
362 ccode = kCondHi;
363 break;
364 case kCondGe:
365 OpCondBranch(kCondGt, taken);
366 OpCondBranch(kCondLt, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000367 ccode = kCondUge;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700368 break;
369 default:
370 LOG(FATAL) << "Unexpected ccode: " << ccode;
371 }
buzbee2700f7e2014-03-07 09:46:20 -0800372 OpRegReg(kOpCmp, rl_src1.reg.GetLow(), rl_src2.reg.GetLow());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700373 OpCondBranch(ccode, taken);
374}
375
376/*
377 * Generate a register comparison to an immediate and branch. Caller
378 * is responsible for setting branch target field.
379 */
buzbee2700f7e2014-03-07 09:46:20 -0800380LIR* ArmMir2Lir::OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) {
Andreas Gampe9522af92014-07-14 20:16:59 -0700381 LIR* branch = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700382 ArmConditionCode arm_cond = ArmConditionEncoding(cond);
buzbeeb48819d2013-09-14 16:15:25 -0700383 /*
384 * A common use of OpCmpImmBranch is for null checks, and using the Thumb 16-bit
385 * compare-and-branch if zero is ideal if it will reach. However, because null checks
Mingyao Yang3a74d152014-04-21 15:39:44 -0700386 * branch forward to a slow path, they will frequently not reach - and thus have to
buzbeeb48819d2013-09-14 16:15:25 -0700387 * be converted to a long form during assembly (which will trigger another assembly
388 * pass). Here we estimate the branch distance for checks, and if large directly
389 * generate the long form in an attempt to avoid an extra assembly pass.
Mingyao Yang3a74d152014-04-21 15:39:44 -0700390 * TODO: consider interspersing slowpaths in code following unconditional branches.
buzbeeb48819d2013-09-14 16:15:25 -0700391 */
392 bool skip = ((target != NULL) && (target->opcode == kPseudoThrowTarget));
Razvan A Lupusoru75035972014-09-11 15:24:59 -0700393 skip &= ((mir_graph_->GetNumDalvikInsns() - current_dalvik_offset_) > 64);
Andreas Gampe9522af92014-07-14 20:16:59 -0700394 if (!skip && reg.Low8() && (check_value == 0)) {
395 if (arm_cond == kArmCondEq || arm_cond == kArmCondNe) {
396 branch = NewLIR2((arm_cond == kArmCondEq) ? kThumb2Cbz : kThumb2Cbnz,
397 reg.GetReg(), 0);
398 } else if (arm_cond == kArmCondLs) {
399 // kArmCondLs is an unsigned less or equal. A comparison r <= 0 is then the same as cbz.
400 // This case happens for a bounds check of array[0].
401 branch = NewLIR2(kThumb2Cbz, reg.GetReg(), 0);
402 }
403 }
404
405 if (branch == nullptr) {
Vladimir Marko22479842013-11-19 17:04:50 +0000406 OpRegImm(kOpCmp, reg, check_value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407 branch = NewLIR2(kThumbBCond, 0, arm_cond);
408 }
Andreas Gampe9522af92014-07-14 20:16:59 -0700409
Brian Carlstrom7940e442013-07-12 13:46:57 -0700410 branch->target = target;
411 return branch;
412}
413
buzbee2700f7e2014-03-07 09:46:20 -0800414LIR* ArmMir2Lir::OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700415 LIR* res;
416 int opcode;
buzbee2700f7e2014-03-07 09:46:20 -0800417 // If src or dest is a pair, we'll be using low reg.
418 if (r_dest.IsPair()) {
419 r_dest = r_dest.GetLow();
420 }
421 if (r_src.IsPair()) {
422 r_src = r_src.GetLow();
423 }
buzbee091cc402014-03-31 10:14:40 -0700424 if (r_dest.IsFloat() || r_src.IsFloat())
Brian Carlstrom7940e442013-07-12 13:46:57 -0700425 return OpFpRegCopy(r_dest, r_src);
buzbee091cc402014-03-31 10:14:40 -0700426 if (r_dest.Low8() && r_src.Low8())
Brian Carlstrom7940e442013-07-12 13:46:57 -0700427 opcode = kThumbMovRR;
buzbee091cc402014-03-31 10:14:40 -0700428 else if (!r_dest.Low8() && !r_src.Low8())
Brian Carlstrom7940e442013-07-12 13:46:57 -0700429 opcode = kThumbMovRR_H2H;
buzbee091cc402014-03-31 10:14:40 -0700430 else if (r_dest.Low8())
Brian Carlstrom7940e442013-07-12 13:46:57 -0700431 opcode = kThumbMovRR_H2L;
432 else
433 opcode = kThumbMovRR_L2H;
buzbee2700f7e2014-03-07 09:46:20 -0800434 res = RawLIR(current_dalvik_offset_, opcode, r_dest.GetReg(), r_src.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700435 if (!(cu_->disable_opt & (1 << kSafeOptimizations)) && r_dest == r_src) {
436 res->flags.is_nop = true;
437 }
438 return res;
439}
440
buzbee7a11ab02014-04-28 20:02:38 -0700441void ArmMir2Lir::OpRegCopy(RegStorage r_dest, RegStorage r_src) {
442 if (r_dest != r_src) {
443 LIR* res = OpRegCopyNoInsert(r_dest, r_src);
444 AppendLIR(res);
445 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700446}
447
buzbee2700f7e2014-03-07 09:46:20 -0800448void ArmMir2Lir::OpRegCopyWide(RegStorage r_dest, RegStorage r_src) {
buzbee7a11ab02014-04-28 20:02:38 -0700449 if (r_dest != r_src) {
buzbee091cc402014-03-31 10:14:40 -0700450 bool dest_fp = r_dest.IsFloat();
451 bool src_fp = r_src.IsFloat();
452 DCHECK(r_dest.Is64Bit());
453 DCHECK(r_src.Is64Bit());
Zheng Xu5667fdb2014-10-23 18:29:55 +0800454 // Note: If the register is get by register allocator, it should never be a pair.
455 // But some functions in mir_2_lir assume 64-bit registers are 32-bit register pairs.
456 // TODO: Rework Mir2Lir::LoadArg() and Mir2Lir::LoadArgDirect().
457 if (dest_fp && r_dest.IsPair()) {
458 r_dest = As64BitFloatReg(r_dest);
459 }
460 if (src_fp && r_src.IsPair()) {
461 r_src = As64BitFloatReg(r_src);
462 }
buzbee7a11ab02014-04-28 20:02:38 -0700463 if (dest_fp) {
464 if (src_fp) {
buzbee091cc402014-03-31 10:14:40 -0700465 OpRegCopy(r_dest, r_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700466 } else {
buzbee091cc402014-03-31 10:14:40 -0700467 NewLIR3(kThumb2Fmdrr, r_dest.GetReg(), r_src.GetLowReg(), r_src.GetHighReg());
buzbee7a11ab02014-04-28 20:02:38 -0700468 }
469 } else {
470 if (src_fp) {
buzbee091cc402014-03-31 10:14:40 -0700471 NewLIR3(kThumb2Fmrrd, r_dest.GetLowReg(), r_dest.GetHighReg(), r_src.GetReg());
buzbee7a11ab02014-04-28 20:02:38 -0700472 } else {
473 // Handle overlap
474 if (r_src.GetHighReg() == r_dest.GetLowReg()) {
475 DCHECK_NE(r_src.GetLowReg(), r_dest.GetHighReg());
476 OpRegCopy(r_dest.GetHigh(), r_src.GetHigh());
477 OpRegCopy(r_dest.GetLow(), r_src.GetLow());
478 } else {
479 OpRegCopy(r_dest.GetLow(), r_src.GetLow());
480 OpRegCopy(r_dest.GetHigh(), r_src.GetHigh());
481 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700482 }
483 }
484 }
485}
486
487// Table of magic divisors
488struct MagicTable {
489 uint32_t magic;
490 uint32_t shift;
491 DividePattern pattern;
492};
493
494static const MagicTable magic_table[] = {
495 {0, 0, DivideNone}, // 0
496 {0, 0, DivideNone}, // 1
497 {0, 0, DivideNone}, // 2
498 {0x55555556, 0, Divide3}, // 3
499 {0, 0, DivideNone}, // 4
500 {0x66666667, 1, Divide5}, // 5
501 {0x2AAAAAAB, 0, Divide3}, // 6
502 {0x92492493, 2, Divide7}, // 7
503 {0, 0, DivideNone}, // 8
504 {0x38E38E39, 1, Divide5}, // 9
505 {0x66666667, 2, Divide5}, // 10
506 {0x2E8BA2E9, 1, Divide5}, // 11
507 {0x2AAAAAAB, 1, Divide5}, // 12
508 {0x4EC4EC4F, 2, Divide5}, // 13
509 {0x92492493, 3, Divide7}, // 14
510 {0x88888889, 3, Divide7}, // 15
511};
512
513// Integer division by constant via reciprocal multiply (Hacker's Delight, 10-4)
buzbee11b63d12013-08-27 07:34:17 -0700514bool ArmMir2Lir::SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700515 RegLocation rl_src, RegLocation rl_dest, int lit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700516 UNUSED(dalvik_opcode);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700517 if ((lit < 0) || (lit >= static_cast<int>(sizeof(magic_table)/sizeof(magic_table[0])))) {
518 return false;
519 }
520 DividePattern pattern = magic_table[lit].pattern;
521 if (pattern == DivideNone) {
522 return false;
523 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700524
buzbee2700f7e2014-03-07 09:46:20 -0800525 RegStorage r_magic = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700526 LoadConstant(r_magic, magic_table[lit].magic);
527 rl_src = LoadValue(rl_src, kCoreReg);
528 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800529 RegStorage r_hi = AllocTemp();
530 RegStorage r_lo = AllocTemp();
Zheng Xuf9719f92014-04-02 13:31:31 +0100531
532 // rl_dest and rl_src might overlap.
533 // Reuse r_hi to save the div result for reminder case.
534 RegStorage r_div_result = is_div ? rl_result.reg : r_hi;
535
buzbee2700f7e2014-03-07 09:46:20 -0800536 NewLIR4(kThumb2Smull, r_lo.GetReg(), r_hi.GetReg(), r_magic.GetReg(), rl_src.reg.GetReg());
Brian Carlstromdf629502013-07-17 22:39:56 -0700537 switch (pattern) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700538 case Divide3:
Zheng Xuf9719f92014-04-02 13:31:31 +0100539 OpRegRegRegShift(kOpSub, r_div_result, r_hi, rl_src.reg, EncodeShift(kArmAsr, 31));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700540 break;
541 case Divide5:
buzbee2700f7e2014-03-07 09:46:20 -0800542 OpRegRegImm(kOpAsr, r_lo, rl_src.reg, 31);
Zheng Xuf9719f92014-04-02 13:31:31 +0100543 OpRegRegRegShift(kOpRsub, r_div_result, r_lo, r_hi,
Ian Rogerse2143c02014-03-28 08:47:16 -0700544 EncodeShift(kArmAsr, magic_table[lit].shift));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700545 break;
546 case Divide7:
buzbee2700f7e2014-03-07 09:46:20 -0800547 OpRegReg(kOpAdd, r_hi, rl_src.reg);
548 OpRegRegImm(kOpAsr, r_lo, rl_src.reg, 31);
Zheng Xuf9719f92014-04-02 13:31:31 +0100549 OpRegRegRegShift(kOpRsub, r_div_result, r_lo, r_hi,
Ian Rogerse2143c02014-03-28 08:47:16 -0700550 EncodeShift(kArmAsr, magic_table[lit].shift));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700551 break;
552 default:
553 LOG(FATAL) << "Unexpected pattern: " << pattern;
554 }
Zheng Xuf9719f92014-04-02 13:31:31 +0100555
556 if (!is_div) {
557 // div_result = src / lit
558 // tmp1 = div_result * lit
559 // dest = src - tmp1
560 RegStorage tmp1 = r_lo;
561 EasyMultiplyOp ops[2];
562
563 bool canEasyMultiply = GetEasyMultiplyTwoOps(lit, ops);
564 DCHECK_NE(canEasyMultiply, false);
565
566 GenEasyMultiplyTwoOps(tmp1, r_div_result, ops);
567 OpRegRegReg(kOpSub, rl_result.reg, rl_src.reg, tmp1);
568 }
569
Brian Carlstrom7940e442013-07-12 13:46:57 -0700570 StoreValue(rl_dest, rl_result);
571 return true;
572}
573
Ian Rogerse2143c02014-03-28 08:47:16 -0700574// Try to convert *lit to 1 RegRegRegShift/RegRegShift form.
575bool ArmMir2Lir::GetEasyMultiplyOp(int lit, ArmMir2Lir::EasyMultiplyOp* op) {
Andreas Gampecfe71e52015-01-05 19:30:59 -0800576 if (lit == 0) {
577 // Special case for *divide-by-zero*. The ops won't actually be used to generate code, as
578 // GenArithOpIntLit will directly generate exception-throwing code, and multiply-by-zero will
579 // have been optimized away earlier.
580 op->op = kOpInvalid;
Dmitry Petrochenkoddf05aa2015-01-14 15:54:20 +0600581 op->shift = 0;
Andreas Gampecfe71e52015-01-05 19:30:59 -0800582 return true;
583 }
584
Ian Rogerse2143c02014-03-28 08:47:16 -0700585 if (IsPowerOfTwo(lit)) {
586 op->op = kOpLsl;
Andreas Gampe7e499922015-01-06 08:28:12 -0800587 op->shift = CTZ(lit);
Ian Rogerse2143c02014-03-28 08:47:16 -0700588 return true;
589 }
590
591 if (IsPowerOfTwo(lit - 1)) {
592 op->op = kOpAdd;
Andreas Gampe7e499922015-01-06 08:28:12 -0800593 op->shift = CTZ(lit - 1);
Ian Rogerse2143c02014-03-28 08:47:16 -0700594 return true;
595 }
596
597 if (IsPowerOfTwo(lit + 1)) {
598 op->op = kOpRsub;
Andreas Gampe7e499922015-01-06 08:28:12 -0800599 op->shift = CTZ(lit + 1);
Ian Rogerse2143c02014-03-28 08:47:16 -0700600 return true;
601 }
602
603 op->op = kOpInvalid;
Zheng Xuf9719f92014-04-02 13:31:31 +0100604 op->shift = 0;
Ian Rogerse2143c02014-03-28 08:47:16 -0700605 return false;
606}
607
608// Try to convert *lit to 1~2 RegRegRegShift/RegRegShift forms.
609bool ArmMir2Lir::GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops) {
Ian Rogerse2143c02014-03-28 08:47:16 -0700610 if (GetEasyMultiplyOp(lit, &ops[0])) {
611 ops[1].op = kOpInvalid;
Zheng Xuf9719f92014-04-02 13:31:31 +0100612 ops[1].shift = 0;
Ian Rogerse2143c02014-03-28 08:47:16 -0700613 return true;
614 }
615
616 int lit1 = lit;
Andreas Gampe7e499922015-01-06 08:28:12 -0800617 uint32_t shift = CTZ(lit1);
Ian Rogerse2143c02014-03-28 08:47:16 -0700618 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
619 ops[1].op = kOpLsl;
620 ops[1].shift = shift;
621 return true;
622 }
623
624 lit1 = lit - 1;
Andreas Gampe7e499922015-01-06 08:28:12 -0800625 shift = CTZ(lit1);
Ian Rogerse2143c02014-03-28 08:47:16 -0700626 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
627 ops[1].op = kOpAdd;
628 ops[1].shift = shift;
629 return true;
630 }
631
632 lit1 = lit + 1;
Andreas Gampe7e499922015-01-06 08:28:12 -0800633 shift = CTZ(lit1);
Ian Rogerse2143c02014-03-28 08:47:16 -0700634 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
635 ops[1].op = kOpRsub;
636 ops[1].shift = shift;
637 return true;
638 }
639
640 return false;
641}
642
Zheng Xuf9719f92014-04-02 13:31:31 +0100643// Generate instructions to do multiply.
644// Additional temporary register is required,
645// if it need to generate 2 instructions and src/dest overlap.
Ian Rogerse2143c02014-03-28 08:47:16 -0700646void ArmMir2Lir::GenEasyMultiplyTwoOps(RegStorage r_dest, RegStorage r_src, EasyMultiplyOp* ops) {
Zheng Xuf9719f92014-04-02 13:31:31 +0100647 // tmp1 = ( src << shift1) + [ src | -src | 0 ]
648 // dest = (tmp1 << shift2) + [ src | -src | 0 ]
649
650 RegStorage r_tmp1;
651 if (ops[1].op == kOpInvalid) {
652 r_tmp1 = r_dest;
653 } else if (r_dest.GetReg() != r_src.GetReg()) {
654 r_tmp1 = r_dest;
655 } else {
656 r_tmp1 = AllocTemp();
657 }
658
659 switch (ops[0].op) {
Ian Rogerse2143c02014-03-28 08:47:16 -0700660 case kOpLsl:
Zheng Xuf9719f92014-04-02 13:31:31 +0100661 OpRegRegImm(kOpLsl, r_tmp1, r_src, ops[0].shift);
Ian Rogerse2143c02014-03-28 08:47:16 -0700662 break;
663 case kOpAdd:
Zheng Xuf9719f92014-04-02 13:31:31 +0100664 OpRegRegRegShift(kOpAdd, r_tmp1, r_src, r_src, EncodeShift(kArmLsl, ops[0].shift));
Ian Rogerse2143c02014-03-28 08:47:16 -0700665 break;
666 case kOpRsub:
Zheng Xuf9719f92014-04-02 13:31:31 +0100667 OpRegRegRegShift(kOpRsub, r_tmp1, r_src, r_src, EncodeShift(kArmLsl, ops[0].shift));
Ian Rogerse2143c02014-03-28 08:47:16 -0700668 break;
669 default:
Zheng Xuf9719f92014-04-02 13:31:31 +0100670 DCHECK_EQ(ops[0].op, kOpInvalid);
Ian Rogerse2143c02014-03-28 08:47:16 -0700671 break;
Zheng Xuf9719f92014-04-02 13:31:31 +0100672 }
673
674 switch (ops[1].op) {
675 case kOpInvalid:
676 return;
677 case kOpLsl:
678 OpRegRegImm(kOpLsl, r_dest, r_tmp1, ops[1].shift);
679 break;
680 case kOpAdd:
681 OpRegRegRegShift(kOpAdd, r_dest, r_src, r_tmp1, EncodeShift(kArmLsl, ops[1].shift));
682 break;
683 case kOpRsub:
684 OpRegRegRegShift(kOpRsub, r_dest, r_src, r_tmp1, EncodeShift(kArmLsl, ops[1].shift));
685 break;
686 default:
687 LOG(FATAL) << "Unexpected opcode passed to GenEasyMultiplyTwoOps";
688 break;
Ian Rogerse2143c02014-03-28 08:47:16 -0700689 }
690}
691
692bool ArmMir2Lir::EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) {
693 EasyMultiplyOp ops[2];
694
695 if (!GetEasyMultiplyTwoOps(lit, ops)) {
696 return false;
697 }
698
699 rl_src = LoadValue(rl_src, kCoreReg);
700 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
701
702 GenEasyMultiplyTwoOps(rl_result.reg, rl_src.reg, ops);
703 StoreValue(rl_dest, rl_result);
704 return true;
705}
706
Mark Mendell2bf31e62014-01-23 12:13:40 -0800707RegLocation ArmMir2Lir::GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700708 RegLocation rl_src2, bool is_div, int flags) {
709 UNUSED(rl_dest, rl_src1, rl_src2, is_div, flags);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800710 LOG(FATAL) << "Unexpected use of GenDivRem for Arm";
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700711 UNREACHABLE();
Mark Mendell2bf31e62014-01-23 12:13:40 -0800712}
713
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700714RegLocation ArmMir2Lir::GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit,
715 bool is_div) {
716 UNUSED(rl_dest, rl_src1, lit, is_div);
Mark Mendell2bf31e62014-01-23 12:13:40 -0800717 LOG(FATAL) << "Unexpected use of GenDivRemLit for Arm";
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700718 UNREACHABLE();
Mark Mendell2bf31e62014-01-23 12:13:40 -0800719}
720
buzbee2700f7e2014-03-07 09:46:20 -0800721RegLocation ArmMir2Lir::GenDivRemLit(RegLocation rl_dest, RegStorage reg1, int lit, bool is_div) {
Dave Allison70202782013-10-22 17:52:19 -0700722 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
723
724 // Put the literal in a temp.
buzbee2700f7e2014-03-07 09:46:20 -0800725 RegStorage lit_temp = AllocTemp();
Dave Allison70202782013-10-22 17:52:19 -0700726 LoadConstant(lit_temp, lit);
727 // Use the generic case for div/rem with arg2 in a register.
728 // TODO: The literal temp can be freed earlier during a modulus to reduce reg pressure.
729 rl_result = GenDivRem(rl_result, reg1, lit_temp, is_div);
730 FreeTemp(lit_temp);
731
732 return rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700733}
734
buzbee2700f7e2014-03-07 09:46:20 -0800735RegLocation ArmMir2Lir::GenDivRem(RegLocation rl_dest, RegStorage reg1, RegStorage reg2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700736 bool is_div) {
Dave Allison70202782013-10-22 17:52:19 -0700737 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
738 if (is_div) {
739 // Simple case, use sdiv instruction.
buzbee2700f7e2014-03-07 09:46:20 -0800740 OpRegRegReg(kOpDiv, rl_result.reg, reg1, reg2);
Dave Allison70202782013-10-22 17:52:19 -0700741 } else {
742 // Remainder case, use the following code:
743 // temp = reg1 / reg2 - integer division
744 // temp = temp * reg2
745 // dest = reg1 - temp
746
buzbee2700f7e2014-03-07 09:46:20 -0800747 RegStorage temp = AllocTemp();
Dave Allison70202782013-10-22 17:52:19 -0700748 OpRegRegReg(kOpDiv, temp, reg1, reg2);
749 OpRegReg(kOpMul, temp, reg2);
buzbee2700f7e2014-03-07 09:46:20 -0800750 OpRegRegReg(kOpSub, rl_result.reg, reg1, temp);
Dave Allison70202782013-10-22 17:52:19 -0700751 FreeTemp(temp);
752 }
753
754 return rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700755}
756
Serban Constantinescu23abec92014-07-02 16:13:38 +0100757bool ArmMir2Lir::GenInlinedMinMax(CallInfo* info, bool is_min, bool is_long) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700758 DCHECK_EQ(cu_->instruction_set, kThumb2);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100759 if (is_long) {
760 return false;
761 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700762 RegLocation rl_src1 = info->args[0];
763 RegLocation rl_src2 = info->args[1];
764 rl_src1 = LoadValue(rl_src1, kCoreReg);
765 rl_src2 = LoadValue(rl_src2, kCoreReg);
766 RegLocation rl_dest = InlineTarget(info);
767 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800768 OpRegReg(kOpCmp, rl_src1.reg, rl_src2.reg);
Dave Allison3da67a52014-04-02 17:03:45 -0700769 LIR* it = OpIT((is_min) ? kCondGt : kCondLt, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800770 OpRegReg(kOpMov, rl_result.reg, rl_src2.reg);
771 OpRegReg(kOpMov, rl_result.reg, rl_src1.reg);
Dave Allison3da67a52014-04-02 17:03:45 -0700772 OpEndIT(it);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700773 StoreValue(rl_dest, rl_result);
774 return true;
775}
776
Vladimir Markoe508a202013-11-04 15:24:22 +0000777bool ArmMir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) {
778 RegLocation rl_src_address = info->args[0]; // long address
buzbee2700f7e2014-03-07 09:46:20 -0800779 rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1]
Vladimir Markoe508a202013-11-04 15:24:22 +0000780 RegLocation rl_dest = InlineTarget(info);
781 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
782 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee695d13a2014-04-19 13:32:20 -0700783 if (size == k64) {
Vladimir Markoe508a202013-11-04 15:24:22 +0000784 // Fake unaligned LDRD by two unaligned LDR instructions on ARMv7 with SCTLR.A set to 0.
buzbee2700f7e2014-03-07 09:46:20 -0800785 if (rl_address.reg.GetReg() != rl_result.reg.GetLowReg()) {
buzbee695d13a2014-04-19 13:32:20 -0700786 Load32Disp(rl_address.reg, 0, rl_result.reg.GetLow());
787 Load32Disp(rl_address.reg, 4, rl_result.reg.GetHigh());
Vladimir Markoe508a202013-11-04 15:24:22 +0000788 } else {
buzbee695d13a2014-04-19 13:32:20 -0700789 Load32Disp(rl_address.reg, 4, rl_result.reg.GetHigh());
790 Load32Disp(rl_address.reg, 0, rl_result.reg.GetLow());
Vladimir Markoe508a202013-11-04 15:24:22 +0000791 }
792 StoreValueWide(rl_dest, rl_result);
793 } else {
buzbee695d13a2014-04-19 13:32:20 -0700794 DCHECK(size == kSignedByte || size == kSignedHalf || size == k32);
Vladimir Markoe508a202013-11-04 15:24:22 +0000795 // Unaligned load with LDR and LDRSH is allowed on ARMv7 with SCTLR.A set to 0.
Andreas Gampe3c12c512014-06-24 18:46:29 +0000796 LoadBaseDisp(rl_address.reg, 0, rl_result.reg, size, kNotVolatile);
Vladimir Markoe508a202013-11-04 15:24:22 +0000797 StoreValue(rl_dest, rl_result);
798 }
799 return true;
800}
801
802bool ArmMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) {
803 RegLocation rl_src_address = info->args[0]; // long address
buzbee2700f7e2014-03-07 09:46:20 -0800804 rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1]
Vladimir Markoe508a202013-11-04 15:24:22 +0000805 RegLocation rl_src_value = info->args[2]; // [size] value
806 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
buzbee695d13a2014-04-19 13:32:20 -0700807 if (size == k64) {
Vladimir Markoe508a202013-11-04 15:24:22 +0000808 // Fake unaligned STRD by two unaligned STR instructions on ARMv7 with SCTLR.A set to 0.
809 RegLocation rl_value = LoadValueWide(rl_src_value, kCoreReg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000810 StoreBaseDisp(rl_address.reg, 0, rl_value.reg.GetLow(), k32, kNotVolatile);
811 StoreBaseDisp(rl_address.reg, 4, rl_value.reg.GetHigh(), k32, kNotVolatile);
Vladimir Markoe508a202013-11-04 15:24:22 +0000812 } else {
buzbee695d13a2014-04-19 13:32:20 -0700813 DCHECK(size == kSignedByte || size == kSignedHalf || size == k32);
Vladimir Markoe508a202013-11-04 15:24:22 +0000814 // Unaligned store with STR and STRSH is allowed on ARMv7 with SCTLR.A set to 0.
815 RegLocation rl_value = LoadValue(rl_src_value, kCoreReg);
Andreas Gampe3c12c512014-06-24 18:46:29 +0000816 StoreBaseDisp(rl_address.reg, 0, rl_value.reg, size, kNotVolatile);
Vladimir Markoe508a202013-11-04 15:24:22 +0000817 }
818 return true;
819}
820
Hans Boehm48f5c472014-06-27 14:50:10 -0700821// Generate a CAS with memory_order_seq_cst semantics.
Vladimir Marko1c282e22013-11-21 14:49:47 +0000822bool ArmMir2Lir::GenInlinedCas(CallInfo* info, bool is_long, bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700823 DCHECK_EQ(cu_->instruction_set, kThumb2);
824 // Unused - RegLocation rl_src_unsafe = info->args[0];
Vladimir Marko1c282e22013-11-21 14:49:47 +0000825 RegLocation rl_src_obj = info->args[1]; // Object - known non-null
826 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -0800827 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Vladimir Marko1c282e22013-11-21 14:49:47 +0000828 RegLocation rl_src_expected = info->args[4]; // int, long or Object
Vladimir Marko3e5af822013-11-21 15:01:20 +0000829 // If is_long, high half is in info->args[5]
830 RegLocation rl_src_new_value = info->args[is_long ? 6 : 5]; // int, long or Object
831 // If is_long, high half is in info->args[7]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700832 RegLocation rl_dest = InlineTarget(info); // boolean place for result
833
Vladimir Marko3e5af822013-11-21 15:01:20 +0000834 // We have only 5 temporary registers available and actually only 4 if the InlineTarget
835 // above locked one of the temps. For a straightforward CAS64 we need 7 registers:
836 // r_ptr (1), new_value (2), expected(2) and ldrexd result (2). If neither expected nor
837 // new_value is in a non-temp core register we shall reload them in the ldrex/strex loop
838 // into the same temps, reducing the number of required temps down to 5. We shall work
839 // around the potentially locked temp by using LR for r_ptr, unconditionally.
840 // TODO: Pass information about the need for more temps to the stack frame generation
841 // code so that we can rely on being able to allocate enough temps.
buzbee091cc402014-03-31 10:14:40 -0700842 DCHECK(!GetRegInfo(rs_rARM_LR)->IsTemp());
843 MarkTemp(rs_rARM_LR);
844 FreeTemp(rs_rARM_LR);
845 LockTemp(rs_rARM_LR);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000846 bool load_early = true;
847 if (is_long) {
buzbee091cc402014-03-31 10:14:40 -0700848 RegStorage expected_reg = rl_src_expected.reg.IsPair() ? rl_src_expected.reg.GetLow() :
849 rl_src_expected.reg;
850 RegStorage new_val_reg = rl_src_new_value.reg.IsPair() ? rl_src_new_value.reg.GetLow() :
851 rl_src_new_value.reg;
852 bool expected_is_core_reg = rl_src_expected.location == kLocPhysReg && !expected_reg.IsFloat();
853 bool new_value_is_core_reg = rl_src_new_value.location == kLocPhysReg && !new_val_reg.IsFloat();
buzbee2700f7e2014-03-07 09:46:20 -0800854 bool expected_is_good_reg = expected_is_core_reg && !IsTemp(expected_reg);
855 bool new_value_is_good_reg = new_value_is_core_reg && !IsTemp(new_val_reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000856
857 if (!expected_is_good_reg && !new_value_is_good_reg) {
858 // None of expected/new_value is non-temp reg, need to load both late
859 load_early = false;
860 // Make sure they are not in the temp regs and the load will not be skipped.
861 if (expected_is_core_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800862 FlushRegWide(rl_src_expected.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000863 ClobberSReg(rl_src_expected.s_reg_low);
864 ClobberSReg(GetSRegHi(rl_src_expected.s_reg_low));
865 rl_src_expected.location = kLocDalvikFrame;
866 }
867 if (new_value_is_core_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800868 FlushRegWide(rl_src_new_value.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000869 ClobberSReg(rl_src_new_value.s_reg_low);
870 ClobberSReg(GetSRegHi(rl_src_new_value.s_reg_low));
871 rl_src_new_value.location = kLocDalvikFrame;
872 }
873 }
874 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700875
Hans Boehm48f5c472014-06-27 14:50:10 -0700876 // Prevent reordering with prior memory operations.
877 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700878
buzbeea0cd2d72014-06-01 09:33:49 -0700879 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000880 RegLocation rl_new_value;
881 if (!is_long) {
buzbee7c02e912014-10-03 13:14:17 -0700882 rl_new_value = LoadValue(rl_src_new_value, LocToRegClass(rl_src_new_value));
Vladimir Marko3e5af822013-11-21 15:01:20 +0000883 } else if (load_early) {
884 rl_new_value = LoadValueWide(rl_src_new_value, kCoreReg);
885 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700886
Vladimir Marko1c282e22013-11-21 14:49:47 +0000887 if (is_object && !mir_graph_->IsConstantNullRef(rl_new_value)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700888 // Mark card for object assuming new value is stored.
Vladimir Marko743b98c2014-11-24 19:45:41 +0000889 MarkGCCard(0, rl_new_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700890 }
891
892 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
893
buzbee2700f7e2014-03-07 09:46:20 -0800894 RegStorage r_ptr = rs_rARM_LR;
895 OpRegRegReg(kOpAdd, r_ptr, rl_object.reg, rl_offset.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700896
897 // Free now unneeded rl_object and rl_offset to give more temps.
898 ClobberSReg(rl_object.s_reg_low);
buzbee091cc402014-03-31 10:14:40 -0700899 FreeTemp(rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700900 ClobberSReg(rl_offset.s_reg_low);
buzbee091cc402014-03-31 10:14:40 -0700901 FreeTemp(rl_offset.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700902
Vladimir Marko3e5af822013-11-21 15:01:20 +0000903 RegLocation rl_expected;
904 if (!is_long) {
buzbee7c02e912014-10-03 13:14:17 -0700905 rl_expected = LoadValue(rl_src_expected, LocToRegClass(rl_src_new_value));
Vladimir Marko3e5af822013-11-21 15:01:20 +0000906 } else if (load_early) {
907 rl_expected = LoadValueWide(rl_src_expected, kCoreReg);
908 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000909 // NOTE: partially defined rl_expected & rl_new_value - but we just want the regs.
buzbee091cc402014-03-31 10:14:40 -0700910 RegStorage low_reg = AllocTemp();
911 RegStorage high_reg = AllocTemp();
912 rl_new_value.reg = RegStorage::MakeRegPair(low_reg, high_reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000913 rl_expected = rl_new_value;
Vladimir Marko3e5af822013-11-21 15:01:20 +0000914 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700915
Vladimir Marko3e5af822013-11-21 15:01:20 +0000916 // do {
917 // tmp = [r_ptr] - expected;
918 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
919 // result = tmp != 0;
920
buzbee2700f7e2014-03-07 09:46:20 -0800921 RegStorage r_tmp = AllocTemp();
Jeff Hao2de2aa12013-09-12 17:20:31 -0700922 LIR* target = NewLIR0(kPseudoTargetLabel);
Jeff Hao2de2aa12013-09-12 17:20:31 -0700923
Dave Allison3da67a52014-04-02 17:03:45 -0700924 LIR* it = nullptr;
Vladimir Marko3e5af822013-11-21 15:01:20 +0000925 if (is_long) {
buzbee2700f7e2014-03-07 09:46:20 -0800926 RegStorage r_tmp_high = AllocTemp();
Vladimir Marko3e5af822013-11-21 15:01:20 +0000927 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800928 LoadValueDirectWide(rl_src_expected, rl_expected.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000929 }
buzbee2700f7e2014-03-07 09:46:20 -0800930 NewLIR3(kThumb2Ldrexd, r_tmp.GetReg(), r_tmp_high.GetReg(), r_ptr.GetReg());
931 OpRegReg(kOpSub, r_tmp, rl_expected.reg.GetLow());
932 OpRegReg(kOpSub, r_tmp_high, rl_expected.reg.GetHigh());
Vladimir Marko3e5af822013-11-21 15:01:20 +0000933 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800934 LoadValueDirectWide(rl_src_new_value, rl_new_value.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000935 }
936 // Make sure we use ORR that sets the ccode
buzbee091cc402014-03-31 10:14:40 -0700937 if (r_tmp.Low8() && r_tmp_high.Low8()) {
buzbee2700f7e2014-03-07 09:46:20 -0800938 NewLIR2(kThumbOrr, r_tmp.GetReg(), r_tmp_high.GetReg());
Vladimir Marko3e5af822013-11-21 15:01:20 +0000939 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800940 NewLIR4(kThumb2OrrRRRs, r_tmp.GetReg(), r_tmp.GetReg(), r_tmp_high.GetReg(), 0);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000941 }
942 FreeTemp(r_tmp_high); // Now unneeded
943
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100944 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Dave Allison3da67a52014-04-02 17:03:45 -0700945 it = OpIT(kCondEq, "T");
buzbee2700f7e2014-03-07 09:46:20 -0800946 NewLIR4(kThumb2Strexd /* eq */, r_tmp.GetReg(), rl_new_value.reg.GetLowReg(), rl_new_value.reg.GetHighReg(), r_ptr.GetReg());
Vladimir Marko3e5af822013-11-21 15:01:20 +0000947
948 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800949 NewLIR3(kThumb2Ldrex, r_tmp.GetReg(), r_ptr.GetReg(), 0);
950 OpRegReg(kOpSub, r_tmp, rl_expected.reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100951 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Dave Allison3da67a52014-04-02 17:03:45 -0700952 it = OpIT(kCondEq, "T");
buzbee2700f7e2014-03-07 09:46:20 -0800953 NewLIR4(kThumb2Strex /* eq */, r_tmp.GetReg(), rl_new_value.reg.GetReg(), r_ptr.GetReg(), 0);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000954 }
955
956 // Still one conditional left from OpIT(kCondEq, "T") from either branch
957 OpRegImm(kOpCmp /* eq */, r_tmp, 1);
Dave Allison3da67a52014-04-02 17:03:45 -0700958 OpEndIT(it);
Dave Allison43a065c2014-04-01 15:14:46 -0700959
Jeff Hao2de2aa12013-09-12 17:20:31 -0700960 OpCondBranch(kCondEq, target);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700961
Vladimir Marko3e5af822013-11-21 15:01:20 +0000962 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800963 FreeTemp(rl_expected.reg); // Now unneeded.
Vladimir Marko3e5af822013-11-21 15:01:20 +0000964 }
965
Hans Boehm48f5c472014-06-27 14:50:10 -0700966 // Prevent reordering with subsequent memory operations.
967 GenMemBarrier(kLoadAny);
968
Vladimir Marko3e5af822013-11-21 15:01:20 +0000969 // result := (tmp1 != 0) ? 0 : 1;
970 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800971 OpRegRegImm(kOpRsub, rl_result.reg, r_tmp, 1);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100972 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Dave Allison3da67a52014-04-02 17:03:45 -0700973 it = OpIT(kCondUlt, "");
buzbee2700f7e2014-03-07 09:46:20 -0800974 LoadConstant(rl_result.reg, 0); /* cc */
Vladimir Marko3e5af822013-11-21 15:01:20 +0000975 FreeTemp(r_tmp); // Now unneeded.
Dave Allison3da67a52014-04-02 17:03:45 -0700976 OpEndIT(it); // Barrier to terminate OpIT.
Vladimir Marko3e5af822013-11-21 15:01:20 +0000977
Brian Carlstrom7940e442013-07-12 13:46:57 -0700978 StoreValue(rl_dest, rl_result);
979
Vladimir Marko3e5af822013-11-21 15:01:20 +0000980 // Now, restore lr to its non-temp status.
buzbee091cc402014-03-31 10:14:40 -0700981 Clobber(rs_rARM_LR);
982 UnmarkTemp(rs_rARM_LR);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700983 return true;
984}
985
Zheng Xu947717a2014-08-07 14:05:23 +0800986bool ArmMir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
987 constexpr int kLargeArrayThreshold = 256;
988
989 RegLocation rl_src = info->args[0];
990 RegLocation rl_src_pos = info->args[1];
991 RegLocation rl_dst = info->args[2];
992 RegLocation rl_dst_pos = info->args[3];
993 RegLocation rl_length = info->args[4];
994 // Compile time check, handle exception by non-inline method to reduce related meta-data.
995 if ((rl_src_pos.is_const && (mir_graph_->ConstantValue(rl_src_pos) < 0)) ||
996 (rl_dst_pos.is_const && (mir_graph_->ConstantValue(rl_dst_pos) < 0)) ||
997 (rl_length.is_const && (mir_graph_->ConstantValue(rl_length) < 0))) {
998 return false;
999 }
1000
1001 ClobberCallerSave();
1002 LockCallTemps(); // Prepare for explicit register usage.
1003 LockTemp(rs_r12);
1004 RegStorage rs_src = rs_r0;
1005 RegStorage rs_dst = rs_r1;
1006 LoadValueDirectFixed(rl_src, rs_src);
1007 LoadValueDirectFixed(rl_dst, rs_dst);
1008
1009 // Handle null pointer exception in slow-path.
1010 LIR* src_check_branch = OpCmpImmBranch(kCondEq, rs_src, 0, nullptr);
1011 LIR* dst_check_branch = OpCmpImmBranch(kCondEq, rs_dst, 0, nullptr);
1012 // Handle potential overlapping in slow-path.
1013 LIR* src_dst_same = OpCmpBranch(kCondEq, rs_src, rs_dst, nullptr);
1014 // Handle exception or big length in slow-path.
1015 RegStorage rs_length = rs_r2;
1016 LoadValueDirectFixed(rl_length, rs_length);
1017 LIR* len_neg_or_too_big = OpCmpImmBranch(kCondHi, rs_length, kLargeArrayThreshold, nullptr);
1018 // Src bounds check.
1019 RegStorage rs_pos = rs_r3;
1020 RegStorage rs_arr_length = rs_r12;
1021 LoadValueDirectFixed(rl_src_pos, rs_pos);
1022 LIR* src_pos_negative = OpCmpImmBranch(kCondLt, rs_pos, 0, nullptr);
1023 Load32Disp(rs_src, mirror::Array::LengthOffset().Int32Value(), rs_arr_length);
1024 OpRegReg(kOpSub, rs_arr_length, rs_pos);
1025 LIR* src_bad_len = OpCmpBranch(kCondLt, rs_arr_length, rs_length, nullptr);
1026 // Dst bounds check.
1027 LoadValueDirectFixed(rl_dst_pos, rs_pos);
1028 LIR* dst_pos_negative = OpCmpImmBranch(kCondLt, rs_pos, 0, nullptr);
1029 Load32Disp(rs_dst, mirror::Array::LengthOffset().Int32Value(), rs_arr_length);
1030 OpRegReg(kOpSub, rs_arr_length, rs_pos);
1031 LIR* dst_bad_len = OpCmpBranch(kCondLt, rs_arr_length, rs_length, nullptr);
1032
1033 // Everything is checked now.
1034 OpRegImm(kOpAdd, rs_dst, mirror::Array::DataOffset(2).Int32Value());
1035 OpRegReg(kOpAdd, rs_dst, rs_pos);
1036 OpRegReg(kOpAdd, rs_dst, rs_pos);
1037 OpRegImm(kOpAdd, rs_src, mirror::Array::DataOffset(2).Int32Value());
1038 LoadValueDirectFixed(rl_src_pos, rs_pos);
1039 OpRegReg(kOpAdd, rs_src, rs_pos);
1040 OpRegReg(kOpAdd, rs_src, rs_pos);
1041
1042 RegStorage rs_tmp = rs_pos;
1043 OpRegRegImm(kOpLsl, rs_length, rs_length, 1);
1044
1045 // Copy one element.
1046 OpRegRegImm(kOpAnd, rs_tmp, rs_length, 2);
1047 LIR* jmp_to_begin_loop = OpCmpImmBranch(kCondEq, rs_tmp, 0, nullptr);
1048 OpRegImm(kOpSub, rs_length, 2);
1049 LoadBaseIndexed(rs_src, rs_length, rs_tmp, 0, kSignedHalf);
1050 StoreBaseIndexed(rs_dst, rs_length, rs_tmp, 0, kSignedHalf);
1051
1052 // Copy two elements.
1053 LIR *begin_loop = NewLIR0(kPseudoTargetLabel);
1054 LIR* jmp_to_ret = OpCmpImmBranch(kCondEq, rs_length, 0, nullptr);
1055 OpRegImm(kOpSub, rs_length, 4);
1056 LoadBaseIndexed(rs_src, rs_length, rs_tmp, 0, k32);
1057 StoreBaseIndexed(rs_dst, rs_length, rs_tmp, 0, k32);
1058 OpUnconditionalBranch(begin_loop);
1059
1060 LIR *check_failed = NewLIR0(kPseudoTargetLabel);
1061 LIR* launchpad_branch = OpUnconditionalBranch(nullptr);
1062 LIR* return_point = NewLIR0(kPseudoTargetLabel);
1063
1064 src_check_branch->target = check_failed;
1065 dst_check_branch->target = check_failed;
1066 src_dst_same->target = check_failed;
1067 len_neg_or_too_big->target = check_failed;
1068 src_pos_negative->target = check_failed;
1069 src_bad_len->target = check_failed;
1070 dst_pos_negative->target = check_failed;
1071 dst_bad_len->target = check_failed;
1072 jmp_to_begin_loop->target = begin_loop;
1073 jmp_to_ret->target = return_point;
1074
1075 AddIntrinsicSlowPath(info, launchpad_branch, return_point);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001076 ClobberCallerSave(); // We must clobber everything because slow path will return here
Zheng Xu947717a2014-08-07 14:05:23 +08001077
1078 return true;
1079}
1080
buzbee2700f7e2014-03-07 09:46:20 -08001081LIR* ArmMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) {
Ningsheng Jian335c5552015-02-04 14:13:45 +08001082 ScopedMemRefType mem_ref_type(this, ResourceMask::kLiteral);
buzbee2700f7e2014-03-07 09:46:20 -08001083 return RawLIR(current_dalvik_offset_, kThumb2LdrPcRel12, reg.GetReg(), 0, 0, 0, 0, target);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001084}
1085
buzbee2700f7e2014-03-07 09:46:20 -08001086LIR* ArmMir2Lir::OpVldm(RegStorage r_base, int count) {
buzbee091cc402014-03-31 10:14:40 -07001087 return NewLIR3(kThumb2Vldms, r_base.GetReg(), rs_fr0.GetReg(), count);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001088}
1089
buzbee2700f7e2014-03-07 09:46:20 -08001090LIR* ArmMir2Lir::OpVstm(RegStorage r_base, int count) {
buzbee091cc402014-03-31 10:14:40 -07001091 return NewLIR3(kThumb2Vstms, r_base.GetReg(), rs_fr0.GetReg(), count);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001092}
1093
Ningsheng Jiana262f772014-11-25 16:48:07 +08001094void ArmMir2Lir::GenMaddMsubInt(RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
1095 RegLocation rl_src3, bool is_sub) {
1096 rl_src1 = LoadValue(rl_src1, kCoreReg);
1097 rl_src2 = LoadValue(rl_src2, kCoreReg);
1098 rl_src3 = LoadValue(rl_src3, kCoreReg);
1099 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1100 NewLIR4(is_sub ? kThumb2Mls : kThumb2Mla, rl_result.reg.GetReg(), rl_src1.reg.GetReg(),
1101 rl_src2.reg.GetReg(), rl_src3.reg.GetReg());
1102 StoreValue(rl_dest, rl_result);
1103}
1104
Brian Carlstrom7940e442013-07-12 13:46:57 -07001105void ArmMir2Lir::GenMultiplyByTwoBitMultiplier(RegLocation rl_src,
1106 RegLocation rl_result, int lit,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001107 int first_bit, int second_bit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001108 UNUSED(lit);
Ian Rogerse2143c02014-03-28 08:47:16 -07001109 OpRegRegRegShift(kOpAdd, rl_result.reg, rl_src.reg, rl_src.reg,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001110 EncodeShift(kArmLsl, second_bit - first_bit));
1111 if (first_bit != 0) {
buzbee2700f7e2014-03-07 09:46:20 -08001112 OpRegRegImm(kOpLsl, rl_result.reg, rl_result.reg, first_bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001113 }
1114}
1115
Mingyao Yange643a172014-04-08 11:02:52 -07001116void ArmMir2Lir::GenDivZeroCheckWide(RegStorage reg) {
buzbee2700f7e2014-03-07 09:46:20 -08001117 DCHECK(reg.IsPair()); // TODO: support k64BitSolo.
1118 RegStorage t_reg = AllocTemp();
1119 NewLIR4(kThumb2OrrRRRs, t_reg.GetReg(), reg.GetLowReg(), reg.GetHighReg(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001120 FreeTemp(t_reg);
Mingyao Yange643a172014-04-08 11:02:52 -07001121 GenDivZeroCheck(kCondEq);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001122}
1123
1124// Test suspend flag, return target of taken suspend branch
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001125LIR* ArmMir2Lir::OpTestSuspend(LIR* target) {
Wei Jin04f4d8a2014-05-29 18:04:29 -07001126#ifdef ARM_R4_SUSPEND_FLAG
buzbee091cc402014-03-31 10:14:40 -07001127 NewLIR2(kThumbSubRI8, rs_rARM_SUSPEND.GetReg(), 1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001128 return OpCondBranch((target == NULL) ? kCondEq : kCondNe, target);
Wei Jin04f4d8a2014-05-29 18:04:29 -07001129#else
1130 RegStorage t_reg = AllocTemp();
1131 LoadBaseDisp(rs_rARM_SELF, Thread::ThreadFlagsOffset<4>().Int32Value(),
Ian Rogers8ba17f62014-10-27 18:48:49 -07001132 t_reg, kUnsignedHalf, kNotVolatile);
Wei Jin04f4d8a2014-05-29 18:04:29 -07001133 LIR* cmp_branch = OpCmpImmBranch((target == NULL) ? kCondNe : kCondEq, t_reg,
1134 0, target);
1135 FreeTemp(t_reg);
1136 return cmp_branch;
1137#endif
Brian Carlstrom7940e442013-07-12 13:46:57 -07001138}
1139
1140// Decrement register and branch on condition
buzbee2700f7e2014-03-07 09:46:20 -08001141LIR* ArmMir2Lir::OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001142 // Combine sub & test using sub setflags encoding here
Vladimir Markodbb8c492014-02-28 17:36:39 +00001143 OpRegRegImm(kOpSub, reg, reg, 1); // For value == 1, this should set flags.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001144 DCHECK(last_lir_insn_->u.m.def_mask->HasBit(ResourceMask::kCCode));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001145 return OpCondBranch(c_code, target);
1146}
1147
Andreas Gampeb14329f2014-05-15 11:16:06 -07001148bool ArmMir2Lir::GenMemBarrier(MemBarrierKind barrier_kind) {
Andreas Gampe0b9203e2015-01-22 20:39:27 -08001149 if (!cu_->compiler_driver->GetInstructionSetFeatures()->IsSmp()) {
Elliott Hughes8366ca02014-11-17 12:02:05 -08001150 return false;
1151 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001152 // Start off with using the last LIR as the barrier. If it is not enough, then we will generate one.
1153 LIR* barrier = last_lir_insn_;
1154
Brian Carlstrom7940e442013-07-12 13:46:57 -07001155 int dmb_flavor;
1156 // TODO: revisit Arm barrier kinds
1157 switch (barrier_kind) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001158 case kAnyStore: dmb_flavor = kISH; break;
1159 case kLoadAny: dmb_flavor = kISH; break;
Ian Rogersb122a4b2013-11-19 18:00:50 -08001160 case kStoreStore: dmb_flavor = kISHST; break;
Hans Boehm48f5c472014-06-27 14:50:10 -07001161 case kAnyAny: dmb_flavor = kISH; break;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001162 default:
1163 LOG(FATAL) << "Unexpected MemBarrierKind: " << barrier_kind;
1164 dmb_flavor = kSY; // quiet gcc.
1165 break;
1166 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001167
Andreas Gampeb14329f2014-05-15 11:16:06 -07001168 bool ret = false;
1169
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001170 // If the same barrier already exists, don't generate another.
1171 if (barrier == nullptr
1172 || (barrier != nullptr && (barrier->opcode != kThumb2Dmb || barrier->operands[0] != dmb_flavor))) {
1173 barrier = NewLIR1(kThumb2Dmb, dmb_flavor);
Andreas Gampeb14329f2014-05-15 11:16:06 -07001174 ret = true;
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001175 }
1176
1177 // At this point we must have a memory barrier. Mark it as a scheduling barrier as well.
1178 DCHECK(!barrier->flags.use_def_invalid);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001179 barrier->u.m.def_mask = &kEncodeAll;
Andreas Gampeb14329f2014-05-15 11:16:06 -07001180 return ret;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001181}
1182
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001183void ArmMir2Lir::GenNegLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001184 rl_src = LoadValueWide(rl_src, kCoreReg);
1185 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001186 RegStorage z_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001187 LoadConstantNoClobber(z_reg, 0);
1188 // Check for destructive overlap
buzbee2700f7e2014-03-07 09:46:20 -08001189 if (rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg()) {
1190 RegStorage t_reg = AllocTemp();
Vladimir Marko2f340a82014-12-01 16:48:48 +00001191 OpRegCopy(t_reg, rl_result.reg.GetLow());
buzbee2700f7e2014-03-07 09:46:20 -08001192 OpRegRegReg(kOpSub, rl_result.reg.GetLow(), z_reg, rl_src.reg.GetLow());
1193 OpRegRegReg(kOpSbc, rl_result.reg.GetHigh(), z_reg, t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001194 FreeTemp(t_reg);
1195 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001196 OpRegRegReg(kOpSub, rl_result.reg.GetLow(), z_reg, rl_src.reg.GetLow());
1197 OpRegRegReg(kOpSbc, rl_result.reg.GetHigh(), z_reg, rl_src.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001198 }
1199 FreeTemp(z_reg);
1200 StoreValueWide(rl_dest, rl_result);
1201}
1202
Mark Mendelle02d48f2014-01-15 11:19:23 -08001203void ArmMir2Lir::GenMulLong(Instruction::Code opcode, RegLocation rl_dest,
1204 RegLocation rl_src1, RegLocation rl_src2) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001205 UNUSED(opcode);
1206 /*
1207 * tmp1 = src1.hi * src2.lo; // src1.hi is no longer needed
1208 * dest = src1.lo * src2.lo;
1209 * tmp1 += src1.lo * src2.hi;
1210 * dest.hi += tmp1;
1211 *
1212 * To pull off inline multiply, we have a worst-case requirement of 7 temporary
1213 * registers. Normally for Arm, we get 5. We can get to 6 by including
1214 * lr in the temp set. The only problematic case is all operands and result are
1215 * distinct, and none have been promoted. In that case, we can succeed by aggressively
1216 * freeing operand temp registers after they are no longer needed. All other cases
1217 * can proceed normally. We'll just punt on the case of the result having a misaligned
1218 * overlap with either operand and send that case to a runtime handler.
1219 */
1220 RegLocation rl_result;
1221 if (PartiallyIntersects(rl_src1, rl_dest) || (PartiallyIntersects(rl_src2, rl_dest))) {
1222 FlushAllRegs();
1223 CallRuntimeHelperRegLocationRegLocation(kQuickLmul, rl_src1, rl_src2, false);
1224 rl_result = GetReturnWide(kCoreReg);
Zheng Xud7f8e022014-03-13 13:40:30 +00001225 StoreValueWide(rl_dest, rl_result);
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001226 return;
1227 }
1228
1229 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1230 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
1231
1232 int reg_status = 0;
1233 RegStorage res_lo;
1234 RegStorage res_hi;
1235 bool dest_promoted = rl_dest.location == kLocPhysReg && rl_dest.reg.Valid() &&
1236 !IsTemp(rl_dest.reg.GetLow()) && !IsTemp(rl_dest.reg.GetHigh());
1237 bool src1_promoted = !IsTemp(rl_src1.reg.GetLow()) && !IsTemp(rl_src1.reg.GetHigh());
1238 bool src2_promoted = !IsTemp(rl_src2.reg.GetLow()) && !IsTemp(rl_src2.reg.GetHigh());
1239 // Check if rl_dest is *not* either operand and we have enough temp registers.
1240 if ((rl_dest.s_reg_low != rl_src1.s_reg_low && rl_dest.s_reg_low != rl_src2.s_reg_low) &&
1241 (dest_promoted || src1_promoted || src2_promoted)) {
1242 // In this case, we do not need to manually allocate temp registers for result.
1243 rl_result = EvalLoc(rl_dest, kCoreReg, true);
1244 res_lo = rl_result.reg.GetLow();
1245 res_hi = rl_result.reg.GetHigh();
1246 } else {
1247 res_lo = AllocTemp();
1248 if ((rl_src1.s_reg_low == rl_src2.s_reg_low) || src1_promoted || src2_promoted) {
1249 // In this case, we have enough temp registers to be allocated for result.
1250 res_hi = AllocTemp();
1251 reg_status = 1;
1252 } else {
1253 // In this case, all temps are now allocated.
1254 // res_hi will be allocated after we can free src1_hi.
1255 reg_status = 2;
1256 }
1257 }
1258
1259 // Temporarily add LR to the temp pool, and assign it to tmp1
1260 MarkTemp(rs_rARM_LR);
1261 FreeTemp(rs_rARM_LR);
1262 RegStorage tmp1 = rs_rARM_LR;
1263 LockTemp(rs_rARM_LR);
1264
1265 if (rl_src1.reg == rl_src2.reg) {
1266 DCHECK(res_hi.Valid());
1267 DCHECK(res_lo.Valid());
1268 NewLIR3(kThumb2MulRRR, tmp1.GetReg(), rl_src1.reg.GetLowReg(), rl_src1.reg.GetHighReg());
1269 NewLIR4(kThumb2Umull, res_lo.GetReg(), res_hi.GetReg(), rl_src1.reg.GetLowReg(),
1270 rl_src1.reg.GetLowReg());
1271 OpRegRegRegShift(kOpAdd, res_hi, res_hi, tmp1, EncodeShift(kArmLsl, 1));
1272 } else {
1273 NewLIR3(kThumb2MulRRR, tmp1.GetReg(), rl_src2.reg.GetLowReg(), rl_src1.reg.GetHighReg());
1274 if (reg_status == 2) {
1275 DCHECK(!res_hi.Valid());
1276 DCHECK_NE(rl_src1.reg.GetLowReg(), rl_src2.reg.GetLowReg());
1277 DCHECK_NE(rl_src1.reg.GetHighReg(), rl_src2.reg.GetHighReg());
1278 // Will force free src1_hi, so must clobber.
1279 Clobber(rl_src1.reg);
1280 FreeTemp(rl_src1.reg.GetHigh());
1281 res_hi = AllocTemp();
1282 }
1283 DCHECK(res_hi.Valid());
1284 DCHECK(res_lo.Valid());
1285 NewLIR4(kThumb2Umull, res_lo.GetReg(), res_hi.GetReg(), rl_src2.reg.GetLowReg(),
1286 rl_src1.reg.GetLowReg());
1287 NewLIR4(kThumb2Mla, tmp1.GetReg(), rl_src1.reg.GetLowReg(), rl_src2.reg.GetHighReg(),
1288 tmp1.GetReg());
1289 NewLIR4(kThumb2AddRRR, res_hi.GetReg(), tmp1.GetReg(), res_hi.GetReg(), 0);
1290 if (reg_status == 2) {
1291 FreeTemp(rl_src1.reg.GetLow());
1292 }
1293 }
1294
1295 // Now, restore lr to its non-temp status.
1296 FreeTemp(tmp1);
1297 Clobber(rs_rARM_LR);
1298 UnmarkTemp(rs_rARM_LR);
1299
1300 if (reg_status != 0) {
1301 // We had manually allocated registers for rl_result.
1302 // Now construct a RegLocation.
1303 rl_result = GetReturnWide(kCoreReg); // Just using as a template.
1304 rl_result.reg = RegStorage::MakeRegPair(res_lo, res_hi);
1305 }
1306
1307 StoreValueWide(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001308}
1309
Andreas Gampec76c6142014-08-04 16:30:03 -07001310void ArmMir2Lir::GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001311 RegLocation rl_src2, int flags) {
Andreas Gampec76c6142014-08-04 16:30:03 -07001312 switch (opcode) {
1313 case Instruction::MUL_LONG:
1314 case Instruction::MUL_LONG_2ADDR:
1315 GenMulLong(opcode, rl_dest, rl_src1, rl_src2);
1316 return;
1317 case Instruction::NEG_LONG:
1318 GenNegLong(rl_dest, rl_src2);
1319 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001320
Andreas Gampec76c6142014-08-04 16:30:03 -07001321 default:
1322 break;
1323 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001324
Andreas Gampec76c6142014-08-04 16:30:03 -07001325 // Fallback for all other ops.
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001326 Mir2Lir::GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001327}
1328
1329/*
1330 * Generate array load
1331 */
1332void ArmMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -07001333 RegLocation rl_index, RegLocation rl_dest, int scale) {
buzbee091cc402014-03-31 10:14:40 -07001334 RegisterClass reg_class = RegClassBySize(size);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001335 int len_offset = mirror::Array::LengthOffset().Int32Value();
1336 int data_offset;
1337 RegLocation rl_result;
1338 bool constant_index = rl_index.is_const;
buzbeea0cd2d72014-06-01 09:33:49 -07001339 rl_array = LoadValue(rl_array, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001340 if (!constant_index) {
1341 rl_index = LoadValue(rl_index, kCoreReg);
1342 }
1343
1344 if (rl_dest.wide) {
1345 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
1346 } else {
1347 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
1348 }
1349
1350 // If index is constant, just fold it into the data offset
1351 if (constant_index) {
1352 data_offset += mir_graph_->ConstantValue(rl_index) << scale;
1353 }
1354
1355 /* null object? */
buzbee2700f7e2014-03-07 09:46:20 -08001356 GenNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001357
1358 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
buzbee2700f7e2014-03-07 09:46:20 -08001359 RegStorage reg_len;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001360 if (needs_range_check) {
1361 reg_len = AllocTemp();
1362 /* Get len */
buzbee695d13a2014-04-19 13:32:20 -07001363 Load32Disp(rl_array.reg, len_offset, reg_len);
Dave Allisonb373e092014-02-20 16:06:36 -08001364 MarkPossibleNullPointerException(opt_flags);
1365 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001366 ForceImplicitNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001367 }
1368 if (rl_dest.wide || rl_dest.fp || constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001369 RegStorage reg_ptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001370 if (constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001371 reg_ptr = rl_array.reg; // NOTE: must not alter reg_ptr in constant case.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001372 } else {
1373 // No special indexed operation, lea + load w/ displacement
buzbeea0cd2d72014-06-01 09:33:49 -07001374 reg_ptr = AllocTempRef();
Ian Rogerse2143c02014-03-28 08:47:16 -07001375 OpRegRegRegShift(kOpAdd, reg_ptr, rl_array.reg, rl_index.reg, EncodeShift(kArmLsl, scale));
buzbee091cc402014-03-31 10:14:40 -07001376 FreeTemp(rl_index.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001377 }
1378 rl_result = EvalLoc(rl_dest, reg_class, true);
1379
1380 if (needs_range_check) {
1381 if (constant_index) {
Mingyao Yang80365d92014-04-18 12:10:58 -07001382 GenArrayBoundsCheck(mir_graph_->ConstantValue(rl_index), reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001383 } else {
Mingyao Yang80365d92014-04-18 12:10:58 -07001384 GenArrayBoundsCheck(rl_index.reg, reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001385 }
1386 FreeTemp(reg_len);
1387 }
Andreas Gampe3c12c512014-06-24 18:46:29 +00001388 LoadBaseDisp(reg_ptr, data_offset, rl_result.reg, size, kNotVolatile);
Vladimir Marko455759b2014-05-06 20:49:36 +01001389 if (!constant_index) {
1390 FreeTemp(reg_ptr);
1391 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001392 if (rl_dest.wide) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001393 StoreValueWide(rl_dest, rl_result);
1394 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001395 StoreValue(rl_dest, rl_result);
1396 }
1397 } else {
1398 // Offset base, then use indexed load
buzbeea0cd2d72014-06-01 09:33:49 -07001399 RegStorage reg_ptr = AllocTempRef();
buzbee2700f7e2014-03-07 09:46:20 -08001400 OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset);
buzbee091cc402014-03-31 10:14:40 -07001401 FreeTemp(rl_array.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001402 rl_result = EvalLoc(rl_dest, reg_class, true);
1403
1404 if (needs_range_check) {
Mingyao Yang80365d92014-04-18 12:10:58 -07001405 GenArrayBoundsCheck(rl_index.reg, reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001406 FreeTemp(reg_len);
1407 }
buzbee2700f7e2014-03-07 09:46:20 -08001408 LoadBaseIndexed(reg_ptr, rl_index.reg, rl_result.reg, scale, size);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001409 FreeTemp(reg_ptr);
1410 StoreValue(rl_dest, rl_result);
1411 }
1412}
1413
1414/*
1415 * Generate array store
1416 *
1417 */
1418void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -07001419 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) {
buzbee091cc402014-03-31 10:14:40 -07001420 RegisterClass reg_class = RegClassBySize(size);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001421 int len_offset = mirror::Array::LengthOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001422 bool constant_index = rl_index.is_const;
1423
Ian Rogersa9a82542013-10-04 11:17:26 -07001424 int data_offset;
buzbee695d13a2014-04-19 13:32:20 -07001425 if (size == k64 || size == kDouble) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001426 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
1427 } else {
1428 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
1429 }
1430
1431 // If index is constant, just fold it into the data offset.
1432 if (constant_index) {
1433 data_offset += mir_graph_->ConstantValue(rl_index) << scale;
1434 }
1435
buzbeea0cd2d72014-06-01 09:33:49 -07001436 rl_array = LoadValue(rl_array, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001437 if (!constant_index) {
1438 rl_index = LoadValue(rl_index, kCoreReg);
1439 }
1440
buzbee2700f7e2014-03-07 09:46:20 -08001441 RegStorage reg_ptr;
Ian Rogers773aab12013-10-14 13:50:10 -07001442 bool allocated_reg_ptr_temp = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001443 if (constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001444 reg_ptr = rl_array.reg;
buzbee091cc402014-03-31 10:14:40 -07001445 } else if (IsTemp(rl_array.reg) && !card_mark) {
1446 Clobber(rl_array.reg);
buzbee2700f7e2014-03-07 09:46:20 -08001447 reg_ptr = rl_array.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001448 } else {
Ian Rogers773aab12013-10-14 13:50:10 -07001449 allocated_reg_ptr_temp = true;
buzbeea0cd2d72014-06-01 09:33:49 -07001450 reg_ptr = AllocTempRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001451 }
1452
1453 /* null object? */
buzbee2700f7e2014-03-07 09:46:20 -08001454 GenNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001455
1456 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
buzbee2700f7e2014-03-07 09:46:20 -08001457 RegStorage reg_len;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001458 if (needs_range_check) {
1459 reg_len = AllocTemp();
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001460 // NOTE: max live temps(4) here.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001461 /* Get len */
buzbee695d13a2014-04-19 13:32:20 -07001462 Load32Disp(rl_array.reg, len_offset, reg_len);
Dave Allisonb373e092014-02-20 16:06:36 -08001463 MarkPossibleNullPointerException(opt_flags);
1464 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001465 ForceImplicitNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001466 }
1467 /* at this point, reg_ptr points to array, 2 live temps */
1468 if (rl_src.wide || rl_src.fp || constant_index) {
1469 if (rl_src.wide) {
1470 rl_src = LoadValueWide(rl_src, reg_class);
1471 } else {
1472 rl_src = LoadValue(rl_src, reg_class);
1473 }
1474 if (!constant_index) {
Ian Rogerse2143c02014-03-28 08:47:16 -07001475 OpRegRegRegShift(kOpAdd, reg_ptr, rl_array.reg, rl_index.reg, EncodeShift(kArmLsl, scale));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001476 }
1477 if (needs_range_check) {
1478 if (constant_index) {
Mingyao Yang80365d92014-04-18 12:10:58 -07001479 GenArrayBoundsCheck(mir_graph_->ConstantValue(rl_index), reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001480 } else {
Mingyao Yang80365d92014-04-18 12:10:58 -07001481 GenArrayBoundsCheck(rl_index.reg, reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001482 }
1483 FreeTemp(reg_len);
1484 }
1485
Andreas Gampe3c12c512014-06-24 18:46:29 +00001486 StoreBaseDisp(reg_ptr, data_offset, rl_src.reg, size, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001487 } else {
1488 /* reg_ptr -> array data */
buzbee2700f7e2014-03-07 09:46:20 -08001489 OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001490 rl_src = LoadValue(rl_src, reg_class);
1491 if (needs_range_check) {
Mingyao Yang80365d92014-04-18 12:10:58 -07001492 GenArrayBoundsCheck(rl_index.reg, reg_len);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001493 FreeTemp(reg_len);
1494 }
buzbee2700f7e2014-03-07 09:46:20 -08001495 StoreBaseIndexed(reg_ptr, rl_index.reg, rl_src.reg, scale, size);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001496 }
Ian Rogers773aab12013-10-14 13:50:10 -07001497 if (allocated_reg_ptr_temp) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001498 FreeTemp(reg_ptr);
1499 }
Ian Rogersa9a82542013-10-04 11:17:26 -07001500 if (card_mark) {
Vladimir Marko743b98c2014-11-24 19:45:41 +00001501 MarkGCCard(opt_flags, rl_src.reg, rl_array.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001502 }
1503}
1504
Ian Rogersa9a82542013-10-04 11:17:26 -07001505
Brian Carlstrom7940e442013-07-12 13:46:57 -07001506void ArmMir2Lir::GenShiftImmOpLong(Instruction::Code opcode,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001507 RegLocation rl_dest, RegLocation rl_src, RegLocation rl_shift,
1508 int flags) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001509 UNUSED(flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001510 rl_src = LoadValueWide(rl_src, kCoreReg);
1511 // Per spec, we only care about low 6 bits of shift amount.
1512 int shift_amount = mir_graph_->ConstantValue(rl_shift) & 0x3f;
1513 if (shift_amount == 0) {
1514 StoreValueWide(rl_dest, rl_src);
1515 return;
1516 }
Alexei Zavjalovd8c3e362014-10-08 15:51:59 +07001517 if (PartiallyIntersects(rl_src, rl_dest)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001518 GenShiftOpLong(opcode, rl_dest, rl_src, rl_shift);
1519 return;
1520 }
1521 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Brian Carlstromdf629502013-07-17 22:39:56 -07001522 switch (opcode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001523 case Instruction::SHL_LONG:
1524 case Instruction::SHL_LONG_2ADDR:
1525 if (shift_amount == 1) {
buzbee2700f7e2014-03-07 09:46:20 -08001526 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), rl_src.reg.GetLow());
1527 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), rl_src.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001528 } else if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001529 OpRegCopy(rl_result.reg.GetHigh(), rl_src.reg);
1530 LoadConstant(rl_result.reg.GetLow(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001531 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001532 OpRegRegImm(kOpLsl, rl_result.reg.GetHigh(), rl_src.reg.GetLow(), shift_amount - 32);
1533 LoadConstant(rl_result.reg.GetLow(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001534 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001535 OpRegRegImm(kOpLsl, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001536 OpRegRegRegShift(kOpOr, rl_result.reg.GetHigh(), rl_result.reg.GetHigh(), rl_src.reg.GetLow(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001537 EncodeShift(kArmLsr, 32 - shift_amount));
buzbee2700f7e2014-03-07 09:46:20 -08001538 OpRegRegImm(kOpLsl, rl_result.reg.GetLow(), rl_src.reg.GetLow(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001539 }
1540 break;
1541 case Instruction::SHR_LONG:
1542 case Instruction::SHR_LONG_2ADDR:
1543 if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001544 OpRegCopy(rl_result.reg.GetLow(), rl_src.reg.GetHigh());
1545 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001546 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001547 OpRegRegImm(kOpAsr, rl_result.reg.GetLow(), rl_src.reg.GetHigh(), shift_amount - 32);
1548 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001549 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001550 RegStorage t_reg = AllocTemp();
1551 OpRegRegImm(kOpLsr, t_reg, rl_src.reg.GetLow(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001552 OpRegRegRegShift(kOpOr, rl_result.reg.GetLow(), t_reg, rl_src.reg.GetHigh(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001553 EncodeShift(kArmLsl, 32 - shift_amount));
1554 FreeTemp(t_reg);
buzbee2700f7e2014-03-07 09:46:20 -08001555 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001556 }
1557 break;
1558 case Instruction::USHR_LONG:
1559 case Instruction::USHR_LONG_2ADDR:
1560 if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001561 OpRegCopy(rl_result.reg.GetLow(), rl_src.reg.GetHigh());
1562 LoadConstant(rl_result.reg.GetHigh(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001563 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001564 OpRegRegImm(kOpLsr, rl_result.reg.GetLow(), rl_src.reg.GetHigh(), shift_amount - 32);
1565 LoadConstant(rl_result.reg.GetHigh(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001566 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001567 RegStorage t_reg = AllocTemp();
1568 OpRegRegImm(kOpLsr, t_reg, rl_src.reg.GetLow(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001569 OpRegRegRegShift(kOpOr, rl_result.reg.GetLow(), t_reg, rl_src.reg.GetHigh(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001570 EncodeShift(kArmLsl, 32 - shift_amount));
1571 FreeTemp(t_reg);
buzbee2700f7e2014-03-07 09:46:20 -08001572 OpRegRegImm(kOpLsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001573 }
1574 break;
1575 default:
1576 LOG(FATAL) << "Unexpected case";
1577 }
1578 StoreValueWide(rl_dest, rl_result);
1579}
1580
1581void ArmMir2Lir::GenArithImmOpLong(Instruction::Code opcode,
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001582 RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2,
1583 int flags) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001584 if ((opcode == Instruction::SUB_LONG_2ADDR) || (opcode == Instruction::SUB_LONG)) {
1585 if (!rl_src2.is_const) {
1586 // Don't bother with special handling for subtract from immediate.
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001587 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001588 return;
1589 }
1590 } else {
1591 // Normalize
1592 if (!rl_src2.is_const) {
1593 DCHECK(rl_src1.is_const);
Vladimir Marko58af1f92013-12-19 13:31:15 +00001594 std::swap(rl_src1, rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001595 }
1596 }
Alexei Zavjalovd8c3e362014-10-08 15:51:59 +07001597 if (PartiallyIntersects(rl_src1, rl_dest)) {
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001598 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001599 return;
1600 }
1601 DCHECK(rl_src2.is_const);
1602 int64_t val = mir_graph_->ConstantValueWide(rl_src2);
1603 uint32_t val_lo = Low32Bits(val);
1604 uint32_t val_hi = High32Bits(val);
1605 int32_t mod_imm_lo = ModifiedImmediate(val_lo);
1606 int32_t mod_imm_hi = ModifiedImmediate(val_hi);
1607
1608 // Only a subset of add/sub immediate instructions set carry - so bail if we don't fit
Brian Carlstromdf629502013-07-17 22:39:56 -07001609 switch (opcode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001610 case Instruction::ADD_LONG:
1611 case Instruction::ADD_LONG_2ADDR:
1612 case Instruction::SUB_LONG:
1613 case Instruction::SUB_LONG_2ADDR:
1614 if ((mod_imm_lo < 0) || (mod_imm_hi < 0)) {
Razvan A Lupusoru5c5676b2014-09-29 16:42:11 -07001615 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2, flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001616 return;
1617 }
1618 break;
1619 default:
1620 break;
1621 }
1622 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1623 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1624 // NOTE: once we've done the EvalLoc on dest, we can no longer bail.
1625 switch (opcode) {
1626 case Instruction::ADD_LONG:
1627 case Instruction::ADD_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001628 NewLIR3(kThumb2AddRRI8M, rl_result.reg.GetLowReg(), rl_src1.reg.GetLowReg(), mod_imm_lo);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001629 NewLIR3(kThumb2AdcRRI8M, rl_result.reg.GetHighReg(), rl_src1.reg.GetHighReg(), mod_imm_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001630 break;
1631 case Instruction::OR_LONG:
1632 case Instruction::OR_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001633 if ((val_lo != 0) || (rl_result.reg.GetLowReg() != rl_src1.reg.GetLowReg())) {
1634 OpRegRegImm(kOpOr, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001635 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001636 if ((val_hi != 0) || (rl_result.reg.GetHighReg() != rl_src1.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001637 OpRegRegImm(kOpOr, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001638 }
1639 break;
1640 case Instruction::XOR_LONG:
1641 case Instruction::XOR_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001642 OpRegRegImm(kOpXor, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
1643 OpRegRegImm(kOpXor, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001644 break;
1645 case Instruction::AND_LONG:
1646 case Instruction::AND_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001647 if ((val_lo != 0xffffffff) || (rl_result.reg.GetLowReg() != rl_src1.reg.GetLowReg())) {
1648 OpRegRegImm(kOpAnd, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001649 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001650 if ((val_hi != 0xffffffff) || (rl_result.reg.GetHighReg() != rl_src1.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001651 OpRegRegImm(kOpAnd, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001652 }
1653 break;
1654 case Instruction::SUB_LONG_2ADDR:
1655 case Instruction::SUB_LONG:
buzbee2700f7e2014-03-07 09:46:20 -08001656 NewLIR3(kThumb2SubRRI8M, rl_result.reg.GetLowReg(), rl_src1.reg.GetLowReg(), mod_imm_lo);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001657 NewLIR3(kThumb2SbcRRI8M, rl_result.reg.GetHighReg(), rl_src1.reg.GetHighReg(), mod_imm_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001658 break;
1659 default:
1660 LOG(FATAL) << "Unexpected opcode " << opcode;
1661 }
1662 StoreValueWide(rl_dest, rl_result);
1663}
1664
Andreas Gamped500b532015-01-16 22:09:55 -08001665bool ArmMir2Lir::HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
1666 RegLocation rl_src, RegLocation rl_dest, int lit) {
1667 if (lit < 2) {
1668 return false;
1669 }
1670
1671 // ARM does either not support a division instruction, or it is potentially expensive. Look for
1672 // more special cases.
1673 if (!IsPowerOfTwo(lit)) {
1674 return SmallLiteralDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit);
1675 }
1676
1677 return Mir2Lir::HandleEasyDivRem(dalvik_opcode, is_div, rl_src, rl_dest, lit);
1678}
1679
Brian Carlstrom7940e442013-07-12 13:46:57 -07001680} // namespace art