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" |
| 29 | #include "utils/arm64/constants_arm64.h" |
| 30 | |
Serban Constantinescu | 82e52ce | 2015-03-26 16:50:57 +0000 | [diff] [blame] | 31 | #include "vixl/a64/disasm-a64.h" |
| 32 | #include "vixl/a64/macro-assembler-a64.h" |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 33 | |
| 34 | using namespace vixl; // NOLINT(build/namespaces) |
| 35 | |
| 36 | namespace art { |
| 37 | |
| 38 | namespace arm64 { |
| 39 | |
| 40 | using helpers::DRegisterFrom; |
| 41 | using helpers::FPRegisterFrom; |
| 42 | using helpers::HeapOperand; |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 43 | using helpers::LocationFrom; |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 44 | using helpers::OperandFrom; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 45 | using helpers::RegisterFrom; |
| 46 | using helpers::SRegisterFrom; |
| 47 | using helpers::WRegisterFrom; |
| 48 | using helpers::XRegisterFrom; |
| 49 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 50 | namespace { |
| 51 | |
| 52 | ALWAYS_INLINE inline MemOperand AbsoluteHeapOperandFrom(Location location, size_t offset = 0) { |
| 53 | return MemOperand(XRegisterFrom(location), offset); |
| 54 | } |
| 55 | |
| 56 | } // namespace |
| 57 | |
| 58 | vixl::MacroAssembler* IntrinsicCodeGeneratorARM64::GetVIXLAssembler() { |
| 59 | return codegen_->GetAssembler()->vixl_masm_; |
| 60 | } |
| 61 | |
| 62 | ArenaAllocator* IntrinsicCodeGeneratorARM64::GetAllocator() { |
| 63 | return codegen_->GetGraph()->GetArena(); |
| 64 | } |
| 65 | |
| 66 | #define __ codegen->GetAssembler()->vixl_masm_-> |
| 67 | |
| 68 | static void MoveFromReturnRegister(Location trg, |
| 69 | Primitive::Type type, |
| 70 | CodeGeneratorARM64* codegen) { |
| 71 | if (!trg.IsValid()) { |
| 72 | DCHECK(type == Primitive::kPrimVoid); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | DCHECK_NE(type, Primitive::kPrimVoid); |
| 77 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 78 | if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 79 | Register trg_reg = RegisterFrom(trg, type); |
| 80 | Register res_reg = RegisterFrom(ARM64ReturnLocation(type), type); |
| 81 | __ Mov(trg_reg, res_reg, kDiscardForSameWReg); |
| 82 | } else { |
| 83 | FPRegister trg_reg = FPRegisterFrom(trg, type); |
| 84 | FPRegister res_reg = FPRegisterFrom(ARM64ReturnLocation(type), type); |
| 85 | __ Fmov(trg_reg, res_reg); |
| 86 | } |
| 87 | } |
| 88 | |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 89 | static void MoveArguments(HInvoke* invoke, CodeGeneratorARM64* codegen) { |
Roland Levillain | 2d27c8e | 2015-04-28 15:48:45 +0100 | [diff] [blame] | 90 | InvokeDexCallingConventionVisitorARM64 calling_convention_visitor; |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 91 | IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // Slow-path for fallback (calling the managed code to handle the intrinsic) in an intrinsified |
| 95 | // call. This will copy the arguments into the positions for a regular call. |
| 96 | // |
| 97 | // Note: The actual parameters are required to be in the locations given by the invoke's location |
| 98 | // summary. If an intrinsic modifies those locations before a slowpath call, they must be |
| 99 | // restored! |
| 100 | class IntrinsicSlowPathARM64 : public SlowPathCodeARM64 { |
| 101 | public: |
| 102 | explicit IntrinsicSlowPathARM64(HInvoke* invoke) : invoke_(invoke) { } |
| 103 | |
| 104 | void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE { |
| 105 | CodeGeneratorARM64* codegen = down_cast<CodeGeneratorARM64*>(codegen_in); |
| 106 | __ Bind(GetEntryLabel()); |
| 107 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 108 | SaveLiveRegisters(codegen, invoke_->GetLocations()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 109 | |
Roland Levillain | ec525fc | 2015-04-28 15:50:20 +0100 | [diff] [blame] | 110 | MoveArguments(invoke_, codegen); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 111 | |
| 112 | if (invoke_->IsInvokeStaticOrDirect()) { |
Nicolas Geoffray | 94015b9 | 2015-06-04 18:21:04 +0100 | [diff] [blame] | 113 | codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), |
| 114 | LocationFrom(kArtMethodRegister)); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 115 | } else { |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 116 | codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), LocationFrom(kArtMethodRegister)); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 117 | } |
Andreas Gampe | bfb5ba9 | 2015-09-01 15:45:02 +0000 | [diff] [blame] | 118 | codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 119 | |
| 120 | // Copy the result back to the expected output. |
| 121 | Location out = invoke_->GetLocations()->Out(); |
| 122 | if (out.IsValid()) { |
| 123 | DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory. |
| 124 | DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg())); |
| 125 | MoveFromReturnRegister(out, invoke_->GetType(), codegen); |
| 126 | } |
| 127 | |
Nicolas Geoffray | a8ac913 | 2015-03-13 16:36:36 +0000 | [diff] [blame] | 128 | RestoreLiveRegisters(codegen, invoke_->GetLocations()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 129 | __ B(GetExitLabel()); |
| 130 | } |
| 131 | |
Alexandre Rames | 9931f31 | 2015-06-19 14:47:01 +0100 | [diff] [blame] | 132 | const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathARM64"; } |
| 133 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 134 | private: |
| 135 | // The instruction where this slow path is happening. |
| 136 | HInvoke* const invoke_; |
| 137 | |
| 138 | DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARM64); |
| 139 | }; |
| 140 | |
| 141 | #undef __ |
| 142 | |
| 143 | bool IntrinsicLocationsBuilderARM64::TryDispatch(HInvoke* invoke) { |
| 144 | Dispatch(invoke); |
| 145 | LocationSummary* res = invoke->GetLocations(); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 146 | if (res == nullptr) { |
| 147 | return false; |
| 148 | } |
| 149 | if (kEmitCompilerReadBarrier && res->CanCall()) { |
| 150 | // Generating an intrinsic for this HInvoke may produce an |
| 151 | // IntrinsicSlowPathARM64 slow path. Currently this approach |
| 152 | // does not work when using read barriers, as the emitted |
| 153 | // calling sequence will make use of another slow path |
| 154 | // (ReadBarrierForRootSlowPathARM64 for HInvokeStaticOrDirect, |
| 155 | // ReadBarrierSlowPathARM64 for HInvokeVirtual). So we bail |
| 156 | // out in this case. |
| 157 | // |
| 158 | // TODO: Find a way to have intrinsics work with read barriers. |
| 159 | invoke->SetLocations(nullptr); |
| 160 | return false; |
| 161 | } |
| 162 | return res->Intrinsified(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | #define __ masm-> |
| 166 | |
| 167 | static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 168 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 169 | LocationSummary::kNoCall, |
| 170 | kIntrinsified); |
| 171 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 172 | locations->SetOut(Location::RequiresRegister()); |
| 173 | } |
| 174 | |
| 175 | static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 176 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 177 | LocationSummary::kNoCall, |
| 178 | kIntrinsified); |
| 179 | locations->SetInAt(0, Location::RequiresRegister()); |
| 180 | locations->SetOut(Location::RequiresFpuRegister()); |
| 181 | } |
| 182 | |
| 183 | static void MoveFPToInt(LocationSummary* locations, bool is64bit, vixl::MacroAssembler* masm) { |
| 184 | Location input = locations->InAt(0); |
| 185 | Location output = locations->Out(); |
| 186 | __ Fmov(is64bit ? XRegisterFrom(output) : WRegisterFrom(output), |
| 187 | is64bit ? DRegisterFrom(input) : SRegisterFrom(input)); |
| 188 | } |
| 189 | |
| 190 | static void MoveIntToFP(LocationSummary* locations, bool is64bit, vixl::MacroAssembler* masm) { |
| 191 | Location input = locations->InAt(0); |
| 192 | Location output = locations->Out(); |
| 193 | __ Fmov(is64bit ? DRegisterFrom(output) : SRegisterFrom(output), |
| 194 | is64bit ? XRegisterFrom(input) : WRegisterFrom(input)); |
| 195 | } |
| 196 | |
| 197 | void IntrinsicLocationsBuilderARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
| 198 | CreateFPToIntLocations(arena_, invoke); |
| 199 | } |
| 200 | void IntrinsicLocationsBuilderARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
| 201 | CreateIntToFPLocations(arena_, invoke); |
| 202 | } |
| 203 | |
| 204 | void IntrinsicCodeGeneratorARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 205 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 206 | } |
| 207 | void IntrinsicCodeGeneratorARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 208 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void IntrinsicLocationsBuilderARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
| 212 | CreateFPToIntLocations(arena_, invoke); |
| 213 | } |
| 214 | void IntrinsicLocationsBuilderARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
| 215 | CreateIntToFPLocations(arena_, invoke); |
| 216 | } |
| 217 | |
| 218 | void IntrinsicCodeGeneratorARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 219 | MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 220 | } |
| 221 | void IntrinsicCodeGeneratorARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 222 | MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 226 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 227 | LocationSummary::kNoCall, |
| 228 | kIntrinsified); |
| 229 | locations->SetInAt(0, Location::RequiresRegister()); |
| 230 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 231 | } |
| 232 | |
| 233 | static void GenReverseBytes(LocationSummary* locations, |
| 234 | Primitive::Type type, |
| 235 | vixl::MacroAssembler* masm) { |
| 236 | Location in = locations->InAt(0); |
| 237 | Location out = locations->Out(); |
| 238 | |
| 239 | switch (type) { |
| 240 | case Primitive::kPrimShort: |
| 241 | __ Rev16(WRegisterFrom(out), WRegisterFrom(in)); |
| 242 | __ Sxth(WRegisterFrom(out), WRegisterFrom(out)); |
| 243 | break; |
| 244 | case Primitive::kPrimInt: |
| 245 | case Primitive::kPrimLong: |
| 246 | __ Rev(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 247 | break; |
| 248 | default: |
| 249 | LOG(FATAL) << "Unexpected size for reverse-bytes: " << type; |
| 250 | UNREACHABLE(); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void IntrinsicLocationsBuilderARM64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 255 | CreateIntToIntLocations(arena_, invoke); |
| 256 | } |
| 257 | |
| 258 | void IntrinsicCodeGeneratorARM64::VisitIntegerReverseBytes(HInvoke* invoke) { |
| 259 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 260 | } |
| 261 | |
| 262 | void IntrinsicLocationsBuilderARM64::VisitLongReverseBytes(HInvoke* invoke) { |
| 263 | CreateIntToIntLocations(arena_, invoke); |
| 264 | } |
| 265 | |
| 266 | void IntrinsicCodeGeneratorARM64::VisitLongReverseBytes(HInvoke* invoke) { |
| 267 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 268 | } |
| 269 | |
| 270 | void IntrinsicLocationsBuilderARM64::VisitShortReverseBytes(HInvoke* invoke) { |
| 271 | CreateIntToIntLocations(arena_, invoke); |
| 272 | } |
| 273 | |
| 274 | void IntrinsicCodeGeneratorARM64::VisitShortReverseBytes(HInvoke* invoke) { |
| 275 | GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetVIXLAssembler()); |
| 276 | } |
| 277 | |
Scott Wakeling | 611d339 | 2015-07-10 11:42:06 +0100 | [diff] [blame] | 278 | static void GenNumberOfLeadingZeros(LocationSummary* locations, |
| 279 | Primitive::Type type, |
| 280 | vixl::MacroAssembler* masm) { |
| 281 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 282 | |
| 283 | Location in = locations->InAt(0); |
| 284 | Location out = locations->Out(); |
| 285 | |
| 286 | __ Clz(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 287 | } |
| 288 | |
| 289 | void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 290 | CreateIntToIntLocations(arena_, invoke); |
| 291 | } |
| 292 | |
| 293 | void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) { |
| 294 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 295 | } |
| 296 | |
| 297 | void IntrinsicLocationsBuilderARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 298 | CreateIntToIntLocations(arena_, invoke); |
| 299 | } |
| 300 | |
| 301 | void IntrinsicCodeGeneratorARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) { |
| 302 | GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 303 | } |
| 304 | |
Scott Wakeling | 9ee23f4 | 2015-07-23 10:44:35 +0100 | [diff] [blame] | 305 | static void GenNumberOfTrailingZeros(LocationSummary* locations, |
| 306 | Primitive::Type type, |
| 307 | vixl::MacroAssembler* masm) { |
| 308 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 309 | |
| 310 | Location in = locations->InAt(0); |
| 311 | Location out = locations->Out(); |
| 312 | |
| 313 | __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 314 | __ Clz(RegisterFrom(out, type), RegisterFrom(out, type)); |
| 315 | } |
| 316 | |
| 317 | void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 318 | CreateIntToIntLocations(arena_, invoke); |
| 319 | } |
| 320 | |
| 321 | void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) { |
| 322 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 323 | } |
| 324 | |
| 325 | void IntrinsicLocationsBuilderARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 326 | CreateIntToIntLocations(arena_, invoke); |
| 327 | } |
| 328 | |
| 329 | void IntrinsicCodeGeneratorARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) { |
| 330 | GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 331 | } |
| 332 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 333 | static void GenReverse(LocationSummary* locations, |
| 334 | Primitive::Type type, |
| 335 | vixl::MacroAssembler* masm) { |
| 336 | DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong); |
| 337 | |
| 338 | Location in = locations->InAt(0); |
| 339 | Location out = locations->Out(); |
| 340 | |
| 341 | __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type)); |
| 342 | } |
| 343 | |
| 344 | void IntrinsicLocationsBuilderARM64::VisitIntegerReverse(HInvoke* invoke) { |
| 345 | CreateIntToIntLocations(arena_, invoke); |
| 346 | } |
| 347 | |
| 348 | void IntrinsicCodeGeneratorARM64::VisitIntegerReverse(HInvoke* invoke) { |
| 349 | GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler()); |
| 350 | } |
| 351 | |
| 352 | void IntrinsicLocationsBuilderARM64::VisitLongReverse(HInvoke* invoke) { |
| 353 | CreateIntToIntLocations(arena_, invoke); |
| 354 | } |
| 355 | |
| 356 | void IntrinsicCodeGeneratorARM64::VisitLongReverse(HInvoke* invoke) { |
| 357 | GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler()); |
| 358 | } |
| 359 | |
| 360 | static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 361 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 362 | LocationSummary::kNoCall, |
| 363 | kIntrinsified); |
| 364 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 365 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 366 | } |
| 367 | |
| 368 | static void MathAbsFP(LocationSummary* locations, bool is64bit, vixl::MacroAssembler* masm) { |
| 369 | Location in = locations->InAt(0); |
| 370 | Location out = locations->Out(); |
| 371 | |
| 372 | FPRegister in_reg = is64bit ? DRegisterFrom(in) : SRegisterFrom(in); |
| 373 | FPRegister out_reg = is64bit ? DRegisterFrom(out) : SRegisterFrom(out); |
| 374 | |
| 375 | __ Fabs(out_reg, in_reg); |
| 376 | } |
| 377 | |
| 378 | void IntrinsicLocationsBuilderARM64::VisitMathAbsDouble(HInvoke* invoke) { |
| 379 | CreateFPToFPLocations(arena_, invoke); |
| 380 | } |
| 381 | |
| 382 | void IntrinsicCodeGeneratorARM64::VisitMathAbsDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 383 | MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void IntrinsicLocationsBuilderARM64::VisitMathAbsFloat(HInvoke* invoke) { |
| 387 | CreateFPToFPLocations(arena_, invoke); |
| 388 | } |
| 389 | |
| 390 | void IntrinsicCodeGeneratorARM64::VisitMathAbsFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 391 | MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 395 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 396 | LocationSummary::kNoCall, |
| 397 | kIntrinsified); |
| 398 | locations->SetInAt(0, Location::RequiresRegister()); |
| 399 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 400 | } |
| 401 | |
| 402 | static void GenAbsInteger(LocationSummary* locations, |
| 403 | bool is64bit, |
| 404 | vixl::MacroAssembler* masm) { |
| 405 | Location in = locations->InAt(0); |
| 406 | Location output = locations->Out(); |
| 407 | |
| 408 | Register in_reg = is64bit ? XRegisterFrom(in) : WRegisterFrom(in); |
| 409 | Register out_reg = is64bit ? XRegisterFrom(output) : WRegisterFrom(output); |
| 410 | |
| 411 | __ Cmp(in_reg, Operand(0)); |
| 412 | __ Cneg(out_reg, in_reg, lt); |
| 413 | } |
| 414 | |
| 415 | void IntrinsicLocationsBuilderARM64::VisitMathAbsInt(HInvoke* invoke) { |
| 416 | CreateIntToInt(arena_, invoke); |
| 417 | } |
| 418 | |
| 419 | void IntrinsicCodeGeneratorARM64::VisitMathAbsInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 420 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void IntrinsicLocationsBuilderARM64::VisitMathAbsLong(HInvoke* invoke) { |
| 424 | CreateIntToInt(arena_, invoke); |
| 425 | } |
| 426 | |
| 427 | void IntrinsicCodeGeneratorARM64::VisitMathAbsLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 428 | GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void GenMinMaxFP(LocationSummary* locations, |
| 432 | bool is_min, |
| 433 | bool is_double, |
| 434 | vixl::MacroAssembler* masm) { |
| 435 | Location op1 = locations->InAt(0); |
| 436 | Location op2 = locations->InAt(1); |
| 437 | Location out = locations->Out(); |
| 438 | |
| 439 | FPRegister op1_reg = is_double ? DRegisterFrom(op1) : SRegisterFrom(op1); |
| 440 | FPRegister op2_reg = is_double ? DRegisterFrom(op2) : SRegisterFrom(op2); |
| 441 | FPRegister out_reg = is_double ? DRegisterFrom(out) : SRegisterFrom(out); |
| 442 | if (is_min) { |
| 443 | __ Fmin(out_reg, op1_reg, op2_reg); |
| 444 | } else { |
| 445 | __ Fmax(out_reg, op1_reg, op2_reg); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 450 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 451 | LocationSummary::kNoCall, |
| 452 | kIntrinsified); |
| 453 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 454 | locations->SetInAt(1, Location::RequiresFpuRegister()); |
| 455 | locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap); |
| 456 | } |
| 457 | |
| 458 | void IntrinsicLocationsBuilderARM64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
| 459 | CreateFPFPToFPLocations(arena_, invoke); |
| 460 | } |
| 461 | |
| 462 | void IntrinsicCodeGeneratorARM64::VisitMathMinDoubleDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 463 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void IntrinsicLocationsBuilderARM64::VisitMathMinFloatFloat(HInvoke* invoke) { |
| 467 | CreateFPFPToFPLocations(arena_, invoke); |
| 468 | } |
| 469 | |
| 470 | void IntrinsicCodeGeneratorARM64::VisitMathMinFloatFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 471 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void IntrinsicLocationsBuilderARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
| 475 | CreateFPFPToFPLocations(arena_, invoke); |
| 476 | } |
| 477 | |
| 478 | void IntrinsicCodeGeneratorARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 479 | GenMinMaxFP(invoke->GetLocations(), /* is_min */ false, /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | void IntrinsicLocationsBuilderARM64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
| 483 | CreateFPFPToFPLocations(arena_, invoke); |
| 484 | } |
| 485 | |
| 486 | void IntrinsicCodeGeneratorARM64::VisitMathMaxFloatFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 487 | GenMinMaxFP( |
| 488 | invoke->GetLocations(), /* is_min */ false, /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | static void GenMinMax(LocationSummary* locations, |
| 492 | bool is_min, |
| 493 | bool is_long, |
| 494 | vixl::MacroAssembler* masm) { |
| 495 | Location op1 = locations->InAt(0); |
| 496 | Location op2 = locations->InAt(1); |
| 497 | Location out = locations->Out(); |
| 498 | |
| 499 | Register op1_reg = is_long ? XRegisterFrom(op1) : WRegisterFrom(op1); |
| 500 | Register op2_reg = is_long ? XRegisterFrom(op2) : WRegisterFrom(op2); |
| 501 | Register out_reg = is_long ? XRegisterFrom(out) : WRegisterFrom(out); |
| 502 | |
| 503 | __ Cmp(op1_reg, op2_reg); |
| 504 | __ Csel(out_reg, op1_reg, op2_reg, is_min ? lt : gt); |
| 505 | } |
| 506 | |
| 507 | static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 508 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 509 | LocationSummary::kNoCall, |
| 510 | kIntrinsified); |
| 511 | locations->SetInAt(0, Location::RequiresRegister()); |
| 512 | locations->SetInAt(1, Location::RequiresRegister()); |
| 513 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 514 | } |
| 515 | |
| 516 | void IntrinsicLocationsBuilderARM64::VisitMathMinIntInt(HInvoke* invoke) { |
| 517 | CreateIntIntToIntLocations(arena_, invoke); |
| 518 | } |
| 519 | |
| 520 | void IntrinsicCodeGeneratorARM64::VisitMathMinIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 521 | GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void IntrinsicLocationsBuilderARM64::VisitMathMinLongLong(HInvoke* invoke) { |
| 525 | CreateIntIntToIntLocations(arena_, invoke); |
| 526 | } |
| 527 | |
| 528 | void IntrinsicCodeGeneratorARM64::VisitMathMinLongLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 529 | GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | void IntrinsicLocationsBuilderARM64::VisitMathMaxIntInt(HInvoke* invoke) { |
| 533 | CreateIntIntToIntLocations(arena_, invoke); |
| 534 | } |
| 535 | |
| 536 | void IntrinsicCodeGeneratorARM64::VisitMathMaxIntInt(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 537 | GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void IntrinsicLocationsBuilderARM64::VisitMathMaxLongLong(HInvoke* invoke) { |
| 541 | CreateIntIntToIntLocations(arena_, invoke); |
| 542 | } |
| 543 | |
| 544 | void IntrinsicCodeGeneratorARM64::VisitMathMaxLongLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 545 | GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | void IntrinsicLocationsBuilderARM64::VisitMathSqrt(HInvoke* invoke) { |
| 549 | CreateFPToFPLocations(arena_, invoke); |
| 550 | } |
| 551 | |
| 552 | void IntrinsicCodeGeneratorARM64::VisitMathSqrt(HInvoke* invoke) { |
| 553 | LocationSummary* locations = invoke->GetLocations(); |
| 554 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 555 | __ Fsqrt(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 556 | } |
| 557 | |
| 558 | void IntrinsicLocationsBuilderARM64::VisitMathCeil(HInvoke* invoke) { |
| 559 | CreateFPToFPLocations(arena_, invoke); |
| 560 | } |
| 561 | |
| 562 | void IntrinsicCodeGeneratorARM64::VisitMathCeil(HInvoke* invoke) { |
| 563 | LocationSummary* locations = invoke->GetLocations(); |
| 564 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 565 | __ Frintp(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 566 | } |
| 567 | |
| 568 | void IntrinsicLocationsBuilderARM64::VisitMathFloor(HInvoke* invoke) { |
| 569 | CreateFPToFPLocations(arena_, invoke); |
| 570 | } |
| 571 | |
| 572 | void IntrinsicCodeGeneratorARM64::VisitMathFloor(HInvoke* invoke) { |
| 573 | LocationSummary* locations = invoke->GetLocations(); |
| 574 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 575 | __ Frintm(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 576 | } |
| 577 | |
| 578 | void IntrinsicLocationsBuilderARM64::VisitMathRint(HInvoke* invoke) { |
| 579 | CreateFPToFPLocations(arena_, invoke); |
| 580 | } |
| 581 | |
| 582 | void IntrinsicCodeGeneratorARM64::VisitMathRint(HInvoke* invoke) { |
| 583 | LocationSummary* locations = invoke->GetLocations(); |
| 584 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 585 | __ Frintn(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0))); |
| 586 | } |
| 587 | |
| 588 | static void CreateFPToIntPlusTempLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 589 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 590 | LocationSummary::kNoCall, |
| 591 | kIntrinsified); |
| 592 | locations->SetInAt(0, Location::RequiresFpuRegister()); |
| 593 | locations->SetOut(Location::RequiresRegister()); |
| 594 | } |
| 595 | |
| 596 | static void GenMathRound(LocationSummary* locations, |
| 597 | bool is_double, |
| 598 | vixl::MacroAssembler* masm) { |
| 599 | FPRegister in_reg = is_double ? |
| 600 | DRegisterFrom(locations->InAt(0)) : SRegisterFrom(locations->InAt(0)); |
| 601 | Register out_reg = is_double ? |
| 602 | XRegisterFrom(locations->Out()) : WRegisterFrom(locations->Out()); |
| 603 | UseScratchRegisterScope temps(masm); |
| 604 | FPRegister temp1_reg = temps.AcquireSameSizeAs(in_reg); |
| 605 | |
| 606 | // 0.5 can be encoded as an immediate, so use fmov. |
| 607 | if (is_double) { |
| 608 | __ Fmov(temp1_reg, static_cast<double>(0.5)); |
| 609 | } else { |
| 610 | __ Fmov(temp1_reg, static_cast<float>(0.5)); |
| 611 | } |
| 612 | __ Fadd(temp1_reg, in_reg, temp1_reg); |
| 613 | __ Fcvtms(out_reg, temp1_reg); |
| 614 | } |
| 615 | |
| 616 | void IntrinsicLocationsBuilderARM64::VisitMathRoundDouble(HInvoke* invoke) { |
| 617 | CreateFPToIntPlusTempLocations(arena_, invoke); |
| 618 | } |
| 619 | |
| 620 | void IntrinsicCodeGeneratorARM64::VisitMathRoundDouble(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 621 | GenMathRound(invoke->GetLocations(), /* is_double */ true, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void IntrinsicLocationsBuilderARM64::VisitMathRoundFloat(HInvoke* invoke) { |
| 625 | CreateFPToIntPlusTempLocations(arena_, invoke); |
| 626 | } |
| 627 | |
| 628 | void IntrinsicCodeGeneratorARM64::VisitMathRoundFloat(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 629 | GenMathRound(invoke->GetLocations(), /* is_double */ false, GetVIXLAssembler()); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 633 | CreateIntToIntLocations(arena_, invoke); |
| 634 | } |
| 635 | |
| 636 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekByte(HInvoke* invoke) { |
| 637 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 638 | __ Ldrsb(WRegisterFrom(invoke->GetLocations()->Out()), |
| 639 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 640 | } |
| 641 | |
| 642 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 643 | CreateIntToIntLocations(arena_, invoke); |
| 644 | } |
| 645 | |
| 646 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekIntNative(HInvoke* invoke) { |
| 647 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 648 | __ Ldr(WRegisterFrom(invoke->GetLocations()->Out()), |
| 649 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 650 | } |
| 651 | |
| 652 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 653 | CreateIntToIntLocations(arena_, invoke); |
| 654 | } |
| 655 | |
| 656 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekLongNative(HInvoke* invoke) { |
| 657 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 658 | __ Ldr(XRegisterFrom(invoke->GetLocations()->Out()), |
| 659 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 660 | } |
| 661 | |
| 662 | void IntrinsicLocationsBuilderARM64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 663 | CreateIntToIntLocations(arena_, invoke); |
| 664 | } |
| 665 | |
| 666 | void IntrinsicCodeGeneratorARM64::VisitMemoryPeekShortNative(HInvoke* invoke) { |
| 667 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 668 | __ Ldrsh(WRegisterFrom(invoke->GetLocations()->Out()), |
| 669 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 670 | } |
| 671 | |
| 672 | static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) { |
| 673 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 674 | LocationSummary::kNoCall, |
| 675 | kIntrinsified); |
| 676 | locations->SetInAt(0, Location::RequiresRegister()); |
| 677 | locations->SetInAt(1, Location::RequiresRegister()); |
| 678 | } |
| 679 | |
| 680 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 681 | CreateIntIntToVoidLocations(arena_, invoke); |
| 682 | } |
| 683 | |
| 684 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeByte(HInvoke* invoke) { |
| 685 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 686 | __ Strb(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 687 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 688 | } |
| 689 | |
| 690 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 691 | CreateIntIntToVoidLocations(arena_, invoke); |
| 692 | } |
| 693 | |
| 694 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeIntNative(HInvoke* invoke) { |
| 695 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 696 | __ Str(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 697 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 698 | } |
| 699 | |
| 700 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 701 | CreateIntIntToVoidLocations(arena_, invoke); |
| 702 | } |
| 703 | |
| 704 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeLongNative(HInvoke* invoke) { |
| 705 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 706 | __ Str(XRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 707 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 708 | } |
| 709 | |
| 710 | void IntrinsicLocationsBuilderARM64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 711 | CreateIntIntToVoidLocations(arena_, invoke); |
| 712 | } |
| 713 | |
| 714 | void IntrinsicCodeGeneratorARM64::VisitMemoryPokeShortNative(HInvoke* invoke) { |
| 715 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 716 | __ Strh(WRegisterFrom(invoke->GetLocations()->InAt(1)), |
| 717 | AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0)); |
| 718 | } |
| 719 | |
| 720 | void IntrinsicLocationsBuilderARM64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 721 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 722 | LocationSummary::kNoCall, |
| 723 | kIntrinsified); |
| 724 | locations->SetOut(Location::RequiresRegister()); |
| 725 | } |
| 726 | |
| 727 | void IntrinsicCodeGeneratorARM64::VisitThreadCurrentThread(HInvoke* invoke) { |
| 728 | codegen_->Load(Primitive::kPrimNot, WRegisterFrom(invoke->GetLocations()->Out()), |
| 729 | MemOperand(tr, Thread::PeerOffset<8>().Int32Value())); |
| 730 | } |
| 731 | |
| 732 | static void GenUnsafeGet(HInvoke* invoke, |
| 733 | Primitive::Type type, |
| 734 | bool is_volatile, |
| 735 | CodeGeneratorARM64* codegen) { |
| 736 | LocationSummary* locations = invoke->GetLocations(); |
| 737 | DCHECK((type == Primitive::kPrimInt) || |
| 738 | (type == Primitive::kPrimLong) || |
| 739 | (type == Primitive::kPrimNot)); |
| 740 | vixl::MacroAssembler* masm = codegen->GetAssembler()->vixl_masm_; |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 741 | Location base_loc = locations->InAt(1); |
| 742 | Register base = WRegisterFrom(base_loc); // Object pointer. |
| 743 | Location offset_loc = locations->InAt(2); |
| 744 | Register offset = XRegisterFrom(offset_loc); // Long offset. |
| 745 | Location trg_loc = locations->Out(); |
| 746 | Register trg = RegisterFrom(trg_loc, type); |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 747 | bool use_acquire_release = codegen->GetInstructionSetFeatures().PreferAcquireRelease(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 748 | |
| 749 | MemOperand mem_op(base.X(), offset); |
| 750 | if (is_volatile) { |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 751 | if (use_acquire_release) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 752 | codegen->LoadAcquire(invoke, trg, mem_op); |
| 753 | } else { |
| 754 | codegen->Load(type, trg, mem_op); |
| 755 | __ Dmb(InnerShareable, BarrierReads); |
| 756 | } |
| 757 | } else { |
| 758 | codegen->Load(type, trg, mem_op); |
| 759 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 760 | |
| 761 | if (type == Primitive::kPrimNot) { |
| 762 | DCHECK(trg.IsW()); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 763 | codegen->MaybeGenerateReadBarrier(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 764 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) { |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 768 | bool can_call = kEmitCompilerReadBarrier && |
| 769 | (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject || |
| 770 | invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 771 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 772 | can_call ? |
| 773 | LocationSummary::kCallOnSlowPath : |
| 774 | LocationSummary::kNoCall, |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 775 | kIntrinsified); |
| 776 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 777 | locations->SetInAt(1, Location::RequiresRegister()); |
| 778 | locations->SetInAt(2, Location::RequiresRegister()); |
| 779 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 780 | } |
| 781 | |
| 782 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGet(HInvoke* invoke) { |
| 783 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 784 | } |
| 785 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
| 786 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 787 | } |
| 788 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLong(HInvoke* invoke) { |
| 789 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 790 | } |
| 791 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
| 792 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 793 | } |
| 794 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObject(HInvoke* invoke) { |
| 795 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 796 | } |
| 797 | void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
| 798 | CreateIntIntIntToIntLocations(arena_, invoke); |
| 799 | } |
| 800 | |
| 801 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGet(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 802 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 803 | } |
| 804 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 805 | GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 806 | } |
| 807 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 808 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 809 | } |
| 810 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 811 | GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 812 | } |
| 813 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 814 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 815 | } |
| 816 | void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 817 | GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) { |
| 821 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 822 | LocationSummary::kNoCall, |
| 823 | kIntrinsified); |
| 824 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 825 | locations->SetInAt(1, Location::RequiresRegister()); |
| 826 | locations->SetInAt(2, Location::RequiresRegister()); |
| 827 | locations->SetInAt(3, Location::RequiresRegister()); |
| 828 | } |
| 829 | |
| 830 | void IntrinsicLocationsBuilderARM64::VisitUnsafePut(HInvoke* invoke) { |
| 831 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 832 | } |
| 833 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutOrdered(HInvoke* invoke) { |
| 834 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 835 | } |
| 836 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutVolatile(HInvoke* invoke) { |
| 837 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 838 | } |
| 839 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObject(HInvoke* invoke) { |
| 840 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 841 | } |
| 842 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
| 843 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 844 | } |
| 845 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
| 846 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 847 | } |
| 848 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLong(HInvoke* invoke) { |
| 849 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 850 | } |
| 851 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
| 852 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 853 | } |
| 854 | void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
| 855 | CreateIntIntIntIntToVoid(arena_, invoke); |
| 856 | } |
| 857 | |
| 858 | static void GenUnsafePut(LocationSummary* locations, |
| 859 | Primitive::Type type, |
| 860 | bool is_volatile, |
| 861 | bool is_ordered, |
| 862 | CodeGeneratorARM64* codegen) { |
| 863 | vixl::MacroAssembler* masm = codegen->GetAssembler()->vixl_masm_; |
| 864 | |
| 865 | Register base = WRegisterFrom(locations->InAt(1)); // Object pointer. |
| 866 | Register offset = XRegisterFrom(locations->InAt(2)); // Long offset. |
| 867 | Register value = RegisterFrom(locations->InAt(3), type); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 868 | Register source = value; |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 869 | bool use_acquire_release = codegen->GetInstructionSetFeatures().PreferAcquireRelease(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 870 | |
| 871 | MemOperand mem_op(base.X(), offset); |
| 872 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 873 | { |
| 874 | // We use a block to end the scratch scope before the write barrier, thus |
| 875 | // freeing the temporary registers so they can be used in `MarkGCCard`. |
| 876 | UseScratchRegisterScope temps(masm); |
| 877 | |
| 878 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 879 | DCHECK(value.IsW()); |
| 880 | Register temp = temps.AcquireW(); |
| 881 | __ Mov(temp.W(), value.W()); |
| 882 | codegen->GetAssembler()->PoisonHeapReference(temp.W()); |
| 883 | source = temp; |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 884 | } |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 885 | |
| 886 | if (is_volatile || is_ordered) { |
| 887 | if (use_acquire_release) { |
| 888 | codegen->StoreRelease(type, source, mem_op); |
| 889 | } else { |
| 890 | __ Dmb(InnerShareable, BarrierAll); |
| 891 | codegen->Store(type, source, mem_op); |
| 892 | if (is_volatile) { |
| 893 | __ Dmb(InnerShareable, BarrierReads); |
| 894 | } |
| 895 | } |
| 896 | } else { |
| 897 | codegen->Store(type, source, mem_op); |
| 898 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | if (type == Primitive::kPrimNot) { |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 902 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 903 | codegen->MarkGCCard(base, value, value_can_be_null); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
| 907 | void IntrinsicCodeGeneratorARM64::VisitUnsafePut(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 908 | GenUnsafePut(invoke->GetLocations(), |
| 909 | Primitive::kPrimInt, |
| 910 | /* is_volatile */ false, |
| 911 | /* is_ordered */ false, |
| 912 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 913 | } |
| 914 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 915 | GenUnsafePut(invoke->GetLocations(), |
| 916 | Primitive::kPrimInt, |
| 917 | /* is_volatile */ false, |
| 918 | /* is_ordered */ true, |
| 919 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 920 | } |
| 921 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 922 | GenUnsafePut(invoke->GetLocations(), |
| 923 | Primitive::kPrimInt, |
| 924 | /* is_volatile */ true, |
| 925 | /* is_ordered */ false, |
| 926 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 927 | } |
| 928 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObject(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 929 | GenUnsafePut(invoke->GetLocations(), |
| 930 | Primitive::kPrimNot, |
| 931 | /* is_volatile */ false, |
| 932 | /* is_ordered */ false, |
| 933 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 934 | } |
| 935 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 936 | GenUnsafePut(invoke->GetLocations(), |
| 937 | Primitive::kPrimNot, |
| 938 | /* is_volatile */ false, |
| 939 | /* is_ordered */ true, |
| 940 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 941 | } |
| 942 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 943 | GenUnsafePut(invoke->GetLocations(), |
| 944 | Primitive::kPrimNot, |
| 945 | /* is_volatile */ true, |
| 946 | /* is_ordered */ false, |
| 947 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 948 | } |
| 949 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLong(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 950 | GenUnsafePut(invoke->GetLocations(), |
| 951 | Primitive::kPrimLong, |
| 952 | /* is_volatile */ false, |
| 953 | /* is_ordered */ false, |
| 954 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 955 | } |
| 956 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 957 | GenUnsafePut(invoke->GetLocations(), |
| 958 | Primitive::kPrimLong, |
| 959 | /* is_volatile */ false, |
| 960 | /* is_ordered */ true, |
| 961 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 962 | } |
| 963 | void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 964 | GenUnsafePut(invoke->GetLocations(), |
| 965 | Primitive::kPrimLong, |
| 966 | /* is_volatile */ true, |
| 967 | /* is_ordered */ false, |
| 968 | codegen_); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | static void CreateIntIntIntIntIntToInt(ArenaAllocator* arena, HInvoke* invoke) { |
| 972 | LocationSummary* locations = new (arena) LocationSummary(invoke, |
| 973 | LocationSummary::kNoCall, |
| 974 | kIntrinsified); |
| 975 | locations->SetInAt(0, Location::NoLocation()); // Unused receiver. |
| 976 | locations->SetInAt(1, Location::RequiresRegister()); |
| 977 | locations->SetInAt(2, Location::RequiresRegister()); |
| 978 | locations->SetInAt(3, Location::RequiresRegister()); |
| 979 | locations->SetInAt(4, Location::RequiresRegister()); |
| 980 | |
| 981 | locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap); |
| 982 | } |
| 983 | |
| 984 | static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM64* codegen) { |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 985 | bool use_acquire_release = codegen->GetInstructionSetFeatures().PreferAcquireRelease(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 986 | vixl::MacroAssembler* masm = codegen->GetAssembler()->vixl_masm_; |
| 987 | |
| 988 | Register out = WRegisterFrom(locations->Out()); // Boolean result. |
| 989 | |
| 990 | Register base = WRegisterFrom(locations->InAt(1)); // Object pointer. |
| 991 | Register offset = XRegisterFrom(locations->InAt(2)); // Long offset. |
| 992 | Register expected = RegisterFrom(locations->InAt(3), type); // Expected. |
| 993 | Register value = RegisterFrom(locations->InAt(4), type); // Value. |
| 994 | |
| 995 | // This needs to be before the temp registers, as MarkGCCard also uses VIXL temps. |
| 996 | if (type == Primitive::kPrimNot) { |
| 997 | // Mark card for object assuming new value is stored. |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 998 | bool value_can_be_null = true; // TODO: Worth finding out this information? |
| 999 | codegen->MarkGCCard(base, value, value_can_be_null); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | UseScratchRegisterScope temps(masm); |
| 1003 | Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory. |
| 1004 | Register tmp_value = temps.AcquireSameSizeAs(value); // Value in memory. |
| 1005 | |
| 1006 | Register tmp_32 = tmp_value.W(); |
| 1007 | |
| 1008 | __ Add(tmp_ptr, base.X(), Operand(offset)); |
| 1009 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1010 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1011 | codegen->GetAssembler()->PoisonHeapReference(expected); |
| 1012 | codegen->GetAssembler()->PoisonHeapReference(value); |
| 1013 | } |
| 1014 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1015 | // do { |
| 1016 | // tmp_value = [tmp_ptr] - expected; |
| 1017 | // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value)); |
| 1018 | // result = tmp_value != 0; |
| 1019 | |
| 1020 | vixl::Label loop_head, exit_loop; |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1021 | if (use_acquire_release) { |
| 1022 | __ Bind(&loop_head); |
| 1023 | __ Ldaxr(tmp_value, MemOperand(tmp_ptr)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1024 | // TODO: Do we need a read barrier here when `type == Primitive::kPrimNot`? |
| 1025 | // Note that this code is not (yet) used when read barriers are |
| 1026 | // enabled (see IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject). |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1027 | __ Cmp(tmp_value, expected); |
| 1028 | __ B(&exit_loop, ne); |
| 1029 | __ Stlxr(tmp_32, value, MemOperand(tmp_ptr)); |
| 1030 | __ Cbnz(tmp_32, &loop_head); |
| 1031 | } else { |
| 1032 | __ Dmb(InnerShareable, BarrierWrites); |
| 1033 | __ Bind(&loop_head); |
| 1034 | __ Ldxr(tmp_value, MemOperand(tmp_ptr)); |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1035 | // TODO: Do we need a read barrier here when `type == Primitive::kPrimNot`? |
| 1036 | // Note that this code is not (yet) used when read barriers are |
| 1037 | // enabled (see IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject). |
Serban Constantinescu | 579885a | 2015-02-22 20:51:33 +0000 | [diff] [blame] | 1038 | __ Cmp(tmp_value, expected); |
| 1039 | __ B(&exit_loop, ne); |
| 1040 | __ Stxr(tmp_32, value, MemOperand(tmp_ptr)); |
| 1041 | __ Cbnz(tmp_32, &loop_head); |
| 1042 | __ Dmb(InnerShareable, BarrierAll); |
| 1043 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1044 | __ Bind(&exit_loop); |
| 1045 | __ Cset(out, eq); |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1046 | |
| 1047 | if (kPoisonHeapReferences && type == Primitive::kPrimNot) { |
| 1048 | codegen->GetAssembler()->UnpoisonHeapReference(value); |
| 1049 | codegen->GetAssembler()->UnpoisonHeapReference(expected); |
| 1050 | } |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASInt(HInvoke* invoke) { |
| 1054 | CreateIntIntIntIntIntToInt(arena_, invoke); |
| 1055 | } |
| 1056 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASLong(HInvoke* invoke) { |
| 1057 | CreateIntIntIntIntIntToInt(arena_, invoke); |
| 1058 | } |
| 1059 | void IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject(HInvoke* invoke) { |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 1060 | // The UnsafeCASObject intrinsic does not always work when heap |
| 1061 | // poisoning is enabled (it breaks run-test 004-UnsafeTest); turn it |
| 1062 | // off temporarily as a quick fix. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1063 | // |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 1064 | // TODO(rpl): Fix it and turn it back on. |
Roland Levillain | 22ccc3a | 2015-11-24 13:10:05 +0000 | [diff] [blame] | 1065 | // |
| 1066 | // TODO(rpl): Also, we should investigate whether we need a read |
| 1067 | // barrier in the generated code. |
Roland Levillain | 985ff70 | 2015-10-23 13:25:35 +0100 | [diff] [blame] | 1068 | if (kPoisonHeapReferences) { |
| 1069 | return; |
| 1070 | } |
| 1071 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1072 | CreateIntIntIntIntIntToInt(arena_, invoke); |
| 1073 | } |
| 1074 | |
| 1075 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASInt(HInvoke* invoke) { |
| 1076 | GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_); |
| 1077 | } |
| 1078 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASLong(HInvoke* invoke) { |
| 1079 | GenCas(invoke->GetLocations(), Primitive::kPrimLong, codegen_); |
| 1080 | } |
| 1081 | void IntrinsicCodeGeneratorARM64::VisitUnsafeCASObject(HInvoke* invoke) { |
| 1082 | GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_); |
| 1083 | } |
| 1084 | |
| 1085 | void IntrinsicLocationsBuilderARM64::VisitStringCharAt(HInvoke* invoke) { |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1086 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1087 | LocationSummary::kCallOnSlowPath, |
| 1088 | kIntrinsified); |
| 1089 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1090 | locations->SetInAt(1, Location::RequiresRegister()); |
Nicolas Geoffray | 82f3449 | 2015-02-04 10:44:23 +0000 | [diff] [blame] | 1091 | // In case we need to go in the slow path, we can't have the output be the same |
| 1092 | // as the input: the current liveness analysis considers the input to be live |
| 1093 | // at the point of the call. |
| 1094 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | void IntrinsicCodeGeneratorARM64::VisitStringCharAt(HInvoke* invoke) { |
| 1098 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1099 | LocationSummary* locations = invoke->GetLocations(); |
| 1100 | |
| 1101 | // Location of reference to data array |
| 1102 | const MemberOffset value_offset = mirror::String::ValueOffset(); |
| 1103 | // Location of count |
| 1104 | const MemberOffset count_offset = mirror::String::CountOffset(); |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1105 | |
| 1106 | Register obj = WRegisterFrom(locations->InAt(0)); // String object pointer. |
| 1107 | Register idx = WRegisterFrom(locations->InAt(1)); // Index of character. |
| 1108 | Register out = WRegisterFrom(locations->Out()); // Result character. |
| 1109 | |
| 1110 | UseScratchRegisterScope temps(masm); |
| 1111 | Register temp = temps.AcquireW(); |
| 1112 | Register array_temp = temps.AcquireW(); // We can trade this for worse scheduling. |
| 1113 | |
| 1114 | // TODO: Maybe we can support range check elimination. Overall, though, I think it's not worth |
| 1115 | // the cost. |
| 1116 | // TODO: For simplicity, the index parameter is requested in a register, so different from Quick |
| 1117 | // we will not optimize the code for constants (which would save a register). |
| 1118 | |
| 1119 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1120 | codegen_->AddSlowPath(slow_path); |
| 1121 | |
| 1122 | __ Ldr(temp, HeapOperand(obj, count_offset)); // temp = str.length. |
| 1123 | codegen_->MaybeRecordImplicitNullCheck(invoke); |
| 1124 | __ Cmp(idx, temp); |
| 1125 | __ B(hs, slow_path->GetEntryLabel()); |
| 1126 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1127 | __ Add(array_temp, obj, Operand(value_offset.Int32Value())); // array_temp := str.value. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1128 | |
| 1129 | // Load the value. |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1130 | __ Ldrh(out, MemOperand(array_temp.X(), idx, UXTW, 1)); // out := array_temp[idx]. |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1131 | |
| 1132 | __ Bind(slow_path->GetExitLabel()); |
| 1133 | } |
| 1134 | |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1135 | void IntrinsicLocationsBuilderARM64::VisitStringCompareTo(HInvoke* invoke) { |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1136 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1137 | LocationSummary::kCall, |
| 1138 | kIntrinsified); |
| 1139 | InvokeRuntimeCallingConvention calling_convention; |
| 1140 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1141 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1142 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1143 | } |
| 1144 | |
| 1145 | void IntrinsicCodeGeneratorARM64::VisitStringCompareTo(HInvoke* invoke) { |
| 1146 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1147 | LocationSummary* locations = invoke->GetLocations(); |
| 1148 | |
Nicolas Geoffray | 512e04d | 2015-03-27 17:21:24 +0000 | [diff] [blame] | 1149 | // Note that the null check must have been done earlier. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1150 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
Nicolas Geoffray | d75948a | 2015-03-27 09:53:16 +0000 | [diff] [blame] | 1151 | |
| 1152 | Register argument = WRegisterFrom(locations->InAt(1)); |
| 1153 | __ Cmp(argument, 0); |
| 1154 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1155 | codegen_->AddSlowPath(slow_path); |
| 1156 | __ B(eq, slow_path->GetEntryLabel()); |
| 1157 | |
| 1158 | __ Ldr( |
| 1159 | lr, MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pStringCompareTo).Int32Value())); |
| 1160 | __ Blr(lr); |
| 1161 | __ Bind(slow_path->GetExitLabel()); |
| 1162 | } |
| 1163 | |
Agi Csaki | ea34b40 | 2015-08-13 17:51:19 -0700 | [diff] [blame] | 1164 | void IntrinsicLocationsBuilderARM64::VisitStringEquals(HInvoke* invoke) { |
| 1165 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1166 | LocationSummary::kNoCall, |
| 1167 | kIntrinsified); |
| 1168 | locations->SetInAt(0, Location::RequiresRegister()); |
| 1169 | locations->SetInAt(1, Location::RequiresRegister()); |
| 1170 | // Temporary registers to store lengths of strings and for calculations. |
| 1171 | locations->AddTemp(Location::RequiresRegister()); |
| 1172 | locations->AddTemp(Location::RequiresRegister()); |
| 1173 | |
| 1174 | locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap); |
| 1175 | } |
| 1176 | |
| 1177 | void IntrinsicCodeGeneratorARM64::VisitStringEquals(HInvoke* invoke) { |
| 1178 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1179 | LocationSummary* locations = invoke->GetLocations(); |
| 1180 | |
| 1181 | Register str = WRegisterFrom(locations->InAt(0)); |
| 1182 | Register arg = WRegisterFrom(locations->InAt(1)); |
| 1183 | Register out = XRegisterFrom(locations->Out()); |
| 1184 | |
| 1185 | UseScratchRegisterScope scratch_scope(masm); |
| 1186 | Register temp = scratch_scope.AcquireW(); |
| 1187 | Register temp1 = WRegisterFrom(locations->GetTemp(0)); |
| 1188 | Register temp2 = WRegisterFrom(locations->GetTemp(1)); |
| 1189 | |
| 1190 | vixl::Label loop; |
| 1191 | vixl::Label end; |
| 1192 | vixl::Label return_true; |
| 1193 | vixl::Label return_false; |
| 1194 | |
| 1195 | // Get offsets of count, value, and class fields within a string object. |
| 1196 | const int32_t count_offset = mirror::String::CountOffset().Int32Value(); |
| 1197 | const int32_t value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1198 | const int32_t class_offset = mirror::Object::ClassOffset().Int32Value(); |
| 1199 | |
| 1200 | // Note that the null check must have been done earlier. |
| 1201 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1202 | |
| 1203 | // Check if input is null, return false if it is. |
| 1204 | __ Cbz(arg, &return_false); |
| 1205 | |
| 1206 | // Reference equality check, return true if same reference. |
| 1207 | __ Cmp(str, arg); |
| 1208 | __ B(&return_true, eq); |
| 1209 | |
| 1210 | // Instanceof check for the argument by comparing class fields. |
| 1211 | // All string objects must have the same type since String cannot be subclassed. |
| 1212 | // Receiver must be a string object, so its class field is equal to all strings' class fields. |
| 1213 | // If the argument is a string object, its class field must be equal to receiver's class field. |
| 1214 | __ Ldr(temp, MemOperand(str.X(), class_offset)); |
| 1215 | __ Ldr(temp1, MemOperand(arg.X(), class_offset)); |
| 1216 | __ Cmp(temp, temp1); |
| 1217 | __ B(&return_false, ne); |
| 1218 | |
| 1219 | // Load lengths of this and argument strings. |
| 1220 | __ Ldr(temp, MemOperand(str.X(), count_offset)); |
| 1221 | __ Ldr(temp1, MemOperand(arg.X(), count_offset)); |
| 1222 | // Check if lengths are equal, return false if they're not. |
| 1223 | __ Cmp(temp, temp1); |
| 1224 | __ B(&return_false, ne); |
| 1225 | // Store offset of string value in preparation for comparison loop |
| 1226 | __ Mov(temp1, value_offset); |
| 1227 | // Return true if both strings are empty. |
| 1228 | __ Cbz(temp, &return_true); |
| 1229 | |
| 1230 | // Assertions that must hold in order to compare strings 4 characters at a time. |
| 1231 | DCHECK_ALIGNED(value_offset, 8); |
| 1232 | static_assert(IsAligned<8>(kObjectAlignment), "String of odd length is not zero padded"); |
| 1233 | |
| 1234 | temp1 = temp1.X(); |
| 1235 | temp2 = temp2.X(); |
| 1236 | |
| 1237 | // Loop to compare strings 4 characters at a time starting at the beginning of the string. |
| 1238 | // Ok to do this because strings are zero-padded to be 8-byte aligned. |
| 1239 | __ Bind(&loop); |
| 1240 | __ Ldr(out, MemOperand(str.X(), temp1)); |
| 1241 | __ Ldr(temp2, MemOperand(arg.X(), temp1)); |
| 1242 | __ Add(temp1, temp1, Operand(sizeof(uint64_t))); |
| 1243 | __ Cmp(out, temp2); |
| 1244 | __ B(&return_false, ne); |
| 1245 | __ Sub(temp, temp, Operand(4), SetFlags); |
| 1246 | __ B(&loop, gt); |
| 1247 | |
| 1248 | // Return true and exit the function. |
| 1249 | // If loop does not result in returning false, we return true. |
| 1250 | __ Bind(&return_true); |
| 1251 | __ Mov(out, 1); |
| 1252 | __ B(&end); |
| 1253 | |
| 1254 | // Return false and exit the function. |
| 1255 | __ Bind(&return_false); |
| 1256 | __ Mov(out, 0); |
| 1257 | __ Bind(&end); |
| 1258 | } |
| 1259 | |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1260 | static void GenerateVisitStringIndexOf(HInvoke* invoke, |
| 1261 | vixl::MacroAssembler* masm, |
| 1262 | CodeGeneratorARM64* codegen, |
| 1263 | ArenaAllocator* allocator, |
| 1264 | bool start_at_zero) { |
| 1265 | LocationSummary* locations = invoke->GetLocations(); |
| 1266 | Register tmp_reg = WRegisterFrom(locations->GetTemp(0)); |
| 1267 | |
| 1268 | // Note that the null check must have been done earlier. |
| 1269 | DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0))); |
| 1270 | |
| 1271 | // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically, |
| 1272 | // or directly dispatch if we have a constant. |
| 1273 | SlowPathCodeARM64* slow_path = nullptr; |
| 1274 | if (invoke->InputAt(1)->IsIntConstant()) { |
| 1275 | if (static_cast<uint32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue()) > 0xFFFFU) { |
| 1276 | // Always needs the slow-path. We could directly dispatch to it, but this case should be |
| 1277 | // rare, so for simplicity just put the full slow-path down and branch unconditionally. |
| 1278 | slow_path = new (allocator) IntrinsicSlowPathARM64(invoke); |
| 1279 | codegen->AddSlowPath(slow_path); |
| 1280 | __ B(slow_path->GetEntryLabel()); |
| 1281 | __ Bind(slow_path->GetExitLabel()); |
| 1282 | return; |
| 1283 | } |
| 1284 | } else { |
| 1285 | Register char_reg = WRegisterFrom(locations->InAt(1)); |
| 1286 | __ Mov(tmp_reg, 0xFFFF); |
| 1287 | __ Cmp(char_reg, Operand(tmp_reg)); |
| 1288 | slow_path = new (allocator) IntrinsicSlowPathARM64(invoke); |
| 1289 | codegen->AddSlowPath(slow_path); |
| 1290 | __ B(hi, slow_path->GetEntryLabel()); |
| 1291 | } |
| 1292 | |
| 1293 | if (start_at_zero) { |
| 1294 | // Start-index = 0. |
| 1295 | __ Mov(tmp_reg, 0); |
| 1296 | } |
| 1297 | |
| 1298 | __ Ldr(lr, MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pIndexOf).Int32Value())); |
| 1299 | __ Blr(lr); |
| 1300 | |
| 1301 | if (slow_path != nullptr) { |
| 1302 | __ Bind(slow_path->GetExitLabel()); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | void IntrinsicLocationsBuilderARM64::VisitStringIndexOf(HInvoke* invoke) { |
| 1307 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1308 | LocationSummary::kCall, |
| 1309 | kIntrinsified); |
| 1310 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1311 | // best to align the inputs accordingly. |
| 1312 | InvokeRuntimeCallingConvention calling_convention; |
| 1313 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1314 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1315 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1316 | |
| 1317 | // Need a temp for slow-path codepoint compare, and need to send start_index=0. |
| 1318 | locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1319 | } |
| 1320 | |
| 1321 | void IntrinsicCodeGeneratorARM64::VisitStringIndexOf(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1322 | GenerateVisitStringIndexOf( |
| 1323 | invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | void IntrinsicLocationsBuilderARM64::VisitStringIndexOfAfter(HInvoke* invoke) { |
| 1327 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1328 | LocationSummary::kCall, |
| 1329 | kIntrinsified); |
| 1330 | // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's |
| 1331 | // best to align the inputs accordingly. |
| 1332 | InvokeRuntimeCallingConvention calling_convention; |
| 1333 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1334 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1335 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1336 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt)); |
| 1337 | |
| 1338 | // Need a temp for slow-path codepoint compare. |
| 1339 | locations->AddTemp(Location::RequiresRegister()); |
| 1340 | } |
| 1341 | |
| 1342 | void IntrinsicCodeGeneratorARM64::VisitStringIndexOfAfter(HInvoke* invoke) { |
Roland Levillain | bf84a3d | 2015-12-04 14:33:02 +0000 | [diff] [blame] | 1343 | GenerateVisitStringIndexOf( |
| 1344 | invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false); |
Andreas Gampe | ba6fdbc | 2015-05-07 22:31:55 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1347 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1348 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1349 | LocationSummary::kCall, |
| 1350 | kIntrinsified); |
| 1351 | InvokeRuntimeCallingConvention calling_convention; |
| 1352 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1353 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1354 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1355 | locations->SetInAt(3, LocationFrom(calling_convention.GetRegisterAt(3))); |
| 1356 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1357 | } |
| 1358 | |
| 1359 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromBytes(HInvoke* invoke) { |
| 1360 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1361 | LocationSummary* locations = invoke->GetLocations(); |
| 1362 | |
| 1363 | Register byte_array = WRegisterFrom(locations->InAt(0)); |
| 1364 | __ Cmp(byte_array, 0); |
| 1365 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1366 | codegen_->AddSlowPath(slow_path); |
| 1367 | __ B(eq, slow_path->GetEntryLabel()); |
| 1368 | |
| 1369 | __ Ldr(lr, |
| 1370 | MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocStringFromBytes).Int32Value())); |
| 1371 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1372 | __ Blr(lr); |
| 1373 | __ Bind(slow_path->GetExitLabel()); |
| 1374 | } |
| 1375 | |
| 1376 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1377 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1378 | LocationSummary::kCall, |
| 1379 | kIntrinsified); |
| 1380 | InvokeRuntimeCallingConvention calling_convention; |
| 1381 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1382 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1383 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1384 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1385 | } |
| 1386 | |
| 1387 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromChars(HInvoke* invoke) { |
| 1388 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1389 | |
| 1390 | __ Ldr(lr, |
| 1391 | MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocStringFromChars).Int32Value())); |
| 1392 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1393 | __ Blr(lr); |
| 1394 | } |
| 1395 | |
| 1396 | void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1397 | // The inputs plus one temp. |
| 1398 | LocationSummary* locations = new (arena_) LocationSummary(invoke, |
| 1399 | LocationSummary::kCall, |
| 1400 | kIntrinsified); |
| 1401 | InvokeRuntimeCallingConvention calling_convention; |
| 1402 | locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0))); |
| 1403 | locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1))); |
| 1404 | locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2))); |
| 1405 | locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot)); |
| 1406 | } |
| 1407 | |
| 1408 | void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromString(HInvoke* invoke) { |
| 1409 | vixl::MacroAssembler* masm = GetVIXLAssembler(); |
| 1410 | LocationSummary* locations = invoke->GetLocations(); |
| 1411 | |
| 1412 | Register string_to_copy = WRegisterFrom(locations->InAt(0)); |
| 1413 | __ Cmp(string_to_copy, 0); |
| 1414 | SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke); |
| 1415 | codegen_->AddSlowPath(slow_path); |
| 1416 | __ B(eq, slow_path->GetEntryLabel()); |
| 1417 | |
| 1418 | __ Ldr(lr, |
| 1419 | MemOperand(tr, QUICK_ENTRYPOINT_OFFSET(kArm64WordSize, pAllocStringFromString).Int32Value())); |
| 1420 | codegen_->RecordPcInfo(invoke, invoke->GetDexPc()); |
| 1421 | __ Blr(lr); |
| 1422 | __ Bind(slow_path->GetExitLabel()); |
| 1423 | } |
| 1424 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1425 | // Unimplemented intrinsics. |
| 1426 | |
| 1427 | #define UNIMPLEMENTED_INTRINSIC(Name) \ |
| 1428 | void IntrinsicLocationsBuilderARM64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1429 | } \ |
| 1430 | void IntrinsicCodeGeneratorARM64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \ |
| 1431 | } |
| 1432 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1433 | UNIMPLEMENTED_INTRINSIC(IntegerRotateLeft) |
| 1434 | UNIMPLEMENTED_INTRINSIC(IntegerRotateRight) |
| 1435 | UNIMPLEMENTED_INTRINSIC(LongRotateLeft) |
| 1436 | UNIMPLEMENTED_INTRINSIC(LongRotateRight) |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1437 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar) |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1438 | UNIMPLEMENTED_INTRINSIC(SystemArrayCopy) |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1439 | UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent) |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1440 | UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck) |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1441 | |
Mark Mendell | a4f1220 | 2015-08-06 15:23:34 -0400 | [diff] [blame] | 1442 | UNIMPLEMENTED_INTRINSIC(MathCos) |
| 1443 | UNIMPLEMENTED_INTRINSIC(MathSin) |
| 1444 | UNIMPLEMENTED_INTRINSIC(MathAcos) |
| 1445 | UNIMPLEMENTED_INTRINSIC(MathAsin) |
| 1446 | UNIMPLEMENTED_INTRINSIC(MathAtan) |
| 1447 | UNIMPLEMENTED_INTRINSIC(MathAtan2) |
| 1448 | UNIMPLEMENTED_INTRINSIC(MathCbrt) |
| 1449 | UNIMPLEMENTED_INTRINSIC(MathCosh) |
| 1450 | UNIMPLEMENTED_INTRINSIC(MathExp) |
| 1451 | UNIMPLEMENTED_INTRINSIC(MathExpm1) |
| 1452 | UNIMPLEMENTED_INTRINSIC(MathHypot) |
| 1453 | UNIMPLEMENTED_INTRINSIC(MathLog) |
| 1454 | UNIMPLEMENTED_INTRINSIC(MathLog10) |
| 1455 | UNIMPLEMENTED_INTRINSIC(MathNextAfter) |
| 1456 | UNIMPLEMENTED_INTRINSIC(MathSinh) |
| 1457 | UNIMPLEMENTED_INTRINSIC(MathTan) |
| 1458 | UNIMPLEMENTED_INTRINSIC(MathTanh) |
| 1459 | |
Roland Levillain | 4d02711 | 2015-07-01 15:41:14 +0100 | [diff] [blame] | 1460 | #undef UNIMPLEMENTED_INTRINSIC |
| 1461 | |
| 1462 | #undef __ |
| 1463 | |
Andreas Gampe | 878d58c | 2015-01-15 23:24:00 -0800 | [diff] [blame] | 1464 | } // namespace arm64 |
| 1465 | } // namespace art |