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