Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_vixl.h" |
| 18 | |
| 19 | #include "arch/arm/instruction_set_features_arm.h" |
| 20 | #include "code_generator_arm_vixl.h" |
| 21 | #include "common_arm.h" |
| 22 | #include "lock_word.h" |
| 23 | #include "mirror/array-inl.h" |
| 24 | |
| 25 | #include "aarch32/constants-aarch32.h" |
| 26 | |
| 27 | namespace art { |
| 28 | namespace arm { |
| 29 | |
| 30 | #define __ assembler->GetVIXLAssembler()-> |
| 31 | |
| 32 | using helpers::DRegisterFrom; |
| 33 | using helpers::HighRegisterFrom; |
| 34 | using helpers::InputDRegisterAt; |
| 35 | using helpers::InputRegisterAt; |
| 36 | using helpers::InputSRegisterAt; |
| 37 | using helpers::InputVRegisterAt; |
| 38 | using helpers::Int32ConstantFrom; |
| 39 | using helpers::LocationFrom; |
| 40 | using helpers::LowRegisterFrom; |
| 41 | using helpers::LowSRegisterFrom; |
xueliang.zhong | 53463ba | 2017-02-16 15:18:03 +0000 | [diff] [blame] | 42 | using helpers::HighSRegisterFrom; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 43 | using helpers::OutputDRegister; |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 44 | using helpers::OutputSRegister; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 45 | using helpers::OutputRegister; |
| 46 | using helpers::OutputVRegister; |
| 47 | using helpers::RegisterFrom; |
| 48 | using helpers::SRegisterFrom; |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 49 | using helpers::DRegisterFromS; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 50 | |
| 51 | using namespace vixl::aarch32; // NOLINT(build/namespaces) |
| 52 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 53 | using vixl::ExactAssemblyScope; |
| 54 | using vixl::CodeBufferCheckScope; |
| 55 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 56 | ArmVIXLAssembler* IntrinsicCodeGeneratorARMVIXL::GetAssembler() { |
| 57 | return codegen_->GetAssembler(); |
| 58 | } |
| 59 | |
| 60 | ArenaAllocator* IntrinsicCodeGeneratorARMVIXL::GetAllocator() { |
| 61 | return codegen_->GetGraph()->GetArena(); |
| 62 | } |
| 63 | |
| 64 | // Default slow-path for fallback (calling the managed code to handle the intrinsic) in an |
| 65 | // intrinsified call. This will copy the arguments into the positions for a regular call. |
| 66 | // |
| 67 | // Note: The actual parameters are required to be in the locations given by the invoke's location |
| 68 | // summary. If an intrinsic modifies those locations before a slowpath call, they must be |
| 69 | // restored! |
| 70 | // |
| 71 | // Note: If an invoke wasn't sharpened, we will put down an invoke-virtual here. That's potentially |
| 72 | // sub-optimal (compared to a direct pointer call), but this is a slow-path. |
| 73 | |
| 74 | class IntrinsicSlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 75 | public: |
| 76 | explicit IntrinsicSlowPathARMVIXL(HInvoke* invoke) |
| 77 | : SlowPathCodeARMVIXL(invoke), invoke_(invoke) {} |
| 78 | |
| 79 | Location MoveArguments(CodeGenerator* codegen) { |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 80 | InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 81 | IntrinsicVisitor::MoveArguments(invoke_, codegen, &calling_convention_visitor); |
| 82 | return calling_convention_visitor.GetMethodLocation(); |
| 83 | } |
| 84 | |
| 85 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 86 | ArmVIXLAssembler* assembler = down_cast<ArmVIXLAssembler*>(codegen->GetAssembler()); |
| 87 | __ Bind(GetEntryLabel()); |
| 88 | |
| 89 | SaveLiveRegisters(codegen, invoke_->GetLocations()); |
| 90 | |
| 91 | Location method_loc = MoveArguments(codegen); |
| 92 | |
| 93 | if (invoke_->IsInvokeStaticOrDirect()) { |
| 94 | codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), method_loc); |
| 95 | } else { |
| 96 | codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), method_loc); |
| 97 | } |
| 98 | codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this); |
| 99 | |
| 100 | // Copy the result back to the expected output. |
| 101 | Location out = invoke_->GetLocations()->Out(); |
| 102 | if (out.IsValid()) { |
| 103 | DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory. |
| 104 | DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 105 | codegen->MoveFromReturnRegister(out, invoke_->GetType()); |
| 106 | } |
| 107 | |
| 108 | RestoreLiveRegisters(codegen, invoke_->GetLocations()); |
| 109 | __ B(GetExitLabel()); |
| 110 | } |
| 111 | |
| 112 | const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPath"; } |
| 113 | |
| 114 | private: |
| 115 | // The instruction where this slow path is happening. |
| 116 | HInvoke* const invoke_; |
| 117 | |
| 118 | DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARMVIXL); |
| 119 | }; |
| 120 | |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 121 | // Compute base address for the System.arraycopy intrinsic in `base`. |
| 122 | static void GenSystemArrayCopyBaseAddress(ArmVIXLAssembler* assembler, |
| 123 | Primitive::Type type, |
| 124 | const vixl32::Register& array, |
| 125 | const Location& pos, |
| 126 | const vixl32::Register& base) { |
| 127 | // This routine is only used by the SystemArrayCopy intrinsic at the |
| 128 | // moment. We can allow Primitive::kPrimNot as `type` to implement |
| 129 | // the SystemArrayCopyChar intrinsic. |
| 130 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 131 | const int32_t element_size = Primitive::ComponentSize(type); |
| 132 | const uint32_t element_size_shift = Primitive::ComponentSizeShift(type); |
| 133 | const uint32_t data_offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
| 134 | |
| 135 | if (pos.IsConstant()) { |
| 136 | int32_t constant = Int32ConstantFrom(pos); |
| 137 | __ Add(base, array, element_size * constant + data_offset); |
| 138 | } else { |
| 139 | __ Add(base, array, Operand(RegisterFrom(pos), vixl32::LSL, element_size_shift)); |
| 140 | __ Add(base, base, data_offset); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Compute end address for the System.arraycopy intrinsic in `end`. |
| 145 | static void GenSystemArrayCopyEndAddress(ArmVIXLAssembler* assembler, |
| 146 | Primitive::Type type, |
| 147 | const Location& copy_length, |
| 148 | const vixl32::Register& base, |
| 149 | const vixl32::Register& end) { |
| 150 | // This routine is only used by the SystemArrayCopy intrinsic at the |
| 151 | // moment. We can allow Primitive::kPrimNot as `type` to implement |
| 152 | // the SystemArrayCopyChar intrinsic. |
| 153 | DCHECK_EQ(type, Primitive::kPrimNot); |
| 154 | const int32_t element_size = Primitive::ComponentSize(type); |
| 155 | const uint32_t element_size_shift = Primitive::ComponentSizeShift(type); |
| 156 | |
| 157 | if (copy_length.IsConstant()) { |
| 158 | int32_t constant = Int32ConstantFrom(copy_length); |
| 159 | __ Add(end, base, element_size * constant); |
| 160 | } else { |
| 161 | __ Add(end, base, Operand(RegisterFrom(copy_length), vixl32::LSL, element_size_shift)); |
| 162 | } |
| 163 | } |
| 164 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 165 | // Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers. |
| 166 | class ReadBarrierSystemArrayCopySlowPathARMVIXL : public SlowPathCodeARMVIXL { |
| 167 | public: |
| 168 | explicit ReadBarrierSystemArrayCopySlowPathARMVIXL(HInstruction* instruction) |
| 169 | : SlowPathCodeARMVIXL(instruction) { |
| 170 | DCHECK(kEmitCompilerReadBarrier); |
| 171 | DCHECK(kUseBakerReadBarrier); |
| 172 | } |
| 173 | |
| 174 | void EmitNativeCode(CodeGenerator* codegen) OVERRIDE { |
| 175 | CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen); |
| 176 | ArmVIXLAssembler* assembler = arm_codegen->GetAssembler(); |
| 177 | LocationSummary* locations = instruction_->GetLocations(); |
| 178 | DCHECK(locations->CanCall()); |
| 179 | DCHECK(instruction_->IsInvokeStaticOrDirect()) |
| 180 | << "Unexpected instruction in read barrier arraycopy slow path: " |
| 181 | << instruction_->DebugName(); |
| 182 | DCHECK(instruction_->GetLocations()->Intrinsified()); |
| 183 | DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy); |
| 184 | |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 185 | Primitive::Type type = Primitive::kPrimNot; |
| 186 | const int32_t element_size = Primitive::ComponentSize(type); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 187 | |
| 188 | vixl32::Register dest = InputRegisterAt(instruction_, 2); |
| 189 | Location dest_pos = locations->InAt(3); |
| 190 | vixl32::Register src_curr_addr = RegisterFrom(locations->GetTemp(0)); |
| 191 | vixl32::Register dst_curr_addr = RegisterFrom(locations->GetTemp(1)); |
| 192 | vixl32::Register src_stop_addr = RegisterFrom(locations->GetTemp(2)); |
| 193 | vixl32::Register tmp = RegisterFrom(locations->GetTemp(3)); |
| 194 | |
| 195 | __ Bind(GetEntryLabel()); |
| 196 | // Compute the base destination address in `dst_curr_addr`. |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 197 | GenSystemArrayCopyBaseAddress(assembler, type, dest, dest_pos, dst_curr_addr); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 198 | |
| 199 | vixl32::Label loop; |
| 200 | __ Bind(&loop); |
| 201 | __ Ldr(tmp, MemOperand(src_curr_addr, element_size, PostIndex)); |
| 202 | assembler->MaybeUnpoisonHeapReference(tmp); |
| 203 | // TODO: Inline the mark bit check before calling the runtime? |
| 204 | // tmp = ReadBarrier::Mark(tmp); |
| 205 | // No need to save live registers; it's taken care of by the |
| 206 | // entrypoint. Also, there is no need to update the stack mask, |
| 207 | // as this runtime call will not trigger a garbage collection. |
| 208 | // (See ReadBarrierMarkSlowPathARM::EmitNativeCode for more |
| 209 | // explanations.) |
| 210 | DCHECK(!tmp.IsSP()); |
| 211 | DCHECK(!tmp.IsLR()); |
| 212 | DCHECK(!tmp.IsPC()); |
| 213 | // IP is used internally by the ReadBarrierMarkRegX entry point |
| 214 | // as a temporary (and not preserved). It thus cannot be used by |
| 215 | // any live register in this slow path. |
| 216 | DCHECK(!src_curr_addr.Is(ip)); |
| 217 | DCHECK(!dst_curr_addr.Is(ip)); |
| 218 | DCHECK(!src_stop_addr.Is(ip)); |
| 219 | DCHECK(!tmp.Is(ip)); |
| 220 | DCHECK(tmp.IsRegister()) << tmp; |
Roland Levillain | 9cc0ea8 | 2017-03-16 11:25:59 +0000 | [diff] [blame] | 221 | // TODO: Load the entrypoint once before the loop, instead of |
| 222 | // loading it at every iteration. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 223 | int32_t entry_point_offset = |
| 224 | CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(tmp.GetCode()); |
| 225 | // This runtime call does not require a stack map. |
| 226 | arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this); |
| 227 | assembler->MaybePoisonHeapReference(tmp); |
| 228 | __ Str(tmp, MemOperand(dst_curr_addr, element_size, PostIndex)); |
| 229 | __ Cmp(src_curr_addr, src_stop_addr); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 230 | __ B(ne, &loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 231 | __ B(GetExitLabel()); |
| 232 | } |
| 233 | |
| 234 | const char* GetDescription() const OVERRIDE { |
| 235 | return "ReadBarrierSystemArrayCopySlowPathARMVIXL"; |
| 236 | } |
| 237 | |
| 238 | private: |
| 239 | DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathARMVIXL); |
| 240 | }; |
| 241 | |
| 242 | IntrinsicLocationsBuilderARMVIXL::IntrinsicLocationsBuilderARMVIXL(CodeGeneratorARMVIXL* codegen) |
| 243 | : arena_(codegen->GetGraph()->GetArena()), |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 244 | codegen_(codegen), |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 245 | assembler_(codegen->GetAssembler()), |
| 246 | features_(codegen->GetInstructionSetFeatures()) {} |
| 247 | |
| 248 | bool IntrinsicLocationsBuilderARMVIXL::TryDispatch(HInvoke* invoke) { |
| 249 | Dispatch(invoke); |
| 250 | LocationSummary* res = invoke->GetLocations(); |
| 251 | if (res == nullptr) { |
| 252 | return false; |
| 253 | } |
| 254 | return res->Intrinsified(); |
| 255 | } |
| 256 | |
| 257 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 258 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 259 | LocationSummary::kNoCall, |
| 260 | kIntrinsified); |
| 261 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 262 | locations->SetOut(Location::RequiresRegister()); |
| 263 | } |
| 264 | |
| 265 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 266 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 267 | LocationSummary::kNoCall, |
| 268 | kIntrinsified); |
| 269 | locations->SetInAt(0, Location::RequiresRegister()); |
| 270 | locations->SetOut(Location::RequiresFpuRegister()); |
| 271 | } |
| 272 | |
| 273 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmVIXLAssembler* assembler) { |
| 274 | Location input = locations->InAt(0); |
| 275 | Location output = locations->Out(); |
| 276 | if (is64bit) { |
| 277 | __ Vmov(LowRegisterFrom(output), HighRegisterFrom(output), DRegisterFrom(input)); |
| 278 | } else { |
| 279 | __ Vmov(RegisterFrom(output), SRegisterFrom(input)); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmVIXLAssembler* assembler) { |
| 284 | Location input = locations->InAt(0); |
| 285 | Location output = locations->Out(); |
| 286 | if (is64bit) { |
| 287 | __ Vmov(DRegisterFrom(output), LowRegisterFrom(input), HighRegisterFrom(input)); |
| 288 | } else { |
| 289 | __ Vmov(SRegisterFrom(output), RegisterFrom(input)); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | void IntrinsicLocationsBuilderARMVIXL::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 294 | CreateFPToIntLocations(arena_, invoke); |
| 295 | } |
| 296 | void IntrinsicLocationsBuilderARMVIXL::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 297 | CreateIntToFPLocations(arena_, invoke); |
| 298 | } |
| 299 | |
| 300 | void IntrinsicCodeGeneratorARMVIXL::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 301 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
| 302 | } |
| 303 | void IntrinsicCodeGeneratorARMVIXL::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 304 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
| 305 | } |
| 306 | |
| 307 | void IntrinsicLocationsBuilderARMVIXL::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 308 | CreateFPToIntLocations(arena_, invoke); |
| 309 | } |
| 310 | void IntrinsicLocationsBuilderARMVIXL::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 311 | CreateIntToFPLocations(arena_, invoke); |
| 312 | } |
| 313 | |
| 314 | void IntrinsicCodeGeneratorARMVIXL::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 315 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
| 316 | } |
| 317 | void IntrinsicCodeGeneratorARMVIXL::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 318 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
| 319 | } |
| 320 | |
| 321 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 322 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 323 | LocationSummary::kNoCall, |
| 324 | kIntrinsified); |
| 325 | locations->SetInAt(0, Location::RequiresRegister()); |
| 326 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 327 | } |
| 328 | |
| 329 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 330 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 331 | LocationSummary::kNoCall, |
| 332 | kIntrinsified); |
| 333 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 334 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 335 | } |
| 336 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 337 | static void GenNumberOfLeadingZeros(HInvoke* invoke, |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 338 | Primitive::Type type, |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 339 | CodeGeneratorARMVIXL* codegen) { |
| 340 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 341 | LocationSummary* locations = invoke->GetLocations(); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 342 | Location in = locations->InAt(0); |
| 343 | vixl32::Register out = RegisterFrom(locations->Out()); |
| 344 | |
| 345 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 346 | |
| 347 | if (type == Primitive::kPrimLong) { |
| 348 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 349 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 350 | vixl32::Label end; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 351 | vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &end); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 352 | __ Clz(out, in_reg_hi); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 353 | __ CompareAndBranchIfNonZero(in_reg_hi, final_label, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 354 | __ Clz(out, in_reg_lo); |
| 355 | __ Add(out, out, 32); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 356 | if (end.IsReferenced()) { |
| 357 | __ Bind(&end); |
| 358 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 359 | } else { |
| 360 | __ Clz(out, RegisterFrom(in)); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 365 | CreateIntToIntLocations(arena_, invoke); |
| 366 | } |
| 367 | |
| 368 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 369 | GenNumberOfLeadingZeros(invoke, Primitive::kPrimInt, codegen_); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | void IntrinsicLocationsBuilderARMVIXL::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 373 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 374 | LocationSummary::kNoCall, |
| 375 | kIntrinsified); |
| 376 | locations->SetInAt(0, Location::RequiresRegister()); |
| 377 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 378 | } |
| 379 | |
| 380 | void IntrinsicCodeGeneratorARMVIXL::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 381 | GenNumberOfLeadingZeros(invoke, Primitive::kPrimLong, codegen_); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 382 | } |
| 383 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 384 | static void GenNumberOfTrailingZeros(HInvoke* invoke, |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 385 | Primitive::Type type, |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 386 | CodeGeneratorARMVIXL* codegen) { |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 387 | DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong)); |
| 388 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 389 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 390 | LocationSummary* locations = invoke->GetLocations(); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 391 | vixl32::Register out = RegisterFrom(locations->Out()); |
| 392 | |
| 393 | if (type == Primitive::kPrimLong) { |
| 394 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 395 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 396 | vixl32::Label end; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 397 | vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &end); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 398 | __ Rbit(out, in_reg_lo); |
| 399 | __ Clz(out, out); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 400 | __ CompareAndBranchIfNonZero(in_reg_lo, final_label, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 401 | __ Rbit(out, in_reg_hi); |
| 402 | __ Clz(out, out); |
| 403 | __ Add(out, out, 32); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 404 | if (end.IsReferenced()) { |
| 405 | __ Bind(&end); |
| 406 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 407 | } else { |
| 408 | vixl32::Register in = RegisterFrom(locations->InAt(0)); |
| 409 | __ Rbit(out, in); |
| 410 | __ Clz(out, out); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 415 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 416 | LocationSummary::kNoCall, |
| 417 | kIntrinsified); |
| 418 | locations->SetInAt(0, Location::RequiresRegister()); |
| 419 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 420 | } |
| 421 | |
| 422 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 423 | GenNumberOfTrailingZeros(invoke, Primitive::kPrimInt, codegen_); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | void IntrinsicLocationsBuilderARMVIXL::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 427 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 428 | LocationSummary::kNoCall, |
| 429 | kIntrinsified); |
| 430 | locations->SetInAt(0, Location::RequiresRegister()); |
| 431 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 432 | } |
| 433 | |
| 434 | void IntrinsicCodeGeneratorARMVIXL::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 435 | GenNumberOfTrailingZeros(invoke, Primitive::kPrimLong, codegen_); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void MathAbsFP(HInvoke* invoke, ArmVIXLAssembler* assembler) { |
| 439 | __ Vabs(OutputVRegister(invoke), InputVRegisterAt(invoke, 0)); |
| 440 | } |
| 441 | |
| 442 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsDouble(HInvoke* invoke) { |
| 443 | CreateFPToFPLocations(arena_, invoke); |
| 444 | } |
| 445 | |
| 446 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsDouble(HInvoke* invoke) { |
| 447 | MathAbsFP(invoke, GetAssembler()); |
| 448 | } |
| 449 | |
| 450 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsFloat(HInvoke* invoke) { |
| 451 | CreateFPToFPLocations(arena_, invoke); |
| 452 | } |
| 453 | |
| 454 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsFloat(HInvoke* invoke) { |
| 455 | MathAbsFP(invoke, GetAssembler()); |
| 456 | } |
| 457 | |
| 458 | static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) { |
| 459 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 460 | LocationSummary::kNoCall, |
| 461 | kIntrinsified); |
| 462 | locations->SetInAt(0, Location::RequiresRegister()); |
| 463 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 464 | |
| 465 | locations->AddTemp(Location::RequiresRegister()); |
| 466 | } |
| 467 | |
| 468 | static void GenAbsInteger(LocationSummary* locations, |
| 469 | bool is64bit, |
| 470 | ArmVIXLAssembler* assembler) { |
| 471 | Location in = locations->InAt(0); |
| 472 | Location output = locations->Out(); |
| 473 | |
| 474 | vixl32::Register mask = RegisterFrom(locations->GetTemp(0)); |
| 475 | |
| 476 | if (is64bit) { |
| 477 | vixl32::Register in_reg_lo = LowRegisterFrom(in); |
| 478 | vixl32::Register in_reg_hi = HighRegisterFrom(in); |
| 479 | vixl32::Register out_reg_lo = LowRegisterFrom(output); |
| 480 | vixl32::Register out_reg_hi = HighRegisterFrom(output); |
| 481 | |
| 482 | DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected."; |
| 483 | |
| 484 | __ Asr(mask, in_reg_hi, 31); |
| 485 | __ Adds(out_reg_lo, in_reg_lo, mask); |
| 486 | __ Adc(out_reg_hi, in_reg_hi, mask); |
| 487 | __ Eor(out_reg_lo, mask, out_reg_lo); |
| 488 | __ Eor(out_reg_hi, mask, out_reg_hi); |
| 489 | } else { |
| 490 | vixl32::Register in_reg = RegisterFrom(in); |
| 491 | vixl32::Register out_reg = RegisterFrom(output); |
| 492 | |
| 493 | __ Asr(mask, in_reg, 31); |
| 494 | __ Add(out_reg, in_reg, mask); |
| 495 | __ Eor(out_reg, mask, out_reg); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsInt(HInvoke* invoke) { |
| 500 | CreateIntToIntPlusTemp(arena_, invoke); |
| 501 | } |
| 502 | |
| 503 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsInt(HInvoke* invoke) { |
| 504 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler()); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsLong(HInvoke* invoke) { |
| 509 | CreateIntToIntPlusTemp(arena_, invoke); |
| 510 | } |
| 511 | |
| 512 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsLong(HInvoke* invoke) { |
| 513 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler()); |
| 514 | } |
| 515 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 516 | static void GenMinMaxFloat(HInvoke* invoke, bool is_min, CodeGeneratorARMVIXL* codegen) { |
| 517 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 518 | Location op1_loc = invoke->GetLocations()->InAt(0); |
| 519 | Location op2_loc = invoke->GetLocations()->InAt(1); |
| 520 | Location out_loc = invoke->GetLocations()->Out(); |
| 521 | |
| 522 | // Optimization: don't generate any code if inputs are the same. |
| 523 | if (op1_loc.Equals(op2_loc)) { |
| 524 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | vixl32::SRegister op1 = SRegisterFrom(op1_loc); |
| 529 | vixl32::SRegister op2 = SRegisterFrom(op2_loc); |
| 530 | vixl32::SRegister out = OutputSRegister(invoke); |
| 531 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 532 | const vixl32::Register temp1 = temps.Acquire(); |
| 533 | vixl32::Register temp2 = RegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 534 | vixl32::Label nan, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 535 | vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &done); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 536 | |
| 537 | DCHECK(op1.Is(out)); |
| 538 | |
| 539 | __ Vcmp(op1, op2); |
| 540 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 541 | __ B(vs, &nan, /* far_target */ false); // if un-ordered, go to NaN handling. |
| 542 | |
| 543 | // op1 <> op2 |
| 544 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 545 | { |
| 546 | ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(), |
| 547 | 2 * kMaxInstructionSizeInBytes, |
| 548 | CodeBufferCheckScope::kMaximumSize); |
| 549 | __ it(cond); |
| 550 | __ vmov(cond, F32, out, op2); |
| 551 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 552 | // for <>(not equal), we've done min/max calculation. |
| 553 | __ B(ne, final_label, /* far_target */ false); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 554 | |
| 555 | // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0). |
| 556 | __ Vmov(temp1, op1); |
| 557 | __ Vmov(temp2, op2); |
| 558 | if (is_min) { |
| 559 | __ Orr(temp1, temp1, temp2); |
| 560 | } else { |
| 561 | __ And(temp1, temp1, temp2); |
| 562 | } |
| 563 | __ Vmov(out, temp1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 564 | __ B(final_label); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 565 | |
| 566 | // handle NaN input. |
| 567 | __ Bind(&nan); |
| 568 | __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN. |
| 569 | __ Vmov(out, temp1); |
| 570 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 571 | if (done.IsReferenced()) { |
| 572 | __ Bind(&done); |
| 573 | } |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 577 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 578 | LocationSummary::kNoCall, |
| 579 | kIntrinsified); |
| 580 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 581 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 582 | locations->SetOut(Location::SameAsFirstInput()); |
| 583 | } |
| 584 | |
| 585 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 586 | CreateFPFPToFPLocations(arena_, invoke); |
| 587 | invoke->GetLocations()->AddTemp(Location::RequiresRegister()); |
| 588 | } |
| 589 | |
| 590 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMinFloatFloat(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 591 | GenMinMaxFloat(invoke, /* is_min */ true, codegen_); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 595 | CreateFPFPToFPLocations(arena_, invoke); |
| 596 | invoke->GetLocations()->AddTemp(Location::RequiresRegister()); |
| 597 | } |
| 598 | |
| 599 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxFloatFloat(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 600 | GenMinMaxFloat(invoke, /* is_min */ false, codegen_); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 601 | } |
| 602 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 603 | static void GenMinMaxDouble(HInvoke* invoke, bool is_min, CodeGeneratorARMVIXL* codegen) { |
| 604 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 605 | Location op1_loc = invoke->GetLocations()->InAt(0); |
| 606 | Location op2_loc = invoke->GetLocations()->InAt(1); |
| 607 | Location out_loc = invoke->GetLocations()->Out(); |
| 608 | |
| 609 | // Optimization: don't generate any code if inputs are the same. |
| 610 | if (op1_loc.Equals(op2_loc)) { |
| 611 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in. |
| 612 | return; |
| 613 | } |
| 614 | |
| 615 | vixl32::DRegister op1 = DRegisterFrom(op1_loc); |
| 616 | vixl32::DRegister op2 = DRegisterFrom(op2_loc); |
| 617 | vixl32::DRegister out = OutputDRegister(invoke); |
| 618 | vixl32::Label handle_nan_eq, done; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 619 | vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &done); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 620 | |
| 621 | DCHECK(op1.Is(out)); |
| 622 | |
| 623 | __ Vcmp(op1, op2); |
| 624 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 625 | __ B(vs, &handle_nan_eq, /* far_target */ false); // if un-ordered, go to NaN handling. |
| 626 | |
| 627 | // op1 <> op2 |
| 628 | vixl32::ConditionType cond = is_min ? gt : lt; |
| 629 | { |
| 630 | ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(), |
| 631 | 2 * kMaxInstructionSizeInBytes, |
| 632 | CodeBufferCheckScope::kMaximumSize); |
| 633 | __ it(cond); |
| 634 | __ vmov(cond, F64, out, op2); |
| 635 | } |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 636 | // for <>(not equal), we've done min/max calculation. |
| 637 | __ B(ne, final_label, /* far_target */ false); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 638 | |
| 639 | // handle op1 == op2, max(+0.0,-0.0). |
| 640 | if (!is_min) { |
| 641 | __ Vand(F64, out, op1, op2); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 642 | __ B(final_label); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | // handle op1 == op2, min(+0.0,-0.0), NaN input. |
| 646 | __ Bind(&handle_nan_eq); |
| 647 | __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN. |
| 648 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 649 | if (done.IsReferenced()) { |
| 650 | __ Bind(&done); |
| 651 | } |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 655 | CreateFPFPToFPLocations(arena_, invoke); |
| 656 | } |
| 657 | |
| 658 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMinDoubleDouble(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 659 | GenMinMaxDouble(invoke, /* is_min */ true , codegen_); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 663 | CreateFPFPToFPLocations(arena_, invoke); |
| 664 | } |
| 665 | |
| 666 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 667 | GenMinMaxDouble(invoke, /* is_min */ false, codegen_); |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void GenMinMaxLong(HInvoke* invoke, bool is_min, ArmVIXLAssembler* assembler) { |
| 671 | Location op1_loc = invoke->GetLocations()->InAt(0); |
| 672 | Location op2_loc = invoke->GetLocations()->InAt(1); |
| 673 | Location out_loc = invoke->GetLocations()->Out(); |
| 674 | |
| 675 | // Optimization: don't generate any code if inputs are the same. |
| 676 | if (op1_loc.Equals(op2_loc)) { |
| 677 | DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder. |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | vixl32::Register op1_lo = LowRegisterFrom(op1_loc); |
| 682 | vixl32::Register op1_hi = HighRegisterFrom(op1_loc); |
| 683 | vixl32::Register op2_lo = LowRegisterFrom(op2_loc); |
| 684 | vixl32::Register op2_hi = HighRegisterFrom(op2_loc); |
| 685 | vixl32::Register out_lo = LowRegisterFrom(out_loc); |
| 686 | vixl32::Register out_hi = HighRegisterFrom(out_loc); |
| 687 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 688 | const vixl32::Register temp = temps.Acquire(); |
| 689 | |
| 690 | DCHECK(op1_lo.Is(out_lo)); |
| 691 | DCHECK(op1_hi.Is(out_hi)); |
| 692 | |
| 693 | // Compare op1 >= op2, or op1 < op2. |
| 694 | __ Cmp(out_lo, op2_lo); |
| 695 | __ Sbcs(temp, out_hi, op2_hi); |
| 696 | |
| 697 | // Now GE/LT condition code is correct for the long comparison. |
| 698 | { |
| 699 | vixl32::ConditionType cond = is_min ? ge : lt; |
| 700 | ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(), |
| 701 | 3 * kMaxInstructionSizeInBytes, |
| 702 | CodeBufferCheckScope::kMaximumSize); |
| 703 | __ itt(cond); |
| 704 | __ mov(cond, out_lo, op2_lo); |
| 705 | __ mov(cond, out_hi, op2_hi); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | static void CreateLongLongToLongLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 710 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 711 | LocationSummary::kNoCall, |
| 712 | kIntrinsified); |
| 713 | locations->SetInAt(0, Location::RequiresRegister()); |
| 714 | locations->SetInAt(1, Location::RequiresRegister()); |
| 715 | locations->SetOut(Location::SameAsFirstInput()); |
| 716 | } |
| 717 | |
| 718 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMinLongLong(HInvoke* invoke) { |
| 719 | CreateLongLongToLongLocations(arena_, invoke); |
| 720 | } |
| 721 | |
| 722 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMinLongLong(HInvoke* invoke) { |
| 723 | GenMinMaxLong(invoke, /* is_min */ true, GetAssembler()); |
| 724 | } |
| 725 | |
| 726 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxLongLong(HInvoke* invoke) { |
| 727 | CreateLongLongToLongLocations(arena_, invoke); |
| 728 | } |
| 729 | |
| 730 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxLongLong(HInvoke* invoke) { |
| 731 | GenMinMaxLong(invoke, /* is_min */ false, GetAssembler()); |
| 732 | } |
| 733 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 734 | static void GenMinMax(HInvoke* invoke, bool is_min, ArmVIXLAssembler* assembler) { |
| 735 | vixl32::Register op1 = InputRegisterAt(invoke, 0); |
| 736 | vixl32::Register op2 = InputRegisterAt(invoke, 1); |
| 737 | vixl32::Register out = OutputRegister(invoke); |
| 738 | |
| 739 | __ Cmp(op1, op2); |
| 740 | |
| 741 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 742 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 743 | 3 * kMaxInstructionSizeInBytes, |
| 744 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 745 | |
| 746 | __ ite(is_min ? lt : gt); |
| 747 | __ mov(is_min ? lt : gt, out, op1); |
| 748 | __ mov(is_min ? ge : le, out, op2); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 753 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 754 | LocationSummary::kNoCall, |
| 755 | kIntrinsified); |
| 756 | locations->SetInAt(0, Location::RequiresRegister()); |
| 757 | locations->SetInAt(1, Location::RequiresRegister()); |
| 758 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 759 | } |
| 760 | |
| 761 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMinIntInt(HInvoke* invoke) { |
| 762 | CreateIntIntToIntLocations(arena_, invoke); |
| 763 | } |
| 764 | |
| 765 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMinIntInt(HInvoke* invoke) { |
| 766 | GenMinMax(invoke, /* is_min */ true, GetAssembler()); |
| 767 | } |
| 768 | |
| 769 | void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxIntInt(HInvoke* invoke) { |
| 770 | CreateIntIntToIntLocations(arena_, invoke); |
| 771 | } |
| 772 | |
| 773 | void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxIntInt(HInvoke* invoke) { |
| 774 | GenMinMax(invoke, /* is_min */ false, GetAssembler()); |
| 775 | } |
| 776 | |
| 777 | void IntrinsicLocationsBuilderARMVIXL::VisitMathSqrt(HInvoke* invoke) { |
| 778 | CreateFPToFPLocations(arena_, invoke); |
| 779 | } |
| 780 | |
| 781 | void IntrinsicCodeGeneratorARMVIXL::VisitMathSqrt(HInvoke* invoke) { |
| 782 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 783 | __ Vsqrt(OutputDRegister(invoke), InputDRegisterAt(invoke, 0)); |
| 784 | } |
| 785 | |
xueliang.zhong | 6099d5e | 2016-04-20 18:44:56 +0100 | [diff] [blame] | 786 | void IntrinsicLocationsBuilderARMVIXL::VisitMathRint(HInvoke* invoke) { |
| 787 | if (features_.HasARMv8AInstructions()) { |
| 788 | CreateFPToFPLocations(arena_, invoke); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | void IntrinsicCodeGeneratorARMVIXL::VisitMathRint(HInvoke* invoke) { |
| 793 | DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions()); |
| 794 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 795 | __ Vrintn(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0)); |
| 796 | } |
| 797 | |
xueliang.zhong | 53463ba | 2017-02-16 15:18:03 +0000 | [diff] [blame] | 798 | void IntrinsicLocationsBuilderARMVIXL::VisitMathRoundFloat(HInvoke* invoke) { |
| 799 | if (features_.HasARMv8AInstructions()) { |
| 800 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 801 | LocationSummary::kNoCall, |
| 802 | kIntrinsified); |
| 803 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 804 | locations->SetOut(Location::RequiresRegister()); |
| 805 | locations->AddTemp(Location::RequiresFpuRegister()); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | void IntrinsicCodeGeneratorARMVIXL::VisitMathRoundFloat(HInvoke* invoke) { |
| 810 | DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions()); |
| 811 | |
| 812 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 813 | vixl32::SRegister in_reg = InputSRegisterAt(invoke, 0); |
| 814 | vixl32::Register out_reg = OutputRegister(invoke); |
| 815 | vixl32::SRegister temp1 = LowSRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 816 | vixl32::SRegister temp2 = HighSRegisterFrom(invoke->GetLocations()->GetTemp(0)); |
| 817 | vixl32::Label done; |
| 818 | vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &done); |
| 819 | |
| 820 | // Round to nearest integer, ties away from zero. |
| 821 | __ Vcvta(S32, F32, temp1, in_reg); |
| 822 | __ Vmov(out_reg, temp1); |
| 823 | |
| 824 | // For positive, zero or NaN inputs, rounding is done. |
| 825 | __ Cmp(out_reg, 0); |
| 826 | __ B(ge, final_label, /* far_target */ false); |
| 827 | |
| 828 | // Handle input < 0 cases. |
| 829 | // If input is negative but not a tie, previous result (round to nearest) is valid. |
| 830 | // If input is a negative tie, change rounding direction to positive infinity, out_reg += 1. |
| 831 | __ Vrinta(F32, F32, temp1, in_reg); |
| 832 | __ Vmov(temp2, 0.5); |
| 833 | __ Vsub(F32, temp1, in_reg, temp1); |
| 834 | __ Vcmp(F32, temp1, temp2); |
| 835 | __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR); |
| 836 | { |
| 837 | // Use ExactAsemblyScope here because we are using IT. |
| 838 | ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(), |
| 839 | 2 * kMaxInstructionSizeInBytes, |
| 840 | CodeBufferCheckScope::kMaximumSize); |
| 841 | __ it(eq); |
| 842 | __ add(eq, out_reg, out_reg, 1); |
| 843 | } |
| 844 | |
| 845 | if (done.IsReferenced()) { |
| 846 | __ Bind(&done); |
| 847 | } |
| 848 | } |
| 849 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 850 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekByte(HInvoke* invoke) { |
| 851 | CreateIntToIntLocations(arena_, invoke); |
| 852 | } |
| 853 | |
| 854 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekByte(HInvoke* invoke) { |
| 855 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 856 | // Ignore upper 4B of long address. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 857 | __ Ldrsb(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 861 | CreateIntToIntLocations(arena_, invoke); |
| 862 | } |
| 863 | |
| 864 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 865 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 866 | // Ignore upper 4B of long address. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 867 | __ Ldr(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 871 | CreateIntToIntLocations(arena_, invoke); |
| 872 | } |
| 873 | |
| 874 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 875 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 876 | // Ignore upper 4B of long address. |
| 877 | vixl32::Register addr = LowRegisterFrom(invoke->GetLocations()->InAt(0)); |
| 878 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 879 | // exception. So we can't use ldrd as addr may be unaligned. |
| 880 | vixl32::Register lo = LowRegisterFrom(invoke->GetLocations()->Out()); |
| 881 | vixl32::Register hi = HighRegisterFrom(invoke->GetLocations()->Out()); |
| 882 | if (addr.Is(lo)) { |
| 883 | __ Ldr(hi, MemOperand(addr, 4)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 884 | __ Ldr(lo, MemOperand(addr)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 885 | } else { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 886 | __ Ldr(lo, MemOperand(addr)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 887 | __ Ldr(hi, MemOperand(addr, 4)); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 892 | CreateIntToIntLocations(arena_, invoke); |
| 893 | } |
| 894 | |
| 895 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 896 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 897 | // Ignore upper 4B of long address. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 898 | __ Ldrsh(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 902 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 903 | LocationSummary::kNoCall, |
| 904 | kIntrinsified); |
| 905 | locations->SetInAt(0, Location::RequiresRegister()); |
| 906 | locations->SetInAt(1, Location::RequiresRegister()); |
| 907 | } |
| 908 | |
| 909 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeByte(HInvoke* invoke) { |
| 910 | CreateIntIntToVoidLocations(arena_, invoke); |
| 911 | } |
| 912 | |
| 913 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeByte(HInvoke* invoke) { |
| 914 | ArmVIXLAssembler* assembler = GetAssembler(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 915 | __ Strb(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 919 | CreateIntIntToVoidLocations(arena_, invoke); |
| 920 | } |
| 921 | |
| 922 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 923 | ArmVIXLAssembler* assembler = GetAssembler(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 924 | __ Str(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 928 | CreateIntIntToVoidLocations(arena_, invoke); |
| 929 | } |
| 930 | |
| 931 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 932 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 933 | // Ignore upper 4B of long address. |
| 934 | vixl32::Register addr = LowRegisterFrom(invoke->GetLocations()->InAt(0)); |
| 935 | // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor |
| 936 | // exception. So we can't use ldrd as addr may be unaligned. |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 937 | __ Str(LowRegisterFrom(invoke->GetLocations()->InAt(1)), MemOperand(addr)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 938 | __ Str(HighRegisterFrom(invoke->GetLocations()->InAt(1)), MemOperand(addr, 4)); |
| 939 | } |
| 940 | |
| 941 | void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 942 | CreateIntIntToVoidLocations(arena_, invoke); |
| 943 | } |
| 944 | |
| 945 | void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 946 | ArmVIXLAssembler* assembler = GetAssembler(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 947 | __ Strh(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0)))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | void IntrinsicLocationsBuilderARMVIXL::VisitThreadCurrentThread(HInvoke* invoke) { |
| 951 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 952 | LocationSummary::kNoCall, |
| 953 | kIntrinsified); |
| 954 | locations->SetOut(Location::RequiresRegister()); |
| 955 | } |
| 956 | |
| 957 | void IntrinsicCodeGeneratorARMVIXL::VisitThreadCurrentThread(HInvoke* invoke) { |
| 958 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 959 | __ Ldr(OutputRegister(invoke), |
| 960 | MemOperand(tr, Thread::PeerOffset<kArmPointerSize>().Int32Value())); |
| 961 | } |
| 962 | |
| 963 | static void GenUnsafeGet(HInvoke* invoke, |
| 964 | Primitive::Type type, |
| 965 | bool is_volatile, |
| 966 | CodeGeneratorARMVIXL* codegen) { |
| 967 | LocationSummary* locations = invoke->GetLocations(); |
| 968 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 969 | Location base_loc = locations->InAt(1); |
| 970 | vixl32::Register base = InputRegisterAt(invoke, 1); // Object pointer. |
| 971 | Location offset_loc = locations->InAt(2); |
| 972 | vixl32::Register offset = LowRegisterFrom(offset_loc); // Long offset, lo part only. |
| 973 | Location trg_loc = locations->Out(); |
| 974 | |
| 975 | switch (type) { |
| 976 | case Primitive::kPrimInt: { |
| 977 | vixl32::Register trg = RegisterFrom(trg_loc); |
| 978 | __ Ldr(trg, MemOperand(base, offset)); |
| 979 | if (is_volatile) { |
| 980 | __ Dmb(vixl32::ISH); |
| 981 | } |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | case Primitive::kPrimNot: { |
| 986 | vixl32::Register trg = RegisterFrom(trg_loc); |
| 987 | if (kEmitCompilerReadBarrier) { |
| 988 | if (kUseBakerReadBarrier) { |
| 989 | Location temp = locations->GetTemp(0); |
| 990 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 991 | invoke, trg_loc, base, 0U, offset_loc, TIMES_1, temp, /* needs_null_check */ false); |
| 992 | if (is_volatile) { |
| 993 | __ Dmb(vixl32::ISH); |
| 994 | } |
| 995 | } else { |
| 996 | __ Ldr(trg, MemOperand(base, offset)); |
| 997 | if (is_volatile) { |
| 998 | __ Dmb(vixl32::ISH); |
| 999 | } |
| 1000 | codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc); |
| 1001 | } |
| 1002 | } else { |
| 1003 | __ Ldr(trg, MemOperand(base, offset)); |
| 1004 | if (is_volatile) { |
| 1005 | __ Dmb(vixl32::ISH); |
| 1006 | } |
| 1007 | assembler->MaybeUnpoisonHeapReference(trg); |
| 1008 | } |
| 1009 | break; |
| 1010 | } |
| 1011 | |
| 1012 | case Primitive::kPrimLong: { |
| 1013 | vixl32::Register trg_lo = LowRegisterFrom(trg_loc); |
| 1014 | vixl32::Register trg_hi = HighRegisterFrom(trg_loc); |
| 1015 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
Artem Serov | 657022c | 2016-11-23 14:19:38 +0000 | [diff] [blame] | 1016 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 1017 | const vixl32::Register temp_reg = temps.Acquire(); |
| 1018 | __ Add(temp_reg, base, offset); |
| 1019 | __ Ldrexd(trg_lo, trg_hi, MemOperand(temp_reg)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1020 | } else { |
| 1021 | __ Ldrd(trg_lo, trg_hi, MemOperand(base, offset)); |
| 1022 | } |
| 1023 | if (is_volatile) { |
| 1024 | __ Dmb(vixl32::ISH); |
| 1025 | } |
| 1026 | break; |
| 1027 | } |
| 1028 | |
| 1029 | default: |
| 1030 | LOG(FATAL) << "Unexpected type " << type; |
| 1031 | UNREACHABLE(); |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, |
| 1036 | HInvoke* invoke, |
| 1037 | Primitive::Type type) { |
| 1038 | bool can_call = kEmitCompilerReadBarrier && |
| 1039 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 1040 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
| 1041 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1042 | (can_call |
| 1043 | ? LocationSummary::kCallOnSlowPath |
| 1044 | : LocationSummary::kNoCall), |
| 1045 | kIntrinsified); |
| 1046 | if (can_call && kUseBakerReadBarrier) { |
| 1047 | locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers. |
| 1048 | } |
| 1049 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1050 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1051 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1052 | locations->SetOut(Location::RequiresRegister(), |
| 1053 | (can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap)); |
| 1054 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1055 | // We need a temporary register for the read barrier marking slow |
| 1056 | // path in InstructionCodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier. |
| 1057 | locations->AddTemp(Location::RequiresRegister()); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGet(HInvoke* invoke) { |
| 1062 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
| 1063 | } |
| 1064 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 1065 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt); |
| 1066 | } |
| 1067 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetLong(HInvoke* invoke) { |
| 1068 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
| 1069 | } |
| 1070 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 1071 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong); |
| 1072 | } |
| 1073 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetObject(HInvoke* invoke) { |
| 1074 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
| 1075 | } |
| 1076 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 1077 | CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot); |
| 1078 | } |
| 1079 | |
| 1080 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGet(HInvoke* invoke) { |
| 1081 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_); |
| 1082 | } |
| 1083 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 1084 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_); |
| 1085 | } |
| 1086 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetLong(HInvoke* invoke) { |
| 1087 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_); |
| 1088 | } |
| 1089 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 1090 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_); |
| 1091 | } |
| 1092 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetObject(HInvoke* invoke) { |
| 1093 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_); |
| 1094 | } |
| 1095 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 1096 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_); |
| 1097 | } |
| 1098 | |
| 1099 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, |
| 1100 | const ArmInstructionSetFeatures& features, |
| 1101 | Primitive::Type type, |
| 1102 | bool is_volatile, |
| 1103 | HInvoke* invoke) { |
| 1104 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1105 | LocationSummary::kNoCall, |
| 1106 | kIntrinsified); |
| 1107 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1108 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1109 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1110 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1111 | |
| 1112 | if (type == Primitive::kPrimLong) { |
| 1113 | // Potentially need temps for ldrexd-strexd loop. |
| 1114 | if (is_volatile && !features.HasAtomicLdrdAndStrd()) { |
| 1115 | locations->AddTemp(Location::RequiresRegister()); // Temp_lo. |
| 1116 | locations->AddTemp(Location::RequiresRegister()); // Temp_hi. |
| 1117 | } |
| 1118 | } else if (type == Primitive::kPrimNot) { |
| 1119 | // Temps for card-marking. |
| 1120 | locations->AddTemp(Location::RequiresRegister()); // Temp. |
| 1121 | locations->AddTemp(Location::RequiresRegister()); // Card. |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePut(HInvoke* invoke) { |
| 1126 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
| 1127 | } |
| 1128 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1129 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke); |
| 1130 | } |
| 1131 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1132 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke); |
| 1133 | } |
| 1134 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObject(HInvoke* invoke) { |
| 1135 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
| 1136 | } |
| 1137 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1138 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke); |
| 1139 | } |
| 1140 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1141 | CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke); |
| 1142 | } |
| 1143 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLong(HInvoke* invoke) { |
| 1144 | CreateIntIntIntIntToVoid( |
| 1145 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
| 1146 | } |
| 1147 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1148 | CreateIntIntIntIntToVoid( |
| 1149 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke); |
| 1150 | } |
| 1151 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1152 | CreateIntIntIntIntToVoid( |
| 1153 | arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke); |
| 1154 | } |
| 1155 | |
| 1156 | static void GenUnsafePut(LocationSummary* locations, |
| 1157 | Primitive::Type type, |
| 1158 | bool is_volatile, |
| 1159 | bool is_ordered, |
| 1160 | CodeGeneratorARMVIXL* codegen) { |
| 1161 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 1162 | |
| 1163 | vixl32::Register base = RegisterFrom(locations->InAt(1)); // Object pointer. |
| 1164 | vixl32::Register offset = LowRegisterFrom(locations->InAt(2)); // Long offset, lo part only. |
| 1165 | vixl32::Register value; |
| 1166 | |
| 1167 | if (is_volatile || is_ordered) { |
| 1168 | __ Dmb(vixl32::ISH); |
| 1169 | } |
| 1170 | |
| 1171 | if (type == Primitive::kPrimLong) { |
| 1172 | vixl32::Register value_lo = LowRegisterFrom(locations->InAt(3)); |
| 1173 | vixl32::Register value_hi = HighRegisterFrom(locations->InAt(3)); |
| 1174 | value = value_lo; |
| 1175 | if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) { |
| 1176 | vixl32::Register temp_lo = RegisterFrom(locations->GetTemp(0)); |
| 1177 | vixl32::Register temp_hi = RegisterFrom(locations->GetTemp(1)); |
| 1178 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 1179 | const vixl32::Register temp_reg = temps.Acquire(); |
| 1180 | |
| 1181 | __ Add(temp_reg, base, offset); |
| 1182 | vixl32::Label loop_head; |
| 1183 | __ Bind(&loop_head); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1184 | __ Ldrexd(temp_lo, temp_hi, MemOperand(temp_reg)); |
| 1185 | __ Strexd(temp_lo, value_lo, value_hi, MemOperand(temp_reg)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1186 | __ Cmp(temp_lo, 0); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1187 | __ B(ne, &loop_head, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1188 | } else { |
| 1189 | __ Strd(value_lo, value_hi, MemOperand(base, offset)); |
| 1190 | } |
| 1191 | } else { |
| 1192 | value = RegisterFrom(locations->InAt(3)); |
| 1193 | vixl32::Register source = value; |
| 1194 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1195 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 1196 | __ Mov(temp, value); |
| 1197 | assembler->PoisonHeapReference(temp); |
| 1198 | source = temp; |
| 1199 | } |
| 1200 | __ Str(source, MemOperand(base, offset)); |
| 1201 | } |
| 1202 | |
| 1203 | if (is_volatile) { |
| 1204 | __ Dmb(vixl32::ISH); |
| 1205 | } |
| 1206 | |
| 1207 | if (type == Primitive::kPrimNot) { |
| 1208 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 1209 | vixl32::Register card = RegisterFrom(locations->GetTemp(1)); |
| 1210 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 1211 | codegen->MarkGCCard(temp, card, base, value, value_can_be_null); |
| 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePut(HInvoke* invoke) { |
| 1216 | GenUnsafePut(invoke->GetLocations(), |
| 1217 | Primitive::kPrimInt, |
| 1218 | /* is_volatile */ false, |
| 1219 | /* is_ordered */ false, |
| 1220 | codegen_); |
| 1221 | } |
| 1222 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 1223 | GenUnsafePut(invoke->GetLocations(), |
| 1224 | Primitive::kPrimInt, |
| 1225 | /* is_volatile */ false, |
| 1226 | /* is_ordered */ true, |
| 1227 | codegen_); |
| 1228 | } |
| 1229 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 1230 | GenUnsafePut(invoke->GetLocations(), |
| 1231 | Primitive::kPrimInt, |
| 1232 | /* is_volatile */ true, |
| 1233 | /* is_ordered */ false, |
| 1234 | codegen_); |
| 1235 | } |
| 1236 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObject(HInvoke* invoke) { |
| 1237 | GenUnsafePut(invoke->GetLocations(), |
| 1238 | Primitive::kPrimNot, |
| 1239 | /* is_volatile */ false, |
| 1240 | /* is_ordered */ false, |
| 1241 | codegen_); |
| 1242 | } |
| 1243 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 1244 | GenUnsafePut(invoke->GetLocations(), |
| 1245 | Primitive::kPrimNot, |
| 1246 | /* is_volatile */ false, |
| 1247 | /* is_ordered */ true, |
| 1248 | codegen_); |
| 1249 | } |
| 1250 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 1251 | GenUnsafePut(invoke->GetLocations(), |
| 1252 | Primitive::kPrimNot, |
| 1253 | /* is_volatile */ true, |
| 1254 | /* is_ordered */ false, |
| 1255 | codegen_); |
| 1256 | } |
| 1257 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLong(HInvoke* invoke) { |
| 1258 | GenUnsafePut(invoke->GetLocations(), |
| 1259 | Primitive::kPrimLong, |
| 1260 | /* is_volatile */ false, |
| 1261 | /* is_ordered */ false, |
| 1262 | codegen_); |
| 1263 | } |
| 1264 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 1265 | GenUnsafePut(invoke->GetLocations(), |
| 1266 | Primitive::kPrimLong, |
| 1267 | /* is_volatile */ false, |
| 1268 | /* is_ordered */ true, |
| 1269 | codegen_); |
| 1270 | } |
| 1271 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 1272 | GenUnsafePut(invoke->GetLocations(), |
| 1273 | Primitive::kPrimLong, |
| 1274 | /* is_volatile */ true, |
| 1275 | /* is_ordered */ false, |
| 1276 | codegen_); |
| 1277 | } |
| 1278 | |
| 1279 | static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena, |
| 1280 | HInvoke* invoke, |
| 1281 | Primitive::Type type) { |
| 1282 | bool can_call = kEmitCompilerReadBarrier && |
| 1283 | kUseBakerReadBarrier && |
| 1284 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeCASObject); |
| 1285 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1286 | (can_call |
| 1287 | ? LocationSummary::kCallOnSlowPath |
| 1288 | : LocationSummary::kNoCall), |
| 1289 | kIntrinsified); |
| 1290 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1291 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1292 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1293 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1294 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1295 | |
| 1296 | // If heap poisoning is enabled, we don't want the unpoisoning |
| 1297 | // operations to potentially clobber the output. Likewise when |
| 1298 | // emitting a (Baker) read barrier, which may call. |
| 1299 | Location::OutputOverlap overlaps = |
| 1300 | ((kPoisonHeapReferences && type == Primitive::kPrimNot) || can_call) |
| 1301 | ? Location::kOutputOverlap |
| 1302 | : Location::kNoOutputOverlap; |
| 1303 | locations->SetOut(Location::RequiresRegister(), overlaps); |
| 1304 | |
| 1305 | // Temporary registers used in CAS. In the object case |
| 1306 | // (UnsafeCASObject intrinsic), these are also used for |
| 1307 | // card-marking, and possibly for (Baker) read barrier. |
| 1308 | locations->AddTemp(Location::RequiresRegister()); // Pointer. |
| 1309 | locations->AddTemp(Location::RequiresRegister()); // Temp 1. |
| 1310 | } |
| 1311 | |
| 1312 | static void GenCas(HInvoke* invoke, Primitive::Type type, CodeGeneratorARMVIXL* codegen) { |
| 1313 | DCHECK_NE(type, Primitive::kPrimLong); |
| 1314 | |
| 1315 | ArmVIXLAssembler* assembler = codegen->GetAssembler(); |
| 1316 | LocationSummary* locations = invoke->GetLocations(); |
| 1317 | |
| 1318 | Location out_loc = locations->Out(); |
| 1319 | vixl32::Register out = OutputRegister(invoke); // Boolean result. |
| 1320 | |
| 1321 | vixl32::Register base = InputRegisterAt(invoke, 1); // Object pointer. |
| 1322 | Location offset_loc = locations->InAt(2); |
| 1323 | vixl32::Register offset = LowRegisterFrom(offset_loc); // Offset (discard high 4B). |
| 1324 | vixl32::Register expected = InputRegisterAt(invoke, 3); // Expected. |
| 1325 | vixl32::Register value = InputRegisterAt(invoke, 4); // Value. |
| 1326 | |
| 1327 | Location tmp_ptr_loc = locations->GetTemp(0); |
| 1328 | vixl32::Register tmp_ptr = RegisterFrom(tmp_ptr_loc); // Pointer to actual memory. |
| 1329 | vixl32::Register tmp = RegisterFrom(locations->GetTemp(1)); // Value in memory. |
| 1330 | |
| 1331 | if (type == Primitive::kPrimNot) { |
| 1332 | // The only read barrier implementation supporting the |
| 1333 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 1334 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
| 1335 | |
| 1336 | // Mark card for object assuming new value is stored. Worst case we will mark an unchanged |
| 1337 | // object and scan the receiver at the next GC for nothing. |
| 1338 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 1339 | codegen->MarkGCCard(tmp_ptr, tmp, base, value, value_can_be_null); |
| 1340 | |
| 1341 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 1342 | // Need to make sure the reference stored in the field is a to-space |
| 1343 | // one before attempting the CAS or the CAS could fail incorrectly. |
| 1344 | codegen->GenerateReferenceLoadWithBakerReadBarrier( |
| 1345 | invoke, |
| 1346 | out_loc, // Unused, used only as a "temporary" within the read barrier. |
| 1347 | base, |
| 1348 | /* offset */ 0u, |
| 1349 | /* index */ offset_loc, |
| 1350 | ScaleFactor::TIMES_1, |
| 1351 | tmp_ptr_loc, |
| 1352 | /* needs_null_check */ false, |
| 1353 | /* always_update_field */ true, |
| 1354 | &tmp); |
| 1355 | } |
| 1356 | } |
| 1357 | |
| 1358 | // Prevent reordering with prior memory operations. |
| 1359 | // Emit a DMB ISH instruction instead of an DMB ISHST one, as the |
| 1360 | // latter allows a preceding load to be delayed past the STXR |
| 1361 | // instruction below. |
| 1362 | __ Dmb(vixl32::ISH); |
| 1363 | |
| 1364 | __ Add(tmp_ptr, base, offset); |
| 1365 | |
| 1366 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1367 | codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1368 | if (value.Is(expected)) { |
| 1369 | // Do not poison `value`, as it is the same register as |
| 1370 | // `expected`, which has just been poisoned. |
| 1371 | } else { |
| 1372 | codegen->GetAssembler()->PoisonHeapReference(value); |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | // do { |
| 1377 | // tmp = [r_ptr] - expected; |
| 1378 | // } while (tmp == 0 && failure([r_ptr] <- r_new_value)); |
| 1379 | // result = tmp != 0; |
| 1380 | |
| 1381 | vixl32::Label loop_head; |
| 1382 | __ Bind(&loop_head); |
| 1383 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1384 | __ Ldrex(tmp, MemOperand(tmp_ptr)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1385 | |
| 1386 | __ Subs(tmp, tmp, expected); |
| 1387 | |
| 1388 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1389 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1390 | 3 * kMaxInstructionSizeInBytes, |
| 1391 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1392 | |
| 1393 | __ itt(eq); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1394 | __ strex(eq, tmp, value, MemOperand(tmp_ptr)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1395 | __ cmp(eq, tmp, 1); |
| 1396 | } |
| 1397 | |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1398 | __ B(eq, &loop_head, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1399 | |
| 1400 | __ Dmb(vixl32::ISH); |
| 1401 | |
| 1402 | __ Rsbs(out, tmp, 1); |
| 1403 | |
| 1404 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1405 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1406 | 2 * kMaxInstructionSizeInBytes, |
| 1407 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1408 | |
| 1409 | __ it(cc); |
| 1410 | __ mov(cc, out, 0); |
| 1411 | } |
| 1412 | |
| 1413 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1414 | codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1415 | if (value.Is(expected)) { |
| 1416 | // Do not unpoison `value`, as it is the same register as |
| 1417 | // `expected`, which has just been unpoisoned. |
| 1418 | } else { |
| 1419 | codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeCASInt(HInvoke* invoke) { |
| 1425 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt); |
| 1426 | } |
| 1427 | void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeCASObject(HInvoke* invoke) { |
| 1428 | // The only read barrier implementation supporting the |
| 1429 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 1430 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
| 1431 | return; |
| 1432 | } |
| 1433 | |
| 1434 | CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot); |
| 1435 | } |
| 1436 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeCASInt(HInvoke* invoke) { |
| 1437 | GenCas(invoke, Primitive::kPrimInt, codegen_); |
| 1438 | } |
| 1439 | void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeCASObject(HInvoke* invoke) { |
| 1440 | // The only read barrier implementation supporting the |
| 1441 | // UnsafeCASObject intrinsic is the Baker-style read barriers. |
| 1442 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
| 1443 | |
| 1444 | GenCas(invoke, Primitive::kPrimNot, codegen_); |
| 1445 | } |
| 1446 | |
| 1447 | void IntrinsicLocationsBuilderARMVIXL::VisitStringCompareTo(HInvoke* invoke) { |
| 1448 | // The inputs plus one temp. |
| 1449 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1450 | invoke->InputAt(1)->CanBeNull() |
| 1451 | ? LocationSummary::kCallOnSlowPath |
| 1452 | : LocationSummary::kNoCall, |
| 1453 | kIntrinsified); |
| 1454 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1455 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1456 | locations->AddTemp(Location::RequiresRegister()); |
| 1457 | locations->AddTemp(Location::RequiresRegister()); |
| 1458 | locations->AddTemp(Location::RequiresRegister()); |
| 1459 | // Need temporary registers for String compression's feature. |
| 1460 | if (mirror::kUseStringCompression) { |
| 1461 | locations->AddTemp(Location::RequiresRegister()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1462 | } |
| 1463 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1464 | } |
| 1465 | |
| 1466 | void IntrinsicCodeGeneratorARMVIXL::VisitStringCompareTo(HInvoke* invoke) { |
| 1467 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 1468 | LocationSummary* locations = invoke->GetLocations(); |
| 1469 | |
| 1470 | vixl32::Register str = InputRegisterAt(invoke, 0); |
| 1471 | vixl32::Register arg = InputRegisterAt(invoke, 1); |
| 1472 | vixl32::Register out = OutputRegister(invoke); |
| 1473 | |
| 1474 | vixl32::Register temp0 = RegisterFrom(locations->GetTemp(0)); |
| 1475 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(1)); |
| 1476 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(2)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1477 | vixl32::Register temp3; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1478 | if (mirror::kUseStringCompression) { |
| 1479 | temp3 = RegisterFrom(locations->GetTemp(3)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | vixl32::Label loop; |
| 1483 | vixl32::Label find_char_diff; |
| 1484 | vixl32::Label end; |
| 1485 | vixl32::Label different_compression; |
| 1486 | |
| 1487 | // Get offsets of count and value fields within a string object. |
| 1488 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1489 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1490 | |
| 1491 | // Note that the null check must have been done earlier. |
| 1492 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1493 | |
| 1494 | // Take slow path and throw if input can be and is null. |
| 1495 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 1496 | const bool can_slow_path = invoke->InputAt(1)->CanBeNull(); |
| 1497 | if (can_slow_path) { |
| 1498 | slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke); |
| 1499 | codegen_->AddSlowPath(slow_path); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1500 | __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | // Reference equality check, return 0 if same reference. |
| 1504 | __ Subs(out, str, arg); |
| 1505 | __ B(eq, &end); |
| 1506 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1507 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1508 | // Load `count` fields of this and argument strings. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1509 | __ Ldr(temp3, MemOperand(str, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1510 | __ Ldr(temp2, MemOperand(arg, count_offset)); |
| 1511 | // Extract lengths from the `count` fields. |
| 1512 | __ Lsr(temp0, temp3, 1u); |
| 1513 | __ Lsr(temp1, temp2, 1u); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1514 | } else { |
| 1515 | // Load lengths of this and argument strings. |
| 1516 | __ Ldr(temp0, MemOperand(str, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1517 | __ Ldr(temp1, MemOperand(arg, count_offset)); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1518 | } |
| 1519 | // out = length diff. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1520 | __ Subs(out, temp0, temp1); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1521 | // temp0 = min(len(str), len(arg)). |
| 1522 | |
| 1523 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1524 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1525 | 2 * kMaxInstructionSizeInBytes, |
| 1526 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1527 | |
| 1528 | __ it(gt); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1529 | __ mov(gt, temp0, temp1); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1530 | } |
| 1531 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1532 | // Shorter string is empty? |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1533 | // Note that mirror::kUseStringCompression==true introduces lots of instructions, |
| 1534 | // which makes &end label far away from this branch and makes it not 'CBZ-encodable'. |
| 1535 | __ CompareAndBranchIfZero(temp0, &end, mirror::kUseStringCompression); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1536 | |
| 1537 | if (mirror::kUseStringCompression) { |
| 1538 | // Check if both strings using same compression style to use this comparison loop. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1539 | __ Eors(temp2, temp2, temp3); |
| 1540 | __ Lsrs(temp2, temp2, 1u); |
| 1541 | __ B(cs, &different_compression); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1542 | // For string compression, calculate the number of bytes to compare (not chars). |
| 1543 | // This could in theory exceed INT32_MAX, so treat temp0 as unsigned. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1544 | __ Lsls(temp3, temp3, 31u); // Extract purely the compression flag. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1545 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1546 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1547 | 2 * kMaxInstructionSizeInBytes, |
| 1548 | CodeBufferCheckScope::kMaximumSize); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1549 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1550 | __ it(ne); |
| 1551 | __ add(ne, temp0, temp0, temp0); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1552 | } |
| 1553 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1554 | // Store offset of string value in preparation for comparison loop. |
| 1555 | __ Mov(temp1, value_offset); |
| 1556 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1557 | // Assertions that must hold in order to compare multiple characters at a time. |
| 1558 | CHECK_ALIGNED(value_offset, 8); |
| 1559 | static_assert(IsAligned<8>(kObjectAlignment), |
| 1560 | "String data must be 8-byte aligned for unrolled CompareTo loop."); |
| 1561 | |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1562 | const unsigned char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1563 | DCHECK_EQ(char_size, 2u); |
| 1564 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1565 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 1566 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1567 | vixl32::Label find_char_diff_2nd_cmp; |
| 1568 | // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment). |
| 1569 | __ Bind(&loop); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1570 | vixl32::Register temp_reg = temps.Acquire(); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1571 | __ Ldr(temp_reg, MemOperand(str, temp1)); |
| 1572 | __ Ldr(temp2, MemOperand(arg, temp1)); |
| 1573 | __ Cmp(temp_reg, temp2); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1574 | __ B(ne, &find_char_diff, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1575 | __ Add(temp1, temp1, char_size * 2); |
| 1576 | |
| 1577 | __ Ldr(temp_reg, MemOperand(str, temp1)); |
| 1578 | __ Ldr(temp2, MemOperand(arg, temp1)); |
| 1579 | __ Cmp(temp_reg, temp2); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1580 | __ B(ne, &find_char_diff_2nd_cmp, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1581 | __ Add(temp1, temp1, char_size * 2); |
| 1582 | // With string compression, we have compared 8 bytes, otherwise 4 chars. |
| 1583 | __ Subs(temp0, temp0, (mirror::kUseStringCompression ? 8 : 4)); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1584 | __ B(hi, &loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1585 | __ B(&end); |
| 1586 | |
| 1587 | __ Bind(&find_char_diff_2nd_cmp); |
| 1588 | if (mirror::kUseStringCompression) { |
| 1589 | __ Subs(temp0, temp0, 4); // 4 bytes previously compared. |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1590 | __ B(ls, &end, /* far_target */ false); // Was the second comparison fully beyond the end? |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1591 | } else { |
| 1592 | // Without string compression, we can start treating temp0 as signed |
| 1593 | // and rely on the signed comparison below. |
| 1594 | __ Sub(temp0, temp0, 2); |
| 1595 | } |
| 1596 | |
| 1597 | // Find the single character difference. |
| 1598 | __ Bind(&find_char_diff); |
| 1599 | // Get the bit position of the first character that differs. |
| 1600 | __ Eor(temp1, temp2, temp_reg); |
| 1601 | __ Rbit(temp1, temp1); |
| 1602 | __ Clz(temp1, temp1); |
| 1603 | |
| 1604 | // temp0 = number of characters remaining to compare. |
| 1605 | // (Without string compression, it could be < 1 if a difference is found by the second CMP |
| 1606 | // in the comparison loop, and after the end of the shorter string data). |
| 1607 | |
| 1608 | // Without string compression (temp1 >> 4) = character where difference occurs between the last |
| 1609 | // two words compared, in the interval [0,1]. |
| 1610 | // (0 for low half-word different, 1 for high half-word different). |
| 1611 | // With string compression, (temp1 << 3) = byte where the difference occurs, |
| 1612 | // in the interval [0,3]. |
| 1613 | |
| 1614 | // If temp0 <= (temp1 >> (kUseStringCompression ? 3 : 4)), the difference occurs outside |
| 1615 | // the remaining string data, so just return length diff (out). |
| 1616 | // The comparison is unsigned for string compression, otherwise signed. |
| 1617 | __ Cmp(temp0, Operand(temp1, vixl32::LSR, (mirror::kUseStringCompression ? 3 : 4))); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1618 | __ B((mirror::kUseStringCompression ? ls : le), &end, /* far_target */ false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1619 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1620 | // Extract the characters and calculate the difference. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1621 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1622 | // For compressed strings we need to clear 0x7 from temp1, for uncompressed we need to clear |
| 1623 | // 0xf. We also need to prepare the character extraction mask `uncompressed ? 0xffffu : 0xffu`. |
| 1624 | // The compression flag is now in the highest bit of temp3, so let's play some tricks. |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1625 | __ Orr(temp3, temp3, 0xffu << 23); // uncompressed ? 0xff800000u : 0x7ff80000u |
| 1626 | __ Bic(temp1, temp1, Operand(temp3, vixl32::LSR, 31 - 3)); // &= ~(uncompressed ? 0xfu : 0x7u) |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1627 | __ Asr(temp3, temp3, 7u); // uncompressed ? 0xffff0000u : 0xff0000u. |
| 1628 | __ Lsr(temp2, temp2, temp1); // Extract second character. |
| 1629 | __ Lsr(temp3, temp3, 16u); // uncompressed ? 0xffffu : 0xffu |
| 1630 | __ Lsr(out, temp_reg, temp1); // Extract first character. |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1631 | __ And(temp2, temp2, temp3); |
| 1632 | __ And(out, out, temp3); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1633 | } else { |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1634 | __ Bic(temp1, temp1, 0xf); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1635 | __ Lsr(temp2, temp2, temp1); |
| 1636 | __ Lsr(out, temp_reg, temp1); |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1637 | __ Movt(temp2, 0); |
| 1638 | __ Movt(out, 0); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1639 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1640 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1641 | __ Sub(out, out, temp2); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1642 | temps.Release(temp_reg); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1643 | |
| 1644 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1645 | __ B(&end); |
| 1646 | __ Bind(&different_compression); |
| 1647 | |
| 1648 | // Comparison for different compression style. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1649 | const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte); |
| 1650 | DCHECK_EQ(c_char_size, 1u); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1651 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1652 | // We want to free up the temp3, currently holding `str.count`, for comparison. |
| 1653 | // So, we move it to the bottom bit of the iteration count `temp0` which we tnen |
| 1654 | // need to treat as unsigned. Start by freeing the bit with an ADD and continue |
| 1655 | // further down by a LSRS+SBC which will flip the meaning of the flag but allow |
| 1656 | // `subs temp0, #2; bhi different_compression_loop` to serve as the loop condition. |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1657 | __ Add(temp0, temp0, temp0); // Unlike LSL, this ADD is always 16-bit. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1658 | // `temp1` will hold the compressed data pointer, `temp2` the uncompressed data pointer. |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1659 | __ Mov(temp1, str); |
| 1660 | __ Mov(temp2, arg); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1661 | __ Lsrs(temp3, temp3, 1u); // Continue the move of the compression flag. |
| 1662 | { |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1663 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1664 | 3 * kMaxInstructionSizeInBytes, |
| 1665 | CodeBufferCheckScope::kMaximumSize); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1666 | __ itt(cs); // Interleave with selection of temp1 and temp2. |
| 1667 | __ mov(cs, temp1, arg); // Preserves flags. |
| 1668 | __ mov(cs, temp2, str); // Preserves flags. |
| 1669 | } |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1670 | __ Sbc(temp0, temp0, 0); // Complete the move of the compression flag. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1671 | |
| 1672 | // Adjust temp1 and temp2 from string pointers to data pointers. |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1673 | __ Add(temp1, temp1, value_offset); |
| 1674 | __ Add(temp2, temp2, value_offset); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1675 | |
| 1676 | vixl32::Label different_compression_loop; |
| 1677 | vixl32::Label different_compression_diff; |
| 1678 | |
| 1679 | // Main loop for different compression. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1680 | temp_reg = temps.Acquire(); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1681 | __ Bind(&different_compression_loop); |
| 1682 | __ Ldrb(temp_reg, MemOperand(temp1, c_char_size, PostIndex)); |
| 1683 | __ Ldrh(temp3, MemOperand(temp2, char_size, PostIndex)); |
Anton Kirilov | b88c484 | 2016-11-14 14:37:00 +0000 | [diff] [blame] | 1684 | __ Cmp(temp_reg, temp3); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1685 | __ B(ne, &different_compression_diff, /* far_target */ false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1686 | __ Subs(temp0, temp0, 2); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1687 | __ B(hi, &different_compression_loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1688 | __ B(&end); |
| 1689 | |
| 1690 | // Calculate the difference. |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1691 | __ Bind(&different_compression_diff); |
| 1692 | __ Sub(out, temp_reg, temp3); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1693 | temps.Release(temp_reg); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1694 | // Flip the difference if the `arg` is compressed. |
| 1695 | // `temp0` contains inverted `str` compression flag, i.e the same as `arg` compression flag. |
| 1696 | __ Lsrs(temp0, temp0, 1u); |
| 1697 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1698 | "Expecting 0=compressed, 1=uncompressed"); |
| 1699 | |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1700 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1701 | 2 * kMaxInstructionSizeInBytes, |
| 1702 | CodeBufferCheckScope::kMaximumSize); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1703 | __ it(cc); |
| 1704 | __ rsb(cc, out, out, 0); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | __ Bind(&end); |
| 1708 | |
| 1709 | if (can_slow_path) { |
| 1710 | __ Bind(slow_path->GetExitLabel()); |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | void IntrinsicLocationsBuilderARMVIXL::VisitStringEquals(HInvoke* invoke) { |
| 1715 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1716 | LocationSummary::kNoCall, |
| 1717 | kIntrinsified); |
| 1718 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1719 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1720 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1721 | // Temporary registers to store lengths of strings and for calculations. |
| 1722 | // Using instruction cbz requires a low register, so explicitly set a temp to be R0. |
| 1723 | locations->AddTemp(LocationFrom(r0)); |
| 1724 | locations->AddTemp(Location::RequiresRegister()); |
| 1725 | locations->AddTemp(Location::RequiresRegister()); |
| 1726 | |
| 1727 | locations->SetOut(Location::RequiresRegister()); |
| 1728 | } |
| 1729 | |
| 1730 | void IntrinsicCodeGeneratorARMVIXL::VisitStringEquals(HInvoke* invoke) { |
| 1731 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 1732 | LocationSummary* locations = invoke->GetLocations(); |
| 1733 | |
| 1734 | vixl32::Register str = InputRegisterAt(invoke, 0); |
| 1735 | vixl32::Register arg = InputRegisterAt(invoke, 1); |
| 1736 | vixl32::Register out = OutputRegister(invoke); |
| 1737 | |
| 1738 | vixl32::Register temp = RegisterFrom(locations->GetTemp(0)); |
| 1739 | vixl32::Register temp1 = RegisterFrom(locations->GetTemp(1)); |
| 1740 | vixl32::Register temp2 = RegisterFrom(locations->GetTemp(2)); |
| 1741 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1742 | vixl32::Label loop; |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1743 | vixl32::Label end; |
| 1744 | vixl32::Label return_true; |
| 1745 | vixl32::Label return_false; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1746 | vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &end); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1747 | |
| 1748 | // Get offsets of count, value, and class fields within a string object. |
| 1749 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 1750 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1751 | const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value(); |
| 1752 | |
| 1753 | // Note that the null check must have been done earlier. |
| 1754 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1755 | |
| 1756 | StringEqualsOptimizations optimizations(invoke); |
| 1757 | if (!optimizations.GetArgumentNotNull()) { |
| 1758 | // Check if input is null, return false if it is. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1759 | __ CompareAndBranchIfZero(arg, &return_false, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1760 | } |
| 1761 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1762 | // Reference equality check, return true if same reference. |
| 1763 | __ Cmp(str, arg); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1764 | __ B(eq, &return_true, /* far_target */ false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1765 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1766 | if (!optimizations.GetArgumentIsString()) { |
| 1767 | // Instanceof check for the argument by comparing class fields. |
| 1768 | // All string objects must have the same type since String cannot be subclassed. |
| 1769 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1770 | // If the argument is a string object, its class field must be equal to receiver's class field. |
| 1771 | __ Ldr(temp, MemOperand(str, class_offset)); |
| 1772 | __ Ldr(temp1, MemOperand(arg, class_offset)); |
| 1773 | __ Cmp(temp, temp1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1774 | __ B(ne, &return_false, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1775 | } |
| 1776 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1777 | // Load `count` fields of this and argument strings. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1778 | __ Ldr(temp, MemOperand(str, count_offset)); |
| 1779 | __ Ldr(temp1, MemOperand(arg, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1780 | // Check if `count` fields are equal, return false if they're not. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1781 | // Also compares the compression style, if differs return false. |
| 1782 | __ Cmp(temp, temp1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1783 | __ B(ne, &return_false, /* far_target */ false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1784 | // Return true if both strings are empty. Even with string compression `count == 0` means empty. |
| 1785 | static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u, |
| 1786 | "Expecting 0=compressed, 1=uncompressed"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 1787 | __ CompareAndBranchIfZero(temp, &return_true, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1788 | |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1789 | // Assertions that must hold in order to compare strings 4 bytes at a time. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1790 | DCHECK_ALIGNED(value_offset, 4); |
| 1791 | static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare."); |
| 1792 | |
| 1793 | if (mirror::kUseStringCompression) { |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1794 | // For string compression, calculate the number of bytes to compare (not chars). |
| 1795 | // This could in theory exceed INT32_MAX, so treat temp as unsigned. |
| 1796 | __ Lsrs(temp, temp, 1u); // Extract length and check compression flag. |
Artem Serov | 0fb3719 | 2016-12-06 18:13:40 +0000 | [diff] [blame] | 1797 | ExactAssemblyScope aas(assembler->GetVIXLAssembler(), |
| 1798 | 2 * kMaxInstructionSizeInBytes, |
| 1799 | CodeBufferCheckScope::kMaximumSize); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1800 | __ it(cs); // If uncompressed, |
| 1801 | __ add(cs, temp, temp, temp); // double the byte count. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1802 | } |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1803 | |
| 1804 | // Store offset of string value in preparation for comparison loop. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1805 | __ Mov(temp1, value_offset); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1806 | |
| 1807 | // Loop to compare strings 4 bytes at a time starting at the front of the string. |
| 1808 | // Ok to do this because strings are zero-padded to kObjectAlignment. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1809 | __ Bind(&loop); |
| 1810 | __ Ldr(out, MemOperand(str, temp1)); |
| 1811 | __ Ldr(temp2, MemOperand(arg, temp1)); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 1812 | __ Add(temp1, temp1, Operand::From(sizeof(uint32_t))); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1813 | __ Cmp(out, temp2); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1814 | __ B(ne, &return_false, /* far_target */ false); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 1815 | // With string compression, we have compared 4 bytes, otherwise 2 chars. |
| 1816 | __ Subs(temp, temp, mirror::kUseStringCompression ? 4 : 2); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 1817 | __ B(hi, &loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1818 | |
| 1819 | // Return true and exit the function. |
| 1820 | // If loop does not result in returning false, we return true. |
| 1821 | __ Bind(&return_true); |
| 1822 | __ Mov(out, 1); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1823 | __ B(final_label); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1824 | |
| 1825 | // Return false and exit the function. |
| 1826 | __ Bind(&return_false); |
| 1827 | __ Mov(out, 0); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 1828 | |
| 1829 | if (end.IsReferenced()) { |
| 1830 | __ Bind(&end); |
| 1831 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | static void GenerateVisitStringIndexOf(HInvoke* invoke, |
| 1835 | ArmVIXLAssembler* assembler, |
| 1836 | CodeGeneratorARMVIXL* codegen, |
| 1837 | ArenaAllocator* allocator, |
| 1838 | bool start_at_zero) { |
| 1839 | LocationSummary* locations = invoke->GetLocations(); |
| 1840 | |
| 1841 | // Note that the null check must have been done earlier. |
| 1842 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1843 | |
| 1844 | // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically, |
| 1845 | // or directly dispatch for a large constant, or omit slow-path for a small constant or a char. |
| 1846 | SlowPathCodeARMVIXL* slow_path = nullptr; |
| 1847 | HInstruction* code_point = invoke->InputAt(1); |
| 1848 | if (code_point->IsIntConstant()) { |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 1849 | if (static_cast<uint32_t>(Int32ConstantFrom(code_point)) > |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 1850 | std::numeric_limits<uint16_t>::max()) { |
| 1851 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1852 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
| 1853 | slow_path = new (allocator) IntrinsicSlowPathARMVIXL(invoke); |
| 1854 | codegen->AddSlowPath(slow_path); |
| 1855 | __ B(slow_path->GetEntryLabel()); |
| 1856 | __ Bind(slow_path->GetExitLabel()); |
| 1857 | return; |
| 1858 | } |
| 1859 | } else if (code_point->GetType() != Primitive::kPrimChar) { |
| 1860 | vixl32::Register char_reg = InputRegisterAt(invoke, 1); |
| 1861 | // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`. |
| 1862 | __ Cmp(char_reg, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1); |
| 1863 | slow_path = new (allocator) IntrinsicSlowPathARMVIXL(invoke); |
| 1864 | codegen->AddSlowPath(slow_path); |
| 1865 | __ B(hs, slow_path->GetEntryLabel()); |
| 1866 | } |
| 1867 | |
| 1868 | if (start_at_zero) { |
| 1869 | vixl32::Register tmp_reg = RegisterFrom(locations->GetTemp(0)); |
| 1870 | DCHECK(tmp_reg.Is(r2)); |
| 1871 | // Start-index = 0. |
| 1872 | __ Mov(tmp_reg, 0); |
| 1873 | } |
| 1874 | |
| 1875 | codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path); |
| 1876 | CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>(); |
| 1877 | |
| 1878 | if (slow_path != nullptr) { |
| 1879 | __ Bind(slow_path->GetExitLabel()); |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | void IntrinsicLocationsBuilderARMVIXL::VisitStringIndexOf(HInvoke* invoke) { |
| 1884 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1885 | LocationSummary::kCallOnMainAndSlowPath, |
| 1886 | kIntrinsified); |
| 1887 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1888 | // best to align the inputs accordingly. |
| 1889 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1890 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1891 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1892 | locations->SetOut(LocationFrom(r0)); |
| 1893 | |
| 1894 | // Need to send start-index=0. |
| 1895 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1896 | } |
| 1897 | |
| 1898 | void IntrinsicCodeGeneratorARMVIXL::VisitStringIndexOf(HInvoke* invoke) { |
| 1899 | GenerateVisitStringIndexOf( |
| 1900 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true); |
| 1901 | } |
| 1902 | |
| 1903 | void IntrinsicLocationsBuilderARMVIXL::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1904 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1905 | LocationSummary::kCallOnMainAndSlowPath, |
| 1906 | kIntrinsified); |
| 1907 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1908 | // best to align the inputs accordingly. |
| 1909 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1910 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1911 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1912 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1913 | locations->SetOut(LocationFrom(r0)); |
| 1914 | } |
| 1915 | |
| 1916 | void IntrinsicCodeGeneratorARMVIXL::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1917 | GenerateVisitStringIndexOf( |
| 1918 | invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false); |
| 1919 | } |
| 1920 | |
| 1921 | void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1922 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1923 | LocationSummary::kCallOnMainAndSlowPath, |
| 1924 | kIntrinsified); |
| 1925 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1926 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1927 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1928 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1929 | locations->SetInAt(3, LocationFrom(calling_convention.GetRegisterAt(3))); |
| 1930 | locations->SetOut(LocationFrom(r0)); |
| 1931 | } |
| 1932 | |
| 1933 | void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1934 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 1935 | vixl32::Register byte_array = InputRegisterAt(invoke, 0); |
| 1936 | __ Cmp(byte_array, 0); |
| 1937 | SlowPathCodeARMVIXL* slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke); |
| 1938 | codegen_->AddSlowPath(slow_path); |
| 1939 | __ B(eq, slow_path->GetEntryLabel()); |
| 1940 | |
| 1941 | codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path); |
| 1942 | CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>(); |
| 1943 | __ Bind(slow_path->GetExitLabel()); |
| 1944 | } |
| 1945 | |
| 1946 | void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1947 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1948 | LocationSummary::kCallOnMainOnly, |
| 1949 | kIntrinsified); |
| 1950 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1951 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1952 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1953 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1954 | locations->SetOut(LocationFrom(r0)); |
| 1955 | } |
| 1956 | |
| 1957 | void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1958 | // No need to emit code checking whether `locations->InAt(2)` is a null |
| 1959 | // pointer, as callers of the native method |
| 1960 | // |
| 1961 | // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data) |
| 1962 | // |
| 1963 | // all include a null check on `data` before calling that method. |
| 1964 | codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc()); |
| 1965 | CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>(); |
| 1966 | } |
| 1967 | |
| 1968 | void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1969 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1970 | LocationSummary::kCallOnMainAndSlowPath, |
| 1971 | kIntrinsified); |
| 1972 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 1973 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1974 | locations->SetOut(LocationFrom(r0)); |
| 1975 | } |
| 1976 | |
| 1977 | void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1978 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 1979 | vixl32::Register string_to_copy = InputRegisterAt(invoke, 0); |
| 1980 | __ Cmp(string_to_copy, 0); |
| 1981 | SlowPathCodeARMVIXL* slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke); |
| 1982 | codegen_->AddSlowPath(slow_path); |
| 1983 | __ B(eq, slow_path->GetEntryLabel()); |
| 1984 | |
| 1985 | codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc(), slow_path); |
| 1986 | CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>(); |
| 1987 | |
| 1988 | __ Bind(slow_path->GetExitLabel()); |
| 1989 | } |
| 1990 | |
| 1991 | void IntrinsicLocationsBuilderARMVIXL::VisitSystemArrayCopy(HInvoke* invoke) { |
| 1992 | // The only read barrier implementation supporting the |
| 1993 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 1994 | if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) { |
| 1995 | return; |
| 1996 | } |
| 1997 | |
| 1998 | CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke); |
| 1999 | LocationSummary* locations = invoke->GetLocations(); |
| 2000 | if (locations == nullptr) { |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 2005 | HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant(); |
| 2006 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 2007 | |
| 2008 | if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) { |
| 2009 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2010 | } |
| 2011 | if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) { |
| 2012 | locations->SetInAt(3, Location::RequiresRegister()); |
| 2013 | } |
| 2014 | if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) { |
| 2015 | locations->SetInAt(4, Location::RequiresRegister()); |
| 2016 | } |
| 2017 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2018 | // Temporary register IP cannot be used in |
| 2019 | // ReadBarrierSystemArrayCopySlowPathARM (because that register |
| 2020 | // is clobbered by ReadBarrierMarkRegX entry points). Get an extra |
| 2021 | // temporary register from the register allocator. |
| 2022 | locations->AddTemp(Location::RequiresRegister()); |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | static void CheckPosition(ArmVIXLAssembler* assembler, |
| 2027 | Location pos, |
| 2028 | vixl32::Register input, |
| 2029 | Location length, |
| 2030 | SlowPathCodeARMVIXL* slow_path, |
| 2031 | vixl32::Register temp, |
| 2032 | bool length_is_input_length = false) { |
| 2033 | // Where is the length in the Array? |
| 2034 | const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value(); |
| 2035 | |
| 2036 | if (pos.IsConstant()) { |
| 2037 | int32_t pos_const = Int32ConstantFrom(pos); |
| 2038 | if (pos_const == 0) { |
| 2039 | if (!length_is_input_length) { |
| 2040 | // Check that length(input) >= length. |
| 2041 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 2042 | if (length.IsConstant()) { |
| 2043 | __ Cmp(temp, Int32ConstantFrom(length)); |
| 2044 | } else { |
| 2045 | __ Cmp(temp, RegisterFrom(length)); |
| 2046 | } |
| 2047 | __ B(lt, slow_path->GetEntryLabel()); |
| 2048 | } |
| 2049 | } else { |
| 2050 | // Check that length(input) >= pos. |
| 2051 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 2052 | __ Subs(temp, temp, pos_const); |
| 2053 | __ B(lt, slow_path->GetEntryLabel()); |
| 2054 | |
| 2055 | // Check that (length(input) - pos) >= length. |
| 2056 | if (length.IsConstant()) { |
| 2057 | __ Cmp(temp, Int32ConstantFrom(length)); |
| 2058 | } else { |
| 2059 | __ Cmp(temp, RegisterFrom(length)); |
| 2060 | } |
| 2061 | __ B(lt, slow_path->GetEntryLabel()); |
| 2062 | } |
| 2063 | } else if (length_is_input_length) { |
| 2064 | // The only way the copy can succeed is if pos is zero. |
| 2065 | vixl32::Register pos_reg = RegisterFrom(pos); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2066 | __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2067 | } else { |
| 2068 | // Check that pos >= 0. |
| 2069 | vixl32::Register pos_reg = RegisterFrom(pos); |
| 2070 | __ Cmp(pos_reg, 0); |
| 2071 | __ B(lt, slow_path->GetEntryLabel()); |
| 2072 | |
| 2073 | // Check that pos <= length(input). |
| 2074 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 2075 | __ Subs(temp, temp, pos_reg); |
| 2076 | __ B(lt, slow_path->GetEntryLabel()); |
| 2077 | |
| 2078 | // Check that (length(input) - pos) >= length. |
| 2079 | if (length.IsConstant()) { |
| 2080 | __ Cmp(temp, Int32ConstantFrom(length)); |
| 2081 | } else { |
| 2082 | __ Cmp(temp, RegisterFrom(length)); |
| 2083 | } |
| 2084 | __ B(lt, slow_path->GetEntryLabel()); |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | void IntrinsicCodeGeneratorARMVIXL::VisitSystemArrayCopy(HInvoke* invoke) { |
| 2089 | // The only read barrier implementation supporting the |
| 2090 | // SystemArrayCopy intrinsic is the Baker-style read barriers. |
| 2091 | DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier); |
| 2092 | |
| 2093 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2094 | LocationSummary* locations = invoke->GetLocations(); |
| 2095 | |
| 2096 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2097 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2098 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2099 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2100 | uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value(); |
| 2101 | |
| 2102 | vixl32::Register src = InputRegisterAt(invoke, 0); |
| 2103 | Location src_pos = locations->InAt(1); |
| 2104 | vixl32::Register dest = InputRegisterAt(invoke, 2); |
| 2105 | Location dest_pos = locations->InAt(3); |
| 2106 | Location length = locations->InAt(4); |
| 2107 | Location temp1_loc = locations->GetTemp(0); |
| 2108 | vixl32::Register temp1 = RegisterFrom(temp1_loc); |
| 2109 | Location temp2_loc = locations->GetTemp(1); |
| 2110 | vixl32::Register temp2 = RegisterFrom(temp2_loc); |
| 2111 | Location temp3_loc = locations->GetTemp(2); |
| 2112 | vixl32::Register temp3 = RegisterFrom(temp3_loc); |
| 2113 | |
| 2114 | SlowPathCodeARMVIXL* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke); |
| 2115 | codegen_->AddSlowPath(intrinsic_slow_path); |
| 2116 | |
| 2117 | vixl32::Label conditions_on_positions_validated; |
| 2118 | SystemArrayCopyOptimizations optimizations(invoke); |
| 2119 | |
| 2120 | // If source and destination are the same, we go to slow path if we need to do |
| 2121 | // forward copying. |
| 2122 | if (src_pos.IsConstant()) { |
| 2123 | int32_t src_pos_constant = Int32ConstantFrom(src_pos); |
| 2124 | if (dest_pos.IsConstant()) { |
| 2125 | int32_t dest_pos_constant = Int32ConstantFrom(dest_pos); |
| 2126 | if (optimizations.GetDestinationIsSource()) { |
| 2127 | // Checked when building locations. |
| 2128 | DCHECK_GE(src_pos_constant, dest_pos_constant); |
| 2129 | } else if (src_pos_constant < dest_pos_constant) { |
| 2130 | __ Cmp(src, dest); |
| 2131 | __ B(eq, intrinsic_slow_path->GetEntryLabel()); |
| 2132 | } |
| 2133 | |
| 2134 | // Checked when building locations. |
| 2135 | DCHECK(!optimizations.GetDestinationIsSource() |
| 2136 | || (src_pos_constant >= Int32ConstantFrom(dest_pos))); |
| 2137 | } else { |
| 2138 | if (!optimizations.GetDestinationIsSource()) { |
| 2139 | __ Cmp(src, dest); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2140 | __ B(ne, &conditions_on_positions_validated, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2141 | } |
| 2142 | __ Cmp(RegisterFrom(dest_pos), src_pos_constant); |
| 2143 | __ B(gt, intrinsic_slow_path->GetEntryLabel()); |
| 2144 | } |
| 2145 | } else { |
| 2146 | if (!optimizations.GetDestinationIsSource()) { |
| 2147 | __ Cmp(src, dest); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2148 | __ B(ne, &conditions_on_positions_validated, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2149 | } |
| 2150 | if (dest_pos.IsConstant()) { |
| 2151 | int32_t dest_pos_constant = Int32ConstantFrom(dest_pos); |
| 2152 | __ Cmp(RegisterFrom(src_pos), dest_pos_constant); |
| 2153 | } else { |
| 2154 | __ Cmp(RegisterFrom(src_pos), RegisterFrom(dest_pos)); |
| 2155 | } |
| 2156 | __ B(lt, intrinsic_slow_path->GetEntryLabel()); |
| 2157 | } |
| 2158 | |
| 2159 | __ Bind(&conditions_on_positions_validated); |
| 2160 | |
| 2161 | if (!optimizations.GetSourceIsNotNull()) { |
| 2162 | // Bail out if the source is null. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2163 | __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) { |
| 2167 | // Bail out if the destination is null. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2168 | __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | // If the length is negative, bail out. |
| 2172 | // We have already checked in the LocationsBuilder for the constant case. |
| 2173 | if (!length.IsConstant() && |
| 2174 | !optimizations.GetCountIsSourceLength() && |
| 2175 | !optimizations.GetCountIsDestinationLength()) { |
| 2176 | __ Cmp(RegisterFrom(length), 0); |
| 2177 | __ B(lt, intrinsic_slow_path->GetEntryLabel()); |
| 2178 | } |
| 2179 | |
| 2180 | // Validity checks: source. |
| 2181 | CheckPosition(assembler, |
| 2182 | src_pos, |
| 2183 | src, |
| 2184 | length, |
| 2185 | intrinsic_slow_path, |
| 2186 | temp1, |
| 2187 | optimizations.GetCountIsSourceLength()); |
| 2188 | |
| 2189 | // Validity checks: dest. |
| 2190 | CheckPosition(assembler, |
| 2191 | dest_pos, |
| 2192 | dest, |
| 2193 | length, |
| 2194 | intrinsic_slow_path, |
| 2195 | temp1, |
| 2196 | optimizations.GetCountIsDestinationLength()); |
| 2197 | |
| 2198 | if (!optimizations.GetDoesNotNeedTypeCheck()) { |
| 2199 | // Check whether all elements of the source array are assignable to the component |
| 2200 | // type of the destination array. We do two checks: the classes are the same, |
| 2201 | // or the destination is Object[]. If none of these checks succeed, we go to the |
| 2202 | // slow path. |
| 2203 | |
| 2204 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2205 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2206 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2207 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2208 | invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false); |
| 2209 | // Bail out if the source is not a non primitive array. |
| 2210 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2211 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2212 | invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2213 | __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2214 | // If heap poisoning is enabled, `temp1` has been unpoisoned |
| 2215 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2216 | // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_); |
| 2217 | __ Ldrh(temp1, MemOperand(temp1, primitive_offset)); |
| 2218 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2219 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 2223 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2224 | invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false); |
| 2225 | |
| 2226 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 2227 | // Bail out if the destination is not a non primitive array. |
| 2228 | // |
| 2229 | // Register `temp1` is not trashed by the read barrier emitted |
| 2230 | // by GenerateFieldLoadWithBakerReadBarrier below, as that |
| 2231 | // method produces a call to a ReadBarrierMarkRegX entry point, |
| 2232 | // which saves all potentially live registers, including |
| 2233 | // temporaries such a `temp1`. |
| 2234 | // /* HeapReference<Class> */ temp2 = temp1->component_type_ |
| 2235 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2236 | invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2237 | __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2238 | // If heap poisoning is enabled, `temp2` has been unpoisoned |
| 2239 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2240 | // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_); |
| 2241 | __ Ldrh(temp2, MemOperand(temp2, primitive_offset)); |
| 2242 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2243 | __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | // For the same reason given earlier, `temp1` is not trashed by the |
| 2247 | // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below. |
| 2248 | // /* HeapReference<Class> */ temp2 = src->klass_ |
| 2249 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2250 | invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false); |
| 2251 | // Note: if heap poisoning is on, we are comparing two unpoisoned references here. |
| 2252 | __ Cmp(temp1, temp2); |
| 2253 | |
| 2254 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 2255 | vixl32::Label do_copy; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2256 | __ B(eq, &do_copy, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2257 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2258 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2259 | invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
| 2260 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2261 | // We do not need to emit a read barrier for the following |
| 2262 | // heap reference load, as `temp1` is only used in a |
| 2263 | // comparison with null below, and this reference is not |
| 2264 | // kept afterwards. |
| 2265 | __ Ldr(temp1, MemOperand(temp1, super_offset)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2266 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2267 | __ Bind(&do_copy); |
| 2268 | } else { |
| 2269 | __ B(ne, intrinsic_slow_path->GetEntryLabel()); |
| 2270 | } |
| 2271 | } else { |
| 2272 | // Non read barrier code. |
| 2273 | |
| 2274 | // /* HeapReference<Class> */ temp1 = dest->klass_ |
| 2275 | __ Ldr(temp1, MemOperand(dest, class_offset)); |
| 2276 | // /* HeapReference<Class> */ temp2 = src->klass_ |
| 2277 | __ Ldr(temp2, MemOperand(src, class_offset)); |
| 2278 | bool did_unpoison = false; |
| 2279 | if (!optimizations.GetDestinationIsNonPrimitiveArray() || |
| 2280 | !optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2281 | // One or two of the references need to be unpoisoned. Unpoison them |
| 2282 | // both to make the identity check valid. |
| 2283 | assembler->MaybeUnpoisonHeapReference(temp1); |
| 2284 | assembler->MaybeUnpoisonHeapReference(temp2); |
| 2285 | did_unpoison = true; |
| 2286 | } |
| 2287 | |
| 2288 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 2289 | // Bail out if the destination is not a non primitive array. |
| 2290 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 2291 | __ Ldr(temp3, MemOperand(temp1, component_offset)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2292 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2293 | assembler->MaybeUnpoisonHeapReference(temp3); |
| 2294 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
| 2295 | __ Ldrh(temp3, MemOperand(temp3, primitive_offset)); |
| 2296 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2297 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2301 | // Bail out if the source is not a non primitive array. |
| 2302 | // /* HeapReference<Class> */ temp3 = temp2->component_type_ |
| 2303 | __ Ldr(temp3, MemOperand(temp2, component_offset)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2304 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2305 | assembler->MaybeUnpoisonHeapReference(temp3); |
| 2306 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
| 2307 | __ Ldrh(temp3, MemOperand(temp3, primitive_offset)); |
| 2308 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2309 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
| 2312 | __ Cmp(temp1, temp2); |
| 2313 | |
| 2314 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
| 2315 | vixl32::Label do_copy; |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2316 | __ B(eq, &do_copy, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2317 | if (!did_unpoison) { |
| 2318 | assembler->MaybeUnpoisonHeapReference(temp1); |
| 2319 | } |
| 2320 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2321 | __ Ldr(temp1, MemOperand(temp1, component_offset)); |
| 2322 | assembler->MaybeUnpoisonHeapReference(temp1); |
| 2323 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2324 | __ Ldr(temp1, MemOperand(temp1, super_offset)); |
| 2325 | // No need to unpoison the result, we're comparing against null. |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2326 | __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2327 | __ Bind(&do_copy); |
| 2328 | } else { |
| 2329 | __ B(ne, intrinsic_slow_path->GetEntryLabel()); |
| 2330 | } |
| 2331 | } |
| 2332 | } else if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2333 | DCHECK(optimizations.GetDestinationIsNonPrimitiveArray()); |
| 2334 | // Bail out if the source is not a non primitive array. |
| 2335 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2336 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2337 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2338 | invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false); |
| 2339 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 2340 | codegen_->GenerateFieldLoadWithBakerReadBarrier( |
| 2341 | invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2342 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2343 | // If heap poisoning is enabled, `temp3` has been unpoisoned |
| 2344 | // by the the previous call to GenerateFieldLoadWithBakerReadBarrier. |
| 2345 | } else { |
| 2346 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2347 | __ Ldr(temp1, MemOperand(src, class_offset)); |
| 2348 | assembler->MaybeUnpoisonHeapReference(temp1); |
| 2349 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 2350 | __ Ldr(temp3, MemOperand(temp1, component_offset)); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2351 | __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2352 | assembler->MaybeUnpoisonHeapReference(temp3); |
| 2353 | } |
| 2354 | // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_); |
| 2355 | __ Ldrh(temp3, MemOperand(temp3, primitive_offset)); |
| 2356 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
xueliang.zhong | f51bc62 | 2016-11-04 09:23:32 +0000 | [diff] [blame] | 2357 | __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel()); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
Roland Levillain | 1663d16 | 2017-03-17 15:15:21 +0000 | [diff] [blame] | 2360 | if (length.IsConstant() && Int32ConstantFrom(length) == 0) { |
| 2361 | // Null constant length: not need to emit the loop code at all. |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2362 | } else { |
Roland Levillain | 1663d16 | 2017-03-17 15:15:21 +0000 | [diff] [blame] | 2363 | vixl32::Label done; |
| 2364 | const Primitive::Type type = Primitive::kPrimNot; |
| 2365 | const int32_t element_size = Primitive::ComponentSize(type); |
| 2366 | |
| 2367 | if (length.IsRegister()) { |
| 2368 | // Don't enter the copy loop if the length is null. |
| 2369 | __ CompareAndBranchIfZero(RegisterFrom(length), &done, /* is_far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2370 | } |
Roland Levillain | 1663d16 | 2017-03-17 15:15:21 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 2373 | // TODO: Also convert this intrinsic to the IsGcMarking strategy? |
| 2374 | |
| 2375 | // SystemArrayCopy implementation for Baker read barriers (see |
| 2376 | // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier): |
| 2377 | // |
| 2378 | // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState(); |
| 2379 | // lfence; // Load fence or artificial data dependency to prevent load-load reordering |
| 2380 | // bool is_gray = (rb_state == ReadBarrier::GrayState()); |
| 2381 | // if (is_gray) { |
| 2382 | // // Slow-path copy. |
| 2383 | // do { |
| 2384 | // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++))); |
| 2385 | // } while (src_ptr != end_ptr) |
| 2386 | // } else { |
| 2387 | // // Fast-path copy. |
| 2388 | // do { |
| 2389 | // *dest_ptr++ = *src_ptr++; |
| 2390 | // } while (src_ptr != end_ptr) |
| 2391 | // } |
| 2392 | |
| 2393 | // /* int32_t */ monitor = src->monitor_ |
| 2394 | __ Ldr(temp2, MemOperand(src, monitor_offset)); |
| 2395 | // /* LockWord */ lock_word = LockWord(monitor) |
| 2396 | static_assert(sizeof(LockWord) == sizeof(int32_t), |
| 2397 | "art::LockWord and int32_t have different sizes."); |
| 2398 | |
| 2399 | // Introduce a dependency on the lock_word including the rb_state, |
| 2400 | // which shall prevent load-load reordering without using |
| 2401 | // a memory barrier (which would be more expensive). |
| 2402 | // `src` is unchanged by this operation, but its value now depends |
| 2403 | // on `temp2`. |
| 2404 | __ Add(src, src, Operand(temp2, vixl32::LSR, 32)); |
| 2405 | |
| 2406 | // Compute the base source address in `temp1`. |
| 2407 | // Note that `temp1` (the base source address) is computed from |
| 2408 | // `src` (and `src_pos`) here, and thus honors the artificial |
| 2409 | // dependency of `src` on `temp2`. |
| 2410 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, src, src_pos, temp1); |
| 2411 | // Compute the end source address in `temp3`. |
| 2412 | GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3); |
| 2413 | // The base destination address is computed later, as `temp2` is |
| 2414 | // used for intermediate computations. |
| 2415 | |
| 2416 | // Slow path used to copy array when `src` is gray. |
| 2417 | // Note that the base destination address is computed in `temp2` |
| 2418 | // by the slow path code. |
| 2419 | SlowPathCodeARMVIXL* read_barrier_slow_path = |
| 2420 | new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARMVIXL(invoke); |
| 2421 | codegen_->AddSlowPath(read_barrier_slow_path); |
| 2422 | |
| 2423 | // Given the numeric representation, it's enough to check the low bit of the |
| 2424 | // rb_state. We do that by shifting the bit out of the lock word with LSRS |
| 2425 | // which can be a 16-bit instruction unlike the TST immediate. |
| 2426 | static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0"); |
| 2427 | static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1"); |
| 2428 | __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1); |
| 2429 | // Carry flag is the last bit shifted out by LSRS. |
| 2430 | __ B(cs, read_barrier_slow_path->GetEntryLabel()); |
| 2431 | |
| 2432 | // Fast-path copy. |
| 2433 | // Compute the base destination address in `temp2`. |
| 2434 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2); |
| 2435 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2436 | // poison/unpoison. |
| 2437 | vixl32::Label loop; |
| 2438 | __ Bind(&loop); |
| 2439 | { |
| 2440 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 2441 | const vixl32::Register temp_reg = temps.Acquire(); |
| 2442 | __ Ldr(temp_reg, MemOperand(temp1, element_size, PostIndex)); |
| 2443 | __ Str(temp_reg, MemOperand(temp2, element_size, PostIndex)); |
| 2444 | } |
| 2445 | __ Cmp(temp1, temp3); |
| 2446 | __ B(ne, &loop, /* far_target */ false); |
| 2447 | |
| 2448 | __ Bind(read_barrier_slow_path->GetExitLabel()); |
| 2449 | } else { |
| 2450 | // Non read barrier code. |
| 2451 | // Compute the base source address in `temp1`. |
| 2452 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, src, src_pos, temp1); |
| 2453 | // Compute the base destination address in `temp2`. |
| 2454 | GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2); |
| 2455 | // Compute the end source address in `temp3`. |
| 2456 | GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3); |
| 2457 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
| 2458 | // poison/unpoison. |
| 2459 | vixl32::Label loop; |
| 2460 | __ Bind(&loop); |
| 2461 | { |
| 2462 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 2463 | const vixl32::Register temp_reg = temps.Acquire(); |
| 2464 | __ Ldr(temp_reg, MemOperand(temp1, element_size, PostIndex)); |
| 2465 | __ Str(temp_reg, MemOperand(temp2, element_size, PostIndex)); |
| 2466 | } |
| 2467 | __ Cmp(temp1, temp3); |
| 2468 | __ B(ne, &loop, /* far_target */ false); |
| 2469 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2470 | __ Bind(&done); |
| 2471 | } |
| 2472 | |
| 2473 | // We only need one card marking on the destination array. |
| 2474 | codegen_->MarkGCCard(temp1, temp2, dest, NoReg, /* value_can_be_null */ false); |
| 2475 | |
| 2476 | __ Bind(intrinsic_slow_path->GetExitLabel()); |
| 2477 | } |
| 2478 | |
| 2479 | static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 2480 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 2481 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 2482 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 2483 | // the input and output locations are unallocated, the register allocator runs out of |
| 2484 | // registers and fails; however, a debuggable graph is not the common case. |
| 2485 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 2486 | return; |
| 2487 | } |
| 2488 | |
| 2489 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 2490 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 2491 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 2492 | |
| 2493 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
| 2494 | LocationSummary::kCallOnMainOnly, |
| 2495 | kIntrinsified); |
| 2496 | const InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2497 | |
| 2498 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2499 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2500 | // Native code uses the soft float ABI. |
| 2501 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2502 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2503 | } |
| 2504 | |
| 2505 | static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 2506 | // If the graph is debuggable, all callee-saved floating-point registers are blocked by |
| 2507 | // the code generator. Furthermore, the register allocator creates fixed live intervals |
| 2508 | // for all caller-saved registers because we are doing a function call. As a result, if |
| 2509 | // the input and output locations are unallocated, the register allocator runs out of |
| 2510 | // registers and fails; however, a debuggable graph is not the common case. |
| 2511 | if (invoke->GetBlock()->GetGraph()->IsDebuggable()) { |
| 2512 | return; |
| 2513 | } |
| 2514 | |
| 2515 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 2516 | DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble); |
| 2517 | DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble); |
| 2518 | DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble); |
| 2519 | |
| 2520 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
| 2521 | LocationSummary::kCallOnMainOnly, |
| 2522 | kIntrinsified); |
| 2523 | const InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 2524 | |
| 2525 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 2526 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 2527 | locations->SetOut(Location::RequiresFpuRegister()); |
| 2528 | // Native code uses the soft float ABI. |
| 2529 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0))); |
| 2530 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1))); |
| 2531 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2))); |
| 2532 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(3))); |
| 2533 | } |
| 2534 | |
| 2535 | static void GenFPToFPCall(HInvoke* invoke, |
| 2536 | ArmVIXLAssembler* assembler, |
| 2537 | CodeGeneratorARMVIXL* codegen, |
| 2538 | QuickEntrypointEnum entry) { |
| 2539 | LocationSummary* const locations = invoke->GetLocations(); |
| 2540 | |
| 2541 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 2542 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 2543 | |
| 2544 | // Native code uses the soft float ABI. |
| 2545 | __ Vmov(RegisterFrom(locations->GetTemp(0)), |
| 2546 | RegisterFrom(locations->GetTemp(1)), |
| 2547 | InputDRegisterAt(invoke, 0)); |
| 2548 | codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc()); |
| 2549 | __ Vmov(OutputDRegister(invoke), |
| 2550 | RegisterFrom(locations->GetTemp(0)), |
| 2551 | RegisterFrom(locations->GetTemp(1))); |
| 2552 | } |
| 2553 | |
| 2554 | static void GenFPFPToFPCall(HInvoke* invoke, |
| 2555 | ArmVIXLAssembler* assembler, |
| 2556 | CodeGeneratorARMVIXL* codegen, |
| 2557 | QuickEntrypointEnum entry) { |
| 2558 | LocationSummary* const locations = invoke->GetLocations(); |
| 2559 | |
| 2560 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 2561 | DCHECK(locations->WillCall() && locations->Intrinsified()); |
| 2562 | |
| 2563 | // Native code uses the soft float ABI. |
| 2564 | __ Vmov(RegisterFrom(locations->GetTemp(0)), |
| 2565 | RegisterFrom(locations->GetTemp(1)), |
| 2566 | InputDRegisterAt(invoke, 0)); |
| 2567 | __ Vmov(RegisterFrom(locations->GetTemp(2)), |
| 2568 | RegisterFrom(locations->GetTemp(3)), |
| 2569 | InputDRegisterAt(invoke, 1)); |
| 2570 | codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc()); |
| 2571 | __ Vmov(OutputDRegister(invoke), |
| 2572 | RegisterFrom(locations->GetTemp(0)), |
| 2573 | RegisterFrom(locations->GetTemp(1))); |
| 2574 | } |
| 2575 | |
| 2576 | void IntrinsicLocationsBuilderARMVIXL::VisitMathCos(HInvoke* invoke) { |
| 2577 | CreateFPToFPCallLocations(arena_, invoke); |
| 2578 | } |
| 2579 | |
| 2580 | void IntrinsicCodeGeneratorARMVIXL::VisitMathCos(HInvoke* invoke) { |
| 2581 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos); |
| 2582 | } |
| 2583 | |
| 2584 | void IntrinsicLocationsBuilderARMVIXL::VisitMathSin(HInvoke* invoke) { |
| 2585 | CreateFPToFPCallLocations(arena_, invoke); |
| 2586 | } |
| 2587 | |
| 2588 | void IntrinsicCodeGeneratorARMVIXL::VisitMathSin(HInvoke* invoke) { |
| 2589 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin); |
| 2590 | } |
| 2591 | |
| 2592 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAcos(HInvoke* invoke) { |
| 2593 | CreateFPToFPCallLocations(arena_, invoke); |
| 2594 | } |
| 2595 | |
| 2596 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAcos(HInvoke* invoke) { |
| 2597 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos); |
| 2598 | } |
| 2599 | |
| 2600 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAsin(HInvoke* invoke) { |
| 2601 | CreateFPToFPCallLocations(arena_, invoke); |
| 2602 | } |
| 2603 | |
| 2604 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAsin(HInvoke* invoke) { |
| 2605 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin); |
| 2606 | } |
| 2607 | |
| 2608 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAtan(HInvoke* invoke) { |
| 2609 | CreateFPToFPCallLocations(arena_, invoke); |
| 2610 | } |
| 2611 | |
| 2612 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAtan(HInvoke* invoke) { |
| 2613 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan); |
| 2614 | } |
| 2615 | |
| 2616 | void IntrinsicLocationsBuilderARMVIXL::VisitMathCbrt(HInvoke* invoke) { |
| 2617 | CreateFPToFPCallLocations(arena_, invoke); |
| 2618 | } |
| 2619 | |
| 2620 | void IntrinsicCodeGeneratorARMVIXL::VisitMathCbrt(HInvoke* invoke) { |
| 2621 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt); |
| 2622 | } |
| 2623 | |
| 2624 | void IntrinsicLocationsBuilderARMVIXL::VisitMathCosh(HInvoke* invoke) { |
| 2625 | CreateFPToFPCallLocations(arena_, invoke); |
| 2626 | } |
| 2627 | |
| 2628 | void IntrinsicCodeGeneratorARMVIXL::VisitMathCosh(HInvoke* invoke) { |
| 2629 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh); |
| 2630 | } |
| 2631 | |
| 2632 | void IntrinsicLocationsBuilderARMVIXL::VisitMathExp(HInvoke* invoke) { |
| 2633 | CreateFPToFPCallLocations(arena_, invoke); |
| 2634 | } |
| 2635 | |
| 2636 | void IntrinsicCodeGeneratorARMVIXL::VisitMathExp(HInvoke* invoke) { |
| 2637 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp); |
| 2638 | } |
| 2639 | |
| 2640 | void IntrinsicLocationsBuilderARMVIXL::VisitMathExpm1(HInvoke* invoke) { |
| 2641 | CreateFPToFPCallLocations(arena_, invoke); |
| 2642 | } |
| 2643 | |
| 2644 | void IntrinsicCodeGeneratorARMVIXL::VisitMathExpm1(HInvoke* invoke) { |
| 2645 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1); |
| 2646 | } |
| 2647 | |
| 2648 | void IntrinsicLocationsBuilderARMVIXL::VisitMathLog(HInvoke* invoke) { |
| 2649 | CreateFPToFPCallLocations(arena_, invoke); |
| 2650 | } |
| 2651 | |
| 2652 | void IntrinsicCodeGeneratorARMVIXL::VisitMathLog(HInvoke* invoke) { |
| 2653 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog); |
| 2654 | } |
| 2655 | |
| 2656 | void IntrinsicLocationsBuilderARMVIXL::VisitMathLog10(HInvoke* invoke) { |
| 2657 | CreateFPToFPCallLocations(arena_, invoke); |
| 2658 | } |
| 2659 | |
| 2660 | void IntrinsicCodeGeneratorARMVIXL::VisitMathLog10(HInvoke* invoke) { |
| 2661 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10); |
| 2662 | } |
| 2663 | |
| 2664 | void IntrinsicLocationsBuilderARMVIXL::VisitMathSinh(HInvoke* invoke) { |
| 2665 | CreateFPToFPCallLocations(arena_, invoke); |
| 2666 | } |
| 2667 | |
| 2668 | void IntrinsicCodeGeneratorARMVIXL::VisitMathSinh(HInvoke* invoke) { |
| 2669 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh); |
| 2670 | } |
| 2671 | |
| 2672 | void IntrinsicLocationsBuilderARMVIXL::VisitMathTan(HInvoke* invoke) { |
| 2673 | CreateFPToFPCallLocations(arena_, invoke); |
| 2674 | } |
| 2675 | |
| 2676 | void IntrinsicCodeGeneratorARMVIXL::VisitMathTan(HInvoke* invoke) { |
| 2677 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan); |
| 2678 | } |
| 2679 | |
| 2680 | void IntrinsicLocationsBuilderARMVIXL::VisitMathTanh(HInvoke* invoke) { |
| 2681 | CreateFPToFPCallLocations(arena_, invoke); |
| 2682 | } |
| 2683 | |
| 2684 | void IntrinsicCodeGeneratorARMVIXL::VisitMathTanh(HInvoke* invoke) { |
| 2685 | GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh); |
| 2686 | } |
| 2687 | |
| 2688 | void IntrinsicLocationsBuilderARMVIXL::VisitMathAtan2(HInvoke* invoke) { |
| 2689 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2690 | } |
| 2691 | |
| 2692 | void IntrinsicCodeGeneratorARMVIXL::VisitMathAtan2(HInvoke* invoke) { |
| 2693 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2); |
| 2694 | } |
| 2695 | |
| 2696 | void IntrinsicLocationsBuilderARMVIXL::VisitMathHypot(HInvoke* invoke) { |
| 2697 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2698 | } |
| 2699 | |
| 2700 | void IntrinsicCodeGeneratorARMVIXL::VisitMathHypot(HInvoke* invoke) { |
| 2701 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot); |
| 2702 | } |
| 2703 | |
| 2704 | void IntrinsicLocationsBuilderARMVIXL::VisitMathNextAfter(HInvoke* invoke) { |
| 2705 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 2706 | } |
| 2707 | |
| 2708 | void IntrinsicCodeGeneratorARMVIXL::VisitMathNextAfter(HInvoke* invoke) { |
| 2709 | GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter); |
| 2710 | } |
| 2711 | |
| 2712 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerReverse(HInvoke* invoke) { |
| 2713 | CreateIntToIntLocations(arena_, invoke); |
| 2714 | } |
| 2715 | |
| 2716 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerReverse(HInvoke* invoke) { |
| 2717 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2718 | __ Rbit(OutputRegister(invoke), InputRegisterAt(invoke, 0)); |
| 2719 | } |
| 2720 | |
| 2721 | void IntrinsicLocationsBuilderARMVIXL::VisitLongReverse(HInvoke* invoke) { |
| 2722 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2723 | LocationSummary::kNoCall, |
| 2724 | kIntrinsified); |
| 2725 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2726 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2727 | } |
| 2728 | |
| 2729 | void IntrinsicCodeGeneratorARMVIXL::VisitLongReverse(HInvoke* invoke) { |
| 2730 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2731 | LocationSummary* locations = invoke->GetLocations(); |
| 2732 | |
| 2733 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 2734 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 2735 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 2736 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 2737 | |
| 2738 | __ Rbit(out_reg_lo, in_reg_hi); |
| 2739 | __ Rbit(out_reg_hi, in_reg_lo); |
| 2740 | } |
| 2741 | |
| 2742 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 2743 | CreateIntToIntLocations(arena_, invoke); |
| 2744 | } |
| 2745 | |
| 2746 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 2747 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2748 | __ Rev(OutputRegister(invoke), InputRegisterAt(invoke, 0)); |
| 2749 | } |
| 2750 | |
| 2751 | void IntrinsicLocationsBuilderARMVIXL::VisitLongReverseBytes(HInvoke* invoke) { |
| 2752 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2753 | LocationSummary::kNoCall, |
| 2754 | kIntrinsified); |
| 2755 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2756 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 2757 | } |
| 2758 | |
| 2759 | void IntrinsicCodeGeneratorARMVIXL::VisitLongReverseBytes(HInvoke* invoke) { |
| 2760 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2761 | LocationSummary* locations = invoke->GetLocations(); |
| 2762 | |
| 2763 | vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0)); |
| 2764 | vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0)); |
| 2765 | vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out()); |
| 2766 | vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out()); |
| 2767 | |
| 2768 | __ Rev(out_reg_lo, in_reg_hi); |
| 2769 | __ Rev(out_reg_hi, in_reg_lo); |
| 2770 | } |
| 2771 | |
| 2772 | void IntrinsicLocationsBuilderARMVIXL::VisitShortReverseBytes(HInvoke* invoke) { |
| 2773 | CreateIntToIntLocations(arena_, invoke); |
| 2774 | } |
| 2775 | |
| 2776 | void IntrinsicCodeGeneratorARMVIXL::VisitShortReverseBytes(HInvoke* invoke) { |
| 2777 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2778 | __ Revsh(OutputRegister(invoke), InputRegisterAt(invoke, 0)); |
| 2779 | } |
| 2780 | |
| 2781 | static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmVIXLAssembler* assembler) { |
| 2782 | DCHECK(Primitive::IsIntOrLongType(type)) << type; |
| 2783 | DCHECK_EQ(instr->GetType(), Primitive::kPrimInt); |
| 2784 | DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type); |
| 2785 | |
| 2786 | bool is_long = type == Primitive::kPrimLong; |
| 2787 | LocationSummary* locations = instr->GetLocations(); |
| 2788 | Location in = locations->InAt(0); |
| 2789 | vixl32::Register src_0 = is_long ? LowRegisterFrom(in) : RegisterFrom(in); |
| 2790 | vixl32::Register src_1 = is_long ? HighRegisterFrom(in) : src_0; |
| 2791 | vixl32::SRegister tmp_s = LowSRegisterFrom(locations->GetTemp(0)); |
| 2792 | vixl32::DRegister tmp_d = DRegisterFrom(locations->GetTemp(0)); |
| 2793 | vixl32::Register out_r = OutputRegister(instr); |
| 2794 | |
| 2795 | // Move data from core register(s) to temp D-reg for bit count calculation, then move back. |
| 2796 | // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg, |
| 2797 | // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency, |
| 2798 | // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'. |
| 2799 | __ Vmov(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0| |
| 2800 | __ Vcnt(Untyped8, tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c| |
| 2801 | __ Vpaddl(U8, tmp_d, tmp_d); // Temp DReg |--c|--c|--c|--c| |
| 2802 | __ Vpaddl(U16, tmp_d, tmp_d); // Temp DReg |------c|------c| |
| 2803 | if (is_long) { |
| 2804 | __ Vpaddl(U32, tmp_d, tmp_d); // Temp DReg |--------------c| |
| 2805 | } |
| 2806 | __ Vmov(out_r, tmp_s); |
| 2807 | } |
| 2808 | |
| 2809 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerBitCount(HInvoke* invoke) { |
| 2810 | CreateIntToIntLocations(arena_, invoke); |
| 2811 | invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister()); |
| 2812 | } |
| 2813 | |
| 2814 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerBitCount(HInvoke* invoke) { |
| 2815 | GenBitCount(invoke, Primitive::kPrimInt, GetAssembler()); |
| 2816 | } |
| 2817 | |
| 2818 | void IntrinsicLocationsBuilderARMVIXL::VisitLongBitCount(HInvoke* invoke) { |
| 2819 | VisitIntegerBitCount(invoke); |
| 2820 | } |
| 2821 | |
| 2822 | void IntrinsicCodeGeneratorARMVIXL::VisitLongBitCount(HInvoke* invoke) { |
| 2823 | GenBitCount(invoke, Primitive::kPrimLong, GetAssembler()); |
| 2824 | } |
| 2825 | |
| 2826 | void IntrinsicLocationsBuilderARMVIXL::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2827 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 2828 | LocationSummary::kNoCall, |
| 2829 | kIntrinsified); |
| 2830 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2831 | locations->SetInAt(1, Location::RequiresRegister()); |
| 2832 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2833 | locations->SetInAt(3, Location::RequiresRegister()); |
| 2834 | locations->SetInAt(4, Location::RequiresRegister()); |
| 2835 | |
| 2836 | // Temporary registers to store lengths of strings and for calculations. |
| 2837 | locations->AddTemp(Location::RequiresRegister()); |
| 2838 | locations->AddTemp(Location::RequiresRegister()); |
| 2839 | locations->AddTemp(Location::RequiresRegister()); |
| 2840 | } |
| 2841 | |
| 2842 | void IntrinsicCodeGeneratorARMVIXL::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 2843 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 2844 | LocationSummary* locations = invoke->GetLocations(); |
| 2845 | |
| 2846 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
| 2847 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 2848 | DCHECK_EQ(char_size, 2u); |
| 2849 | |
| 2850 | // Location of data in char array buffer. |
| 2851 | const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value(); |
| 2852 | |
| 2853 | // Location of char array data in string. |
| 2854 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 2855 | |
| 2856 | // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
| 2857 | // Since getChars() calls getCharsNoCheck() - we use registers rather than constants. |
| 2858 | vixl32::Register srcObj = InputRegisterAt(invoke, 0); |
| 2859 | vixl32::Register srcBegin = InputRegisterAt(invoke, 1); |
| 2860 | vixl32::Register srcEnd = InputRegisterAt(invoke, 2); |
| 2861 | vixl32::Register dstObj = InputRegisterAt(invoke, 3); |
| 2862 | vixl32::Register dstBegin = InputRegisterAt(invoke, 4); |
| 2863 | |
| 2864 | vixl32::Register num_chr = RegisterFrom(locations->GetTemp(0)); |
| 2865 | vixl32::Register src_ptr = RegisterFrom(locations->GetTemp(1)); |
| 2866 | vixl32::Register dst_ptr = RegisterFrom(locations->GetTemp(2)); |
| 2867 | |
| 2868 | vixl32::Label done, compressed_string_loop; |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2869 | vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &done); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2870 | // dst to be copied. |
| 2871 | __ Add(dst_ptr, dstObj, data_offset); |
| 2872 | __ Add(dst_ptr, dst_ptr, Operand(dstBegin, vixl32::LSL, 1)); |
| 2873 | |
| 2874 | __ Subs(num_chr, srcEnd, srcBegin); |
| 2875 | // Early out for valid zero-length retrievals. |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2876 | __ B(eq, final_label, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2877 | |
| 2878 | // src range to copy. |
| 2879 | __ Add(src_ptr, srcObj, value_offset); |
| 2880 | |
| 2881 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 2882 | vixl32::Register temp; |
| 2883 | vixl32::Label compressed_string_preloop; |
| 2884 | if (mirror::kUseStringCompression) { |
| 2885 | // Location of count in string. |
| 2886 | const uint32_t count_offset = mirror::String::CountOffset().Uint32Value(); |
| 2887 | temp = temps.Acquire(); |
| 2888 | // String's length. |
| 2889 | __ Ldr(temp, MemOperand(srcObj, count_offset)); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2890 | __ Tst(temp, 1); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2891 | temps.Release(temp); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2892 | __ B(eq, &compressed_string_preloop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2893 | } |
| 2894 | __ Add(src_ptr, src_ptr, Operand(srcBegin, vixl32::LSL, 1)); |
| 2895 | |
| 2896 | // Do the copy. |
| 2897 | vixl32::Label loop, remainder; |
| 2898 | |
| 2899 | temp = temps.Acquire(); |
| 2900 | // Save repairing the value of num_chr on the < 4 character path. |
| 2901 | __ Subs(temp, num_chr, 4); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2902 | __ B(lt, &remainder, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2903 | |
| 2904 | // Keep the result of the earlier subs, we are going to fetch at least 4 characters. |
| 2905 | __ Mov(num_chr, temp); |
| 2906 | |
| 2907 | // Main loop used for longer fetches loads and stores 4x16-bit characters at a time. |
| 2908 | // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code |
| 2909 | // to rectify these everywhere this intrinsic applies.) |
| 2910 | __ Bind(&loop); |
| 2911 | __ Ldr(temp, MemOperand(src_ptr, char_size * 2)); |
| 2912 | __ Subs(num_chr, num_chr, 4); |
| 2913 | __ Str(temp, MemOperand(dst_ptr, char_size * 2)); |
| 2914 | __ Ldr(temp, MemOperand(src_ptr, char_size * 4, PostIndex)); |
| 2915 | __ Str(temp, MemOperand(dst_ptr, char_size * 4, PostIndex)); |
| 2916 | temps.Release(temp); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2917 | __ B(ge, &loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2918 | |
| 2919 | __ Adds(num_chr, num_chr, 4); |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2920 | __ B(eq, final_label, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2921 | |
| 2922 | // Main loop for < 4 character case and remainder handling. Loads and stores one |
| 2923 | // 16-bit Java character at a time. |
| 2924 | __ Bind(&remainder); |
| 2925 | temp = temps.Acquire(); |
| 2926 | __ Ldrh(temp, MemOperand(src_ptr, char_size, PostIndex)); |
| 2927 | __ Subs(num_chr, num_chr, 1); |
| 2928 | __ Strh(temp, MemOperand(dst_ptr, char_size, PostIndex)); |
| 2929 | temps.Release(temp); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2930 | __ B(gt, &remainder, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2931 | |
| 2932 | if (mirror::kUseStringCompression) { |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2933 | __ B(final_label); |
Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 2934 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2935 | const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte); |
| 2936 | DCHECK_EQ(c_char_size, 1u); |
| 2937 | // Copy loop for compressed src, copying 1 character (8-bit) to (16-bit) at a time. |
| 2938 | __ Bind(&compressed_string_preloop); |
| 2939 | __ Add(src_ptr, src_ptr, srcBegin); |
| 2940 | __ Bind(&compressed_string_loop); |
| 2941 | temp = temps.Acquire(); |
| 2942 | __ Ldrb(temp, MemOperand(src_ptr, c_char_size, PostIndex)); |
| 2943 | __ Strh(temp, MemOperand(dst_ptr, char_size, PostIndex)); |
| 2944 | temps.Release(temp); |
| 2945 | __ Subs(num_chr, num_chr, 1); |
Artem Serov | 517d9f6 | 2016-12-12 15:51:15 +0000 | [diff] [blame] | 2946 | __ B(gt, &compressed_string_loop, /* far_target */ false); |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2947 | } |
| 2948 | |
Anton Kirilov | 6f64420 | 2017-02-27 18:29:45 +0000 | [diff] [blame] | 2949 | if (done.IsReferenced()) { |
| 2950 | __ Bind(&done); |
| 2951 | } |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | void IntrinsicLocationsBuilderARMVIXL::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2955 | CreateFPToIntLocations(arena_, invoke); |
| 2956 | } |
| 2957 | |
| 2958 | void IntrinsicCodeGeneratorARMVIXL::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2959 | ArmVIXLAssembler* const assembler = GetAssembler(); |
| 2960 | const vixl32::Register out = OutputRegister(invoke); |
| 2961 | // Shifting left by 1 bit makes the value encodable as an immediate operand; |
| 2962 | // we don't care about the sign bit anyway. |
| 2963 | constexpr uint32_t infinity = kPositiveInfinityFloat << 1U; |
| 2964 | |
| 2965 | __ Vmov(out, InputSRegisterAt(invoke, 0)); |
| 2966 | // We don't care about the sign bit, so shift left. |
| 2967 | __ Lsl(out, out, 1); |
| 2968 | __ Eor(out, out, infinity); |
| 2969 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 2970 | __ Clz(out, out); |
| 2971 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 2972 | // the same operation on 32 yields 1. |
| 2973 | __ Lsr(out, out, 5); |
| 2974 | } |
| 2975 | |
| 2976 | void IntrinsicLocationsBuilderARMVIXL::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2977 | CreateFPToIntLocations(arena_, invoke); |
| 2978 | } |
| 2979 | |
| 2980 | void IntrinsicCodeGeneratorARMVIXL::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2981 | ArmVIXLAssembler* const assembler = GetAssembler(); |
| 2982 | const vixl32::Register out = OutputRegister(invoke); |
| 2983 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 2984 | const vixl32::Register temp = temps.Acquire(); |
| 2985 | // The highest 32 bits of double precision positive infinity separated into |
| 2986 | // two constants encodable as immediate operands. |
| 2987 | constexpr uint32_t infinity_high = 0x7f000000U; |
| 2988 | constexpr uint32_t infinity_high2 = 0x00f00000U; |
| 2989 | |
| 2990 | static_assert((infinity_high | infinity_high2) == |
| 2991 | static_cast<uint32_t>(kPositiveInfinityDouble >> 32U), |
| 2992 | "The constants do not add up to the high 32 bits of double " |
| 2993 | "precision positive infinity."); |
| 2994 | __ Vmov(temp, out, InputDRegisterAt(invoke, 0)); |
| 2995 | __ Eor(out, out, infinity_high); |
| 2996 | __ Eor(out, out, infinity_high2); |
| 2997 | // We don't care about the sign bit, so shift left. |
| 2998 | __ Orr(out, temp, Operand(out, vixl32::LSL, 1)); |
| 2999 | // If the result is 0, then it has 32 leading zeros, and less than that otherwise. |
| 3000 | __ Clz(out, out); |
| 3001 | // Any number less than 32 logically shifted right by 5 bits results in 0; |
| 3002 | // the same operation on 32 yields 1. |
| 3003 | __ Lsr(out, out, 5); |
| 3004 | } |
| 3005 | |
TatWai Chong | d8c052a | 2016-11-02 16:12:48 +0800 | [diff] [blame] | 3006 | void IntrinsicLocationsBuilderARMVIXL::VisitReferenceGetReferent(HInvoke* invoke) { |
| 3007 | if (kEmitCompilerReadBarrier) { |
| 3008 | // Do not intrinsify this call with the read barrier configuration. |
| 3009 | return; |
| 3010 | } |
| 3011 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 3012 | LocationSummary::kCallOnSlowPath, |
| 3013 | kIntrinsified); |
| 3014 | locations->SetInAt(0, Location::RequiresRegister()); |
| 3015 | locations->SetOut(Location::SameAsFirstInput()); |
| 3016 | locations->AddTemp(Location::RequiresRegister()); |
| 3017 | } |
| 3018 | |
| 3019 | void IntrinsicCodeGeneratorARMVIXL::VisitReferenceGetReferent(HInvoke* invoke) { |
| 3020 | DCHECK(!kEmitCompilerReadBarrier); |
| 3021 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 3022 | LocationSummary* locations = invoke->GetLocations(); |
| 3023 | |
| 3024 | vixl32::Register obj = InputRegisterAt(invoke, 0); |
| 3025 | vixl32::Register out = OutputRegister(invoke); |
| 3026 | |
| 3027 | SlowPathCodeARMVIXL* slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke); |
| 3028 | codegen_->AddSlowPath(slow_path); |
| 3029 | |
| 3030 | // Load ArtMethod first. |
| 3031 | HInvokeStaticOrDirect* invoke_direct = invoke->AsInvokeStaticOrDirect(); |
| 3032 | DCHECK(invoke_direct != nullptr); |
| 3033 | vixl32::Register temp0 = RegisterFrom(codegen_->GenerateCalleeMethodStaticOrDirectCall( |
| 3034 | invoke_direct, locations->GetTemp(0))); |
| 3035 | |
| 3036 | // Now get declaring class. |
| 3037 | __ Ldr(temp0, MemOperand(temp0, ArtMethod::DeclaringClassOffset().Int32Value())); |
| 3038 | |
| 3039 | uint32_t slow_path_flag_offset = codegen_->GetReferenceSlowFlagOffset(); |
| 3040 | uint32_t disable_flag_offset = codegen_->GetReferenceDisableFlagOffset(); |
| 3041 | DCHECK_NE(slow_path_flag_offset, 0u); |
| 3042 | DCHECK_NE(disable_flag_offset, 0u); |
| 3043 | DCHECK_NE(slow_path_flag_offset, disable_flag_offset); |
| 3044 | |
| 3045 | // Check static flags that prevent using intrinsic. |
| 3046 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 3047 | vixl32::Register temp1 = temps.Acquire(); |
| 3048 | __ Ldr(temp1, MemOperand(temp0, disable_flag_offset)); |
| 3049 | __ Ldr(temp0, MemOperand(temp0, slow_path_flag_offset)); |
| 3050 | __ Orr(temp0, temp1, temp0); |
| 3051 | __ CompareAndBranchIfNonZero(temp0, slow_path->GetEntryLabel()); |
| 3052 | |
| 3053 | // Fast path. |
| 3054 | __ Ldr(out, MemOperand(obj, mirror::Reference::ReferentOffset().Int32Value())); |
| 3055 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 3056 | assembler->MaybeUnpoisonHeapReference(out); |
| 3057 | __ Bind(slow_path->GetExitLabel()); |
| 3058 | } |
| 3059 | |
Artem Serov | 9aee2d4 | 2017-01-06 15:58:31 +0000 | [diff] [blame] | 3060 | void IntrinsicLocationsBuilderARMVIXL::VisitMathCeil(HInvoke* invoke) { |
| 3061 | if (features_.HasARMv8AInstructions()) { |
| 3062 | CreateFPToFPLocations(arena_, invoke); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | void IntrinsicCodeGeneratorARMVIXL::VisitMathCeil(HInvoke* invoke) { |
| 3067 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 3068 | DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions()); |
| 3069 | __ Vrintp(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0)); |
| 3070 | } |
| 3071 | |
| 3072 | void IntrinsicLocationsBuilderARMVIXL::VisitMathFloor(HInvoke* invoke) { |
| 3073 | if (features_.HasARMv8AInstructions()) { |
| 3074 | CreateFPToFPLocations(arena_, invoke); |
| 3075 | } |
| 3076 | } |
| 3077 | |
| 3078 | void IntrinsicCodeGeneratorARMVIXL::VisitMathFloor(HInvoke* invoke) { |
| 3079 | ArmVIXLAssembler* assembler = GetAssembler(); |
| 3080 | DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions()); |
| 3081 | __ Vrintm(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0)); |
| 3082 | } |
| 3083 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 3084 | void IntrinsicLocationsBuilderARMVIXL::VisitIntegerValueOf(HInvoke* invoke) { |
| 3085 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3086 | IntrinsicVisitor::ComputeIntegerValueOfLocations( |
| 3087 | invoke, |
| 3088 | codegen_, |
| 3089 | LocationFrom(r0), |
| 3090 | LocationFrom(calling_convention.GetRegisterAt(0))); |
| 3091 | } |
| 3092 | |
| 3093 | void IntrinsicCodeGeneratorARMVIXL::VisitIntegerValueOf(HInvoke* invoke) { |
| 3094 | IntrinsicVisitor::IntegerValueOfInfo info = IntrinsicVisitor::ComputeIntegerValueOfInfo(); |
| 3095 | LocationSummary* locations = invoke->GetLocations(); |
| 3096 | ArmVIXLAssembler* const assembler = GetAssembler(); |
| 3097 | |
| 3098 | vixl32::Register out = RegisterFrom(locations->Out()); |
| 3099 | UseScratchRegisterScope temps(assembler->GetVIXLAssembler()); |
| 3100 | vixl32::Register temp = temps.Acquire(); |
| 3101 | InvokeRuntimeCallingConventionARMVIXL calling_convention; |
| 3102 | vixl32::Register argument = calling_convention.GetRegisterAt(0); |
| 3103 | if (invoke->InputAt(0)->IsConstant()) { |
| 3104 | int32_t value = invoke->InputAt(0)->AsIntConstant()->GetValue(); |
| 3105 | if (value >= info.low && value <= info.high) { |
| 3106 | // Just embed the j.l.Integer in the code. |
| 3107 | ScopedObjectAccess soa(Thread::Current()); |
| 3108 | mirror::Object* boxed = info.cache->Get(value + (-info.low)); |
| 3109 | DCHECK(boxed != nullptr && Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(boxed)); |
| 3110 | uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(boxed)); |
| 3111 | __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 3112 | } else { |
| 3113 | // Allocate and initialize a new j.l.Integer. |
| 3114 | // TODO: If we JIT, we could allocate the j.l.Integer now, and store it in the |
| 3115 | // JIT object table. |
| 3116 | uint32_t address = |
| 3117 | dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer)); |
| 3118 | __ Ldr(argument, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 3119 | codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 3120 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 3121 | __ Mov(temp, value); |
| 3122 | assembler->StoreToOffset(kStoreWord, temp, out, info.value_offset); |
| 3123 | // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation |
| 3124 | // one. |
| 3125 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3126 | } |
| 3127 | } else { |
| 3128 | vixl32::Register in = RegisterFrom(locations->InAt(0)); |
| 3129 | // Check bounds of our cache. |
| 3130 | __ Add(out, in, -info.low); |
| 3131 | __ Cmp(out, info.high - info.low + 1); |
| 3132 | vixl32::Label allocate, done; |
| 3133 | __ B(hs, &allocate); |
| 3134 | // If the value is within the bounds, load the j.l.Integer directly from the array. |
| 3135 | uint32_t data_offset = mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value(); |
| 3136 | uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.cache)); |
| 3137 | __ Ldr(temp, codegen_->DeduplicateBootImageAddressLiteral(data_offset + address)); |
| 3138 | codegen_->LoadFromShiftedRegOffset(Primitive::kPrimNot, locations->Out(), temp, out); |
| 3139 | assembler->MaybeUnpoisonHeapReference(out); |
| 3140 | __ B(&done); |
| 3141 | __ Bind(&allocate); |
| 3142 | // Otherwise allocate and initialize a new j.l.Integer. |
| 3143 | address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer)); |
| 3144 | __ Ldr(argument, codegen_->DeduplicateBootImageAddressLiteral(address)); |
| 3145 | codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc()); |
| 3146 | CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>(); |
| 3147 | assembler->StoreToOffset(kStoreWord, in, out, info.value_offset); |
| 3148 | // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation |
| 3149 | // one. |
| 3150 | codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore); |
| 3151 | __ Bind(&done); |
| 3152 | } |
| 3153 | } |
| 3154 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3155 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, MathRoundDouble) // Could be done by changing rounding mode, maybe? |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3156 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeCASLong) // High register pressure. |
| 3157 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, SystemArrayCopyChar) |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3158 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, IntegerHighestOneBit) |
| 3159 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, LongHighestOneBit) |
| 3160 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, IntegerLowestOneBit) |
| 3161 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, LongLowestOneBit) |
| 3162 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3163 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringStringIndexOf); |
| 3164 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringStringIndexOfAfter); |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 3165 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferAppend); |
| 3166 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferLength); |
| 3167 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferToString); |
| 3168 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderAppend); |
| 3169 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderLength); |
| 3170 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderToString); |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 3171 | |
Anton Kirilov | 5ec6218 | 2016-10-13 20:16:02 +0100 | [diff] [blame] | 3172 | // 1.8. |
| 3173 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndAddInt) |
| 3174 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndAddLong) |
| 3175 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetInt) |
| 3176 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetLong) |
| 3177 | UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetObject) |
| 3178 | |
| 3179 | UNREACHABLE_INTRINSICS(ARMVIXL) |
| 3180 | |
| 3181 | #undef __ |
| 3182 | |
| 3183 | } // namespace arm |
| 3184 | } // namespace art |