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" |
| 24 | #include "intrinsics.h" |
| 25 | #include "mirror/array-inl.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 26 | #include "mirror/string.h" |
| 27 | #include "thread.h" |
| 28 | #include "utils/arm64/assembler_arm64.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 29 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 30 | using namespace vixl::aarch64; // NOLINT(build/namespaces) |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 31 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 32 | // TODO: make vixl clean wrt -Wshadow. |
| 33 | #pragma GCC diagnostic push |
| 34 | #pragma GCC diagnostic ignored "-Wshadow" |
| 35 | #include "a64/disasm-a64.h" |
| 36 | #include "a64/macro-assembler-a64.h" |
| 37 | #pragma GCC diagnostic pop |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
| 41 | namespace arm64 { |
| 42 | |
| 43 | using helpers::DRegisterFrom; |
| 44 | using helpers::FPRegisterFrom; |
| 45 | using helpers::HeapOperand; |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 46 | using helpers::LocationFrom; |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 47 | using helpers::OperandFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 48 | using helpers::RegisterFrom; |
| 49 | using helpers::SRegisterFrom; |
| 50 | using helpers::WRegisterFrom; |
| 51 | using helpers::XRegisterFrom; |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 52 | using helpers::InputRegisterAt; |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 53 | using helpers::OutputRegister; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 54 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 55 | namespace { |
| 56 | |
| 57 | ALWAYS_INLINE inline MemOperand AbsoluteHeapOperandFrom(Location location, size_t offset = 0) { |
| 58 | return MemOperand(XRegisterFrom(location), offset); |
| 59 | } |
| 60 | |
| 61 | } // namespace |
| 62 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 63 | MacroAssembler* IntrinsicCodeGeneratorARM64::GetVIXLAssembler() { |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame^] | 64 | return codegen_->GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | ArenaAllocator* IntrinsicCodeGeneratorARM64::GetAllocator() { |
| 68 | return codegen_->GetGraph()->GetArena(); |
| 69 | } |
| 70 | |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame^] | 71 | #define __ codegen->GetVIXLAssembler()-> |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 72 | |
| 73 | static void MoveFromReturnRegister(Location trg, |
| 74 | Primitive::Type type, |
| 75 | CodeGeneratorARM64* codegen) { |
| 76 | if (!trg.IsValid()) { |
| 77 | DCHECK(type == Primitive::kPrimVoid); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 82 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 83 | if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 84 | Register trg_reg = RegisterFrom(trg, type); |
| 85 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 86 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 87 | } else { |
| 88 | FPRegister trg_reg = FPRegisterFrom(trg, type); |
| 89 | FPRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 90 | __ Fmov(trg_reg, res_reg); |
| 91 | } |
| 92 | } |
| 93 | |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 94 | static void MoveArguments(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 95 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 96 | IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | // Slow-path for fallback (calling the managed code to handle the intrinsic) in an intrinsified |
| 100 | // call. This will copy the arguments into the positions for a regular call. |
| 101 | // |
| 102 | // Note: The actual parameters are required to be in the locations given by the invoke's location |
| 103 | // summary. If an intrinsic modifies those locations before a slowpath call, they must be |
| 104 | // restored! |
| 105 | class IntrinsicSlowPathARM64 : public SlowPathCodeARM64 { |
| 106 | public: |
David Srbecky | 9cd6d37 | 2016-02-09 15:24:47 +0000 | [diff] [blame] | 107 | explicit IntrinsicSlowPathARM64(HInvoke* invoke) |
| 108 | : SlowPathCodeARM64(invoke), invoke_(invoke) { } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 109 | |
| 110 | void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE { |
| 111 | CodeGeneratorARM64* codegen = down_cast<CodeGeneratorARM64*>(codegen_in); |
| 112 | __ Bind(GetEntryLabel()); |
| 113 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 114 | SaveLiveRegisters(codegen, invoke_->GetLocations()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 115 | |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 116 | MoveArguments(invoke_, codegen); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 117 | |
| 118 | if (invoke_->IsInvokeStaticOrDirect()) { |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 119 | codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), |
| 120 | LocationFrom(kArtMethodRegister)); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 121 | } else { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 122 | codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), LocationFrom(kArtMethodRegister)); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 123 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 124 | codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 125 | |
| 126 | // Copy the result back to the expected output. |
| 127 | Location out = invoke_->GetLocations()->Out(); |
| 128 | if (out.IsValid()) { |
| 129 | DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory. |
| 130 | DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 131 | MoveFromReturnRegister(out, invoke_->GetType(), codegen); |
| 132 | } |
| 133 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 134 | RestoreLiveRegisters(codegen, invoke_->GetLocations()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 135 | __ B(GetExitLabel()); |
| 136 | } |
| 137 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 138 | const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathARM64"; } |
| 139 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 140 | private: |
| 141 | // The instruction where this slow path is happening. |
| 142 | HInvoke* const invoke_; |
| 143 | |
| 144 | DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARM64); |
| 145 | }; |
| 146 | |
| 147 | #undef __ |
| 148 | |
| 149 | bool IntrinsicLocationsBuilderARM64::TryDispatch(HInvoke* invoke) { |
| 150 | Dispatch(invoke); |
| 151 | LocationSummary* res = invoke->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 152 | if (res == nullptr) { |
| 153 | return false; |
| 154 | } |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 155 | return res->Intrinsified(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | #define __ masm-> |
| 159 | |
| 160 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 161 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 162 | LocationSummary::kNoCall, |
| 163 | kIntrinsified); |
| 164 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 165 | locations->SetOut(Location::RequiresRegister()); |
| 166 | } |
| 167 | |
| 168 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 169 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 170 | LocationSummary::kNoCall, |
| 171 | kIntrinsified); |
| 172 | locations->SetInAt(0, Location::RequiresRegister()); |
| 173 | locations->SetOut(Location::RequiresFpuRegister()); |
| 174 | } |
| 175 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 176 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 177 | Location input = locations->InAt(0); |
| 178 | Location output = locations->Out(); |
| 179 | __ Fmov(is64bit ? XRegisterFrom(output) : WRegisterFrom(output), |
| 180 | is64bit ? DRegisterFrom(input) : SRegisterFrom(input)); |
| 181 | } |
| 182 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 183 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 184 | Location input = locations->InAt(0); |
| 185 | Location output = locations->Out(); |
| 186 | __ Fmov(is64bit ? DRegisterFrom(output) : SRegisterFrom(output), |
| 187 | is64bit ? XRegisterFrom(input) : WRegisterFrom(input)); |
| 188 | } |
| 189 | |
| 190 | void IntrinsicLocationsBuilderARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 191 | CreateFPToIntLocations(arena_, invoke); |
| 192 | } |
| 193 | void IntrinsicLocationsBuilderARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 194 | CreateIntToFPLocations(arena_, invoke); |
| 195 | } |
| 196 | |
| 197 | void IntrinsicCodeGeneratorARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 198 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 199 | } |
| 200 | void IntrinsicCodeGeneratorARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 201 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void IntrinsicLocationsBuilderARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 205 | CreateFPToIntLocations(arena_, invoke); |
| 206 | } |
| 207 | void IntrinsicLocationsBuilderARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 208 | CreateIntToFPLocations(arena_, invoke); |
| 209 | } |
| 210 | |
| 211 | void IntrinsicCodeGeneratorARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 212 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 213 | } |
| 214 | void IntrinsicCodeGeneratorARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 215 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 219 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 220 | LocationSummary::kNoCall, |
| 221 | kIntrinsified); |
| 222 | locations->SetInAt(0, Location::RequiresRegister()); |
| 223 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 224 | } |
| 225 | |
| 226 | static void GenReverseBytes(LocationSummary* locations, |
| 227 | Primitive::Type type, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 228 | MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 229 | Location in = locations->InAt(0); |
| 230 | Location out = locations->Out(); |
| 231 | |
| 232 | switch (type) { |
| 233 | case Primitive::kPrimShort: |
| 234 | __ Rev16(WRegisterFrom(out), WRegisterFrom(in)); |
| 235 | __ Sxth(WRegisterFrom(out), WRegisterFrom(out)); |
| 236 | break; |
| 237 | case Primitive::kPrimInt: |
| 238 | case Primitive::kPrimLong: |
| 239 | __ Rev(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 240 | break; |
| 241 | default: |
| 242 | LOG(FATAL) << "Unexpected size for reverse-bytes: " << type; |
| 243 | UNREACHABLE(); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | void IntrinsicLocationsBuilderARM64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 248 | CreateIntToIntLocations(arena_, invoke); |
| 249 | } |
| 250 | |
| 251 | void IntrinsicCodeGeneratorARM64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 252 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 253 | } |
| 254 | |
| 255 | void IntrinsicLocationsBuilderARM64::VisitLongReverseBytes(HInvoke* invoke) { |
| 256 | CreateIntToIntLocations(arena_, invoke); |
| 257 | } |
| 258 | |
| 259 | void IntrinsicCodeGeneratorARM64::VisitLongReverseBytes(HInvoke* invoke) { |
| 260 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 261 | } |
| 262 | |
| 263 | void IntrinsicLocationsBuilderARM64::VisitShortReverseBytes(HInvoke* invoke) { |
| 264 | CreateIntToIntLocations(arena_, invoke); |
| 265 | } |
| 266 | |
| 267 | void IntrinsicCodeGeneratorARM64::VisitShortReverseBytes(HInvoke* invoke) { |
| 268 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetVIXLAssembler()); |
| 269 | } |
| 270 | |
Aart Bik | 7b56502 | 2016-01-28 14:36:22 -0800 | [diff] [blame] | 271 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 272 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 273 | LocationSummary::kNoCall, |
| 274 | kIntrinsified); |
| 275 | locations->SetInAt(0, Location::RequiresRegister()); |
| 276 | locations->SetInAt(1, Location::RequiresRegister()); |
| 277 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 278 | } |
| 279 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 280 | static void GenNumberOfLeadingZeros(LocationSummary* locations, |
| 281 | Primitive::Type type, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 282 | MacroAssembler* masm) { |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 283 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 284 | |
| 285 | Location in = locations->InAt(0); |
| 286 | Location out = locations->Out(); |
| 287 | |
| 288 | __ Clz(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 289 | } |
| 290 | |
| 291 | void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 292 | CreateIntToIntLocations(arena_, invoke); |
| 293 | } |
| 294 | |
| 295 | void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 296 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 297 | } |
| 298 | |
| 299 | void IntrinsicLocationsBuilderARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 300 | CreateIntToIntLocations(arena_, invoke); |
| 301 | } |
| 302 | |
| 303 | void IntrinsicCodeGeneratorARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 304 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 305 | } |
| 306 | |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 307 | static void GenNumberOfTrailingZeros(LocationSummary* locations, |
| 308 | Primitive::Type type, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 309 | MacroAssembler* masm) { |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 310 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 311 | |
| 312 | Location in = locations->InAt(0); |
| 313 | Location out = locations->Out(); |
| 314 | |
| 315 | __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 316 | __ Clz(RegisterFrom(out, type), RegisterFrom(out, type)); |
| 317 | } |
| 318 | |
| 319 | void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 320 | CreateIntToIntLocations(arena_, invoke); |
| 321 | } |
| 322 | |
| 323 | void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 324 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 325 | } |
| 326 | |
| 327 | void IntrinsicLocationsBuilderARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 328 | CreateIntToIntLocations(arena_, invoke); |
| 329 | } |
| 330 | |
| 331 | void IntrinsicCodeGeneratorARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 332 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 333 | } |
| 334 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 335 | static void GenReverse(LocationSummary* locations, |
| 336 | Primitive::Type type, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 337 | MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 338 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 339 | |
| 340 | Location in = locations->InAt(0); |
| 341 | Location out = locations->Out(); |
| 342 | |
| 343 | __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 344 | } |
| 345 | |
| 346 | void IntrinsicLocationsBuilderARM64::VisitIntegerReverse(HInvoke* invoke) { |
| 347 | CreateIntToIntLocations(arena_, invoke); |
| 348 | } |
| 349 | |
| 350 | void IntrinsicCodeGeneratorARM64::VisitIntegerReverse(HInvoke* invoke) { |
| 351 | GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 352 | } |
| 353 | |
| 354 | void IntrinsicLocationsBuilderARM64::VisitLongReverse(HInvoke* invoke) { |
| 355 | CreateIntToIntLocations(arena_, invoke); |
| 356 | } |
| 357 | |
| 358 | void IntrinsicCodeGeneratorARM64::VisitLongReverse(HInvoke* invoke) { |
| 359 | GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 360 | } |
| 361 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 362 | static void GenBitCount(HInvoke* instr, Primitive::Type type, MacroAssembler* masm) { |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 363 | DCHECK(Primitive::IsIntOrLongType(type)) << type; |
| 364 | DCHECK_EQ(instr->GetType(), Primitive::kPrimInt); |
| 365 | DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type); |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 366 | |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 367 | UseScratchRegisterScope temps(masm); |
| 368 | |
Nicolas Geoffray | 457413a | 2016-03-04 11:10:17 +0000 | [diff] [blame] | 369 | Register src = InputRegisterAt(instr, 0); |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 370 | Register dst = RegisterFrom(instr->GetLocations()->Out(), type); |
| 371 | FPRegister fpr = (type == Primitive::kPrimLong) ? temps.AcquireD() : temps.AcquireS(); |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 372 | |
| 373 | __ Fmov(fpr, src); |
Nicolas Geoffray | 457413a | 2016-03-04 11:10:17 +0000 | [diff] [blame] | 374 | __ Cnt(fpr.V8B(), fpr.V8B()); |
| 375 | __ Addv(fpr.B(), fpr.V8B()); |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 376 | __ Fmov(dst, fpr); |
| 377 | } |
| 378 | |
| 379 | void IntrinsicLocationsBuilderARM64::VisitLongBitCount(HInvoke* invoke) { |
| 380 | CreateIntToIntLocations(arena_, invoke); |
| 381 | } |
| 382 | |
| 383 | void IntrinsicCodeGeneratorARM64::VisitLongBitCount(HInvoke* invoke) { |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 384 | GenBitCount(invoke, Primitive::kPrimLong, GetVIXLAssembler()); |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void IntrinsicLocationsBuilderARM64::VisitIntegerBitCount(HInvoke* invoke) { |
| 388 | CreateIntToIntLocations(arena_, invoke); |
| 389 | } |
| 390 | |
| 391 | void IntrinsicCodeGeneratorARM64::VisitIntegerBitCount(HInvoke* invoke) { |
Roland Levillain | fa3912e | 2016-04-01 18:21:55 +0100 | [diff] [blame] | 392 | GenBitCount(invoke, Primitive::kPrimInt, GetVIXLAssembler()); |
xueliang.zhong | 49924c9 | 2016-03-03 10:52:51 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 395 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 396 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 397 | LocationSummary::kNoCall, |
| 398 | kIntrinsified); |
| 399 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 400 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 401 | } |
| 402 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 403 | static void MathAbsFP(LocationSummary* locations, bool is64bit, MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 404 | Location in = locations->InAt(0); |
| 405 | Location out = locations->Out(); |
| 406 | |
| 407 | FPRegister in_reg = is64bit ? DRegisterFrom(in) : SRegisterFrom(in); |
| 408 | FPRegister out_reg = is64bit ? DRegisterFrom(out) : SRegisterFrom(out); |
| 409 | |
| 410 | __ Fabs(out_reg, in_reg); |
| 411 | } |
| 412 | |
| 413 | void IntrinsicLocationsBuilderARM64::VisitMathAbsDouble(HInvoke* invoke) { |
| 414 | CreateFPToFPLocations(arena_, invoke); |
| 415 | } |
| 416 | |
| 417 | void IntrinsicCodeGeneratorARM64::VisitMathAbsDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 418 | MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void IntrinsicLocationsBuilderARM64::VisitMathAbsFloat(HInvoke* invoke) { |
| 422 | CreateFPToFPLocations(arena_, invoke); |
| 423 | } |
| 424 | |
| 425 | void IntrinsicCodeGeneratorARM64::VisitMathAbsFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 426 | MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 430 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 431 | LocationSummary::kNoCall, |
| 432 | kIntrinsified); |
| 433 | locations->SetInAt(0, Location::RequiresRegister()); |
| 434 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 435 | } |
| 436 | |
| 437 | static void GenAbsInteger(LocationSummary* locations, |
| 438 | bool is64bit, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 439 | MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 440 | Location in = locations->InAt(0); |
| 441 | Location output = locations->Out(); |
| 442 | |
| 443 | Register in_reg = is64bit ? XRegisterFrom(in) : WRegisterFrom(in); |
| 444 | Register out_reg = is64bit ? XRegisterFrom(output) : WRegisterFrom(output); |
| 445 | |
| 446 | __ Cmp(in_reg, Operand(0)); |
| 447 | __ Cneg(out_reg, in_reg, lt); |
| 448 | } |
| 449 | |
| 450 | void IntrinsicLocationsBuilderARM64::VisitMathAbsInt(HInvoke* invoke) { |
| 451 | CreateIntToInt(arena_, invoke); |
| 452 | } |
| 453 | |
| 454 | void IntrinsicCodeGeneratorARM64::VisitMathAbsInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 455 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | void IntrinsicLocationsBuilderARM64::VisitMathAbsLong(HInvoke* invoke) { |
| 459 | CreateIntToInt(arena_, invoke); |
| 460 | } |
| 461 | |
| 462 | void IntrinsicCodeGeneratorARM64::VisitMathAbsLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 463 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void GenMinMaxFP(LocationSummary* locations, |
| 467 | bool is_min, |
| 468 | bool is_double, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 469 | MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 470 | Location op1 = locations->InAt(0); |
| 471 | Location op2 = locations->InAt(1); |
| 472 | Location out = locations->Out(); |
| 473 | |
| 474 | FPRegister op1_reg = is_double ? DRegisterFrom(op1) : SRegisterFrom(op1); |
| 475 | FPRegister op2_reg = is_double ? DRegisterFrom(op2) : SRegisterFrom(op2); |
| 476 | FPRegister out_reg = is_double ? DRegisterFrom(out) : SRegisterFrom(out); |
| 477 | if (is_min) { |
| 478 | __ Fmin(out_reg, op1_reg, op2_reg); |
| 479 | } else { |
| 480 | __ Fmax(out_reg, op1_reg, op2_reg); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 485 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 486 | LocationSummary::kNoCall, |
| 487 | kIntrinsified); |
| 488 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 489 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 490 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 491 | } |
| 492 | |
| 493 | void IntrinsicLocationsBuilderARM64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 494 | CreateFPFPToFPLocations(arena_, invoke); |
| 495 | } |
| 496 | |
| 497 | void IntrinsicCodeGeneratorARM64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 498 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | void IntrinsicLocationsBuilderARM64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 502 | CreateFPFPToFPLocations(arena_, invoke); |
| 503 | } |
| 504 | |
| 505 | void IntrinsicCodeGeneratorARM64::VisitMathMinFloatFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 506 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | void IntrinsicLocationsBuilderARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 510 | CreateFPFPToFPLocations(arena_, invoke); |
| 511 | } |
| 512 | |
| 513 | void IntrinsicCodeGeneratorARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 514 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ false, /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | void IntrinsicLocationsBuilderARM64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 518 | CreateFPFPToFPLocations(arena_, invoke); |
| 519 | } |
| 520 | |
| 521 | void IntrinsicCodeGeneratorARM64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 522 | GenMinMaxFP( |
| 523 | invoke->GetLocations(), /* is_min */ false, /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void GenMinMax(LocationSummary* locations, |
| 527 | bool is_min, |
| 528 | bool is_long, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 529 | MacroAssembler* masm) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 530 | Location op1 = locations->InAt(0); |
| 531 | Location op2 = locations->InAt(1); |
| 532 | Location out = locations->Out(); |
| 533 | |
| 534 | Register op1_reg = is_long ? XRegisterFrom(op1) : WRegisterFrom(op1); |
| 535 | Register op2_reg = is_long ? XRegisterFrom(op2) : WRegisterFrom(op2); |
| 536 | Register out_reg = is_long ? XRegisterFrom(out) : WRegisterFrom(out); |
| 537 | |
| 538 | __ Cmp(op1_reg, op2_reg); |
| 539 | __ Csel(out_reg, op1_reg, op2_reg, is_min ? lt : gt); |
| 540 | } |
| 541 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 542 | void IntrinsicLocationsBuilderARM64::VisitMathMinIntInt(HInvoke* invoke) { |
| 543 | CreateIntIntToIntLocations(arena_, invoke); |
| 544 | } |
| 545 | |
| 546 | void IntrinsicCodeGeneratorARM64::VisitMathMinIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 547 | GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | void IntrinsicLocationsBuilderARM64::VisitMathMinLongLong(HInvoke* invoke) { |
| 551 | CreateIntIntToIntLocations(arena_, invoke); |
| 552 | } |
| 553 | |
| 554 | void IntrinsicCodeGeneratorARM64::VisitMathMinLongLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 555 | GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void IntrinsicLocationsBuilderARM64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 559 | CreateIntIntToIntLocations(arena_, invoke); |
| 560 | } |
| 561 | |
| 562 | void IntrinsicCodeGeneratorARM64::VisitMathMaxIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 563 | GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | void IntrinsicLocationsBuilderARM64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 567 | CreateIntIntToIntLocations(arena_, invoke); |
| 568 | } |
| 569 | |
| 570 | void IntrinsicCodeGeneratorARM64::VisitMathMaxLongLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 571 | GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | void IntrinsicLocationsBuilderARM64::VisitMathSqrt(HInvoke* invoke) { |
| 575 | CreateFPToFPLocations(arena_, invoke); |
| 576 | } |
| 577 | |
| 578 | void IntrinsicCodeGeneratorARM64::VisitMathSqrt(HInvoke* invoke) { |
| 579 | LocationSummary* locations = invoke->GetLocations(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 580 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 581 | __ Fsqrt(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 582 | } |
| 583 | |
| 584 | void IntrinsicLocationsBuilderARM64::VisitMathCeil(HInvoke* invoke) { |
| 585 | CreateFPToFPLocations(arena_, invoke); |
| 586 | } |
| 587 | |
| 588 | void IntrinsicCodeGeneratorARM64::VisitMathCeil(HInvoke* invoke) { |
| 589 | LocationSummary* locations = invoke->GetLocations(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 590 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 591 | __ Frintp(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 592 | } |
| 593 | |
| 594 | void IntrinsicLocationsBuilderARM64::VisitMathFloor(HInvoke* invoke) { |
| 595 | CreateFPToFPLocations(arena_, invoke); |
| 596 | } |
| 597 | |
| 598 | void IntrinsicCodeGeneratorARM64::VisitMathFloor(HInvoke* invoke) { |
| 599 | LocationSummary* locations = invoke->GetLocations(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 600 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 601 | __ Frintm(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 602 | } |
| 603 | |
| 604 | void IntrinsicLocationsBuilderARM64::VisitMathRint(HInvoke* invoke) { |
| 605 | CreateFPToFPLocations(arena_, invoke); |
| 606 | } |
| 607 | |
| 608 | void IntrinsicCodeGeneratorARM64::VisitMathRint(HInvoke* invoke) { |
| 609 | LocationSummary* locations = invoke->GetLocations(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 610 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 611 | __ Frintn(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 612 | } |
| 613 | |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 614 | static void CreateFPToIntPlusFPTempLocations(ArenaAllocator* arena, HInvoke* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 615 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 616 | LocationSummary::kNoCall, |
| 617 | kIntrinsified); |
| 618 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 619 | locations->SetOut(Location::RequiresRegister()); |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 620 | locations->AddTemp(Location::RequiresFpuRegister()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 621 | } |
| 622 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 623 | static void GenMathRound(HInvoke* invoke, bool is_double, vixl::aarch64::MacroAssembler* masm) { |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 624 | // Java 8 API definition for Math.round(): |
| 625 | // Return the closest long or int to the argument, with ties rounding to positive infinity. |
| 626 | // |
| 627 | // There is no single instruction in ARMv8 that can support the above definition. |
| 628 | // We choose to use FCVTAS here, because it has closest semantic. |
| 629 | // FCVTAS performs rounding to nearest integer, ties away from zero. |
| 630 | // For most inputs (positive values, zero or NaN), this instruction is enough. |
| 631 | // We only need a few handling code after FCVTAS if the input is negative half value. |
| 632 | // |
| 633 | // The reason why we didn't choose FCVTPS instruction here is that |
| 634 | // although it performs rounding toward positive infinity, it doesn't perform rounding to nearest. |
| 635 | // For example, FCVTPS(-1.9) = -1 and FCVTPS(1.1) = 2. |
| 636 | // If we were using this instruction, for most inputs, more handling code would be needed. |
| 637 | LocationSummary* l = invoke->GetLocations(); |
| 638 | FPRegister in_reg = is_double ? DRegisterFrom(l->InAt(0)) : SRegisterFrom(l->InAt(0)); |
| 639 | FPRegister tmp_fp = is_double ? DRegisterFrom(l->GetTemp(0)) : SRegisterFrom(l->GetTemp(0)); |
| 640 | Register out_reg = is_double ? XRegisterFrom(l->Out()) : WRegisterFrom(l->Out()); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 641 | vixl::aarch64::Label done; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 642 | |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 643 | // Round to nearest integer, ties away from zero. |
| 644 | __ Fcvtas(out_reg, in_reg); |
| 645 | |
| 646 | // For positive values, zero or NaN inputs, rounding is done. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 647 | __ Tbz(out_reg, out_reg.GetSizeInBits() - 1, &done); |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 648 | |
| 649 | // Handle input < 0 cases. |
| 650 | // If input is negative but not a tie, previous result (round to nearest) is valid. |
| 651 | // If input is a negative tie, out_reg += 1. |
| 652 | __ Frinta(tmp_fp, in_reg); |
| 653 | __ Fsub(tmp_fp, in_reg, tmp_fp); |
| 654 | __ Fcmp(tmp_fp, 0.5); |
| 655 | __ Cinc(out_reg, out_reg, eq); |
| 656 | |
| 657 | __ Bind(&done); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | void IntrinsicLocationsBuilderARM64::VisitMathRoundDouble(HInvoke* invoke) { |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 661 | CreateFPToIntPlusFPTempLocations(arena_, invoke); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | void IntrinsicCodeGeneratorARM64::VisitMathRoundDouble(HInvoke* invoke) { |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 665 | GenMathRound(invoke, /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | void IntrinsicLocationsBuilderARM64::VisitMathRoundFloat(HInvoke* invoke) { |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 669 | CreateFPToIntPlusFPTempLocations(arena_, invoke); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | void IntrinsicCodeGeneratorARM64::VisitMathRoundFloat(HInvoke* invoke) { |
xueliang.zhong | d1e153c | 2016-05-27 18:56:13 +0100 | [diff] [blame] | 673 | GenMathRound(invoke, /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 677 | CreateIntToIntLocations(arena_, invoke); |
| 678 | } |
| 679 | |
| 680 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekByte(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 681 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 682 | __ Ldrsb(WRegisterFrom(invoke->GetLocations()->Out()), |
| 683 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 684 | } |
| 685 | |
| 686 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 687 | CreateIntToIntLocations(arena_, invoke); |
| 688 | } |
| 689 | |
| 690 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 691 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 692 | __ Ldr(WRegisterFrom(invoke->GetLocations()->Out()), |
| 693 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 694 | } |
| 695 | |
| 696 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 697 | CreateIntToIntLocations(arena_, invoke); |
| 698 | } |
| 699 | |
| 700 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 701 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 702 | __ Ldr(XRegisterFrom(invoke->GetLocations()->Out()), |
| 703 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 704 | } |
| 705 | |
| 706 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 707 | CreateIntToIntLocations(arena_, invoke); |
| 708 | } |
| 709 | |
| 710 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 711 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 712 | __ Ldrsh(WRegisterFrom(invoke->GetLocations()->Out()), |
| 713 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 714 | } |
| 715 | |
| 716 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 717 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 718 | LocationSummary::kNoCall, |
| 719 | kIntrinsified); |
| 720 | locations->SetInAt(0, Location::RequiresRegister()); |
| 721 | locations->SetInAt(1, Location::RequiresRegister()); |
| 722 | } |
| 723 | |
| 724 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 725 | CreateIntIntToVoidLocations(arena_, invoke); |
| 726 | } |
| 727 | |
| 728 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeByte(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 729 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 730 | __ Strb(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 731 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 732 | } |
| 733 | |
| 734 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 735 | CreateIntIntToVoidLocations(arena_, invoke); |
| 736 | } |
| 737 | |
| 738 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 739 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 740 | __ Str(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 741 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 742 | } |
| 743 | |
| 744 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 745 | CreateIntIntToVoidLocations(arena_, invoke); |
| 746 | } |
| 747 | |
| 748 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 749 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 750 | __ Str(XRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 751 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 752 | } |
| 753 | |
| 754 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 755 | CreateIntIntToVoidLocations(arena_, invoke); |
| 756 | } |
| 757 | |
| 758 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 759 | MacroAssembler* masm = GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 760 | __ Strh(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 761 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 762 | } |
| 763 | |
| 764 | void IntrinsicLocationsBuilderARM64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 765 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 766 | LocationSummary::kNoCall, |
| 767 | kIntrinsified); |
| 768 | locations->SetOut(Location::RequiresRegister()); |
| 769 | } |
| 770 | |
| 771 | void IntrinsicCodeGeneratorARM64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 772 | codegen_->Load(Primitive::kPrimNot, WRegisterFrom(invoke->GetLocations()->Out()), |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 773 | MemOperand(tr, Thread::PeerOffset<kArm64PointerSize>().Int32Value())); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | static void GenUnsafeGet(HInvoke* invoke, |
| 777 | Primitive::Type type, |
| 778 | bool is_volatile, |
| 779 | CodeGeneratorARM64* codegen) { |
| 780 | LocationSummary* locations = invoke->GetLocations(); |
| 781 | DCHECK((type == Primitive::kPrimInt) || |
| 782 | (type == Primitive::kPrimLong) || |
| 783 | (type == Primitive::kPrimNot)); |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame^] | 784 | MacroAssembler* masm = codegen->GetVIXLAssembler(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 785 | Location base_loc = locations->InAt(1); |
| 786 | Register base = WRegisterFrom(base_loc); // Object pointer. |
| 787 | Location offset_loc = locations->InAt(2); |
| 788 | Register offset = XRegisterFrom(offset_loc); // Long offset. |
| 789 | Location trg_loc = locations->Out(); |
| 790 | Register trg = RegisterFrom(trg_loc, type); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 791 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 792 | if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) { |
| 793 | // UnsafeGetObject/UnsafeGetObjectVolatile with Baker's read barrier case. |
| 794 | UseScratchRegisterScope temps(masm); |
| 795 | Register temp = temps.AcquireW(); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 796 | codegen->GenerateReferenceLoadWithBakerReadBarrier(invoke, |
| 797 | trg_loc, |
| 798 | base, |
| 799 | /* offset */ 0U, |
| 800 | /* index */ offset_loc, |
| 801 | /* scale_factor */ 0U, |
| 802 | temp, |
| 803 | /* needs_null_check */ false, |
| 804 | is_volatile); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 805 | } else { |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 806 | // Other cases. |
| 807 | MemOperand mem_op(base.X(), offset); |
| 808 | if (is_volatile) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 809 | codegen->LoadAcquire(invoke, trg, mem_op, /* needs_null_check */ true); |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 810 | } else { |
| 811 | codegen->Load(type, trg, mem_op); |
| 812 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 813 | |
Roland Levillain | 4401586 | 2016-01-22 11:47:17 +0000 | [diff] [blame] | 814 | if (type == Primitive::kPrimNot) { |
| 815 | DCHECK(trg.IsW()); |
| 816 | codegen->MaybeGenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc); |
| 817 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 818 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 822 | bool can_call = kEmitCompilerReadBarrier && |
| 823 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 824 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 825 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 826 | can_call ? |
| 827 | LocationSummary::kCallOnSlowPath : |
| 828 | LocationSummary::kNoCall, |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 829 | kIntrinsified); |
| 830 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 831 | locations->SetInAt(1, Location::RequiresRegister()); |
| 832 | locations->SetInAt(2, Location::RequiresRegister()); |
Roland Levillain | bfea335 | 2016-06-23 13:48:47 +0100 | [diff] [blame] | 833 | locations->SetOut(Location::RequiresRegister(), |
| 834 | can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGet(HInvoke* invoke) { |
| 838 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 839 | } |
| 840 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 841 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 842 | } |
| 843 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 844 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 845 | } |
| 846 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 847 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 848 | } |
| 849 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 850 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 851 | } |
| 852 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 853 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 854 | } |
| 855 | |
| 856 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 857 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 858 | } |
| 859 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 860 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 861 | } |
| 862 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 863 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 864 | } |
| 865 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 866 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 867 | } |
| 868 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 869 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 870 | } |
| 871 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 872 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) { |
| 876 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 877 | LocationSummary::kNoCall, |
| 878 | kIntrinsified); |
| 879 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 880 | locations->SetInAt(1, Location::RequiresRegister()); |
| 881 | locations->SetInAt(2, Location::RequiresRegister()); |
| 882 | locations->SetInAt(3, Location::RequiresRegister()); |
| 883 | } |
| 884 | |
| 885 | void IntrinsicLocationsBuilderARM64::VisitUnsafePut(HInvoke* invoke) { |
| 886 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 887 | } |
| 888 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 889 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 890 | } |
| 891 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 892 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 893 | } |
| 894 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObject(HInvoke* invoke) { |
| 895 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 896 | } |
| 897 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 898 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 899 | } |
| 900 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 901 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 902 | } |
| 903 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLong(HInvoke* invoke) { |
| 904 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 905 | } |
| 906 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 907 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 908 | } |
| 909 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 910 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 911 | } |
| 912 | |
| 913 | static void GenUnsafePut(LocationSummary* locations, |
| 914 | Primitive::Type type, |
| 915 | bool is_volatile, |
| 916 | bool is_ordered, |
| 917 | CodeGeneratorARM64* codegen) { |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame^] | 918 | MacroAssembler* masm = codegen->GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 919 | |
| 920 | Register base = WRegisterFrom(locations->InAt(1)); // Object pointer. |
| 921 | Register offset = XRegisterFrom(locations->InAt(2)); // Long offset. |
| 922 | Register value = RegisterFrom(locations->InAt(3), type); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 923 | Register source = value; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 924 | MemOperand mem_op(base.X(), offset); |
| 925 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 926 | { |
| 927 | // We use a block to end the scratch scope before the write barrier, thus |
| 928 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 929 | UseScratchRegisterScope temps(masm); |
| 930 | |
| 931 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 932 | DCHECK(value.IsW()); |
| 933 | Register temp = temps.AcquireW(); |
| 934 | __ Mov(temp.W(), value.W()); |
| 935 | codegen->GetAssembler()->PoisonHeapReference(temp.W()); |
| 936 | source = temp; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 937 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 938 | |
| 939 | if (is_volatile || is_ordered) { |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 940 | codegen->StoreRelease(type, source, mem_op); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 941 | } else { |
| 942 | codegen->Store(type, source, mem_op); |
| 943 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | if (type == Primitive::kPrimNot) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 947 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 948 | codegen->MarkGCCard(base, value, value_can_be_null); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
| 952 | void IntrinsicCodeGeneratorARM64::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 953 | GenUnsafePut(invoke->GetLocations(), |
| 954 | Primitive::kPrimInt, |
| 955 | /* is_volatile */ false, |
| 956 | /* is_ordered */ false, |
| 957 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 958 | } |
| 959 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 960 | GenUnsafePut(invoke->GetLocations(), |
| 961 | Primitive::kPrimInt, |
| 962 | /* is_volatile */ false, |
| 963 | /* is_ordered */ true, |
| 964 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 965 | } |
| 966 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 967 | GenUnsafePut(invoke->GetLocations(), |
| 968 | Primitive::kPrimInt, |
| 969 | /* is_volatile */ true, |
| 970 | /* is_ordered */ false, |
| 971 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 972 | } |
| 973 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 974 | GenUnsafePut(invoke->GetLocations(), |
| 975 | Primitive::kPrimNot, |
| 976 | /* is_volatile */ false, |
| 977 | /* is_ordered */ false, |
| 978 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 979 | } |
| 980 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 981 | GenUnsafePut(invoke->GetLocations(), |
| 982 | Primitive::kPrimNot, |
| 983 | /* is_volatile */ false, |
| 984 | /* is_ordered */ true, |
| 985 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 986 | } |
| 987 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 988 | GenUnsafePut(invoke->GetLocations(), |
| 989 | Primitive::kPrimNot, |
| 990 | /* is_volatile */ true, |
| 991 | /* is_ordered */ false, |
| 992 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 993 | } |
| 994 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 995 | GenUnsafePut(invoke->GetLocations(), |
| 996 | Primitive::kPrimLong, |
| 997 | /* is_volatile */ false, |
| 998 | /* is_ordered */ false, |
| 999 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1000 | } |
| 1001 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1002 | GenUnsafePut(invoke->GetLocations(), |
| 1003 | Primitive::kPrimLong, |
| 1004 | /* is_volatile */ false, |
| 1005 | /* is_ordered */ true, |
| 1006 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1007 | } |
| 1008 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1009 | GenUnsafePut(invoke->GetLocations(), |
| 1010 | Primitive::kPrimLong, |
| 1011 | /* is_volatile */ true, |
| 1012 | /* is_ordered */ false, |
| 1013 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1016 | static void CreateIntIntIntIntIntToInt(ArenaAllocator* arena, |
| 1017 | HInvoke* invoke, |
| 1018 | Primitive::Type type) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1019 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 1020 | LocationSummary::kNoCall, |
| 1021 | kIntrinsified); |
| 1022 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 1023 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1024 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1025 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1026 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1027 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1028 | // If heap poisoning is enabled, we don't want the unpoisoning |
| 1029 | // operations to potentially clobber the output. |
| 1030 | Location::OutputOverlap overlaps = (kPoisonHeapReferences && type == Primitive::kPrimNot) |
| 1031 | ? Location::kOutputOverlap |
| 1032 | : Location::kNoOutputOverlap; |
| 1033 | locations->SetOut(Location::RequiresRegister(), overlaps); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM64* codegen) { |
Alexandre Rames | 087930f | 2016-08-02 13:45:28 +0100 | [diff] [blame^] | 1037 | MacroAssembler* masm = codegen->GetVIXLAssembler(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1038 | |
| 1039 | Register out = WRegisterFrom(locations->Out()); // Boolean result. |
| 1040 | |
| 1041 | Register base = WRegisterFrom(locations->InAt(1)); // Object pointer. |
| 1042 | Register offset = XRegisterFrom(locations->InAt(2)); // Long offset. |
| 1043 | Register expected = RegisterFrom(locations->InAt(3), type); // Expected. |
| 1044 | Register value = RegisterFrom(locations->InAt(4), type); // Value. |
| 1045 | |
| 1046 | // This needs to be before the temp registers, as MarkGCCard also uses VIXL temps. |
| 1047 | if (type == Primitive::kPrimNot) { |
| 1048 | // Mark card for object assuming new value is stored. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 1049 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 1050 | codegen->MarkGCCard(base, value, value_can_be_null); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | UseScratchRegisterScope temps(masm); |
| 1054 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1055 | Register tmp_value = temps.AcquireSameSizeAs(value); // Value in memory. |
| 1056 | |
| 1057 | Register tmp_32 = tmp_value.W(); |
| 1058 | |
| 1059 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1060 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1061 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1062 | codegen->GetAssembler()->PoisonHeapReference(expected); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1063 | if (value.Is(expected)) { |
| 1064 | // Do not poison `value`, as it is the same register as |
| 1065 | // `expected`, which has just been poisoned. |
| 1066 | } else { |
| 1067 | codegen->GetAssembler()->PoisonHeapReference(value); |
| 1068 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1069 | } |
| 1070 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1071 | // do { |
| 1072 | // tmp_value = [tmp_ptr] - expected; |
| 1073 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1074 | // result = tmp_value != 0; |
| 1075 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1076 | vixl::aarch64::Label loop_head, exit_loop; |
Serban Constantinescu | 4a6a67c | 2016-01-27 09:19:56 +0000 | [diff] [blame] | 1077 | __ Bind(&loop_head); |
| 1078 | // TODO: When `type == Primitive::kPrimNot`, add a read barrier for |
| 1079 | // the reference stored in the object before attempting the CAS, |
| 1080 | // similar to the one in the art::Unsafe_compareAndSwapObject JNI |
| 1081 | // implementation. |
| 1082 | // |
| 1083 | // Note that this code is not (yet) used when read barriers are |
| 1084 | // enabled (see IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject). |
| 1085 | DCHECK(!(type == Primitive::kPrimNot && kEmitCompilerReadBarrier)); |
| 1086 | __ Ldaxr(tmp_value, MemOperand(tmp_ptr)); |
| 1087 | __ Cmp(tmp_value, expected); |
| 1088 | __ B(&exit_loop, ne); |
| 1089 | __ Stlxr(tmp_32, value, MemOperand(tmp_ptr)); |
| 1090 | __ Cbnz(tmp_32, &loop_head); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1091 | __ Bind(&exit_loop); |
| 1092 | __ Cset(out, eq); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1093 | |
| 1094 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1095 | codegen->GetAssembler()->UnpoisonHeapReference(expected); |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1096 | if (value.Is(expected)) { |
| 1097 | // Do not unpoison `value`, as it is the same register as |
| 1098 | // `expected`, which has just been unpoisoned. |
| 1099 | } else { |
| 1100 | codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1101 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1102 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASInt(HInvoke* invoke) { |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1106 | CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimInt); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1107 | } |
| 1108 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASLong(HInvoke* invoke) { |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1109 | CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimLong); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1110 | } |
| 1111 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 1112 | // The UnsafeCASObject intrinsic is missing a read barrier, and |
| 1113 | // therefore sometimes does not work as expected (b/25883050). |
| 1114 | // Turn it off temporarily as a quick fix, until the read barrier is |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1115 | // implemented (see TODO in GenCAS). |
Roland Levillain | 391b866 | 2015-12-18 11:43:38 +0000 | [diff] [blame] | 1116 | // |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1117 | // TODO(rpl): Implement read barrier support in GenCAS and re-enable |
| 1118 | // this intrinsic. |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1119 | if (kEmitCompilerReadBarrier) { |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 1120 | return; |
| 1121 | } |
| 1122 | |
Roland Levillain | 2e50ecb | 2016-01-27 14:08:33 +0000 | [diff] [blame] | 1123 | CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimNot); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASInt(HInvoke* invoke) { |
| 1127 | GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_); |
| 1128 | } |
| 1129 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASLong(HInvoke* invoke) { |
| 1130 | GenCas(invoke->GetLocations(), Primitive::kPrimLong, codegen_); |
| 1131 | } |
| 1132 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 1133 | // The UnsafeCASObject intrinsic is missing a read barrier, and |
| 1134 | // therefore sometimes does not work as expected (b/25883050). |
| 1135 | // Turn it off temporarily as a quick fix, until the read barrier is |
| 1136 | // implemented (see TODO in GenCAS). |
| 1137 | // |
| 1138 | // TODO(rpl): Implement read barrier support in GenCAS and re-enable |
| 1139 | // this intrinsic. |
| 1140 | DCHECK(!kEmitCompilerReadBarrier); |
| 1141 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1142 | GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_); |
| 1143 | } |
| 1144 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1145 | void IntrinsicLocationsBuilderARM64::VisitStringCompareTo(HInvoke* invoke) { |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1146 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1147 | invoke->InputAt(1)->CanBeNull() |
| 1148 | ? LocationSummary::kCallOnSlowPath |
| 1149 | : LocationSummary::kNoCall, |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1150 | kIntrinsified); |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1151 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1152 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1153 | locations->AddTemp(Location::RequiresRegister()); |
| 1154 | locations->AddTemp(Location::RequiresRegister()); |
| 1155 | locations->AddTemp(Location::RequiresRegister()); |
| 1156 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | void IntrinsicCodeGeneratorARM64::VisitStringCompareTo(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1160 | MacroAssembler* masm = GetVIXLAssembler(); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1161 | LocationSummary* locations = invoke->GetLocations(); |
| 1162 | |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1163 | Register str = XRegisterFrom(locations->InAt(0)); |
| 1164 | Register arg = XRegisterFrom(locations->InAt(1)); |
| 1165 | Register out = OutputRegister(invoke); |
| 1166 | |
| 1167 | Register temp0 = WRegisterFrom(locations->GetTemp(0)); |
| 1168 | Register temp1 = WRegisterFrom(locations->GetTemp(1)); |
| 1169 | Register temp2 = WRegisterFrom(locations->GetTemp(2)); |
| 1170 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1171 | vixl::aarch64::Label loop; |
| 1172 | vixl::aarch64::Label find_char_diff; |
| 1173 | vixl::aarch64::Label end; |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1174 | |
| 1175 | // Get offsets of count and value fields within a string object. |
| 1176 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1177 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1178 | |
Nicolas Geoffray | 512e04d | 2015-03-27 17:21:24 +0000 | [diff] [blame] | 1179 | // Note that the null check must have been done earlier. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1180 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1181 | |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1182 | // Take slow path and throw if input can be and is null. |
| 1183 | SlowPathCodeARM64* slow_path = nullptr; |
| 1184 | const bool can_slow_path = invoke->InputAt(1)->CanBeNull(); |
| 1185 | if (can_slow_path) { |
| 1186 | slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1187 | codegen_->AddSlowPath(slow_path); |
| 1188 | __ Cbz(arg, slow_path->GetEntryLabel()); |
| 1189 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1190 | |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1191 | // Reference equality check, return 0 if same reference. |
| 1192 | __ Subs(out, str, arg); |
| 1193 | __ B(&end, eq); |
| 1194 | // Load lengths of this and argument strings. |
| 1195 | __ Ldr(temp0, MemOperand(str.X(), count_offset)); |
| 1196 | __ Ldr(temp1, MemOperand(arg.X(), count_offset)); |
| 1197 | // Return zero if both strings are empty. |
| 1198 | __ Orr(out, temp0, temp1); |
| 1199 | __ Cbz(out, &end); |
| 1200 | // out = length diff. |
| 1201 | __ Subs(out, temp0, temp1); |
| 1202 | // temp2 = min(len(str), len(arg)). |
| 1203 | __ Csel(temp2, temp1, temp0, ge); |
| 1204 | // Shorter string is empty? |
| 1205 | __ Cbz(temp2, &end); |
| 1206 | |
| 1207 | // Store offset of string value in preparation for comparison loop. |
| 1208 | __ Mov(temp1, value_offset); |
| 1209 | |
| 1210 | UseScratchRegisterScope scratch_scope(masm); |
| 1211 | Register temp4 = scratch_scope.AcquireX(); |
| 1212 | |
| 1213 | // Assertions that must hold in order to compare strings 4 characters at a time. |
| 1214 | DCHECK_ALIGNED(value_offset, 8); |
| 1215 | static_assert(IsAligned<8>(kObjectAlignment), "String of odd length is not zero padded"); |
| 1216 | |
| 1217 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 1218 | DCHECK_EQ(char_size, 2u); |
| 1219 | |
| 1220 | // Promote temp0 to an X reg, ready for LDR. |
| 1221 | temp0 = temp0.X(); |
| 1222 | |
| 1223 | // Loop to compare 4x16-bit characters at a time (ok because of string data alignment). |
| 1224 | __ Bind(&loop); |
| 1225 | __ Ldr(temp4, MemOperand(str.X(), temp1)); |
| 1226 | __ Ldr(temp0, MemOperand(arg.X(), temp1)); |
| 1227 | __ Cmp(temp4, temp0); |
| 1228 | __ B(ne, &find_char_diff); |
| 1229 | __ Add(temp1, temp1, char_size * 4); |
| 1230 | __ Subs(temp2, temp2, 4); |
| 1231 | __ B(gt, &loop); |
| 1232 | __ B(&end); |
| 1233 | |
| 1234 | // Promote temp1 to an X reg, ready for EOR. |
| 1235 | temp1 = temp1.X(); |
| 1236 | |
| 1237 | // Find the single 16-bit character difference. |
| 1238 | __ Bind(&find_char_diff); |
| 1239 | // Get the bit position of the first character that differs. |
| 1240 | __ Eor(temp1, temp0, temp4); |
| 1241 | __ Rbit(temp1, temp1); |
| 1242 | __ Clz(temp1, temp1); |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1243 | // If the number of 16-bit chars remaining <= the index where the difference occurs (0-3), then |
| 1244 | // the difference occurs outside the remaining string data, so just return length diff (out). |
| 1245 | __ Cmp(temp2, Operand(temp1, LSR, 4)); |
| 1246 | __ B(le, &end); |
| 1247 | // Extract the characters and calculate the difference. |
Scott Wakeling | e5ed20b | 2016-05-20 10:41:38 +0100 | [diff] [blame] | 1248 | __ Bic(temp1, temp1, 0xf); |
Scott Wakeling | 1f36f41 | 2016-04-21 11:13:45 +0100 | [diff] [blame] | 1249 | __ Lsr(temp0, temp0, temp1); |
| 1250 | __ Lsr(temp4, temp4, temp1); |
| 1251 | __ And(temp4, temp4, 0xffff); |
| 1252 | __ Sub(out, temp4, Operand(temp0, UXTH)); |
| 1253 | |
| 1254 | __ Bind(&end); |
| 1255 | |
| 1256 | if (can_slow_path) { |
| 1257 | __ Bind(slow_path->GetExitLabel()); |
| 1258 | } |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1259 | } |
| 1260 | |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1261 | void IntrinsicLocationsBuilderARM64::VisitStringEquals(HInvoke* invoke) { |
| 1262 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1263 | LocationSummary::kNoCall, |
| 1264 | kIntrinsified); |
| 1265 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1266 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1267 | // Temporary registers to store lengths of strings and for calculations. |
| 1268 | locations->AddTemp(Location::RequiresRegister()); |
| 1269 | locations->AddTemp(Location::RequiresRegister()); |
| 1270 | |
| 1271 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1272 | } |
| 1273 | |
| 1274 | void IntrinsicCodeGeneratorARM64::VisitStringEquals(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1275 | MacroAssembler* masm = GetVIXLAssembler(); |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1276 | LocationSummary* locations = invoke->GetLocations(); |
| 1277 | |
| 1278 | Register str = WRegisterFrom(locations->InAt(0)); |
| 1279 | Register arg = WRegisterFrom(locations->InAt(1)); |
| 1280 | Register out = XRegisterFrom(locations->Out()); |
| 1281 | |
| 1282 | UseScratchRegisterScope scratch_scope(masm); |
| 1283 | Register temp = scratch_scope.AcquireW(); |
| 1284 | Register temp1 = WRegisterFrom(locations->GetTemp(0)); |
| 1285 | Register temp2 = WRegisterFrom(locations->GetTemp(1)); |
| 1286 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1287 | vixl::aarch64::Label loop; |
| 1288 | vixl::aarch64::Label end; |
| 1289 | vixl::aarch64::Label return_true; |
| 1290 | vixl::aarch64::Label return_false; |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1291 | |
| 1292 | // Get offsets of count, value, and class fields within a string object. |
| 1293 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1294 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1295 | const int32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1296 | |
| 1297 | // Note that the null check must have been done earlier. |
| 1298 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1299 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1300 | StringEqualsOptimizations optimizations(invoke); |
| 1301 | if (!optimizations.GetArgumentNotNull()) { |
| 1302 | // Check if input is null, return false if it is. |
| 1303 | __ Cbz(arg, &return_false); |
| 1304 | } |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1305 | |
| 1306 | // Reference equality check, return true if same reference. |
| 1307 | __ Cmp(str, arg); |
| 1308 | __ B(&return_true, eq); |
| 1309 | |
Vladimir Marko | 53b5200 | 2016-05-24 19:30:45 +0100 | [diff] [blame] | 1310 | if (!optimizations.GetArgumentIsString()) { |
| 1311 | // Instanceof check for the argument by comparing class fields. |
| 1312 | // All string objects must have the same type since String cannot be subclassed. |
| 1313 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1314 | // If the argument is a string object, its class field must be equal to receiver's class field. |
| 1315 | __ Ldr(temp, MemOperand(str.X(), class_offset)); |
| 1316 | __ Ldr(temp1, MemOperand(arg.X(), class_offset)); |
| 1317 | __ Cmp(temp, temp1); |
| 1318 | __ B(&return_false, ne); |
| 1319 | } |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1320 | |
| 1321 | // Load lengths of this and argument strings. |
| 1322 | __ Ldr(temp, MemOperand(str.X(), count_offset)); |
| 1323 | __ Ldr(temp1, MemOperand(arg.X(), count_offset)); |
| 1324 | // Check if lengths are equal, return false if they're not. |
| 1325 | __ Cmp(temp, temp1); |
| 1326 | __ B(&return_false, ne); |
| 1327 | // Store offset of string value in preparation for comparison loop |
| 1328 | __ Mov(temp1, value_offset); |
| 1329 | // Return true if both strings are empty. |
| 1330 | __ Cbz(temp, &return_true); |
| 1331 | |
| 1332 | // Assertions that must hold in order to compare strings 4 characters at a time. |
| 1333 | DCHECK_ALIGNED(value_offset, 8); |
| 1334 | static_assert(IsAligned<8>(kObjectAlignment), "String of odd length is not zero padded"); |
| 1335 | |
| 1336 | temp1 = temp1.X(); |
| 1337 | temp2 = temp2.X(); |
| 1338 | |
| 1339 | // Loop to compare strings 4 characters at a time starting at the beginning of the string. |
| 1340 | // Ok to do this because strings are zero-padded to be 8-byte aligned. |
| 1341 | __ Bind(&loop); |
| 1342 | __ Ldr(out, MemOperand(str.X(), temp1)); |
| 1343 | __ Ldr(temp2, MemOperand(arg.X(), temp1)); |
| 1344 | __ Add(temp1, temp1, Operand(sizeof(uint64_t))); |
| 1345 | __ Cmp(out, temp2); |
| 1346 | __ B(&return_false, ne); |
| 1347 | __ Sub(temp, temp, Operand(4), SetFlags); |
| 1348 | __ B(&loop, gt); |
| 1349 | |
| 1350 | // Return true and exit the function. |
| 1351 | // If loop does not result in returning false, we return true. |
| 1352 | __ Bind(&return_true); |
| 1353 | __ Mov(out, 1); |
| 1354 | __ B(&end); |
| 1355 | |
| 1356 | // Return false and exit the function. |
| 1357 | __ Bind(&return_false); |
| 1358 | __ Mov(out, 0); |
| 1359 | __ Bind(&end); |
| 1360 | } |
| 1361 | |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1362 | static void GenerateVisitStringIndexOf(HInvoke* invoke, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1363 | MacroAssembler* masm, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1364 | CodeGeneratorARM64* codegen, |
| 1365 | ArenaAllocator* allocator, |
| 1366 | bool start_at_zero) { |
| 1367 | LocationSummary* locations = invoke->GetLocations(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1368 | |
| 1369 | // Note that the null check must have been done earlier. |
| 1370 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1371 | |
| 1372 | // 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] | 1373 | // 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] | 1374 | SlowPathCodeARM64* slow_path = nullptr; |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1375 | HInstruction* code_point = invoke->InputAt(1); |
| 1376 | if (code_point->IsIntConstant()) { |
Vladimir Marko | da05108 | 2016-05-17 16:10:20 +0100 | [diff] [blame] | 1377 | if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) > 0xFFFFU) { |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1378 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1379 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
| 1380 | slow_path = new (allocator) IntrinsicSlowPathARM64(invoke); |
| 1381 | codegen->AddSlowPath(slow_path); |
| 1382 | __ B(slow_path->GetEntryLabel()); |
| 1383 | __ Bind(slow_path->GetExitLabel()); |
| 1384 | return; |
| 1385 | } |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1386 | } else if (code_point->GetType() != Primitive::kPrimChar) { |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1387 | Register char_reg = WRegisterFrom(locations->InAt(1)); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1388 | __ Tst(char_reg, 0xFFFF0000); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1389 | slow_path = new (allocator) IntrinsicSlowPathARM64(invoke); |
| 1390 | codegen->AddSlowPath(slow_path); |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1391 | __ B(ne, slow_path->GetEntryLabel()); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | if (start_at_zero) { |
| 1395 | // Start-index = 0. |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1396 | Register tmp_reg = WRegisterFrom(locations->GetTemp(0)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1397 | __ Mov(tmp_reg, 0); |
| 1398 | } |
| 1399 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1400 | __ Ldr(lr, MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, pIndexOf).Int32Value())); |
Roland Levillain | 42ad288 | 2016-02-29 18:26:54 +0000 | [diff] [blame] | 1401 | CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>(); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1402 | __ Blr(lr); |
| 1403 | |
| 1404 | if (slow_path != nullptr) { |
| 1405 | __ Bind(slow_path->GetExitLabel()); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | void IntrinsicLocationsBuilderARM64::VisitStringIndexOf(HInvoke* invoke) { |
| 1410 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1411 | LocationSummary::kCallOnMainOnly, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1412 | kIntrinsified); |
| 1413 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1414 | // best to align the inputs accordingly. |
| 1415 | InvokeRuntimeCallingConvention calling_convention; |
| 1416 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1417 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1418 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1419 | |
Vladimir Marko | fb6c90a | 2016-05-06 15:52:12 +0100 | [diff] [blame] | 1420 | // Need to send start_index=0. |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1421 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1422 | } |
| 1423 | |
| 1424 | void IntrinsicCodeGeneratorARM64::VisitStringIndexOf(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1425 | GenerateVisitStringIndexOf( |
| 1426 | invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | void IntrinsicLocationsBuilderARM64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1430 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1431 | LocationSummary::kCallOnMainOnly, |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1432 | kIntrinsified); |
| 1433 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1434 | // best to align the inputs accordingly. |
| 1435 | InvokeRuntimeCallingConvention calling_convention; |
| 1436 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1437 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1438 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1439 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | void IntrinsicCodeGeneratorARM64::VisitStringIndexOfAfter(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1443 | GenerateVisitStringIndexOf( |
| 1444 | invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1447 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1448 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1449 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1450 | kIntrinsified); |
| 1451 | InvokeRuntimeCallingConvention calling_convention; |
| 1452 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1453 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1454 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1455 | locations->SetInAt(3, LocationFrom(calling_convention.GetRegisterAt(3))); |
| 1456 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1457 | } |
| 1458 | |
| 1459 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1460 | MacroAssembler* masm = GetVIXLAssembler(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1461 | LocationSummary* locations = invoke->GetLocations(); |
| 1462 | |
| 1463 | Register byte_array = WRegisterFrom(locations->InAt(0)); |
| 1464 | __ Cmp(byte_array, 0); |
| 1465 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1466 | codegen_->AddSlowPath(slow_path); |
| 1467 | __ B(eq, slow_path->GetEntryLabel()); |
| 1468 | |
| 1469 | __ Ldr(lr, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1470 | MemOperand(tr, |
| 1471 | QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, pAllocStringFromBytes).Int32Value())); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1472 | CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1473 | __ Blr(lr); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1474 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1475 | __ Bind(slow_path->GetExitLabel()); |
| 1476 | } |
| 1477 | |
| 1478 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1479 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1480 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1481 | kIntrinsified); |
| 1482 | InvokeRuntimeCallingConvention calling_convention; |
| 1483 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1484 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1485 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1486 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1487 | } |
| 1488 | |
| 1489 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromChars(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1490 | MacroAssembler* masm = GetVIXLAssembler(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1491 | |
Roland Levillain | cc3839c | 2016-02-29 16:23:48 +0000 | [diff] [blame] | 1492 | // No need to emit code checking whether `locations->InAt(2)` is a null |
| 1493 | // pointer, as callers of the native method |
| 1494 | // |
| 1495 | // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data) |
| 1496 | // |
| 1497 | // all include a null check on `data` before calling that method. |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1498 | __ Ldr(lr, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1499 | MemOperand(tr, |
| 1500 | QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, pAllocStringFromChars).Int32Value())); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1501 | CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1502 | __ Blr(lr); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1503 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromString(HInvoke* invoke) { |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1507 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1508 | LocationSummary::kCallOnMainOnly, |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1509 | kIntrinsified); |
| 1510 | InvokeRuntimeCallingConvention calling_convention; |
| 1511 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1512 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1513 | } |
| 1514 | |
| 1515 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromString(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1516 | MacroAssembler* masm = GetVIXLAssembler(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1517 | LocationSummary* locations = invoke->GetLocations(); |
| 1518 | |
| 1519 | Register string_to_copy = WRegisterFrom(locations->InAt(0)); |
| 1520 | __ Cmp(string_to_copy, 0); |
| 1521 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1522 | codegen_->AddSlowPath(slow_path); |
| 1523 | __ B(eq, slow_path->GetEntryLabel()); |
| 1524 | |
| 1525 | __ Ldr(lr, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1526 | MemOperand(tr, |
| 1527 | QUICK_ENTRYPOINT_OFFSET(kArm64PointerSize, pAllocStringFromString).Int32Value())); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1528 | CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>(); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1529 | __ Blr(lr); |
Roland Levillain | f969a20 | 2016-03-09 16:14:00 +0000 | [diff] [blame] | 1530 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1531 | __ Bind(slow_path->GetExitLabel()); |
| 1532 | } |
| 1533 | |
Anton Kirilov | 02fc24e | 2016-01-20 16:48:19 +0000 | [diff] [blame] | 1534 | static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 1535 | DCHECK_EQ(invoke->GetNumberOfArguments(), 1U); |
| 1536 | DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(0)->GetType())); |
| 1537 | DCHECK(Primitive::IsFloatingPointType(invoke->GetType())); |
| 1538 | |
| 1539 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1540 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | 02fc24e | 2016-01-20 16:48:19 +0000 | [diff] [blame] | 1541 | kIntrinsified); |
| 1542 | InvokeRuntimeCallingConvention calling_convention; |
| 1543 | |
| 1544 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 1545 | locations->SetOut(calling_convention.GetReturnLocation(invoke->GetType())); |
| 1546 | } |
| 1547 | |
| 1548 | static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 1549 | DCHECK_EQ(invoke->GetNumberOfArguments(), 2U); |
| 1550 | DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(0)->GetType())); |
| 1551 | DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(1)->GetType())); |
| 1552 | DCHECK(Primitive::IsFloatingPointType(invoke->GetType())); |
| 1553 | |
| 1554 | LocationSummary* const locations = new (arena) LocationSummary(invoke, |
Serban Constantinescu | 54ff482 | 2016-07-07 18:03:19 +0100 | [diff] [blame] | 1555 | LocationSummary::kCallOnMainOnly, |
Anton Kirilov | 02fc24e | 2016-01-20 16:48:19 +0000 | [diff] [blame] | 1556 | kIntrinsified); |
| 1557 | InvokeRuntimeCallingConvention calling_convention; |
| 1558 | |
| 1559 | locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0))); |
| 1560 | locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1))); |
| 1561 | locations->SetOut(calling_convention.GetReturnLocation(invoke->GetType())); |
| 1562 | } |
| 1563 | |
| 1564 | static void GenFPToFPCall(HInvoke* invoke, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1565 | MacroAssembler* masm, |
Anton Kirilov | 02fc24e | 2016-01-20 16:48:19 +0000 | [diff] [blame] | 1566 | CodeGeneratorARM64* codegen, |
| 1567 | QuickEntrypointEnum entry) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1568 | __ Ldr(lr, MemOperand(tr, |
| 1569 | GetThreadOffset<kArm64PointerSize>(entry).Int32Value())); |
Anton Kirilov | 02fc24e | 2016-01-20 16:48:19 +0000 | [diff] [blame] | 1570 | __ Blr(lr); |
| 1571 | codegen->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1572 | } |
| 1573 | |
| 1574 | void IntrinsicLocationsBuilderARM64::VisitMathCos(HInvoke* invoke) { |
| 1575 | CreateFPToFPCallLocations(arena_, invoke); |
| 1576 | } |
| 1577 | |
| 1578 | void IntrinsicCodeGeneratorARM64::VisitMathCos(HInvoke* invoke) { |
| 1579 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickCos); |
| 1580 | } |
| 1581 | |
| 1582 | void IntrinsicLocationsBuilderARM64::VisitMathSin(HInvoke* invoke) { |
| 1583 | CreateFPToFPCallLocations(arena_, invoke); |
| 1584 | } |
| 1585 | |
| 1586 | void IntrinsicCodeGeneratorARM64::VisitMathSin(HInvoke* invoke) { |
| 1587 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickSin); |
| 1588 | } |
| 1589 | |
| 1590 | void IntrinsicLocationsBuilderARM64::VisitMathAcos(HInvoke* invoke) { |
| 1591 | CreateFPToFPCallLocations(arena_, invoke); |
| 1592 | } |
| 1593 | |
| 1594 | void IntrinsicCodeGeneratorARM64::VisitMathAcos(HInvoke* invoke) { |
| 1595 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickAcos); |
| 1596 | } |
| 1597 | |
| 1598 | void IntrinsicLocationsBuilderARM64::VisitMathAsin(HInvoke* invoke) { |
| 1599 | CreateFPToFPCallLocations(arena_, invoke); |
| 1600 | } |
| 1601 | |
| 1602 | void IntrinsicCodeGeneratorARM64::VisitMathAsin(HInvoke* invoke) { |
| 1603 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickAsin); |
| 1604 | } |
| 1605 | |
| 1606 | void IntrinsicLocationsBuilderARM64::VisitMathAtan(HInvoke* invoke) { |
| 1607 | CreateFPToFPCallLocations(arena_, invoke); |
| 1608 | } |
| 1609 | |
| 1610 | void IntrinsicCodeGeneratorARM64::VisitMathAtan(HInvoke* invoke) { |
| 1611 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickAtan); |
| 1612 | } |
| 1613 | |
| 1614 | void IntrinsicLocationsBuilderARM64::VisitMathCbrt(HInvoke* invoke) { |
| 1615 | CreateFPToFPCallLocations(arena_, invoke); |
| 1616 | } |
| 1617 | |
| 1618 | void IntrinsicCodeGeneratorARM64::VisitMathCbrt(HInvoke* invoke) { |
| 1619 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickCbrt); |
| 1620 | } |
| 1621 | |
| 1622 | void IntrinsicLocationsBuilderARM64::VisitMathCosh(HInvoke* invoke) { |
| 1623 | CreateFPToFPCallLocations(arena_, invoke); |
| 1624 | } |
| 1625 | |
| 1626 | void IntrinsicCodeGeneratorARM64::VisitMathCosh(HInvoke* invoke) { |
| 1627 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickCosh); |
| 1628 | } |
| 1629 | |
| 1630 | void IntrinsicLocationsBuilderARM64::VisitMathExp(HInvoke* invoke) { |
| 1631 | CreateFPToFPCallLocations(arena_, invoke); |
| 1632 | } |
| 1633 | |
| 1634 | void IntrinsicCodeGeneratorARM64::VisitMathExp(HInvoke* invoke) { |
| 1635 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickExp); |
| 1636 | } |
| 1637 | |
| 1638 | void IntrinsicLocationsBuilderARM64::VisitMathExpm1(HInvoke* invoke) { |
| 1639 | CreateFPToFPCallLocations(arena_, invoke); |
| 1640 | } |
| 1641 | |
| 1642 | void IntrinsicCodeGeneratorARM64::VisitMathExpm1(HInvoke* invoke) { |
| 1643 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickExpm1); |
| 1644 | } |
| 1645 | |
| 1646 | void IntrinsicLocationsBuilderARM64::VisitMathLog(HInvoke* invoke) { |
| 1647 | CreateFPToFPCallLocations(arena_, invoke); |
| 1648 | } |
| 1649 | |
| 1650 | void IntrinsicCodeGeneratorARM64::VisitMathLog(HInvoke* invoke) { |
| 1651 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickLog); |
| 1652 | } |
| 1653 | |
| 1654 | void IntrinsicLocationsBuilderARM64::VisitMathLog10(HInvoke* invoke) { |
| 1655 | CreateFPToFPCallLocations(arena_, invoke); |
| 1656 | } |
| 1657 | |
| 1658 | void IntrinsicCodeGeneratorARM64::VisitMathLog10(HInvoke* invoke) { |
| 1659 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickLog10); |
| 1660 | } |
| 1661 | |
| 1662 | void IntrinsicLocationsBuilderARM64::VisitMathSinh(HInvoke* invoke) { |
| 1663 | CreateFPToFPCallLocations(arena_, invoke); |
| 1664 | } |
| 1665 | |
| 1666 | void IntrinsicCodeGeneratorARM64::VisitMathSinh(HInvoke* invoke) { |
| 1667 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickSinh); |
| 1668 | } |
| 1669 | |
| 1670 | void IntrinsicLocationsBuilderARM64::VisitMathTan(HInvoke* invoke) { |
| 1671 | CreateFPToFPCallLocations(arena_, invoke); |
| 1672 | } |
| 1673 | |
| 1674 | void IntrinsicCodeGeneratorARM64::VisitMathTan(HInvoke* invoke) { |
| 1675 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickTan); |
| 1676 | } |
| 1677 | |
| 1678 | void IntrinsicLocationsBuilderARM64::VisitMathTanh(HInvoke* invoke) { |
| 1679 | CreateFPToFPCallLocations(arena_, invoke); |
| 1680 | } |
| 1681 | |
| 1682 | void IntrinsicCodeGeneratorARM64::VisitMathTanh(HInvoke* invoke) { |
| 1683 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickTanh); |
| 1684 | } |
| 1685 | |
| 1686 | void IntrinsicLocationsBuilderARM64::VisitMathAtan2(HInvoke* invoke) { |
| 1687 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1688 | } |
| 1689 | |
| 1690 | void IntrinsicCodeGeneratorARM64::VisitMathAtan2(HInvoke* invoke) { |
| 1691 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickAtan2); |
| 1692 | } |
| 1693 | |
| 1694 | void IntrinsicLocationsBuilderARM64::VisitMathHypot(HInvoke* invoke) { |
| 1695 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1696 | } |
| 1697 | |
| 1698 | void IntrinsicCodeGeneratorARM64::VisitMathHypot(HInvoke* invoke) { |
| 1699 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickHypot); |
| 1700 | } |
| 1701 | |
| 1702 | void IntrinsicLocationsBuilderARM64::VisitMathNextAfter(HInvoke* invoke) { |
| 1703 | CreateFPFPToFPCallLocations(arena_, invoke); |
| 1704 | } |
| 1705 | |
| 1706 | void IntrinsicCodeGeneratorARM64::VisitMathNextAfter(HInvoke* invoke) { |
| 1707 | GenFPToFPCall(invoke, GetVIXLAssembler(), codegen_, kQuickNextAfter); |
| 1708 | } |
| 1709 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1710 | void IntrinsicLocationsBuilderARM64::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
| 1711 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1712 | LocationSummary::kNoCall, |
| 1713 | kIntrinsified); |
| 1714 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1715 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1716 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1717 | locations->SetInAt(3, Location::RequiresRegister()); |
| 1718 | locations->SetInAt(4, Location::RequiresRegister()); |
| 1719 | |
| 1720 | locations->AddTemp(Location::RequiresRegister()); |
| 1721 | locations->AddTemp(Location::RequiresRegister()); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1722 | locations->AddTemp(Location::RequiresRegister()); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | void IntrinsicCodeGeneratorARM64::VisitStringGetCharsNoCheck(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1726 | MacroAssembler* masm = GetVIXLAssembler(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1727 | LocationSummary* locations = invoke->GetLocations(); |
| 1728 | |
| 1729 | // Check assumption that sizeof(Char) is 2 (used in scaling below). |
| 1730 | const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 1731 | DCHECK_EQ(char_size, 2u); |
| 1732 | |
| 1733 | // Location of data in char array buffer. |
| 1734 | const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value(); |
| 1735 | |
| 1736 | // Location of char array data in string. |
| 1737 | const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value(); |
| 1738 | |
| 1739 | // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin); |
| 1740 | // Since getChars() calls getCharsNoCheck() - we use registers rather than constants. |
| 1741 | Register srcObj = XRegisterFrom(locations->InAt(0)); |
| 1742 | Register srcBegin = XRegisterFrom(locations->InAt(1)); |
| 1743 | Register srcEnd = XRegisterFrom(locations->InAt(2)); |
| 1744 | Register dstObj = XRegisterFrom(locations->InAt(3)); |
| 1745 | Register dstBegin = XRegisterFrom(locations->InAt(4)); |
| 1746 | |
| 1747 | Register src_ptr = XRegisterFrom(locations->GetTemp(0)); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1748 | Register num_chr = XRegisterFrom(locations->GetTemp(1)); |
| 1749 | Register tmp1 = XRegisterFrom(locations->GetTemp(2)); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1750 | |
| 1751 | UseScratchRegisterScope temps(masm); |
| 1752 | Register dst_ptr = temps.AcquireX(); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1753 | Register tmp2 = temps.AcquireX(); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1754 | |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1755 | // src address to copy from. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1756 | __ Add(src_ptr, srcObj, Operand(value_offset)); |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1757 | __ Add(src_ptr, src_ptr, Operand(srcBegin, LSL, 1)); |
| 1758 | |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1759 | // dst address start to copy to. |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1760 | __ Add(dst_ptr, dstObj, Operand(data_offset)); |
| 1761 | __ Add(dst_ptr, dst_ptr, Operand(dstBegin, LSL, 1)); |
| 1762 | |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1763 | __ Sub(num_chr, srcEnd, srcBegin); |
| 1764 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1765 | // Do the copy. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1766 | vixl::aarch64::Label loop; |
| 1767 | vixl::aarch64::Label done; |
| 1768 | vixl::aarch64::Label remainder; |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1769 | |
| 1770 | // Early out for valid zero-length retrievals. |
| 1771 | __ Cbz(num_chr, &done); |
| 1772 | |
| 1773 | // Save repairing the value of num_chr on the < 8 character path. |
| 1774 | __ Subs(tmp1, num_chr, 8); |
| 1775 | __ B(lt, &remainder); |
| 1776 | |
| 1777 | // Keep the result of the earlier subs, we are going to fetch at least 8 characters. |
| 1778 | __ Mov(num_chr, tmp1); |
| 1779 | |
| 1780 | // Main loop used for longer fetches loads and stores 8x16-bit characters at a time. |
| 1781 | // (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] | 1782 | __ Bind(&loop); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1783 | __ Ldp(tmp1, tmp2, MemOperand(src_ptr, char_size * 8, PostIndex)); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1784 | __ Subs(num_chr, num_chr, 8); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1785 | __ Stp(tmp1, tmp2, MemOperand(dst_ptr, char_size * 8, PostIndex)); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1786 | __ B(ge, &loop); |
| 1787 | |
| 1788 | __ Adds(num_chr, num_chr, 8); |
| 1789 | __ B(eq, &done); |
| 1790 | |
| 1791 | // Main loop for < 8 character case and remainder handling. Loads and stores one |
| 1792 | // 16-bit Java character at a time. |
| 1793 | __ Bind(&remainder); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1794 | __ Ldrh(tmp1, MemOperand(src_ptr, char_size, PostIndex)); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1795 | __ Subs(num_chr, num_chr, 1); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1796 | __ Strh(tmp1, MemOperand(dst_ptr, char_size, PostIndex)); |
Scott Wakeling | df109d9 | 2016-04-22 11:35:56 +0100 | [diff] [blame] | 1797 | __ B(gt, &remainder); |
| 1798 | |
Tim Zhang | 25abd6c | 2016-01-19 23:39:24 +0800 | [diff] [blame] | 1799 | __ Bind(&done); |
| 1800 | } |
| 1801 | |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1802 | // Mirrors ARRAYCOPY_SHORT_CHAR_ARRAY_THRESHOLD in libcore, so we can choose to use the native |
| 1803 | // implementation there for longer copy lengths. |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 1804 | static constexpr int32_t kSystemArrayCopyCharThreshold = 32; |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1805 | |
| 1806 | static void SetSystemArrayCopyLocationRequires(LocationSummary* locations, |
| 1807 | uint32_t at, |
| 1808 | HInstruction* input) { |
| 1809 | HIntConstant* const_input = input->AsIntConstant(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1810 | if (const_input != nullptr && !vixl::aarch64::Assembler::IsImmAddSub(const_input->GetValue())) { |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1811 | locations->SetInAt(at, Location::RequiresRegister()); |
| 1812 | } else { |
| 1813 | locations->SetInAt(at, Location::RegisterOrConstant(input)); |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | void IntrinsicLocationsBuilderARM64::VisitSystemArrayCopyChar(HInvoke* invoke) { |
| 1818 | // Check to see if we have known failures that will cause us to have to bail out |
| 1819 | // to the runtime, and just generate the runtime call directly. |
| 1820 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 1821 | HIntConstant* dst_pos = invoke->InputAt(3)->AsIntConstant(); |
| 1822 | |
| 1823 | // The positions must be non-negative. |
| 1824 | if ((src_pos != nullptr && src_pos->GetValue() < 0) || |
| 1825 | (dst_pos != nullptr && dst_pos->GetValue() < 0)) { |
| 1826 | // We will have to fail anyways. |
| 1827 | return; |
| 1828 | } |
| 1829 | |
| 1830 | // The length must be >= 0 and not so long that we would (currently) prefer libcore's |
| 1831 | // native implementation. |
| 1832 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 1833 | if (length != nullptr) { |
| 1834 | int32_t len = length->GetValue(); |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 1835 | if (len < 0 || len > kSystemArrayCopyCharThreshold) { |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1836 | // Just call as normal. |
| 1837 | return; |
| 1838 | } |
| 1839 | } |
| 1840 | |
| 1841 | ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena(); |
| 1842 | LocationSummary* locations = new (allocator) LocationSummary(invoke, |
| 1843 | LocationSummary::kCallOnSlowPath, |
| 1844 | kIntrinsified); |
| 1845 | // arraycopy(char[] src, int src_pos, char[] dst, int dst_pos, int length). |
| 1846 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1847 | SetSystemArrayCopyLocationRequires(locations, 1, invoke->InputAt(1)); |
| 1848 | locations->SetInAt(2, Location::RequiresRegister()); |
| 1849 | SetSystemArrayCopyLocationRequires(locations, 3, invoke->InputAt(3)); |
| 1850 | SetSystemArrayCopyLocationRequires(locations, 4, invoke->InputAt(4)); |
| 1851 | |
| 1852 | locations->AddTemp(Location::RequiresRegister()); |
| 1853 | locations->AddTemp(Location::RequiresRegister()); |
| 1854 | locations->AddTemp(Location::RequiresRegister()); |
| 1855 | } |
| 1856 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1857 | static void CheckSystemArrayCopyPosition(MacroAssembler* masm, |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1858 | const Location& pos, |
| 1859 | const Register& input, |
| 1860 | const Location& length, |
| 1861 | SlowPathCodeARM64* slow_path, |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1862 | const Register& temp, |
| 1863 | bool length_is_input_length = false) { |
| 1864 | const int32_t length_offset = mirror::Array::LengthOffset().Int32Value(); |
| 1865 | if (pos.IsConstant()) { |
| 1866 | int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue(); |
| 1867 | if (pos_const == 0) { |
| 1868 | if (!length_is_input_length) { |
| 1869 | // Check that length(input) >= length. |
| 1870 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 1871 | __ Cmp(temp, OperandFrom(length, Primitive::kPrimInt)); |
| 1872 | __ B(slow_path->GetEntryLabel(), lt); |
| 1873 | } |
| 1874 | } else { |
| 1875 | // Check that length(input) >= pos. |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 1876 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 1877 | __ Subs(temp, temp, pos_const); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1878 | __ B(slow_path->GetEntryLabel(), lt); |
| 1879 | |
| 1880 | // Check that (length(input) - pos) >= length. |
| 1881 | __ Cmp(temp, OperandFrom(length, Primitive::kPrimInt)); |
| 1882 | __ B(slow_path->GetEntryLabel(), lt); |
| 1883 | } |
| 1884 | } else if (length_is_input_length) { |
| 1885 | // The only way the copy can succeed is if pos is zero. |
| 1886 | __ Cbnz(WRegisterFrom(pos), slow_path->GetEntryLabel()); |
| 1887 | } else { |
| 1888 | // Check that pos >= 0. |
| 1889 | Register pos_reg = WRegisterFrom(pos); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1890 | __ Tbnz(pos_reg, pos_reg.GetSizeInBits() - 1, slow_path->GetEntryLabel()); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1891 | |
| 1892 | // Check that pos <= length(input) && (length(input) - pos) >= length. |
| 1893 | __ Ldr(temp, MemOperand(input, length_offset)); |
| 1894 | __ Subs(temp, temp, pos_reg); |
| 1895 | // Ccmp if length(input) >= pos, else definitely bail to slow path (N!=V == lt). |
| 1896 | __ Ccmp(temp, OperandFrom(length, Primitive::kPrimInt), NFlag, ge); |
| 1897 | __ B(slow_path->GetEntryLabel(), lt); |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | // Compute base source address, base destination address, and end source address |
| 1902 | // for System.arraycopy* intrinsics. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1903 | static void GenSystemArrayCopyAddresses(MacroAssembler* masm, |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1904 | Primitive::Type type, |
| 1905 | const Register& src, |
| 1906 | const Location& src_pos, |
| 1907 | const Register& dst, |
| 1908 | const Location& dst_pos, |
| 1909 | const Location& copy_length, |
| 1910 | const Register& src_base, |
| 1911 | const Register& dst_base, |
| 1912 | const Register& src_end) { |
| 1913 | DCHECK(type == Primitive::kPrimNot || type == Primitive::kPrimChar) |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1914 | << "Unexpected element type: " << type; |
| 1915 | const int32_t element_size = Primitive::ComponentSize(type); |
| 1916 | const int32_t element_size_shift = Primitive::ComponentSizeShift(type); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1917 | |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1918 | uint32_t data_offset = mirror::Array::DataOffset(element_size).Uint32Value(); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1919 | if (src_pos.IsConstant()) { |
| 1920 | int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1921 | __ Add(src_base, src, element_size * constant + data_offset); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1922 | } else { |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1923 | __ Add(src_base, src, data_offset); |
| 1924 | __ 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] | 1925 | } |
| 1926 | |
| 1927 | if (dst_pos.IsConstant()) { |
| 1928 | int32_t constant = dst_pos.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1929 | __ Add(dst_base, dst, element_size * constant + data_offset); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1930 | } else { |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1931 | __ Add(dst_base, dst, data_offset); |
| 1932 | __ 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] | 1933 | } |
| 1934 | |
| 1935 | if (copy_length.IsConstant()) { |
| 1936 | int32_t constant = copy_length.GetConstant()->AsIntConstant()->GetValue(); |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1937 | __ Add(src_end, src_base, element_size * constant); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1938 | } else { |
Roland Levillain | ebea3d2 | 2016-04-12 15:42:57 +0100 | [diff] [blame] | 1939 | __ 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] | 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | void IntrinsicCodeGeneratorARM64::VisitSystemArrayCopyChar(HInvoke* invoke) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 1944 | MacroAssembler* masm = GetVIXLAssembler(); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1945 | LocationSummary* locations = invoke->GetLocations(); |
| 1946 | Register src = XRegisterFrom(locations->InAt(0)); |
| 1947 | Location src_pos = locations->InAt(1); |
| 1948 | Register dst = XRegisterFrom(locations->InAt(2)); |
| 1949 | Location dst_pos = locations->InAt(3); |
| 1950 | Location length = locations->InAt(4); |
| 1951 | |
| 1952 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1953 | codegen_->AddSlowPath(slow_path); |
| 1954 | |
| 1955 | // If source and destination are the same, take the slow path. Overlapping copy regions must be |
| 1956 | // copied in reverse and we can't know in all cases if it's needed. |
| 1957 | __ Cmp(src, dst); |
| 1958 | __ B(slow_path->GetEntryLabel(), eq); |
| 1959 | |
| 1960 | // Bail out if the source is null. |
| 1961 | __ Cbz(src, slow_path->GetEntryLabel()); |
| 1962 | |
| 1963 | // Bail out if the destination is null. |
| 1964 | __ Cbz(dst, slow_path->GetEntryLabel()); |
| 1965 | |
| 1966 | if (!length.IsConstant()) { |
| 1967 | // If the length is negative, bail out. |
| 1968 | __ Tbnz(WRegisterFrom(length), kWRegSize - 1, slow_path->GetEntryLabel()); |
| 1969 | // If the length > 32 then (currently) prefer libcore's native implementation. |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 1970 | __ Cmp(WRegisterFrom(length), kSystemArrayCopyCharThreshold); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1971 | __ B(slow_path->GetEntryLabel(), gt); |
| 1972 | } else { |
| 1973 | // We have already checked in the LocationsBuilder for the constant case. |
| 1974 | DCHECK_GE(length.GetConstant()->AsIntConstant()->GetValue(), 0); |
| 1975 | DCHECK_LE(length.GetConstant()->AsIntConstant()->GetValue(), 32); |
| 1976 | } |
| 1977 | |
| 1978 | Register src_curr_addr = WRegisterFrom(locations->GetTemp(0)); |
| 1979 | Register dst_curr_addr = WRegisterFrom(locations->GetTemp(1)); |
| 1980 | Register src_stop_addr = WRegisterFrom(locations->GetTemp(2)); |
| 1981 | |
| 1982 | CheckSystemArrayCopyPosition(masm, |
| 1983 | src_pos, |
| 1984 | src, |
| 1985 | length, |
| 1986 | slow_path, |
| 1987 | src_curr_addr, |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1988 | false); |
| 1989 | |
| 1990 | CheckSystemArrayCopyPosition(masm, |
| 1991 | dst_pos, |
| 1992 | dst, |
| 1993 | length, |
| 1994 | slow_path, |
| 1995 | src_curr_addr, |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 1996 | false); |
| 1997 | |
| 1998 | src_curr_addr = src_curr_addr.X(); |
| 1999 | dst_curr_addr = dst_curr_addr.X(); |
| 2000 | src_stop_addr = src_stop_addr.X(); |
| 2001 | |
| 2002 | GenSystemArrayCopyAddresses(masm, |
| 2003 | Primitive::kPrimChar, |
| 2004 | src, |
| 2005 | src_pos, |
| 2006 | dst, |
| 2007 | dst_pos, |
| 2008 | length, |
| 2009 | src_curr_addr, |
| 2010 | dst_curr_addr, |
| 2011 | src_stop_addr); |
| 2012 | |
| 2013 | // Iterate over the arrays and do a raw copy of the chars. |
| 2014 | const int32_t char_size = Primitive::ComponentSize(Primitive::kPrimChar); |
| 2015 | UseScratchRegisterScope temps(masm); |
| 2016 | Register tmp = temps.AcquireW(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2017 | vixl::aarch64::Label loop, done; |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 2018 | __ Bind(&loop); |
| 2019 | __ Cmp(src_curr_addr, src_stop_addr); |
| 2020 | __ B(&done, eq); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2021 | __ Ldrh(tmp, MemOperand(src_curr_addr, char_size, PostIndex)); |
| 2022 | __ Strh(tmp, MemOperand(dst_curr_addr, char_size, PostIndex)); |
Scott Wakeling | d3d0da5 | 2016-02-29 15:17:20 +0000 | [diff] [blame] | 2023 | __ B(&loop); |
| 2024 | __ Bind(&done); |
| 2025 | |
| 2026 | __ Bind(slow_path->GetExitLabel()); |
| 2027 | } |
| 2028 | |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2029 | // We can choose to use the native implementation there for longer copy lengths. |
| 2030 | static constexpr int32_t kSystemArrayCopyThreshold = 128; |
| 2031 | |
| 2032 | // CodeGenerator::CreateSystemArrayCopyLocationSummary use three temporary registers. |
| 2033 | // We want to use two temporary registers in order to reduce the register pressure in arm64. |
| 2034 | // So we don't use the CodeGenerator::CreateSystemArrayCopyLocationSummary. |
| 2035 | void IntrinsicLocationsBuilderARM64::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 2036 | // TODO(rpl): Implement read barriers in the SystemArrayCopy |
| 2037 | // intrinsic and re-enable it (b/29516905). |
| 2038 | if (kEmitCompilerReadBarrier) { |
| 2039 | return; |
| 2040 | } |
| 2041 | |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2042 | // Check to see if we have known failures that will cause us to have to bail out |
| 2043 | // to the runtime, and just generate the runtime call directly. |
| 2044 | HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant(); |
| 2045 | HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant(); |
| 2046 | |
| 2047 | // The positions must be non-negative. |
| 2048 | if ((src_pos != nullptr && src_pos->GetValue() < 0) || |
| 2049 | (dest_pos != nullptr && dest_pos->GetValue() < 0)) { |
| 2050 | // We will have to fail anyways. |
| 2051 | return; |
| 2052 | } |
| 2053 | |
| 2054 | // The length must be >= 0. |
| 2055 | HIntConstant* length = invoke->InputAt(4)->AsIntConstant(); |
| 2056 | if (length != nullptr) { |
| 2057 | int32_t len = length->GetValue(); |
| 2058 | if (len < 0 || len >= kSystemArrayCopyThreshold) { |
| 2059 | // Just call as normal. |
| 2060 | return; |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | SystemArrayCopyOptimizations optimizations(invoke); |
| 2065 | |
| 2066 | if (optimizations.GetDestinationIsSource()) { |
| 2067 | if (src_pos != nullptr && dest_pos != nullptr && src_pos->GetValue() < dest_pos->GetValue()) { |
| 2068 | // We only support backward copying if source and destination are the same. |
| 2069 | return; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | if (optimizations.GetDestinationIsPrimitiveArray() || optimizations.GetSourceIsPrimitiveArray()) { |
| 2074 | // We currently don't intrinsify primitive copying. |
| 2075 | return; |
| 2076 | } |
| 2077 | |
| 2078 | ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena(); |
| 2079 | LocationSummary* locations = new (allocator) LocationSummary(invoke, |
| 2080 | LocationSummary::kCallOnSlowPath, |
| 2081 | kIntrinsified); |
| 2082 | // arraycopy(Object src, int src_pos, Object dest, int dest_pos, int length). |
| 2083 | locations->SetInAt(0, Location::RequiresRegister()); |
| 2084 | SetSystemArrayCopyLocationRequires(locations, 1, invoke->InputAt(1)); |
| 2085 | locations->SetInAt(2, Location::RequiresRegister()); |
| 2086 | SetSystemArrayCopyLocationRequires(locations, 3, invoke->InputAt(3)); |
| 2087 | SetSystemArrayCopyLocationRequires(locations, 4, invoke->InputAt(4)); |
| 2088 | |
| 2089 | locations->AddTemp(Location::RequiresRegister()); |
| 2090 | locations->AddTemp(Location::RequiresRegister()); |
| 2091 | } |
| 2092 | |
| 2093 | void IntrinsicCodeGeneratorARM64::VisitSystemArrayCopy(HInvoke* invoke) { |
Roland Levillain | 3d31242 | 2016-06-23 13:53:42 +0100 | [diff] [blame] | 2094 | // TODO(rpl): Implement read barriers in the SystemArrayCopy |
| 2095 | // intrinsic and re-enable it (b/29516905). |
| 2096 | DCHECK(!kEmitCompilerReadBarrier); |
| 2097 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2098 | MacroAssembler* masm = GetVIXLAssembler(); |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2099 | LocationSummary* locations = invoke->GetLocations(); |
| 2100 | |
| 2101 | uint32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 2102 | uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value(); |
| 2103 | uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value(); |
| 2104 | uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value(); |
| 2105 | |
| 2106 | Register src = XRegisterFrom(locations->InAt(0)); |
| 2107 | Location src_pos = locations->InAt(1); |
| 2108 | Register dest = XRegisterFrom(locations->InAt(2)); |
| 2109 | Location dest_pos = locations->InAt(3); |
| 2110 | Location length = locations->InAt(4); |
| 2111 | Register temp1 = WRegisterFrom(locations->GetTemp(0)); |
| 2112 | Register temp2 = WRegisterFrom(locations->GetTemp(1)); |
| 2113 | |
| 2114 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 2115 | codegen_->AddSlowPath(slow_path); |
| 2116 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2117 | vixl::aarch64::Label conditions_on_positions_validated; |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2118 | SystemArrayCopyOptimizations optimizations(invoke); |
| 2119 | |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2120 | // If source and destination are the same, we go to slow path if we need to do |
| 2121 | // forward copying. |
| 2122 | if (src_pos.IsConstant()) { |
| 2123 | int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2124 | if (dest_pos.IsConstant()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 2125 | int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue(); |
| 2126 | if (optimizations.GetDestinationIsSource()) { |
| 2127 | // Checked when building locations. |
| 2128 | DCHECK_GE(src_pos_constant, dest_pos_constant); |
| 2129 | } else if (src_pos_constant < dest_pos_constant) { |
| 2130 | __ Cmp(src, dest); |
| 2131 | __ B(slow_path->GetEntryLabel(), eq); |
| 2132 | } |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2133 | // Checked when building locations. |
| 2134 | DCHECK(!optimizations.GetDestinationIsSource() |
| 2135 | || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue())); |
| 2136 | } else { |
| 2137 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 2138 | __ Cmp(src, dest); |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2139 | __ B(&conditions_on_positions_validated, ne); |
| 2140 | } |
| 2141 | __ Cmp(WRegisterFrom(dest_pos), src_pos_constant); |
| 2142 | __ B(slow_path->GetEntryLabel(), gt); |
| 2143 | } |
| 2144 | } else { |
| 2145 | if (!optimizations.GetDestinationIsSource()) { |
Nicolas Geoffray | 9f65db8 | 2016-07-07 12:07:42 +0100 | [diff] [blame] | 2146 | __ Cmp(src, dest); |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2147 | __ B(&conditions_on_positions_validated, ne); |
| 2148 | } |
| 2149 | __ Cmp(RegisterFrom(src_pos, invoke->InputAt(1)->GetType()), |
| 2150 | OperandFrom(dest_pos, invoke->InputAt(3)->GetType())); |
| 2151 | __ B(slow_path->GetEntryLabel(), lt); |
| 2152 | } |
| 2153 | |
| 2154 | __ Bind(&conditions_on_positions_validated); |
| 2155 | |
| 2156 | if (!optimizations.GetSourceIsNotNull()) { |
| 2157 | // Bail out if the source is null. |
| 2158 | __ Cbz(src, slow_path->GetEntryLabel()); |
| 2159 | } |
| 2160 | |
| 2161 | if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) { |
| 2162 | // Bail out if the destination is null. |
| 2163 | __ Cbz(dest, slow_path->GetEntryLabel()); |
| 2164 | } |
| 2165 | |
| 2166 | // We have already checked in the LocationsBuilder for the constant case. |
| 2167 | if (!length.IsConstant() && |
| 2168 | !optimizations.GetCountIsSourceLength() && |
| 2169 | !optimizations.GetCountIsDestinationLength()) { |
| 2170 | // If the length is negative, bail out. |
| 2171 | __ Tbnz(WRegisterFrom(length), kWRegSize - 1, slow_path->GetEntryLabel()); |
| 2172 | // If the length >= 128 then (currently) prefer native implementation. |
| 2173 | __ Cmp(WRegisterFrom(length), kSystemArrayCopyThreshold); |
| 2174 | __ B(slow_path->GetEntryLabel(), ge); |
| 2175 | } |
| 2176 | // Validity checks: source. |
| 2177 | CheckSystemArrayCopyPosition(masm, |
| 2178 | src_pos, |
| 2179 | src, |
| 2180 | length, |
| 2181 | slow_path, |
| 2182 | temp1, |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2183 | optimizations.GetCountIsSourceLength()); |
| 2184 | |
| 2185 | // Validity checks: dest. |
| 2186 | CheckSystemArrayCopyPosition(masm, |
| 2187 | dest_pos, |
| 2188 | dest, |
| 2189 | length, |
| 2190 | slow_path, |
| 2191 | temp1, |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2192 | optimizations.GetCountIsDestinationLength()); |
| 2193 | { |
| 2194 | // We use a block to end the scratch scope before the write barrier, thus |
| 2195 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 2196 | UseScratchRegisterScope temps(masm); |
| 2197 | Register temp3 = temps.AcquireW(); |
| 2198 | if (!optimizations.GetDoesNotNeedTypeCheck()) { |
| 2199 | // Check whether all elements of the source array are assignable to the component |
| 2200 | // type of the destination array. We do two checks: the classes are the same, |
| 2201 | // or the destination is Object[]. If none of these checks succeed, we go to the |
| 2202 | // slow path. |
| 2203 | __ Ldr(temp1, MemOperand(dest, class_offset)); |
| 2204 | __ Ldr(temp2, MemOperand(src, class_offset)); |
| 2205 | bool did_unpoison = false; |
| 2206 | if (!optimizations.GetDestinationIsNonPrimitiveArray() || |
| 2207 | !optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2208 | // One or two of the references need to be unpoisoned. Unpoison them |
| 2209 | // both to make the identity check valid. |
| 2210 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 2211 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp2); |
| 2212 | did_unpoison = true; |
| 2213 | } |
| 2214 | |
| 2215 | if (!optimizations.GetDestinationIsNonPrimitiveArray()) { |
| 2216 | // Bail out if the destination is not a non primitive array. |
| 2217 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 2218 | __ Ldr(temp3, HeapOperand(temp1, component_offset)); |
| 2219 | __ Cbz(temp3, slow_path->GetEntryLabel()); |
| 2220 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp3); |
| 2221 | __ Ldrh(temp3, HeapOperand(temp3, primitive_offset)); |
| 2222 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2223 | __ Cbnz(temp3, slow_path->GetEntryLabel()); |
| 2224 | } |
| 2225 | |
| 2226 | if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2227 | // Bail out if the source is not a non primitive array. |
| 2228 | // /* HeapReference<Class> */ temp3 = temp2->component_type_ |
| 2229 | __ Ldr(temp3, HeapOperand(temp2, component_offset)); |
| 2230 | __ Cbz(temp3, slow_path->GetEntryLabel()); |
| 2231 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp3); |
| 2232 | __ Ldrh(temp3, HeapOperand(temp3, primitive_offset)); |
| 2233 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2234 | __ Cbnz(temp3, slow_path->GetEntryLabel()); |
| 2235 | } |
| 2236 | |
| 2237 | __ Cmp(temp1, temp2); |
| 2238 | |
| 2239 | if (optimizations.GetDestinationIsTypedObjectArray()) { |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2240 | vixl::aarch64::Label do_copy; |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2241 | __ B(&do_copy, eq); |
| 2242 | if (!did_unpoison) { |
| 2243 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 2244 | } |
| 2245 | // /* HeapReference<Class> */ temp1 = temp1->component_type_ |
| 2246 | __ Ldr(temp1, HeapOperand(temp1, component_offset)); |
| 2247 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 2248 | // /* HeapReference<Class> */ temp1 = temp1->super_class_ |
| 2249 | __ Ldr(temp1, HeapOperand(temp1, super_offset)); |
| 2250 | // No need to unpoison the result, we're comparing against null. |
| 2251 | __ Cbnz(temp1, slow_path->GetEntryLabel()); |
| 2252 | __ Bind(&do_copy); |
| 2253 | } else { |
| 2254 | __ B(slow_path->GetEntryLabel(), ne); |
| 2255 | } |
| 2256 | } else if (!optimizations.GetSourceIsNonPrimitiveArray()) { |
| 2257 | DCHECK(optimizations.GetDestinationIsNonPrimitiveArray()); |
| 2258 | // Bail out if the source is not a non primitive array. |
| 2259 | // /* HeapReference<Class> */ temp1 = src->klass_ |
| 2260 | __ Ldr(temp1, HeapOperand(src.W(), class_offset)); |
| 2261 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1); |
| 2262 | // /* HeapReference<Class> */ temp3 = temp1->component_type_ |
| 2263 | __ Ldr(temp3, HeapOperand(temp1, component_offset)); |
| 2264 | __ Cbz(temp3, slow_path->GetEntryLabel()); |
| 2265 | codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp3); |
| 2266 | __ Ldrh(temp3, HeapOperand(temp3, primitive_offset)); |
| 2267 | static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot"); |
| 2268 | __ Cbnz(temp3, slow_path->GetEntryLabel()); |
| 2269 | } |
| 2270 | |
| 2271 | Register src_curr_addr = temp1.X(); |
| 2272 | Register dst_curr_addr = temp2.X(); |
| 2273 | Register src_stop_addr = temp3.X(); |
| 2274 | |
| 2275 | GenSystemArrayCopyAddresses(masm, |
| 2276 | Primitive::kPrimNot, |
| 2277 | src, |
| 2278 | src_pos, |
| 2279 | dest, |
| 2280 | dest_pos, |
| 2281 | length, |
| 2282 | src_curr_addr, |
| 2283 | dst_curr_addr, |
| 2284 | src_stop_addr); |
| 2285 | |
| 2286 | // Iterate over the arrays and do a raw copy of the objects. We don't need to |
Nicolas Geoffray | fea1abd | 2016-07-06 12:09:12 +0100 | [diff] [blame] | 2287 | // poison/unpoison. |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2288 | vixl::aarch64::Label loop, done; |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2289 | const int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot); |
| 2290 | __ Bind(&loop); |
| 2291 | __ Cmp(src_curr_addr, src_stop_addr); |
| 2292 | __ B(&done, eq); |
| 2293 | { |
| 2294 | Register tmp = temps.AcquireW(); |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2295 | __ Ldr(tmp, MemOperand(src_curr_addr, element_size, PostIndex)); |
| 2296 | __ Str(tmp, MemOperand(dst_curr_addr, element_size, PostIndex)); |
donghui.bai | c2ec9ad | 2016-03-10 14:02:55 +0800 | [diff] [blame] | 2297 | } |
| 2298 | __ B(&loop); |
| 2299 | __ Bind(&done); |
| 2300 | } |
| 2301 | // We only need one card marking on the destination array. |
| 2302 | codegen_->MarkGCCard(dest.W(), Register(), /* value_can_be_null */ false); |
| 2303 | |
| 2304 | __ Bind(slow_path->GetExitLabel()); |
| 2305 | } |
| 2306 | |
Anton Kirilov | a3ffea2 | 2016-04-07 17:02:37 +0100 | [diff] [blame] | 2307 | static void GenIsInfinite(LocationSummary* locations, |
| 2308 | bool is64bit, |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2309 | MacroAssembler* masm) { |
Anton Kirilov | a3ffea2 | 2016-04-07 17:02:37 +0100 | [diff] [blame] | 2310 | Operand infinity; |
| 2311 | Register out; |
| 2312 | |
| 2313 | if (is64bit) { |
| 2314 | infinity = kPositiveInfinityDouble; |
| 2315 | out = XRegisterFrom(locations->Out()); |
| 2316 | } else { |
| 2317 | infinity = kPositiveInfinityFloat; |
| 2318 | out = WRegisterFrom(locations->Out()); |
| 2319 | } |
| 2320 | |
Scott Wakeling | 97c72b7 | 2016-06-24 16:19:36 +0100 | [diff] [blame] | 2321 | const Register zero = vixl::aarch64::Assembler::AppropriateZeroRegFor(out); |
Anton Kirilov | a3ffea2 | 2016-04-07 17:02:37 +0100 | [diff] [blame] | 2322 | |
| 2323 | MoveFPToInt(locations, is64bit, masm); |
| 2324 | __ Eor(out, out, infinity); |
| 2325 | // We don't care about the sign bit, so shift left. |
| 2326 | __ Cmp(zero, Operand(out, LSL, 1)); |
| 2327 | __ Cset(out, eq); |
| 2328 | } |
| 2329 | |
| 2330 | void IntrinsicLocationsBuilderARM64::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2331 | CreateFPToIntLocations(arena_, invoke); |
| 2332 | } |
| 2333 | |
| 2334 | void IntrinsicCodeGeneratorARM64::VisitFloatIsInfinite(HInvoke* invoke) { |
| 2335 | GenIsInfinite(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
| 2336 | } |
| 2337 | |
| 2338 | void IntrinsicLocationsBuilderARM64::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2339 | CreateFPToIntLocations(arena_, invoke); |
| 2340 | } |
| 2341 | |
| 2342 | void IntrinsicCodeGeneratorARM64::VisitDoubleIsInfinite(HInvoke* invoke) { |
| 2343 | GenIsInfinite(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
| 2344 | } |
| 2345 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2346 | UNIMPLEMENTED_INTRINSIC(ARM64, ReferenceGetReferent) |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2347 | UNIMPLEMENTED_INTRINSIC(ARM64, IntegerHighestOneBit) |
| 2348 | UNIMPLEMENTED_INTRINSIC(ARM64, LongHighestOneBit) |
| 2349 | UNIMPLEMENTED_INTRINSIC(ARM64, IntegerLowestOneBit) |
| 2350 | UNIMPLEMENTED_INTRINSIC(ARM64, LongLowestOneBit) |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2351 | |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2352 | // 1.8. |
| 2353 | UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndAddInt) |
| 2354 | UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndAddLong) |
| 2355 | UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetInt) |
| 2356 | UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetLong) |
| 2357 | UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetObject) |
Aart Bik | 0e54c01 | 2016-03-04 12:08:31 -0800 | [diff] [blame] | 2358 | |
Aart Bik | 2f9fcc9 | 2016-03-01 15:16:54 -0800 | [diff] [blame] | 2359 | UNREACHABLE_INTRINSICS(ARM64) |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 2360 | |
| 2361 | #undef __ |
| 2362 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 2363 | } // namespace arm64 |
| 2364 | } // namespace art |