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