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