blob: 8177999131457353727aac2416bf509d264ac461 [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
19#include "arm_lir.h"
20#include "codegen_arm.h"
21#include "dex/quick/mir_to_lir-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070022#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "mirror/array.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070024
25namespace art {
26
buzbee2700f7e2014-03-07 09:46:20 -080027LIR* ArmMir2Lir::OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070028 OpRegReg(kOpCmp, src1, src2);
29 return OpCondBranch(cond, target);
30}
31
32/*
33 * Generate a Thumb2 IT instruction, which can nullify up to
34 * four subsequent instructions based on a condition and its
35 * inverse. The condition applies to the first instruction, which
36 * is executed if the condition is met. The string "guide" consists
37 * of 0 to 3 chars, and applies to the 2nd through 4th instruction.
38 * A "T" means the instruction is executed if the condition is
39 * met, and an "E" means the instruction is executed if the condition
40 * is not met.
41 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070042LIR* ArmMir2Lir::OpIT(ConditionCode ccode, const char* guide) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070043 int mask;
44 int mask3 = 0;
45 int mask2 = 0;
46 int mask1 = 0;
47 ArmConditionCode code = ArmConditionEncoding(ccode);
48 int cond_bit = code & 1;
49 int alt_bit = cond_bit ^ 1;
50
Brian Carlstrom7934ac22013-07-26 10:54:15 -070051 // Note: case fallthroughs intentional
Brian Carlstrom7940e442013-07-12 13:46:57 -070052 switch (strlen(guide)) {
53 case 3:
54 mask1 = (guide[2] == 'T') ? cond_bit : alt_bit;
55 case 2:
56 mask2 = (guide[1] == 'T') ? cond_bit : alt_bit;
57 case 1:
58 mask3 = (guide[0] == 'T') ? cond_bit : alt_bit;
59 break;
60 case 0:
61 break;
62 default:
63 LOG(FATAL) << "OAT: bad case in OpIT";
64 }
65 mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) |
66 (1 << (3 - strlen(guide)));
67 return NewLIR2(kThumb2It, code, mask);
68}
69
70/*
71 * 64-bit 3way compare function.
72 * mov rX, #-1
73 * cmp op1hi, op2hi
74 * blt done
75 * bgt flip
76 * sub rX, op1lo, op2lo (treat as unsigned)
77 * beq done
78 * ite hi
79 * mov(hi) rX, #-1
80 * mov(!hi) rX, #1
81 * flip:
82 * neg rX
83 * done:
84 */
85void ArmMir2Lir::GenCmpLong(RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070086 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070087 LIR* target1;
88 LIR* target2;
89 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
90 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -080091 RegStorage t_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 LoadConstant(t_reg, -1);
buzbee2700f7e2014-03-07 09:46:20 -080093 OpRegReg(kOpCmp, rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -070094 LIR* branch1 = OpCondBranch(kCondLt, NULL);
95 LIR* branch2 = OpCondBranch(kCondGt, NULL);
buzbee2700f7e2014-03-07 09:46:20 -080096 OpRegRegReg(kOpSub, t_reg, rl_src1.reg, rl_src2.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070097 LIR* branch3 = OpCondBranch(kCondEq, NULL);
98
99 OpIT(kCondHi, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800100 NewLIR2(kThumb2MovI8M, t_reg.GetReg(), ModifiedImmediate(-1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101 LoadConstant(t_reg, 1);
102 GenBarrier();
103
104 target2 = NewLIR0(kPseudoTargetLabel);
105 OpRegReg(kOpNeg, t_reg, t_reg);
106
107 target1 = NewLIR0(kPseudoTargetLabel);
108
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700109 RegLocation rl_temp = LocCReturn(); // Just using as template, will change
buzbee2700f7e2014-03-07 09:46:20 -0800110 rl_temp.reg.SetReg(t_reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700111 StoreValue(rl_dest, rl_temp);
112 FreeTemp(t_reg);
113
114 branch1->target = target1;
115 branch2->target = target2;
116 branch3->target = branch1->target;
117}
118
119void ArmMir2Lir::GenFusedLongCmpImmBranch(BasicBlock* bb, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700120 int64_t val, ConditionCode ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700121 int32_t val_lo = Low32Bits(val);
122 int32_t val_hi = High32Bits(val);
Brian Carlstrom42748892013-07-18 18:04:08 -0700123 DCHECK_GE(ModifiedImmediate(val_lo), 0);
124 DCHECK_GE(ModifiedImmediate(val_hi), 0);
buzbee0d829482013-10-11 15:24:55 -0700125 LIR* taken = &block_label_list_[bb->taken];
126 LIR* not_taken = &block_label_list_[bb->fall_through];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700127 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800128 RegStorage low_reg = rl_src1.reg.GetLow();
129 RegStorage high_reg = rl_src1.reg.GetHigh();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130
Vladimir Marko58af1f92013-12-19 13:31:15 +0000131 if (val == 0 && (ccode == kCondEq || ccode == kCondNe)) {
buzbee2700f7e2014-03-07 09:46:20 -0800132 RegStorage t_reg = AllocTemp();
133 NewLIR4(kThumb2OrrRRRs, t_reg.GetReg(), low_reg.GetReg(), high_reg.GetReg(), 0);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000134 FreeTemp(t_reg);
135 OpCondBranch(ccode, taken);
136 return;
137 }
138
Brian Carlstromdf629502013-07-17 22:39:56 -0700139 switch (ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140 case kCondEq:
141 case kCondNe:
Vladimir Marko58af1f92013-12-19 13:31:15 +0000142 OpCmpImmBranch(kCondNe, high_reg, val_hi, (ccode == kCondEq) ? not_taken : taken);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143 break;
144 case kCondLt:
145 OpCmpImmBranch(kCondLt, high_reg, val_hi, taken);
146 OpCmpImmBranch(kCondGt, high_reg, val_hi, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000147 ccode = kCondUlt;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 break;
149 case kCondLe:
150 OpCmpImmBranch(kCondLt, high_reg, val_hi, taken);
151 OpCmpImmBranch(kCondGt, high_reg, val_hi, not_taken);
152 ccode = kCondLs;
153 break;
154 case kCondGt:
155 OpCmpImmBranch(kCondGt, high_reg, val_hi, taken);
156 OpCmpImmBranch(kCondLt, high_reg, val_hi, not_taken);
157 ccode = kCondHi;
158 break;
159 case kCondGe:
160 OpCmpImmBranch(kCondGt, high_reg, val_hi, taken);
161 OpCmpImmBranch(kCondLt, high_reg, val_hi, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000162 ccode = kCondUge;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700163 break;
164 default:
165 LOG(FATAL) << "Unexpected ccode: " << ccode;
166 }
167 OpCmpImmBranch(ccode, low_reg, val_lo, taken);
168}
169
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700170void ArmMir2Lir::GenSelect(BasicBlock* bb, MIR* mir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700171 RegLocation rl_result;
172 RegLocation rl_src = mir_graph_->GetSrc(mir, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700173 RegLocation rl_dest = mir_graph_->GetDest(mir);
174 rl_src = LoadValue(rl_src, kCoreReg);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000175 ConditionCode ccode = mir->meta.ccode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700176 if (mir->ssa_rep->num_uses == 1) {
177 // CONST case
178 int true_val = mir->dalvikInsn.vB;
179 int false_val = mir->dalvikInsn.vC;
180 rl_result = EvalLoc(rl_dest, kCoreReg, true);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000181 // Change kCondNe to kCondEq for the special cases below.
182 if (ccode == kCondNe) {
183 ccode = kCondEq;
184 std::swap(true_val, false_val);
185 }
186 bool cheap_false_val = InexpensiveConstantInt(false_val);
187 if (cheap_false_val && ccode == kCondEq && (true_val == 0 || true_val == -1)) {
buzbee2700f7e2014-03-07 09:46:20 -0800188 OpRegRegImm(kOpSub, rl_result.reg, rl_src.reg, -true_val);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000189 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
190 OpIT(true_val == 0 ? kCondNe : kCondUge, "");
buzbee2700f7e2014-03-07 09:46:20 -0800191 LoadConstant(rl_result.reg, false_val);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700192 GenBarrier(); // Add a scheduling barrier to keep the IT shadow intact
Vladimir Markoa1a70742014-03-03 10:28:05 +0000193 } else if (cheap_false_val && ccode == kCondEq && true_val == 1) {
buzbee2700f7e2014-03-07 09:46:20 -0800194 OpRegRegImm(kOpRsub, rl_result.reg, rl_src.reg, 1);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000195 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
196 OpIT(kCondLs, "");
buzbee2700f7e2014-03-07 09:46:20 -0800197 LoadConstant(rl_result.reg, false_val);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000198 GenBarrier(); // Add a scheduling barrier to keep the IT shadow intact
199 } else if (cheap_false_val && InexpensiveConstantInt(true_val)) {
buzbee2700f7e2014-03-07 09:46:20 -0800200 OpRegImm(kOpCmp, rl_src.reg, 0);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000201 OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800202 LoadConstant(rl_result.reg, true_val);
203 LoadConstant(rl_result.reg, false_val);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700204 GenBarrier(); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700205 } else {
206 // Unlikely case - could be tuned.
buzbee2700f7e2014-03-07 09:46:20 -0800207 RegStorage t_reg1 = AllocTemp();
208 RegStorage t_reg2 = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700209 LoadConstant(t_reg1, true_val);
210 LoadConstant(t_reg2, false_val);
buzbee2700f7e2014-03-07 09:46:20 -0800211 OpRegImm(kOpCmp, rl_src.reg, 0);
Vladimir Markoa1a70742014-03-03 10:28:05 +0000212 OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800213 OpRegCopy(rl_result.reg, t_reg1);
214 OpRegCopy(rl_result.reg, t_reg2);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700215 GenBarrier(); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700216 }
217 } else {
218 // MOVE case
219 RegLocation rl_true = mir_graph_->reg_location_[mir->ssa_rep->uses[1]];
220 RegLocation rl_false = mir_graph_->reg_location_[mir->ssa_rep->uses[2]];
221 rl_true = LoadValue(rl_true, kCoreReg);
222 rl_false = LoadValue(rl_false, kCoreReg);
223 rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800224 OpRegImm(kOpCmp, rl_src.reg, 0);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000225 if (rl_result.reg.GetReg() == rl_true.reg.GetReg()) { // Is the "true" case already in place?
Vladimir Markoa1a70742014-03-03 10:28:05 +0000226 OpIT(NegateComparison(ccode), "");
buzbee2700f7e2014-03-07 09:46:20 -0800227 OpRegCopy(rl_result.reg, rl_false.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000228 } else if (rl_result.reg.GetReg() == rl_false.reg.GetReg()) { // False case in place?
Vladimir Markoa1a70742014-03-03 10:28:05 +0000229 OpIT(ccode, "");
buzbee2700f7e2014-03-07 09:46:20 -0800230 OpRegCopy(rl_result.reg, rl_true.reg);
buzbee252254b2013-09-08 16:20:53 -0700231 } else { // Normal - select between the two.
Vladimir Markoa1a70742014-03-03 10:28:05 +0000232 OpIT(ccode, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800233 OpRegCopy(rl_result.reg, rl_true.reg);
234 OpRegCopy(rl_result.reg, rl_false.reg);
buzbee252254b2013-09-08 16:20:53 -0700235 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700236 GenBarrier(); // Add a scheduling barrier to keep the IT shadow intact
Brian Carlstrom7940e442013-07-12 13:46:57 -0700237 }
238 StoreValue(rl_dest, rl_result);
239}
240
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700241void ArmMir2Lir::GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242 RegLocation rl_src1 = mir_graph_->GetSrcWide(mir, 0);
243 RegLocation rl_src2 = mir_graph_->GetSrcWide(mir, 2);
244 // Normalize such that if either operand is constant, src2 will be constant.
Vladimir Markoa8946072014-01-22 10:30:44 +0000245 ConditionCode ccode = mir->meta.ccode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700246 if (rl_src1.is_const) {
Vladimir Marko58af1f92013-12-19 13:31:15 +0000247 std::swap(rl_src1, rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700248 ccode = FlipComparisonOrder(ccode);
249 }
250 if (rl_src2.is_const) {
251 RegLocation rl_temp = UpdateLocWide(rl_src2);
252 // Do special compare/branch against simple const operand if not already in registers.
253 int64_t val = mir_graph_->ConstantValueWide(rl_src2);
254 if ((rl_temp.location != kLocPhysReg) &&
255 ((ModifiedImmediate(Low32Bits(val)) >= 0) && (ModifiedImmediate(High32Bits(val)) >= 0))) {
256 GenFusedLongCmpImmBranch(bb, rl_src1, val, ccode);
257 return;
258 }
259 }
buzbee0d829482013-10-11 15:24:55 -0700260 LIR* taken = &block_label_list_[bb->taken];
261 LIR* not_taken = &block_label_list_[bb->fall_through];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700262 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
263 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800264 OpRegReg(kOpCmp, rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh());
Brian Carlstromdf629502013-07-17 22:39:56 -0700265 switch (ccode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700266 case kCondEq:
267 OpCondBranch(kCondNe, not_taken);
268 break;
269 case kCondNe:
270 OpCondBranch(kCondNe, taken);
271 break;
272 case kCondLt:
273 OpCondBranch(kCondLt, taken);
274 OpCondBranch(kCondGt, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000275 ccode = kCondUlt;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700276 break;
277 case kCondLe:
278 OpCondBranch(kCondLt, taken);
279 OpCondBranch(kCondGt, not_taken);
280 ccode = kCondLs;
281 break;
282 case kCondGt:
283 OpCondBranch(kCondGt, taken);
284 OpCondBranch(kCondLt, not_taken);
285 ccode = kCondHi;
286 break;
287 case kCondGe:
288 OpCondBranch(kCondGt, taken);
289 OpCondBranch(kCondLt, not_taken);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000290 ccode = kCondUge;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700291 break;
292 default:
293 LOG(FATAL) << "Unexpected ccode: " << ccode;
294 }
buzbee2700f7e2014-03-07 09:46:20 -0800295 OpRegReg(kOpCmp, rl_src1.reg.GetLow(), rl_src2.reg.GetLow());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700296 OpCondBranch(ccode, taken);
297}
298
299/*
300 * Generate a register comparison to an immediate and branch. Caller
301 * is responsible for setting branch target field.
302 */
buzbee2700f7e2014-03-07 09:46:20 -0800303LIR* ArmMir2Lir::OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700304 LIR* branch;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700305 ArmConditionCode arm_cond = ArmConditionEncoding(cond);
buzbeeb48819d2013-09-14 16:15:25 -0700306 /*
307 * A common use of OpCmpImmBranch is for null checks, and using the Thumb 16-bit
308 * compare-and-branch if zero is ideal if it will reach. However, because null checks
309 * branch forward to a launch pad, they will frequently not reach - and thus have to
310 * be converted to a long form during assembly (which will trigger another assembly
311 * pass). Here we estimate the branch distance for checks, and if large directly
312 * generate the long form in an attempt to avoid an extra assembly pass.
313 * TODO: consider interspersing launchpads in code following unconditional branches.
314 */
315 bool skip = ((target != NULL) && (target->opcode == kPseudoThrowTarget));
316 skip &= ((cu_->code_item->insns_size_in_code_units_ - current_dalvik_offset_) > 64);
buzbee2700f7e2014-03-07 09:46:20 -0800317 if (!skip && (ARM_LOWREG(reg.GetReg())) && (check_value == 0) &&
Brian Carlstrom7940e442013-07-12 13:46:57 -0700318 ((arm_cond == kArmCondEq) || (arm_cond == kArmCondNe))) {
319 branch = NewLIR2((arm_cond == kArmCondEq) ? kThumb2Cbz : kThumb2Cbnz,
buzbee2700f7e2014-03-07 09:46:20 -0800320 reg.GetReg(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700321 } else {
Vladimir Marko22479842013-11-19 17:04:50 +0000322 OpRegImm(kOpCmp, reg, check_value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700323 branch = NewLIR2(kThumbBCond, 0, arm_cond);
324 }
325 branch->target = target;
326 return branch;
327}
328
buzbee2700f7e2014-03-07 09:46:20 -0800329LIR* ArmMir2Lir::OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700330 LIR* res;
331 int opcode;
buzbee2700f7e2014-03-07 09:46:20 -0800332 // If src or dest is a pair, we'll be using low reg.
333 if (r_dest.IsPair()) {
334 r_dest = r_dest.GetLow();
335 }
336 if (r_src.IsPair()) {
337 r_src = r_src.GetLow();
338 }
339 if (ARM_FPREG(r_dest.GetReg()) || ARM_FPREG(r_src.GetReg()))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700340 return OpFpRegCopy(r_dest, r_src);
buzbee2700f7e2014-03-07 09:46:20 -0800341 if (ARM_LOWREG(r_dest.GetReg()) && ARM_LOWREG(r_src.GetReg()))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700342 opcode = kThumbMovRR;
buzbee2700f7e2014-03-07 09:46:20 -0800343 else if (!ARM_LOWREG(r_dest.GetReg()) && !ARM_LOWREG(r_src.GetReg()))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 opcode = kThumbMovRR_H2H;
buzbee2700f7e2014-03-07 09:46:20 -0800345 else if (ARM_LOWREG(r_dest.GetReg()))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700346 opcode = kThumbMovRR_H2L;
347 else
348 opcode = kThumbMovRR_L2H;
buzbee2700f7e2014-03-07 09:46:20 -0800349 res = RawLIR(current_dalvik_offset_, opcode, r_dest.GetReg(), r_src.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700350 if (!(cu_->disable_opt & (1 << kSafeOptimizations)) && r_dest == r_src) {
351 res->flags.is_nop = true;
352 }
353 return res;
354}
355
buzbee2700f7e2014-03-07 09:46:20 -0800356LIR* ArmMir2Lir::OpRegCopy(RegStorage r_dest, RegStorage r_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700357 LIR* res = OpRegCopyNoInsert(r_dest, r_src);
358 AppendLIR(res);
359 return res;
360}
361
buzbee2700f7e2014-03-07 09:46:20 -0800362void ArmMir2Lir::OpRegCopyWide(RegStorage r_dest, RegStorage r_src) {
363 bool dest_fp = ARM_FPREG(r_dest.GetLowReg());
364 bool src_fp = ARM_FPREG(r_src.GetLowReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700365 if (dest_fp) {
366 if (src_fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800367 // FIXME: handle 64-bit solo's here.
368 OpRegCopy(RegStorage::Solo64(S2d(r_dest.GetLowReg(), r_dest.GetHighReg())),
369 RegStorage::Solo64(S2d(r_src.GetLowReg(), r_src.GetHighReg())));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700370 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800371 NewLIR3(kThumb2Fmdrr, S2d(r_dest.GetLowReg(), r_dest.GetHighReg()),
372 r_src.GetLowReg(), r_src.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700373 }
374 } else {
375 if (src_fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800376 NewLIR3(kThumb2Fmrrd, r_dest.GetLowReg(), r_dest.GetHighReg(), S2d(r_src.GetLowReg(),
377 r_src.GetHighReg()));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700378 } else {
379 // Handle overlap
buzbee2700f7e2014-03-07 09:46:20 -0800380 if (r_src.GetHighReg() == r_dest.GetLowReg()) {
381 DCHECK_NE(r_src.GetLowReg(), r_dest.GetHighReg());
382 OpRegCopy(r_dest.GetHigh(), r_src.GetHigh());
383 OpRegCopy(r_dest.GetLow(), r_src.GetLow());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700384 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800385 OpRegCopy(r_dest.GetLow(), r_src.GetLow());
386 OpRegCopy(r_dest.GetHigh(), r_src.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387 }
388 }
389 }
390}
391
392// Table of magic divisors
393struct MagicTable {
394 uint32_t magic;
395 uint32_t shift;
396 DividePattern pattern;
397};
398
399static const MagicTable magic_table[] = {
400 {0, 0, DivideNone}, // 0
401 {0, 0, DivideNone}, // 1
402 {0, 0, DivideNone}, // 2
403 {0x55555556, 0, Divide3}, // 3
404 {0, 0, DivideNone}, // 4
405 {0x66666667, 1, Divide5}, // 5
406 {0x2AAAAAAB, 0, Divide3}, // 6
407 {0x92492493, 2, Divide7}, // 7
408 {0, 0, DivideNone}, // 8
409 {0x38E38E39, 1, Divide5}, // 9
410 {0x66666667, 2, Divide5}, // 10
411 {0x2E8BA2E9, 1, Divide5}, // 11
412 {0x2AAAAAAB, 1, Divide5}, // 12
413 {0x4EC4EC4F, 2, Divide5}, // 13
414 {0x92492493, 3, Divide7}, // 14
415 {0x88888889, 3, Divide7}, // 15
416};
417
418// Integer division by constant via reciprocal multiply (Hacker's Delight, 10-4)
buzbee11b63d12013-08-27 07:34:17 -0700419bool ArmMir2Lir::SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700420 RegLocation rl_src, RegLocation rl_dest, int lit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421 if ((lit < 0) || (lit >= static_cast<int>(sizeof(magic_table)/sizeof(magic_table[0])))) {
422 return false;
423 }
424 DividePattern pattern = magic_table[lit].pattern;
425 if (pattern == DivideNone) {
426 return false;
427 }
Brian Carlstrom3654a6f2014-03-27 17:14:26 -0700428 // Tuning: add rem patterns
429 if (!is_div) {
430 return false;
431 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432
buzbee2700f7e2014-03-07 09:46:20 -0800433 RegStorage r_magic = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700434 LoadConstant(r_magic, magic_table[lit].magic);
435 rl_src = LoadValue(rl_src, kCoreReg);
436 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800437 RegStorage r_hi = AllocTemp();
438 RegStorage r_lo = AllocTemp();
439 NewLIR4(kThumb2Smull, r_lo.GetReg(), r_hi.GetReg(), r_magic.GetReg(), rl_src.reg.GetReg());
Brian Carlstromdf629502013-07-17 22:39:56 -0700440 switch (pattern) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700441 case Divide3:
Ian Rogerse2143c02014-03-28 08:47:16 -0700442 OpRegRegRegShift(kOpSub, rl_result.reg, r_hi, rl_src.reg, EncodeShift(kArmAsr, 31));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700443 break;
444 case Divide5:
buzbee2700f7e2014-03-07 09:46:20 -0800445 OpRegRegImm(kOpAsr, r_lo, rl_src.reg, 31);
Ian Rogerse2143c02014-03-28 08:47:16 -0700446 OpRegRegRegShift(kOpRsub, rl_result.reg, r_lo, r_hi,
447 EncodeShift(kArmAsr, magic_table[lit].shift));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700448 break;
449 case Divide7:
buzbee2700f7e2014-03-07 09:46:20 -0800450 OpRegReg(kOpAdd, r_hi, rl_src.reg);
451 OpRegRegImm(kOpAsr, r_lo, rl_src.reg, 31);
Ian Rogerse2143c02014-03-28 08:47:16 -0700452 OpRegRegRegShift(kOpRsub, rl_result.reg, r_lo, r_hi,
453 EncodeShift(kArmAsr, magic_table[lit].shift));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700454 break;
455 default:
456 LOG(FATAL) << "Unexpected pattern: " << pattern;
457 }
458 StoreValue(rl_dest, rl_result);
459 return true;
460}
461
Ian Rogerse2143c02014-03-28 08:47:16 -0700462// Try to convert *lit to 1 RegRegRegShift/RegRegShift form.
463bool ArmMir2Lir::GetEasyMultiplyOp(int lit, ArmMir2Lir::EasyMultiplyOp* op) {
464 if (IsPowerOfTwo(lit)) {
465 op->op = kOpLsl;
466 op->shift = LowestSetBit(lit);
467 return true;
468 }
469
470 if (IsPowerOfTwo(lit - 1)) {
471 op->op = kOpAdd;
472 op->shift = LowestSetBit(lit - 1);
473 return true;
474 }
475
476 if (IsPowerOfTwo(lit + 1)) {
477 op->op = kOpRsub;
478 op->shift = LowestSetBit(lit + 1);
479 return true;
480 }
481
482 op->op = kOpInvalid;
483 return false;
484}
485
486// Try to convert *lit to 1~2 RegRegRegShift/RegRegShift forms.
487bool ArmMir2Lir::GetEasyMultiplyTwoOps(int lit, EasyMultiplyOp* ops) {
488 GetEasyMultiplyOp(lit, &ops[0]);
489 if (GetEasyMultiplyOp(lit, &ops[0])) {
490 ops[1].op = kOpInvalid;
491 return true;
492 }
493
494 int lit1 = lit;
495 uint32_t shift = LowestSetBit(lit1);
496 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
497 ops[1].op = kOpLsl;
498 ops[1].shift = shift;
499 return true;
500 }
501
502 lit1 = lit - 1;
503 shift = LowestSetBit(lit1);
504 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
505 ops[1].op = kOpAdd;
506 ops[1].shift = shift;
507 return true;
508 }
509
510 lit1 = lit + 1;
511 shift = LowestSetBit(lit1);
512 if (GetEasyMultiplyOp(lit1 >> shift, &ops[0])) {
513 ops[1].op = kOpRsub;
514 ops[1].shift = shift;
515 return true;
516 }
517
518 return false;
519}
520
521void ArmMir2Lir::GenEasyMultiplyTwoOps(RegStorage r_dest, RegStorage r_src, EasyMultiplyOp* ops) {
522 // dest = ( src << shift1) + [ src | -src | 0 ]
523 // dest = (dest << shift2) + [ src | -src | 0 ]
524 for (int i = 0; i < 2; i++) {
525 RegStorage r_src2;
526 if (i == 0) {
527 r_src2 = r_src;
528 } else {
529 r_src2 = r_dest;
530 }
531 switch (ops[i].op) {
532 case kOpLsl:
533 OpRegRegImm(kOpLsl, r_dest, r_src2, ops[i].shift);
534 break;
535 case kOpAdd:
536 OpRegRegRegShift(kOpAdd, r_dest, r_src, r_src2, EncodeShift(kArmLsl, ops[i].shift));
537 break;
538 case kOpRsub:
539 OpRegRegRegShift(kOpRsub, r_dest, r_src, r_src2, EncodeShift(kArmLsl, ops[i].shift));
540 break;
541 default:
542 DCHECK_NE(i, 0);
543 DCHECK_EQ(ops[i].op, kOpInvalid);
544 break;
545 }
546 }
547}
548
549bool ArmMir2Lir::EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) {
550 EasyMultiplyOp ops[2];
551
552 if (!GetEasyMultiplyTwoOps(lit, ops)) {
553 return false;
554 }
555
556 rl_src = LoadValue(rl_src, kCoreReg);
557 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
558
559 GenEasyMultiplyTwoOps(rl_result.reg, rl_src.reg, ops);
560 StoreValue(rl_dest, rl_result);
561 return true;
562}
563
buzbee2700f7e2014-03-07 09:46:20 -0800564LIR* ArmMir2Lir::GenRegMemCheck(ConditionCode c_code, RegStorage reg1, RegStorage base,
565 int offset, ThrowKind kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700566 LOG(FATAL) << "Unexpected use of GenRegMemCheck for Arm";
567 return NULL;
568}
569
Mark Mendell2bf31e62014-01-23 12:13:40 -0800570RegLocation ArmMir2Lir::GenDivRem(RegLocation rl_dest, RegLocation rl_src1,
571 RegLocation rl_src2, bool is_div, bool check_zero) {
572 LOG(FATAL) << "Unexpected use of GenDivRem for Arm";
573 return rl_dest;
574}
575
576RegLocation ArmMir2Lir::GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) {
577 LOG(FATAL) << "Unexpected use of GenDivRemLit for Arm";
578 return rl_dest;
579}
580
buzbee2700f7e2014-03-07 09:46:20 -0800581RegLocation ArmMir2Lir::GenDivRemLit(RegLocation rl_dest, RegStorage reg1, int lit, bool is_div) {
Dave Allison70202782013-10-22 17:52:19 -0700582 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
583
584 // Put the literal in a temp.
buzbee2700f7e2014-03-07 09:46:20 -0800585 RegStorage lit_temp = AllocTemp();
Dave Allison70202782013-10-22 17:52:19 -0700586 LoadConstant(lit_temp, lit);
587 // Use the generic case for div/rem with arg2 in a register.
588 // TODO: The literal temp can be freed earlier during a modulus to reduce reg pressure.
589 rl_result = GenDivRem(rl_result, reg1, lit_temp, is_div);
590 FreeTemp(lit_temp);
591
592 return rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700593}
594
buzbee2700f7e2014-03-07 09:46:20 -0800595RegLocation ArmMir2Lir::GenDivRem(RegLocation rl_dest, RegStorage reg1, RegStorage reg2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700596 bool is_div) {
Dave Allison70202782013-10-22 17:52:19 -0700597 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
598 if (is_div) {
599 // Simple case, use sdiv instruction.
buzbee2700f7e2014-03-07 09:46:20 -0800600 OpRegRegReg(kOpDiv, rl_result.reg, reg1, reg2);
Dave Allison70202782013-10-22 17:52:19 -0700601 } else {
602 // Remainder case, use the following code:
603 // temp = reg1 / reg2 - integer division
604 // temp = temp * reg2
605 // dest = reg1 - temp
606
buzbee2700f7e2014-03-07 09:46:20 -0800607 RegStorage temp = AllocTemp();
Dave Allison70202782013-10-22 17:52:19 -0700608 OpRegRegReg(kOpDiv, temp, reg1, reg2);
609 OpRegReg(kOpMul, temp, reg2);
buzbee2700f7e2014-03-07 09:46:20 -0800610 OpRegRegReg(kOpSub, rl_result.reg, reg1, temp);
Dave Allison70202782013-10-22 17:52:19 -0700611 FreeTemp(temp);
612 }
613
614 return rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700615}
616
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700617bool ArmMir2Lir::GenInlinedMinMaxInt(CallInfo* info, bool is_min) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700618 DCHECK_EQ(cu_->instruction_set, kThumb2);
619 RegLocation rl_src1 = info->args[0];
620 RegLocation rl_src2 = info->args[1];
621 rl_src1 = LoadValue(rl_src1, kCoreReg);
622 rl_src2 = LoadValue(rl_src2, kCoreReg);
623 RegLocation rl_dest = InlineTarget(info);
624 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800625 OpRegReg(kOpCmp, rl_src1.reg, rl_src2.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700626 OpIT((is_min) ? kCondGt : kCondLt, "E");
buzbee2700f7e2014-03-07 09:46:20 -0800627 OpRegReg(kOpMov, rl_result.reg, rl_src2.reg);
628 OpRegReg(kOpMov, rl_result.reg, rl_src1.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700629 GenBarrier();
630 StoreValue(rl_dest, rl_result);
631 return true;
632}
633
Vladimir Markoe508a202013-11-04 15:24:22 +0000634bool ArmMir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) {
635 RegLocation rl_src_address = info->args[0]; // long address
buzbee2700f7e2014-03-07 09:46:20 -0800636 rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1]
Vladimir Markoe508a202013-11-04 15:24:22 +0000637 RegLocation rl_dest = InlineTarget(info);
638 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
639 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
640 if (size == kLong) {
641 // Fake unaligned LDRD by two unaligned LDR instructions on ARMv7 with SCTLR.A set to 0.
buzbee2700f7e2014-03-07 09:46:20 -0800642 if (rl_address.reg.GetReg() != rl_result.reg.GetLowReg()) {
643 LoadWordDisp(rl_address.reg, 0, rl_result.reg.GetLow());
644 LoadWordDisp(rl_address.reg, 4, rl_result.reg.GetHigh());
Vladimir Markoe508a202013-11-04 15:24:22 +0000645 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800646 LoadWordDisp(rl_address.reg, 4, rl_result.reg.GetHigh());
647 LoadWordDisp(rl_address.reg, 0, rl_result.reg.GetLow());
Vladimir Markoe508a202013-11-04 15:24:22 +0000648 }
649 StoreValueWide(rl_dest, rl_result);
650 } else {
651 DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord);
652 // Unaligned load with LDR and LDRSH is allowed on ARMv7 with SCTLR.A set to 0.
buzbee2700f7e2014-03-07 09:46:20 -0800653 LoadBaseDisp(rl_address.reg, 0, rl_result.reg, size, INVALID_SREG);
Vladimir Markoe508a202013-11-04 15:24:22 +0000654 StoreValue(rl_dest, rl_result);
655 }
656 return true;
657}
658
659bool ArmMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) {
660 RegLocation rl_src_address = info->args[0]; // long address
buzbee2700f7e2014-03-07 09:46:20 -0800661 rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1]
Vladimir Markoe508a202013-11-04 15:24:22 +0000662 RegLocation rl_src_value = info->args[2]; // [size] value
663 RegLocation rl_address = LoadValue(rl_src_address, kCoreReg);
664 if (size == kLong) {
665 // Fake unaligned STRD by two unaligned STR instructions on ARMv7 with SCTLR.A set to 0.
666 RegLocation rl_value = LoadValueWide(rl_src_value, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800667 StoreBaseDisp(rl_address.reg, 0, rl_value.reg.GetLow(), kWord);
668 StoreBaseDisp(rl_address.reg, 4, rl_value.reg.GetHigh(), kWord);
Vladimir Markoe508a202013-11-04 15:24:22 +0000669 } else {
670 DCHECK(size == kSignedByte || size == kSignedHalf || size == kWord);
671 // Unaligned store with STR and STRSH is allowed on ARMv7 with SCTLR.A set to 0.
672 RegLocation rl_value = LoadValue(rl_src_value, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800673 StoreBaseDisp(rl_address.reg, 0, rl_value.reg, size);
Vladimir Markoe508a202013-11-04 15:24:22 +0000674 }
675 return true;
676}
677
buzbee2700f7e2014-03-07 09:46:20 -0800678void ArmMir2Lir::OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, int offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700679 LOG(FATAL) << "Unexpected use of OpLea for Arm";
680}
681
Ian Rogersdd7624d2014-03-14 17:43:00 -0700682void ArmMir2Lir::OpTlsCmp(ThreadOffset<4> offset, int val) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700683 LOG(FATAL) << "Unexpected use of OpTlsCmp for Arm";
684}
685
Vladimir Marko1c282e22013-11-21 14:49:47 +0000686bool ArmMir2Lir::GenInlinedCas(CallInfo* info, bool is_long, bool is_object) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700687 DCHECK_EQ(cu_->instruction_set, kThumb2);
688 // Unused - RegLocation rl_src_unsafe = info->args[0];
Vladimir Marko1c282e22013-11-21 14:49:47 +0000689 RegLocation rl_src_obj = info->args[1]; // Object - known non-null
690 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -0800691 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Vladimir Marko1c282e22013-11-21 14:49:47 +0000692 RegLocation rl_src_expected = info->args[4]; // int, long or Object
Vladimir Marko3e5af822013-11-21 15:01:20 +0000693 // If is_long, high half is in info->args[5]
694 RegLocation rl_src_new_value = info->args[is_long ? 6 : 5]; // int, long or Object
695 // If is_long, high half is in info->args[7]
Brian Carlstrom7940e442013-07-12 13:46:57 -0700696 RegLocation rl_dest = InlineTarget(info); // boolean place for result
697
Vladimir Marko3e5af822013-11-21 15:01:20 +0000698 // We have only 5 temporary registers available and actually only 4 if the InlineTarget
699 // above locked one of the temps. For a straightforward CAS64 we need 7 registers:
700 // r_ptr (1), new_value (2), expected(2) and ldrexd result (2). If neither expected nor
701 // new_value is in a non-temp core register we shall reload them in the ldrex/strex loop
702 // into the same temps, reducing the number of required temps down to 5. We shall work
703 // around the potentially locked temp by using LR for r_ptr, unconditionally.
704 // TODO: Pass information about the need for more temps to the stack frame generation
705 // code so that we can rely on being able to allocate enough temps.
706 DCHECK(!reg_pool_->core_regs[rARM_LR].is_temp);
707 MarkTemp(rARM_LR);
708 FreeTemp(rARM_LR);
709 LockTemp(rARM_LR);
710 bool load_early = true;
711 if (is_long) {
buzbee2700f7e2014-03-07 09:46:20 -0800712 int expected_reg = is_long ? rl_src_expected.reg.GetLowReg() : rl_src_expected.reg.GetReg();
713 int new_val_reg = is_long ? rl_src_new_value.reg.GetLowReg() : rl_src_new_value.reg.GetReg();
714 bool expected_is_core_reg = rl_src_expected.location == kLocPhysReg && !IsFpReg(expected_reg);
715 bool new_value_is_core_reg = rl_src_new_value.location == kLocPhysReg && !IsFpReg(new_val_reg);
716 bool expected_is_good_reg = expected_is_core_reg && !IsTemp(expected_reg);
717 bool new_value_is_good_reg = new_value_is_core_reg && !IsTemp(new_val_reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000718
719 if (!expected_is_good_reg && !new_value_is_good_reg) {
720 // None of expected/new_value is non-temp reg, need to load both late
721 load_early = false;
722 // Make sure they are not in the temp regs and the load will not be skipped.
723 if (expected_is_core_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800724 FlushRegWide(rl_src_expected.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000725 ClobberSReg(rl_src_expected.s_reg_low);
726 ClobberSReg(GetSRegHi(rl_src_expected.s_reg_low));
727 rl_src_expected.location = kLocDalvikFrame;
728 }
729 if (new_value_is_core_reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800730 FlushRegWide(rl_src_new_value.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000731 ClobberSReg(rl_src_new_value.s_reg_low);
732 ClobberSReg(GetSRegHi(rl_src_new_value.s_reg_low));
733 rl_src_new_value.location = kLocDalvikFrame;
734 }
735 }
736 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700737
738 // Release store semantics, get the barrier out of the way. TODO: revisit
739 GenMemBarrier(kStoreLoad);
740
741 RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000742 RegLocation rl_new_value;
743 if (!is_long) {
744 rl_new_value = LoadValue(rl_src_new_value, kCoreReg);
745 } else if (load_early) {
746 rl_new_value = LoadValueWide(rl_src_new_value, kCoreReg);
747 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700748
Vladimir Marko1c282e22013-11-21 14:49:47 +0000749 if (is_object && !mir_graph_->IsConstantNullRef(rl_new_value)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700750 // Mark card for object assuming new value is stored.
buzbee2700f7e2014-03-07 09:46:20 -0800751 MarkGCCard(rl_new_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700752 }
753
754 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
755
buzbee2700f7e2014-03-07 09:46:20 -0800756 RegStorage r_ptr = rs_rARM_LR;
757 OpRegRegReg(kOpAdd, r_ptr, rl_object.reg, rl_offset.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700758
759 // Free now unneeded rl_object and rl_offset to give more temps.
760 ClobberSReg(rl_object.s_reg_low);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000761 FreeTemp(rl_object.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700762 ClobberSReg(rl_offset.s_reg_low);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000763 FreeTemp(rl_offset.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700764
Vladimir Marko3e5af822013-11-21 15:01:20 +0000765 RegLocation rl_expected;
766 if (!is_long) {
767 rl_expected = LoadValue(rl_src_expected, kCoreReg);
768 } else if (load_early) {
769 rl_expected = LoadValueWide(rl_src_expected, kCoreReg);
770 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000771 // NOTE: partially defined rl_expected & rl_new_value - but we just want the regs.
buzbee2700f7e2014-03-07 09:46:20 -0800772 int low_reg = AllocTemp().GetReg();
773 int high_reg = AllocTemp().GetReg();
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000774 rl_new_value.reg = RegStorage(RegStorage::k64BitPair, low_reg, high_reg);
775 rl_expected = rl_new_value;
Vladimir Marko3e5af822013-11-21 15:01:20 +0000776 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700777
Vladimir Marko3e5af822013-11-21 15:01:20 +0000778 // do {
779 // tmp = [r_ptr] - expected;
780 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
781 // result = tmp != 0;
782
buzbee2700f7e2014-03-07 09:46:20 -0800783 RegStorage r_tmp = AllocTemp();
Jeff Hao2de2aa12013-09-12 17:20:31 -0700784 LIR* target = NewLIR0(kPseudoTargetLabel);
Jeff Hao2de2aa12013-09-12 17:20:31 -0700785
Vladimir Marko3e5af822013-11-21 15:01:20 +0000786 if (is_long) {
buzbee2700f7e2014-03-07 09:46:20 -0800787 RegStorage r_tmp_high = AllocTemp();
Vladimir Marko3e5af822013-11-21 15:01:20 +0000788 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800789 LoadValueDirectWide(rl_src_expected, rl_expected.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000790 }
buzbee2700f7e2014-03-07 09:46:20 -0800791 NewLIR3(kThumb2Ldrexd, r_tmp.GetReg(), r_tmp_high.GetReg(), r_ptr.GetReg());
792 OpRegReg(kOpSub, r_tmp, rl_expected.reg.GetLow());
793 OpRegReg(kOpSub, r_tmp_high, rl_expected.reg.GetHigh());
Vladimir Marko3e5af822013-11-21 15:01:20 +0000794 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800795 LoadValueDirectWide(rl_src_new_value, rl_new_value.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000796 }
797 // Make sure we use ORR that sets the ccode
buzbee2700f7e2014-03-07 09:46:20 -0800798 if (ARM_LOWREG(r_tmp.GetReg()) && ARM_LOWREG(r_tmp_high.GetReg())) {
799 NewLIR2(kThumbOrr, r_tmp.GetReg(), r_tmp_high.GetReg());
Vladimir Marko3e5af822013-11-21 15:01:20 +0000800 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800801 NewLIR4(kThumb2OrrRRRs, r_tmp.GetReg(), r_tmp.GetReg(), r_tmp_high.GetReg(), 0);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000802 }
803 FreeTemp(r_tmp_high); // Now unneeded
804
805 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
806 OpIT(kCondEq, "T");
buzbee2700f7e2014-03-07 09:46:20 -0800807 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 +0000808
809 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800810 NewLIR3(kThumb2Ldrex, r_tmp.GetReg(), r_ptr.GetReg(), 0);
811 OpRegReg(kOpSub, r_tmp, rl_expected.reg);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000812 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
813 OpIT(kCondEq, "T");
buzbee2700f7e2014-03-07 09:46:20 -0800814 NewLIR4(kThumb2Strex /* eq */, r_tmp.GetReg(), rl_new_value.reg.GetReg(), r_ptr.GetReg(), 0);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000815 }
816
817 // Still one conditional left from OpIT(kCondEq, "T") from either branch
818 OpRegImm(kOpCmp /* eq */, r_tmp, 1);
Dave Allison43a065c2014-04-01 15:14:46 -0700819 GenBarrier();
820
Jeff Hao2de2aa12013-09-12 17:20:31 -0700821 OpCondBranch(kCondEq, target);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700822
Vladimir Marko3e5af822013-11-21 15:01:20 +0000823 if (!load_early) {
buzbee2700f7e2014-03-07 09:46:20 -0800824 FreeTemp(rl_expected.reg); // Now unneeded.
Vladimir Marko3e5af822013-11-21 15:01:20 +0000825 }
826
827 // result := (tmp1 != 0) ? 0 : 1;
828 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800829 OpRegRegImm(kOpRsub, rl_result.reg, r_tmp, 1);
Vladimir Marko3e5af822013-11-21 15:01:20 +0000830 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
Vladimir Marko58af1f92013-12-19 13:31:15 +0000831 OpIT(kCondUlt, "");
buzbee2700f7e2014-03-07 09:46:20 -0800832 LoadConstant(rl_result.reg, 0); /* cc */
Vladimir Marko3e5af822013-11-21 15:01:20 +0000833 FreeTemp(r_tmp); // Now unneeded.
Dave Allison43a065c2014-04-01 15:14:46 -0700834 GenBarrier(); // Barrier to terminate OpIT.
Vladimir Marko3e5af822013-11-21 15:01:20 +0000835
Brian Carlstrom7940e442013-07-12 13:46:57 -0700836 StoreValue(rl_dest, rl_result);
837
Vladimir Marko3e5af822013-11-21 15:01:20 +0000838 // Now, restore lr to its non-temp status.
839 Clobber(rARM_LR);
840 UnmarkTemp(rARM_LR);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700841 return true;
842}
843
buzbee2700f7e2014-03-07 09:46:20 -0800844LIR* ArmMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) {
845 return RawLIR(current_dalvik_offset_, kThumb2LdrPcRel12, reg.GetReg(), 0, 0, 0, 0, target);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700846}
847
buzbee2700f7e2014-03-07 09:46:20 -0800848LIR* ArmMir2Lir::OpVldm(RegStorage r_base, int count) {
849 return NewLIR3(kThumb2Vldms, r_base.GetReg(), fr0, count);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700850}
851
buzbee2700f7e2014-03-07 09:46:20 -0800852LIR* ArmMir2Lir::OpVstm(RegStorage r_base, int count) {
853 return NewLIR3(kThumb2Vstms, r_base.GetReg(), fr0, count);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700854}
855
856void ArmMir2Lir::GenMultiplyByTwoBitMultiplier(RegLocation rl_src,
857 RegLocation rl_result, int lit,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700858 int first_bit, int second_bit) {
Ian Rogerse2143c02014-03-28 08:47:16 -0700859 OpRegRegRegShift(kOpAdd, rl_result.reg, rl_src.reg, rl_src.reg,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700860 EncodeShift(kArmLsl, second_bit - first_bit));
861 if (first_bit != 0) {
buzbee2700f7e2014-03-07 09:46:20 -0800862 OpRegRegImm(kOpLsl, rl_result.reg, rl_result.reg, first_bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700863 }
864}
865
buzbee2700f7e2014-03-07 09:46:20 -0800866void ArmMir2Lir::GenDivZeroCheck(RegStorage reg) {
867 DCHECK(reg.IsPair()); // TODO: support k64BitSolo.
868 RegStorage t_reg = AllocTemp();
869 NewLIR4(kThumb2OrrRRRs, t_reg.GetReg(), reg.GetLowReg(), reg.GetHighReg(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700870 FreeTemp(t_reg);
871 GenCheck(kCondEq, kThrowDivZero);
872}
873
874// Test suspend flag, return target of taken suspend branch
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700875LIR* ArmMir2Lir::OpTestSuspend(LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700876 NewLIR2(kThumbSubRI8, rARM_SUSPEND, 1);
877 return OpCondBranch((target == NULL) ? kCondEq : kCondNe, target);
878}
879
880// Decrement register and branch on condition
buzbee2700f7e2014-03-07 09:46:20 -0800881LIR* ArmMir2Lir::OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700882 // Combine sub & test using sub setflags encoding here
Vladimir Markodbb8c492014-02-28 17:36:39 +0000883 OpRegRegImm(kOpSub, reg, reg, 1); // For value == 1, this should set flags.
884 DCHECK(last_lir_insn_->u.m.def_mask & ENCODE_CCODE);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700885 return OpCondBranch(c_code, target);
886}
887
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700888void ArmMir2Lir::GenMemBarrier(MemBarrierKind barrier_kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700889#if ANDROID_SMP != 0
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800890 // Start off with using the last LIR as the barrier. If it is not enough, then we will generate one.
891 LIR* barrier = last_lir_insn_;
892
Brian Carlstrom7940e442013-07-12 13:46:57 -0700893 int dmb_flavor;
894 // TODO: revisit Arm barrier kinds
895 switch (barrier_kind) {
Ian Rogersb122a4b2013-11-19 18:00:50 -0800896 case kLoadStore: dmb_flavor = kISH; break;
897 case kLoadLoad: dmb_flavor = kISH; break;
898 case kStoreStore: dmb_flavor = kISHST; break;
899 case kStoreLoad: dmb_flavor = kISH; break;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700900 default:
901 LOG(FATAL) << "Unexpected MemBarrierKind: " << barrier_kind;
902 dmb_flavor = kSY; // quiet gcc.
903 break;
904 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -0800905
906 // If the same barrier already exists, don't generate another.
907 if (barrier == nullptr
908 || (barrier != nullptr && (barrier->opcode != kThumb2Dmb || barrier->operands[0] != dmb_flavor))) {
909 barrier = NewLIR1(kThumb2Dmb, dmb_flavor);
910 }
911
912 // At this point we must have a memory barrier. Mark it as a scheduling barrier as well.
913 DCHECK(!barrier->flags.use_def_invalid);
914 barrier->u.m.def_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700915#endif
916}
917
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700918void ArmMir2Lir::GenNegLong(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700919 rl_src = LoadValueWide(rl_src, kCoreReg);
920 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800921 RegStorage z_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700922 LoadConstantNoClobber(z_reg, 0);
923 // Check for destructive overlap
buzbee2700f7e2014-03-07 09:46:20 -0800924 if (rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg()) {
925 RegStorage t_reg = AllocTemp();
926 OpRegRegReg(kOpSub, rl_result.reg.GetLow(), z_reg, rl_src.reg.GetLow());
927 OpRegRegReg(kOpSbc, rl_result.reg.GetHigh(), z_reg, t_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700928 FreeTemp(t_reg);
929 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800930 OpRegRegReg(kOpSub, rl_result.reg.GetLow(), z_reg, rl_src.reg.GetLow());
931 OpRegRegReg(kOpSbc, rl_result.reg.GetHigh(), z_reg, rl_src.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700932 }
933 FreeTemp(z_reg);
934 StoreValueWide(rl_dest, rl_result);
935}
936
Mark Mendelle02d48f2014-01-15 11:19:23 -0800937void ArmMir2Lir::GenMulLong(Instruction::Code opcode, RegLocation rl_dest,
938 RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700939 /*
Zheng Xud7f8e022014-03-13 13:40:30 +0000940 * tmp1 = src1.hi * src2.lo; // src1.hi is no longer needed
941 * dest = src1.lo * src2.lo;
942 * tmp1 += src1.lo * src2.hi;
943 * dest.hi += tmp1;
944 *
945 * To pull off inline multiply, we have a worst-case requirement of 7 temporary
Brian Carlstrom7940e442013-07-12 13:46:57 -0700946 * registers. Normally for Arm, we get 5. We can get to 6 by including
947 * lr in the temp set. The only problematic case is all operands and result are
948 * distinct, and none have been promoted. In that case, we can succeed by aggressively
949 * freeing operand temp registers after they are no longer needed. All other cases
950 * can proceed normally. We'll just punt on the case of the result having a misaligned
951 * overlap with either operand and send that case to a runtime handler.
952 */
953 RegLocation rl_result;
954 if (BadOverlap(rl_src1, rl_dest) || (BadOverlap(rl_src2, rl_dest))) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700955 ThreadOffset<4> func_offset = QUICK_ENTRYPOINT_OFFSET(4, pLmul);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700956 FlushAllRegs();
957 CallRuntimeHelperRegLocationRegLocation(func_offset, rl_src1, rl_src2, false);
958 rl_result = GetReturnWide(false);
959 StoreValueWide(rl_dest, rl_result);
960 return;
961 }
Zheng Xud7f8e022014-03-13 13:40:30 +0000962
963 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
964 rl_src2 = LoadValueWide(rl_src2, kCoreReg);
965
966 int reg_status = 0;
buzbee2700f7e2014-03-07 09:46:20 -0800967 RegStorage res_lo;
968 RegStorage res_hi;
969 bool dest_promoted = rl_dest.location == kLocPhysReg && rl_dest.reg.Valid() &&
970 !IsTemp(rl_dest.reg.GetLowReg()) && !IsTemp(rl_dest.reg.GetHighReg());
971 bool src1_promoted = !IsTemp(rl_src1.reg.GetLowReg()) && !IsTemp(rl_src1.reg.GetHighReg());
972 bool src2_promoted = !IsTemp(rl_src2.reg.GetLowReg()) && !IsTemp(rl_src2.reg.GetHighReg());
Zheng Xud7f8e022014-03-13 13:40:30 +0000973 // Check if rl_dest is *not* either operand and we have enough temp registers.
974 if ((rl_dest.s_reg_low != rl_src1.s_reg_low && rl_dest.s_reg_low != rl_src2.s_reg_low) &&
975 (dest_promoted || src1_promoted || src2_promoted)) {
976 // In this case, we do not need to manually allocate temp registers for result.
977 rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -0800978 res_lo = rl_result.reg.GetLow();
979 res_hi = rl_result.reg.GetHigh();
Zheng Xud7f8e022014-03-13 13:40:30 +0000980 } else {
981 res_lo = AllocTemp();
982 if ((rl_src1.s_reg_low == rl_src2.s_reg_low) || src1_promoted || src2_promoted) {
983 // In this case, we have enough temp registers to be allocated for result.
984 res_hi = AllocTemp();
985 reg_status = 1;
986 } else {
987 // In this case, all temps are now allocated.
988 // res_hi will be allocated after we can free src1_hi.
989 reg_status = 2;
990 }
991 }
992
Brian Carlstrom7940e442013-07-12 13:46:57 -0700993 // Temporarily add LR to the temp pool, and assign it to tmp1
994 MarkTemp(rARM_LR);
995 FreeTemp(rARM_LR);
buzbee2700f7e2014-03-07 09:46:20 -0800996 RegStorage tmp1 = rs_rARM_LR;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700997 LockTemp(rARM_LR);
998
buzbee2700f7e2014-03-07 09:46:20 -0800999 if (rl_src1.reg == rl_src2.reg) {
1000 DCHECK(res_hi.Valid());
1001 DCHECK(res_lo.Valid());
1002 NewLIR3(kThumb2MulRRR, tmp1.GetReg(), rl_src1.reg.GetLowReg(), rl_src1.reg.GetHighReg());
1003 NewLIR4(kThumb2Umull, res_lo.GetReg(), res_hi.GetReg(), rl_src1.reg.GetLowReg(),
1004 rl_src1.reg.GetLowReg());
Ian Rogerse2143c02014-03-28 08:47:16 -07001005 OpRegRegRegShift(kOpAdd, res_hi, res_hi, tmp1, EncodeShift(kArmLsl, 1));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001006 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001007 NewLIR3(kThumb2MulRRR, tmp1.GetReg(), rl_src2.reg.GetLowReg(), rl_src1.reg.GetHighReg());
Zheng Xud7f8e022014-03-13 13:40:30 +00001008 if (reg_status == 2) {
buzbee2700f7e2014-03-07 09:46:20 -08001009 DCHECK(!res_hi.Valid());
1010 DCHECK_NE(rl_src1.reg.GetLowReg(), rl_src2.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001011 DCHECK_NE(rl_src1.reg.GetHighReg(), rl_src2.reg.GetHighReg());
1012 FreeTemp(rl_src1.reg.GetHighReg());
Zheng Xud7f8e022014-03-13 13:40:30 +00001013 res_hi = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001014 }
buzbee2700f7e2014-03-07 09:46:20 -08001015 DCHECK(res_hi.Valid());
1016 DCHECK(res_lo.Valid());
1017 NewLIR4(kThumb2Umull, res_lo.GetReg(), res_hi.GetReg(), rl_src2.reg.GetLowReg(),
1018 rl_src1.reg.GetLowReg());
1019 NewLIR4(kThumb2Mla, tmp1.GetReg(), rl_src1.reg.GetLowReg(), rl_src2.reg.GetHighReg(),
1020 tmp1.GetReg());
1021 NewLIR4(kThumb2AddRRR, res_hi.GetReg(), tmp1.GetReg(), res_hi.GetReg(), 0);
Zheng Xud7f8e022014-03-13 13:40:30 +00001022 if (reg_status == 2) {
1023 // Clobber rl_src1 since it was corrupted.
buzbee2700f7e2014-03-07 09:46:20 -08001024 FreeTemp(rl_src1.reg);
1025 Clobber(rl_src1.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001026 }
1027 }
Zheng Xud7f8e022014-03-13 13:40:30 +00001028
Brian Carlstrom7940e442013-07-12 13:46:57 -07001029 // Now, restore lr to its non-temp status.
Zheng Xud7f8e022014-03-13 13:40:30 +00001030 FreeTemp(tmp1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001031 Clobber(rARM_LR);
1032 UnmarkTemp(rARM_LR);
Zheng Xud7f8e022014-03-13 13:40:30 +00001033
1034 if (reg_status != 0) {
1035 // We had manually allocated registers for rl_result.
1036 // Now construct a RegLocation.
1037 rl_result = GetReturnWide(false); // Just using as a template.
buzbee2700f7e2014-03-07 09:46:20 -08001038 rl_result.reg = RegStorage::MakeRegPair(res_lo, res_hi);
Zheng Xud7f8e022014-03-13 13:40:30 +00001039 }
1040
1041 StoreValueWide(rl_dest, rl_result);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001042}
1043
Mark Mendelle02d48f2014-01-15 11:19:23 -08001044void ArmMir2Lir::GenAddLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001045 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001046 LOG(FATAL) << "Unexpected use of GenAddLong for Arm";
1047}
1048
Mark Mendelle02d48f2014-01-15 11:19:23 -08001049void ArmMir2Lir::GenSubLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001050 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001051 LOG(FATAL) << "Unexpected use of GenSubLong for Arm";
1052}
1053
Mark Mendelle02d48f2014-01-15 11:19:23 -08001054void ArmMir2Lir::GenAndLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001055 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001056 LOG(FATAL) << "Unexpected use of GenAndLong for Arm";
1057}
1058
Mark Mendelle02d48f2014-01-15 11:19:23 -08001059void ArmMir2Lir::GenOrLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001060 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001061 LOG(FATAL) << "Unexpected use of GenOrLong for Arm";
1062}
1063
Mark Mendelle02d48f2014-01-15 11:19:23 -08001064void ArmMir2Lir::GenXorLong(Instruction::Code opcode, RegLocation rl_dest, RegLocation rl_src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001065 RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001066 LOG(FATAL) << "Unexpected use of genXoLong for Arm";
1067}
1068
1069/*
1070 * Generate array load
1071 */
1072void ArmMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -07001073 RegLocation rl_index, RegLocation rl_dest, int scale) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001074 RegisterClass reg_class = oat_reg_class_by_size(size);
1075 int len_offset = mirror::Array::LengthOffset().Int32Value();
1076 int data_offset;
1077 RegLocation rl_result;
1078 bool constant_index = rl_index.is_const;
1079 rl_array = LoadValue(rl_array, kCoreReg);
1080 if (!constant_index) {
1081 rl_index = LoadValue(rl_index, kCoreReg);
1082 }
1083
1084 if (rl_dest.wide) {
1085 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
1086 } else {
1087 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
1088 }
1089
1090 // If index is constant, just fold it into the data offset
1091 if (constant_index) {
1092 data_offset += mir_graph_->ConstantValue(rl_index) << scale;
1093 }
1094
1095 /* null object? */
buzbee2700f7e2014-03-07 09:46:20 -08001096 GenNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001097
1098 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
buzbee2700f7e2014-03-07 09:46:20 -08001099 RegStorage reg_len;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001100 if (needs_range_check) {
1101 reg_len = AllocTemp();
1102 /* Get len */
buzbee2700f7e2014-03-07 09:46:20 -08001103 LoadWordDisp(rl_array.reg, len_offset, reg_len);
Dave Allisonb373e092014-02-20 16:06:36 -08001104 MarkPossibleNullPointerException(opt_flags);
1105 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001106 ForceImplicitNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001107 }
1108 if (rl_dest.wide || rl_dest.fp || constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001109 RegStorage reg_ptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001110 if (constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001111 reg_ptr = rl_array.reg; // NOTE: must not alter reg_ptr in constant case.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001112 } else {
1113 // No special indexed operation, lea + load w/ displacement
1114 reg_ptr = AllocTemp();
Ian Rogerse2143c02014-03-28 08:47:16 -07001115 OpRegRegRegShift(kOpAdd, reg_ptr, rl_array.reg, rl_index.reg, EncodeShift(kArmLsl, scale));
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001116 FreeTemp(rl_index.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001117 }
1118 rl_result = EvalLoc(rl_dest, reg_class, true);
1119
1120 if (needs_range_check) {
1121 if (constant_index) {
1122 GenImmedCheck(kCondLs, reg_len, mir_graph_->ConstantValue(rl_index), kThrowConstantArrayBounds);
1123 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001124 GenRegRegCheck(kCondLs, reg_len, rl_index.reg, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001125 }
1126 FreeTemp(reg_len);
1127 }
1128 if (rl_dest.wide) {
buzbee2700f7e2014-03-07 09:46:20 -08001129 LoadBaseDispWide(reg_ptr, data_offset, rl_result.reg, INVALID_SREG);
Dave Allisonb373e092014-02-20 16:06:36 -08001130 MarkPossibleNullPointerException(opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001131 if (!constant_index) {
1132 FreeTemp(reg_ptr);
1133 }
1134 StoreValueWide(rl_dest, rl_result);
1135 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001136 LoadBaseDisp(reg_ptr, data_offset, rl_result.reg, size, INVALID_SREG);
Dave Allisonb373e092014-02-20 16:06:36 -08001137 MarkPossibleNullPointerException(opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001138 if (!constant_index) {
1139 FreeTemp(reg_ptr);
1140 }
1141 StoreValue(rl_dest, rl_result);
1142 }
1143 } else {
1144 // Offset base, then use indexed load
buzbee2700f7e2014-03-07 09:46:20 -08001145 RegStorage reg_ptr = AllocTemp();
1146 OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001147 FreeTemp(rl_array.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001148 rl_result = EvalLoc(rl_dest, reg_class, true);
1149
1150 if (needs_range_check) {
buzbee2700f7e2014-03-07 09:46:20 -08001151 GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001152 FreeTemp(reg_len);
1153 }
buzbee2700f7e2014-03-07 09:46:20 -08001154 LoadBaseIndexed(reg_ptr, rl_index.reg, rl_result.reg, scale, size);
Dave Allisonb373e092014-02-20 16:06:36 -08001155 MarkPossibleNullPointerException(opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001156 FreeTemp(reg_ptr);
1157 StoreValue(rl_dest, rl_result);
1158 }
1159}
1160
1161/*
1162 * Generate array store
1163 *
1164 */
1165void ArmMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -07001166 RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001167 RegisterClass reg_class = oat_reg_class_by_size(size);
1168 int len_offset = mirror::Array::LengthOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001169 bool constant_index = rl_index.is_const;
1170
Ian Rogersa9a82542013-10-04 11:17:26 -07001171 int data_offset;
1172 if (size == kLong || size == kDouble) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001173 data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value();
1174 } else {
1175 data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value();
1176 }
1177
1178 // If index is constant, just fold it into the data offset.
1179 if (constant_index) {
1180 data_offset += mir_graph_->ConstantValue(rl_index) << scale;
1181 }
1182
1183 rl_array = LoadValue(rl_array, kCoreReg);
1184 if (!constant_index) {
1185 rl_index = LoadValue(rl_index, kCoreReg);
1186 }
1187
buzbee2700f7e2014-03-07 09:46:20 -08001188 RegStorage reg_ptr;
Ian Rogers773aab12013-10-14 13:50:10 -07001189 bool allocated_reg_ptr_temp = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001190 if (constant_index) {
buzbee2700f7e2014-03-07 09:46:20 -08001191 reg_ptr = rl_array.reg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001192 } else if (IsTemp(rl_array.reg.GetReg()) && !card_mark) {
1193 Clobber(rl_array.reg.GetReg());
buzbee2700f7e2014-03-07 09:46:20 -08001194 reg_ptr = rl_array.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001195 } else {
Ian Rogers773aab12013-10-14 13:50:10 -07001196 allocated_reg_ptr_temp = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001197 reg_ptr = AllocTemp();
1198 }
1199
1200 /* null object? */
buzbee2700f7e2014-03-07 09:46:20 -08001201 GenNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001202
1203 bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK));
buzbee2700f7e2014-03-07 09:46:20 -08001204 RegStorage reg_len;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001205 if (needs_range_check) {
1206 reg_len = AllocTemp();
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001207 // NOTE: max live temps(4) here.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001208 /* Get len */
buzbee2700f7e2014-03-07 09:46:20 -08001209 LoadWordDisp(rl_array.reg, len_offset, reg_len);
Dave Allisonb373e092014-02-20 16:06:36 -08001210 MarkPossibleNullPointerException(opt_flags);
1211 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001212 ForceImplicitNullCheck(rl_array.reg, opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001213 }
1214 /* at this point, reg_ptr points to array, 2 live temps */
1215 if (rl_src.wide || rl_src.fp || constant_index) {
1216 if (rl_src.wide) {
1217 rl_src = LoadValueWide(rl_src, reg_class);
1218 } else {
1219 rl_src = LoadValue(rl_src, reg_class);
1220 }
1221 if (!constant_index) {
Ian Rogerse2143c02014-03-28 08:47:16 -07001222 OpRegRegRegShift(kOpAdd, reg_ptr, rl_array.reg, rl_index.reg, EncodeShift(kArmLsl, scale));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001223 }
1224 if (needs_range_check) {
1225 if (constant_index) {
1226 GenImmedCheck(kCondLs, reg_len, mir_graph_->ConstantValue(rl_index), kThrowConstantArrayBounds);
1227 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001228 GenRegRegCheck(kCondLs, reg_len, rl_index.reg, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001229 }
1230 FreeTemp(reg_len);
1231 }
1232
1233 if (rl_src.wide) {
buzbee2700f7e2014-03-07 09:46:20 -08001234 StoreBaseDispWide(reg_ptr, data_offset, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001235 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001236 StoreBaseDisp(reg_ptr, data_offset, rl_src.reg, size);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001237 }
Dave Allisonb373e092014-02-20 16:06:36 -08001238 MarkPossibleNullPointerException(opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001239 } else {
1240 /* reg_ptr -> array data */
buzbee2700f7e2014-03-07 09:46:20 -08001241 OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001242 rl_src = LoadValue(rl_src, reg_class);
1243 if (needs_range_check) {
buzbee2700f7e2014-03-07 09:46:20 -08001244 GenRegRegCheck(kCondUge, rl_index.reg, reg_len, kThrowArrayBounds);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001245 FreeTemp(reg_len);
1246 }
buzbee2700f7e2014-03-07 09:46:20 -08001247 StoreBaseIndexed(reg_ptr, rl_index.reg, rl_src.reg, scale, size);
Dave Allisonb373e092014-02-20 16:06:36 -08001248 MarkPossibleNullPointerException(opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001249 }
Ian Rogers773aab12013-10-14 13:50:10 -07001250 if (allocated_reg_ptr_temp) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001251 FreeTemp(reg_ptr);
1252 }
Ian Rogersa9a82542013-10-04 11:17:26 -07001253 if (card_mark) {
buzbee2700f7e2014-03-07 09:46:20 -08001254 MarkGCCard(rl_src.reg, rl_array.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001255 }
1256}
1257
Ian Rogersa9a82542013-10-04 11:17:26 -07001258
Brian Carlstrom7940e442013-07-12 13:46:57 -07001259void ArmMir2Lir::GenShiftImmOpLong(Instruction::Code opcode,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001260 RegLocation rl_dest, RegLocation rl_src, RegLocation rl_shift) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001261 rl_src = LoadValueWide(rl_src, kCoreReg);
1262 // Per spec, we only care about low 6 bits of shift amount.
1263 int shift_amount = mir_graph_->ConstantValue(rl_shift) & 0x3f;
1264 if (shift_amount == 0) {
1265 StoreValueWide(rl_dest, rl_src);
1266 return;
1267 }
1268 if (BadOverlap(rl_src, rl_dest)) {
1269 GenShiftOpLong(opcode, rl_dest, rl_src, rl_shift);
1270 return;
1271 }
1272 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Brian Carlstromdf629502013-07-17 22:39:56 -07001273 switch (opcode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001274 case Instruction::SHL_LONG:
1275 case Instruction::SHL_LONG_2ADDR:
1276 if (shift_amount == 1) {
buzbee2700f7e2014-03-07 09:46:20 -08001277 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), rl_src.reg.GetLow());
1278 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), rl_src.reg.GetHigh());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001279 } else if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001280 OpRegCopy(rl_result.reg.GetHigh(), rl_src.reg);
1281 LoadConstant(rl_result.reg.GetLow(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001282 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001283 OpRegRegImm(kOpLsl, rl_result.reg.GetHigh(), rl_src.reg.GetLow(), shift_amount - 32);
1284 LoadConstant(rl_result.reg.GetLow(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001285 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001286 OpRegRegImm(kOpLsl, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001287 OpRegRegRegShift(kOpOr, rl_result.reg.GetHigh(), rl_result.reg.GetHigh(), rl_src.reg.GetLow(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001288 EncodeShift(kArmLsr, 32 - shift_amount));
buzbee2700f7e2014-03-07 09:46:20 -08001289 OpRegRegImm(kOpLsl, rl_result.reg.GetLow(), rl_src.reg.GetLow(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001290 }
1291 break;
1292 case Instruction::SHR_LONG:
1293 case Instruction::SHR_LONG_2ADDR:
1294 if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001295 OpRegCopy(rl_result.reg.GetLow(), rl_src.reg.GetHigh());
1296 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001297 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001298 OpRegRegImm(kOpAsr, rl_result.reg.GetLow(), rl_src.reg.GetHigh(), shift_amount - 32);
1299 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001300 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001301 RegStorage t_reg = AllocTemp();
1302 OpRegRegImm(kOpLsr, t_reg, rl_src.reg.GetLow(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001303 OpRegRegRegShift(kOpOr, rl_result.reg.GetLow(), t_reg, rl_src.reg.GetHigh(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001304 EncodeShift(kArmLsl, 32 - shift_amount));
1305 FreeTemp(t_reg);
buzbee2700f7e2014-03-07 09:46:20 -08001306 OpRegRegImm(kOpAsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001307 }
1308 break;
1309 case Instruction::USHR_LONG:
1310 case Instruction::USHR_LONG_2ADDR:
1311 if (shift_amount == 32) {
buzbee2700f7e2014-03-07 09:46:20 -08001312 OpRegCopy(rl_result.reg.GetLow(), rl_src.reg.GetHigh());
1313 LoadConstant(rl_result.reg.GetHigh(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001314 } else if (shift_amount > 31) {
buzbee2700f7e2014-03-07 09:46:20 -08001315 OpRegRegImm(kOpLsr, rl_result.reg.GetLow(), rl_src.reg.GetHigh(), shift_amount - 32);
1316 LoadConstant(rl_result.reg.GetHigh(), 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001317 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001318 RegStorage t_reg = AllocTemp();
1319 OpRegRegImm(kOpLsr, t_reg, rl_src.reg.GetLow(), shift_amount);
Ian Rogerse2143c02014-03-28 08:47:16 -07001320 OpRegRegRegShift(kOpOr, rl_result.reg.GetLow(), t_reg, rl_src.reg.GetHigh(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001321 EncodeShift(kArmLsl, 32 - shift_amount));
1322 FreeTemp(t_reg);
buzbee2700f7e2014-03-07 09:46:20 -08001323 OpRegRegImm(kOpLsr, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), shift_amount);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001324 }
1325 break;
1326 default:
1327 LOG(FATAL) << "Unexpected case";
1328 }
1329 StoreValueWide(rl_dest, rl_result);
1330}
1331
1332void ArmMir2Lir::GenArithImmOpLong(Instruction::Code opcode,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001333 RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001334 if ((opcode == Instruction::SUB_LONG_2ADDR) || (opcode == Instruction::SUB_LONG)) {
1335 if (!rl_src2.is_const) {
1336 // Don't bother with special handling for subtract from immediate.
1337 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2);
1338 return;
1339 }
1340 } else {
1341 // Normalize
1342 if (!rl_src2.is_const) {
1343 DCHECK(rl_src1.is_const);
Vladimir Marko58af1f92013-12-19 13:31:15 +00001344 std::swap(rl_src1, rl_src2);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001345 }
1346 }
1347 if (BadOverlap(rl_src1, rl_dest)) {
1348 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2);
1349 return;
1350 }
1351 DCHECK(rl_src2.is_const);
1352 int64_t val = mir_graph_->ConstantValueWide(rl_src2);
1353 uint32_t val_lo = Low32Bits(val);
1354 uint32_t val_hi = High32Bits(val);
1355 int32_t mod_imm_lo = ModifiedImmediate(val_lo);
1356 int32_t mod_imm_hi = ModifiedImmediate(val_hi);
1357
1358 // Only a subset of add/sub immediate instructions set carry - so bail if we don't fit
Brian Carlstromdf629502013-07-17 22:39:56 -07001359 switch (opcode) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001360 case Instruction::ADD_LONG:
1361 case Instruction::ADD_LONG_2ADDR:
1362 case Instruction::SUB_LONG:
1363 case Instruction::SUB_LONG_2ADDR:
1364 if ((mod_imm_lo < 0) || (mod_imm_hi < 0)) {
1365 GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2);
1366 return;
1367 }
1368 break;
1369 default:
1370 break;
1371 }
1372 rl_src1 = LoadValueWide(rl_src1, kCoreReg);
1373 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1374 // NOTE: once we've done the EvalLoc on dest, we can no longer bail.
1375 switch (opcode) {
1376 case Instruction::ADD_LONG:
1377 case Instruction::ADD_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001378 NewLIR3(kThumb2AddRRI8M, rl_result.reg.GetLowReg(), rl_src1.reg.GetLowReg(), mod_imm_lo);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001379 NewLIR3(kThumb2AdcRRI8M, rl_result.reg.GetHighReg(), rl_src1.reg.GetHighReg(), mod_imm_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001380 break;
1381 case Instruction::OR_LONG:
1382 case Instruction::OR_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001383 if ((val_lo != 0) || (rl_result.reg.GetLowReg() != rl_src1.reg.GetLowReg())) {
1384 OpRegRegImm(kOpOr, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001385 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001386 if ((val_hi != 0) || (rl_result.reg.GetHighReg() != rl_src1.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001387 OpRegRegImm(kOpOr, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001388 }
1389 break;
1390 case Instruction::XOR_LONG:
1391 case Instruction::XOR_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001392 OpRegRegImm(kOpXor, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
1393 OpRegRegImm(kOpXor, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001394 break;
1395 case Instruction::AND_LONG:
1396 case Instruction::AND_LONG_2ADDR:
buzbee2700f7e2014-03-07 09:46:20 -08001397 if ((val_lo != 0xffffffff) || (rl_result.reg.GetLowReg() != rl_src1.reg.GetLowReg())) {
1398 OpRegRegImm(kOpAnd, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), val_lo);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001399 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001400 if ((val_hi != 0xffffffff) || (rl_result.reg.GetHighReg() != rl_src1.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001401 OpRegRegImm(kOpAnd, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), val_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001402 }
1403 break;
1404 case Instruction::SUB_LONG_2ADDR:
1405 case Instruction::SUB_LONG:
buzbee2700f7e2014-03-07 09:46:20 -08001406 NewLIR3(kThumb2SubRRI8M, rl_result.reg.GetLowReg(), rl_src1.reg.GetLowReg(), mod_imm_lo);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001407 NewLIR3(kThumb2SbcRRI8M, rl_result.reg.GetHighReg(), rl_src1.reg.GetHighReg(), mod_imm_hi);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001408 break;
1409 default:
1410 LOG(FATAL) << "Unexpected opcode " << opcode;
1411 }
1412 StoreValueWide(rl_dest, rl_result);
1413}
1414
1415} // namespace art