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