Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* This file contains codegen for the Mips ISA */ |
| 18 | |
| 19 | #include "codegen_mips.h" |
| 20 | #include "dex/quick/mir_to_lir-inl.h" |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame^] | 21 | #include "dex/reg_storage_eq.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "mips_lir.h" |
| 24 | #include "mirror/array.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| 28 | /* |
| 29 | * Compare two 64-bit values |
| 30 | * x = y return 0 |
| 31 | * x < y return -1 |
| 32 | * x > y return 1 |
| 33 | * |
| 34 | * slt t0, x.hi, y.hi; # (x.hi < y.hi) ? 1:0 |
| 35 | * sgt t1, x.hi, y.hi; # (y.hi > x.hi) ? 1:0 |
| 36 | * subu res, t0, t1 # res = -1:1:0 for [ < > = ] |
| 37 | * bnez res, finish |
| 38 | * sltu t0, x.lo, y.lo |
| 39 | * sgtu r1, x.lo, y.lo |
| 40 | * subu res, t0, t1 |
| 41 | * finish: |
| 42 | * |
| 43 | */ |
| 44 | void MipsMir2Lir::GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 45 | RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 46 | rl_src1 = LoadValueWide(rl_src1, kCoreReg); |
| 47 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 48 | RegStorage t0 = AllocTemp(); |
| 49 | RegStorage t1 = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 50 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 51 | NewLIR3(kMipsSlt, t0.GetReg(), rl_src1.reg.GetHighReg(), rl_src2.reg.GetHighReg()); |
| 52 | NewLIR3(kMipsSlt, t1.GetReg(), rl_src2.reg.GetHighReg(), rl_src1.reg.GetHighReg()); |
| 53 | NewLIR3(kMipsSubu, rl_result.reg.GetReg(), t1.GetReg(), t0.GetReg()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 54 | LIR* branch = OpCmpImmBranch(kCondNe, rl_result.reg, 0, NULL); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 55 | NewLIR3(kMipsSltu, t0.GetReg(), rl_src1.reg.GetLowReg(), rl_src2.reg.GetLowReg()); |
| 56 | NewLIR3(kMipsSltu, t1.GetReg(), rl_src2.reg.GetLowReg(), rl_src1.reg.GetLowReg()); |
| 57 | NewLIR3(kMipsSubu, rl_result.reg.GetReg(), t1.GetReg(), t0.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 58 | FreeTemp(t0); |
| 59 | FreeTemp(t1); |
| 60 | LIR* target = NewLIR0(kPseudoTargetLabel); |
| 61 | branch->target = target; |
| 62 | StoreValue(rl_dest, rl_result); |
| 63 | } |
| 64 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 65 | LIR* MipsMir2Lir::OpCmpBranch(ConditionCode cond, RegStorage src1, RegStorage src2, LIR* target) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 66 | LIR* branch; |
| 67 | MipsOpCode slt_op; |
| 68 | MipsOpCode br_op; |
| 69 | bool cmp_zero = false; |
| 70 | bool swapped = false; |
| 71 | switch (cond) { |
| 72 | case kCondEq: |
| 73 | br_op = kMipsBeq; |
| 74 | cmp_zero = true; |
| 75 | break; |
| 76 | case kCondNe: |
| 77 | br_op = kMipsBne; |
| 78 | cmp_zero = true; |
| 79 | break; |
Vladimir Marko | 58af1f9 | 2013-12-19 13:31:15 +0000 | [diff] [blame] | 80 | case kCondUlt: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | slt_op = kMipsSltu; |
| 82 | br_op = kMipsBnez; |
| 83 | break; |
Vladimir Marko | 58af1f9 | 2013-12-19 13:31:15 +0000 | [diff] [blame] | 84 | case kCondUge: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 85 | slt_op = kMipsSltu; |
| 86 | br_op = kMipsBeqz; |
| 87 | break; |
| 88 | case kCondGe: |
| 89 | slt_op = kMipsSlt; |
| 90 | br_op = kMipsBeqz; |
| 91 | break; |
| 92 | case kCondGt: |
| 93 | slt_op = kMipsSlt; |
| 94 | br_op = kMipsBnez; |
| 95 | swapped = true; |
| 96 | break; |
| 97 | case kCondLe: |
| 98 | slt_op = kMipsSlt; |
| 99 | br_op = kMipsBeqz; |
| 100 | swapped = true; |
| 101 | break; |
| 102 | case kCondLt: |
| 103 | slt_op = kMipsSlt; |
| 104 | br_op = kMipsBnez; |
| 105 | break; |
| 106 | case kCondHi: // Gtu |
| 107 | slt_op = kMipsSltu; |
| 108 | br_op = kMipsBnez; |
| 109 | swapped = true; |
| 110 | break; |
| 111 | default: |
| 112 | LOG(FATAL) << "No support for ConditionCode: " << cond; |
| 113 | return NULL; |
| 114 | } |
| 115 | if (cmp_zero) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 116 | branch = NewLIR2(br_op, src1.GetReg(), src2.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 117 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 118 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 119 | if (swapped) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 120 | NewLIR3(slt_op, t_reg.GetReg(), src2.GetReg(), src1.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 121 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 122 | NewLIR3(slt_op, t_reg.GetReg(), src1.GetReg(), src2.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 123 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 124 | branch = NewLIR1(br_op, t_reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 125 | FreeTemp(t_reg); |
| 126 | } |
| 127 | branch->target = target; |
| 128 | return branch; |
| 129 | } |
| 130 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 131 | LIR* MipsMir2Lir::OpCmpImmBranch(ConditionCode cond, RegStorage reg, int check_value, LIR* target) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 132 | LIR* branch; |
| 133 | if (check_value != 0) { |
| 134 | // TUNING: handle s16 & kCondLt/Mi case using slti |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 135 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 136 | LoadConstant(t_reg, check_value); |
| 137 | branch = OpCmpBranch(cond, reg, t_reg, target); |
| 138 | FreeTemp(t_reg); |
| 139 | return branch; |
| 140 | } |
| 141 | MipsOpCode opc; |
| 142 | switch (cond) { |
| 143 | case kCondEq: opc = kMipsBeqz; break; |
| 144 | case kCondGe: opc = kMipsBgez; break; |
| 145 | case kCondGt: opc = kMipsBgtz; break; |
| 146 | case kCondLe: opc = kMipsBlez; break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 147 | // case KCondMi: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 148 | case kCondLt: opc = kMipsBltz; break; |
| 149 | case kCondNe: opc = kMipsBnez; break; |
| 150 | default: |
| 151 | // Tuning: use slti when applicable |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 152 | RegStorage t_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 153 | LoadConstant(t_reg, check_value); |
| 154 | branch = OpCmpBranch(cond, reg, t_reg, target); |
| 155 | FreeTemp(t_reg); |
| 156 | return branch; |
| 157 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 158 | branch = NewLIR1(opc, reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 159 | branch->target = target; |
| 160 | return branch; |
| 161 | } |
| 162 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 163 | LIR* MipsMir2Lir::OpRegCopyNoInsert(RegStorage r_dest, RegStorage r_src) { |
| 164 | // If src or dest is a pair, we'll be using low reg. |
| 165 | if (r_dest.IsPair()) { |
| 166 | r_dest = r_dest.GetLow(); |
| 167 | } |
| 168 | if (r_src.IsPair()) { |
| 169 | r_src = r_src.GetLow(); |
| 170 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 171 | if (r_dest.IsFloat() || r_src.IsFloat()) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 172 | return OpFpRegCopy(r_dest, r_src); |
| 173 | LIR* res = RawLIR(current_dalvik_offset_, kMipsMove, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 174 | r_dest.GetReg(), r_src.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 175 | if (!(cu_->disable_opt & (1 << kSafeOptimizations)) && r_dest == r_src) { |
| 176 | res->flags.is_nop = true; |
| 177 | } |
| 178 | return res; |
| 179 | } |
| 180 | |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 181 | void MipsMir2Lir::OpRegCopy(RegStorage r_dest, RegStorage r_src) { |
| 182 | if (r_dest != r_src) { |
| 183 | LIR *res = OpRegCopyNoInsert(r_dest, r_src); |
| 184 | AppendLIR(res); |
| 185 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 186 | } |
| 187 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 188 | void MipsMir2Lir::OpRegCopyWide(RegStorage r_dest, RegStorage r_src) { |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 189 | if (r_dest != r_src) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 190 | bool dest_fp = r_dest.IsFloat(); |
| 191 | bool src_fp = r_src.IsFloat(); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 192 | if (dest_fp) { |
| 193 | if (src_fp) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 194 | OpRegCopy(r_dest, r_src); |
| 195 | } else { |
| 196 | /* note the operands are swapped for the mtc1 instr */ |
| 197 | NewLIR2(kMipsMtc1, r_src.GetLowReg(), r_dest.GetLowReg()); |
| 198 | NewLIR2(kMipsMtc1, r_src.GetHighReg(), r_dest.GetHighReg()); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 199 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 200 | } else { |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 201 | if (src_fp) { |
| 202 | NewLIR2(kMipsMfc1, r_dest.GetLowReg(), r_src.GetLowReg()); |
| 203 | NewLIR2(kMipsMfc1, r_dest.GetHighReg(), r_src.GetHighReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 204 | } else { |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 205 | // Handle overlap |
| 206 | if (r_src.GetHighReg() == r_dest.GetLowReg()) { |
| 207 | OpRegCopy(r_dest.GetHigh(), r_src.GetHigh()); |
| 208 | OpRegCopy(r_dest.GetLow(), r_src.GetLow()); |
| 209 | } else { |
| 210 | OpRegCopy(r_dest.GetLow(), r_src.GetLow()); |
| 211 | OpRegCopy(r_dest.GetHigh(), r_src.GetHigh()); |
| 212 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 218 | void MipsMir2Lir::GenSelect(BasicBlock* bb, MIR* mir) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 219 | UNIMPLEMENTED(FATAL) << "Need codegen for select"; |
| 220 | } |
| 221 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 222 | void MipsMir2Lir::GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 223 | UNIMPLEMENTED(FATAL) << "Need codegen for fused long cmp branch"; |
| 224 | } |
| 225 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 226 | RegLocation MipsMir2Lir::GenDivRem(RegLocation rl_dest, RegStorage reg1, RegStorage reg2, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 227 | bool is_div) { |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 228 | NewLIR2(kMipsDiv, reg1.GetReg(), reg2.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 229 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 230 | if (is_div) { |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 231 | NewLIR1(kMipsMflo, rl_result.reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 232 | } else { |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 233 | NewLIR1(kMipsMfhi, rl_result.reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 234 | } |
| 235 | return rl_result; |
| 236 | } |
| 237 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 238 | RegLocation MipsMir2Lir::GenDivRemLit(RegLocation rl_dest, RegStorage reg1, int lit, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 239 | bool is_div) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 240 | RegStorage t_reg = AllocTemp(); |
| 241 | NewLIR3(kMipsAddiu, t_reg.GetReg(), rZERO, lit); |
| 242 | NewLIR2(kMipsDiv, reg1.GetReg(), t_reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 243 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 244 | if (is_div) { |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 245 | NewLIR1(kMipsMflo, rl_result.reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 246 | } else { |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 247 | NewLIR1(kMipsMfhi, rl_result.reg.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 248 | } |
| 249 | FreeTemp(t_reg); |
| 250 | return rl_result; |
| 251 | } |
| 252 | |
Mark Mendell | 2bf31e6 | 2014-01-23 12:13:40 -0800 | [diff] [blame] | 253 | RegLocation MipsMir2Lir::GenDivRem(RegLocation rl_dest, RegLocation rl_src1, |
| 254 | RegLocation rl_src2, bool is_div, bool check_zero) { |
| 255 | LOG(FATAL) << "Unexpected use of GenDivRem for Mips"; |
| 256 | return rl_dest; |
| 257 | } |
| 258 | |
| 259 | RegLocation MipsMir2Lir::GenDivRemLit(RegLocation rl_dest, RegLocation rl_src1, int lit, bool is_div) { |
| 260 | LOG(FATAL) << "Unexpected use of GenDivRemLit for Mips"; |
| 261 | return rl_dest; |
| 262 | } |
| 263 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 264 | void MipsMir2Lir::OpLea(RegStorage r_base, RegStorage reg1, RegStorage reg2, int scale, |
| 265 | int offset) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 266 | LOG(FATAL) << "Unexpected use of OpLea for Arm"; |
| 267 | } |
| 268 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 269 | void MipsMir2Lir::OpTlsCmp(ThreadOffset<4> offset, int val) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 270 | LOG(FATAL) << "Unexpected use of OpTlsCmp for Arm"; |
| 271 | } |
| 272 | |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 273 | void MipsMir2Lir::OpTlsCmp(ThreadOffset<8> offset, int val) { |
| 274 | UNIMPLEMENTED(FATAL) << "Should not be called."; |
| 275 | } |
| 276 | |
Vladimir Marko | 1c282e2 | 2013-11-21 14:49:47 +0000 | [diff] [blame] | 277 | bool MipsMir2Lir::GenInlinedCas(CallInfo* info, bool is_long, bool is_object) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 278 | DCHECK_NE(cu_->instruction_set, kThumb2); |
| 279 | return false; |
| 280 | } |
| 281 | |
| 282 | bool MipsMir2Lir::GenInlinedSqrt(CallInfo* info) { |
| 283 | DCHECK_NE(cu_->instruction_set, kThumb2); |
| 284 | return false; |
| 285 | } |
| 286 | |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 287 | bool MipsMir2Lir::GenInlinedPeek(CallInfo* info, OpSize size) { |
| 288 | if (size != kSignedByte) { |
| 289 | // MIPS supports only aligned access. Defer unaligned access to JNI implementation. |
| 290 | return false; |
| 291 | } |
| 292 | RegLocation rl_src_address = info->args[0]; // long address |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 293 | rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1] |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 294 | RegLocation rl_dest = InlineTarget(info); |
| 295 | RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); |
| 296 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 297 | DCHECK(size == kSignedByte); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 298 | LoadBaseDisp(rl_address.reg, 0, rl_result.reg, size, kNotVolatile); |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 299 | StoreValue(rl_dest, rl_result); |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | bool MipsMir2Lir::GenInlinedPoke(CallInfo* info, OpSize size) { |
| 304 | if (size != kSignedByte) { |
| 305 | // MIPS supports only aligned access. Defer unaligned access to JNI implementation. |
| 306 | return false; |
| 307 | } |
| 308 | RegLocation rl_src_address = info->args[0]; // long address |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 309 | rl_src_address = NarrowRegLoc(rl_src_address); // ignore high half in info->args[1] |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 310 | RegLocation rl_src_value = info->args[2]; // [size] value |
| 311 | RegLocation rl_address = LoadValue(rl_src_address, kCoreReg); |
| 312 | DCHECK(size == kSignedByte); |
| 313 | RegLocation rl_value = LoadValue(rl_src_value, kCoreReg); |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 314 | StoreBaseDisp(rl_address.reg, 0, rl_value.reg, size, kNotVolatile); |
Vladimir Marko | e508a20 | 2013-11-04 15:24:22 +0000 | [diff] [blame] | 315 | return true; |
| 316 | } |
| 317 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 318 | LIR* MipsMir2Lir::OpPcRelLoad(RegStorage reg, LIR* target) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 319 | LOG(FATAL) << "Unexpected use of OpPcRelLoad for Mips"; |
| 320 | return NULL; |
| 321 | } |
| 322 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 323 | LIR* MipsMir2Lir::OpVldm(RegStorage r_base, int count) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 324 | LOG(FATAL) << "Unexpected use of OpVldm for Mips"; |
| 325 | return NULL; |
| 326 | } |
| 327 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 328 | LIR* MipsMir2Lir::OpVstm(RegStorage r_base, int count) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 329 | LOG(FATAL) << "Unexpected use of OpVstm for Mips"; |
| 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | void MipsMir2Lir::GenMultiplyByTwoBitMultiplier(RegLocation rl_src, |
| 334 | RegLocation rl_result, int lit, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 335 | int first_bit, int second_bit) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 336 | RegStorage t_reg = AllocTemp(); |
| 337 | OpRegRegImm(kOpLsl, t_reg, rl_src.reg, second_bit - first_bit); |
| 338 | OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 339 | FreeTemp(t_reg); |
| 340 | if (first_bit != 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 341 | OpRegRegImm(kOpLsl, rl_result.reg, rl_result.reg, first_bit); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 345 | void MipsMir2Lir::GenDivZeroCheckWide(RegStorage reg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 346 | DCHECK(reg.IsPair()); // TODO: support k64BitSolo. |
| 347 | RegStorage t_reg = AllocTemp(); |
| 348 | OpRegRegReg(kOpOr, t_reg, reg.GetLow(), reg.GetHigh()); |
Mingyao Yang | d15f4e2 | 2014-04-17 18:46:24 -0700 | [diff] [blame] | 349 | GenDivZeroCheck(t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 350 | FreeTemp(t_reg); |
| 351 | } |
| 352 | |
| 353 | // Test suspend flag, return target of taken suspend branch |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 354 | LIR* MipsMir2Lir::OpTestSuspend(LIR* target) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 355 | OpRegImm(kOpSub, rs_rMIPS_SUSPEND, 1); |
| 356 | return OpCmpImmBranch((target == NULL) ? kCondEq : kCondNe, rs_rMIPS_SUSPEND, 0, target); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | // Decrement register and branch on condition |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 360 | LIR* MipsMir2Lir::OpDecAndBranch(ConditionCode c_code, RegStorage reg, LIR* target) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 361 | OpRegImm(kOpSub, reg, 1); |
| 362 | return OpCmpImmBranch(c_code, reg, 0, target); |
| 363 | } |
| 364 | |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 365 | bool MipsMir2Lir::SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 366 | RegLocation rl_src, RegLocation rl_dest, int lit) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 367 | LOG(FATAL) << "Unexpected use of smallLiteralDive in Mips"; |
| 368 | return false; |
| 369 | } |
| 370 | |
Ian Rogers | e2143c0 | 2014-03-28 08:47:16 -0700 | [diff] [blame] | 371 | bool MipsMir2Lir::EasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit) { |
| 372 | LOG(FATAL) << "Unexpected use of easyMultiply in Mips"; |
| 373 | return false; |
| 374 | } |
| 375 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 376 | LIR* MipsMir2Lir::OpIT(ConditionCode cond, const char* guide) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 377 | LOG(FATAL) << "Unexpected use of OpIT in Mips"; |
| 378 | return NULL; |
| 379 | } |
| 380 | |
Dave Allison | 3da67a5 | 2014-04-02 17:03:45 -0700 | [diff] [blame] | 381 | void MipsMir2Lir::OpEndIT(LIR* it) { |
| 382 | LOG(FATAL) << "Unexpected use of OpEndIT in Mips"; |
| 383 | } |
| 384 | |
| 385 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 386 | void MipsMir2Lir::GenMulLong(Instruction::Code opcode, RegLocation rl_dest, |
| 387 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 388 | LOG(FATAL) << "Unexpected use of GenMulLong for Mips"; |
| 389 | } |
| 390 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 391 | void MipsMir2Lir::GenAddLong(Instruction::Code opcode, RegLocation rl_dest, |
| 392 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 393 | rl_src1 = LoadValueWide(rl_src1, kCoreReg); |
| 394 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 395 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 396 | /* |
| 397 | * [v1 v0] = [a1 a0] + [a3 a2]; |
| 398 | * addu v0,a2,a0 |
| 399 | * addu t1,a3,a1 |
| 400 | * sltu v1,v0,a2 |
| 401 | * addu v1,v1,t1 |
| 402 | */ |
| 403 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 404 | OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src2.reg.GetLow(), rl_src1.reg.GetLow()); |
| 405 | RegStorage t_reg = AllocTemp(); |
| 406 | OpRegRegReg(kOpAdd, t_reg, rl_src2.reg.GetHigh(), rl_src1.reg.GetHigh()); |
| 407 | NewLIR3(kMipsSltu, rl_result.reg.GetHighReg(), rl_result.reg.GetLowReg(), rl_src2.reg.GetLowReg()); |
| 408 | OpRegRegReg(kOpAdd, rl_result.reg.GetHigh(), rl_result.reg.GetHigh(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 409 | FreeTemp(t_reg); |
| 410 | StoreValueWide(rl_dest, rl_result); |
| 411 | } |
| 412 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 413 | void MipsMir2Lir::GenSubLong(Instruction::Code opcode, RegLocation rl_dest, |
| 414 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 415 | rl_src1 = LoadValueWide(rl_src1, kCoreReg); |
| 416 | rl_src2 = LoadValueWide(rl_src2, kCoreReg); |
| 417 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 418 | /* |
| 419 | * [v1 v0] = [a1 a0] - [a3 a2]; |
| 420 | * sltu t1,a0,a2 |
| 421 | * subu v0,a0,a2 |
| 422 | * subu v1,a1,a3 |
| 423 | * subu v1,v1,t1 |
| 424 | */ |
| 425 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 426 | RegStorage t_reg = AllocTemp(); |
| 427 | NewLIR3(kMipsSltu, t_reg.GetReg(), rl_src1.reg.GetLowReg(), rl_src2.reg.GetLowReg()); |
| 428 | OpRegRegReg(kOpSub, rl_result.reg.GetLow(), rl_src1.reg.GetLow(), rl_src2.reg.GetLow()); |
| 429 | OpRegRegReg(kOpSub, rl_result.reg.GetHigh(), rl_src1.reg.GetHigh(), rl_src2.reg.GetHigh()); |
| 430 | OpRegRegReg(kOpSub, rl_result.reg.GetHigh(), rl_result.reg.GetHigh(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 431 | FreeTemp(t_reg); |
| 432 | StoreValueWide(rl_dest, rl_result); |
| 433 | } |
| 434 | |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 435 | void MipsMir2Lir::GenNotLong(RegLocation rl_dest, RegLocation rl_src) { |
| 436 | LOG(FATAL) << "Unexpected use GenNotLong()"; |
| 437 | } |
| 438 | |
| 439 | void MipsMir2Lir::GenDivRemLong(Instruction::Code, RegLocation rl_dest, RegLocation rl_src1, |
| 440 | RegLocation rl_src2, bool is_div) { |
| 441 | LOG(FATAL) << "Unexpected use GenDivRemLong()"; |
| 442 | } |
| 443 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 444 | void MipsMir2Lir::GenNegLong(RegLocation rl_dest, RegLocation rl_src) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 445 | rl_src = LoadValueWide(rl_src, kCoreReg); |
| 446 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 447 | /* |
| 448 | * [v1 v0] = -[a1 a0] |
| 449 | * negu v0,a0 |
| 450 | * negu v1,a1 |
| 451 | * sltu t1,r_zero |
| 452 | * subu v1,v1,t1 |
| 453 | */ |
| 454 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 455 | OpRegReg(kOpNeg, rl_result.reg.GetLow(), rl_src.reg.GetLow()); |
| 456 | OpRegReg(kOpNeg, rl_result.reg.GetHigh(), rl_src.reg.GetHigh()); |
| 457 | RegStorage t_reg = AllocTemp(); |
| 458 | NewLIR3(kMipsSltu, t_reg.GetReg(), rZERO, rl_result.reg.GetLowReg()); |
| 459 | OpRegRegReg(kOpSub, rl_result.reg.GetHigh(), rl_result.reg.GetHigh(), t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 460 | FreeTemp(t_reg); |
| 461 | StoreValueWide(rl_dest, rl_result); |
| 462 | } |
| 463 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 464 | void MipsMir2Lir::GenAndLong(Instruction::Code opcode, RegLocation rl_dest, |
| 465 | RegLocation rl_src1, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 466 | RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 467 | LOG(FATAL) << "Unexpected use of GenAndLong for Mips"; |
| 468 | } |
| 469 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 470 | void MipsMir2Lir::GenOrLong(Instruction::Code opcode, RegLocation rl_dest, |
| 471 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 472 | LOG(FATAL) << "Unexpected use of GenOrLong for Mips"; |
| 473 | } |
| 474 | |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 475 | void MipsMir2Lir::GenXorLong(Instruction::Code opcode, RegLocation rl_dest, |
| 476 | RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 477 | LOG(FATAL) << "Unexpected use of GenXorLong for Mips"; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Generate array load |
| 482 | */ |
| 483 | void MipsMir2Lir::GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 484 | RegLocation rl_index, RegLocation rl_dest, int scale) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 485 | RegisterClass reg_class = RegClassBySize(size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 486 | int len_offset = mirror::Array::LengthOffset().Int32Value(); |
| 487 | int data_offset; |
| 488 | RegLocation rl_result; |
Douglas Leung | 2db3e26 | 2014-06-25 16:02:55 -0700 | [diff] [blame] | 489 | rl_array = LoadValue(rl_array, kRefReg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 490 | rl_index = LoadValue(rl_index, kCoreReg); |
| 491 | |
Douglas Leung | 2db3e26 | 2014-06-25 16:02:55 -0700 | [diff] [blame] | 492 | // FIXME: need to add support for rl_index.is_const. |
| 493 | |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 494 | if (size == k64 || size == kDouble) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 495 | data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 496 | } else { |
| 497 | data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 498 | } |
| 499 | |
| 500 | /* null object? */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 501 | GenNullCheck(rl_array.reg, opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 502 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 503 | RegStorage reg_ptr = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 504 | bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK)); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 505 | RegStorage reg_len; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 506 | if (needs_range_check) { |
| 507 | reg_len = AllocTemp(); |
| 508 | /* Get len */ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 509 | Load32Disp(rl_array.reg, len_offset, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 510 | } |
| 511 | /* reg_ptr -> array data */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 512 | OpRegRegImm(kOpAdd, reg_ptr, rl_array.reg, data_offset); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 513 | FreeTemp(rl_array.reg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 514 | if ((size == k64) || (size == kDouble)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 515 | if (scale) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 516 | RegStorage r_new_index = AllocTemp(); |
| 517 | OpRegRegImm(kOpLsl, r_new_index, rl_index.reg, scale); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 518 | OpRegReg(kOpAdd, reg_ptr, r_new_index); |
| 519 | FreeTemp(r_new_index); |
| 520 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 521 | OpRegReg(kOpAdd, reg_ptr, rl_index.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 522 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 523 | FreeTemp(rl_index.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 524 | rl_result = EvalLoc(rl_dest, reg_class, true); |
| 525 | |
| 526 | if (needs_range_check) { |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 527 | GenArrayBoundsCheck(rl_index.reg, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 528 | FreeTemp(reg_len); |
| 529 | } |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 530 | LoadBaseDisp(reg_ptr, 0, rl_result.reg, size, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 531 | |
| 532 | FreeTemp(reg_ptr); |
| 533 | StoreValueWide(rl_dest, rl_result); |
| 534 | } else { |
| 535 | rl_result = EvalLoc(rl_dest, reg_class, true); |
| 536 | |
| 537 | if (needs_range_check) { |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 538 | GenArrayBoundsCheck(rl_index.reg, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 539 | FreeTemp(reg_len); |
| 540 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 541 | LoadBaseIndexed(reg_ptr, rl_index.reg, rl_result.reg, scale, size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 542 | |
| 543 | FreeTemp(reg_ptr); |
| 544 | StoreValue(rl_dest, rl_result); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | /* |
| 549 | * Generate array store |
| 550 | * |
| 551 | */ |
| 552 | void MipsMir2Lir::GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 553 | RegLocation rl_index, RegLocation rl_src, int scale, bool card_mark) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 554 | RegisterClass reg_class = RegClassBySize(size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 555 | int len_offset = mirror::Array::LengthOffset().Int32Value(); |
| 556 | int data_offset; |
| 557 | |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 558 | if (size == k64 || size == kDouble) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 559 | data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 560 | } else { |
| 561 | data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 562 | } |
| 563 | |
Douglas Leung | 2db3e26 | 2014-06-25 16:02:55 -0700 | [diff] [blame] | 564 | rl_array = LoadValue(rl_array, kRefReg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 565 | rl_index = LoadValue(rl_index, kCoreReg); |
Douglas Leung | 2db3e26 | 2014-06-25 16:02:55 -0700 | [diff] [blame] | 566 | |
| 567 | // FIXME: need to add support for rl_index.is_const. |
| 568 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 569 | RegStorage reg_ptr; |
Ian Rogers | 773aab1 | 2013-10-14 13:50:10 -0700 | [diff] [blame] | 570 | bool allocated_reg_ptr_temp = false; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 571 | if (IsTemp(rl_array.reg) && !card_mark) { |
| 572 | Clobber(rl_array.reg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 573 | reg_ptr = rl_array.reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 574 | } else { |
| 575 | reg_ptr = AllocTemp(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 576 | OpRegCopy(reg_ptr, rl_array.reg); |
Ian Rogers | 773aab1 | 2013-10-14 13:50:10 -0700 | [diff] [blame] | 577 | allocated_reg_ptr_temp = true; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /* null object? */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 581 | GenNullCheck(rl_array.reg, opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 582 | |
| 583 | bool needs_range_check = (!(opt_flags & MIR_IGNORE_RANGE_CHECK)); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 584 | RegStorage reg_len; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 585 | if (needs_range_check) { |
| 586 | reg_len = AllocTemp(); |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 587 | // NOTE: max live temps(4) here. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 588 | /* Get len */ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 589 | Load32Disp(rl_array.reg, len_offset, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 590 | } |
| 591 | /* reg_ptr -> array data */ |
| 592 | OpRegImm(kOpAdd, reg_ptr, data_offset); |
| 593 | /* at this point, reg_ptr points to array, 2 live temps */ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 594 | if ((size == k64) || (size == kDouble)) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 595 | // TUNING: specific wide routine that can handle fp regs |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 596 | if (scale) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 597 | RegStorage r_new_index = AllocTemp(); |
| 598 | OpRegRegImm(kOpLsl, r_new_index, rl_index.reg, scale); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 599 | OpRegReg(kOpAdd, reg_ptr, r_new_index); |
| 600 | FreeTemp(r_new_index); |
| 601 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 602 | OpRegReg(kOpAdd, reg_ptr, rl_index.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 603 | } |
| 604 | rl_src = LoadValueWide(rl_src, reg_class); |
| 605 | |
| 606 | if (needs_range_check) { |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 607 | GenArrayBoundsCheck(rl_index.reg, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 608 | FreeTemp(reg_len); |
| 609 | } |
| 610 | |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 611 | StoreBaseDisp(reg_ptr, 0, rl_src.reg, size, kNotVolatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 612 | } else { |
| 613 | rl_src = LoadValue(rl_src, reg_class); |
| 614 | if (needs_range_check) { |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 615 | GenArrayBoundsCheck(rl_index.reg, reg_len); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 616 | FreeTemp(reg_len); |
| 617 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 618 | StoreBaseIndexed(reg_ptr, rl_index.reg, rl_src.reg, scale, size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 619 | } |
Ian Rogers | 773aab1 | 2013-10-14 13:50:10 -0700 | [diff] [blame] | 620 | if (allocated_reg_ptr_temp) { |
| 621 | FreeTemp(reg_ptr); |
| 622 | } |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 623 | if (card_mark) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 624 | MarkGCCard(rl_src.reg, rl_array.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | void MipsMir2Lir::GenShiftImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 629 | RegLocation rl_src1, RegLocation rl_shift) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 630 | // Default implementation is just to ignore the constant case. |
| 631 | GenShiftOpLong(opcode, rl_dest, rl_src1, rl_shift); |
| 632 | } |
| 633 | |
| 634 | void MipsMir2Lir::GenArithImmOpLong(Instruction::Code opcode, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 635 | RegLocation rl_dest, RegLocation rl_src1, RegLocation rl_src2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 636 | // Default - bail to non-const handler. |
| 637 | GenArithOpLong(opcode, rl_dest, rl_src1, rl_src2); |
| 638 | } |
| 639 | |
| 640 | } // namespace art |