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