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 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 44 | // NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy. |
| 45 | #define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT |
| 46 | |
| 47 | // Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers. |
| 48 | class ReadBarrierSystemArrayCopySlowPathARM : public SlowPathCode { |
| 49 | public: |
| 50 | explicit ReadBarrierSystemArrayCopySlowPathARM(HInstruction* instruction) |
| 51 | : SlowPathCode(instruction) { |
| 52 | DCHECK(kEmitCompilerReadBarrier); |
| 53 | DCHECK(kUseBakerReadBarrier); |
| 54 | } |
| 55 | |
| 56 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 57 | CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen); |
| 58 | LocationSummary* locations = instruction_->GetLocations(); |
| 59 | DCHECK(locations->CanCall()); |
| 60 | DCHECK(instruction_->IsInvokeStaticOrDirect()) |
| 61 | << "Unexpected instruction in read barrier arraycopy slow path: " |
| 62 | << instruction_->DebugName(); |
| 63 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 64 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy); |
| 65 | |
| 66 | int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot); |
| 67 | uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
| 68 | uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
| 69 | |
| 70 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 71 | Location dest_pos = locations->InAt(3); |
| 72 | Register src_curr_addr = locations->GetTemp(0).AsRegister<Register>(); |
| 73 | Register dst_curr_addr = locations->GetTemp(1).AsRegister<Register>(); |
| 74 | Register src_stop_addr = locations->GetTemp(2).AsRegister<Register>(); |
| 75 | Register tmp = locations->GetTemp(3).AsRegister<Register>(); |
| 76 | |
| 77 | __ Bind(GetEntryLabel()); |
| 78 | // Compute the base destination address in `dst_curr_addr`. |
| 79 | if (dest_pos.IsConstant()) { |
| 80 | int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 81 | __ AddConstant(dst_curr_addr, dest, element_size * constant + offset); |
| 82 | } else { |
| 83 | __ add(dst_curr_addr, |
| 84 | dest, |
| 85 | ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift)); |
| 86 | __ AddConstant(dst_curr_addr, offset); |
| 87 | } |
| 88 | |
| 89 | Label loop; |
| 90 | __ Bind(&loop); |
| 91 | __ ldr(tmp, Address(src_curr_addr, element_size, Address::PostIndex)); |
| 92 | __ MaybeUnpoisonHeapReference(tmp); |
| 93 | // TODO: Inline the mark bit check before calling the runtime? |
| 94 | // tmp = ReadBarrier::Mark(tmp); |
| 95 | // No need to save live registers; it's taken care of by the |
| 96 | // entrypoint. Also, there is no need to update the stack mask, |
| 97 | // as this runtime call will not trigger a garbage collection. |
| 98 | // (See ReadBarrierMarkSlowPathARM::EmitNativeCode for more |
| 99 | // explanations.) |
| 100 | DCHECK_NE(tmp, SP); |
| 101 | DCHECK_NE(tmp, LR); |
| 102 | DCHECK_NE(tmp, PC); |
| 103 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 104 | // as a temporary (and not preserved). It thus cannot be used by |
| 105 | // any live register in this slow path. |
| 106 | DCHECK_NE(src_curr_addr, IP); |
| 107 | DCHECK_NE(dst_curr_addr, IP); |
| 108 | DCHECK_NE(src_stop_addr, IP); |
| 109 | DCHECK_NE(tmp, IP); |
| 110 | DCHECK(0 <= tmp && tmp < kNumberOfCoreRegisters) << tmp; |
| 111 | int32_t entry_point_offset = |
| 112 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(tmp); |
| 113 | // This runtime call does not require a stack map. |
| 114 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 115 | __ MaybePoisonHeapReference(tmp); |
| 116 | __ str(tmp, Address(dst_curr_addr, element_size, Address::PostIndex)); |
| 117 | __ cmp(src_curr_addr, ShifterOperand(src_stop_addr)); |
| 118 | __ b(&loop, NE); |
| 119 | __ b(GetExitLabel()); |
| 120 | } |
| 121 | |
| 122 | const char* GetDescription() const OVERRIDE { return "ReadBarrierSystemArrayCopySlowPathARM"; } |
| 123 | |
| 124 | private: |
| 125 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathARM); |
| 126 | }; |
| 127 | |
| 128 | #undef __ |
| 129 | |
Vladimir Marko | 68c981f | 2016-08-26 13:13:33 +0100 | [diff] [blame] | 130 | IntrinsicLocationsBuilderARM::IntrinsicLocationsBuilderARM(CodeGeneratorARM* codegen) |
| 131 | : arena_(codegen->GetGraph()->GetArena()), |
| 132 | assembler_(codegen->GetAssembler()), |
| 133 | features_(codegen->GetInstructionSetFeatures()) {} |
| 134 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 135 | bool IntrinsicLocationsBuilderARM::TryDispatch(HInvoke* invoke) { |
| 136 | Dispatch(invoke); |
| 137 | LocationSummary* res = invoke->GetLocations(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 138 | if (res == nullptr) { |
| 139 | return false; |
| 140 | } |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 141 | return res->Intrinsified(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | #define __ assembler-> |
| 145 | |
| 146 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 147 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 148 | LocationSummary::kNoCall, |
| 149 | kIntrinsified); |
| 150 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 151 | locations->SetOut(Location::RequiresRegister()); |
| 152 | } |
| 153 | |
| 154 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 155 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 156 | LocationSummary::kNoCall, |
| 157 | kIntrinsified); |
| 158 | locations->SetInAt(0, Location::RequiresRegister()); |
| 159 | locations->SetOut(Location::RequiresFpuRegister()); |
| 160 | } |
| 161 | |
| 162 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 163 | Location input = locations->InAt(0); |
| 164 | Location output = locations->Out(); |
| 165 | if (is64bit) { |
| 166 | __ vmovrrd(output.AsRegisterPairLow<Register>(), |
| 167 | output.AsRegisterPairHigh<Register>(), |
| 168 | FromLowSToD(input.AsFpuRegisterPairLow<SRegister>())); |
| 169 | } else { |
| 170 | __ vmovrs(output.AsRegister<Register>(), input.AsFpuRegister<SRegister>()); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 175 | Location input = locations->InAt(0); |
| 176 | Location output = locations->Out(); |
| 177 | if (is64bit) { |
| 178 | __ vmovdrr(FromLowSToD(output.AsFpuRegisterPairLow<SRegister>()), |
| 179 | input.AsRegisterPairLow<Register>(), |
| 180 | input.AsRegisterPairHigh<Register>()); |
| 181 | } else { |
| 182 | __ vmovsr(output.AsFpuRegister<SRegister>(), input.AsRegister<Register>()); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | void IntrinsicLocationsBuilderARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 187 | CreateFPToIntLocations(arena_, invoke); |
| 188 | } |
| 189 | void IntrinsicLocationsBuilderARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 190 | CreateIntToFPLocations(arena_, invoke); |
| 191 | } |
| 192 | |
| 193 | void IntrinsicCodeGeneratorARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 194 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 195 | } |
| 196 | void IntrinsicCodeGeneratorARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 197 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | void IntrinsicLocationsBuilderARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 201 | CreateFPToIntLocations(arena_, invoke); |
| 202 | } |
| 203 | void IntrinsicLocationsBuilderARM::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 204 | CreateIntToFPLocations(arena_, invoke); |
| 205 | } |
| 206 | |
| 207 | void IntrinsicCodeGeneratorARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 208 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 209 | } |
| 210 | void IntrinsicCodeGeneratorARM::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 211 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 215 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 216 | LocationSummary::kNoCall, |
| 217 | kIntrinsified); |
| 218 | locations->SetInAt(0, Location::RequiresRegister()); |
| 219 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 220 | } |
| 221 | |
| 222 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 223 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 224 | LocationSummary::kNoCall, |
| 225 | kIntrinsified); |
| 226 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 227 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 228 | } |
| 229 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 230 | static void GenNumberOfLeadingZeros(LocationSummary* locations, |
| 231 | Primitive::Type type, |
| 232 | ArmAssembler* assembler) { |
| 233 | Location in = locations->InAt(0); |
| 234 | Register out = locations->Out().AsRegister<Register>(); |
| 235 | |
| 236 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 237 | |
| 238 | if (type == Primitive::kPrimLong) { |
| 239 | Register in_reg_lo = in.AsRegisterPairLow<Register>(); |
| 240 | Register in_reg_hi = in.AsRegisterPairHigh<Register>(); |
| 241 | Label end; |
| 242 | __ clz(out, in_reg_hi); |
| 243 | __ CompareAndBranchIfNonZero(in_reg_hi, &end); |
| 244 | __ clz(out, in_reg_lo); |
| 245 | __ AddConstant(out, 32); |
| 246 | __ Bind(&end); |
| 247 | } else { |
| 248 | __ clz(out, in.AsRegister<Register>()); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 253 | CreateIntToIntLocations(arena_, invoke); |
| 254 | } |
| 255 | |
| 256 | void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 257 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 258 | } |
| 259 | |
| 260 | void IntrinsicLocationsBuilderARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 261 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 262 | LocationSummary::kNoCall, |
| 263 | kIntrinsified); |
| 264 | locations->SetInAt(0, Location::RequiresRegister()); |
| 265 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 266 | } |
| 267 | |
| 268 | void IntrinsicCodeGeneratorARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 269 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 270 | } |
| 271 | |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 272 | static void GenNumberOfTrailingZeros(LocationSummary* locations, |
| 273 | Primitive::Type type, |
| 274 | ArmAssembler* assembler) { |
| 275 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 276 | |
| 277 | Register out = locations->Out().AsRegister<Register>(); |
| 278 | |
| 279 | if (type == Primitive::kPrimLong) { |
| 280 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 281 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 282 | Label end; |
| 283 | __ rbit(out, in_reg_lo); |
| 284 | __ clz(out, out); |
| 285 | __ CompareAndBranchIfNonZero(in_reg_lo, &end); |
| 286 | __ rbit(out, in_reg_hi); |
| 287 | __ clz(out, out); |
| 288 | __ AddConstant(out, 32); |
| 289 | __ Bind(&end); |
| 290 | } else { |
| 291 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 292 | __ rbit(out, in); |
| 293 | __ clz(out, out); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 298 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 299 | LocationSummary::kNoCall, |
| 300 | kIntrinsified); |
| 301 | locations->SetInAt(0, Location::RequiresRegister()); |
| 302 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 303 | } |
| 304 | |
| 305 | void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 306 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler()); |
| 307 | } |
| 308 | |
| 309 | void IntrinsicLocationsBuilderARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 310 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 311 | LocationSummary::kNoCall, |
| 312 | kIntrinsified); |
| 313 | locations->SetInAt(0, Location::RequiresRegister()); |
| 314 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 315 | } |
| 316 | |
| 317 | void IntrinsicCodeGeneratorARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 318 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler()); |
| 319 | } |
| 320 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 321 | static void MathAbsFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) { |
| 322 | Location in = locations->InAt(0); |
| 323 | Location out = locations->Out(); |
| 324 | |
| 325 | if (is64bit) { |
| 326 | __ vabsd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), |
| 327 | FromLowSToD(in.AsFpuRegisterPairLow<SRegister>())); |
| 328 | } else { |
| 329 | __ vabss(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>()); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | void IntrinsicLocationsBuilderARM::VisitMathAbsDouble(HInvoke* invoke) { |
| 334 | CreateFPToFPLocations(arena_, invoke); |
| 335 | } |
| 336 | |
| 337 | void IntrinsicCodeGeneratorARM::VisitMathAbsDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 338 | MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void IntrinsicLocationsBuilderARM::VisitMathAbsFloat(HInvoke* invoke) { |
| 342 | CreateFPToFPLocations(arena_, invoke); |
| 343 | } |
| 344 | |
| 345 | void IntrinsicCodeGeneratorARM::VisitMathAbsFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 346 | MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) { |
| 350 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 351 | LocationSummary::kNoCall, |
| 352 | kIntrinsified); |
| 353 | locations->SetInAt(0, Location::RequiresRegister()); |
| 354 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 355 | |
| 356 | locations->AddTemp(Location::RequiresRegister()); |
| 357 | } |
| 358 | |
| 359 | static void GenAbsInteger(LocationSummary* locations, |
| 360 | bool is64bit, |
| 361 | ArmAssembler* assembler) { |
| 362 | Location in = locations->InAt(0); |
| 363 | Location output = locations->Out(); |
| 364 | |
| 365 | Register mask = locations->GetTemp(0).AsRegister<Register>(); |
| 366 | |
| 367 | if (is64bit) { |
| 368 | Register in_reg_lo = in.AsRegisterPairLow<Register>(); |
| 369 | Register in_reg_hi = in.AsRegisterPairHigh<Register>(); |
| 370 | Register out_reg_lo = output.AsRegisterPairLow<Register>(); |
| 371 | Register out_reg_hi = output.AsRegisterPairHigh<Register>(); |
| 372 | |
| 373 | DCHECK_NE(out_reg_lo, in_reg_hi) << "Diagonal overlap unexpected."; |
| 374 | |
| 375 | __ Asr(mask, in_reg_hi, 31); |
| 376 | __ adds(out_reg_lo, in_reg_lo, ShifterOperand(mask)); |
| 377 | __ adc(out_reg_hi, in_reg_hi, ShifterOperand(mask)); |
| 378 | __ eor(out_reg_lo, mask, ShifterOperand(out_reg_lo)); |
| 379 | __ eor(out_reg_hi, mask, ShifterOperand(out_reg_hi)); |
| 380 | } else { |
| 381 | Register in_reg = in.AsRegister<Register>(); |
| 382 | Register out_reg = output.AsRegister<Register>(); |
| 383 | |
| 384 | __ Asr(mask, in_reg, 31); |
| 385 | __ add(out_reg, in_reg, ShifterOperand(mask)); |
| 386 | __ eor(out_reg, mask, ShifterOperand(out_reg)); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | void IntrinsicLocationsBuilderARM::VisitMathAbsInt(HInvoke* invoke) { |
| 391 | CreateIntToIntPlusTemp(arena_, invoke); |
| 392 | } |
| 393 | |
| 394 | void IntrinsicCodeGeneratorARM::VisitMathAbsInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 395 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | |
| 399 | void IntrinsicLocationsBuilderARM::VisitMathAbsLong(HInvoke* invoke) { |
| 400 | CreateIntToIntPlusTemp(arena_, invoke); |
| 401 | } |
| 402 | |
| 403 | void IntrinsicCodeGeneratorARM::VisitMathAbsLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 404 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void GenMinMax(LocationSummary* locations, |
| 408 | bool is_min, |
| 409 | ArmAssembler* assembler) { |
| 410 | Register op1 = locations->InAt(0).AsRegister<Register>(); |
| 411 | Register op2 = locations->InAt(1).AsRegister<Register>(); |
| 412 | Register out = locations->Out().AsRegister<Register>(); |
| 413 | |
| 414 | __ cmp(op1, ShifterOperand(op2)); |
| 415 | |
| 416 | __ it((is_min) ? Condition::LT : Condition::GT, kItElse); |
| 417 | __ mov(out, ShifterOperand(op1), is_min ? Condition::LT : Condition::GT); |
| 418 | __ mov(out, ShifterOperand(op2), is_min ? Condition::GE : Condition::LE); |
| 419 | } |
| 420 | |
| 421 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 422 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 423 | LocationSummary::kNoCall, |
| 424 | kIntrinsified); |
| 425 | locations->SetInAt(0, Location::RequiresRegister()); |
| 426 | locations->SetInAt(1, Location::RequiresRegister()); |
| 427 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 428 | } |
| 429 | |
| 430 | void IntrinsicLocationsBuilderARM::VisitMathMinIntInt(HInvoke* invoke) { |
| 431 | CreateIntIntToIntLocations(arena_, invoke); |
| 432 | } |
| 433 | |
| 434 | void IntrinsicCodeGeneratorARM::VisitMathMinIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 435 | GenMinMax(invoke->GetLocations(), /* is_min */ true, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void IntrinsicLocationsBuilderARM::VisitMathMaxIntInt(HInvoke* invoke) { |
| 439 | CreateIntIntToIntLocations(arena_, invoke); |
| 440 | } |
| 441 | |
| 442 | void IntrinsicCodeGeneratorARM::VisitMathMaxIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 443 | GenMinMax(invoke->GetLocations(), /* is_min */ false, GetAssembler()); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void IntrinsicLocationsBuilderARM::VisitMathSqrt(HInvoke* invoke) { |
| 447 | CreateFPToFPLocations(arena_, invoke); |
| 448 | } |
| 449 | |
| 450 | void IntrinsicCodeGeneratorARM::VisitMathSqrt(HInvoke* invoke) { |
| 451 | LocationSummary* locations = invoke->GetLocations(); |
| 452 | ArmAssembler* assembler = GetAssembler(); |
| 453 | __ vsqrtd(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 454 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 455 | } |
| 456 | |
| 457 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekByte(HInvoke* invoke) { |
| 458 | CreateIntToIntLocations(arena_, invoke); |
| 459 | } |
| 460 | |
| 461 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekByte(HInvoke* invoke) { |
| 462 | ArmAssembler* assembler = GetAssembler(); |
| 463 | // Ignore upper 4B of long address. |
| 464 | __ ldrsb(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 465 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 466 | } |
| 467 | |
| 468 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 469 | CreateIntToIntLocations(arena_, invoke); |
| 470 | } |
| 471 | |
| 472 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 473 | ArmAssembler* assembler = GetAssembler(); |
| 474 | // Ignore upper 4B of long address. |
| 475 | __ ldr(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 476 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 477 | } |
| 478 | |
| 479 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 480 | CreateIntToIntLocations(arena_, invoke); |
| 481 | } |
| 482 | |
| 483 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 484 | ArmAssembler* assembler = GetAssembler(); |
| 485 | // Ignore upper 4B of long address. |
| 486 | Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>(); |
| 487 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 488 | // exception. So we can't use ldrd as addr may be unaligned. |
| 489 | Register lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>(); |
| 490 | Register hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>(); |
| 491 | if (addr == lo) { |
| 492 | __ ldr(hi, Address(addr, 4)); |
| 493 | __ ldr(lo, Address(addr, 0)); |
| 494 | } else { |
| 495 | __ ldr(lo, Address(addr, 0)); |
| 496 | __ ldr(hi, Address(addr, 4)); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | void IntrinsicLocationsBuilderARM::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 501 | CreateIntToIntLocations(arena_, invoke); |
| 502 | } |
| 503 | |
| 504 | void IntrinsicCodeGeneratorARM::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 505 | ArmAssembler* assembler = GetAssembler(); |
| 506 | // Ignore upper 4B of long address. |
| 507 | __ ldrsh(invoke->GetLocations()->Out().AsRegister<Register>(), |
| 508 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 509 | } |
| 510 | |
| 511 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 512 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 513 | LocationSummary::kNoCall, |
| 514 | kIntrinsified); |
| 515 | locations->SetInAt(0, Location::RequiresRegister()); |
| 516 | locations->SetInAt(1, Location::RequiresRegister()); |
| 517 | } |
| 518 | |
| 519 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeByte(HInvoke* invoke) { |
| 520 | CreateIntIntToVoidLocations(arena_, invoke); |
| 521 | } |
| 522 | |
| 523 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeByte(HInvoke* invoke) { |
| 524 | ArmAssembler* assembler = GetAssembler(); |
| 525 | __ strb(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 526 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 527 | } |
| 528 | |
| 529 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 530 | CreateIntIntToVoidLocations(arena_, invoke); |
| 531 | } |
| 532 | |
| 533 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 534 | ArmAssembler* assembler = GetAssembler(); |
| 535 | __ str(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 536 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 537 | } |
| 538 | |
| 539 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 540 | CreateIntIntToVoidLocations(arena_, invoke); |
| 541 | } |
| 542 | |
| 543 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 544 | ArmAssembler* assembler = GetAssembler(); |
| 545 | // Ignore upper 4B of long address. |
| 546 | Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>(); |
| 547 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 548 | // exception. So we can't use ldrd as addr may be unaligned. |
| 549 | __ str(invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>(), Address(addr, 0)); |
| 550 | __ str(invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>(), Address(addr, 4)); |
| 551 | } |
| 552 | |
| 553 | void IntrinsicLocationsBuilderARM::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 554 | CreateIntIntToVoidLocations(arena_, invoke); |
| 555 | } |
| 556 | |
| 557 | void IntrinsicCodeGeneratorARM::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 558 | ArmAssembler* assembler = GetAssembler(); |
| 559 | __ strh(invoke->GetLocations()->InAt(1).AsRegister<Register>(), |
| 560 | Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>())); |
| 561 | } |
| 562 | |
| 563 | void IntrinsicLocationsBuilderARM::VisitThreadCurrentThread(HInvoke* invoke) { |
| 564 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 565 | LocationSummary::kNoCall, |
| 566 | kIntrinsified); |
| 567 | locations->SetOut(Location::RequiresRegister()); |
| 568 | } |
| 569 | |
| 570 | void IntrinsicCodeGeneratorARM::VisitThreadCurrentThread(HInvoke* invoke) { |
| 571 | ArmAssembler* assembler = GetAssembler(); |
| 572 | __ LoadFromOffset(kLoadWord, |
| 573 | invoke->GetLocations()->Out().AsRegister<Register>(), |
| 574 | TR, |
| 575 | Thread::PeerOffset<kArmPointerSize>().Int32Value()); |
| 576 | } |
| 577 | |
| 578 | static void GenUnsafeGet(HInvoke* invoke, |
| 579 | Primitive::Type type, |
| 580 | bool is_volatile, |
| 581 | CodeGeneratorARM* codegen) { |
| 582 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 583 | ArmAssembler* assembler = codegen->GetAssembler(); |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 584 | Location base_loc = locations->InAt(1); |
| 585 | Register base = base_loc.AsRegister<Register>(); // Object pointer. |
| 586 | Location offset_loc = locations->InAt(2); |
| 587 | Register offset = offset_loc.AsRegisterPairLow<Register>(); // Long offset, lo part only. |
| 588 | Location trg_loc = locations->Out(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 589 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 590 | switch (type) { |
| 591 | case Primitive::kPrimInt: { |
| 592 | Register trg = trg_loc.AsRegister<Register>(); |
| 593 | __ ldr(trg, Address(base, offset)); |
| 594 | if (is_volatile) { |
| 595 | __ dmb(ISH); |
| 596 | } |
| 597 | break; |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 598 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 599 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 600 | case Primitive::kPrimNot: { |
| 601 | Register trg = trg_loc.AsRegister<Register>(); |
| 602 | if (kEmitCompilerReadBarrier) { |
| 603 | if (kUseBakerReadBarrier) { |
| 604 | Location temp = locations->GetTemp(0); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 605 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 606 | 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] | 607 | if (is_volatile) { |
| 608 | __ dmb(ISH); |
| 609 | } |
| 610 | } else { |
| 611 | __ ldr(trg, Address(base, offset)); |
| 612 | if (is_volatile) { |
| 613 | __ dmb(ISH); |
| 614 | } |
| 615 | codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc); |
| 616 | } |
| 617 | } else { |
| 618 | __ ldr(trg, Address(base, offset)); |
| 619 | if (is_volatile) { |
| 620 | __ dmb(ISH); |
| 621 | } |
| 622 | __ MaybeUnpoisonHeapReference(trg); |
| 623 | } |
| 624 | break; |
| 625 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 626 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 627 | case Primitive::kPrimLong: { |
| 628 | Register trg_lo = trg_loc.AsRegisterPairLow<Register>(); |
| 629 | __ add(IP, base, ShifterOperand(offset)); |
| 630 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
| 631 | Register trg_hi = trg_loc.AsRegisterPairHigh<Register>(); |
| 632 | __ ldrexd(trg_lo, trg_hi, IP); |
| 633 | } else { |
| 634 | __ ldrd(trg_lo, Address(IP)); |
| 635 | } |
| 636 | if (is_volatile) { |
| 637 | __ dmb(ISH); |
| 638 | } |
| 639 | break; |
| 640 | } |
| 641 | |
| 642 | default: |
| 643 | LOG(FATAL) << "Unexpected type " << type; |
| 644 | UNREACHABLE(); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 645 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 646 | } |
| 647 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 648 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, |
| 649 | HInvoke* invoke, |
| 650 | Primitive::Type type) { |
Roland Levillain | 3b359c7 | 2015-11-17 19:35:12 +0000 | [diff] [blame] | 651 | bool can_call = kEmitCompilerReadBarrier && |
| 652 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 653 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 654 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 655 | (can_call |
| 656 | ? LocationSummary::kCallOnSlowPath |
| 657 | : LocationSummary::kNoCall), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 658 | kIntrinsified); |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 659 | if (can_call && kUseBakerReadBarrier) { |
Vladimir Marko | 804b03f | 2016-09-14 16:26:36 +0100 | [diff] [blame] | 660 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
Vladimir Marko | 70e9746 | 2016-08-09 11:04:26 +0100 | [diff] [blame] | 661 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 662 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 663 | locations->SetInAt(1, Location::RequiresRegister()); |
| 664 | locations->SetInAt(2, Location::RequiresRegister()); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 665 | locations->SetOut(Location::RequiresRegister(), |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 666 | (can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 667 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 668 | // We need a temporary register for the read barrier marking slow |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 669 | // path in InstructionCodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier. |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 670 | locations->AddTemp(Location::RequiresRegister()); |
| 671 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 675 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 676 | } |
| 677 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 678 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 679 | } |
| 680 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 681 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 682 | } |
| 683 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 684 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 685 | } |
| 686 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 687 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 688 | } |
| 689 | void IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 690 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | void IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 694 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 695 | } |
| 696 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 697 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 698 | } |
| 699 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 700 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 701 | } |
| 702 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 703 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 704 | } |
| 705 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 706 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 707 | } |
| 708 | void IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 709 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, |
| 713 | const ArmInstructionSetFeatures& features, |
| 714 | Primitive::Type type, |
| 715 | bool is_volatile, |
| 716 | HInvoke* invoke) { |
| 717 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 718 | LocationSummary::kNoCall, |
| 719 | kIntrinsified); |
| 720 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 721 | locations->SetInAt(1, Location::RequiresRegister()); |
| 722 | locations->SetInAt(2, Location::RequiresRegister()); |
| 723 | locations->SetInAt(3, Location::RequiresRegister()); |
| 724 | |
| 725 | if (type == Primitive::kPrimLong) { |
| 726 | // Potentially need temps for ldrexd-strexd loop. |
| 727 | if (is_volatile && !features.HasAtomicLdrdAndStrd()) { |
| 728 | locations->AddTemp(Location::RequiresRegister()); // Temp_lo. |
| 729 | locations->AddTemp(Location::RequiresRegister()); // Temp_hi. |
| 730 | } |
| 731 | } else if (type == Primitive::kPrimNot) { |
| 732 | // Temps for card-marking. |
| 733 | locations->AddTemp(Location::RequiresRegister()); // Temp. |
| 734 | locations->AddTemp(Location::RequiresRegister()); // Card. |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | void IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 739 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 740 | } |
| 741 | void IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 742 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 743 | } |
| 744 | void IntrinsicLocationsBuilderARM::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 745 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 746 | } |
| 747 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 748 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 749 | } |
| 750 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 751 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 752 | } |
| 753 | void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 754 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 755 | } |
| 756 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 757 | CreateIntIntIntIntToVoid( |
| 758 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 759 | } |
| 760 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 761 | CreateIntIntIntIntToVoid( |
| 762 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 763 | } |
| 764 | void IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 765 | CreateIntIntIntIntToVoid( |
| 766 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | static void GenUnsafePut(LocationSummary* locations, |
| 770 | Primitive::Type type, |
| 771 | bool is_volatile, |
| 772 | bool is_ordered, |
| 773 | CodeGeneratorARM* codegen) { |
| 774 | ArmAssembler* assembler = codegen->GetAssembler(); |
| 775 | |
| 776 | Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer. |
| 777 | Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Long offset, lo part only. |
| 778 | Register value; |
| 779 | |
| 780 | if (is_volatile || is_ordered) { |
| 781 | __ dmb(ISH); |
| 782 | } |
| 783 | |
| 784 | if (type == Primitive::kPrimLong) { |
| 785 | Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>(); |
| 786 | value = value_lo; |
| 787 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
| 788 | Register temp_lo = locations->GetTemp(0).AsRegister<Register>(); |
| 789 | Register temp_hi = locations->GetTemp(1).AsRegister<Register>(); |
| 790 | Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>(); |
| 791 | |
| 792 | __ add(IP, base, ShifterOperand(offset)); |
| 793 | Label loop_head; |
| 794 | __ Bind(&loop_head); |
| 795 | __ ldrexd(temp_lo, temp_hi, IP); |
| 796 | __ strexd(temp_lo, value_lo, value_hi, IP); |
| 797 | __ cmp(temp_lo, ShifterOperand(0)); |
| 798 | __ b(&loop_head, NE); |
| 799 | } else { |
| 800 | __ add(IP, base, ShifterOperand(offset)); |
| 801 | __ strd(value_lo, Address(IP)); |
| 802 | } |
| 803 | } else { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 804 | value = locations->InAt(3).AsRegister<Register>(); |
| 805 | Register source = value; |
| 806 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 807 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 808 | __ Mov(temp, value); |
| 809 | __ PoisonHeapReference(temp); |
| 810 | source = temp; |
| 811 | } |
| 812 | __ str(source, Address(base, offset)); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | if (is_volatile) { |
| 816 | __ dmb(ISH); |
| 817 | } |
| 818 | |
| 819 | if (type == Primitive::kPrimNot) { |
| 820 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 821 | Register card = locations->GetTemp(1).AsRegister<Register>(); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 822 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 823 | codegen->MarkGCCard(temp, card, base, value, value_can_be_null); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | |
| 827 | void IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 828 | GenUnsafePut(invoke->GetLocations(), |
| 829 | Primitive::kPrimInt, |
| 830 | /* is_volatile */ false, |
| 831 | /* is_ordered */ false, |
| 832 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 833 | } |
| 834 | void IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 835 | GenUnsafePut(invoke->GetLocations(), |
| 836 | Primitive::kPrimInt, |
| 837 | /* is_volatile */ false, |
| 838 | /* is_ordered */ true, |
| 839 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 840 | } |
| 841 | void IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 842 | GenUnsafePut(invoke->GetLocations(), |
| 843 | Primitive::kPrimInt, |
| 844 | /* is_volatile */ true, |
| 845 | /* is_ordered */ false, |
| 846 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 847 | } |
| 848 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 849 | GenUnsafePut(invoke->GetLocations(), |
| 850 | Primitive::kPrimNot, |
| 851 | /* is_volatile */ false, |
| 852 | /* is_ordered */ false, |
| 853 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 854 | } |
| 855 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 856 | GenUnsafePut(invoke->GetLocations(), |
| 857 | Primitive::kPrimNot, |
| 858 | /* is_volatile */ false, |
| 859 | /* is_ordered */ true, |
| 860 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 861 | } |
| 862 | void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 863 | GenUnsafePut(invoke->GetLocations(), |
| 864 | Primitive::kPrimNot, |
| 865 | /* is_volatile */ true, |
| 866 | /* is_ordered */ false, |
| 867 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 868 | } |
| 869 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 870 | GenUnsafePut(invoke->GetLocations(), |
| 871 | Primitive::kPrimLong, |
| 872 | /* is_volatile */ false, |
| 873 | /* is_ordered */ false, |
| 874 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 875 | } |
| 876 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 877 | GenUnsafePut(invoke->GetLocations(), |
| 878 | Primitive::kPrimLong, |
| 879 | /* is_volatile */ false, |
| 880 | /* is_ordered */ true, |
| 881 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 882 | } |
| 883 | void IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 884 | GenUnsafePut(invoke->GetLocations(), |
| 885 | Primitive::kPrimLong, |
| 886 | /* is_volatile */ true, |
| 887 | /* is_ordered */ false, |
| 888 | codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena, |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 892 | HInvoke* invoke, |
| 893 | Primitive::Type type) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 894 | bool can_call = kEmitCompilerReadBarrier && |
| 895 | kUseBakerReadBarrier && |
| 896 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeCASObject); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 897 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 898 | (can_call |
| 899 | ? LocationSummary::kCallOnSlowPath |
| 900 | : LocationSummary::kNoCall), |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 901 | kIntrinsified); |
| 902 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 903 | locations->SetInAt(1, Location::RequiresRegister()); |
| 904 | locations->SetInAt(2, Location::RequiresRegister()); |
| 905 | locations->SetInAt(3, Location::RequiresRegister()); |
| 906 | locations->SetInAt(4, Location::RequiresRegister()); |
| 907 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 908 | // If heap poisoning is enabled, we don't want the unpoisoning |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 909 | // operations to potentially clobber the output. Likewise when |
| 910 | // emitting a (Baker) read barrier, which may call. |
| 911 | Location::OutputOverlap overlaps = |
| 912 | ((kPoisonHeapReferences && type == Primitive::kPrimNot) || can_call) |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 913 | ? Location::kOutputOverlap |
| 914 | : Location::kNoOutputOverlap; |
| 915 | locations->SetOut(Location::RequiresRegister(), overlaps); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 916 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 917 | // Temporary registers used in CAS. In the object case |
| 918 | // (UnsafeCASObject intrinsic), these are also used for |
| 919 | // card-marking, and possibly for (Baker) read barrier. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 920 | locations->AddTemp(Location::RequiresRegister()); // Pointer. |
| 921 | locations->AddTemp(Location::RequiresRegister()); // Temp 1. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 924 | static void GenCas(HInvoke* invoke, Primitive::Type type, CodeGeneratorARM* codegen) { |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 925 | DCHECK_NE(type, Primitive::kPrimLong); |
| 926 | |
| 927 | ArmAssembler* assembler = codegen->GetAssembler(); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 928 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 929 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 930 | Location out_loc = locations->Out(); |
| 931 | Register out = out_loc.AsRegister<Register>(); // Boolean result. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 932 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 933 | Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer. |
| 934 | Location offset_loc = locations->InAt(2); |
| 935 | Register offset = offset_loc.AsRegisterPairLow<Register>(); // Offset (discard high 4B). |
| 936 | Register expected = locations->InAt(3).AsRegister<Register>(); // Expected. |
| 937 | Register value = locations->InAt(4).AsRegister<Register>(); // Value. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 938 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 939 | Location tmp_ptr_loc = locations->GetTemp(0); |
| 940 | Register tmp_ptr = tmp_ptr_loc.AsRegister<Register>(); // Pointer to actual memory. |
| 941 | Register tmp = locations->GetTemp(1).AsRegister<Register>(); // Value in memory. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 942 | |
| 943 | if (type == Primitive::kPrimNot) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 944 | // The only read barrier implementation supporting the |
| 945 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 946 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
| 947 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 948 | // Mark card for object assuming new value is stored. Worst case we will mark an unchanged |
| 949 | // object and scan the receiver at the next GC for nothing. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 950 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 951 | codegen->MarkGCCard(tmp_ptr, tmp, base, value, value_can_be_null); |
| 952 | |
| 953 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 954 | // Need to make sure the reference stored in the field is a to-space |
| 955 | // one before attempting the CAS or the CAS could fail incorrectly. |
| 956 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 957 | invoke, |
| 958 | out_loc, // Unused, used only as a "temporary" within the read barrier. |
| 959 | base, |
| 960 | /* offset */ 0u, |
| 961 | /* index */ offset_loc, |
| 962 | ScaleFactor::TIMES_1, |
| 963 | tmp_ptr_loc, |
| 964 | /* needs_null_check */ false, |
| 965 | /* always_update_field */ true, |
| 966 | &tmp); |
| 967 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | // Prevent reordering with prior memory operations. |
Roland Levillain | 4bedb38 | 2016-01-12 12:01:04 +0000 | [diff] [blame] | 971 | // Emit a DMB ISH instruction instead of an DMB ISHST one, as the |
| 972 | // latter allows a preceding load to be delayed past the STXR |
| 973 | // instruction below. |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 974 | __ dmb(ISH); |
| 975 | |
| 976 | __ add(tmp_ptr, base, ShifterOperand(offset)); |
| 977 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 978 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 979 | __ PoisonHeapReference(expected); |
| 980 | if (value == expected) { |
| 981 | // Do not poison `value`, as it is the same register as |
| 982 | // `expected`, which has just been poisoned. |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 983 | } else { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 984 | __ PoisonHeapReference(value); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 985 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 986 | } |
| 987 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 988 | // do { |
| 989 | // tmp = [r_ptr] - expected; |
| 990 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 991 | // result = tmp != 0; |
| 992 | |
| 993 | Label loop_head; |
| 994 | __ Bind(&loop_head); |
| 995 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 996 | __ ldrex(tmp, tmp_ptr); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 997 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 998 | __ subs(tmp, tmp, ShifterOperand(expected)); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 999 | |
| 1000 | __ it(EQ, ItState::kItT); |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1001 | __ strex(tmp, value, tmp_ptr, EQ); |
| 1002 | __ cmp(tmp, ShifterOperand(1), EQ); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1003 | |
| 1004 | __ b(&loop_head, EQ); |
| 1005 | |
| 1006 | __ dmb(ISH); |
| 1007 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1008 | __ rsbs(out, tmp, ShifterOperand(1)); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1009 | __ it(CC); |
| 1010 | __ mov(out, ShifterOperand(0), CC); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1011 | |
| 1012 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1013 | __ UnpoisonHeapReference(expected); |
| 1014 | if (value == expected) { |
| 1015 | // Do not unpoison `value`, as it is the same register as |
| 1016 | // `expected`, which has just been unpoisoned. |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1017 | } else { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1018 | __ UnpoisonHeapReference(value); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1019 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1020 | } |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Andreas Gampe | ca71458 | 2015-04-03 19:41:34 -0700 | [diff] [blame] | 1023 | void IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) { |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1024 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1025 | } |
Andreas Gampe | ca71458 | 2015-04-03 19:41:34 -0700 | [diff] [blame] | 1026 | void IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1027 | // The only read barrier implementation supporting the |
| 1028 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 1029 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 1030 | return; |
| 1031 | } |
| 1032 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1033 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1034 | } |
| 1035 | void IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1036 | GenCas(invoke, Primitive::kPrimInt, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1037 | } |
| 1038 | void IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1039 | // The only read barrier implementation supporting the |
| 1040 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 1041 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1042 | |
Roland Levillain | a1aa3b1 | 2016-10-26 13:03:38 +0100 | [diff] [blame] | 1043 | GenCas(invoke, Primitive::kPrimNot, codegen_); |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1046 | void IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) { |
| 1047 | // The inputs plus one temp. |
| 1048 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1049 | invoke->InputAt(1)->CanBeNull() |
| 1050 | ? LocationSummary::kCallOnSlowPath |
| 1051 | : LocationSummary::kNoCall, |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1052 | kIntrinsified); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1053 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1054 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1055 | locations->AddTemp(Location::RequiresRegister()); |
| 1056 | locations->AddTemp(Location::RequiresRegister()); |
| 1057 | locations->AddTemp(Location::RequiresRegister()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1058 | // Need temporary registers for String compression's feature. |
| 1059 | if (mirror::kUseStringCompression) { |
| 1060 | locations->AddTemp(Location::RequiresRegister()); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1061 | } |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1062 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | void IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) { |
| 1066 | ArmAssembler* assembler = GetAssembler(); |
| 1067 | LocationSummary* locations = invoke->GetLocations(); |
| 1068 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1069 | Register str = locations->InAt(0).AsRegister<Register>(); |
| 1070 | Register arg = locations->InAt(1).AsRegister<Register>(); |
| 1071 | Register out = locations->Out().AsRegister<Register>(); |
| 1072 | |
| 1073 | Register temp0 = locations->GetTemp(0).AsRegister<Register>(); |
| 1074 | Register temp1 = locations->GetTemp(1).AsRegister<Register>(); |
| 1075 | Register temp2 = locations->GetTemp(2).AsRegister<Register>(); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1076 | Register temp3; |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1077 | if (mirror::kUseStringCompression) { |
| 1078 | temp3 = locations->GetTemp(3).AsRegister<Register>(); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1079 | } |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1080 | |
| 1081 | Label loop; |
| 1082 | Label find_char_diff; |
| 1083 | Label end; |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1084 | Label different_compression; |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1085 | |
| 1086 | // Get offsets of count and value fields within a string object. |
| 1087 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1088 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1089 | |
Nicolas Geoffray | 512e04d | 2015-03-27 17:21:24 +0000 | [diff] [blame] | 1090 | // Note that the null check must have been done earlier. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1091 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1092 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1093 | // Take slow path and throw if input can be and is null. |
| 1094 | SlowPathCode* slow_path = nullptr; |
| 1095 | const bool can_slow_path = invoke->InputAt(1)->CanBeNull(); |
| 1096 | if (can_slow_path) { |
| 1097 | slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
| 1098 | codegen_->AddSlowPath(slow_path); |
| 1099 | __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel()); |
| 1100 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1101 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1102 | // Reference equality check, return 0 if same reference. |
| 1103 | __ subs(out, str, ShifterOperand(arg)); |
| 1104 | __ b(&end, EQ); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1105 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1106 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1107 | // Load `count` fields of this and argument strings. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1108 | __ ldr(temp3, Address(str, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1109 | __ ldr(temp2, Address(arg, count_offset)); |
| 1110 | // Extract lengths from the `count` fields. |
| 1111 | __ Lsr(temp0, temp3, 1u); |
| 1112 | __ Lsr(temp1, temp2, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1113 | } else { |
| 1114 | // Load lengths of this and argument strings. |
| 1115 | __ ldr(temp0, Address(str, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1116 | __ ldr(temp1, Address(arg, count_offset)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1117 | } |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1118 | // out = length diff. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1119 | __ subs(out, temp0, ShifterOperand(temp1)); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1120 | // temp0 = min(len(str), len(arg)). |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1121 | __ it(GT); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1122 | __ mov(temp0, ShifterOperand(temp1), GT); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1123 | // Shorter string is empty? |
| 1124 | __ CompareAndBranchIfZero(temp0, &end); |
| 1125 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1126 | if (mirror::kUseStringCompression) { |
| 1127 | // Check if both strings using same compression style to use this comparison loop. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1128 | __ eor(temp2, temp2, ShifterOperand(temp3)); |
| 1129 | __ Lsrs(temp2, temp2, 1u); |
| 1130 | __ b(&different_compression, CS); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1131 | // For string compression, calculate the number of bytes to compare (not chars). |
| 1132 | // This could in theory exceed INT32_MAX, so treat temp0 as unsigned. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1133 | __ Lsls(temp3, temp3, 31u); // Extract purely the compression flag. |
| 1134 | __ it(NE); |
| 1135 | __ add(temp0, temp0, ShifterOperand(temp0), NE); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1136 | } |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1137 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1138 | // Store offset of string value in preparation for comparison loop. |
| 1139 | __ mov(temp1, ShifterOperand(value_offset)); |
| 1140 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1141 | // Assertions that must hold in order to compare multiple characters at a time. |
| 1142 | CHECK_ALIGNED(value_offset, 8); |
| 1143 | static_assert(IsAligned<8>(kObjectAlignment), |
| 1144 | "String data must be 8-byte aligned for unrolled CompareTo loop."); |
| 1145 | |
| 1146 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 1147 | DCHECK_EQ(char_size, 2u); |
| 1148 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1149 | Label find_char_diff_2nd_cmp; |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1150 | // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment). |
| 1151 | __ Bind(&loop); |
| 1152 | __ ldr(IP, Address(str, temp1)); |
| 1153 | __ ldr(temp2, Address(arg, temp1)); |
| 1154 | __ cmp(IP, ShifterOperand(temp2)); |
| 1155 | __ b(&find_char_diff, NE); |
| 1156 | __ add(temp1, temp1, ShifterOperand(char_size * 2)); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1157 | |
| 1158 | __ ldr(IP, Address(str, temp1)); |
| 1159 | __ ldr(temp2, Address(arg, temp1)); |
| 1160 | __ cmp(IP, ShifterOperand(temp2)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1161 | __ b(&find_char_diff_2nd_cmp, NE); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1162 | __ add(temp1, temp1, ShifterOperand(char_size * 2)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1163 | // With string compression, we have compared 8 bytes, otherwise 4 chars. |
| 1164 | __ subs(temp0, temp0, ShifterOperand(mirror::kUseStringCompression ? 8 : 4)); |
| 1165 | __ b(&loop, HI); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1166 | __ b(&end); |
| 1167 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1168 | __ Bind(&find_char_diff_2nd_cmp); |
| 1169 | if (mirror::kUseStringCompression) { |
| 1170 | __ subs(temp0, temp0, ShifterOperand(4)); // 4 bytes previously compared. |
| 1171 | __ b(&end, LS); // Was the second comparison fully beyond the end? |
| 1172 | } else { |
| 1173 | // Without string compression, we can start treating temp0 as signed |
| 1174 | // and rely on the signed comparison below. |
| 1175 | __ sub(temp0, temp0, ShifterOperand(2)); |
| 1176 | } |
| 1177 | |
| 1178 | // Find the single character difference. |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1179 | __ Bind(&find_char_diff); |
| 1180 | // Get the bit position of the first character that differs. |
| 1181 | __ eor(temp1, temp2, ShifterOperand(IP)); |
| 1182 | __ rbit(temp1, temp1); |
| 1183 | __ clz(temp1, temp1); |
| 1184 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1185 | // temp0 = number of characters remaining to compare. |
| 1186 | // (Without string compression, it could be < 1 if a difference is found by the second CMP |
| 1187 | // in the comparison loop, and after the end of the shorter string data). |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1188 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1189 | // Without string compression (temp1 >> 4) = character where difference occurs between the last |
| 1190 | // two words compared, in the interval [0,1]. |
| 1191 | // (0 for low half-word different, 1 for high half-word different). |
| 1192 | // With string compression, (temp1 << 3) = byte where the difference occurs, |
| 1193 | // in the interval [0,3]. |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1194 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1195 | // If temp0 <= (temp1 >> (kUseStringCompression ? 3 : 4)), the difference occurs outside |
| 1196 | // the remaining string data, so just return length diff (out). |
| 1197 | // The comparison is unsigned for string compression, otherwise signed. |
| 1198 | __ cmp(temp0, ShifterOperand(temp1, LSR, mirror::kUseStringCompression ? 3 : 4)); |
| 1199 | __ b(&end, mirror::kUseStringCompression ? LS : LE); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1200 | |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1201 | // Extract the characters and calculate the difference. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1202 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1203 | // For compressed strings we need to clear 0x7 from temp1, for uncompressed we need to clear |
| 1204 | // 0xf. We also need to prepare the character extraction mask `uncompressed ? 0xffffu : 0xffu`. |
| 1205 | // The compression flag is now in the highest bit of temp3, so let's play some tricks. |
| 1206 | __ orr(temp3, temp3, ShifterOperand(0xffu << 23)); // uncompressed ? 0xff800000u : 0x7ff80000u |
| 1207 | __ bic(temp1, temp1, ShifterOperand(temp3, LSR, 31 - 3)); // &= ~(uncompressed ? 0xfu : 0x7u) |
| 1208 | __ Asr(temp3, temp3, 7u); // uncompressed ? 0xffff0000u : 0xff0000u. |
| 1209 | __ Lsr(temp2, temp2, temp1); // Extract second character. |
| 1210 | __ Lsr(temp3, temp3, 16u); // uncompressed ? 0xffffu : 0xffu |
| 1211 | __ Lsr(out, IP, temp1); // Extract first character. |
| 1212 | __ and_(temp2, temp2, ShifterOperand(temp3)); |
| 1213 | __ and_(out, out, ShifterOperand(temp3)); |
| 1214 | } else { |
| 1215 | __ bic(temp1, temp1, ShifterOperand(0xf)); |
| 1216 | __ Lsr(temp2, temp2, temp1); |
| 1217 | __ Lsr(out, IP, temp1); |
| 1218 | __ movt(temp2, 0); |
| 1219 | __ movt(out, 0); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1220 | } |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1221 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1222 | __ sub(out, out, ShifterOperand(temp2)); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1223 | |
| 1224 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1225 | __ b(&end); |
| 1226 | __ Bind(&different_compression); |
| 1227 | |
| 1228 | // Comparison for different compression style. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1229 | const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte); |
| 1230 | DCHECK_EQ(c_char_size, 1u); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1231 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1232 | // We want to free up the temp3, currently holding `str.count`, for comparison. |
| 1233 | // So, we move it to the bottom bit of the iteration count `temp0` which we tnen |
| 1234 | // need to treat as unsigned. Start by freeing the bit with an ADD and continue |
| 1235 | // further down by a LSRS+SBC which will flip the meaning of the flag but allow |
| 1236 | // `subs temp0, #2; bhi different_compression_loop` to serve as the loop condition. |
| 1237 | __ add(temp0, temp0, ShifterOperand(temp0)); // Unlike LSL, this ADD is always 16-bit. |
| 1238 | // `temp1` will hold the compressed data pointer, `temp2` the uncompressed data pointer. |
| 1239 | __ mov(temp1, ShifterOperand(str)); |
| 1240 | __ mov(temp2, ShifterOperand(arg)); |
| 1241 | __ Lsrs(temp3, temp3, 1u); // Continue the move of the compression flag. |
| 1242 | __ it(CS, kItThen); // Interleave with selection of temp1 and temp2. |
| 1243 | __ mov(temp1, ShifterOperand(arg), CS); // Preserves flags. |
| 1244 | __ mov(temp2, ShifterOperand(str), CS); // Preserves flags. |
| 1245 | __ sbc(temp0, temp0, ShifterOperand(0)); // Complete the move of the compression flag. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1246 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1247 | // Adjust temp1 and temp2 from string pointers to data pointers. |
| 1248 | __ add(temp1, temp1, ShifterOperand(value_offset)); |
| 1249 | __ add(temp2, temp2, ShifterOperand(value_offset)); |
| 1250 | |
| 1251 | Label different_compression_loop; |
| 1252 | Label different_compression_diff; |
| 1253 | |
| 1254 | // Main loop for different compression. |
| 1255 | __ Bind(&different_compression_loop); |
| 1256 | __ ldrb(IP, Address(temp1, c_char_size, Address::PostIndex)); |
| 1257 | __ ldrh(temp3, Address(temp2, char_size, Address::PostIndex)); |
| 1258 | __ cmp(IP, ShifterOperand(temp3)); |
| 1259 | __ b(&different_compression_diff, NE); |
| 1260 | __ subs(temp0, temp0, ShifterOperand(2)); |
| 1261 | __ b(&different_compression_loop, HI); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1262 | __ b(&end); |
| 1263 | |
| 1264 | // Calculate the difference. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1265 | __ Bind(&different_compression_diff); |
| 1266 | __ sub(out, IP, ShifterOperand(temp3)); |
| 1267 | // Flip the difference if the `arg` is compressed. |
| 1268 | // `temp0` contains inverted `str` compression flag, i.e the same as `arg` compression flag. |
| 1269 | __ Lsrs(temp0, temp0, 1u); |
| 1270 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1271 | "Expecting 0=compressed, 1=uncompressed"); |
| 1272 | __ it(CC); |
| 1273 | __ rsb(out, out, ShifterOperand(0), CC); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1274 | } |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1275 | |
| 1276 | __ Bind(&end); |
| 1277 | |
| 1278 | if (can_slow_path) { |
| 1279 | __ Bind(slow_path->GetExitLabel()); |
| 1280 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1283 | void IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) { |
| 1284 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1285 | LocationSummary::kNoCall, |
| 1286 | kIntrinsified); |
| 1287 | InvokeRuntimeCallingConvention calling_convention; |
| 1288 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1289 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1290 | // Temporary registers to store lengths of strings and for calculations. |
| 1291 | // Using instruction cbz requires a low register, so explicitly set a temp to be R0. |
| 1292 | locations->AddTemp(Location::RegisterLocation(R0)); |
| 1293 | locations->AddTemp(Location::RequiresRegister()); |
| 1294 | locations->AddTemp(Location::RequiresRegister()); |
| 1295 | |
| 1296 | locations->SetOut(Location::RequiresRegister()); |
| 1297 | } |
| 1298 | |
| 1299 | void IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) { |
| 1300 | ArmAssembler* assembler = GetAssembler(); |
| 1301 | LocationSummary* locations = invoke->GetLocations(); |
| 1302 | |
| 1303 | Register str = locations->InAt(0).AsRegister<Register>(); |
| 1304 | Register arg = locations->InAt(1).AsRegister<Register>(); |
| 1305 | Register out = locations->Out().AsRegister<Register>(); |
| 1306 | |
| 1307 | Register temp = locations->GetTemp(0).AsRegister<Register>(); |
| 1308 | Register temp1 = locations->GetTemp(1).AsRegister<Register>(); |
| 1309 | Register temp2 = locations->GetTemp(2).AsRegister<Register>(); |
| 1310 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1311 | Label loop; |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1312 | Label end; |
| 1313 | Label return_true; |
| 1314 | Label return_false; |
| 1315 | |
| 1316 | // Get offsets of count, value, and class fields within a string object. |
| 1317 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1318 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1319 | const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value(); |
| 1320 | |
| 1321 | // Note that the null check must have been done earlier. |
| 1322 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1323 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1324 | StringEqualsOptimizations optimizations(invoke); |
| 1325 | if (!optimizations.GetArgumentNotNull()) { |
| 1326 | // Check if input is null, return false if it is. |
| 1327 | __ CompareAndBranchIfZero(arg, &return_false); |
| 1328 | } |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1329 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1330 | // Reference equality check, return true if same reference. |
| 1331 | __ cmp(str, ShifterOperand(arg)); |
| 1332 | __ b(&return_true, EQ); |
| 1333 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1334 | if (!optimizations.GetArgumentIsString()) { |
| 1335 | // Instanceof check for the argument by comparing class fields. |
| 1336 | // All string objects must have the same type since String cannot be subclassed. |
| 1337 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1338 | // If the argument is a string object, its class field must be equal to receiver's class field. |
| 1339 | __ ldr(temp, Address(str, class_offset)); |
| 1340 | __ ldr(temp1, Address(arg, class_offset)); |
| 1341 | __ cmp(temp, ShifterOperand(temp1)); |
| 1342 | __ b(&return_false, NE); |
| 1343 | } |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1344 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1345 | // Load `count` fields of this and argument strings. |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1346 | __ ldr(temp, Address(str, count_offset)); |
| 1347 | __ ldr(temp1, Address(arg, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1348 | // Check if `count` fields are equal, return false if they're not. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1349 | // Also compares the compression style, if differs return false. |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1350 | __ cmp(temp, ShifterOperand(temp1)); |
| 1351 | __ b(&return_false, NE); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1352 | // Return true if both strings are empty. Even with string compression `count == 0` means empty. |
| 1353 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1354 | "Expecting 0=compressed, 1=uncompressed"); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1355 | __ cbz(temp, &return_true); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1356 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1357 | // Assertions that must hold in order to compare strings 4 bytes at a time. |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1358 | DCHECK_ALIGNED(value_offset, 4); |
Scott Wakeling | c25cbf1 | 2016-04-18 09:00:11 +0100 | [diff] [blame] | 1359 | 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] | 1360 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1361 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1362 | // For string compression, calculate the number of bytes to compare (not chars). |
| 1363 | // This could in theory exceed INT32_MAX, so treat temp as unsigned. |
| 1364 | __ Lsrs(temp, temp, 1u); // Extract length and check compression flag. |
| 1365 | __ it(CS); // If uncompressed, |
| 1366 | __ add(temp, temp, ShifterOperand(temp), CS); // double the byte count. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1367 | } |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1368 | |
| 1369 | // Store offset of string value in preparation for comparison loop. |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 1370 | __ LoadImmediate(temp1, value_offset); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1371 | |
| 1372 | // Loop to compare strings 4 bytes at a time starting at the front of the string. |
| 1373 | // Ok to do this because strings are zero-padded to kObjectAlignment. |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1374 | __ Bind(&loop); |
| 1375 | __ ldr(out, Address(str, temp1)); |
| 1376 | __ ldr(temp2, Address(arg, temp1)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1377 | __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t))); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1378 | __ cmp(out, ShifterOperand(temp2)); |
| 1379 | __ b(&return_false, NE); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1380 | // With string compression, we have compared 4 bytes, otherwise 2 chars. |
| 1381 | __ subs(temp, temp, ShifterOperand(mirror::kUseStringCompression ? 4 : 2)); |
| 1382 | __ b(&loop, HI); |
Agi Csaki | 289cd55 | 2015-08-18 17:10:38 -0700 | [diff] [blame] | 1383 | |
| 1384 | // Return true and exit the function. |
| 1385 | // If loop does not result in returning false, we return true. |
| 1386 | __ Bind(&return_true); |
| 1387 | __ LoadImmediate(out, 1); |
| 1388 | __ b(&end); |
| 1389 | |
| 1390 | // Return false and exit the function. |
| 1391 | __ Bind(&return_false); |
| 1392 | __ LoadImmediate(out, 0); |
| 1393 | __ Bind(&end); |
| 1394 | } |
| 1395 | |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1396 | static void GenerateVisitStringIndexOf(HInvoke* invoke, |
| 1397 | ArmAssembler* assembler, |
| 1398 | CodeGeneratorARM* codegen, |
| 1399 | ArenaAllocator* allocator, |
| 1400 | bool start_at_zero) { |
| 1401 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1402 | |
| 1403 | // Note that the null check must have been done earlier. |
| 1404 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1405 | |
| 1406 | // 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] | 1407 | // 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] | 1408 | SlowPathCode* slow_path = nullptr; |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1409 | HInstruction* code_point = invoke->InputAt(1); |
| 1410 | if (code_point->IsIntConstant()) { |
Vladimir Marko | da05108 | 2016-05-17 16:10:20 +0100 | [diff] [blame] | 1411 | if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) > |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1412 | std::numeric_limits<uint16_t>::max()) { |
| 1413 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1414 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
| 1415 | slow_path = new (allocator) IntrinsicSlowPathARM(invoke); |
| 1416 | codegen->AddSlowPath(slow_path); |
| 1417 | __ b(slow_path->GetEntryLabel()); |
| 1418 | __ Bind(slow_path->GetExitLabel()); |
| 1419 | return; |
| 1420 | } |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1421 | } else if (code_point->GetType() != Primitive::kPrimChar) { |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1422 | Register char_reg = locations->InAt(1).AsRegister<Register>(); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1423 | // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`. |
| 1424 | __ cmp(char_reg, |
| 1425 | ShifterOperand(static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1426 | slow_path = new (allocator) IntrinsicSlowPathARM(invoke); |
| 1427 | codegen->AddSlowPath(slow_path); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1428 | __ b(slow_path->GetEntryLabel(), HS); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | if (start_at_zero) { |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1432 | Register tmp_reg = locations->GetTemp(0).AsRegister<Register>(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1433 | DCHECK_EQ(tmp_reg, R2); |
| 1434 | // Start-index = 0. |
| 1435 | __ LoadImmediate(tmp_reg, 0); |
| 1436 | } |
| 1437 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1438 | codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path); |
Roland Levillain | 42ad288 | 2016-02-29 18:26:54 +0000 | [diff] [blame] | 1439 | CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1440 | |
| 1441 | if (slow_path != nullptr) { |
| 1442 | __ Bind(slow_path->GetExitLabel()); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) { |
| 1447 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 1448 | LocationSummary::kCallOnMainAndSlowPath, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1449 | kIntrinsified); |
| 1450 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1451 | // best to align the inputs accordingly. |
| 1452 | InvokeRuntimeCallingConvention calling_convention; |
| 1453 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1454 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1455 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1456 | |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1457 | // Need to send start-index=0. |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1458 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1459 | } |
| 1460 | |
| 1461 | void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1462 | GenerateVisitStringIndexOf( |
| 1463 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1467 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 1468 | LocationSummary::kCallOnMainAndSlowPath, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1469 | kIntrinsified); |
| 1470 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1471 | // best to align the inputs accordingly. |
| 1472 | InvokeRuntimeCallingConvention calling_convention; |
| 1473 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1474 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1475 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1476 | locations->SetOut(Location::RegisterLocation(R0)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1480 | GenerateVisitStringIndexOf( |
| 1481 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1484 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1485 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 1486 | LocationSummary::kCallOnMainAndSlowPath, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1487 | kIntrinsified); |
| 1488 | InvokeRuntimeCallingConvention calling_convention; |
| 1489 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1490 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1491 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1492 | locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 1493 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1494 | } |
| 1495 | |
| 1496 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1497 | ArmAssembler* assembler = GetAssembler(); |
| 1498 | LocationSummary* locations = invoke->GetLocations(); |
| 1499 | |
| 1500 | Register byte_array = locations->InAt(0).AsRegister<Register>(); |
| 1501 | __ cmp(byte_array, ShifterOperand(0)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1502 | SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1503 | codegen_->AddSlowPath(slow_path); |
| 1504 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1505 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1506 | codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1507 | CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1508 | __ Bind(slow_path->GetExitLabel()); |
| 1509 | } |
| 1510 | |
| 1511 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1512 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1513 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1514 | kIntrinsified); |
| 1515 | InvokeRuntimeCallingConvention calling_convention; |
| 1516 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1517 | locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 1518 | locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 1519 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1520 | } |
| 1521 | |
| 1522 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) { |
Roland Levillain | cc3839c | 2016-02-29 16:23:48 +0000 | [diff] [blame] | 1523 | // No need to emit code checking whether `locations->InAt(2)` is a null |
| 1524 | // pointer, as callers of the native method |
| 1525 | // |
| 1526 | // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data) |
| 1527 | // |
| 1528 | // all include a null check on `data` before calling that method. |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1529 | codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc()); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1530 | CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1534 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 806f012 | 2016-03-09 11:10:16 +0000 | [diff] [blame] | 1535 | LocationSummary::kCallOnMainAndSlowPath, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1536 | kIntrinsified); |
| 1537 | InvokeRuntimeCallingConvention calling_convention; |
| 1538 | locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 1539 | locations->SetOut(Location::RegisterLocation(R0)); |
| 1540 | } |
| 1541 | |
| 1542 | void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1543 | ArmAssembler* assembler = GetAssembler(); |
| 1544 | LocationSummary* locations = invoke->GetLocations(); |
| 1545 | |
| 1546 | Register string_to_copy = locations->InAt(0).AsRegister<Register>(); |
| 1547 | __ cmp(string_to_copy, ShifterOperand(0)); |
Andreas Gampe | 85b62f2 | 2015-09-09 13:15:38 -0700 | [diff] [blame] | 1548 | SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1549 | codegen_->AddSlowPath(slow_path); |
| 1550 | __ b(slow_path->GetEntryLabel(), EQ); |
| 1551 | |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1552 | codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc(), slow_path); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1553 | CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>(); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 1554 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1555 | __ Bind(slow_path->GetExitLabel()); |
| 1556 | } |
| 1557 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1558 | void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1559 | // The only read barrier implementation supporting the |
| 1560 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 1561 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1562 | return; |
| 1563 | } |
| 1564 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1565 | CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke); |
| 1566 | LocationSummary* locations = invoke->GetLocations(); |
| 1567 | if (locations == nullptr) { |
| 1568 | return; |
| 1569 | } |
| 1570 | |
| 1571 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 1572 | HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant(); |
| 1573 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 1574 | |
| 1575 | if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) { |
| 1576 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1577 | } |
| 1578 | if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) { |
| 1579 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1580 | } |
| 1581 | if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) { |
| 1582 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1583 | } |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1584 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1585 | // Temporary register IP cannot be used in |
Roland Levillain | 16d9f94 | 2016-08-25 17:27:56 +0100 | [diff] [blame] | 1586 | // ReadBarrierSystemArrayCopySlowPathARM (because that register |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1587 | // is clobbered by ReadBarrierMarkRegX entry points). Get an extra |
| 1588 | // temporary register from the register allocator. |
| 1589 | locations->AddTemp(Location::RequiresRegister()); |
| 1590 | } |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | static void CheckPosition(ArmAssembler* assembler, |
| 1594 | Location pos, |
| 1595 | Register input, |
| 1596 | Location length, |
| 1597 | SlowPathCode* slow_path, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1598 | Register temp, |
| 1599 | bool length_is_input_length = false) { |
| 1600 | // Where is the length in the Array? |
| 1601 | const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 1602 | |
| 1603 | if (pos.IsConstant()) { |
| 1604 | int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1605 | if (pos_const == 0) { |
| 1606 | if (!length_is_input_length) { |
| 1607 | // Check that length(input) >= length. |
| 1608 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1609 | if (length.IsConstant()) { |
| 1610 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1611 | } else { |
| 1612 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1613 | } |
| 1614 | __ b(slow_path->GetEntryLabel(), LT); |
| 1615 | } |
| 1616 | } else { |
| 1617 | // Check that length(input) >= pos. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1618 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1619 | __ subs(temp, temp, ShifterOperand(pos_const)); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1620 | __ b(slow_path->GetEntryLabel(), LT); |
| 1621 | |
| 1622 | // Check that (length(input) - pos) >= length. |
| 1623 | if (length.IsConstant()) { |
| 1624 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1625 | } else { |
| 1626 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1627 | } |
| 1628 | __ b(slow_path->GetEntryLabel(), LT); |
| 1629 | } |
| 1630 | } else if (length_is_input_length) { |
| 1631 | // The only way the copy can succeed is if pos is zero. |
| 1632 | Register pos_reg = pos.AsRegister<Register>(); |
| 1633 | __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel()); |
| 1634 | } else { |
| 1635 | // Check that pos >= 0. |
| 1636 | Register pos_reg = pos.AsRegister<Register>(); |
| 1637 | __ cmp(pos_reg, ShifterOperand(0)); |
| 1638 | __ b(slow_path->GetEntryLabel(), LT); |
| 1639 | |
| 1640 | // Check that pos <= length(input). |
| 1641 | __ LoadFromOffset(kLoadWord, temp, input, length_offset); |
| 1642 | __ subs(temp, temp, ShifterOperand(pos_reg)); |
| 1643 | __ b(slow_path->GetEntryLabel(), LT); |
| 1644 | |
| 1645 | // Check that (length(input) - pos) >= length. |
| 1646 | if (length.IsConstant()) { |
| 1647 | __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue())); |
| 1648 | } else { |
| 1649 | __ cmp(temp, ShifterOperand(length.AsRegister<Register>())); |
| 1650 | } |
| 1651 | __ b(slow_path->GetEntryLabel(), LT); |
| 1652 | } |
| 1653 | } |
| 1654 | |
| 1655 | void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1656 | // The only read barrier implementation supporting the |
| 1657 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 1658 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1659 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1660 | ArmAssembler* assembler = GetAssembler(); |
| 1661 | LocationSummary* locations = invoke->GetLocations(); |
| 1662 | |
| 1663 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1664 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 1665 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 1666 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1667 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1668 | |
| 1669 | Register src = locations->InAt(0).AsRegister<Register>(); |
| 1670 | Location src_pos = locations->InAt(1); |
| 1671 | Register dest = locations->InAt(2).AsRegister<Register>(); |
| 1672 | Location dest_pos = locations->InAt(3); |
| 1673 | Location length = locations->InAt(4); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1674 | Location temp1_loc = locations->GetTemp(0); |
| 1675 | Register temp1 = temp1_loc.AsRegister<Register>(); |
| 1676 | Location temp2_loc = locations->GetTemp(1); |
| 1677 | Register temp2 = temp2_loc.AsRegister<Register>(); |
| 1678 | Location temp3_loc = locations->GetTemp(2); |
| 1679 | Register temp3 = temp3_loc.AsRegister<Register>(); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1680 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1681 | SlowPathCode* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke); |
| 1682 | codegen_->AddSlowPath(intrinsic_slow_path); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1683 | |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1684 | Label conditions_on_positions_validated; |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1685 | SystemArrayCopyOptimizations optimizations(invoke); |
| 1686 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1687 | // If source and destination are the same, we go to slow path if we need to do |
| 1688 | // forward copying. |
| 1689 | if (src_pos.IsConstant()) { |
| 1690 | int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1691 | if (dest_pos.IsConstant()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1692 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1693 | if (optimizations.GetDestinationIsSource()) { |
| 1694 | // Checked when building locations. |
| 1695 | DCHECK_GE(src_pos_constant, dest_pos_constant); |
| 1696 | } else if (src_pos_constant < dest_pos_constant) { |
| 1697 | __ cmp(src, ShifterOperand(dest)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1698 | __ b(intrinsic_slow_path->GetEntryLabel(), EQ); |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1699 | } |
| 1700 | |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1701 | // Checked when building locations. |
| 1702 | DCHECK(!optimizations.GetDestinationIsSource() |
| 1703 | || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue())); |
| 1704 | } else { |
| 1705 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1706 | __ cmp(src, ShifterOperand(dest)); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1707 | __ b(&conditions_on_positions_validated, NE); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1708 | } |
| 1709 | __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1710 | __ b(intrinsic_slow_path->GetEntryLabel(), GT); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1711 | } |
| 1712 | } else { |
| 1713 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 1714 | __ cmp(src, ShifterOperand(dest)); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1715 | __ b(&conditions_on_positions_validated, NE); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1716 | } |
| 1717 | if (dest_pos.IsConstant()) { |
| 1718 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1719 | __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant)); |
| 1720 | } else { |
| 1721 | __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>())); |
| 1722 | } |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1723 | __ b(intrinsic_slow_path->GetEntryLabel(), LT); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1726 | __ Bind(&conditions_on_positions_validated); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1727 | |
| 1728 | if (!optimizations.GetSourceIsNotNull()) { |
| 1729 | // Bail out if the source is null. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1730 | __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) { |
| 1734 | // Bail out if the destination is null. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1735 | __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | // If the length is negative, bail out. |
| 1739 | // We have already checked in the LocationsBuilder for the constant case. |
| 1740 | if (!length.IsConstant() && |
| 1741 | !optimizations.GetCountIsSourceLength() && |
| 1742 | !optimizations.GetCountIsDestinationLength()) { |
| 1743 | __ cmp(length.AsRegister<Register>(), ShifterOperand(0)); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1744 | __ b(intrinsic_slow_path->GetEntryLabel(), LT); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | // Validity checks: source. |
| 1748 | CheckPosition(assembler, |
| 1749 | src_pos, |
| 1750 | src, |
| 1751 | length, |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1752 | intrinsic_slow_path, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1753 | temp1, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1754 | optimizations.GetCountIsSourceLength()); |
| 1755 | |
| 1756 | // Validity checks: dest. |
| 1757 | CheckPosition(assembler, |
| 1758 | dest_pos, |
| 1759 | dest, |
| 1760 | length, |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1761 | intrinsic_slow_path, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1762 | temp1, |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1763 | optimizations.GetCountIsDestinationLength()); |
| 1764 | |
| 1765 | if (!optimizations.GetDoesNotNeedTypeCheck()) { |
| 1766 | // Check whether all elements of the source array are assignable to the component |
| 1767 | // type of the destination array. We do two checks: the classes are the same, |
| 1768 | // or the destination is Object[]. If none of these checks succeed, we go to the |
| 1769 | // slow path. |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1770 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1771 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1772 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1773 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 1774 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1775 | invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false); |
| 1776 | // Bail out if the source is not a non primitive array. |
| 1777 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 1778 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1779 | invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
| 1780 | __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
| 1781 | // If heap poisoning is enabled, `temp1` has been unpoisoned |
| 1782 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 1783 | // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_); |
| 1784 | __ LoadFromOffset(kLoadUnsignedHalfword, temp1, temp1, primitive_offset); |
| 1785 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1786 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1787 | } |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1788 | |
| 1789 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 1790 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1791 | invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false); |
| 1792 | |
| 1793 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 1794 | // Bail out if the destination is not a non primitive array. |
| 1795 | // |
| 1796 | // Register `temp1` is not trashed by the read barrier emitted |
| 1797 | // by GenerateFieldLoadWithBakerReadBarrier below, as that |
| 1798 | // method produces a call to a ReadBarrierMarkRegX entry point, |
| 1799 | // which saves all potentially live registers, including |
| 1800 | // temporaries such a `temp1`. |
| 1801 | // /* HeapReference<Class> */ temp2 = temp1->component_type_ |
| 1802 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1803 | invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false); |
| 1804 | __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel()); |
| 1805 | // If heap poisoning is enabled, `temp2` has been unpoisoned |
| 1806 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 1807 | // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_); |
| 1808 | __ LoadFromOffset(kLoadUnsignedHalfword, temp2, temp2, primitive_offset); |
| 1809 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1810 | __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel()); |
| 1811 | } |
| 1812 | |
| 1813 | // For the same reason given earlier, `temp1` is not trashed by the |
| 1814 | // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below. |
| 1815 | // /* HeapReference<Class> */ temp2 = src->klass_ |
| 1816 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1817 | invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false); |
| 1818 | // Note: if heap poisoning is on, we are comparing two unpoisoned references here. |
| 1819 | __ cmp(temp1, ShifterOperand(temp2)); |
| 1820 | |
| 1821 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 1822 | Label do_copy; |
| 1823 | __ b(&do_copy, EQ); |
| 1824 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 1825 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1826 | invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
| 1827 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 1828 | // We do not need to emit a read barrier for the following |
| 1829 | // heap reference load, as `temp1` is only used in a |
| 1830 | // comparison with null below, and this reference is not |
| 1831 | // kept afterwards. |
| 1832 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 1833 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
| 1834 | __ Bind(&do_copy); |
| 1835 | } else { |
| 1836 | __ b(intrinsic_slow_path->GetEntryLabel(), NE); |
| 1837 | } |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1838 | } else { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1839 | // Non read barrier code. |
| 1840 | |
| 1841 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 1842 | __ LoadFromOffset(kLoadWord, temp1, dest, class_offset); |
| 1843 | // /* HeapReference<Class> */ temp2 = src->klass_ |
| 1844 | __ LoadFromOffset(kLoadWord, temp2, src, class_offset); |
| 1845 | bool did_unpoison = false; |
| 1846 | if (!optimizations.GetDestinationIsNonPrimitiveArray() || |
| 1847 | !optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1848 | // One or two of the references need to be unpoisoned. Unpoison them |
| 1849 | // both to make the identity check valid. |
| 1850 | __ MaybeUnpoisonHeapReference(temp1); |
| 1851 | __ MaybeUnpoisonHeapReference(temp2); |
| 1852 | did_unpoison = true; |
| 1853 | } |
| 1854 | |
| 1855 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 1856 | // Bail out if the destination is not a non primitive array. |
| 1857 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 1858 | __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset); |
| 1859 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1860 | __ MaybeUnpoisonHeapReference(temp3); |
| 1861 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
| 1862 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1863 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1864 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1865 | } |
| 1866 | |
| 1867 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1868 | // Bail out if the source is not a non primitive array. |
| 1869 | // /* HeapReference<Class> */ temp3 = temp2->component_type_ |
| 1870 | __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset); |
| 1871 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1872 | __ MaybeUnpoisonHeapReference(temp3); |
| 1873 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
| 1874 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1875 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 1876 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1877 | } |
| 1878 | |
| 1879 | __ cmp(temp1, ShifterOperand(temp2)); |
| 1880 | |
| 1881 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 1882 | Label do_copy; |
| 1883 | __ b(&do_copy, EQ); |
| 1884 | if (!did_unpoison) { |
| 1885 | __ MaybeUnpoisonHeapReference(temp1); |
| 1886 | } |
| 1887 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 1888 | __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset); |
| 1889 | __ MaybeUnpoisonHeapReference(temp1); |
| 1890 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 1891 | __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset); |
| 1892 | // No need to unpoison the result, we're comparing against null. |
| 1893 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
| 1894 | __ Bind(&do_copy); |
| 1895 | } else { |
| 1896 | __ b(intrinsic_slow_path->GetEntryLabel(), NE); |
| 1897 | } |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1898 | } |
| 1899 | } else if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 1900 | DCHECK(optimizations.GetDestinationIsNonPrimitiveArray()); |
| 1901 | // Bail out if the source is not a non primitive array. |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1902 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1903 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 1904 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1905 | invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false); |
| 1906 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 1907 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 1908 | invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
| 1909 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1910 | // If heap poisoning is enabled, `temp3` has been unpoisoned |
| 1911 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 1912 | } else { |
| 1913 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 1914 | __ LoadFromOffset(kLoadWord, temp1, src, class_offset); |
| 1915 | __ MaybeUnpoisonHeapReference(temp1); |
| 1916 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 1917 | __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset); |
| 1918 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
| 1919 | __ MaybeUnpoisonHeapReference(temp3); |
| 1920 | } |
| 1921 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1922 | __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset); |
| 1923 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1924 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1927 | int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1928 | uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1929 | uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1930 | |
| 1931 | // Compute the base source address in `temp1`. |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1932 | if (src_pos.IsConstant()) { |
| 1933 | int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1934 | __ AddConstant(temp1, src, element_size * constant + offset); |
| 1935 | } else { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1936 | __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, element_size_shift)); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1937 | __ AddConstant(temp1, offset); |
| 1938 | } |
| 1939 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1940 | // Compute the end source address in `temp3`. |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1941 | if (length.IsConstant()) { |
| 1942 | int32_t constant = length.GetConstant()->AsIntConstant()->GetValue(); |
| 1943 | __ AddConstant(temp3, temp1, element_size * constant); |
| 1944 | } else { |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1945 | __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, element_size_shift)); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1948 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1949 | // The base destination address is computed later, as `temp2` is |
| 1950 | // used for intermediate computations. |
| 1951 | |
| 1952 | // SystemArrayCopy implementation for Baker read barriers (see |
| 1953 | // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier): |
| 1954 | // |
| 1955 | // if (src_ptr != end_ptr) { |
| 1956 | // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState(); |
| 1957 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 1958 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 1959 | // if (is_gray) { |
| 1960 | // // Slow-path copy. |
| 1961 | // do { |
| 1962 | // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++))); |
| 1963 | // } while (src_ptr != end_ptr) |
| 1964 | // } else { |
| 1965 | // // Fast-path copy. |
| 1966 | // do { |
| 1967 | // *dest_ptr++ = *src_ptr++; |
| 1968 | // } while (src_ptr != end_ptr) |
| 1969 | // } |
| 1970 | // } |
| 1971 | |
| 1972 | Label loop, done; |
| 1973 | |
| 1974 | // Don't enter copy loop if `length == 0`. |
| 1975 | __ cmp(temp1, ShifterOperand(temp3)); |
| 1976 | __ b(&done, EQ); |
| 1977 | |
| 1978 | // /* int32_t */ monitor = src->monitor_ |
| 1979 | __ LoadFromOffset(kLoadWord, temp2, src, monitor_offset); |
| 1980 | // /* LockWord */ lock_word = LockWord(monitor) |
| 1981 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 1982 | "art::LockWord and int32_t have different sizes."); |
| 1983 | |
| 1984 | // Introduce a dependency on the lock_word including the rb_state, |
| 1985 | // which shall prevent load-load reordering without using |
| 1986 | // a memory barrier (which would be more expensive). |
| 1987 | // `src` is unchanged by this operation, but its value now depends |
| 1988 | // on `temp2`. |
| 1989 | __ add(src, src, ShifterOperand(temp2, LSR, 32)); |
| 1990 | |
| 1991 | // Slow path used to copy array when `src` is gray. |
| 1992 | SlowPathCode* read_barrier_slow_path = |
| 1993 | new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARM(invoke); |
| 1994 | codegen_->AddSlowPath(read_barrier_slow_path); |
| 1995 | |
| 1996 | // Given the numeric representation, it's enough to check the low bit of the |
| 1997 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 1998 | // which can be a 16-bit instruction unlike the TST immediate. |
Hiroshi Yamauchi | 12b58b2 | 2016-11-01 11:55:29 -0700 | [diff] [blame] | 1999 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 2000 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2001 | __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1); |
| 2002 | // Carry flag is the last bit shifted out by LSRS. |
| 2003 | __ b(read_barrier_slow_path->GetEntryLabel(), CS); |
| 2004 | |
| 2005 | // Fast-path copy. |
| 2006 | |
| 2007 | // Compute the base destination address in `temp2`. |
| 2008 | if (dest_pos.IsConstant()) { |
| 2009 | int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2010 | __ AddConstant(temp2, dest, element_size * constant + offset); |
| 2011 | } else { |
| 2012 | __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift)); |
| 2013 | __ AddConstant(temp2, offset); |
| 2014 | } |
| 2015 | |
| 2016 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2017 | // poison/unpoison. |
| 2018 | __ Bind(&loop); |
| 2019 | __ ldr(IP, Address(temp1, element_size, Address::PostIndex)); |
| 2020 | __ str(IP, Address(temp2, element_size, Address::PostIndex)); |
| 2021 | __ cmp(temp1, ShifterOperand(temp3)); |
| 2022 | __ b(&loop, NE); |
| 2023 | |
| 2024 | __ Bind(read_barrier_slow_path->GetExitLabel()); |
| 2025 | __ Bind(&done); |
| 2026 | } else { |
| 2027 | // Non read barrier code. |
| 2028 | |
| 2029 | // Compute the base destination address in `temp2`. |
| 2030 | if (dest_pos.IsConstant()) { |
| 2031 | int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2032 | __ AddConstant(temp2, dest, element_size * constant + offset); |
| 2033 | } else { |
| 2034 | __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift)); |
| 2035 | __ AddConstant(temp2, offset); |
| 2036 | } |
| 2037 | |
| 2038 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2039 | // poison/unpoison. |
| 2040 | Label loop, done; |
| 2041 | __ cmp(temp1, ShifterOperand(temp3)); |
| 2042 | __ b(&done, EQ); |
| 2043 | __ Bind(&loop); |
| 2044 | __ ldr(IP, Address(temp1, element_size, Address::PostIndex)); |
| 2045 | __ str(IP, Address(temp2, element_size, Address::PostIndex)); |
| 2046 | __ cmp(temp1, ShifterOperand(temp3)); |
| 2047 | __ b(&loop, NE); |
| 2048 | __ Bind(&done); |
| 2049 | } |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 2050 | |
| 2051 | // We only need one card marking on the destination array. |
| 2052 | codegen_->MarkGCCard(temp1, |
| 2053 | temp2, |
| 2054 | dest, |
| 2055 | Register(kNoRegister), |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 2056 | /* value_can_be_null */ false); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 2057 | |
Roland Levillain | 0b671c0 | 2016-08-19 12:02:34 +0100 | [diff] [blame] | 2058 | __ Bind(intrinsic_slow_path->GetExitLabel()); |
Nicolas Geoffray | 5bd05a5 | 2015-10-13 09:48:30 +0100 | [diff] [blame] | 2059 | } |
| 2060 | |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2061 | static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 2062 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 2063 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 2064 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 2065 | // the input and output locations are unallocated, the register allocator runs out of |
| 2066 | // registers and fails; however, a debuggable graph is not the common case. |
| 2067 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 2068 | return; |
| 2069 | } |
| 2070 | |
| 2071 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 2072 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 2073 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 2074 | |
| 2075 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2076 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2077 | kIntrinsified); |
| 2078 | const InvokeRuntimeCallingConvention calling_convention; |
| 2079 | |
| 2080 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2081 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2082 | // Native code uses the soft float ABI. |
| 2083 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2084 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2085 | } |
| 2086 | |
| 2087 | static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 2088 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 2089 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 2090 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 2091 | // the input and output locations are unallocated, the register allocator runs out of |
| 2092 | // registers and fails; however, a debuggable graph is not the common case. |
| 2093 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 2094 | return; |
| 2095 | } |
| 2096 | |
| 2097 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 2098 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 2099 | DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble); |
| 2100 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 2101 | |
| 2102 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 2103 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2104 | kIntrinsified); |
| 2105 | const InvokeRuntimeCallingConvention calling_convention; |
| 2106 | |
| 2107 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2108 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2109 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2110 | // Native code uses the soft float ABI. |
| 2111 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0))); |
| 2112 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1))); |
| 2113 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2))); |
| 2114 | locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3))); |
| 2115 | } |
| 2116 | |
| 2117 | static void GenFPToFPCall(HInvoke* invoke, |
| 2118 | ArmAssembler* assembler, |
| 2119 | CodeGeneratorARM* codegen, |
| 2120 | QuickEntrypointEnum entry) { |
| 2121 | LocationSummary* const locations = invoke->GetLocations(); |
| 2122 | const InvokeRuntimeCallingConvention calling_convention; |
| 2123 | |
| 2124 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 2125 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 2126 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0))); |
| 2127 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1))); |
| 2128 | |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2129 | // Native code uses the soft float ABI. |
| 2130 | __ vmovrrd(calling_convention.GetRegisterAt(0), |
| 2131 | calling_convention.GetRegisterAt(1), |
| 2132 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2133 | codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc()); |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2134 | __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 2135 | calling_convention.GetRegisterAt(0), |
| 2136 | calling_convention.GetRegisterAt(1)); |
| 2137 | } |
| 2138 | |
| 2139 | static void GenFPFPToFPCall(HInvoke* invoke, |
| 2140 | ArmAssembler* assembler, |
| 2141 | CodeGeneratorARM* codegen, |
| 2142 | QuickEntrypointEnum entry) { |
| 2143 | LocationSummary* const locations = invoke->GetLocations(); |
| 2144 | const InvokeRuntimeCallingConvention calling_convention; |
| 2145 | |
| 2146 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 2147 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 2148 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0))); |
| 2149 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1))); |
| 2150 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2))); |
| 2151 | DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3))); |
| 2152 | |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2153 | // Native code uses the soft float ABI. |
| 2154 | __ vmovrrd(calling_convention.GetRegisterAt(0), |
| 2155 | calling_convention.GetRegisterAt(1), |
| 2156 | FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 2157 | __ vmovrrd(calling_convention.GetRegisterAt(2), |
| 2158 | calling_convention.GetRegisterAt(3), |
| 2159 | FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>())); |
Serban Constantinescu | 4bb30ac | 2016-06-22 17:04:45 +0100 | [diff] [blame] | 2160 | codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc()); |
Anton Kirilov | d70dc9d | 2016-02-04 14:59:04 +0000 | [diff] [blame] | 2161 | __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()), |
| 2162 | calling_convention.GetRegisterAt(0), |
| 2163 | calling_convention.GetRegisterAt(1)); |
| 2164 | } |
| 2165 | |
| 2166 | void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) { |
| 2167 | CreateFPToFPCallLocations(arena_, invoke); |
| 2168 | } |
| 2169 | |
| 2170 | void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) { |
| 2171 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos); |
| 2172 | } |
| 2173 | |
| 2174 | void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) { |
| 2175 | CreateFPToFPCallLocations(arena_, invoke); |
| 2176 | } |
| 2177 | |
| 2178 | void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) { |
| 2179 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin); |
| 2180 | } |
| 2181 | |
| 2182 | void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) { |
| 2183 | CreateFPToFPCallLocations(arena_, invoke); |
| 2184 | } |
| 2185 | |
| 2186 | void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) { |
| 2187 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos); |
| 2188 | } |
| 2189 | |
| 2190 | void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) { |
| 2191 | CreateFPToFPCallLocations(arena_, invoke); |
| 2192 | } |
| 2193 | |
| 2194 | void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) { |
| 2195 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin); |
| 2196 | } |
| 2197 | |
| 2198 | void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) { |
| 2199 | CreateFPToFPCallLocations(arena_, invoke); |
| 2200 | } |
| 2201 | |
| 2202 | void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) { |
| 2203 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan); |
| 2204 | } |
| 2205 | |
| 2206 | void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) { |
| 2207 | CreateFPToFPCallLocations(arena_, invoke); |
| 2208 | } |
| 2209 | |
| 2210 | void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) { |
| 2211 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt); |
| 2212 | } |
| 2213 | |
| 2214 | void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) { |
| 2215 | CreateFPToFPCallLocations(arena_, invoke); |
| 2216 | } |
| 2217 | |
| 2218 | void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) { |
| 2219 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh); |
| 2220 | } |
| 2221 | |
| 2222 | void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) { |
| 2223 | CreateFPToFPCallLocations(arena_, invoke); |
| 2224 | } |
| 2225 | |
| 2226 | void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) { |
| 2227 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp); |
| 2228 | } |
| 2229 | |
| 2230 | void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) { |
| 2231 | CreateFPToFPCallLocations(arena_, invoke); |
| 2232 | } |
| 2233 | |
| 2234 | void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) { |
| 2235 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1); |
| 2236 | } |
| 2237 | |
| 2238 | void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) { |
| 2239 | CreateFPToFPCallLocations(arena_, invoke); |
| 2240 | } |
| 2241 | |
| 2242 | void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) { |
| 2243 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog); |
| 2244 | } |
| 2245 | |
| 2246 | void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) { |
| 2247 | CreateFPToFPCallLocations(arena_, invoke); |
| 2248 | } |
| 2249 | |
| 2250 | void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) { |
| 2251 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10); |
| 2252 | } |
| 2253 | |
| 2254 | void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) { |
| 2255 | CreateFPToFPCallLocations(arena_, invoke); |
| 2256 | } |
| 2257 | |
| 2258 | void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) { |
| 2259 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh); |
| 2260 | } |
| 2261 | |
| 2262 | void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) { |
| 2263 | CreateFPToFPCallLocations(arena_, invoke); |
| 2264 | } |
| 2265 | |
| 2266 | void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) { |
| 2267 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan); |
| 2268 | } |
| 2269 | |
| 2270 | void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) { |
| 2271 | CreateFPToFPCallLocations(arena_, invoke); |
| 2272 | } |
| 2273 | |
| 2274 | void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) { |
| 2275 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh); |
| 2276 | } |
| 2277 | |
| 2278 | void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) { |
| 2279 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2280 | } |
| 2281 | |
| 2282 | void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) { |
| 2283 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2); |
| 2284 | } |
| 2285 | |
| 2286 | void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) { |
| 2287 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2288 | } |
| 2289 | |
| 2290 | void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) { |
| 2291 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot); |
| 2292 | } |
| 2293 | |
| 2294 | void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) { |
| 2295 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2296 | } |
| 2297 | |
| 2298 | void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) { |
| 2299 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter); |
| 2300 | } |
| 2301 | |
Artem Serov | c257da7 | 2016-02-02 13:49:43 +0000 | [diff] [blame] | 2302 | void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) { |
| 2303 | CreateIntToIntLocations(arena_, invoke); |
| 2304 | } |
| 2305 | |
| 2306 | void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) { |
| 2307 | ArmAssembler* assembler = GetAssembler(); |
| 2308 | LocationSummary* locations = invoke->GetLocations(); |
| 2309 | |
| 2310 | Register out = locations->Out().AsRegister<Register>(); |
| 2311 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 2312 | |
| 2313 | __ rbit(out, in); |
| 2314 | } |
| 2315 | |
| 2316 | void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) { |
| 2317 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2318 | LocationSummary::kNoCall, |
| 2319 | kIntrinsified); |
| 2320 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2321 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2322 | } |
| 2323 | |
| 2324 | void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) { |
| 2325 | ArmAssembler* assembler = GetAssembler(); |
| 2326 | LocationSummary* locations = invoke->GetLocations(); |
| 2327 | |
| 2328 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2329 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2330 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 2331 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 2332 | |
| 2333 | __ rbit(out_reg_lo, in_reg_hi); |
| 2334 | __ rbit(out_reg_hi, in_reg_lo); |
| 2335 | } |
| 2336 | |
| 2337 | void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 2338 | CreateIntToIntLocations(arena_, invoke); |
| 2339 | } |
| 2340 | |
| 2341 | void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 2342 | ArmAssembler* assembler = GetAssembler(); |
| 2343 | LocationSummary* locations = invoke->GetLocations(); |
| 2344 | |
| 2345 | Register out = locations->Out().AsRegister<Register>(); |
| 2346 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 2347 | |
| 2348 | __ rev(out, in); |
| 2349 | } |
| 2350 | |
| 2351 | void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) { |
| 2352 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2353 | LocationSummary::kNoCall, |
| 2354 | kIntrinsified); |
| 2355 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2356 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2357 | } |
| 2358 | |
| 2359 | void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) { |
| 2360 | ArmAssembler* assembler = GetAssembler(); |
| 2361 | LocationSummary* locations = invoke->GetLocations(); |
| 2362 | |
| 2363 | Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>(); |
| 2364 | Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>(); |
| 2365 | Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>(); |
| 2366 | Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>(); |
| 2367 | |
| 2368 | __ rev(out_reg_lo, in_reg_hi); |
| 2369 | __ rev(out_reg_hi, in_reg_lo); |
| 2370 | } |
| 2371 | |
| 2372 | void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) { |
| 2373 | CreateIntToIntLocations(arena_, invoke); |
| 2374 | } |
| 2375 | |
| 2376 | void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) { |
| 2377 | ArmAssembler* assembler = GetAssembler(); |
| 2378 | LocationSummary* locations = invoke->GetLocations(); |
| 2379 | |
| 2380 | Register out = locations->Out().AsRegister<Register>(); |
| 2381 | Register in = locations->InAt(0).AsRegister<Register>(); |
| 2382 | |
| 2383 | __ revsh(out, in); |
| 2384 | } |
| 2385 | |
xueliang.zhong | f1073c8 | 2016-07-05 15:28:19 +0100 | [diff] [blame] | 2386 | static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmAssembler* assembler) { |
| 2387 | DCHECK(Primitive::IsIntOrLongType(type)) << type; |
| 2388 | DCHECK_EQ(instr->GetType(), Primitive::kPrimInt); |
| 2389 | DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type); |
| 2390 | |
| 2391 | bool is_long = type == Primitive::kPrimLong; |
| 2392 | LocationSummary* locations = instr->GetLocations(); |
| 2393 | Location in = locations->InAt(0); |
| 2394 | Register src_0 = is_long ? in.AsRegisterPairLow<Register>() : in.AsRegister<Register>(); |
| 2395 | Register src_1 = is_long ? in.AsRegisterPairHigh<Register>() : src_0; |
| 2396 | SRegister tmp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>(); |
| 2397 | DRegister tmp_d = FromLowSToD(tmp_s); |
| 2398 | Register out_r = locations->Out().AsRegister<Register>(); |
| 2399 | |
| 2400 | // Move data from core register(s) to temp D-reg for bit count calculation, then move back. |
| 2401 | // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg, |
| 2402 | // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency, |
| 2403 | // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'. |
| 2404 | __ vmovdrr(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0| |
| 2405 | __ vcntd(tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c| |
| 2406 | __ vpaddld(tmp_d, tmp_d, 8, /* is_unsigned */ true); // Temp DReg |--c|--c|--c|--c| |
| 2407 | __ vpaddld(tmp_d, tmp_d, 16, /* is_unsigned */ true); // Temp DReg |------c|------c| |
| 2408 | if (is_long) { |
| 2409 | __ vpaddld(tmp_d, tmp_d, 32, /* is_unsigned */ true); // Temp DReg |--------------c| |
| 2410 | } |
| 2411 | __ vmovrs(out_r, tmp_s); |
| 2412 | } |
| 2413 | |
| 2414 | void IntrinsicLocationsBuilderARM::VisitIntegerBitCount(HInvoke* invoke) { |
| 2415 | CreateIntToIntLocations(arena_, invoke); |
| 2416 | invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 2417 | } |
| 2418 | |
| 2419 | void IntrinsicCodeGeneratorARM::VisitIntegerBitCount(HInvoke* invoke) { |
| 2420 | GenBitCount(invoke, Primitive::kPrimInt, GetAssembler()); |
| 2421 | } |
| 2422 | |
| 2423 | void IntrinsicLocationsBuilderARM::VisitLongBitCount(HInvoke* invoke) { |
| 2424 | VisitIntegerBitCount(invoke); |
| 2425 | } |
| 2426 | |
| 2427 | void IntrinsicCodeGeneratorARM::VisitLongBitCount(HInvoke* invoke) { |
| 2428 | GenBitCount(invoke, Primitive::kPrimLong, GetAssembler()); |
| 2429 | } |
| 2430 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2431 | void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2432 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2433 | LocationSummary::kNoCall, |
| 2434 | kIntrinsified); |
| 2435 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2436 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2437 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2438 | locations->SetInAt(3, Location::RequiresRegister()); |
| 2439 | locations->SetInAt(4, Location::RequiresRegister()); |
| 2440 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2441 | // Temporary registers to store lengths of strings and for calculations. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2442 | locations->AddTemp(Location::RequiresRegister()); |
| 2443 | locations->AddTemp(Location::RequiresRegister()); |
| 2444 | locations->AddTemp(Location::RequiresRegister()); |
| 2445 | } |
| 2446 | |
| 2447 | void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2448 | ArmAssembler* assembler = GetAssembler(); |
| 2449 | LocationSummary* locations = invoke->GetLocations(); |
| 2450 | |
| 2451 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
| 2452 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 2453 | DCHECK_EQ(char_size, 2u); |
| 2454 | |
| 2455 | // Location of data in char array buffer. |
| 2456 | const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value(); |
| 2457 | |
| 2458 | // Location of char array data in string. |
| 2459 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 2460 | |
| 2461 | // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
| 2462 | // Since getChars() calls getCharsNoCheck() - we use registers rather than constants. |
| 2463 | Register srcObj = locations->InAt(0).AsRegister<Register>(); |
| 2464 | Register srcBegin = locations->InAt(1).AsRegister<Register>(); |
| 2465 | Register srcEnd = locations->InAt(2).AsRegister<Register>(); |
| 2466 | Register dstObj = locations->InAt(3).AsRegister<Register>(); |
| 2467 | Register dstBegin = locations->InAt(4).AsRegister<Register>(); |
| 2468 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2469 | Register num_chr = locations->GetTemp(0).AsRegister<Register>(); |
| 2470 | Register src_ptr = locations->GetTemp(1).AsRegister<Register>(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2471 | Register dst_ptr = locations->GetTemp(2).AsRegister<Register>(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2472 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2473 | Label done, compressed_string_loop; |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2474 | // dst to be copied. |
| 2475 | __ add(dst_ptr, dstObj, ShifterOperand(data_offset)); |
| 2476 | __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1)); |
| 2477 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2478 | __ subs(num_chr, srcEnd, ShifterOperand(srcBegin)); |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2479 | // Early out for valid zero-length retrievals. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2480 | __ b(&done, EQ); |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2481 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2482 | // src range to copy. |
| 2483 | __ add(src_ptr, srcObj, ShifterOperand(value_offset)); |
| 2484 | Label compressed_string_preloop; |
| 2485 | if (mirror::kUseStringCompression) { |
| 2486 | // Location of count in string. |
| 2487 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2488 | // String's length. |
| 2489 | __ ldr(IP, Address(srcObj, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2490 | __ tst(IP, ShifterOperand(1)); |
| 2491 | __ b(&compressed_string_preloop, EQ); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2492 | } |
| 2493 | __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1)); |
| 2494 | |
| 2495 | // Do the copy. |
| 2496 | Label loop, remainder; |
| 2497 | |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2498 | // Save repairing the value of num_chr on the < 4 character path. |
| 2499 | __ subs(IP, num_chr, ShifterOperand(4)); |
| 2500 | __ b(&remainder, LT); |
| 2501 | |
| 2502 | // Keep the result of the earlier subs, we are going to fetch at least 4 characters. |
| 2503 | __ mov(num_chr, ShifterOperand(IP)); |
| 2504 | |
| 2505 | // Main loop used for longer fetches loads and stores 4x16-bit characters at a time. |
| 2506 | // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code |
| 2507 | // to rectify these everywhere this intrinsic applies.) |
| 2508 | __ Bind(&loop); |
| 2509 | __ ldr(IP, Address(src_ptr, char_size * 2)); |
| 2510 | __ subs(num_chr, num_chr, ShifterOperand(4)); |
| 2511 | __ str(IP, Address(dst_ptr, char_size * 2)); |
| 2512 | __ ldr(IP, Address(src_ptr, char_size * 4, Address::PostIndex)); |
| 2513 | __ str(IP, Address(dst_ptr, char_size * 4, Address::PostIndex)); |
| 2514 | __ b(&loop, GE); |
| 2515 | |
| 2516 | __ adds(num_chr, num_chr, ShifterOperand(4)); |
| 2517 | __ b(&done, EQ); |
| 2518 | |
| 2519 | // Main loop for < 4 character case and remainder handling. Loads and stores one |
| 2520 | // 16-bit Java character at a time. |
| 2521 | __ Bind(&remainder); |
| 2522 | __ ldrh(IP, Address(src_ptr, char_size, Address::PostIndex)); |
| 2523 | __ subs(num_chr, num_chr, ShifterOperand(1)); |
| 2524 | __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex)); |
| 2525 | __ b(&remainder, GT); |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2526 | |
| 2527 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2528 | __ b(&done); |
| 2529 | |
jessicahandojo | 0576575 | 2016-09-09 19:01:32 -0700 | [diff] [blame] | 2530 | const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte); |
| 2531 | DCHECK_EQ(c_char_size, 1u); |
| 2532 | // Copy loop for compressed src, copying 1 character (8-bit) to (16-bit) at a time. |
| 2533 | __ Bind(&compressed_string_preloop); |
| 2534 | __ add(src_ptr, src_ptr, ShifterOperand(srcBegin)); |
| 2535 | __ Bind(&compressed_string_loop); |
| 2536 | __ ldrb(IP, Address(src_ptr, c_char_size, Address::PostIndex)); |
| 2537 | __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex)); |
| 2538 | __ subs(num_chr, num_chr, ShifterOperand(1)); |
| 2539 | __ b(&compressed_string_loop, GT); |
| 2540 | } |
Scott Wakeling | 3fdab77 | 2016-04-25 11:32:37 +0100 | [diff] [blame] | 2541 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 2542 | __ Bind(&done); |
| 2543 | } |
| 2544 | |
Anton Kirilov | a3ffea2 | 2016-04-07 17:02:37 +0100 | [diff] [blame] | 2545 | void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2546 | CreateFPToIntLocations(arena_, invoke); |
| 2547 | } |
| 2548 | |
| 2549 | void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2550 | ArmAssembler* const assembler = GetAssembler(); |
| 2551 | LocationSummary* const locations = invoke->GetLocations(); |
| 2552 | const Register out = locations->Out().AsRegister<Register>(); |
| 2553 | // Shifting left by 1 bit makes the value encodable as an immediate operand; |
| 2554 | // we don't care about the sign bit anyway. |
| 2555 | constexpr uint32_t infinity = kPositiveInfinityFloat << 1U; |
| 2556 | |
| 2557 | __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>()); |
| 2558 | // We don't care about the sign bit, so shift left. |
| 2559 | __ Lsl(out, out, 1); |
| 2560 | __ eor(out, out, ShifterOperand(infinity)); |
| 2561 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2562 | __ clz(out, out); |
| 2563 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2564 | // the same operation on 32 yields 1. |
| 2565 | __ Lsr(out, out, 5); |
| 2566 | } |
| 2567 | |
| 2568 | void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2569 | CreateFPToIntLocations(arena_, invoke); |
| 2570 | } |
| 2571 | |
| 2572 | void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2573 | ArmAssembler* const assembler = GetAssembler(); |
| 2574 | LocationSummary* const locations = invoke->GetLocations(); |
| 2575 | const Register out = locations->Out().AsRegister<Register>(); |
| 2576 | // The highest 32 bits of double precision positive infinity separated into |
| 2577 | // two constants encodable as immediate operands. |
| 2578 | constexpr uint32_t infinity_high = 0x7f000000U; |
| 2579 | constexpr uint32_t infinity_high2 = 0x00f00000U; |
| 2580 | |
| 2581 | static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U), |
| 2582 | "The constants do not add up to the high 32 bits of double precision positive infinity."); |
| 2583 | __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>())); |
| 2584 | __ eor(out, out, ShifterOperand(infinity_high)); |
| 2585 | __ eor(out, out, ShifterOperand(infinity_high2)); |
| 2586 | // We don't care about the sign bit, so shift left. |
| 2587 | __ orr(out, IP, ShifterOperand(out, LSL, 1)); |
| 2588 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2589 | __ clz(out, out); |
| 2590 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2591 | // the same operation on 32 yields 1. |
| 2592 | __ Lsr(out, out, 5); |
| 2593 | } |
| 2594 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2595 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble) |
| 2596 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat) |
| 2597 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble) |
| 2598 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat) |
| 2599 | UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong) |
| 2600 | UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong) |
| 2601 | UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe? |
| 2602 | UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe? |
| 2603 | UNIMPLEMENTED_INTRINSIC(ARM, MathRint) |
| 2604 | UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe? |
| 2605 | UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe? |
| 2606 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure. |
| 2607 | UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar) |
| 2608 | UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent) |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2609 | UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit) |
| 2610 | UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit) |
| 2611 | UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit) |
| 2612 | UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit) |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2613 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2614 | UNIMPLEMENTED_INTRINSIC(ARM, StringStringIndexOf); |
| 2615 | UNIMPLEMENTED_INTRINSIC(ARM, StringStringIndexOfAfter); |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2616 | UNIMPLEMENTED_INTRINSIC(ARM, StringBufferAppend); |
| 2617 | UNIMPLEMENTED_INTRINSIC(ARM, StringBufferLength); |
| 2618 | UNIMPLEMENTED_INTRINSIC(ARM, StringBufferToString); |
| 2619 | UNIMPLEMENTED_INTRINSIC(ARM, StringBuilderAppend); |
| 2620 | UNIMPLEMENTED_INTRINSIC(ARM, StringBuilderLength); |
| 2621 | UNIMPLEMENTED_INTRINSIC(ARM, StringBuilderToString); |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2622 | |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2623 | // 1.8. |
| 2624 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt) |
| 2625 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong) |
| 2626 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt) |
| 2627 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong) |
| 2628 | UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject) |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2629 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2630 | UNREACHABLE_INTRINSICS(ARM) |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2631 | |
| 2632 | #undef __ |
| 2633 | |
Andreas Gampe | 2bcf9bf | 2015-01-29 09:56:07 -0800 | [diff] [blame] | 2634 | } // namespace arm |
| 2635 | } // namespace art |