Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "intrinsics_arm.h" |
| 18 | |
| 19 | #include "arch/arm/instruction_set_features_arm.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 21 | #include "code_generator_arm.h" |
| 22 | #include "entrypoints/quick/quick_entrypoints.h" |
| 23 | #include "intrinsics.h" |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 24 | #include "intrinsics_utils.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 25 | #include "mirror/array-inl.h" |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 26 | #include "mirror/string.h" |
| 27 | #include "thread.h" |
| 28 | #include "utils/arm/assembler_arm.h" |
| 29 | |
| 30 | namespace art { |
| 31 | |
| 32 | namespace arm { |
| 33 | |
| 34 | ArmAssembler* IntrinsicCodeGeneratorARM::GetAssembler() { |
| 35 | return codegen_->GetAssembler(); |
| 36 | } |
| 37 | |
| 38 | ArenaAllocator* IntrinsicCodeGeneratorARM::GetAllocator() { |
| 39 | return codegen_->GetGraph()->GetArena(); |
| 40 | } |
| 41 | |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 42 | using IntrinsicSlowPathARM = IntrinsicSlowPath<InvokeDexCallingConventionVisitorARM>; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 43 | |
| 44 | bool IntrinsicLocationsBuilderARM::TryDispatch(HInvoke* invoke) { |
| 45 | Dispatch(invoke); |
| 46 | LocationSummary* res = invoke->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 47 | if (res == nullptr) { |
| 48 | return false; |
| 49 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 50 | return res->Intrinsified(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | #define __ assembler-> |
| 54 | |
| 55 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 56 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 57 | LocationSummary::kNoCall, |
| 58 | kIntrinsified); |
| 59 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 60 | locations->SetOut(Location::RequiresRegister()); |
| 61 | } |
| 62 | |
| 63 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 64 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 65 | LocationSummary::kNoCall, |
| 66 | kIntrinsified); |
| 67 | locations->SetInAt(0, Location::RequiresRegister()); |
| 68 | locations->SetOut(Location::RequiresFpuRegister()); |
| 69 | } |
| 70 | |
| 71 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 72 | Location input = locations->InAt(0); |
| 73 | Location output = locations->Out(); |
| 74 | if (is64bit) { |
| 75 | __ vmovrrd(output.AsRegisterPairLow<Register>(), |
| 76 | output.AsRegisterPairHigh<Register>(), |
| 77 | FromLowSToD(input.AsFpuRegisterPairLow<SRegister>())); |
| 78 | } else { |
| 79 | __ vmovrs(output.AsRegister<Register>(), input.AsFpuRegister<SRegister>()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 84 | Location input = locations->InAt(0); |
| 85 | Location output = locations->Out(); |
| 86 | if (is64bit) { |
| 87 | __ vmovdrr(FromLowSToD(output.AsFpuRegisterPairLow<SRegister>()), |
| 88 | input.AsRegisterPairLow<Register>(), |
| 89 | input.AsRegisterPairHigh<Register>()); |
| 90 | } else { |
| 91 | __ vmovsr(output.AsFpuRegister<SRegister>(), input.AsRegister<Register>()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void IntrinsicLocationsBuilderARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 96 | CreateFPToIntLocations(arena_, invoke); |
| 97 | } |
| 98 | void IntrinsicLocationsBuilderARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 99 | CreateIntToFPLocations(arena_, invoke); |
| 100 | } |
| 101 | |
| 102 | void IntrinsicCodeGeneratorARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 103 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 104 | } |
| 105 | void IntrinsicCodeGeneratorARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 106 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void IntrinsicLocationsBuilderARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 110 | CreateFPToIntLocations(arena_, invoke); |
| 111 | } |
| 112 | void IntrinsicLocationsBuilderARM::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 113 | CreateIntToFPLocations(arena_, invoke); |
| 114 | } |
| 115 | |
| 116 | void IntrinsicCodeGeneratorARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 117 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 118 | } |
| 119 | void IntrinsicCodeGeneratorARM::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 120 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 124 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 125 | LocationSummary::kNoCall, |
| 126 | kIntrinsified); |
| 127 | locations->SetInAt(0, Location::RequiresRegister()); |
| 128 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 129 | } |
| 130 | |
| 131 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 132 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 133 | LocationSummary::kNoCall, |
| 134 | kIntrinsified); |
| 135 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 136 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 137 | } |
| 138 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 139 | static void GenNumberOfLeadingZeros(LocationSummary* locations, |
| 140 | Primitive::Type type, |
| 141 | ArmAssembler* assembler) { |
| 142 | Location in = locations->InAt(0); |
| 143 | Register out = locations->Out().AsRegister<Register>(); |
| 144 | |
| 145 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 146 | |
| 147 | if (type == Primitive::kPrimLong) { |
| 148 | Register in_reg_lo = in.AsRegisterPairLow<Register>(); |
| 149 | Register in_reg_hi = in.AsRegisterPairHigh<Register>(); |
| 150 | Label end; |
| 151 | __ clz(out, in_reg_hi); |
| 152 | __ CompareAndBranchIfNonZero(in_reg_hi, &end); |
| 153 | __ clz(out, in_reg_lo); |
| 154 | __ AddConstant(out, 32); |
| 155 | __ Bind(&end); |
| 156 | } else { |
| 157 | __ clz(out, in.AsRegister<Register>()); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 162 | CreateIntToIntLocations(arena_, invoke); |
| 163 | } |
| 164 | |
| 165 | void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 166 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 167 | } |
| 168 | |
| 169 | void IntrinsicLocationsBuilderARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 170 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 171 | LocationSummary::kNoCall, |
| 172 | kIntrinsified); |
| 173 | locations->SetInAt(0, Location::RequiresRegister()); |
| 174 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 175 | } |
| 176 | |
| 177 | void IntrinsicCodeGeneratorARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 178 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 179 | } |
| 180 | |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 181 | static void GenNumberOfTrailingZeros(LocationSummary* locations, |
| 182 | Primitive::Type type, |
| 183 | ArmAssembler* assembler) { |
| 184 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 185 | |
| 186 | Register out = locations->Out().AsRegister<Register>(); |
| 187 | |
| 188 | if (type == Primitive::kPrimLong) { |
| 189 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 190 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 191 | Label end; |
| 192 | __ rbit(out, in_reg_lo); |
| 193 | __ clz(out, out); |
| 194 | __ CompareAndBranchIfNonZero(in_reg_lo, &end); |
| 195 | __ rbit(out, in_reg_hi); |
| 196 | __ clz(out, out); |
| 197 | __ AddConstant(out, 32); |
| 198 | __ Bind(&end); |
| 199 | } else { |
| 200 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 201 | __ rbit(out, in); |
| 202 | __ clz(out, out); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 207 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 208 | LocationSummary::kNoCall, |
| 209 | kIntrinsified); |
| 210 | locations->SetInAt(0, Location::RequiresRegister()); |
| 211 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 212 | } |
| 213 | |
| 214 | void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 215 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 216 | } |
| 217 | |
| 218 | void IntrinsicLocationsBuilderARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 219 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 220 | LocationSummary::kNoCall, |
| 221 | kIntrinsified); |
| 222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 223 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 224 | } |
| 225 | |
| 226 | void IntrinsicCodeGeneratorARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 227 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 228 | } |
| 229 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 230 | static void MathAbsFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 231 | Location in = locations->InAt(0); |
| 232 | Location out = locations->Out(); |
| 233 | |
| 234 | if (is64bit) { |
| 235 | __ vabsd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 236 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 237 | } else { |
| 238 | __ vabss(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void IntrinsicLocationsBuilderARM::VisitMathAbsDouble(HInvoke* invoke) { |
| 243 | CreateFPToFPLocations(arena_, invoke); |
| 244 | } |
| 245 | |
| 246 | void IntrinsicCodeGeneratorARM::VisitMathAbsDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 247 | MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void IntrinsicLocationsBuilderARM::VisitMathAbsFloat(HInvoke* invoke) { |
| 251 | CreateFPToFPLocations(arena_, invoke); |
| 252 | } |
| 253 | |
| 254 | void IntrinsicCodeGeneratorARM::VisitMathAbsFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 255 | MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) { |
| 259 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 260 | LocationSummary::kNoCall, |
| 261 | kIntrinsified); |
| 262 | locations->SetInAt(0, Location::RequiresRegister()); |
| 263 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 264 | |
| 265 | locations->AddTemp(Location::RequiresRegister()); |
| 266 | } |
| 267 | |
| 268 | static void GenAbsInteger(LocationSummary* locations, |
| 269 | bool is64bit, |
| 270 | ArmAssembler* assembler) { |
| 271 | Location in = locations->InAt(0); |
| 272 | Location output = locations->Out(); |
| 273 | |
| 274 | Register mask = locations->GetTemp(0).AsRegister<Register>(); |
| 275 | |
| 276 | if (is64bit) { |
| 277 | Register in_reg_lo = in.AsRegisterPairLow<Register>(); |
| 278 | Register in_reg_hi = in.AsRegisterPairHigh<Register>(); |
| 279 | Register out_reg_lo = output.AsRegisterPairLow<Register>(); |
| 280 | Register out_reg_hi = output.AsRegisterPairHigh<Register>(); |
| 281 | |
| 282 | DCHECK_NE(out_reg_lo, in_reg_hi) << "Diagonal overlap unexpected."; |
| 283 | |
| 284 | __ Asr(mask, in_reg_hi, 31); |
| 285 | __ adds(out_reg_lo, in_reg_lo, ShifterOperand(mask)); |
| 286 | __ adc(out_reg_hi, in_reg_hi, ShifterOperand(mask)); |
| 287 | __ eor(out_reg_lo, mask, ShifterOperand(out_reg_lo)); |
| 288 | __ eor(out_reg_hi, mask, ShifterOperand(out_reg_hi)); |
| 289 | } else { |
| 290 | Register in_reg = in.AsRegister<Register>(); |
| 291 | Register out_reg = output.AsRegister<Register>(); |
| 292 | |
| 293 | __ Asr(mask, in_reg, 31); |
| 294 | __ add(out_reg, in_reg, ShifterOperand(mask)); |
| 295 | __ eor(out_reg, mask, ShifterOperand(out_reg)); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | void IntrinsicLocationsBuilderARM::VisitMathAbsInt(HInvoke* invoke) { |
| 300 | CreateIntToIntPlusTemp(arena_, invoke); |
| 301 | } |
| 302 | |
| 303 | void IntrinsicCodeGeneratorARM::VisitMathAbsInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 304 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
| 308 | void IntrinsicLocationsBuilderARM::VisitMathAbsLong(HInvoke* invoke) { |
| 309 | CreateIntToIntPlusTemp(arena_, invoke); |
| 310 | } |
| 311 | |
| 312 | void IntrinsicCodeGeneratorARM::VisitMathAbsLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 313 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | static void GenMinMax(LocationSummary* locations, |
| 317 | bool is_min, |
| 318 | ArmAssembler* assembler) { |
| 319 | Register op1 = locations->InAt(0).AsRegister<Register>(); |
| 320 | Register op2 = locations->InAt(1).AsRegister<Register>(); |
| 321 | Register out = locations->Out().AsRegister<Register>(); |
| 322 | |
| 323 | __ cmp(op1, ShifterOperand(op2)); |
| 324 | |
| 325 | __ it((is_min) ? Condition::LT : Condition::GT, kItElse); |
| 326 | __ mov(out, ShifterOperand(op1), is_min ? Condition::LT : Condition::GT); |
| 327 | __ mov(out, ShifterOperand(op2), is_min ? Condition::GE : Condition::LE); |
| 328 | } |
| 329 | |
| 330 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 331 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 332 | LocationSummary::kNoCall, |
| 333 | kIntrinsified); |
| 334 | locations->SetInAt(0, Location::RequiresRegister()); |
| 335 | locations->SetInAt(1, Location::RequiresRegister()); |
| 336 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 337 | } |
| 338 | |
| 339 | void IntrinsicLocationsBuilderARM::VisitMathMinIntInt(HInvoke* invoke) { |
| 340 | CreateIntIntToIntLocations(arena_, invoke); |
| 341 | } |
| 342 | |
| 343 | void IntrinsicCodeGeneratorARM::VisitMathMinIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 344 | GenMinMax(invoke->GetLocations(), /* is_min */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | void IntrinsicLocationsBuilderARM::VisitMathMaxIntInt(HInvoke* invoke) { |
| 348 | CreateIntIntToIntLocations(arena_, invoke); |
| 349 | } |
| 350 | |
| 351 | void IntrinsicCodeGeneratorARM::VisitMathMaxIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 352 | GenMinMax(invoke->GetLocations(), /* is_min */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void IntrinsicLocationsBuilderARM::VisitMathSqrt(HInvoke* invoke) { |
| 356 | CreateFPToFPLocations(arena_, invoke); |
| 357 | } |
| 358 | |
| 359 | void IntrinsicCodeGeneratorARM::VisitMathSqrt(HInvoke* invoke) { |
| 360 | LocationSummary* locations = invoke->GetLocations(); |
| 361 | ArmAssembler* assembler = GetAssembler(); |
| 362 | __ vsqrtd(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 363 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 364 | } |
| 365 | |
| 366 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekByte(HInvoke* invoke) { |
| 367 | CreateIntToIntLocations(arena_, invoke); |
| 368 | } |
| 369 | |
| 370 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekByte(HInvoke* invoke) { |
| 371 | ArmAssembler* assembler = GetAssembler(); |
| 372 | // Ignore upper 4B of long address. |
| 373 | __ ldrsb(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 374 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 375 | } |
| 376 | |
| 377 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 378 | CreateIntToIntLocations(arena_, invoke); |
| 379 | } |
| 380 | |
| 381 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 382 | ArmAssembler* assembler = GetAssembler(); |
| 383 | // Ignore upper 4B of long address. |
| 384 | __ ldr(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 385 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 386 | } |
| 387 | |
| 388 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 389 | CreateIntToIntLocations(arena_, invoke); |
| 390 | } |
| 391 | |
| 392 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 393 | ArmAssembler* assembler = GetAssembler(); |
| 394 | // Ignore upper 4B of long address. |
| 395 | Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>(); |
| 396 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 397 | // exception. So we can't use ldrd as addr may be unaligned. |
| 398 | Register lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>(); |
| 399 | Register hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>(); |
| 400 | if (addr == lo) { |
| 401 | __ ldr(hi, Address(addr, 4)); |
| 402 | __ ldr(lo, Address(addr, 0)); |
| 403 | } else { |
| 404 | __ ldr(lo, Address(addr, 0)); |
| 405 | __ ldr(hi, Address(addr, 4)); |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 410 | CreateIntToIntLocations(arena_, invoke); |
| 411 | } |
| 412 | |
| 413 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 414 | ArmAssembler* assembler = GetAssembler(); |
| 415 | // Ignore upper 4B of long address. |
| 416 | __ ldrsh(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 417 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 418 | } |
| 419 | |
| 420 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 421 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 422 | LocationSummary::kNoCall, |
| 423 | kIntrinsified); |
| 424 | locations->SetInAt(0, Location::RequiresRegister()); |
| 425 | locations->SetInAt(1, Location::RequiresRegister()); |
| 426 | } |
| 427 | |
| 428 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeByte(HInvoke* invoke) { |
| 429 | CreateIntIntToVoidLocations(arena_, invoke); |
| 430 | } |
| 431 | |
| 432 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeByte(HInvoke* invoke) { |
| 433 | ArmAssembler* assembler = GetAssembler(); |
| 434 | __ strb(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 435 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 436 | } |
| 437 | |
| 438 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 439 | CreateIntIntToVoidLocations(arena_, invoke); |
| 440 | } |
| 441 | |
| 442 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 443 | ArmAssembler* assembler = GetAssembler(); |
| 444 | __ str(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 445 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 446 | } |
| 447 | |
| 448 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 449 | CreateIntIntToVoidLocations(arena_, invoke); |
| 450 | } |
| 451 | |
| 452 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 453 | ArmAssembler* assembler = GetAssembler(); |
| 454 | // Ignore upper 4B of long address. |
| 455 | Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>(); |
| 456 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 457 | // exception. So we can't use ldrd as addr may be unaligned. |
| 458 | __ str(invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>(), Address(addr, 0)); |
| 459 | __ str(invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>(), Address(addr, 4)); |
| 460 | } |
| 461 | |
| 462 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 463 | CreateIntIntToVoidLocations(arena_, invoke); |
| 464 | } |
| 465 | |
| 466 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 467 | ArmAssembler* assembler = GetAssembler(); |
| 468 | __ strh(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 469 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 470 | } |
| 471 | |
| 472 | void IntrinsicLocationsBuilderARM::VisitThreadCurrentThread(HInvoke* invoke) { |
| 473 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 474 | LocationSummary::kNoCall, |
| 475 | kIntrinsified); |
| 476 | locations->SetOut(Location::RequiresRegister()); |
| 477 | } |
| 478 | |
| 479 | void IntrinsicCodeGeneratorARM::VisitThreadCurrentThread(HInvoke* invoke) { |
| 480 | ArmAssembler* assembler = GetAssembler(); |
| 481 | __ LoadFromOffset(kLoadWord, |
| 482 | invoke->GetLocations()->Out().AsRegister<Register>(), |
| 483 | TR, |
| 484 | Thread::PeerOffset<kArmPointerSize>().Int32Value()); |
| 485 | } |
| 486 | |
| 487 | static void GenUnsafeGet(HInvoke* invoke, |
| 488 | Primitive::Type type, |
| 489 | bool is_volatile, |
| 490 | CodeGeneratorARM* codegen) { |
| 491 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 492 | ArmAssembler* assembler = codegen->GetAssembler(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 493 | Location base_loc = locations->InAt(1); |
| 494 | Register base = base_loc.AsRegister<Register>(); // Object pointer. |
| 495 | Location offset_loc = locations->InAt(2); |
| 496 | Register offset = offset_loc.AsRegisterPairLow<Register>(); // Long offset, lo part only. |
| 497 | Location trg_loc = locations->Out(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 498 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 499 | switch (type) { |
| 500 | case Primitive::kPrimInt: { |
| 501 | Register trg = trg_loc.AsRegister<Register>(); |
| 502 | __ ldr(trg, Address(base, offset)); |
| 503 | if (is_volatile) { |
| 504 | __ dmb(ISH); |
| 505 | } |
| 506 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 507 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 508 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 509 | case Primitive::kPrimNot: { |
| 510 | Register trg = trg_loc.AsRegister<Register>(); |
| 511 | if (kEmitCompilerReadBarrier) { |
| 512 | if (kUseBakerReadBarrier) { |
| 513 | Location temp = locations->GetTemp(0); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 514 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 515 | invoke, trg_loc, base, 0U, offset_loc, TIMES_1, temp, /* needs_null_check */ false); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 516 | if (is_volatile) { |
| 517 | __ dmb(ISH); |
| 518 | } |
| 519 | } else { |
| 520 | __ ldr(trg, Address(base, offset)); |
| 521 | if (is_volatile) { |
| 522 | __ dmb(ISH); |
| 523 | } |
| 524 | codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc); |
| 525 | } |
| 526 | } else { |
| 527 | __ ldr(trg, Address(base, offset)); |
| 528 | if (is_volatile) { |
| 529 | __ dmb(ISH); |
| 530 | } |
| 531 | __ MaybeUnpoisonHeapReference(trg); |
| 532 | } |
| 533 | break; |
| 534 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 535 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 536 | case Primitive::kPrimLong: { |
| 537 | Register trg_lo = trg_loc.AsRegisterPairLow<Register>(); |
| 538 | __ add(IP, base, ShifterOperand(offset)); |
| 539 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
| 540 | Register trg_hi = trg_loc.AsRegisterPairHigh<Register>(); |
| 541 | __ ldrexd(trg_lo, trg_hi, IP); |
| 542 | } else { |
| 543 | __ ldrd(trg_lo, Address(IP)); |
| 544 | } |
| 545 | if (is_volatile) { |
| 546 | __ dmb(ISH); |
| 547 | } |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | default: |
| 552 | LOG(FATAL) << "Unexpected type " << type; |
| 553 | UNREACHABLE(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 554 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 557 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, |
| 558 | HInvoke* invoke, |
| 559 | Primitive::Type type) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 560 | bool can_call = kEmitCompilerReadBarrier && |
| 561 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 562 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 563 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 564 | can_call ? |
| 565 | LocationSummary::kCallOnSlowPath : |
| 566 | LocationSummary::kNoCall, |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 567 | kIntrinsified); |
| 568 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 569 | locations->SetInAt(1, Location::RequiresRegister()); |
| 570 | locations->SetInAt(2, Location::RequiresRegister()); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 571 | locations->SetOut(Location::RequiresRegister(), |
| 572 | can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 573 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 574 | // We need a temporary register for the read barrier marking slow |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 575 | // path in InstructionCodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 576 | locations->AddTemp(Location::RequiresRegister()); |
| 577 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | void IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 581 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 582 | } |
| 583 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 584 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 585 | } |
| 586 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 587 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 588 | } |
| 589 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 590 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 591 | } |
| 592 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 593 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 594 | } |
| 595 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 596 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | void IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 600 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 601 | } |
| 602 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 603 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 604 | } |
| 605 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 606 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 607 | } |
| 608 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 609 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 610 | } |
| 611 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 612 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 613 | } |
| 614 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 615 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, |
| 619 | const ArmInstructionSetFeatures& features, |
| 620 | Primitive::Type type, |
| 621 | bool is_volatile, |
| 622 | HInvoke* invoke) { |
| 623 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 624 | LocationSummary::kNoCall, |
| 625 | kIntrinsified); |
| 626 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 627 | locations->SetInAt(1, Location::RequiresRegister()); |
| 628 | locations->SetInAt(2, Location::RequiresRegister()); |
| 629 | locations->SetInAt(3, Location::RequiresRegister()); |
| 630 | |
| 631 | if (type == Primitive::kPrimLong) { |
| 632 | // Potentially need temps for ldrexd-strexd loop. |
| 633 | if (is_volatile && !features.HasAtomicLdrdAndStrd()) { |
| 634 | locations->AddTemp(Location::RequiresRegister()); // Temp_lo. |
| 635 | locations->AddTemp(Location::RequiresRegister()); // Temp_hi. |
| 636 | } |
| 637 | } else if (type == Primitive::kPrimNot) { |
| 638 | // Temps for card-marking. |
| 639 | locations->AddTemp(Location::RequiresRegister()); // Temp. |
| 640 | locations->AddTemp(Location::RequiresRegister()); // Card. |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | void IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 645 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 646 | } |
| 647 | void IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 648 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 649 | } |
| 650 | void IntrinsicLocationsBuilderARM::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 651 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 652 | } |
| 653 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 654 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 655 | } |
| 656 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 657 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 658 | } |
| 659 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 660 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 661 | } |
| 662 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 663 | CreateIntIntIntIntToVoid( |
| 664 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 665 | } |
| 666 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 667 | CreateIntIntIntIntToVoid( |
| 668 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 669 | } |
| 670 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 671 | CreateIntIntIntIntToVoid( |
| 672 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | static void GenUnsafePut(LocationSummary* locations, |
| 676 | Primitive::Type type, |
| 677 | bool is_volatile, |
| 678 | bool is_ordered, |
| 679 | CodeGeneratorARM* codegen) { |
| 680 | ArmAssembler* assembler = codegen->GetAssembler(); |
| 681 | |
| 682 | Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer. |
| 683 | Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Long offset, lo part only. |
| 684 | Register value; |
| 685 | |
| 686 | if (is_volatile || is_ordered) { |
| 687 | __ dmb(ISH); |
| 688 | } |
| 689 | |
| 690 | if (type == Primitive::kPrimLong) { |
| 691 | Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>(); |
| 692 | value = value_lo; |
| 693 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
| 694 | Register temp_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 695 | Register temp_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 696 | Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>(); |
| 697 | |
| 698 | __ add(IP, base, ShifterOperand(offset)); |
| 699 | Label loop_head; |
| 700 | __ Bind(&loop_head); |
| 701 | __ ldrexd(temp_lo, temp_hi, IP); |
| 702 | __ strexd(temp_lo, value_lo, value_hi, IP); |
| 703 | __ cmp(temp_lo, ShifterOperand(0)); |
| 704 | __ b(&loop_head, NE); |
| 705 | } else { |
| 706 | __ add(IP, base, ShifterOperand(offset)); |
| 707 | __ strd(value_lo, Address(IP)); |
| 708 | } |
| 709 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 710 | value = locations->InAt(3).AsRegister<Register>(); |
| 711 | Register source = value; |
| 712 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 713 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 714 | __ Mov(temp, value); |
| 715 | __ PoisonHeapReference(temp); |
| 716 | source = temp; |
| 717 | } |
| 718 | __ str(source, Address(base, offset)); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | if (is_volatile) { |
| 722 | __ dmb(ISH); |
| 723 | } |
| 724 | |
| 725 | if (type == Primitive::kPrimNot) { |
| 726 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 727 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 728 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 729 | codegen->MarkGCCard(temp, card, base, value, value_can_be_null); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 730 | } |
| 731 | } |
| 732 | |
| 733 | void IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 734 | GenUnsafePut(invoke->GetLocations(), |
| 735 | Primitive::kPrimInt, |
| 736 | /* is_volatile */ false, |
| 737 | /* is_ordered */ false, |
| 738 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 739 | } |
| 740 | void IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 741 | GenUnsafePut(invoke->GetLocations(), |
| 742 | Primitive::kPrimInt, |
| 743 | /* is_volatile */ false, |
| 744 | /* is_ordered */ true, |
| 745 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 746 | } |
| 747 | void IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 748 | GenUnsafePut(invoke->GetLocations(), |
| 749 | Primitive::kPrimInt, |
| 750 | /* is_volatile */ true, |
| 751 | /* is_ordered */ false, |
| 752 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 753 | } |
| 754 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 755 | GenUnsafePut(invoke->GetLocations(), |
| 756 | Primitive::kPrimNot, |
| 757 | /* is_volatile */ false, |
| 758 | /* is_ordered */ false, |
| 759 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 760 | } |
| 761 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 762 | GenUnsafePut(invoke->GetLocations(), |
| 763 | Primitive::kPrimNot, |
| 764 | /* is_volatile */ false, |
| 765 | /* is_ordered */ true, |
| 766 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 767 | } |
| 768 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 769 | GenUnsafePut(invoke->GetLocations(), |
| 770 | Primitive::kPrimNot, |
| 771 | /* is_volatile */ true, |
| 772 | /* is_ordered */ false, |
| 773 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 774 | } |
| 775 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 776 | GenUnsafePut(invoke->GetLocations(), |
| 777 | Primitive::kPrimLong, |
| 778 | /* is_volatile */ false, |
| 779 | /* is_ordered */ false, |
| 780 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 781 | } |
| 782 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 783 | GenUnsafePut(invoke->GetLocations(), |
| 784 | Primitive::kPrimLong, |
| 785 | /* is_volatile */ false, |
| 786 | /* is_ordered */ true, |
| 787 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 788 | } |
| 789 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 790 | GenUnsafePut(invoke->GetLocations(), |
| 791 | Primitive::kPrimLong, |
| 792 | /* is_volatile */ true, |
| 793 | /* is_ordered */ false, |
| 794 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena, |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 798 | HInvoke* invoke, |
| 799 | Primitive::Type type) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 800 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 801 | LocationSummary::kNoCall, |
| 802 | kIntrinsified); |
| 803 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 804 | locations->SetInAt(1, Location::RequiresRegister()); |
| 805 | locations->SetInAt(2, Location::RequiresRegister()); |
| 806 | locations->SetInAt(3, Location::RequiresRegister()); |
| 807 | locations->SetInAt(4, Location::RequiresRegister()); |
| 808 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 809 | // If heap poisoning is enabled, we don't want the unpoisoning |
| 810 | // operations to potentially clobber the output. |
| 811 | Location::OutputOverlap overlaps = (kPoisonHeapReferences && type == Primitive::kPrimNot) |
| 812 | ? Location::kOutputOverlap |
| 813 | : Location::kNoOutputOverlap; |
| 814 | locations->SetOut(Location::RequiresRegister(), overlaps); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 815 | |
| 816 | locations->AddTemp(Location::RequiresRegister()); // Pointer. |
| 817 | locations->AddTemp(Location::RequiresRegister()); // Temp 1. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM* codegen) { |
| 821 | DCHECK_NE(type, Primitive::kPrimLong); |
| 822 | |
| 823 | ArmAssembler* assembler = codegen->GetAssembler(); |
| 824 | |
| 825 | Register out = locations->Out().AsRegister<Register>(); // Boolean result. |
| 826 | |
| 827 | Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer. |
| 828 | Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Offset (discard high 4B). |
| 829 | Register expected_lo = locations->InAt(3).AsRegister<Register>(); // Expected. |
| 830 | Register value_lo = locations->InAt(4).AsRegister<Register>(); // Value. |
| 831 | |
| 832 | Register tmp_ptr = locations->GetTemp(0).AsRegister<Register>(); // Pointer to actual memory. |
| 833 | Register tmp_lo = locations->GetTemp(1).AsRegister<Register>(); // Value in memory. |
| 834 | |
| 835 | if (type == Primitive::kPrimNot) { |
| 836 | // Mark card for object assuming new value is stored. Worst case we will mark an unchanged |
| 837 | // object and scan the receiver at the next GC for nothing. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 838 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 839 | codegen->MarkGCCard(tmp_ptr, tmp_lo, base, value_lo, value_can_be_null); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | // Prevent reordering with prior memory operations. |
Roland Levillain | 4bedb38 | 2016-01-12 12:01:04 +0000 | [diff] [blame] | 843 | // Emit a DMB ISH instruction instead of an DMB ISHST one, as the |
| 844 | // latter allows a preceding load to be delayed past the STXR |
| 845 | // instruction below. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 846 | __ dmb(ISH); |
| 847 | |
| 848 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 849 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 850 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 851 | codegen->GetAssembler()->PoisonHeapReference(expected_lo); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 852 | if (value_lo == expected_lo) { |
| 853 | // Do not poison `value_lo`, as it is the same register as |
| 854 | // `expected_lo`, which has just been poisoned. |
| 855 | } else { |
| 856 | codegen->GetAssembler()->PoisonHeapReference(value_lo); |
| 857 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 858 | } |
| 859 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 860 | // do { |
| 861 | // tmp = [r_ptr] - expected; |
| 862 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 863 | // result = tmp != 0; |
| 864 | |
| 865 | Label loop_head; |
| 866 | __ Bind(&loop_head); |
| 867 | |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 868 | // TODO: When `type == Primitive::kPrimNot`, add a read barrier for |
| 869 | // the reference stored in the object before attempting the CAS, |
| 870 | // similar to the one in the art::Unsafe_compareAndSwapObject JNI |
| 871 | // implementation. |
| 872 | // |
| 873 | // Note that this code is not (yet) used when read barriers are |
| 874 | // enabled (see IntrinsicLocationsBuilderARM::VisitUnsafeCASObject). |
| 875 | DCHECK(!(type == Primitive::kPrimNot && kEmitCompilerReadBarrier)); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 876 | __ ldrex(tmp_lo, tmp_ptr); |
| 877 | |
| 878 | __ subs(tmp_lo, tmp_lo, ShifterOperand(expected_lo)); |
| 879 | |
| 880 | __ it(EQ, ItState::kItT); |
| 881 | __ strex(tmp_lo, value_lo, tmp_ptr, EQ); |
| 882 | __ cmp(tmp_lo, ShifterOperand(1), EQ); |
| 883 | |
| 884 | __ b(&loop_head, EQ); |
| 885 | |
| 886 | __ dmb(ISH); |
| 887 | |
| 888 | __ rsbs(out, tmp_lo, ShifterOperand(1)); |
| 889 | __ it(CC); |
| 890 | __ mov(out, ShifterOperand(0), CC); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 891 | |
| 892 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 893 | codegen->GetAssembler()->UnpoisonHeapReference(expected_lo); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 894 | if (value_lo == expected_lo) { |
| 895 | // Do not unpoison `value_lo`, as it is the same register as |
| 896 | // `expected_lo`, which has just been unpoisoned. |
| 897 | } else { |
| 898 | codegen->GetAssembler()->UnpoisonHeapReference(value_lo); |
| 899 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 900 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Andreas Gampe | ca71458 | 2015-04-03 19:41:34 -0700 | [diff] [blame] | 903 | void IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) { |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 904 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 905 | } |
Andreas Gampe | ca71458 | 2015-04-03 19:41:34 -0700 | [diff] [blame] | 906 | void IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 907 | // The UnsafeCASObject intrinsic is missing a read barrier, and |
| 908 | // therefore sometimes does not work as expected (b/25883050). |
| 909 | // Turn it off temporarily as a quick fix, until the read barrier is |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 910 | // implemented (see TODO in GenCAS). |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 911 | // |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 912 | // TODO(rpl): Implement read barrier support in GenCAS and re-enable |
| 913 | // this intrinsic. |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 914 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 915 | return; |
| 916 | } |
| 917 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 918 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 919 | } |
| 920 | void IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) { |
| 921 | GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_); |
| 922 | } |
| 923 | void IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 924 | // The UnsafeCASObject intrinsic is missing a read barrier, and |
| 925 | // therefore sometimes does not work as expected (b/25883050). |
| 926 | // Turn it off temporarily as a quick fix, until the read barrier is |
| 927 | // implemented (see TODO in GenCAS). |
| 928 | // |
| 929 | // TODO(rpl): Implement read barrier support in GenCAS and re-enable |
| 930 | // this intrinsic. |
| 931 | DCHECK(!kEmitCompilerReadBarrier); |
| 932 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 933 | GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_); |
| 934 | } |
| 935 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 936 | void IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) { |
| 937 | // The inputs plus one temp. |
| 938 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 939 | invoke->InputAt(1)->CanBeNull() |
| 940 | ? LocationSummary::kCallOnSlowPath |
| 941 | : LocationSummary::kNoCall, |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 942 | kIntrinsified); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 943 | locations->SetInAt(0, Location::RequiresRegister()); |
| 944 | locations->SetInAt(1, Location::RequiresRegister()); |
| 945 | locations->AddTemp(Location::RequiresRegister()); |
| 946 | locations->AddTemp(Location::RequiresRegister()); |
| 947 | locations->AddTemp(Location::RequiresRegister()); |
| 948 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) { |
| 952 | ArmAssembler* assembler = GetAssembler(); |
| 953 | LocationSummary* locations = invoke->GetLocations(); |
| 954 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 955 | Register str = locations->InAt(0).AsRegister<Register>(); |
| 956 | Register arg = locations->InAt(1).AsRegister<Register>(); |
| 957 | Register out = locations->Out().AsRegister<Register>(); |
| 958 | |
| 959 | Register temp0 = locations->GetTemp(0).AsRegister<Register>(); |
| 960 | Register temp1 = locations->GetTemp(1).AsRegister<Register>(); |
| 961 | Register temp2 = locations->GetTemp(2).AsRegister<Register>(); |
| 962 | |
| 963 | Label loop; |
| 964 | Label find_char_diff; |
| 965 | Label end; |
| 966 | |
| 967 | // Get offsets of count and value fields within a string object. |
| 968 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 969 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 970 | |
Nicolas Geoffray | 512e04d | 2015-03-27 17:21:24 +0000 | [diff] [blame] | 971 | // Note that the null check must have been done earlier. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 972 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 973 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 974 | // Take slow path and throw if input can be and is null. |
| 975 | SlowPathCode* slow_path = nullptr; |
| 976 | const bool can_slow_path = invoke->InputAt(1)->CanBeNull(); |
| 977 | if (can_slow_path) { |
| 978 | slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
| 979 | codegen_->AddSlowPath(slow_path); |
| 980 | __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel()); |
| 981 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 982 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 983 | // Reference equality check, return 0 if same reference. |
| 984 | __ subs(out, str, ShifterOperand(arg)); |
| 985 | __ b(&end, EQ); |
| 986 | // Load lengths of this and argument strings. |
| 987 | __ ldr(temp2, Address(str, count_offset)); |
| 988 | __ ldr(temp1, Address(arg, count_offset)); |
| 989 | // out = length diff. |
| 990 | __ subs(out, temp2, ShifterOperand(temp1)); |
| 991 | // temp0 = min(len(str), len(arg)). |
| 992 | __ it(Condition::LT, kItElse); |
| 993 | __ mov(temp0, ShifterOperand(temp2), Condition::LT); |
| 994 | __ mov(temp0, ShifterOperand(temp1), Condition::GE); |
| 995 | // Shorter string is empty? |
| 996 | __ CompareAndBranchIfZero(temp0, &end); |
| 997 | |
| 998 | // Store offset of string value in preparation for comparison loop. |
| 999 | __ mov(temp1, ShifterOperand(value_offset)); |
| 1000 | |
| 1001 | // Assertions that must hold in order to compare multiple characters at a time. |
| 1002 | CHECK_ALIGNED(value_offset, 8); |
| 1003 | static_assert(IsAligned<8>(kObjectAlignment), |
| 1004 | "String data must be 8-byte aligned for unrolled CompareTo loop."); |
| 1005 | |
| 1006 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 1007 | DCHECK_EQ(char_size, 2u); |
| 1008 | |
| 1009 | // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment). |
| 1010 | __ Bind(&loop); |
| 1011 | __ ldr(IP, Address(str, temp1)); |
| 1012 | __ ldr(temp2, Address(arg, temp1)); |
| 1013 | __ cmp(IP, ShifterOperand(temp2)); |
| 1014 | __ b(&find_char_diff, NE); |
| 1015 | __ add(temp1, temp1, ShifterOperand(char_size * 2)); |
| 1016 | __ sub(temp0, temp0, ShifterOperand(2)); |
| 1017 | |
| 1018 | __ ldr(IP, Address(str, temp1)); |
| 1019 | __ ldr(temp2, Address(arg, temp1)); |
| 1020 | __ cmp(IP, ShifterOperand(temp2)); |
| 1021 | __ b(&find_char_diff, NE); |
| 1022 | __ add(temp1, temp1, ShifterOperand(char_size * 2)); |
| 1023 | __ subs(temp0, temp0, ShifterOperand(2)); |
| 1024 | |
| 1025 | __ b(&loop, GT); |
| 1026 | __ b(&end); |
| 1027 | |
| 1028 | // Find the single 16-bit character difference. |
| 1029 | __ Bind(&find_char_diff); |
| 1030 | // Get the bit position of the first character that differs. |
| 1031 | __ eor(temp1, temp2, ShifterOperand(IP)); |
| 1032 | __ rbit(temp1, temp1); |
| 1033 | __ clz(temp1, temp1); |
| 1034 | |
| 1035 | // temp0 = number of 16-bit characters remaining to compare. |
| 1036 | // (it could be < 1 if a difference is found after the first SUB in the comparison loop, and |
| 1037 | // after the end of the shorter string data). |
| 1038 | |
| 1039 | // (temp1 >> 4) = character where difference occurs between the last two words compared, on the |
| 1040 | // interval [0,1] (0 for low half-word different, 1 for high half-word different). |
| 1041 | |
| 1042 | // If temp0 <= (temp1 >> 4), the difference occurs outside the remaining string data, so just |
| 1043 | // return length diff (out). |
| 1044 | __ cmp(temp0, ShifterOperand(temp1, LSR, 4)); |
| 1045 | __ b(&end, LE); |
| 1046 | // Extract the characters and calculate the difference. |
| 1047 | __ bic(temp1, temp1, ShifterOperand(0xf)); |
| 1048 | __ Lsr(temp2, temp2, temp1); |
| 1049 | __ Lsr(IP, IP, temp1); |
| 1050 | __ movt(temp2, 0); |
| 1051 | __ movt(IP, 0); |
| 1052 | __ sub(out, IP, ShifterOperand(temp2)); |
| 1053 | |
| 1054 | __ Bind(&end); |
| 1055 | |
| 1056 | if (can_slow_path) { |
| 1057 | __ Bind(slow_path->GetExitLabel()); |
| 1058 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1061 | void IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) { |
| 1062 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1063 | LocationSummary::kNoCall, |
| 1064 | kIntrinsified); |
| 1065 | InvokeRuntimeCallingConvention calling_convention; |
| 1066 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1067 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1068 | // Temporary registers to store lengths of strings and for calculations. |
| 1069 | // Using instruction cbz requires a low register, so explicitly set a temp to be R0. |
| 1070 | locations->AddTemp(Location::RegisterLocation(R0)); |
| 1071 | locations->AddTemp(Location::RequiresRegister()); |
| 1072 | locations->AddTemp(Location::RequiresRegister()); |
| 1073 | |
| 1074 | locations->SetOut(Location::RequiresRegister()); |
| 1075 | } |
| 1076 | |
| 1077 | void IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) { |
| 1078 | ArmAssembler* assembler = GetAssembler(); |
| 1079 | LocationSummary* locations = invoke->GetLocations(); |
| 1080 | |
| 1081 | Register str = locations->InAt(0).AsRegister<Register>(); |
| 1082 | Register arg = locations->InAt(1).AsRegister<Register>(); |
| 1083 | Register out = locations->Out().AsRegister<Register>(); |
| 1084 | |
| 1085 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1086 | Register temp1 = locations->GetTemp(1).AsRegister<Register>(); |
| 1087 | Register temp2 = locations->GetTemp(2).AsRegister<Register>(); |
| 1088 | |
| 1089 | Label loop; |
| 1090 | Label end; |
| 1091 | Label return_true; |
| 1092 | Label return_false; |
| 1093 | |
| 1094 | // Get offsets of count, value, and class fields within a string object. |
| 1095 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1096 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1097 | const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value(); |
| 1098 | |
| 1099 | // Note that the null check must have been done earlier. |
| 1100 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1101 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1102 | StringEqualsOptimizations optimizations(invoke); |
| 1103 | if (!optimizations.GetArgumentNotNull()) { |
| 1104 | // Check if input is null, return false if it is. |
| 1105 | __ CompareAndBranchIfZero(arg, &return_false); |
| 1106 | } |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1107 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1108 | if (!optimizations.GetArgumentIsString()) { |
| 1109 | // Instanceof check for the argument by comparing class fields. |
| 1110 | // All string objects must have the same type since String cannot be subclassed. |
| 1111 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1112 | // If the argument is a string object, its class field must be equal to receiver's class field. |
| 1113 | __ ldr(temp, Address(str, class_offset)); |
| 1114 | __ ldr(temp1, Address(arg, class_offset)); |
| 1115 | __ cmp(temp, ShifterOperand(temp1)); |
| 1116 | __ b(&return_false, NE); |
| 1117 | } |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1118 | |
| 1119 | // Load lengths of this and argument strings. |
| 1120 | __ ldr(temp, Address(str, count_offset)); |
| 1121 | __ ldr(temp1, Address(arg, count_offset)); |
| 1122 | // Check if lengths are equal, return false if they're not. |
| 1123 | __ cmp(temp, ShifterOperand(temp1)); |
| 1124 | __ b(&return_false, NE); |
| 1125 | // Return true if both strings are empty. |
| 1126 | __ cbz(temp, &return_true); |
| 1127 | |
| 1128 | // Reference equality check, return true if same reference. |
| 1129 | __ cmp(str, ShifterOperand(arg)); |
| 1130 | __ b(&return_true, EQ); |
| 1131 | |
| 1132 | // Assertions that must hold in order to compare strings 2 characters at a time. |
| 1133 | DCHECK_ALIGNED(value_offset, 4); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1134 | static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare."); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1135 | |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1136 | __ LoadImmediate(temp1, value_offset); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1137 | |
| 1138 | // Loop to compare strings 2 characters at a time starting at the front of the string. |
| 1139 | // Ok to do this because strings with an odd length are zero-padded. |
| 1140 | __ Bind(&loop); |
| 1141 | __ ldr(out, Address(str, temp1)); |
| 1142 | __ ldr(temp2, Address(arg, temp1)); |
| 1143 | __ cmp(out, ShifterOperand(temp2)); |
| 1144 | __ b(&return_false, NE); |
| 1145 | __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t))); |
Vladimir Marko | a63f0d4 | 2015-09-01 13:36:35 +0100 | [diff] [blame] | 1146 | __ subs(temp, temp, ShifterOperand(sizeof(uint32_t) / sizeof(uint16_t))); |
| 1147 | __ b(&loop, GT); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1148 | |
| 1149 | // Return true and exit the function. |
| 1150 | // If loop does not result in returning false, we return true. |
| 1151 | __ Bind(&return_true); |
| 1152 | __ LoadImmediate(out, 1); |
| 1153 | __ b(&end); |
| 1154 | |
| 1155 | // Return false and exit the function. |
| 1156 | __ Bind(&return_false); |
| 1157 | __ LoadImmediate(out, 0); |
| 1158 | __ Bind(&end); |
| 1159 | } |
| 1160 | |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1161 | static void GenerateVisitStringIndexOf(HInvoke* invoke, |
| 1162 | ArmAssembler* assembler, |
| 1163 | CodeGeneratorARM* codegen, |
| 1164 | ArenaAllocator* allocator, |
| 1165 | bool start_at_zero) { |
| 1166 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1167 | |
| 1168 | // Note that the null check must have been done earlier. |
| 1169 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1170 | |
| 1171 | // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically, |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1172 | // or directly dispatch for a large constant, or omit slow-path for a small constant or a char. |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1173 | SlowPathCode* slow_path = nullptr; |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1174 | HInstruction* code_point = invoke->InputAt(1); |
| 1175 | if (code_point->IsIntConstant()) { |
Vladimir Marko | da05108 | 2016-05-17 16:10:20 +0100 | [diff] [blame] | 1176 | if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) > |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1177 | std::numeric_limits<uint16_t>::max()) { |
| 1178 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1179 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
| 1180 | slow_path = new (allocator) IntrinsicSlowPathARM(invoke); |
| 1181 | codegen->AddSlowPath(slow_path); |
| 1182 | __ b(slow_path->GetEntryLabel()); |
| 1183 | __ Bind(slow_path->GetExitLabel()); |
| 1184 | return; |
| 1185 | } |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1186 | } else if (code_point->GetType() != Primitive::kPrimChar) { |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1187 | Register char_reg = locations->InAt(1).AsRegister<Register>(); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1188 | // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`. |
| 1189 | __ cmp(char_reg, |
| 1190 | ShifterOperand(static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1191 | slow_path = new (allocator) IntrinsicSlowPathARM(invoke); |
| 1192 | codegen->AddSlowPath(slow_path); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1193 | __ b(slow_path->GetEntryLabel(), HS); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | if (start_at_zero) { |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1197 | Register tmp_reg = locations->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1198 | DCHECK_EQ(tmp_reg, R2); |
| 1199 | // Start-index = 0. |
| 1200 | __ LoadImmediate(tmp_reg, 0); |
| 1201 | } |
| 1202 | |
| 1203 | __ LoadFromOffset(kLoadWord, LR, TR, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1204 | QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pIndexOf).Int32Value()); |
Roland Levillain | 42ad288 | 2016-02-29 18:26:54 +0000 | [diff] [blame] | 1205 | CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1206 | __ blx(LR); |
| 1207 | |
| 1208 | if (slow_path != nullptr) { |
| 1209 | __ Bind(slow_path->GetExitLabel()); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) { |
| 1214 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1215 | LocationSummary::kCallOnMainOnly, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1216 | kIntrinsified); |
| 1217 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1218 | // best to align the inputs accordingly. |
| 1219 | InvokeRuntimeCallingConvention calling_convention; |
| 1220 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1221 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1222 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1223 | |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1224 | // Need to send start-index=0. |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1225 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1226 | } |
| 1227 | |
| 1228 | void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1229 | GenerateVisitStringIndexOf( |
| 1230 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1234 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1235 | LocationSummary::kCallOnMainOnly, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1236 | kIntrinsified); |
| 1237 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1238 | // best to align the inputs accordingly. |
| 1239 | InvokeRuntimeCallingConvention calling_convention; |
| 1240 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1241 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1242 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1243 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1247 | GenerateVisitStringIndexOf( |
| 1248 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1251 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1252 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1253 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1254 | kIntrinsified); |
| 1255 | InvokeRuntimeCallingConvention calling_convention; |
| 1256 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1257 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1258 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1259 | locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1260 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1261 | } |
| 1262 | |
| 1263 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1264 | ArmAssembler* assembler = GetAssembler(); |
| 1265 | LocationSummary* locations = invoke->GetLocations(); |
| 1266 | |
| 1267 | Register byte_array = locations->InAt(0).AsRegister<Register>(); |
| 1268 | __ cmp(byte_array, ShifterOperand(0)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1269 | SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1270 | codegen_->AddSlowPath(slow_path); |
| 1271 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1272 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1273 | __ LoadFromOffset(kLoadWord, |
| 1274 | LR, |
| 1275 | TR, |
| 1276 | QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromBytes).Int32Value()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1277 | CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1278 | __ blx(LR); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1279 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1280 | __ Bind(slow_path->GetExitLabel()); |
| 1281 | } |
| 1282 | |
| 1283 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1284 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1285 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1286 | kIntrinsified); |
| 1287 | InvokeRuntimeCallingConvention calling_convention; |
| 1288 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1289 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1290 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1291 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1292 | } |
| 1293 | |
| 1294 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1295 | ArmAssembler* assembler = GetAssembler(); |
| 1296 | |
Roland Levillain | cc3839c | 2016-02-29 16:23:48 +0000 | [diff] [blame] | 1297 | // No need to emit code checking whether `locations->InAt(2)` is a null |
| 1298 | // pointer, as callers of the native method |
| 1299 | // |
| 1300 | // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data) |
| 1301 | // |
| 1302 | // all include a null check on `data` before calling that method. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1303 | __ LoadFromOffset(kLoadWord, |
| 1304 | LR, |
| 1305 | TR, |
| 1306 | QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromChars).Int32Value()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1307 | CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1308 | __ blx(LR); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1309 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1313 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1314 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1315 | kIntrinsified); |
| 1316 | InvokeRuntimeCallingConvention calling_convention; |
| 1317 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1318 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1319 | } |
| 1320 | |
| 1321 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1322 | ArmAssembler* assembler = GetAssembler(); |
| 1323 | LocationSummary* locations = invoke->GetLocations(); |
| 1324 | |
| 1325 | Register string_to_copy = locations->InAt(0).AsRegister<Register>(); |
| 1326 | __ cmp(string_to_copy, ShifterOperand(0)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1327 | SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1328 | codegen_->AddSlowPath(slow_path); |
| 1329 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1330 | |
| 1331 | __ LoadFromOffset(kLoadWord, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1332 | LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromString).Int32Value()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1333 | CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1334 | __ blx(LR); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1335 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1336 | __ Bind(slow_path->GetExitLabel()); |
| 1337 | } |
| 1338 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1339 | void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1340 | // TODO(rpl): Implement read barriers in the SystemArrayCopy |
| 1341 | // intrinsic and re-enable it (b/29516905). |
| 1342 | if (kEmitCompilerReadBarrier) { |
| 1343 | return; |
| 1344 | } |
| 1345 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1346 | CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke); |
| 1347 | LocationSummary* locations = invoke->GetLocations(); |
| 1348 | if (locations == nullptr) { |
| 1349 | return; |
| 1350 | } |
| 1351 | |
| 1352 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 1353 | HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant(); |
| 1354 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 1355 | |
| 1356 | if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) { |
| 1357 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1358 | } |
| 1359 | if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) { |
| 1360 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1361 | } |
| 1362 | if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) { |
| 1363 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | static void CheckPosition(ArmAssembler* assembler, |
| 1368 | Location pos, |
| 1369 | Register input, |
| 1370 | Location length, |
| 1371 | SlowPathCode* slow_path, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1372 | Register temp, |
| 1373 | bool length_is_input_length = false) { |
| 1374 | // Where is the length in the Array? |
| 1375 | const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1376 | |
| 1377 | if (pos.IsConstant()) { |
| 1378 | int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1379 | if (pos_const == 0) { |
| 1380 | if (!length_is_input_length) { |
| 1381 | // Check that length(input) >= length. |
| 1382 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1383 | if (length.IsConstant()) { |
| 1384 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1385 | } else { |
| 1386 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1387 | } |
| 1388 | __ b(slow_path->GetEntryLabel(), LT); |
| 1389 | } |
| 1390 | } else { |
| 1391 | // Check that length(input) >= pos. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1392 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1393 | __ subs(temp, temp, ShifterOperand(pos_const)); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1394 | __ b(slow_path->GetEntryLabel(), LT); |
| 1395 | |
| 1396 | // Check that (length(input) - pos) >= length. |
| 1397 | if (length.IsConstant()) { |
| 1398 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1399 | } else { |
| 1400 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1401 | } |
| 1402 | __ b(slow_path->GetEntryLabel(), LT); |
| 1403 | } |
| 1404 | } else if (length_is_input_length) { |
| 1405 | // The only way the copy can succeed is if pos is zero. |
| 1406 | Register pos_reg = pos.AsRegister<Register>(); |
| 1407 | __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel()); |
| 1408 | } else { |
| 1409 | // Check that pos >= 0. |
| 1410 | Register pos_reg = pos.AsRegister<Register>(); |
| 1411 | __ cmp(pos_reg, ShifterOperand(0)); |
| 1412 | __ b(slow_path->GetEntryLabel(), LT); |
| 1413 | |
| 1414 | // Check that pos <= length(input). |
| 1415 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1416 | __ subs(temp, temp, ShifterOperand(pos_reg)); |
| 1417 | __ b(slow_path->GetEntryLabel(), LT); |
| 1418 | |
| 1419 | // Check that (length(input) - pos) >= length. |
| 1420 | if (length.IsConstant()) { |
| 1421 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1422 | } else { |
| 1423 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1424 | } |
| 1425 | __ b(slow_path->GetEntryLabel(), LT); |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1430 | // TODO(rpl): Implement read barriers in the SystemArrayCopy |
| 1431 | // intrinsic and re-enable it (b/29516905). |
| 1432 | DCHECK(!kEmitCompilerReadBarrier); |
| 1433 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1434 | ArmAssembler* assembler = GetAssembler(); |
| 1435 | LocationSummary* locations = invoke->GetLocations(); |
| 1436 | |
| 1437 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1438 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 1439 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 1440 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 1441 | |
| 1442 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 1443 | Location src_pos = locations->InAt(1); |
| 1444 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 1445 | Location dest_pos = locations->InAt(3); |
| 1446 | Location length = locations->InAt(4); |
| 1447 | Register temp1 = locations->GetTemp(0).AsRegister<Register>(); |
| 1448 | Register temp2 = locations->GetTemp(1).AsRegister<Register>(); |
| 1449 | Register temp3 = locations->GetTemp(2).AsRegister<Register>(); |
| 1450 | |
| 1451 | SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
| 1452 | codegen_->AddSlowPath(slow_path); |
| 1453 | |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1454 | Label conditions_on_positions_validated; |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1455 | SystemArrayCopyOptimizations optimizations(invoke); |
| 1456 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1457 | // If source and destination are the same, we go to slow path if we need to do |
| 1458 | // forward copying. |
| 1459 | if (src_pos.IsConstant()) { |
| 1460 | int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1461 | if (dest_pos.IsConstant()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1462 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1463 | if (optimizations.GetDestinationIsSource()) { |
| 1464 | // Checked when building locations. |
| 1465 | DCHECK_GE(src_pos_constant, dest_pos_constant); |
| 1466 | } else if (src_pos_constant < dest_pos_constant) { |
| 1467 | __ cmp(src, ShifterOperand(dest)); |
| 1468 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1469 | } |
| 1470 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1471 | // Checked when building locations. |
| 1472 | DCHECK(!optimizations.GetDestinationIsSource() |
| 1473 | || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue())); |
| 1474 | } else { |
| 1475 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1476 | __ cmp(src, ShifterOperand(dest)); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1477 | __ b(&conditions_on_positions_validated, NE); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1478 | } |
| 1479 | __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant)); |
| 1480 | __ b(slow_path->GetEntryLabel(), GT); |
| 1481 | } |
| 1482 | } else { |
| 1483 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1484 | __ cmp(src, ShifterOperand(dest)); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1485 | __ b(&conditions_on_positions_validated, NE); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1486 | } |
| 1487 | if (dest_pos.IsConstant()) { |
| 1488 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1489 | __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant)); |
| 1490 | } else { |
| 1491 | __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>())); |
| 1492 | } |
| 1493 | __ b(slow_path->GetEntryLabel(), LT); |
| 1494 | } |
| 1495 | |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1496 | __ Bind(&conditions_on_positions_validated); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1497 | |
| 1498 | if (!optimizations.GetSourceIsNotNull()) { |
| 1499 | // Bail out if the source is null. |
| 1500 | __ CompareAndBranchIfZero(src, slow_path->GetEntryLabel()); |
| 1501 | } |
| 1502 | |
| 1503 | if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) { |
| 1504 | // Bail out if the destination is null. |
| 1505 | __ CompareAndBranchIfZero(dest, slow_path->GetEntryLabel()); |
| 1506 | } |
| 1507 | |
| 1508 | // If the length is negative, bail out. |
| 1509 | // We have already checked in the LocationsBuilder for the constant case. |
| 1510 | if (!length.IsConstant() && |
| 1511 | !optimizations.GetCountIsSourceLength() && |
| 1512 | !optimizations.GetCountIsDestinationLength()) { |
| 1513 | __ cmp(length.AsRegister<Register>(), ShifterOperand(0)); |
| 1514 | __ b(slow_path->GetEntryLabel(), LT); |
| 1515 | } |
| 1516 | |
| 1517 | // Validity checks: source. |
| 1518 | CheckPosition(assembler, |
| 1519 | src_pos, |
| 1520 | src, |
| 1521 | length, |
| 1522 | slow_path, |
| 1523 | temp1, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1524 | optimizations.GetCountIsSourceLength()); |
| 1525 | |
| 1526 | // Validity checks: dest. |
| 1527 | CheckPosition(assembler, |
| 1528 | dest_pos, |
| 1529 | dest, |
| 1530 | length, |
| 1531 | slow_path, |
| 1532 | temp1, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1533 | optimizations.GetCountIsDestinationLength()); |
| 1534 | |
| 1535 | if (!optimizations.GetDoesNotNeedTypeCheck()) { |
| 1536 | // Check whether all elements of the source array are assignable to the component |
| 1537 | // type of the destination array. We do two checks: the classes are the same, |
| 1538 | // or the destination is Object[]. If none of these checks succeed, we go to the |
| 1539 | // slow path. |
| 1540 | __ LoadFromOffset(kLoadWord, temp1, dest, class_offset); |
| 1541 | __ LoadFromOffset(kLoadWord, temp2, src, class_offset); |
| 1542 | bool did_unpoison = false; |
| 1543 | if (!optimizations.GetDestinationIsNonPrimitiveArray() || |
| 1544 | !optimizations.GetSourceIsNonPrimitiveArray()) { |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1545 | // One or two of the references need to be unpoisoned. Unpoison them |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1546 | // both to make the identity check valid. |
| 1547 | __ MaybeUnpoisonHeapReference(temp1); |
| 1548 | __ MaybeUnpoisonHeapReference(temp2); |
| 1549 | did_unpoison = true; |
| 1550 | } |
| 1551 | |
| 1552 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 1553 | // Bail out if the destination is not a non primitive array. |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1554 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1555 | __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset); |
| 1556 | __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel()); |
| 1557 | __ MaybeUnpoisonHeapReference(temp3); |
| 1558 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1559 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1560 | __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel()); |
| 1561 | } |
| 1562 | |
| 1563 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1564 | // Bail out if the source is not a non primitive array. |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1565 | // /* HeapReference<Class> */ temp3 = temp2->component_type_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1566 | __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset); |
| 1567 | __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel()); |
| 1568 | __ MaybeUnpoisonHeapReference(temp3); |
| 1569 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1570 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1571 | __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel()); |
| 1572 | } |
| 1573 | |
| 1574 | __ cmp(temp1, ShifterOperand(temp2)); |
| 1575 | |
| 1576 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 1577 | Label do_copy; |
| 1578 | __ b(&do_copy, EQ); |
| 1579 | if (!did_unpoison) { |
| 1580 | __ MaybeUnpoisonHeapReference(temp1); |
| 1581 | } |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1582 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1583 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 1584 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1585 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1586 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 1587 | // No need to unpoison the result, we're comparing against null. |
| 1588 | __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel()); |
| 1589 | __ Bind(&do_copy); |
| 1590 | } else { |
| 1591 | __ b(slow_path->GetEntryLabel(), NE); |
| 1592 | } |
| 1593 | } else if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1594 | DCHECK(optimizations.GetDestinationIsNonPrimitiveArray()); |
| 1595 | // Bail out if the source is not a non primitive array. |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1596 | // /* HeapReference<Class> */ temp1 = src->klass_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1597 | __ LoadFromOffset(kLoadWord, temp1, src, class_offset); |
| 1598 | __ MaybeUnpoisonHeapReference(temp1); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1599 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1600 | __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset); |
| 1601 | __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel()); |
| 1602 | __ MaybeUnpoisonHeapReference(temp3); |
| 1603 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1604 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1605 | __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel()); |
| 1606 | } |
| 1607 | |
| 1608 | // Compute base source address, base destination address, and end source address. |
| 1609 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1610 | int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1611 | uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
| 1612 | if (src_pos.IsConstant()) { |
| 1613 | int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1614 | __ AddConstant(temp1, src, element_size * constant + offset); |
| 1615 | } else { |
| 1616 | __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, 2)); |
| 1617 | __ AddConstant(temp1, offset); |
| 1618 | } |
| 1619 | |
| 1620 | if (dest_pos.IsConstant()) { |
| 1621 | int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1622 | __ AddConstant(temp2, dest, element_size * constant + offset); |
| 1623 | } else { |
| 1624 | __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, 2)); |
| 1625 | __ AddConstant(temp2, offset); |
| 1626 | } |
| 1627 | |
| 1628 | if (length.IsConstant()) { |
| 1629 | int32_t constant = length.GetConstant()->AsIntConstant()->GetValue(); |
| 1630 | __ AddConstant(temp3, temp1, element_size * constant); |
| 1631 | } else { |
| 1632 | __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, 2)); |
| 1633 | } |
| 1634 | |
| 1635 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1636 | // poison/unpoison. |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1637 | Label loop, done; |
| 1638 | __ cmp(temp1, ShifterOperand(temp3)); |
| 1639 | __ b(&done, EQ); |
| 1640 | __ Bind(&loop); |
| 1641 | __ ldr(IP, Address(temp1, element_size, Address::PostIndex)); |
| 1642 | __ str(IP, Address(temp2, element_size, Address::PostIndex)); |
| 1643 | __ cmp(temp1, ShifterOperand(temp3)); |
| 1644 | __ b(&loop, NE); |
| 1645 | __ Bind(&done); |
| 1646 | |
| 1647 | // We only need one card marking on the destination array. |
| 1648 | codegen_->MarkGCCard(temp1, |
| 1649 | temp2, |
| 1650 | dest, |
| 1651 | Register(kNoRegister), |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1652 | /* value_can_be_null */ false); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1653 | |
| 1654 | __ Bind(slow_path->GetExitLabel()); |
| 1655 | } |
| 1656 | |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 1657 | static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 1658 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 1659 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 1660 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 1661 | // the input and output locations are unallocated, the register allocator runs out of |
| 1662 | // registers and fails; however, a debuggable graph is not the common case. |
| 1663 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 1664 | return; |
| 1665 | } |
| 1666 | |
| 1667 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 1668 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 1669 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 1670 | |
| 1671 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1672 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 1673 | kIntrinsified); |
| 1674 | const InvokeRuntimeCallingConvention calling_convention; |
| 1675 | |
| 1676 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1677 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1678 | // Native code uses the soft float ABI. |
| 1679 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1680 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1681 | } |
| 1682 | |
| 1683 | static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 1684 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 1685 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 1686 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 1687 | // the input and output locations are unallocated, the register allocator runs out of |
| 1688 | // registers and fails; however, a debuggable graph is not the common case. |
| 1689 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 1690 | return; |
| 1691 | } |
| 1692 | |
| 1693 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 1694 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 1695 | DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble); |
| 1696 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 1697 | |
| 1698 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1699 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 1700 | kIntrinsified); |
| 1701 | const InvokeRuntimeCallingConvention calling_convention; |
| 1702 | |
| 1703 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 1704 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 1705 | locations->SetOut(Location::RequiresFpuRegister()); |
| 1706 | // Native code uses the soft float ABI. |
| 1707 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1708 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1709 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1710 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1711 | } |
| 1712 | |
| 1713 | static void GenFPToFPCall(HInvoke* invoke, |
| 1714 | ArmAssembler* assembler, |
| 1715 | CodeGeneratorARM* codegen, |
| 1716 | QuickEntrypointEnum entry) { |
| 1717 | LocationSummary* const locations = invoke->GetLocations(); |
| 1718 | const InvokeRuntimeCallingConvention calling_convention; |
| 1719 | |
| 1720 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 1721 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 1722 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0))); |
| 1723 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1))); |
| 1724 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1725 | __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value()); |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 1726 | // Native code uses the soft float ABI. |
| 1727 | __ vmovrrd(calling_convention.GetRegisterAt(0), |
| 1728 | calling_convention.GetRegisterAt(1), |
| 1729 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 1730 | __ blx(LR); |
| 1731 | codegen->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1732 | __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 1733 | calling_convention.GetRegisterAt(0), |
| 1734 | calling_convention.GetRegisterAt(1)); |
| 1735 | } |
| 1736 | |
| 1737 | static void GenFPFPToFPCall(HInvoke* invoke, |
| 1738 | ArmAssembler* assembler, |
| 1739 | CodeGeneratorARM* codegen, |
| 1740 | QuickEntrypointEnum entry) { |
| 1741 | LocationSummary* const locations = invoke->GetLocations(); |
| 1742 | const InvokeRuntimeCallingConvention calling_convention; |
| 1743 | |
| 1744 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 1745 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 1746 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0))); |
| 1747 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1))); |
| 1748 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2))); |
| 1749 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3))); |
| 1750 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame^] | 1751 | __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value()); |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 1752 | // Native code uses the soft float ABI. |
| 1753 | __ vmovrrd(calling_convention.GetRegisterAt(0), |
| 1754 | calling_convention.GetRegisterAt(1), |
| 1755 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 1756 | __ vmovrrd(calling_convention.GetRegisterAt(2), |
| 1757 | calling_convention.GetRegisterAt(3), |
| 1758 | FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>())); |
| 1759 | __ blx(LR); |
| 1760 | codegen->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1761 | __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 1762 | calling_convention.GetRegisterAt(0), |
| 1763 | calling_convention.GetRegisterAt(1)); |
| 1764 | } |
| 1765 | |
| 1766 | void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) { |
| 1767 | CreateFPToFPCallLocations(arena_, invoke); |
| 1768 | } |
| 1769 | |
| 1770 | void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) { |
| 1771 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos); |
| 1772 | } |
| 1773 | |
| 1774 | void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) { |
| 1775 | CreateFPToFPCallLocations(arena_, invoke); |
| 1776 | } |
| 1777 | |
| 1778 | void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) { |
| 1779 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin); |
| 1780 | } |
| 1781 | |
| 1782 | void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) { |
| 1783 | CreateFPToFPCallLocations(arena_, invoke); |
| 1784 | } |
| 1785 | |
| 1786 | void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) { |
| 1787 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos); |
| 1788 | } |
| 1789 | |
| 1790 | void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) { |
| 1791 | CreateFPToFPCallLocations(arena_, invoke); |
| 1792 | } |
| 1793 | |
| 1794 | void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) { |
| 1795 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin); |
| 1796 | } |
| 1797 | |
| 1798 | void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) { |
| 1799 | CreateFPToFPCallLocations(arena_, invoke); |
| 1800 | } |
| 1801 | |
| 1802 | void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) { |
| 1803 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan); |
| 1804 | } |
| 1805 | |
| 1806 | void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) { |
| 1807 | CreateFPToFPCallLocations(arena_, invoke); |
| 1808 | } |
| 1809 | |
| 1810 | void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) { |
| 1811 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt); |
| 1812 | } |
| 1813 | |
| 1814 | void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) { |
| 1815 | CreateFPToFPCallLocations(arena_, invoke); |
| 1816 | } |
| 1817 | |
| 1818 | void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) { |
| 1819 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh); |
| 1820 | } |
| 1821 | |
| 1822 | void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) { |
| 1823 | CreateFPToFPCallLocations(arena_, invoke); |
| 1824 | } |
| 1825 | |
| 1826 | void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) { |
| 1827 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp); |
| 1828 | } |
| 1829 | |
| 1830 | void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) { |
| 1831 | CreateFPToFPCallLocations(arena_, invoke); |
| 1832 | } |
| 1833 | |
| 1834 | void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) { |
| 1835 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1); |
| 1836 | } |
| 1837 | |
| 1838 | void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) { |
| 1839 | CreateFPToFPCallLocations(arena_, invoke); |
| 1840 | } |
| 1841 | |
| 1842 | void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) { |
| 1843 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog); |
| 1844 | } |
| 1845 | |
| 1846 | void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) { |
| 1847 | CreateFPToFPCallLocations(arena_, invoke); |
| 1848 | } |
| 1849 | |
| 1850 | void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) { |
| 1851 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10); |
| 1852 | } |
| 1853 | |
| 1854 | void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) { |
| 1855 | CreateFPToFPCallLocations(arena_, invoke); |
| 1856 | } |
| 1857 | |
| 1858 | void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) { |
| 1859 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh); |
| 1860 | } |
| 1861 | |
| 1862 | void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) { |
| 1863 | CreateFPToFPCallLocations(arena_, invoke); |
| 1864 | } |
| 1865 | |
| 1866 | void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) { |
| 1867 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan); |
| 1868 | } |
| 1869 | |
| 1870 | void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) { |
| 1871 | CreateFPToFPCallLocations(arena_, invoke); |
| 1872 | } |
| 1873 | |
| 1874 | void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) { |
| 1875 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh); |
| 1876 | } |
| 1877 | |
| 1878 | void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) { |
| 1879 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1880 | } |
| 1881 | |
| 1882 | void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) { |
| 1883 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2); |
| 1884 | } |
| 1885 | |
| 1886 | void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) { |
| 1887 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1888 | } |
| 1889 | |
| 1890 | void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) { |
| 1891 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot); |
| 1892 | } |
| 1893 | |
| 1894 | void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) { |
| 1895 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1896 | } |
| 1897 | |
| 1898 | void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) { |
| 1899 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter); |
| 1900 | } |
| 1901 | |
Artem Serov | c257da7 | 2016-02-02 13:49:43 +0000 | [diff] [blame] | 1902 | void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) { |
| 1903 | CreateIntToIntLocations(arena_, invoke); |
| 1904 | } |
| 1905 | |
| 1906 | void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) { |
| 1907 | ArmAssembler* assembler = GetAssembler(); |
| 1908 | LocationSummary* locations = invoke->GetLocations(); |
| 1909 | |
| 1910 | Register out = locations->Out().AsRegister<Register>(); |
| 1911 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 1912 | |
| 1913 | __ rbit(out, in); |
| 1914 | } |
| 1915 | |
| 1916 | void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) { |
| 1917 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1918 | LocationSummary::kNoCall, |
| 1919 | kIntrinsified); |
| 1920 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1921 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1922 | } |
| 1923 | |
| 1924 | void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) { |
| 1925 | ArmAssembler* assembler = GetAssembler(); |
| 1926 | LocationSummary* locations = invoke->GetLocations(); |
| 1927 | |
| 1928 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1929 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1930 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 1931 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 1932 | |
| 1933 | __ rbit(out_reg_lo, in_reg_hi); |
| 1934 | __ rbit(out_reg_hi, in_reg_lo); |
| 1935 | } |
| 1936 | |
| 1937 | void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 1938 | CreateIntToIntLocations(arena_, invoke); |
| 1939 | } |
| 1940 | |
| 1941 | void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 1942 | ArmAssembler* assembler = GetAssembler(); |
| 1943 | LocationSummary* locations = invoke->GetLocations(); |
| 1944 | |
| 1945 | Register out = locations->Out().AsRegister<Register>(); |
| 1946 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 1947 | |
| 1948 | __ rev(out, in); |
| 1949 | } |
| 1950 | |
| 1951 | void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) { |
| 1952 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1953 | LocationSummary::kNoCall, |
| 1954 | kIntrinsified); |
| 1955 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1956 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1957 | } |
| 1958 | |
| 1959 | void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) { |
| 1960 | ArmAssembler* assembler = GetAssembler(); |
| 1961 | LocationSummary* locations = invoke->GetLocations(); |
| 1962 | |
| 1963 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 1964 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 1965 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 1966 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 1967 | |
| 1968 | __ rev(out_reg_lo, in_reg_hi); |
| 1969 | __ rev(out_reg_hi, in_reg_lo); |
| 1970 | } |
| 1971 | |
| 1972 | void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) { |
| 1973 | CreateIntToIntLocations(arena_, invoke); |
| 1974 | } |
| 1975 | |
| 1976 | void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) { |
| 1977 | ArmAssembler* assembler = GetAssembler(); |
| 1978 | LocationSummary* locations = invoke->GetLocations(); |
| 1979 | |
| 1980 | Register out = locations->Out().AsRegister<Register>(); |
| 1981 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 1982 | |
| 1983 | __ revsh(out, in); |
| 1984 | } |
| 1985 | |
xueliang.zhong | f1073c8 | 2016-07-05 15:28:19 +0100 | [diff] [blame] | 1986 | static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmAssembler* assembler) { |
| 1987 | DCHECK(Primitive::IsIntOrLongType(type)) << type; |
| 1988 | DCHECK_EQ(instr->GetType(), Primitive::kPrimInt); |
| 1989 | DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type); |
| 1990 | |
| 1991 | bool is_long = type == Primitive::kPrimLong; |
| 1992 | LocationSummary* locations = instr->GetLocations(); |
| 1993 | Location in = locations->InAt(0); |
| 1994 | Register src_0 = is_long ? in.AsRegisterPairLow<Register>() : in.AsRegister<Register>(); |
| 1995 | Register src_1 = is_long ? in.AsRegisterPairHigh<Register>() : src_0; |
| 1996 | SRegister tmp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 1997 | DRegister tmp_d = FromLowSToD(tmp_s); |
| 1998 | Register out_r = locations->Out().AsRegister<Register>(); |
| 1999 | |
| 2000 | // Move data from core register(s) to temp D-reg for bit count calculation, then move back. |
| 2001 | // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg, |
| 2002 | // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency, |
| 2003 | // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'. |
| 2004 | __ vmovdrr(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0| |
| 2005 | __ vcntd(tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c| |
| 2006 | __ vpaddld(tmp_d, tmp_d, 8, /* is_unsigned */ true); // Temp DReg |--c|--c|--c|--c| |
| 2007 | __ vpaddld(tmp_d, tmp_d, 16, /* is_unsigned */ true); // Temp DReg |------c|------c| |
| 2008 | if (is_long) { |
| 2009 | __ vpaddld(tmp_d, tmp_d, 32, /* is_unsigned */ true); // Temp DReg |--------------c| |
| 2010 | } |
| 2011 | __ vmovrs(out_r, tmp_s); |
| 2012 | } |
| 2013 | |
| 2014 | void IntrinsicLocationsBuilderARM::VisitIntegerBitCount(HInvoke* invoke) { |
| 2015 | CreateIntToIntLocations(arena_, invoke); |
| 2016 | invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 2017 | } |
| 2018 | |
| 2019 | void IntrinsicCodeGeneratorARM::VisitIntegerBitCount(HInvoke* invoke) { |
| 2020 | GenBitCount(invoke, Primitive::kPrimInt, GetAssembler()); |
| 2021 | } |
| 2022 | |
| 2023 | void IntrinsicLocationsBuilderARM::VisitLongBitCount(HInvoke* invoke) { |
| 2024 | VisitIntegerBitCount(invoke); |
| 2025 | } |
| 2026 | |
| 2027 | void IntrinsicCodeGeneratorARM::VisitLongBitCount(HInvoke* invoke) { |
| 2028 | GenBitCount(invoke, Primitive::kPrimLong, GetAssembler()); |
| 2029 | } |
| 2030 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2031 | void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2032 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2033 | LocationSummary::kNoCall, |
| 2034 | kIntrinsified); |
| 2035 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2036 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2037 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2038 | locations->SetInAt(3, Location::RequiresRegister()); |
| 2039 | locations->SetInAt(4, Location::RequiresRegister()); |
| 2040 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2041 | // Temporary registers to store lengths of strings and for calculations. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2042 | locations->AddTemp(Location::RequiresRegister()); |
| 2043 | locations->AddTemp(Location::RequiresRegister()); |
| 2044 | locations->AddTemp(Location::RequiresRegister()); |
| 2045 | } |
| 2046 | |
| 2047 | void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2048 | ArmAssembler* assembler = GetAssembler(); |
| 2049 | LocationSummary* locations = invoke->GetLocations(); |
| 2050 | |
| 2051 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
| 2052 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 2053 | DCHECK_EQ(char_size, 2u); |
| 2054 | |
| 2055 | // Location of data in char array buffer. |
| 2056 | const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value(); |
| 2057 | |
| 2058 | // Location of char array data in string. |
| 2059 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 2060 | |
| 2061 | // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
| 2062 | // Since getChars() calls getCharsNoCheck() - we use registers rather than constants. |
| 2063 | Register srcObj = locations->InAt(0).AsRegister<Register>(); |
| 2064 | Register srcBegin = locations->InAt(1).AsRegister<Register>(); |
| 2065 | Register srcEnd = locations->InAt(2).AsRegister<Register>(); |
| 2066 | Register dstObj = locations->InAt(3).AsRegister<Register>(); |
| 2067 | Register dstBegin = locations->InAt(4).AsRegister<Register>(); |
| 2068 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2069 | Register num_chr = locations->GetTemp(0).AsRegister<Register>(); |
| 2070 | Register src_ptr = locations->GetTemp(1).AsRegister<Register>(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2071 | Register dst_ptr = locations->GetTemp(2).AsRegister<Register>(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2072 | |
| 2073 | // src range to copy. |
| 2074 | __ add(src_ptr, srcObj, ShifterOperand(value_offset)); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2075 | __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1)); |
| 2076 | |
| 2077 | // dst to be copied. |
| 2078 | __ add(dst_ptr, dstObj, ShifterOperand(data_offset)); |
| 2079 | __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1)); |
| 2080 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2081 | __ subs(num_chr, srcEnd, ShifterOperand(srcBegin)); |
| 2082 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2083 | // Do the copy. |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2084 | Label loop, remainder, done; |
| 2085 | |
| 2086 | // Early out for valid zero-length retrievals. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2087 | __ b(&done, EQ); |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2088 | |
| 2089 | // Save repairing the value of num_chr on the < 4 character path. |
| 2090 | __ subs(IP, num_chr, ShifterOperand(4)); |
| 2091 | __ b(&remainder, LT); |
| 2092 | |
| 2093 | // Keep the result of the earlier subs, we are going to fetch at least 4 characters. |
| 2094 | __ mov(num_chr, ShifterOperand(IP)); |
| 2095 | |
| 2096 | // Main loop used for longer fetches loads and stores 4x16-bit characters at a time. |
| 2097 | // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code |
| 2098 | // to rectify these everywhere this intrinsic applies.) |
| 2099 | __ Bind(&loop); |
| 2100 | __ ldr(IP, Address(src_ptr, char_size * 2)); |
| 2101 | __ subs(num_chr, num_chr, ShifterOperand(4)); |
| 2102 | __ str(IP, Address(dst_ptr, char_size * 2)); |
| 2103 | __ ldr(IP, Address(src_ptr, char_size * 4, Address::PostIndex)); |
| 2104 | __ str(IP, Address(dst_ptr, char_size * 4, Address::PostIndex)); |
| 2105 | __ b(&loop, GE); |
| 2106 | |
| 2107 | __ adds(num_chr, num_chr, ShifterOperand(4)); |
| 2108 | __ b(&done, EQ); |
| 2109 | |
| 2110 | // Main loop for < 4 character case and remainder handling. Loads and stores one |
| 2111 | // 16-bit Java character at a time. |
| 2112 | __ Bind(&remainder); |
| 2113 | __ ldrh(IP, Address(src_ptr, char_size, Address::PostIndex)); |
| 2114 | __ subs(num_chr, num_chr, ShifterOperand(1)); |
| 2115 | __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex)); |
| 2116 | __ b(&remainder, GT); |
| 2117 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2118 | __ Bind(&done); |
| 2119 | } |
| 2120 | |
Anton Kirilov | a3ffea2 | 2016-04-07 17:02:37 +0100 | [diff] [blame] | 2121 | void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2122 | CreateFPToIntLocations(arena_, invoke); |
| 2123 | } |
| 2124 | |
| 2125 | void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2126 | ArmAssembler* const assembler = GetAssembler(); |
| 2127 | LocationSummary* const locations = invoke->GetLocations(); |
| 2128 | const Register out = locations->Out().AsRegister<Register>(); |
| 2129 | // Shifting left by 1 bit makes the value encodable as an immediate operand; |
| 2130 | // we don't care about the sign bit anyway. |
| 2131 | constexpr uint32_t infinity = kPositiveInfinityFloat << 1U; |
| 2132 | |
| 2133 | __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>()); |
| 2134 | // We don't care about the sign bit, so shift left. |
| 2135 | __ Lsl(out, out, 1); |
| 2136 | __ eor(out, out, ShifterOperand(infinity)); |
| 2137 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2138 | __ clz(out, out); |
| 2139 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2140 | // the same operation on 32 yields 1. |
| 2141 | __ Lsr(out, out, 5); |
| 2142 | } |
| 2143 | |
| 2144 | void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2145 | CreateFPToIntLocations(arena_, invoke); |
| 2146 | } |
| 2147 | |
| 2148 | void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2149 | ArmAssembler* const assembler = GetAssembler(); |
| 2150 | LocationSummary* const locations = invoke->GetLocations(); |
| 2151 | const Register out = locations->Out().AsRegister<Register>(); |
| 2152 | // The highest 32 bits of double precision positive infinity separated into |
| 2153 | // two constants encodable as immediate operands. |
| 2154 | constexpr uint32_t infinity_high = 0x7f000000U; |
| 2155 | constexpr uint32_t infinity_high2 = 0x00f00000U; |
| 2156 | |
| 2157 | static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U), |
| 2158 | "The constants do not add up to the high 32 bits of double precision positive infinity."); |
| 2159 | __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 2160 | __ eor(out, out, ShifterOperand(infinity_high)); |
| 2161 | __ eor(out, out, ShifterOperand(infinity_high2)); |
| 2162 | // We don't care about the sign bit, so shift left. |
| 2163 | __ orr(out, IP, ShifterOperand(out, LSL, 1)); |
| 2164 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2165 | __ clz(out, out); |
| 2166 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2167 | // the same operation on 32 yields 1. |
| 2168 | __ Lsr(out, out, 5); |
| 2169 | } |
| 2170 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2171 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble) |
| 2172 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat) |
| 2173 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble) |
| 2174 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat) |
| 2175 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong) |
| 2176 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong) |
| 2177 | UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe? |
| 2178 | UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe? |
| 2179 | UNIMPLEMENTED_INTRINSIC(ARM, MathRint) |
| 2180 | UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe? |
| 2181 | UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe? |
| 2182 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure. |
| 2183 | UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar) |
| 2184 | UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent) |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2185 | UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit) |
| 2186 | UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit) |
| 2187 | UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit) |
| 2188 | UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit) |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2189 | |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2190 | // 1.8. |
| 2191 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt) |
| 2192 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong) |
| 2193 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt) |
| 2194 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong) |
| 2195 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject) |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2196 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2197 | UNREACHABLE_INTRINSICS(ARM) |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2198 | |
| 2199 | #undef __ |
| 2200 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2201 | } // namespace arm |
| 2202 | } // namespace art |