blob: 934ba1b9fb604058db29fd63070a5bf395699818 [file] [log] [blame]
Andreas Gampe878d58c2015-01-15 23:24:00 -08001/*
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 Constantinescu579885a2015-02-22 20:51:33 +000019#include "arch/arm64/instruction_set_features_arm64.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080021#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"
Vladimir Markoe39f14f2017-02-10 15:44:25 +000026#include "mirror/string-inl.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080027#include "thread.h"
28#include "utils/arm64/assembler_arm64.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080029
Scott Wakeling97c72b72016-06-24 16:19:36 +010030using namespace vixl::aarch64; // NOLINT(build/namespaces)
Andreas Gampe878d58c2015-01-15 23:24:00 -080031
Artem Serovaf4e42a2016-08-08 15:11:24 +010032// TODO(VIXL): Make VIXL compile with -Wshadow.
Scott Wakeling97c72b72016-06-24 16:19:36 +010033#pragma GCC diagnostic push
34#pragma GCC diagnostic ignored "-Wshadow"
Artem Serovaf4e42a2016-08-08 15:11:24 +010035#include "aarch64/disasm-aarch64.h"
36#include "aarch64/macro-assembler-aarch64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010037#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080038
39namespace art {
40
41namespace arm64 {
42
43using helpers::DRegisterFrom;
44using helpers::FPRegisterFrom;
45using helpers::HeapOperand;
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +000046using helpers::LocationFrom;
Scott Wakeling9ee23f42015-07-23 10:44:35 +010047using helpers::OperandFrom;
Andreas Gampe878d58c2015-01-15 23:24:00 -080048using helpers::RegisterFrom;
49using helpers::SRegisterFrom;
50using helpers::WRegisterFrom;
51using helpers::XRegisterFrom;
xueliang.zhong49924c92016-03-03 10:52:51 +000052using helpers::InputRegisterAt;
Scott Wakeling1f36f412016-04-21 11:13:45 +010053using helpers::OutputRegister;
Andreas Gampe878d58c2015-01-15 23:24:00 -080054
Andreas Gampe878d58c2015-01-15 23:24:00 -080055namespace {
56
57ALWAYS_INLINE inline MemOperand AbsoluteHeapOperandFrom(Location location, size_t offset = 0) {
58 return MemOperand(XRegisterFrom(location), offset);
59}
60
61} // namespace
62
Scott Wakeling97c72b72016-06-24 16:19:36 +010063MacroAssembler* IntrinsicCodeGeneratorARM64::GetVIXLAssembler() {
Alexandre Rames087930f2016-08-02 13:45:28 +010064 return codegen_->GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -080065}
66
67ArenaAllocator* IntrinsicCodeGeneratorARM64::GetAllocator() {
68 return codegen_->GetGraph()->GetArena();
69}
70
Alexandre Rames087930f2016-08-02 13:45:28 +010071#define __ codegen->GetVIXLAssembler()->
Andreas Gampe878d58c2015-01-15 23:24:00 -080072
73static 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 Hao848f70a2014-01-15 13:49:50 -080083 if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080084 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 Levillainec525fc2015-04-28 15:50:20 +010094static void MoveArguments(HInvoke* invoke, CodeGeneratorARM64* codegen) {
Roland Levillain2d27c8e2015-04-28 15:48:45 +010095 InvokeDexCallingConventionVisitorARM64 calling_convention_visitor;
Roland Levillainec525fc2015-04-28 15:50:20 +010096 IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor);
Andreas Gampe878d58c2015-01-15 23:24:00 -080097}
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!
105class IntrinsicSlowPathARM64 : public SlowPathCodeARM64 {
106 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000107 explicit IntrinsicSlowPathARM64(HInvoke* invoke)
108 : SlowPathCodeARM64(invoke), invoke_(invoke) { }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800109
110 void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE {
111 CodeGeneratorARM64* codegen = down_cast<CodeGeneratorARM64*>(codegen_in);
112 __ Bind(GetEntryLabel());
113
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000114 SaveLiveRegisters(codegen, invoke_->GetLocations());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800115
Roland Levillainec525fc2015-04-28 15:50:20 +0100116 MoveArguments(invoke_, codegen);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800117
Artem Serov914d7a82017-02-07 14:33:49 +0000118 {
119 // Ensure that between the BLR (emitted by Generate*Call) and RecordPcInfo there
120 // are no pools emitted.
121 vixl::EmissionCheckScope guard(codegen->GetVIXLAssembler(), kInvokeCodeMarginSizeInBytes);
122 if (invoke_->IsInvokeStaticOrDirect()) {
123 codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(),
124 LocationFrom(kArtMethodRegister));
125 } else {
126 codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), LocationFrom(kArtMethodRegister));
127 }
128 codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800129 }
130
131 // Copy the result back to the expected output.
132 Location out = invoke_->GetLocations()->Out();
133 if (out.IsValid()) {
134 DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory.
135 DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
136 MoveFromReturnRegister(out, invoke_->GetType(), codegen);
137 }
138
Nicolas Geoffraya8ac9132015-03-13 16:36:36 +0000139 RestoreLiveRegisters(codegen, invoke_->GetLocations());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800140 __ B(GetExitLabel());
141 }
142
Alexandre Rames9931f312015-06-19 14:47:01 +0100143 const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathARM64"; }
144
Andreas Gampe878d58c2015-01-15 23:24:00 -0800145 private:
146 // The instruction where this slow path is happening.
147 HInvoke* const invoke_;
148
149 DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARM64);
150};
151
Roland Levillain0b671c02016-08-19 12:02:34 +0100152// Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers.
153class ReadBarrierSystemArrayCopySlowPathARM64 : public SlowPathCodeARM64 {
154 public:
155 ReadBarrierSystemArrayCopySlowPathARM64(HInstruction* instruction, Location tmp)
156 : SlowPathCodeARM64(instruction), tmp_(tmp) {
157 DCHECK(kEmitCompilerReadBarrier);
158 DCHECK(kUseBakerReadBarrier);
159 }
160
161 void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE {
162 CodeGeneratorARM64* codegen = down_cast<CodeGeneratorARM64*>(codegen_in);
163 LocationSummary* locations = instruction_->GetLocations();
164 DCHECK(locations->CanCall());
165 DCHECK(instruction_->IsInvokeStaticOrDirect())
166 << "Unexpected instruction in read barrier arraycopy slow path: "
167 << instruction_->DebugName();
168 DCHECK(instruction_->GetLocations()->Intrinsified());
169 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy);
170
171 const int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
172
173 Register src_curr_addr = XRegisterFrom(locations->GetTemp(0));
174 Register dst_curr_addr = XRegisterFrom(locations->GetTemp(1));
175 Register src_stop_addr = XRegisterFrom(locations->GetTemp(2));
176 Register tmp_reg = WRegisterFrom(tmp_);
177
178 __ Bind(GetEntryLabel());
179 vixl::aarch64::Label slow_copy_loop;
180 __ Bind(&slow_copy_loop);
181 __ Ldr(tmp_reg, MemOperand(src_curr_addr, element_size, PostIndex));
182 codegen->GetAssembler()->MaybeUnpoisonHeapReference(tmp_reg);
183 // TODO: Inline the mark bit check before calling the runtime?
184 // tmp_reg = ReadBarrier::Mark(tmp_reg);
185 // No need to save live registers; it's taken care of by the
186 // entrypoint. Also, there is no need to update the stack mask,
187 // as this runtime call will not trigger a garbage collection.
188 // (See ReadBarrierMarkSlowPathARM64::EmitNativeCode for more
189 // explanations.)
190 DCHECK_NE(tmp_.reg(), LR);
191 DCHECK_NE(tmp_.reg(), WSP);
192 DCHECK_NE(tmp_.reg(), WZR);
193 // IP0 is used internally by the ReadBarrierMarkRegX entry point
194 // as a temporary (and not preserved). It thus cannot be used by
195 // any live register in this slow path.
196 DCHECK_NE(LocationFrom(src_curr_addr).reg(), IP0);
197 DCHECK_NE(LocationFrom(dst_curr_addr).reg(), IP0);
198 DCHECK_NE(LocationFrom(src_stop_addr).reg(), IP0);
199 DCHECK_NE(tmp_.reg(), IP0);
200 DCHECK(0 <= tmp_.reg() && tmp_.reg() < kNumberOfWRegisters) << tmp_.reg();
201 int32_t entry_point_offset =
202 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArm64PointerSize>(tmp_.reg());
203 // This runtime call does not require a stack map.
204 codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
205 codegen->GetAssembler()->MaybePoisonHeapReference(tmp_reg);
206 __ Str(tmp_reg, MemOperand(dst_curr_addr, element_size, PostIndex));
207 __ Cmp(src_curr_addr, src_stop_addr);
208 __ B(&slow_copy_loop, ne);
209 __ B(GetExitLabel());
210 }
211
212 const char* GetDescription() const OVERRIDE { return "ReadBarrierSystemArrayCopySlowPathARM64"; }
213
214 private:
215 Location tmp_;
216
217 DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathARM64);
218};
Andreas Gampe878d58c2015-01-15 23:24:00 -0800219#undef __
220
221bool IntrinsicLocationsBuilderARM64::TryDispatch(HInvoke* invoke) {
222 Dispatch(invoke);
223 LocationSummary* res = invoke->GetLocations();
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000224 if (res == nullptr) {
225 return false;
226 }
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000227 return res->Intrinsified();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800228}
229
230#define __ masm->
231
232static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
233 LocationSummary* locations = new (arena) LocationSummary(invoke,
234 LocationSummary::kNoCall,
235 kIntrinsified);
236 locations->SetInAt(0, Location::RequiresFpuRegister());
237 locations->SetOut(Location::RequiresRegister());
238}
239
240static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
241 LocationSummary* locations = new (arena) LocationSummary(invoke,
242 LocationSummary::kNoCall,
243 kIntrinsified);
244 locations->SetInAt(0, Location::RequiresRegister());
245 locations->SetOut(Location::RequiresFpuRegister());
246}
247
Scott Wakeling97c72b72016-06-24 16:19:36 +0100248static void MoveFPToInt(LocationSummary* locations, bool is64bit, MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800249 Location input = locations->InAt(0);
250 Location output = locations->Out();
251 __ Fmov(is64bit ? XRegisterFrom(output) : WRegisterFrom(output),
252 is64bit ? DRegisterFrom(input) : SRegisterFrom(input));
253}
254
Scott Wakeling97c72b72016-06-24 16:19:36 +0100255static void MoveIntToFP(LocationSummary* locations, bool is64bit, MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800256 Location input = locations->InAt(0);
257 Location output = locations->Out();
258 __ Fmov(is64bit ? DRegisterFrom(output) : SRegisterFrom(output),
259 is64bit ? XRegisterFrom(input) : WRegisterFrom(input));
260}
261
262void IntrinsicLocationsBuilderARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
263 CreateFPToIntLocations(arena_, invoke);
264}
265void IntrinsicLocationsBuilderARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
266 CreateIntToFPLocations(arena_, invoke);
267}
268
269void IntrinsicCodeGeneratorARM64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000270 MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800271}
272void IntrinsicCodeGeneratorARM64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000273 MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800274}
275
276void IntrinsicLocationsBuilderARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
277 CreateFPToIntLocations(arena_, invoke);
278}
279void IntrinsicLocationsBuilderARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
280 CreateIntToFPLocations(arena_, invoke);
281}
282
283void IntrinsicCodeGeneratorARM64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000284 MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800285}
286void IntrinsicCodeGeneratorARM64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000287 MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800288}
289
290static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
291 LocationSummary* locations = new (arena) LocationSummary(invoke,
292 LocationSummary::kNoCall,
293 kIntrinsified);
294 locations->SetInAt(0, Location::RequiresRegister());
295 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
296}
297
298static void GenReverseBytes(LocationSummary* locations,
299 Primitive::Type type,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100300 MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800301 Location in = locations->InAt(0);
302 Location out = locations->Out();
303
304 switch (type) {
305 case Primitive::kPrimShort:
306 __ Rev16(WRegisterFrom(out), WRegisterFrom(in));
307 __ Sxth(WRegisterFrom(out), WRegisterFrom(out));
308 break;
309 case Primitive::kPrimInt:
310 case Primitive::kPrimLong:
311 __ Rev(RegisterFrom(out, type), RegisterFrom(in, type));
312 break;
313 default:
314 LOG(FATAL) << "Unexpected size for reverse-bytes: " << type;
315 UNREACHABLE();
316 }
317}
318
319void IntrinsicLocationsBuilderARM64::VisitIntegerReverseBytes(HInvoke* invoke) {
320 CreateIntToIntLocations(arena_, invoke);
321}
322
323void IntrinsicCodeGeneratorARM64::VisitIntegerReverseBytes(HInvoke* invoke) {
324 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler());
325}
326
327void IntrinsicLocationsBuilderARM64::VisitLongReverseBytes(HInvoke* invoke) {
328 CreateIntToIntLocations(arena_, invoke);
329}
330
331void IntrinsicCodeGeneratorARM64::VisitLongReverseBytes(HInvoke* invoke) {
332 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler());
333}
334
335void IntrinsicLocationsBuilderARM64::VisitShortReverseBytes(HInvoke* invoke) {
336 CreateIntToIntLocations(arena_, invoke);
337}
338
339void IntrinsicCodeGeneratorARM64::VisitShortReverseBytes(HInvoke* invoke) {
340 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetVIXLAssembler());
341}
342
Aart Bik7b565022016-01-28 14:36:22 -0800343static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
344 LocationSummary* locations = new (arena) LocationSummary(invoke,
345 LocationSummary::kNoCall,
346 kIntrinsified);
347 locations->SetInAt(0, Location::RequiresRegister());
348 locations->SetInAt(1, Location::RequiresRegister());
349 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
350}
351
Scott Wakeling611d3392015-07-10 11:42:06 +0100352static void GenNumberOfLeadingZeros(LocationSummary* locations,
353 Primitive::Type type,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100354 MacroAssembler* masm) {
Scott Wakeling611d3392015-07-10 11:42:06 +0100355 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
356
357 Location in = locations->InAt(0);
358 Location out = locations->Out();
359
360 __ Clz(RegisterFrom(out, type), RegisterFrom(in, type));
361}
362
363void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
364 CreateIntToIntLocations(arena_, invoke);
365}
366
367void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
368 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler());
369}
370
371void IntrinsicLocationsBuilderARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
372 CreateIntToIntLocations(arena_, invoke);
373}
374
375void IntrinsicCodeGeneratorARM64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
376 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler());
377}
378
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100379static void GenNumberOfTrailingZeros(LocationSummary* locations,
380 Primitive::Type type,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100381 MacroAssembler* masm) {
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100382 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
383
384 Location in = locations->InAt(0);
385 Location out = locations->Out();
386
387 __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type));
388 __ Clz(RegisterFrom(out, type), RegisterFrom(out, type));
389}
390
391void IntrinsicLocationsBuilderARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
392 CreateIntToIntLocations(arena_, invoke);
393}
394
395void IntrinsicCodeGeneratorARM64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
396 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler());
397}
398
399void IntrinsicLocationsBuilderARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
400 CreateIntToIntLocations(arena_, invoke);
401}
402
403void IntrinsicCodeGeneratorARM64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
404 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler());
405}
406
Andreas Gampe878d58c2015-01-15 23:24:00 -0800407static void GenReverse(LocationSummary* locations,
408 Primitive::Type type,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100409 MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800410 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
411
412 Location in = locations->InAt(0);
413 Location out = locations->Out();
414
415 __ Rbit(RegisterFrom(out, type), RegisterFrom(in, type));
416}
417
418void IntrinsicLocationsBuilderARM64::VisitIntegerReverse(HInvoke* invoke) {
419 CreateIntToIntLocations(arena_, invoke);
420}
421
422void IntrinsicCodeGeneratorARM64::VisitIntegerReverse(HInvoke* invoke) {
423 GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetVIXLAssembler());
424}
425
426void IntrinsicLocationsBuilderARM64::VisitLongReverse(HInvoke* invoke) {
427 CreateIntToIntLocations(arena_, invoke);
428}
429
430void IntrinsicCodeGeneratorARM64::VisitLongReverse(HInvoke* invoke) {
431 GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetVIXLAssembler());
432}
433
Scott Wakeling97c72b72016-06-24 16:19:36 +0100434static void GenBitCount(HInvoke* instr, Primitive::Type type, MacroAssembler* masm) {
Roland Levillainfa3912e2016-04-01 18:21:55 +0100435 DCHECK(Primitive::IsIntOrLongType(type)) << type;
436 DCHECK_EQ(instr->GetType(), Primitive::kPrimInt);
437 DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type);
xueliang.zhong49924c92016-03-03 10:52:51 +0000438
xueliang.zhong49924c92016-03-03 10:52:51 +0000439 UseScratchRegisterScope temps(masm);
440
Nicolas Geoffray457413a2016-03-04 11:10:17 +0000441 Register src = InputRegisterAt(instr, 0);
Roland Levillainfa3912e2016-04-01 18:21:55 +0100442 Register dst = RegisterFrom(instr->GetLocations()->Out(), type);
443 FPRegister fpr = (type == Primitive::kPrimLong) ? temps.AcquireD() : temps.AcquireS();
xueliang.zhong49924c92016-03-03 10:52:51 +0000444
445 __ Fmov(fpr, src);
Nicolas Geoffray457413a2016-03-04 11:10:17 +0000446 __ Cnt(fpr.V8B(), fpr.V8B());
447 __ Addv(fpr.B(), fpr.V8B());
xueliang.zhong49924c92016-03-03 10:52:51 +0000448 __ Fmov(dst, fpr);
449}
450
451void IntrinsicLocationsBuilderARM64::VisitLongBitCount(HInvoke* invoke) {
452 CreateIntToIntLocations(arena_, invoke);
453}
454
455void IntrinsicCodeGeneratorARM64::VisitLongBitCount(HInvoke* invoke) {
Roland Levillainfa3912e2016-04-01 18:21:55 +0100456 GenBitCount(invoke, Primitive::kPrimLong, GetVIXLAssembler());
xueliang.zhong49924c92016-03-03 10:52:51 +0000457}
458
459void IntrinsicLocationsBuilderARM64::VisitIntegerBitCount(HInvoke* invoke) {
460 CreateIntToIntLocations(arena_, invoke);
461}
462
463void IntrinsicCodeGeneratorARM64::VisitIntegerBitCount(HInvoke* invoke) {
Roland Levillainfa3912e2016-04-01 18:21:55 +0100464 GenBitCount(invoke, Primitive::kPrimInt, GetVIXLAssembler());
xueliang.zhong49924c92016-03-03 10:52:51 +0000465}
466
Andreas Gampe878d58c2015-01-15 23:24:00 -0800467static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800468 LocationSummary* locations = new (arena) LocationSummary(invoke,
469 LocationSummary::kNoCall,
470 kIntrinsified);
471 locations->SetInAt(0, Location::RequiresFpuRegister());
472 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
473}
474
Scott Wakeling97c72b72016-06-24 16:19:36 +0100475static void MathAbsFP(LocationSummary* locations, bool is64bit, MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800476 Location in = locations->InAt(0);
477 Location out = locations->Out();
478
479 FPRegister in_reg = is64bit ? DRegisterFrom(in) : SRegisterFrom(in);
480 FPRegister out_reg = is64bit ? DRegisterFrom(out) : SRegisterFrom(out);
481
482 __ Fabs(out_reg, in_reg);
483}
484
485void IntrinsicLocationsBuilderARM64::VisitMathAbsDouble(HInvoke* invoke) {
486 CreateFPToFPLocations(arena_, invoke);
487}
488
489void IntrinsicCodeGeneratorARM64::VisitMathAbsDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000490 MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800491}
492
493void IntrinsicLocationsBuilderARM64::VisitMathAbsFloat(HInvoke* invoke) {
494 CreateFPToFPLocations(arena_, invoke);
495}
496
497void IntrinsicCodeGeneratorARM64::VisitMathAbsFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000498 MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800499}
500
501static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) {
502 LocationSummary* locations = new (arena) LocationSummary(invoke,
503 LocationSummary::kNoCall,
504 kIntrinsified);
505 locations->SetInAt(0, Location::RequiresRegister());
506 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
507}
508
509static void GenAbsInteger(LocationSummary* locations,
510 bool is64bit,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100511 MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800512 Location in = locations->InAt(0);
513 Location output = locations->Out();
514
515 Register in_reg = is64bit ? XRegisterFrom(in) : WRegisterFrom(in);
516 Register out_reg = is64bit ? XRegisterFrom(output) : WRegisterFrom(output);
517
518 __ Cmp(in_reg, Operand(0));
519 __ Cneg(out_reg, in_reg, lt);
520}
521
522void IntrinsicLocationsBuilderARM64::VisitMathAbsInt(HInvoke* invoke) {
523 CreateIntToInt(arena_, invoke);
524}
525
526void IntrinsicCodeGeneratorARM64::VisitMathAbsInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000527 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800528}
529
530void IntrinsicLocationsBuilderARM64::VisitMathAbsLong(HInvoke* invoke) {
531 CreateIntToInt(arena_, invoke);
532}
533
534void IntrinsicCodeGeneratorARM64::VisitMathAbsLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000535 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800536}
537
538static void GenMinMaxFP(LocationSummary* locations,
539 bool is_min,
540 bool is_double,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100541 MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800542 Location op1 = locations->InAt(0);
543 Location op2 = locations->InAt(1);
544 Location out = locations->Out();
545
546 FPRegister op1_reg = is_double ? DRegisterFrom(op1) : SRegisterFrom(op1);
547 FPRegister op2_reg = is_double ? DRegisterFrom(op2) : SRegisterFrom(op2);
548 FPRegister out_reg = is_double ? DRegisterFrom(out) : SRegisterFrom(out);
549 if (is_min) {
550 __ Fmin(out_reg, op1_reg, op2_reg);
551 } else {
552 __ Fmax(out_reg, op1_reg, op2_reg);
553 }
554}
555
556static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
557 LocationSummary* locations = new (arena) LocationSummary(invoke,
558 LocationSummary::kNoCall,
559 kIntrinsified);
560 locations->SetInAt(0, Location::RequiresFpuRegister());
561 locations->SetInAt(1, Location::RequiresFpuRegister());
562 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
563}
564
565void IntrinsicLocationsBuilderARM64::VisitMathMinDoubleDouble(HInvoke* invoke) {
566 CreateFPFPToFPLocations(arena_, invoke);
567}
568
569void IntrinsicCodeGeneratorARM64::VisitMathMinDoubleDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000570 GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800571}
572
573void IntrinsicLocationsBuilderARM64::VisitMathMinFloatFloat(HInvoke* invoke) {
574 CreateFPFPToFPLocations(arena_, invoke);
575}
576
577void IntrinsicCodeGeneratorARM64::VisitMathMinFloatFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000578 GenMinMaxFP(invoke->GetLocations(), /* is_min */ true, /* is_double */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800579}
580
581void IntrinsicLocationsBuilderARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) {
582 CreateFPFPToFPLocations(arena_, invoke);
583}
584
585void IntrinsicCodeGeneratorARM64::VisitMathMaxDoubleDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000586 GenMinMaxFP(invoke->GetLocations(), /* is_min */ false, /* is_double */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800587}
588
589void IntrinsicLocationsBuilderARM64::VisitMathMaxFloatFloat(HInvoke* invoke) {
590 CreateFPFPToFPLocations(arena_, invoke);
591}
592
593void IntrinsicCodeGeneratorARM64::VisitMathMaxFloatFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000594 GenMinMaxFP(
595 invoke->GetLocations(), /* is_min */ false, /* is_double */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800596}
597
598static void GenMinMax(LocationSummary* locations,
599 bool is_min,
600 bool is_long,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100601 MacroAssembler* masm) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800602 Location op1 = locations->InAt(0);
603 Location op2 = locations->InAt(1);
604 Location out = locations->Out();
605
606 Register op1_reg = is_long ? XRegisterFrom(op1) : WRegisterFrom(op1);
607 Register op2_reg = is_long ? XRegisterFrom(op2) : WRegisterFrom(op2);
608 Register out_reg = is_long ? XRegisterFrom(out) : WRegisterFrom(out);
609
610 __ Cmp(op1_reg, op2_reg);
611 __ Csel(out_reg, op1_reg, op2_reg, is_min ? lt : gt);
612}
613
Andreas Gampe878d58c2015-01-15 23:24:00 -0800614void IntrinsicLocationsBuilderARM64::VisitMathMinIntInt(HInvoke* invoke) {
615 CreateIntIntToIntLocations(arena_, invoke);
616}
617
618void IntrinsicCodeGeneratorARM64::VisitMathMinIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000619 GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800620}
621
622void IntrinsicLocationsBuilderARM64::VisitMathMinLongLong(HInvoke* invoke) {
623 CreateIntIntToIntLocations(arena_, invoke);
624}
625
626void IntrinsicCodeGeneratorARM64::VisitMathMinLongLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000627 GenMinMax(invoke->GetLocations(), /* is_min */ true, /* is_long */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800628}
629
630void IntrinsicLocationsBuilderARM64::VisitMathMaxIntInt(HInvoke* invoke) {
631 CreateIntIntToIntLocations(arena_, invoke);
632}
633
634void IntrinsicCodeGeneratorARM64::VisitMathMaxIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000635 GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800636}
637
638void IntrinsicLocationsBuilderARM64::VisitMathMaxLongLong(HInvoke* invoke) {
639 CreateIntIntToIntLocations(arena_, invoke);
640}
641
642void IntrinsicCodeGeneratorARM64::VisitMathMaxLongLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000643 GenMinMax(invoke->GetLocations(), /* is_min */ false, /* is_long */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800644}
645
646void IntrinsicLocationsBuilderARM64::VisitMathSqrt(HInvoke* invoke) {
647 CreateFPToFPLocations(arena_, invoke);
648}
649
650void IntrinsicCodeGeneratorARM64::VisitMathSqrt(HInvoke* invoke) {
651 LocationSummary* locations = invoke->GetLocations();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100652 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800653 __ Fsqrt(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0)));
654}
655
656void IntrinsicLocationsBuilderARM64::VisitMathCeil(HInvoke* invoke) {
657 CreateFPToFPLocations(arena_, invoke);
658}
659
660void IntrinsicCodeGeneratorARM64::VisitMathCeil(HInvoke* invoke) {
661 LocationSummary* locations = invoke->GetLocations();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100662 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800663 __ Frintp(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0)));
664}
665
666void IntrinsicLocationsBuilderARM64::VisitMathFloor(HInvoke* invoke) {
667 CreateFPToFPLocations(arena_, invoke);
668}
669
670void IntrinsicCodeGeneratorARM64::VisitMathFloor(HInvoke* invoke) {
671 LocationSummary* locations = invoke->GetLocations();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100672 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800673 __ Frintm(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0)));
674}
675
676void IntrinsicLocationsBuilderARM64::VisitMathRint(HInvoke* invoke) {
677 CreateFPToFPLocations(arena_, invoke);
678}
679
680void IntrinsicCodeGeneratorARM64::VisitMathRint(HInvoke* invoke) {
681 LocationSummary* locations = invoke->GetLocations();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100682 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800683 __ Frintn(DRegisterFrom(locations->Out()), DRegisterFrom(locations->InAt(0)));
684}
685
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100686static void CreateFPToIntPlusFPTempLocations(ArenaAllocator* arena, HInvoke* invoke) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800687 LocationSummary* locations = new (arena) LocationSummary(invoke,
688 LocationSummary::kNoCall,
689 kIntrinsified);
690 locations->SetInAt(0, Location::RequiresFpuRegister());
691 locations->SetOut(Location::RequiresRegister());
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100692 locations->AddTemp(Location::RequiresFpuRegister());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800693}
694
Scott Wakeling97c72b72016-06-24 16:19:36 +0100695static void GenMathRound(HInvoke* invoke, bool is_double, vixl::aarch64::MacroAssembler* masm) {
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100696 // Java 8 API definition for Math.round():
697 // Return the closest long or int to the argument, with ties rounding to positive infinity.
698 //
699 // There is no single instruction in ARMv8 that can support the above definition.
700 // We choose to use FCVTAS here, because it has closest semantic.
701 // FCVTAS performs rounding to nearest integer, ties away from zero.
702 // For most inputs (positive values, zero or NaN), this instruction is enough.
703 // We only need a few handling code after FCVTAS if the input is negative half value.
704 //
705 // The reason why we didn't choose FCVTPS instruction here is that
706 // although it performs rounding toward positive infinity, it doesn't perform rounding to nearest.
707 // For example, FCVTPS(-1.9) = -1 and FCVTPS(1.1) = 2.
708 // If we were using this instruction, for most inputs, more handling code would be needed.
709 LocationSummary* l = invoke->GetLocations();
710 FPRegister in_reg = is_double ? DRegisterFrom(l->InAt(0)) : SRegisterFrom(l->InAt(0));
711 FPRegister tmp_fp = is_double ? DRegisterFrom(l->GetTemp(0)) : SRegisterFrom(l->GetTemp(0));
712 Register out_reg = is_double ? XRegisterFrom(l->Out()) : WRegisterFrom(l->Out());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100713 vixl::aarch64::Label done;
Andreas Gampe878d58c2015-01-15 23:24:00 -0800714
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100715 // Round to nearest integer, ties away from zero.
716 __ Fcvtas(out_reg, in_reg);
717
718 // For positive values, zero or NaN inputs, rounding is done.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100719 __ Tbz(out_reg, out_reg.GetSizeInBits() - 1, &done);
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100720
721 // Handle input < 0 cases.
722 // If input is negative but not a tie, previous result (round to nearest) is valid.
723 // If input is a negative tie, out_reg += 1.
724 __ Frinta(tmp_fp, in_reg);
725 __ Fsub(tmp_fp, in_reg, tmp_fp);
726 __ Fcmp(tmp_fp, 0.5);
727 __ Cinc(out_reg, out_reg, eq);
728
729 __ Bind(&done);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800730}
731
732void IntrinsicLocationsBuilderARM64::VisitMathRoundDouble(HInvoke* invoke) {
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100733 CreateFPToIntPlusFPTempLocations(arena_, invoke);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800734}
735
736void IntrinsicCodeGeneratorARM64::VisitMathRoundDouble(HInvoke* invoke) {
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100737 GenMathRound(invoke, /* is_double */ true, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800738}
739
740void IntrinsicLocationsBuilderARM64::VisitMathRoundFloat(HInvoke* invoke) {
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100741 CreateFPToIntPlusFPTempLocations(arena_, invoke);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800742}
743
744void IntrinsicCodeGeneratorARM64::VisitMathRoundFloat(HInvoke* invoke) {
xueliang.zhongd1e153c2016-05-27 18:56:13 +0100745 GenMathRound(invoke, /* is_double */ false, GetVIXLAssembler());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800746}
747
748void IntrinsicLocationsBuilderARM64::VisitMemoryPeekByte(HInvoke* invoke) {
749 CreateIntToIntLocations(arena_, invoke);
750}
751
752void IntrinsicCodeGeneratorARM64::VisitMemoryPeekByte(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100753 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800754 __ Ldrsb(WRegisterFrom(invoke->GetLocations()->Out()),
755 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
756}
757
758void IntrinsicLocationsBuilderARM64::VisitMemoryPeekIntNative(HInvoke* invoke) {
759 CreateIntToIntLocations(arena_, invoke);
760}
761
762void IntrinsicCodeGeneratorARM64::VisitMemoryPeekIntNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100763 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800764 __ Ldr(WRegisterFrom(invoke->GetLocations()->Out()),
765 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
766}
767
768void IntrinsicLocationsBuilderARM64::VisitMemoryPeekLongNative(HInvoke* invoke) {
769 CreateIntToIntLocations(arena_, invoke);
770}
771
772void IntrinsicCodeGeneratorARM64::VisitMemoryPeekLongNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100773 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800774 __ Ldr(XRegisterFrom(invoke->GetLocations()->Out()),
775 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
776}
777
778void IntrinsicLocationsBuilderARM64::VisitMemoryPeekShortNative(HInvoke* invoke) {
779 CreateIntToIntLocations(arena_, invoke);
780}
781
782void IntrinsicCodeGeneratorARM64::VisitMemoryPeekShortNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100783 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800784 __ Ldrsh(WRegisterFrom(invoke->GetLocations()->Out()),
785 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
786}
787
788static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
789 LocationSummary* locations = new (arena) LocationSummary(invoke,
790 LocationSummary::kNoCall,
791 kIntrinsified);
792 locations->SetInAt(0, Location::RequiresRegister());
793 locations->SetInAt(1, Location::RequiresRegister());
794}
795
796void IntrinsicLocationsBuilderARM64::VisitMemoryPokeByte(HInvoke* invoke) {
797 CreateIntIntToVoidLocations(arena_, invoke);
798}
799
800void IntrinsicCodeGeneratorARM64::VisitMemoryPokeByte(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100801 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800802 __ Strb(WRegisterFrom(invoke->GetLocations()->InAt(1)),
803 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
804}
805
806void IntrinsicLocationsBuilderARM64::VisitMemoryPokeIntNative(HInvoke* invoke) {
807 CreateIntIntToVoidLocations(arena_, invoke);
808}
809
810void IntrinsicCodeGeneratorARM64::VisitMemoryPokeIntNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100811 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800812 __ Str(WRegisterFrom(invoke->GetLocations()->InAt(1)),
813 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
814}
815
816void IntrinsicLocationsBuilderARM64::VisitMemoryPokeLongNative(HInvoke* invoke) {
817 CreateIntIntToVoidLocations(arena_, invoke);
818}
819
820void IntrinsicCodeGeneratorARM64::VisitMemoryPokeLongNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100821 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800822 __ Str(XRegisterFrom(invoke->GetLocations()->InAt(1)),
823 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
824}
825
826void IntrinsicLocationsBuilderARM64::VisitMemoryPokeShortNative(HInvoke* invoke) {
827 CreateIntIntToVoidLocations(arena_, invoke);
828}
829
830void IntrinsicCodeGeneratorARM64::VisitMemoryPokeShortNative(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100831 MacroAssembler* masm = GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800832 __ Strh(WRegisterFrom(invoke->GetLocations()->InAt(1)),
833 AbsoluteHeapOperandFrom(invoke->GetLocations()->InAt(0), 0));
834}
835
836void IntrinsicLocationsBuilderARM64::VisitThreadCurrentThread(HInvoke* invoke) {
837 LocationSummary* locations = new (arena_) LocationSummary(invoke,
838 LocationSummary::kNoCall,
839 kIntrinsified);
840 locations->SetOut(Location::RequiresRegister());
841}
842
843void IntrinsicCodeGeneratorARM64::VisitThreadCurrentThread(HInvoke* invoke) {
844 codegen_->Load(Primitive::kPrimNot, WRegisterFrom(invoke->GetLocations()->Out()),
Andreas Gampe542451c2016-07-26 09:02:02 -0700845 MemOperand(tr, Thread::PeerOffset<kArm64PointerSize>().Int32Value()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800846}
847
848static void GenUnsafeGet(HInvoke* invoke,
849 Primitive::Type type,
850 bool is_volatile,
851 CodeGeneratorARM64* codegen) {
852 LocationSummary* locations = invoke->GetLocations();
853 DCHECK((type == Primitive::kPrimInt) ||
854 (type == Primitive::kPrimLong) ||
855 (type == Primitive::kPrimNot));
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000856 Location base_loc = locations->InAt(1);
857 Register base = WRegisterFrom(base_loc); // Object pointer.
858 Location offset_loc = locations->InAt(2);
859 Register offset = XRegisterFrom(offset_loc); // Long offset.
860 Location trg_loc = locations->Out();
861 Register trg = RegisterFrom(trg_loc, type);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800862
Roland Levillain44015862016-01-22 11:47:17 +0000863 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
864 // UnsafeGetObject/UnsafeGetObjectVolatile with Baker's read barrier case.
Roland Levillain54f869e2017-03-06 13:54:11 +0000865 Register temp = WRegisterFrom(locations->GetTemp(0));
Roland Levillainbfea3352016-06-23 13:48:47 +0100866 codegen->GenerateReferenceLoadWithBakerReadBarrier(invoke,
867 trg_loc,
868 base,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100869 /* offset */ 0u,
Roland Levillainbfea3352016-06-23 13:48:47 +0100870 /* index */ offset_loc,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100871 /* scale_factor */ 0u,
Roland Levillainbfea3352016-06-23 13:48:47 +0100872 temp,
873 /* needs_null_check */ false,
874 is_volatile);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800875 } else {
Roland Levillain44015862016-01-22 11:47:17 +0000876 // Other cases.
877 MemOperand mem_op(base.X(), offset);
878 if (is_volatile) {
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +0000879 codegen->LoadAcquire(invoke, trg, mem_op, /* needs_null_check */ true);
Roland Levillain44015862016-01-22 11:47:17 +0000880 } else {
881 codegen->Load(type, trg, mem_op);
882 }
Roland Levillain4d027112015-07-01 15:41:14 +0100883
Roland Levillain44015862016-01-22 11:47:17 +0000884 if (type == Primitive::kPrimNot) {
885 DCHECK(trg.IsW());
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100886 codegen->MaybeGenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0u, offset_loc);
Roland Levillain44015862016-01-22 11:47:17 +0000887 }
Roland Levillain4d027112015-07-01 15:41:14 +0100888 }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800889}
890
891static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
Roland Levillain22ccc3a2015-11-24 13:10:05 +0000892 bool can_call = kEmitCompilerReadBarrier &&
893 (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject ||
894 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800895 LocationSummary* locations = new (arena) LocationSummary(invoke,
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100896 (can_call
897 ? LocationSummary::kCallOnSlowPath
898 : LocationSummary::kNoCall),
Andreas Gampe878d58c2015-01-15 23:24:00 -0800899 kIntrinsified);
Vladimir Marko70e97462016-08-09 11:04:26 +0100900 if (can_call && kUseBakerReadBarrier) {
Vladimir Marko804b03f2016-09-14 16:26:36 +0100901 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Roland Levillain54f869e2017-03-06 13:54:11 +0000902 // We need a temporary register for the read barrier marking slow
903 // path in CodeGeneratorARM64::GenerateReferenceLoadWithBakerReadBarrier.
904 locations->AddTemp(Location::RequiresRegister());
Vladimir Marko70e97462016-08-09 11:04:26 +0100905 }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800906 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
907 locations->SetInAt(1, Location::RequiresRegister());
908 locations->SetInAt(2, Location::RequiresRegister());
Roland Levillainbfea3352016-06-23 13:48:47 +0100909 locations->SetOut(Location::RequiresRegister(),
Roland Levillaina1aa3b12016-10-26 13:03:38 +0100910 (can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800911}
912
913void IntrinsicLocationsBuilderARM64::VisitUnsafeGet(HInvoke* invoke) {
914 CreateIntIntIntToIntLocations(arena_, invoke);
915}
916void IntrinsicLocationsBuilderARM64::VisitUnsafeGetVolatile(HInvoke* invoke) {
917 CreateIntIntIntToIntLocations(arena_, invoke);
918}
919void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLong(HInvoke* invoke) {
920 CreateIntIntIntToIntLocations(arena_, invoke);
921}
922void IntrinsicLocationsBuilderARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
923 CreateIntIntIntToIntLocations(arena_, invoke);
924}
925void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObject(HInvoke* invoke) {
926 CreateIntIntIntToIntLocations(arena_, invoke);
927}
928void IntrinsicLocationsBuilderARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
929 CreateIntIntIntToIntLocations(arena_, invoke);
930}
931
932void IntrinsicCodeGeneratorARM64::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000933 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800934}
935void IntrinsicCodeGeneratorARM64::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000936 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800937}
938void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000939 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800940}
941void IntrinsicCodeGeneratorARM64::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000942 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800943}
944void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000945 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800946}
947void IntrinsicCodeGeneratorARM64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000948 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800949}
950
951static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) {
952 LocationSummary* locations = new (arena) LocationSummary(invoke,
953 LocationSummary::kNoCall,
954 kIntrinsified);
955 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
956 locations->SetInAt(1, Location::RequiresRegister());
957 locations->SetInAt(2, Location::RequiresRegister());
958 locations->SetInAt(3, Location::RequiresRegister());
959}
960
961void IntrinsicLocationsBuilderARM64::VisitUnsafePut(HInvoke* invoke) {
962 CreateIntIntIntIntToVoid(arena_, invoke);
963}
964void IntrinsicLocationsBuilderARM64::VisitUnsafePutOrdered(HInvoke* invoke) {
965 CreateIntIntIntIntToVoid(arena_, invoke);
966}
967void IntrinsicLocationsBuilderARM64::VisitUnsafePutVolatile(HInvoke* invoke) {
968 CreateIntIntIntIntToVoid(arena_, invoke);
969}
970void IntrinsicLocationsBuilderARM64::VisitUnsafePutObject(HInvoke* invoke) {
971 CreateIntIntIntIntToVoid(arena_, invoke);
972}
973void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
974 CreateIntIntIntIntToVoid(arena_, invoke);
975}
976void IntrinsicLocationsBuilderARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
977 CreateIntIntIntIntToVoid(arena_, invoke);
978}
979void IntrinsicLocationsBuilderARM64::VisitUnsafePutLong(HInvoke* invoke) {
980 CreateIntIntIntIntToVoid(arena_, invoke);
981}
982void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) {
983 CreateIntIntIntIntToVoid(arena_, invoke);
984}
985void IntrinsicLocationsBuilderARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) {
986 CreateIntIntIntIntToVoid(arena_, invoke);
987}
988
Artem Serov914d7a82017-02-07 14:33:49 +0000989static void GenUnsafePut(HInvoke* invoke,
Andreas Gampe878d58c2015-01-15 23:24:00 -0800990 Primitive::Type type,
991 bool is_volatile,
992 bool is_ordered,
993 CodeGeneratorARM64* codegen) {
Artem Serov914d7a82017-02-07 14:33:49 +0000994 LocationSummary* locations = invoke->GetLocations();
Alexandre Rames087930f2016-08-02 13:45:28 +0100995 MacroAssembler* masm = codegen->GetVIXLAssembler();
Andreas Gampe878d58c2015-01-15 23:24:00 -0800996
997 Register base = WRegisterFrom(locations->InAt(1)); // Object pointer.
998 Register offset = XRegisterFrom(locations->InAt(2)); // Long offset.
999 Register value = RegisterFrom(locations->InAt(3), type);
Roland Levillain4d027112015-07-01 15:41:14 +01001000 Register source = value;
Andreas Gampe878d58c2015-01-15 23:24:00 -08001001 MemOperand mem_op(base.X(), offset);
1002
Roland Levillain4d027112015-07-01 15:41:14 +01001003 {
1004 // We use a block to end the scratch scope before the write barrier, thus
1005 // freeing the temporary registers so they can be used in `MarkGCCard`.
1006 UseScratchRegisterScope temps(masm);
1007
1008 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
1009 DCHECK(value.IsW());
1010 Register temp = temps.AcquireW();
1011 __ Mov(temp.W(), value.W());
1012 codegen->GetAssembler()->PoisonHeapReference(temp.W());
1013 source = temp;
Andreas Gampe878d58c2015-01-15 23:24:00 -08001014 }
Roland Levillain4d027112015-07-01 15:41:14 +01001015
1016 if (is_volatile || is_ordered) {
Artem Serov914d7a82017-02-07 14:33:49 +00001017 codegen->StoreRelease(invoke, type, source, mem_op, /* needs_null_check */ false);
Roland Levillain4d027112015-07-01 15:41:14 +01001018 } else {
1019 codegen->Store(type, source, mem_op);
1020 }
Andreas Gampe878d58c2015-01-15 23:24:00 -08001021 }
1022
1023 if (type == Primitive::kPrimNot) {
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001024 bool value_can_be_null = true; // TODO: Worth finding out this information?
1025 codegen->MarkGCCard(base, value, value_can_be_null);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001026 }
1027}
1028
1029void IntrinsicCodeGeneratorARM64::VisitUnsafePut(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001030 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001031 Primitive::kPrimInt,
1032 /* is_volatile */ false,
1033 /* is_ordered */ false,
1034 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001035}
1036void IntrinsicCodeGeneratorARM64::VisitUnsafePutOrdered(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001037 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001038 Primitive::kPrimInt,
1039 /* is_volatile */ false,
1040 /* is_ordered */ true,
1041 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001042}
1043void IntrinsicCodeGeneratorARM64::VisitUnsafePutVolatile(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001044 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001045 Primitive::kPrimInt,
1046 /* is_volatile */ true,
1047 /* is_ordered */ false,
1048 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001049}
1050void IntrinsicCodeGeneratorARM64::VisitUnsafePutObject(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001051 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001052 Primitive::kPrimNot,
1053 /* is_volatile */ false,
1054 /* is_ordered */ false,
1055 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001056}
1057void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001058 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001059 Primitive::kPrimNot,
1060 /* is_volatile */ false,
1061 /* is_ordered */ true,
1062 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001063}
1064void IntrinsicCodeGeneratorARM64::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001065 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001066 Primitive::kPrimNot,
1067 /* is_volatile */ true,
1068 /* is_ordered */ false,
1069 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001070}
1071void IntrinsicCodeGeneratorARM64::VisitUnsafePutLong(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001072 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001073 Primitive::kPrimLong,
1074 /* is_volatile */ false,
1075 /* is_ordered */ false,
1076 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001077}
1078void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001079 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001080 Primitive::kPrimLong,
1081 /* is_volatile */ false,
1082 /* is_ordered */ true,
1083 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001084}
1085void IntrinsicCodeGeneratorARM64::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Artem Serov914d7a82017-02-07 14:33:49 +00001086 GenUnsafePut(invoke,
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001087 Primitive::kPrimLong,
1088 /* is_volatile */ true,
1089 /* is_ordered */ false,
1090 codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001091}
1092
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001093static void CreateIntIntIntIntIntToInt(ArenaAllocator* arena,
1094 HInvoke* invoke,
1095 Primitive::Type type) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001096 bool can_call = kEmitCompilerReadBarrier &&
1097 kUseBakerReadBarrier &&
1098 (invoke->GetIntrinsic() == Intrinsics::kUnsafeCASObject);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001099 LocationSummary* locations = new (arena) LocationSummary(invoke,
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001100 (can_call
1101 ? LocationSummary::kCallOnSlowPath
1102 : LocationSummary::kNoCall),
Andreas Gampe878d58c2015-01-15 23:24:00 -08001103 kIntrinsified);
1104 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1105 locations->SetInAt(1, Location::RequiresRegister());
1106 locations->SetInAt(2, Location::RequiresRegister());
1107 locations->SetInAt(3, Location::RequiresRegister());
1108 locations->SetInAt(4, Location::RequiresRegister());
1109
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001110 // If heap poisoning is enabled, we don't want the unpoisoning
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001111 // operations to potentially clobber the output. Likewise when
1112 // emitting a (Baker) read barrier, which may call.
1113 Location::OutputOverlap overlaps =
1114 ((kPoisonHeapReferences && type == Primitive::kPrimNot) || can_call)
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001115 ? Location::kOutputOverlap
1116 : Location::kNoOutputOverlap;
1117 locations->SetOut(Location::RequiresRegister(), overlaps);
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001118 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1119 // Temporary register for (Baker) read barrier.
1120 locations->AddTemp(Location::RequiresRegister());
1121 }
Andreas Gampe878d58c2015-01-15 23:24:00 -08001122}
1123
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001124static void GenCas(HInvoke* invoke, Primitive::Type type, CodeGeneratorARM64* codegen) {
Alexandre Rames087930f2016-08-02 13:45:28 +01001125 MacroAssembler* masm = codegen->GetVIXLAssembler();
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001126 LocationSummary* locations = invoke->GetLocations();
Andreas Gampe878d58c2015-01-15 23:24:00 -08001127
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001128 Location out_loc = locations->Out();
1129 Register out = WRegisterFrom(out_loc); // Boolean result.
Andreas Gampe878d58c2015-01-15 23:24:00 -08001130
1131 Register base = WRegisterFrom(locations->InAt(1)); // Object pointer.
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001132 Location offset_loc = locations->InAt(2);
1133 Register offset = XRegisterFrom(offset_loc); // Long offset.
Andreas Gampe878d58c2015-01-15 23:24:00 -08001134 Register expected = RegisterFrom(locations->InAt(3), type); // Expected.
1135 Register value = RegisterFrom(locations->InAt(4), type); // Value.
1136
1137 // This needs to be before the temp registers, as MarkGCCard also uses VIXL temps.
1138 if (type == Primitive::kPrimNot) {
1139 // Mark card for object assuming new value is stored.
Nicolas Geoffray07276db2015-05-18 14:22:09 +01001140 bool value_can_be_null = true; // TODO: Worth finding out this information?
1141 codegen->MarkGCCard(base, value, value_can_be_null);
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001142
1143 // The only read barrier implementation supporting the
1144 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1145 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
1146
1147 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1148 Register temp = WRegisterFrom(locations->GetTemp(0));
1149 // Need to make sure the reference stored in the field is a to-space
1150 // one before attempting the CAS or the CAS could fail incorrectly.
1151 codegen->GenerateReferenceLoadWithBakerReadBarrier(
1152 invoke,
1153 out_loc, // Unused, used only as a "temporary" within the read barrier.
1154 base,
1155 /* offset */ 0u,
1156 /* index */ offset_loc,
1157 /* scale_factor */ 0u,
1158 temp,
1159 /* needs_null_check */ false,
1160 /* use_load_acquire */ false,
1161 /* always_update_field */ true);
1162 }
Andreas Gampe878d58c2015-01-15 23:24:00 -08001163 }
1164
1165 UseScratchRegisterScope temps(masm);
1166 Register tmp_ptr = temps.AcquireX(); // Pointer to actual memory.
1167 Register tmp_value = temps.AcquireSameSizeAs(value); // Value in memory.
1168
1169 Register tmp_32 = tmp_value.W();
1170
1171 __ Add(tmp_ptr, base.X(), Operand(offset));
1172
Roland Levillain4d027112015-07-01 15:41:14 +01001173 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
1174 codegen->GetAssembler()->PoisonHeapReference(expected);
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001175 if (value.Is(expected)) {
1176 // Do not poison `value`, as it is the same register as
1177 // `expected`, which has just been poisoned.
1178 } else {
1179 codegen->GetAssembler()->PoisonHeapReference(value);
1180 }
Roland Levillain4d027112015-07-01 15:41:14 +01001181 }
1182
Andreas Gampe878d58c2015-01-15 23:24:00 -08001183 // do {
1184 // tmp_value = [tmp_ptr] - expected;
1185 // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value));
1186 // result = tmp_value != 0;
1187
Scott Wakeling97c72b72016-06-24 16:19:36 +01001188 vixl::aarch64::Label loop_head, exit_loop;
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001189 __ Bind(&loop_head);
Serban Constantinescu4a6a67c2016-01-27 09:19:56 +00001190 __ Ldaxr(tmp_value, MemOperand(tmp_ptr));
1191 __ Cmp(tmp_value, expected);
1192 __ B(&exit_loop, ne);
1193 __ Stlxr(tmp_32, value, MemOperand(tmp_ptr));
1194 __ Cbnz(tmp_32, &loop_head);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001195 __ Bind(&exit_loop);
1196 __ Cset(out, eq);
Roland Levillain4d027112015-07-01 15:41:14 +01001197
1198 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
Roland Levillain4d027112015-07-01 15:41:14 +01001199 codegen->GetAssembler()->UnpoisonHeapReference(expected);
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001200 if (value.Is(expected)) {
1201 // Do not unpoison `value`, as it is the same register as
1202 // `expected`, which has just been unpoisoned.
1203 } else {
1204 codegen->GetAssembler()->UnpoisonHeapReference(value);
1205 }
Roland Levillain4d027112015-07-01 15:41:14 +01001206 }
Andreas Gampe878d58c2015-01-15 23:24:00 -08001207}
1208
1209void IntrinsicLocationsBuilderARM64::VisitUnsafeCASInt(HInvoke* invoke) {
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001210 CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001211}
1212void IntrinsicLocationsBuilderARM64::VisitUnsafeCASLong(HInvoke* invoke) {
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001213 CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001214}
1215void IntrinsicLocationsBuilderARM64::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001216 // The only read barrier implementation supporting the
1217 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1218 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
Roland Levillain985ff702015-10-23 13:25:35 +01001219 return;
1220 }
1221
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001222 CreateIntIntIntIntIntToInt(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001223}
1224
1225void IntrinsicCodeGeneratorARM64::VisitUnsafeCASInt(HInvoke* invoke) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001226 GenCas(invoke, Primitive::kPrimInt, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001227}
1228void IntrinsicCodeGeneratorARM64::VisitUnsafeCASLong(HInvoke* invoke) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001229 GenCas(invoke, Primitive::kPrimLong, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001230}
1231void IntrinsicCodeGeneratorARM64::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001232 // The only read barrier implementation supporting the
1233 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1234 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
Roland Levillain3d312422016-06-23 13:53:42 +01001235
Roland Levillaina1aa3b12016-10-26 13:03:38 +01001236 GenCas(invoke, Primitive::kPrimNot, codegen_);
Andreas Gampe878d58c2015-01-15 23:24:00 -08001237}
1238
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001239void IntrinsicLocationsBuilderARM64::VisitStringCompareTo(HInvoke* invoke) {
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001240 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Scott Wakeling1f36f412016-04-21 11:13:45 +01001241 invoke->InputAt(1)->CanBeNull()
1242 ? LocationSummary::kCallOnSlowPath
1243 : LocationSummary::kNoCall,
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001244 kIntrinsified);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001245 locations->SetInAt(0, Location::RequiresRegister());
1246 locations->SetInAt(1, Location::RequiresRegister());
1247 locations->AddTemp(Location::RequiresRegister());
1248 locations->AddTemp(Location::RequiresRegister());
1249 locations->AddTemp(Location::RequiresRegister());
jessicahandojo05765752016-09-09 19:01:32 -07001250 // Need temporary registers for String compression's feature.
1251 if (mirror::kUseStringCompression) {
1252 locations->AddTemp(Location::RequiresRegister());
jessicahandojo05765752016-09-09 19:01:32 -07001253 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001254 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001255}
1256
1257void IntrinsicCodeGeneratorARM64::VisitStringCompareTo(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001258 MacroAssembler* masm = GetVIXLAssembler();
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001259 LocationSummary* locations = invoke->GetLocations();
1260
Alexandre Rames2ea91532016-08-11 17:04:14 +01001261 Register str = InputRegisterAt(invoke, 0);
1262 Register arg = InputRegisterAt(invoke, 1);
1263 DCHECK(str.IsW());
1264 DCHECK(arg.IsW());
Scott Wakeling1f36f412016-04-21 11:13:45 +01001265 Register out = OutputRegister(invoke);
1266
1267 Register temp0 = WRegisterFrom(locations->GetTemp(0));
1268 Register temp1 = WRegisterFrom(locations->GetTemp(1));
1269 Register temp2 = WRegisterFrom(locations->GetTemp(2));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001270 Register temp3;
jessicahandojo05765752016-09-09 19:01:32 -07001271 if (mirror::kUseStringCompression) {
1272 temp3 = WRegisterFrom(locations->GetTemp(3));
jessicahandojo05765752016-09-09 19:01:32 -07001273 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001274
Scott Wakeling97c72b72016-06-24 16:19:36 +01001275 vixl::aarch64::Label loop;
1276 vixl::aarch64::Label find_char_diff;
1277 vixl::aarch64::Label end;
jessicahandojo05765752016-09-09 19:01:32 -07001278 vixl::aarch64::Label different_compression;
Scott Wakeling1f36f412016-04-21 11:13:45 +01001279
1280 // Get offsets of count and value fields within a string object.
1281 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1282 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1283
Nicolas Geoffray512e04d2015-03-27 17:21:24 +00001284 // Note that the null check must have been done earlier.
Calin Juravle641547a2015-04-21 22:08:51 +01001285 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001286
Scott Wakeling1f36f412016-04-21 11:13:45 +01001287 // Take slow path and throw if input can be and is null.
1288 SlowPathCodeARM64* slow_path = nullptr;
1289 const bool can_slow_path = invoke->InputAt(1)->CanBeNull();
1290 if (can_slow_path) {
1291 slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
1292 codegen_->AddSlowPath(slow_path);
1293 __ Cbz(arg, slow_path->GetEntryLabel());
1294 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001295
Scott Wakeling1f36f412016-04-21 11:13:45 +01001296 // Reference equality check, return 0 if same reference.
1297 __ Subs(out, str, arg);
1298 __ B(&end, eq);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001299
jessicahandojo05765752016-09-09 19:01:32 -07001300 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001301 // Load `count` fields of this and argument strings.
jessicahandojo05765752016-09-09 19:01:32 -07001302 __ Ldr(temp3, HeapOperand(str, count_offset));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001303 __ Ldr(temp2, HeapOperand(arg, count_offset));
jessicahandojo05765752016-09-09 19:01:32 -07001304 // Clean out compression flag from lengths.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001305 __ Lsr(temp0, temp3, 1u);
1306 __ Lsr(temp1, temp2, 1u);
jessicahandojo05765752016-09-09 19:01:32 -07001307 } else {
1308 // Load lengths of this and argument strings.
1309 __ Ldr(temp0, HeapOperand(str, count_offset));
1310 __ Ldr(temp1, HeapOperand(arg, count_offset));
1311 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001312 // out = length diff.
1313 __ Subs(out, temp0, temp1);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001314 // temp0 = min(len(str), len(arg)).
1315 __ Csel(temp0, temp1, temp0, ge);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001316 // Shorter string is empty?
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001317 __ Cbz(temp0, &end);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001318
jessicahandojo05765752016-09-09 19:01:32 -07001319 if (mirror::kUseStringCompression) {
1320 // Check if both strings using same compression style to use this comparison loop.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001321 __ Eor(temp2, temp2, Operand(temp3));
1322 // Interleave with compression flag extraction which is needed for both paths
1323 // and also set flags which is needed only for the different compressions path.
1324 __ Ands(temp3.W(), temp3.W(), Operand(1));
1325 __ Tbnz(temp2, 0, &different_compression); // Does not use flags.
jessicahandojo05765752016-09-09 19:01:32 -07001326 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001327 // Store offset of string value in preparation for comparison loop.
1328 __ Mov(temp1, value_offset);
jessicahandojo05765752016-09-09 19:01:32 -07001329 if (mirror::kUseStringCompression) {
1330 // For string compression, calculate the number of bytes to compare (not chars).
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001331 // This could in theory exceed INT32_MAX, so treat temp0 as unsigned.
1332 __ Lsl(temp0, temp0, temp3);
jessicahandojo05765752016-09-09 19:01:32 -07001333 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001334
1335 UseScratchRegisterScope scratch_scope(masm);
1336 Register temp4 = scratch_scope.AcquireX();
1337
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001338 // Assertions that must hold in order to compare strings 8 bytes at a time.
Scott Wakeling1f36f412016-04-21 11:13:45 +01001339 DCHECK_ALIGNED(value_offset, 8);
1340 static_assert(IsAligned<8>(kObjectAlignment), "String of odd length is not zero padded");
1341
1342 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
1343 DCHECK_EQ(char_size, 2u);
1344
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001345 // Promote temp2 to an X reg, ready for LDR.
1346 temp2 = temp2.X();
Scott Wakeling1f36f412016-04-21 11:13:45 +01001347
1348 // Loop to compare 4x16-bit characters at a time (ok because of string data alignment).
1349 __ Bind(&loop);
Alexandre Rames2ea91532016-08-11 17:04:14 +01001350 __ Ldr(temp4, MemOperand(str.X(), temp1.X()));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001351 __ Ldr(temp2, MemOperand(arg.X(), temp1.X()));
1352 __ Cmp(temp4, temp2);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001353 __ B(ne, &find_char_diff);
1354 __ Add(temp1, temp1, char_size * 4);
jessicahandojo05765752016-09-09 19:01:32 -07001355 // With string compression, we have compared 8 bytes, otherwise 4 chars.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001356 __ Subs(temp0, temp0, (mirror::kUseStringCompression) ? 8 : 4);
1357 __ B(&loop, hi);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001358 __ B(&end);
1359
1360 // Promote temp1 to an X reg, ready for EOR.
1361 temp1 = temp1.X();
1362
jessicahandojo05765752016-09-09 19:01:32 -07001363 // Find the single character difference.
Scott Wakeling1f36f412016-04-21 11:13:45 +01001364 __ Bind(&find_char_diff);
1365 // Get the bit position of the first character that differs.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001366 __ Eor(temp1, temp2, temp4);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001367 __ Rbit(temp1, temp1);
1368 __ Clz(temp1, temp1);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001369
jessicahandojo05765752016-09-09 19:01:32 -07001370 // If the number of chars remaining <= the index where the difference occurs (0-3), then
Scott Wakeling1f36f412016-04-21 11:13:45 +01001371 // the difference occurs outside the remaining string data, so just return length diff (out).
jessicahandojo05765752016-09-09 19:01:32 -07001372 // Unlike ARM, we're doing the comparison in one go here, without the subtraction at the
1373 // find_char_diff_2nd_cmp path, so it doesn't matter whether the comparison is signed or
1374 // unsigned when string compression is disabled.
1375 // When it's enabled, the comparison must be unsigned.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001376 __ Cmp(temp0, Operand(temp1.W(), LSR, (mirror::kUseStringCompression) ? 3 : 4));
jessicahandojo05765752016-09-09 19:01:32 -07001377 __ B(ls, &end);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001378
Scott Wakeling1f36f412016-04-21 11:13:45 +01001379 // Extract the characters and calculate the difference.
jessicahandojo05765752016-09-09 19:01:32 -07001380 if (mirror:: kUseStringCompression) {
jessicahandojo05765752016-09-09 19:01:32 -07001381 __ Bic(temp1, temp1, 0x7);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001382 __ Bic(temp1, temp1, Operand(temp3.X(), LSL, 3u));
1383 } else {
1384 __ Bic(temp1, temp1, 0xf);
jessicahandojo05765752016-09-09 19:01:32 -07001385 }
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001386 __ Lsr(temp2, temp2, temp1);
Scott Wakeling1f36f412016-04-21 11:13:45 +01001387 __ Lsr(temp4, temp4, temp1);
jessicahandojo05765752016-09-09 19:01:32 -07001388 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001389 // Prioritize the case of compressed strings and calculate such result first.
1390 __ Uxtb(temp1, temp4);
1391 __ Sub(out, temp1.W(), Operand(temp2.W(), UXTB));
1392 __ Tbz(temp3, 0u, &end); // If actually compressed, we're done.
jessicahandojo05765752016-09-09 19:01:32 -07001393 }
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001394 __ Uxth(temp4, temp4);
1395 __ Sub(out, temp4.W(), Operand(temp2.W(), UXTH));
jessicahandojo05765752016-09-09 19:01:32 -07001396
1397 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001398 __ B(&end);
1399 __ Bind(&different_compression);
1400
1401 // Comparison for different compression style.
jessicahandojo05765752016-09-09 19:01:32 -07001402 const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte);
1403 DCHECK_EQ(c_char_size, 1u);
jessicahandojo05765752016-09-09 19:01:32 -07001404 temp1 = temp1.W();
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001405 temp2 = temp2.W();
1406 temp4 = temp4.W();
jessicahandojo05765752016-09-09 19:01:32 -07001407
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001408 // `temp1` will hold the compressed data pointer, `temp2` the uncompressed data pointer.
1409 // Note that flags have been set by the `str` compression flag extraction to `temp3`
1410 // before branching to the `different_compression` label.
1411 __ Csel(temp1, str, arg, eq); // Pointer to the compressed string.
1412 __ Csel(temp2, str, arg, ne); // Pointer to the uncompressed string.
jessicahandojo05765752016-09-09 19:01:32 -07001413
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001414 // We want to free up the temp3, currently holding `str` compression flag, for comparison.
1415 // So, we move it to the bottom bit of the iteration count `temp0` which we then need to treat
1416 // as unsigned. Start by freeing the bit with a LSL and continue further down by a SUB which
1417 // will allow `subs temp0, #2; bhi different_compression_loop` to serve as the loop condition.
1418 __ Lsl(temp0, temp0, 1u);
1419
1420 // Adjust temp1 and temp2 from string pointers to data pointers.
1421 __ Add(temp1, temp1, Operand(value_offset));
1422 __ Add(temp2, temp2, Operand(value_offset));
1423
1424 // Complete the move of the compression flag.
1425 __ Sub(temp0, temp0, Operand(temp3));
1426
1427 vixl::aarch64::Label different_compression_loop;
1428 vixl::aarch64::Label different_compression_diff;
1429
1430 __ Bind(&different_compression_loop);
1431 __ Ldrb(temp4, MemOperand(temp1.X(), c_char_size, PostIndex));
1432 __ Ldrh(temp3, MemOperand(temp2.X(), char_size, PostIndex));
1433 __ Subs(temp4, temp4, Operand(temp3));
1434 __ B(&different_compression_diff, ne);
1435 __ Subs(temp0, temp0, 2);
1436 __ B(&different_compression_loop, hi);
jessicahandojo05765752016-09-09 19:01:32 -07001437 __ B(&end);
1438
1439 // Calculate the difference.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001440 __ Bind(&different_compression_diff);
1441 __ Tst(temp0, Operand(1));
1442 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
1443 "Expecting 0=compressed, 1=uncompressed");
1444 __ Cneg(out, temp4, ne);
jessicahandojo05765752016-09-09 19:01:32 -07001445 }
Scott Wakeling1f36f412016-04-21 11:13:45 +01001446
1447 __ Bind(&end);
1448
1449 if (can_slow_path) {
1450 __ Bind(slow_path->GetExitLabel());
1451 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001452}
1453
Vladimir Markoe39f14f2017-02-10 15:44:25 +00001454// The cut off for unrolling the loop in String.equals() intrinsic for const strings.
1455// The normal loop plus the pre-header is 9 instructions without string compression and 12
1456// instructions with string compression. We can compare up to 8 bytes in 4 instructions
1457// (LDR+LDR+CMP+BNE) and up to 16 bytes in 5 instructions (LDP+LDP+CMP+CCMP+BNE). Allow up
1458// to 10 instructions for the unrolled loop.
1459constexpr size_t kShortConstStringEqualsCutoffInBytes = 32;
1460
1461static const char* GetConstString(HInstruction* candidate, uint32_t* utf16_length) {
1462 if (candidate->IsLoadString()) {
1463 HLoadString* load_string = candidate->AsLoadString();
1464 const DexFile& dex_file = load_string->GetDexFile();
1465 return dex_file.StringDataAndUtf16LengthByIdx(load_string->GetStringIndex(), utf16_length);
1466 }
1467 return nullptr;
1468}
1469
Agi Csakiea34b402015-08-13 17:51:19 -07001470void IntrinsicLocationsBuilderARM64::VisitStringEquals(HInvoke* invoke) {
1471 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1472 LocationSummary::kNoCall,
1473 kIntrinsified);
1474 locations->SetInAt(0, Location::RequiresRegister());
1475 locations->SetInAt(1, Location::RequiresRegister());
Agi Csakiea34b402015-08-13 17:51:19 -07001476
Vladimir Markoe39f14f2017-02-10 15:44:25 +00001477 // For the generic implementation and for long const strings we need a temporary.
1478 // We do not need it for short const strings, up to 8 bytes, see code generation below.
1479 uint32_t const_string_length = 0u;
1480 const char* const_string = GetConstString(invoke->InputAt(0), &const_string_length);
1481 if (const_string == nullptr) {
1482 const_string = GetConstString(invoke->InputAt(1), &const_string_length);
1483 }
1484 bool is_compressed =
1485 mirror::kUseStringCompression &&
1486 const_string != nullptr &&
1487 mirror::String::DexFileStringAllASCII(const_string, const_string_length);
1488 if (const_string == nullptr || const_string_length > (is_compressed ? 8u : 4u)) {
1489 locations->AddTemp(Location::RequiresRegister());
1490 }
1491
1492 // TODO: If the String.equals() is used only for an immediately following HIf, we can
1493 // mark it as emitted-at-use-site and emit branches directly to the appropriate blocks.
1494 // Then we shall need an extra temporary register instead of the output register.
Agi Csakiea34b402015-08-13 17:51:19 -07001495 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1496}
1497
1498void IntrinsicCodeGeneratorARM64::VisitStringEquals(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001499 MacroAssembler* masm = GetVIXLAssembler();
Agi Csakiea34b402015-08-13 17:51:19 -07001500 LocationSummary* locations = invoke->GetLocations();
1501
1502 Register str = WRegisterFrom(locations->InAt(0));
1503 Register arg = WRegisterFrom(locations->InAt(1));
1504 Register out = XRegisterFrom(locations->Out());
1505
1506 UseScratchRegisterScope scratch_scope(masm);
1507 Register temp = scratch_scope.AcquireW();
Vladimir Markoe39f14f2017-02-10 15:44:25 +00001508 Register temp1 = scratch_scope.AcquireW();
Agi Csakiea34b402015-08-13 17:51:19 -07001509
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001510 vixl::aarch64::Label loop;
Scott Wakeling97c72b72016-06-24 16:19:36 +01001511 vixl::aarch64::Label end;
1512 vixl::aarch64::Label return_true;
1513 vixl::aarch64::Label return_false;
Agi Csakiea34b402015-08-13 17:51:19 -07001514
1515 // Get offsets of count, value, and class fields within a string object.
1516 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1517 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1518 const int32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1519
1520 // Note that the null check must have been done earlier.
1521 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1522
Vladimir Marko53b52002016-05-24 19:30:45 +01001523 StringEqualsOptimizations optimizations(invoke);
1524 if (!optimizations.GetArgumentNotNull()) {
1525 // Check if input is null, return false if it is.
1526 __ Cbz(arg, &return_false);
1527 }
Agi Csakiea34b402015-08-13 17:51:19 -07001528
1529 // Reference equality check, return true if same reference.
1530 __ Cmp(str, arg);
1531 __ B(&return_true, eq);
1532
Vladimir Marko53b52002016-05-24 19:30:45 +01001533 if (!optimizations.GetArgumentIsString()) {
1534 // Instanceof check for the argument by comparing class fields.
1535 // All string objects must have the same type since String cannot be subclassed.
1536 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1537 // If the argument is a string object, its class field must be equal to receiver's class field.
1538 __ Ldr(temp, MemOperand(str.X(), class_offset));
1539 __ Ldr(temp1, MemOperand(arg.X(), class_offset));
1540 __ Cmp(temp, temp1);
1541 __ B(&return_false, ne);
1542 }
Agi Csakiea34b402015-08-13 17:51:19 -07001543
Vladimir Markoe39f14f2017-02-10 15:44:25 +00001544 // Check if one of the inputs is a const string. Do not special-case both strings
1545 // being const, such cases should be handled by constant folding if needed.
1546 uint32_t const_string_length = 0u;
1547 const char* const_string = GetConstString(invoke->InputAt(0), &const_string_length);
1548 if (const_string == nullptr) {
1549 const_string = GetConstString(invoke->InputAt(1), &const_string_length);
1550 if (const_string != nullptr) {
1551 std::swap(str, arg); // Make sure the const string is in `str`.
1552 }
1553 }
1554 bool is_compressed =
1555 mirror::kUseStringCompression &&
1556 const_string != nullptr &&
1557 mirror::String::DexFileStringAllASCII(const_string, const_string_length);
1558
1559 if (const_string != nullptr) {
1560 // Load `count` field of the argument string and check if it matches the const string.
1561 // Also compares the compression style, if differs return false.
1562 __ Ldr(temp, MemOperand(arg.X(), count_offset));
1563 __ Cmp(temp, Operand(mirror::String::GetFlaggedCount(const_string_length, is_compressed)));
1564 __ B(&return_false, ne);
1565 } else {
1566 // Load `count` fields of this and argument strings.
1567 __ Ldr(temp, MemOperand(str.X(), count_offset));
1568 __ Ldr(temp1, MemOperand(arg.X(), count_offset));
1569 // Check if `count` fields are equal, return false if they're not.
1570 // Also compares the compression style, if differs return false.
1571 __ Cmp(temp, temp1);
1572 __ B(&return_false, ne);
1573 }
Agi Csakiea34b402015-08-13 17:51:19 -07001574
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001575 // Assertions that must hold in order to compare strings 8 bytes at a time.
Agi Csakiea34b402015-08-13 17:51:19 -07001576 DCHECK_ALIGNED(value_offset, 8);
1577 static_assert(IsAligned<8>(kObjectAlignment), "String of odd length is not zero padded");
1578
Vladimir Markoe39f14f2017-02-10 15:44:25 +00001579 if (const_string != nullptr &&
1580 const_string_length < (is_compressed ? kShortConstStringEqualsCutoffInBytes
1581 : kShortConstStringEqualsCutoffInBytes / 2u)) {
1582 // Load and compare the contents. Though we know the contents of the short const string
1583 // at compile time, materializing constants may be more code than loading from memory.
1584 int32_t offset = value_offset;
1585 size_t remaining_bytes =
1586 RoundUp(is_compressed ? const_string_length : const_string_length * 2u, 8u);
1587 temp = temp.X();
1588 temp1 = temp1.X();
1589 while (remaining_bytes > 8u) {
1590 Register temp2 = XRegisterFrom(locations->GetTemp(0));
1591 __ Ldp(temp, temp1, MemOperand(str.X(), offset));
1592 __ Ldp(temp2, out, MemOperand(arg.X(), offset));
1593 __ Cmp(temp, temp2);
1594 __ Ccmp(temp1, out, NoFlag, eq);
1595 __ B(&return_false, ne);
1596 offset += 2u * sizeof(uint64_t);
1597 remaining_bytes -= 2u * sizeof(uint64_t);
1598 }
1599 if (remaining_bytes != 0u) {
1600 __ Ldr(temp, MemOperand(str.X(), offset));
1601 __ Ldr(temp1, MemOperand(arg.X(), offset));
1602 __ Cmp(temp, temp1);
1603 __ B(&return_false, ne);
1604 }
1605 } else {
1606 // Return true if both strings are empty. Even with string compression `count == 0` means empty.
1607 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
1608 "Expecting 0=compressed, 1=uncompressed");
1609 __ Cbz(temp, &return_true);
1610
1611 if (mirror::kUseStringCompression) {
1612 // For string compression, calculate the number of bytes to compare (not chars).
1613 // This could in theory exceed INT32_MAX, so treat temp as unsigned.
1614 __ And(temp1, temp, Operand(1)); // Extract compression flag.
1615 __ Lsr(temp, temp, 1u); // Extract length.
1616 __ Lsl(temp, temp, temp1); // Calculate number of bytes to compare.
1617 }
1618
1619 // Store offset of string value in preparation for comparison loop
1620 __ Mov(temp1, value_offset);
1621
1622 temp1 = temp1.X();
1623 Register temp2 = XRegisterFrom(locations->GetTemp(0));
1624 // Loop to compare strings 8 bytes at a time starting at the front of the string.
1625 // Ok to do this because strings are zero-padded to kObjectAlignment.
1626 __ Bind(&loop);
1627 __ Ldr(out, MemOperand(str.X(), temp1));
1628 __ Ldr(temp2, MemOperand(arg.X(), temp1));
1629 __ Add(temp1, temp1, Operand(sizeof(uint64_t)));
1630 __ Cmp(out, temp2);
1631 __ B(&return_false, ne);
1632 // With string compression, we have compared 8 bytes, otherwise 4 chars.
1633 __ Sub(temp, temp, Operand(mirror::kUseStringCompression ? 8 : 4), SetFlags);
1634 __ B(&loop, hi);
jessicahandojo05765752016-09-09 19:01:32 -07001635 }
1636
Agi Csakiea34b402015-08-13 17:51:19 -07001637 // Return true and exit the function.
1638 // If loop does not result in returning false, we return true.
1639 __ Bind(&return_true);
1640 __ Mov(out, 1);
1641 __ B(&end);
1642
1643 // Return false and exit the function.
1644 __ Bind(&return_false);
1645 __ Mov(out, 0);
1646 __ Bind(&end);
1647}
1648
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001649static void GenerateVisitStringIndexOf(HInvoke* invoke,
Scott Wakeling97c72b72016-06-24 16:19:36 +01001650 MacroAssembler* masm,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001651 CodeGeneratorARM64* codegen,
1652 ArenaAllocator* allocator,
1653 bool start_at_zero) {
1654 LocationSummary* locations = invoke->GetLocations();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001655
1656 // Note that the null check must have been done earlier.
1657 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1658
1659 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001660 // or directly dispatch for a large constant, or omit slow-path for a small constant or a char.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001661 SlowPathCodeARM64* slow_path = nullptr;
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001662 HInstruction* code_point = invoke->InputAt(1);
1663 if (code_point->IsIntConstant()) {
Vladimir Markoda051082016-05-17 16:10:20 +01001664 if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) > 0xFFFFU) {
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001665 // Always needs the slow-path. We could directly dispatch to it, but this case should be
1666 // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1667 slow_path = new (allocator) IntrinsicSlowPathARM64(invoke);
1668 codegen->AddSlowPath(slow_path);
1669 __ B(slow_path->GetEntryLabel());
1670 __ Bind(slow_path->GetExitLabel());
1671 return;
1672 }
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001673 } else if (code_point->GetType() != Primitive::kPrimChar) {
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001674 Register char_reg = WRegisterFrom(locations->InAt(1));
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001675 __ Tst(char_reg, 0xFFFF0000);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001676 slow_path = new (allocator) IntrinsicSlowPathARM64(invoke);
1677 codegen->AddSlowPath(slow_path);
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001678 __ B(ne, slow_path->GetEntryLabel());
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001679 }
1680
1681 if (start_at_zero) {
1682 // Start-index = 0.
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001683 Register tmp_reg = WRegisterFrom(locations->GetTemp(0));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001684 __ Mov(tmp_reg, 0);
1685 }
1686
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001687 codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path);
Roland Levillain42ad2882016-02-29 18:26:54 +00001688 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001689
1690 if (slow_path != nullptr) {
1691 __ Bind(slow_path->GetExitLabel());
1692 }
1693}
1694
1695void IntrinsicLocationsBuilderARM64::VisitStringIndexOf(HInvoke* invoke) {
1696 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001697 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001698 kIntrinsified);
1699 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1700 // best to align the inputs accordingly.
1701 InvokeRuntimeCallingConvention calling_convention;
1702 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1703 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1704 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt));
1705
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001706 // Need to send start_index=0.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001707 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
1708}
1709
1710void IntrinsicCodeGeneratorARM64::VisitStringIndexOf(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001711 GenerateVisitStringIndexOf(
1712 invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001713}
1714
1715void IntrinsicLocationsBuilderARM64::VisitStringIndexOfAfter(HInvoke* invoke) {
1716 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001717 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001718 kIntrinsified);
1719 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1720 // best to align the inputs accordingly.
1721 InvokeRuntimeCallingConvention calling_convention;
1722 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1723 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1724 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1725 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimInt));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001726}
1727
1728void IntrinsicCodeGeneratorARM64::VisitStringIndexOfAfter(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001729 GenerateVisitStringIndexOf(
1730 invoke, GetVIXLAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001731}
1732
Jeff Hao848f70a2014-01-15 13:49:50 -08001733void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromBytes(HInvoke* invoke) {
1734 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001735 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001736 kIntrinsified);
1737 InvokeRuntimeCallingConvention calling_convention;
1738 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1739 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1740 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1741 locations->SetInAt(3, LocationFrom(calling_convention.GetRegisterAt(3)));
1742 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
1743}
1744
1745void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromBytes(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001746 MacroAssembler* masm = GetVIXLAssembler();
Jeff Hao848f70a2014-01-15 13:49:50 -08001747 LocationSummary* locations = invoke->GetLocations();
1748
1749 Register byte_array = WRegisterFrom(locations->InAt(0));
1750 __ Cmp(byte_array, 0);
1751 SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
1752 codegen_->AddSlowPath(slow_path);
1753 __ B(eq, slow_path->GetEntryLabel());
1754
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001755 codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path);
Roland Levillainf969a202016-03-09 16:14:00 +00001756 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001757 __ Bind(slow_path->GetExitLabel());
1758}
1759
1760void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromChars(HInvoke* invoke) {
1761 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001762 LocationSummary::kCallOnMainOnly,
Jeff Hao848f70a2014-01-15 13:49:50 -08001763 kIntrinsified);
1764 InvokeRuntimeCallingConvention calling_convention;
1765 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1766 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1767 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1768 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
1769}
1770
1771void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromChars(HInvoke* invoke) {
Roland Levillaincc3839c2016-02-29 16:23:48 +00001772 // No need to emit code checking whether `locations->InAt(2)` is a null
1773 // pointer, as callers of the native method
1774 //
1775 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1776 //
1777 // all include a null check on `data` before calling that method.
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001778 codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc());
Roland Levillainf969a202016-03-09 16:14:00 +00001779 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001780}
1781
1782void IntrinsicLocationsBuilderARM64::VisitStringNewStringFromString(HInvoke* invoke) {
Jeff Hao848f70a2014-01-15 13:49:50 -08001783 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001784 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001785 kIntrinsified);
1786 InvokeRuntimeCallingConvention calling_convention;
1787 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
Jeff Hao848f70a2014-01-15 13:49:50 -08001788 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
1789}
1790
1791void IntrinsicCodeGeneratorARM64::VisitStringNewStringFromString(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001792 MacroAssembler* masm = GetVIXLAssembler();
Jeff Hao848f70a2014-01-15 13:49:50 -08001793 LocationSummary* locations = invoke->GetLocations();
1794
1795 Register string_to_copy = WRegisterFrom(locations->InAt(0));
1796 __ Cmp(string_to_copy, 0);
1797 SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
1798 codegen_->AddSlowPath(slow_path);
1799 __ B(eq, slow_path->GetEntryLabel());
1800
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001801 codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc(), slow_path);
Roland Levillainf969a202016-03-09 16:14:00 +00001802 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001803 __ Bind(slow_path->GetExitLabel());
1804}
1805
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001806static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1807 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1808 DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(0)->GetType()));
1809 DCHECK(Primitive::IsFloatingPointType(invoke->GetType()));
1810
1811 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001812 LocationSummary::kCallOnMainOnly,
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001813 kIntrinsified);
1814 InvokeRuntimeCallingConvention calling_convention;
1815
1816 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
1817 locations->SetOut(calling_convention.GetReturnLocation(invoke->GetType()));
1818}
1819
1820static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1821 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1822 DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(0)->GetType()));
1823 DCHECK(Primitive::IsFloatingPointType(invoke->InputAt(1)->GetType()));
1824 DCHECK(Primitive::IsFloatingPointType(invoke->GetType()));
1825
1826 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001827 LocationSummary::kCallOnMainOnly,
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001828 kIntrinsified);
1829 InvokeRuntimeCallingConvention calling_convention;
1830
1831 locations->SetInAt(0, LocationFrom(calling_convention.GetFpuRegisterAt(0)));
1832 locations->SetInAt(1, LocationFrom(calling_convention.GetFpuRegisterAt(1)));
1833 locations->SetOut(calling_convention.GetReturnLocation(invoke->GetType()));
1834}
1835
1836static void GenFPToFPCall(HInvoke* invoke,
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001837 CodeGeneratorARM64* codegen,
1838 QuickEntrypointEnum entry) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001839 codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc());
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001840}
1841
1842void IntrinsicLocationsBuilderARM64::VisitMathCos(HInvoke* invoke) {
1843 CreateFPToFPCallLocations(arena_, invoke);
1844}
1845
1846void IntrinsicCodeGeneratorARM64::VisitMathCos(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001847 GenFPToFPCall(invoke, codegen_, kQuickCos);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001848}
1849
1850void IntrinsicLocationsBuilderARM64::VisitMathSin(HInvoke* invoke) {
1851 CreateFPToFPCallLocations(arena_, invoke);
1852}
1853
1854void IntrinsicCodeGeneratorARM64::VisitMathSin(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001855 GenFPToFPCall(invoke, codegen_, kQuickSin);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001856}
1857
1858void IntrinsicLocationsBuilderARM64::VisitMathAcos(HInvoke* invoke) {
1859 CreateFPToFPCallLocations(arena_, invoke);
1860}
1861
1862void IntrinsicCodeGeneratorARM64::VisitMathAcos(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001863 GenFPToFPCall(invoke, codegen_, kQuickAcos);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001864}
1865
1866void IntrinsicLocationsBuilderARM64::VisitMathAsin(HInvoke* invoke) {
1867 CreateFPToFPCallLocations(arena_, invoke);
1868}
1869
1870void IntrinsicCodeGeneratorARM64::VisitMathAsin(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001871 GenFPToFPCall(invoke, codegen_, kQuickAsin);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001872}
1873
1874void IntrinsicLocationsBuilderARM64::VisitMathAtan(HInvoke* invoke) {
1875 CreateFPToFPCallLocations(arena_, invoke);
1876}
1877
1878void IntrinsicCodeGeneratorARM64::VisitMathAtan(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001879 GenFPToFPCall(invoke, codegen_, kQuickAtan);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001880}
1881
1882void IntrinsicLocationsBuilderARM64::VisitMathCbrt(HInvoke* invoke) {
1883 CreateFPToFPCallLocations(arena_, invoke);
1884}
1885
1886void IntrinsicCodeGeneratorARM64::VisitMathCbrt(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001887 GenFPToFPCall(invoke, codegen_, kQuickCbrt);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001888}
1889
1890void IntrinsicLocationsBuilderARM64::VisitMathCosh(HInvoke* invoke) {
1891 CreateFPToFPCallLocations(arena_, invoke);
1892}
1893
1894void IntrinsicCodeGeneratorARM64::VisitMathCosh(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001895 GenFPToFPCall(invoke, codegen_, kQuickCosh);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001896}
1897
1898void IntrinsicLocationsBuilderARM64::VisitMathExp(HInvoke* invoke) {
1899 CreateFPToFPCallLocations(arena_, invoke);
1900}
1901
1902void IntrinsicCodeGeneratorARM64::VisitMathExp(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001903 GenFPToFPCall(invoke, codegen_, kQuickExp);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001904}
1905
1906void IntrinsicLocationsBuilderARM64::VisitMathExpm1(HInvoke* invoke) {
1907 CreateFPToFPCallLocations(arena_, invoke);
1908}
1909
1910void IntrinsicCodeGeneratorARM64::VisitMathExpm1(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001911 GenFPToFPCall(invoke, codegen_, kQuickExpm1);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001912}
1913
1914void IntrinsicLocationsBuilderARM64::VisitMathLog(HInvoke* invoke) {
1915 CreateFPToFPCallLocations(arena_, invoke);
1916}
1917
1918void IntrinsicCodeGeneratorARM64::VisitMathLog(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001919 GenFPToFPCall(invoke, codegen_, kQuickLog);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001920}
1921
1922void IntrinsicLocationsBuilderARM64::VisitMathLog10(HInvoke* invoke) {
1923 CreateFPToFPCallLocations(arena_, invoke);
1924}
1925
1926void IntrinsicCodeGeneratorARM64::VisitMathLog10(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001927 GenFPToFPCall(invoke, codegen_, kQuickLog10);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001928}
1929
1930void IntrinsicLocationsBuilderARM64::VisitMathSinh(HInvoke* invoke) {
1931 CreateFPToFPCallLocations(arena_, invoke);
1932}
1933
1934void IntrinsicCodeGeneratorARM64::VisitMathSinh(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001935 GenFPToFPCall(invoke, codegen_, kQuickSinh);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001936}
1937
1938void IntrinsicLocationsBuilderARM64::VisitMathTan(HInvoke* invoke) {
1939 CreateFPToFPCallLocations(arena_, invoke);
1940}
1941
1942void IntrinsicCodeGeneratorARM64::VisitMathTan(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001943 GenFPToFPCall(invoke, codegen_, kQuickTan);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001944}
1945
1946void IntrinsicLocationsBuilderARM64::VisitMathTanh(HInvoke* invoke) {
1947 CreateFPToFPCallLocations(arena_, invoke);
1948}
1949
1950void IntrinsicCodeGeneratorARM64::VisitMathTanh(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001951 GenFPToFPCall(invoke, codegen_, kQuickTanh);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001952}
1953
1954void IntrinsicLocationsBuilderARM64::VisitMathAtan2(HInvoke* invoke) {
1955 CreateFPFPToFPCallLocations(arena_, invoke);
1956}
1957
1958void IntrinsicCodeGeneratorARM64::VisitMathAtan2(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001959 GenFPToFPCall(invoke, codegen_, kQuickAtan2);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001960}
1961
1962void IntrinsicLocationsBuilderARM64::VisitMathHypot(HInvoke* invoke) {
1963 CreateFPFPToFPCallLocations(arena_, invoke);
1964}
1965
1966void IntrinsicCodeGeneratorARM64::VisitMathHypot(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001967 GenFPToFPCall(invoke, codegen_, kQuickHypot);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001968}
1969
1970void IntrinsicLocationsBuilderARM64::VisitMathNextAfter(HInvoke* invoke) {
1971 CreateFPFPToFPCallLocations(arena_, invoke);
1972}
1973
1974void IntrinsicCodeGeneratorARM64::VisitMathNextAfter(HInvoke* invoke) {
Serban Constantinescu22f81d32016-02-18 16:06:31 +00001975 GenFPToFPCall(invoke, codegen_, kQuickNextAfter);
Anton Kirilov02fc24e2016-01-20 16:48:19 +00001976}
1977
Tim Zhang25abd6c2016-01-19 23:39:24 +08001978void IntrinsicLocationsBuilderARM64::VisitStringGetCharsNoCheck(HInvoke* invoke) {
1979 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1980 LocationSummary::kNoCall,
1981 kIntrinsified);
1982 locations->SetInAt(0, Location::RequiresRegister());
1983 locations->SetInAt(1, Location::RequiresRegister());
1984 locations->SetInAt(2, Location::RequiresRegister());
1985 locations->SetInAt(3, Location::RequiresRegister());
1986 locations->SetInAt(4, Location::RequiresRegister());
1987
1988 locations->AddTemp(Location::RequiresRegister());
1989 locations->AddTemp(Location::RequiresRegister());
Scott Wakelingdf109d92016-04-22 11:35:56 +01001990 locations->AddTemp(Location::RequiresRegister());
Tim Zhang25abd6c2016-01-19 23:39:24 +08001991}
1992
1993void IntrinsicCodeGeneratorARM64::VisitStringGetCharsNoCheck(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01001994 MacroAssembler* masm = GetVIXLAssembler();
Tim Zhang25abd6c2016-01-19 23:39:24 +08001995 LocationSummary* locations = invoke->GetLocations();
1996
1997 // Check assumption that sizeof(Char) is 2 (used in scaling below).
1998 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
1999 DCHECK_EQ(char_size, 2u);
2000
2001 // Location of data in char array buffer.
2002 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
2003
2004 // Location of char array data in string.
2005 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
2006
2007 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
2008 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
2009 Register srcObj = XRegisterFrom(locations->InAt(0));
2010 Register srcBegin = XRegisterFrom(locations->InAt(1));
2011 Register srcEnd = XRegisterFrom(locations->InAt(2));
2012 Register dstObj = XRegisterFrom(locations->InAt(3));
2013 Register dstBegin = XRegisterFrom(locations->InAt(4));
2014
2015 Register src_ptr = XRegisterFrom(locations->GetTemp(0));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002016 Register num_chr = XRegisterFrom(locations->GetTemp(1));
2017 Register tmp1 = XRegisterFrom(locations->GetTemp(2));
Tim Zhang25abd6c2016-01-19 23:39:24 +08002018
2019 UseScratchRegisterScope temps(masm);
2020 Register dst_ptr = temps.AcquireX();
Scott Wakelingdf109d92016-04-22 11:35:56 +01002021 Register tmp2 = temps.AcquireX();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002022
jessicahandojo05765752016-09-09 19:01:32 -07002023 vixl::aarch64::Label done;
2024 vixl::aarch64::Label compressed_string_loop;
2025 __ Sub(num_chr, srcEnd, srcBegin);
2026 // Early out for valid zero-length retrievals.
2027 __ Cbz(num_chr, &done);
Tim Zhang25abd6c2016-01-19 23:39:24 +08002028
Scott Wakelingdf109d92016-04-22 11:35:56 +01002029 // dst address start to copy to.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002030 __ Add(dst_ptr, dstObj, Operand(data_offset));
2031 __ Add(dst_ptr, dst_ptr, Operand(dstBegin, LSL, 1));
2032
jessicahandojo05765752016-09-09 19:01:32 -07002033 // src address to copy from.
2034 __ Add(src_ptr, srcObj, Operand(value_offset));
2035 vixl::aarch64::Label compressed_string_preloop;
2036 if (mirror::kUseStringCompression) {
2037 // Location of count in string.
2038 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
2039 // String's length.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01002040 __ Ldr(tmp2, MemOperand(srcObj, count_offset));
2041 __ Tbz(tmp2, 0, &compressed_string_preloop);
jessicahandojo05765752016-09-09 19:01:32 -07002042 }
2043 __ Add(src_ptr, src_ptr, Operand(srcBegin, LSL, 1));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002044
Tim Zhang25abd6c2016-01-19 23:39:24 +08002045 // Do the copy.
Scott Wakeling97c72b72016-06-24 16:19:36 +01002046 vixl::aarch64::Label loop;
Scott Wakeling97c72b72016-06-24 16:19:36 +01002047 vixl::aarch64::Label remainder;
Scott Wakelingdf109d92016-04-22 11:35:56 +01002048
Scott Wakelingdf109d92016-04-22 11:35:56 +01002049 // Save repairing the value of num_chr on the < 8 character path.
2050 __ Subs(tmp1, num_chr, 8);
2051 __ B(lt, &remainder);
2052
2053 // Keep the result of the earlier subs, we are going to fetch at least 8 characters.
2054 __ Mov(num_chr, tmp1);
2055
2056 // Main loop used for longer fetches loads and stores 8x16-bit characters at a time.
2057 // (Unaligned addresses are acceptable here and not worth inlining extra code to rectify.)
Tim Zhang25abd6c2016-01-19 23:39:24 +08002058 __ Bind(&loop);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002059 __ Ldp(tmp1, tmp2, MemOperand(src_ptr, char_size * 8, PostIndex));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002060 __ Subs(num_chr, num_chr, 8);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002061 __ Stp(tmp1, tmp2, MemOperand(dst_ptr, char_size * 8, PostIndex));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002062 __ B(ge, &loop);
2063
2064 __ Adds(num_chr, num_chr, 8);
2065 __ B(eq, &done);
2066
2067 // Main loop for < 8 character case and remainder handling. Loads and stores one
2068 // 16-bit Java character at a time.
2069 __ Bind(&remainder);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002070 __ Ldrh(tmp1, MemOperand(src_ptr, char_size, PostIndex));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002071 __ Subs(num_chr, num_chr, 1);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002072 __ Strh(tmp1, MemOperand(dst_ptr, char_size, PostIndex));
Scott Wakelingdf109d92016-04-22 11:35:56 +01002073 __ B(gt, &remainder);
jessicahandojo05765752016-09-09 19:01:32 -07002074 __ B(&done);
2075
2076 if (mirror::kUseStringCompression) {
2077 const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte);
2078 DCHECK_EQ(c_char_size, 1u);
2079 __ Bind(&compressed_string_preloop);
2080 __ Add(src_ptr, src_ptr, Operand(srcBegin));
2081 // Copy loop for compressed src, copying 1 character (8-bit) to (16-bit) at a time.
2082 __ Bind(&compressed_string_loop);
2083 __ Ldrb(tmp1, MemOperand(src_ptr, c_char_size, PostIndex));
2084 __ Strh(tmp1, MemOperand(dst_ptr, char_size, PostIndex));
2085 __ Subs(num_chr, num_chr, Operand(1));
2086 __ B(gt, &compressed_string_loop);
2087 }
Scott Wakelingdf109d92016-04-22 11:35:56 +01002088
Tim Zhang25abd6c2016-01-19 23:39:24 +08002089 __ Bind(&done);
2090}
2091
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002092// Mirrors ARRAYCOPY_SHORT_CHAR_ARRAY_THRESHOLD in libcore, so we can choose to use the native
2093// implementation there for longer copy lengths.
donghui.baic2ec9ad2016-03-10 14:02:55 +08002094static constexpr int32_t kSystemArrayCopyCharThreshold = 32;
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002095
2096static void SetSystemArrayCopyLocationRequires(LocationSummary* locations,
2097 uint32_t at,
2098 HInstruction* input) {
2099 HIntConstant* const_input = input->AsIntConstant();
Scott Wakeling97c72b72016-06-24 16:19:36 +01002100 if (const_input != nullptr && !vixl::aarch64::Assembler::IsImmAddSub(const_input->GetValue())) {
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002101 locations->SetInAt(at, Location::RequiresRegister());
2102 } else {
2103 locations->SetInAt(at, Location::RegisterOrConstant(input));
2104 }
2105}
2106
2107void IntrinsicLocationsBuilderARM64::VisitSystemArrayCopyChar(HInvoke* invoke) {
2108 // Check to see if we have known failures that will cause us to have to bail out
2109 // to the runtime, and just generate the runtime call directly.
2110 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
2111 HIntConstant* dst_pos = invoke->InputAt(3)->AsIntConstant();
2112
2113 // The positions must be non-negative.
2114 if ((src_pos != nullptr && src_pos->GetValue() < 0) ||
2115 (dst_pos != nullptr && dst_pos->GetValue() < 0)) {
2116 // We will have to fail anyways.
2117 return;
2118 }
2119
2120 // The length must be >= 0 and not so long that we would (currently) prefer libcore's
2121 // native implementation.
2122 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
2123 if (length != nullptr) {
2124 int32_t len = length->GetValue();
donghui.baic2ec9ad2016-03-10 14:02:55 +08002125 if (len < 0 || len > kSystemArrayCopyCharThreshold) {
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002126 // Just call as normal.
2127 return;
2128 }
2129 }
2130
2131 ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena();
2132 LocationSummary* locations = new (allocator) LocationSummary(invoke,
2133 LocationSummary::kCallOnSlowPath,
2134 kIntrinsified);
2135 // arraycopy(char[] src, int src_pos, char[] dst, int dst_pos, int length).
2136 locations->SetInAt(0, Location::RequiresRegister());
2137 SetSystemArrayCopyLocationRequires(locations, 1, invoke->InputAt(1));
2138 locations->SetInAt(2, Location::RequiresRegister());
2139 SetSystemArrayCopyLocationRequires(locations, 3, invoke->InputAt(3));
2140 SetSystemArrayCopyLocationRequires(locations, 4, invoke->InputAt(4));
2141
2142 locations->AddTemp(Location::RequiresRegister());
2143 locations->AddTemp(Location::RequiresRegister());
2144 locations->AddTemp(Location::RequiresRegister());
2145}
2146
Scott Wakeling97c72b72016-06-24 16:19:36 +01002147static void CheckSystemArrayCopyPosition(MacroAssembler* masm,
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002148 const Location& pos,
2149 const Register& input,
2150 const Location& length,
2151 SlowPathCodeARM64* slow_path,
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002152 const Register& temp,
2153 bool length_is_input_length = false) {
2154 const int32_t length_offset = mirror::Array::LengthOffset().Int32Value();
2155 if (pos.IsConstant()) {
2156 int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue();
2157 if (pos_const == 0) {
2158 if (!length_is_input_length) {
2159 // Check that length(input) >= length.
2160 __ Ldr(temp, MemOperand(input, length_offset));
2161 __ Cmp(temp, OperandFrom(length, Primitive::kPrimInt));
2162 __ B(slow_path->GetEntryLabel(), lt);
2163 }
2164 } else {
2165 // Check that length(input) >= pos.
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01002166 __ Ldr(temp, MemOperand(input, length_offset));
2167 __ Subs(temp, temp, pos_const);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002168 __ B(slow_path->GetEntryLabel(), lt);
2169
2170 // Check that (length(input) - pos) >= length.
2171 __ Cmp(temp, OperandFrom(length, Primitive::kPrimInt));
2172 __ B(slow_path->GetEntryLabel(), lt);
2173 }
2174 } else if (length_is_input_length) {
2175 // The only way the copy can succeed is if pos is zero.
2176 __ Cbnz(WRegisterFrom(pos), slow_path->GetEntryLabel());
2177 } else {
2178 // Check that pos >= 0.
2179 Register pos_reg = WRegisterFrom(pos);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002180 __ Tbnz(pos_reg, pos_reg.GetSizeInBits() - 1, slow_path->GetEntryLabel());
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002181
2182 // Check that pos <= length(input) && (length(input) - pos) >= length.
2183 __ Ldr(temp, MemOperand(input, length_offset));
2184 __ Subs(temp, temp, pos_reg);
2185 // Ccmp if length(input) >= pos, else definitely bail to slow path (N!=V == lt).
2186 __ Ccmp(temp, OperandFrom(length, Primitive::kPrimInt), NFlag, ge);
2187 __ B(slow_path->GetEntryLabel(), lt);
2188 }
2189}
2190
2191// Compute base source address, base destination address, and end source address
2192// for System.arraycopy* intrinsics.
Scott Wakeling97c72b72016-06-24 16:19:36 +01002193static void GenSystemArrayCopyAddresses(MacroAssembler* masm,
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002194 Primitive::Type type,
2195 const Register& src,
2196 const Location& src_pos,
2197 const Register& dst,
2198 const Location& dst_pos,
2199 const Location& copy_length,
2200 const Register& src_base,
2201 const Register& dst_base,
2202 const Register& src_end) {
2203 DCHECK(type == Primitive::kPrimNot || type == Primitive::kPrimChar)
Roland Levillainebea3d22016-04-12 15:42:57 +01002204 << "Unexpected element type: " << type;
2205 const int32_t element_size = Primitive::ComponentSize(type);
2206 const int32_t element_size_shift = Primitive::ComponentSizeShift(type);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002207
Roland Levillainebea3d22016-04-12 15:42:57 +01002208 uint32_t data_offset = mirror::Array::DataOffset(element_size).Uint32Value();
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002209 if (src_pos.IsConstant()) {
2210 int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
Roland Levillainebea3d22016-04-12 15:42:57 +01002211 __ Add(src_base, src, element_size * constant + data_offset);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002212 } else {
Roland Levillainebea3d22016-04-12 15:42:57 +01002213 __ Add(src_base, src, data_offset);
2214 __ Add(src_base, src_base, Operand(XRegisterFrom(src_pos), LSL, element_size_shift));
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002215 }
2216
2217 if (dst_pos.IsConstant()) {
2218 int32_t constant = dst_pos.GetConstant()->AsIntConstant()->GetValue();
Roland Levillainebea3d22016-04-12 15:42:57 +01002219 __ Add(dst_base, dst, element_size * constant + data_offset);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002220 } else {
Roland Levillainebea3d22016-04-12 15:42:57 +01002221 __ Add(dst_base, dst, data_offset);
2222 __ Add(dst_base, dst_base, Operand(XRegisterFrom(dst_pos), LSL, element_size_shift));
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002223 }
2224
2225 if (copy_length.IsConstant()) {
2226 int32_t constant = copy_length.GetConstant()->AsIntConstant()->GetValue();
Roland Levillainebea3d22016-04-12 15:42:57 +01002227 __ Add(src_end, src_base, element_size * constant);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002228 } else {
Roland Levillainebea3d22016-04-12 15:42:57 +01002229 __ Add(src_end, src_base, Operand(XRegisterFrom(copy_length), LSL, element_size_shift));
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002230 }
2231}
2232
2233void IntrinsicCodeGeneratorARM64::VisitSystemArrayCopyChar(HInvoke* invoke) {
Scott Wakeling97c72b72016-06-24 16:19:36 +01002234 MacroAssembler* masm = GetVIXLAssembler();
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002235 LocationSummary* locations = invoke->GetLocations();
2236 Register src = XRegisterFrom(locations->InAt(0));
2237 Location src_pos = locations->InAt(1);
2238 Register dst = XRegisterFrom(locations->InAt(2));
2239 Location dst_pos = locations->InAt(3);
2240 Location length = locations->InAt(4);
2241
2242 SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
2243 codegen_->AddSlowPath(slow_path);
2244
2245 // If source and destination are the same, take the slow path. Overlapping copy regions must be
2246 // copied in reverse and we can't know in all cases if it's needed.
2247 __ Cmp(src, dst);
2248 __ B(slow_path->GetEntryLabel(), eq);
2249
2250 // Bail out if the source is null.
2251 __ Cbz(src, slow_path->GetEntryLabel());
2252
2253 // Bail out if the destination is null.
2254 __ Cbz(dst, slow_path->GetEntryLabel());
2255
2256 if (!length.IsConstant()) {
Vladimir Markoc5646202016-11-28 16:03:15 +00002257 // Merge the following two comparisons into one:
2258 // If the length is negative, bail out (delegate to libcore's native implementation).
2259 // If the length > 32 then (currently) prefer libcore's native implementation.
donghui.baic2ec9ad2016-03-10 14:02:55 +08002260 __ Cmp(WRegisterFrom(length), kSystemArrayCopyCharThreshold);
Vladimir Markoc5646202016-11-28 16:03:15 +00002261 __ B(slow_path->GetEntryLabel(), hi);
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002262 } else {
2263 // We have already checked in the LocationsBuilder for the constant case.
2264 DCHECK_GE(length.GetConstant()->AsIntConstant()->GetValue(), 0);
2265 DCHECK_LE(length.GetConstant()->AsIntConstant()->GetValue(), 32);
2266 }
2267
2268 Register src_curr_addr = WRegisterFrom(locations->GetTemp(0));
2269 Register dst_curr_addr = WRegisterFrom(locations->GetTemp(1));
2270 Register src_stop_addr = WRegisterFrom(locations->GetTemp(2));
2271
2272 CheckSystemArrayCopyPosition(masm,
2273 src_pos,
2274 src,
2275 length,
2276 slow_path,
2277 src_curr_addr,
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002278 false);
2279
2280 CheckSystemArrayCopyPosition(masm,
2281 dst_pos,
2282 dst,
2283 length,
2284 slow_path,
2285 src_curr_addr,
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002286 false);
2287
2288 src_curr_addr = src_curr_addr.X();
2289 dst_curr_addr = dst_curr_addr.X();
2290 src_stop_addr = src_stop_addr.X();
2291
2292 GenSystemArrayCopyAddresses(masm,
2293 Primitive::kPrimChar,
2294 src,
2295 src_pos,
2296 dst,
2297 dst_pos,
2298 length,
2299 src_curr_addr,
2300 dst_curr_addr,
2301 src_stop_addr);
2302
2303 // Iterate over the arrays and do a raw copy of the chars.
2304 const int32_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
2305 UseScratchRegisterScope temps(masm);
2306 Register tmp = temps.AcquireW();
Scott Wakeling97c72b72016-06-24 16:19:36 +01002307 vixl::aarch64::Label loop, done;
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002308 __ Bind(&loop);
2309 __ Cmp(src_curr_addr, src_stop_addr);
2310 __ B(&done, eq);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002311 __ Ldrh(tmp, MemOperand(src_curr_addr, char_size, PostIndex));
2312 __ Strh(tmp, MemOperand(dst_curr_addr, char_size, PostIndex));
Scott Wakelingd3d0da52016-02-29 15:17:20 +00002313 __ B(&loop);
2314 __ Bind(&done);
2315
2316 __ Bind(slow_path->GetExitLabel());
2317}
2318
donghui.baic2ec9ad2016-03-10 14:02:55 +08002319// We can choose to use the native implementation there for longer copy lengths.
2320static constexpr int32_t kSystemArrayCopyThreshold = 128;
2321
2322// CodeGenerator::CreateSystemArrayCopyLocationSummary use three temporary registers.
2323// We want to use two temporary registers in order to reduce the register pressure in arm64.
2324// So we don't use the CodeGenerator::CreateSystemArrayCopyLocationSummary.
2325void IntrinsicLocationsBuilderARM64::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01002326 // The only read barrier implementation supporting the
2327 // SystemArrayCopy intrinsic is the Baker-style read barriers.
2328 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
Roland Levillain3d312422016-06-23 13:53:42 +01002329 return;
2330 }
2331
donghui.baic2ec9ad2016-03-10 14:02:55 +08002332 // Check to see if we have known failures that will cause us to have to bail out
2333 // to the runtime, and just generate the runtime call directly.
2334 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
2335 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
2336
2337 // The positions must be non-negative.
2338 if ((src_pos != nullptr && src_pos->GetValue() < 0) ||
2339 (dest_pos != nullptr && dest_pos->GetValue() < 0)) {
2340 // We will have to fail anyways.
2341 return;
2342 }
2343
2344 // The length must be >= 0.
2345 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
2346 if (length != nullptr) {
2347 int32_t len = length->GetValue();
2348 if (len < 0 || len >= kSystemArrayCopyThreshold) {
2349 // Just call as normal.
2350 return;
2351 }
2352 }
2353
2354 SystemArrayCopyOptimizations optimizations(invoke);
2355
2356 if (optimizations.GetDestinationIsSource()) {
2357 if (src_pos != nullptr && dest_pos != nullptr && src_pos->GetValue() < dest_pos->GetValue()) {
2358 // We only support backward copying if source and destination are the same.
2359 return;
2360 }
2361 }
2362
2363 if (optimizations.GetDestinationIsPrimitiveArray() || optimizations.GetSourceIsPrimitiveArray()) {
2364 // We currently don't intrinsify primitive copying.
2365 return;
2366 }
2367
2368 ArenaAllocator* allocator = invoke->GetBlock()->GetGraph()->GetArena();
2369 LocationSummary* locations = new (allocator) LocationSummary(invoke,
2370 LocationSummary::kCallOnSlowPath,
2371 kIntrinsified);
2372 // arraycopy(Object src, int src_pos, Object dest, int dest_pos, int length).
2373 locations->SetInAt(0, Location::RequiresRegister());
2374 SetSystemArrayCopyLocationRequires(locations, 1, invoke->InputAt(1));
2375 locations->SetInAt(2, Location::RequiresRegister());
2376 SetSystemArrayCopyLocationRequires(locations, 3, invoke->InputAt(3));
2377 SetSystemArrayCopyLocationRequires(locations, 4, invoke->InputAt(4));
2378
2379 locations->AddTemp(Location::RequiresRegister());
2380 locations->AddTemp(Location::RequiresRegister());
Roland Levillain0b671c02016-08-19 12:02:34 +01002381 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2382 // Temporary register IP0, obtained from the VIXL scratch register
2383 // pool, cannot be used in ReadBarrierSystemArrayCopySlowPathARM64
2384 // (because that register is clobbered by ReadBarrierMarkRegX
Roland Levillain54f869e2017-03-06 13:54:11 +00002385 // entry points). It cannot be used in calls to
2386 // CodeGeneratorARM64::GenerateFieldLoadWithBakerReadBarrier
2387 // either. For these reasons, get a third extra temporary register
2388 // from the register allocator.
Roland Levillain0b671c02016-08-19 12:02:34 +01002389 locations->AddTemp(Location::RequiresRegister());
Roland Levillain54f869e2017-03-06 13:54:11 +00002390 } else {
2391 // Cases other than Baker read barriers: the third temporary will
2392 // be acquired from the VIXL scratch register pool.
Roland Levillain0b671c02016-08-19 12:02:34 +01002393 }
donghui.baic2ec9ad2016-03-10 14:02:55 +08002394}
2395
2396void IntrinsicCodeGeneratorARM64::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01002397 // The only read barrier implementation supporting the
2398 // SystemArrayCopy intrinsic is the Baker-style read barriers.
2399 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
Roland Levillain3d312422016-06-23 13:53:42 +01002400
Scott Wakeling97c72b72016-06-24 16:19:36 +01002401 MacroAssembler* masm = GetVIXLAssembler();
donghui.baic2ec9ad2016-03-10 14:02:55 +08002402 LocationSummary* locations = invoke->GetLocations();
2403
2404 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2405 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2406 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2407 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01002408 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
donghui.baic2ec9ad2016-03-10 14:02:55 +08002409
2410 Register src = XRegisterFrom(locations->InAt(0));
2411 Location src_pos = locations->InAt(1);
2412 Register dest = XRegisterFrom(locations->InAt(2));
2413 Location dest_pos = locations->InAt(3);
2414 Location length = locations->InAt(4);
2415 Register temp1 = WRegisterFrom(locations->GetTemp(0));
Roland Levillain0b671c02016-08-19 12:02:34 +01002416 Location temp1_loc = LocationFrom(temp1);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002417 Register temp2 = WRegisterFrom(locations->GetTemp(1));
Roland Levillain0b671c02016-08-19 12:02:34 +01002418 Location temp2_loc = LocationFrom(temp2);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002419
Roland Levillain0b671c02016-08-19 12:02:34 +01002420 SlowPathCodeARM64* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
2421 codegen_->AddSlowPath(intrinsic_slow_path);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002422
Scott Wakeling97c72b72016-06-24 16:19:36 +01002423 vixl::aarch64::Label conditions_on_positions_validated;
donghui.baic2ec9ad2016-03-10 14:02:55 +08002424 SystemArrayCopyOptimizations optimizations(invoke);
2425
donghui.baic2ec9ad2016-03-10 14:02:55 +08002426 // If source and destination are the same, we go to slow path if we need to do
2427 // forward copying.
2428 if (src_pos.IsConstant()) {
2429 int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
2430 if (dest_pos.IsConstant()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01002431 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
2432 if (optimizations.GetDestinationIsSource()) {
2433 // Checked when building locations.
2434 DCHECK_GE(src_pos_constant, dest_pos_constant);
2435 } else if (src_pos_constant < dest_pos_constant) {
2436 __ Cmp(src, dest);
Roland Levillain0b671c02016-08-19 12:02:34 +01002437 __ B(intrinsic_slow_path->GetEntryLabel(), eq);
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01002438 }
donghui.baic2ec9ad2016-03-10 14:02:55 +08002439 // Checked when building locations.
2440 DCHECK(!optimizations.GetDestinationIsSource()
2441 || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue()));
2442 } else {
2443 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01002444 __ Cmp(src, dest);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002445 __ B(&conditions_on_positions_validated, ne);
2446 }
2447 __ Cmp(WRegisterFrom(dest_pos), src_pos_constant);
Roland Levillain0b671c02016-08-19 12:02:34 +01002448 __ B(intrinsic_slow_path->GetEntryLabel(), gt);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002449 }
2450 } else {
2451 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01002452 __ Cmp(src, dest);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002453 __ B(&conditions_on_positions_validated, ne);
2454 }
2455 __ Cmp(RegisterFrom(src_pos, invoke->InputAt(1)->GetType()),
2456 OperandFrom(dest_pos, invoke->InputAt(3)->GetType()));
Roland Levillain0b671c02016-08-19 12:02:34 +01002457 __ B(intrinsic_slow_path->GetEntryLabel(), lt);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002458 }
2459
2460 __ Bind(&conditions_on_positions_validated);
2461
2462 if (!optimizations.GetSourceIsNotNull()) {
2463 // Bail out if the source is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01002464 __ Cbz(src, intrinsic_slow_path->GetEntryLabel());
donghui.baic2ec9ad2016-03-10 14:02:55 +08002465 }
2466
2467 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
2468 // Bail out if the destination is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01002469 __ Cbz(dest, intrinsic_slow_path->GetEntryLabel());
donghui.baic2ec9ad2016-03-10 14:02:55 +08002470 }
2471
2472 // We have already checked in the LocationsBuilder for the constant case.
2473 if (!length.IsConstant() &&
2474 !optimizations.GetCountIsSourceLength() &&
2475 !optimizations.GetCountIsDestinationLength()) {
Vladimir Markoc5646202016-11-28 16:03:15 +00002476 // Merge the following two comparisons into one:
2477 // If the length is negative, bail out (delegate to libcore's native implementation).
2478 // If the length >= 128 then (currently) prefer native implementation.
donghui.baic2ec9ad2016-03-10 14:02:55 +08002479 __ Cmp(WRegisterFrom(length), kSystemArrayCopyThreshold);
Vladimir Markoc5646202016-11-28 16:03:15 +00002480 __ B(intrinsic_slow_path->GetEntryLabel(), hs);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002481 }
2482 // Validity checks: source.
2483 CheckSystemArrayCopyPosition(masm,
2484 src_pos,
2485 src,
2486 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01002487 intrinsic_slow_path,
donghui.baic2ec9ad2016-03-10 14:02:55 +08002488 temp1,
donghui.baic2ec9ad2016-03-10 14:02:55 +08002489 optimizations.GetCountIsSourceLength());
2490
2491 // Validity checks: dest.
2492 CheckSystemArrayCopyPosition(masm,
2493 dest_pos,
2494 dest,
2495 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01002496 intrinsic_slow_path,
donghui.baic2ec9ad2016-03-10 14:02:55 +08002497 temp1,
donghui.baic2ec9ad2016-03-10 14:02:55 +08002498 optimizations.GetCountIsDestinationLength());
2499 {
2500 // We use a block to end the scratch scope before the write barrier, thus
2501 // freeing the temporary registers so they can be used in `MarkGCCard`.
2502 UseScratchRegisterScope temps(masm);
Roland Levillain54f869e2017-03-06 13:54:11 +00002503 Register temp3;
2504 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2505 temp3 = WRegisterFrom(locations->GetTemp(2));
2506 } else {
2507 temp3 = temps.AcquireW();
2508 }
Roland Levillain0b671c02016-08-19 12:02:34 +01002509
donghui.baic2ec9ad2016-03-10 14:02:55 +08002510 if (!optimizations.GetDoesNotNeedTypeCheck()) {
2511 // Check whether all elements of the source array are assignable to the component
2512 // type of the destination array. We do two checks: the classes are the same,
2513 // or the destination is Object[]. If none of these checks succeed, we go to the
2514 // slow path.
donghui.baic2ec9ad2016-03-10 14:02:55 +08002515
Roland Levillain0b671c02016-08-19 12:02:34 +01002516 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2517 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2518 // /* HeapReference<Class> */ temp1 = src->klass_
2519 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2520 temp1_loc,
2521 src.W(),
2522 class_offset,
2523 temp2,
2524 /* needs_null_check */ false,
2525 /* use_load_acquire */ false);
2526 // Bail out if the source is not a non primitive array.
2527 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2528 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2529 temp1_loc,
2530 temp1,
2531 component_offset,
2532 temp2,
2533 /* needs_null_check */ false,
2534 /* use_load_acquire */ false);
2535 __ Cbz(temp1, intrinsic_slow_path->GetEntryLabel());
2536 // If heap poisoning is enabled, `temp1` has been unpoisoned
2537 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2538 // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_);
2539 __ Ldrh(temp1, HeapOperand(temp1, primitive_offset));
2540 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2541 __ Cbnz(temp1, intrinsic_slow_path->GetEntryLabel());
donghui.baic2ec9ad2016-03-10 14:02:55 +08002542 }
Roland Levillain0b671c02016-08-19 12:02:34 +01002543
2544 // /* HeapReference<Class> */ temp1 = dest->klass_
2545 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2546 temp1_loc,
2547 dest.W(),
2548 class_offset,
2549 temp2,
2550 /* needs_null_check */ false,
2551 /* use_load_acquire */ false);
2552
2553 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
2554 // Bail out if the destination is not a non primitive array.
2555 //
2556 // Register `temp1` is not trashed by the read barrier emitted
2557 // by GenerateFieldLoadWithBakerReadBarrier below, as that
2558 // method produces a call to a ReadBarrierMarkRegX entry point,
2559 // which saves all potentially live registers, including
2560 // temporaries such a `temp1`.
2561 // /* HeapReference<Class> */ temp2 = temp1->component_type_
2562 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2563 temp2_loc,
2564 temp1,
2565 component_offset,
2566 temp3,
2567 /* needs_null_check */ false,
2568 /* use_load_acquire */ false);
2569 __ Cbz(temp2, intrinsic_slow_path->GetEntryLabel());
2570 // If heap poisoning is enabled, `temp2` has been unpoisoned
2571 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2572 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
2573 __ Ldrh(temp2, HeapOperand(temp2, primitive_offset));
2574 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2575 __ Cbnz(temp2, intrinsic_slow_path->GetEntryLabel());
2576 }
2577
2578 // For the same reason given earlier, `temp1` is not trashed by the
2579 // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below.
2580 // /* HeapReference<Class> */ temp2 = src->klass_
2581 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2582 temp2_loc,
2583 src.W(),
2584 class_offset,
2585 temp3,
2586 /* needs_null_check */ false,
2587 /* use_load_acquire */ false);
2588 // Note: if heap poisoning is on, we are comparing two unpoisoned references here.
2589 __ Cmp(temp1, temp2);
2590
2591 if (optimizations.GetDestinationIsTypedObjectArray()) {
2592 vixl::aarch64::Label do_copy;
2593 __ B(&do_copy, eq);
2594 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2595 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2596 temp1_loc,
2597 temp1,
2598 component_offset,
2599 temp2,
2600 /* needs_null_check */ false,
2601 /* use_load_acquire */ false);
2602 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2603 // We do not need to emit a read barrier for the following
2604 // heap reference load, as `temp1` is only used in a
2605 // comparison with null below, and this reference is not
2606 // kept afterwards.
2607 __ Ldr(temp1, HeapOperand(temp1, super_offset));
2608 __ Cbnz(temp1, intrinsic_slow_path->GetEntryLabel());
2609 __ Bind(&do_copy);
2610 } else {
2611 __ B(intrinsic_slow_path->GetEntryLabel(), ne);
2612 }
donghui.baic2ec9ad2016-03-10 14:02:55 +08002613 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01002614 // Non read barrier code.
2615
2616 // /* HeapReference<Class> */ temp1 = dest->klass_
2617 __ Ldr(temp1, MemOperand(dest, class_offset));
2618 // /* HeapReference<Class> */ temp2 = src->klass_
2619 __ Ldr(temp2, MemOperand(src, class_offset));
2620 bool did_unpoison = false;
2621 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
2622 !optimizations.GetSourceIsNonPrimitiveArray()) {
2623 // One or two of the references need to be unpoisoned. Unpoison them
2624 // both to make the identity check valid.
2625 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1);
2626 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp2);
2627 did_unpoison = true;
2628 }
2629
2630 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
2631 // Bail out if the destination is not a non primitive array.
2632 // /* HeapReference<Class> */ temp3 = temp1->component_type_
2633 __ Ldr(temp3, HeapOperand(temp1, component_offset));
2634 __ Cbz(temp3, intrinsic_slow_path->GetEntryLabel());
2635 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp3);
2636 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
2637 __ Ldrh(temp3, HeapOperand(temp3, primitive_offset));
2638 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2639 __ Cbnz(temp3, intrinsic_slow_path->GetEntryLabel());
2640 }
2641
2642 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2643 // Bail out if the source is not a non primitive array.
2644 // /* HeapReference<Class> */ temp3 = temp2->component_type_
2645 __ Ldr(temp3, HeapOperand(temp2, component_offset));
2646 __ Cbz(temp3, intrinsic_slow_path->GetEntryLabel());
2647 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp3);
2648 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
2649 __ Ldrh(temp3, HeapOperand(temp3, primitive_offset));
2650 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
2651 __ Cbnz(temp3, intrinsic_slow_path->GetEntryLabel());
2652 }
2653
2654 __ Cmp(temp1, temp2);
2655
2656 if (optimizations.GetDestinationIsTypedObjectArray()) {
2657 vixl::aarch64::Label do_copy;
2658 __ B(&do_copy, eq);
2659 if (!did_unpoison) {
2660 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1);
2661 }
2662 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2663 __ Ldr(temp1, HeapOperand(temp1, component_offset));
2664 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1);
2665 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2666 __ Ldr(temp1, HeapOperand(temp1, super_offset));
2667 // No need to unpoison the result, we're comparing against null.
2668 __ Cbnz(temp1, intrinsic_slow_path->GetEntryLabel());
2669 __ Bind(&do_copy);
2670 } else {
2671 __ B(intrinsic_slow_path->GetEntryLabel(), ne);
2672 }
donghui.baic2ec9ad2016-03-10 14:02:55 +08002673 }
2674 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2675 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
2676 // Bail out if the source is not a non primitive array.
Roland Levillain0b671c02016-08-19 12:02:34 +01002677 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2678 // /* HeapReference<Class> */ temp1 = src->klass_
2679 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2680 temp1_loc,
2681 src.W(),
2682 class_offset,
2683 temp2,
2684 /* needs_null_check */ false,
2685 /* use_load_acquire */ false);
2686 // /* HeapReference<Class> */ temp2 = temp1->component_type_
2687 codegen_->GenerateFieldLoadWithBakerReadBarrier(invoke,
2688 temp2_loc,
2689 temp1,
2690 component_offset,
2691 temp3,
2692 /* needs_null_check */ false,
2693 /* use_load_acquire */ false);
2694 __ Cbz(temp2, intrinsic_slow_path->GetEntryLabel());
2695 // If heap poisoning is enabled, `temp2` has been unpoisoned
2696 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2697 } else {
2698 // /* HeapReference<Class> */ temp1 = src->klass_
2699 __ Ldr(temp1, HeapOperand(src.W(), class_offset));
2700 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp1);
2701 // /* HeapReference<Class> */ temp2 = temp1->component_type_
2702 __ Ldr(temp2, HeapOperand(temp1, component_offset));
2703 __ Cbz(temp2, intrinsic_slow_path->GetEntryLabel());
2704 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(temp2);
2705 }
2706 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
2707 __ Ldrh(temp2, HeapOperand(temp2, primitive_offset));
donghui.baic2ec9ad2016-03-10 14:02:55 +08002708 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
Roland Levillain0b671c02016-08-19 12:02:34 +01002709 __ Cbnz(temp2, intrinsic_slow_path->GetEntryLabel());
donghui.baic2ec9ad2016-03-10 14:02:55 +08002710 }
2711
2712 Register src_curr_addr = temp1.X();
2713 Register dst_curr_addr = temp2.X();
Roland Levillain54f869e2017-03-06 13:54:11 +00002714 Register src_stop_addr = temp3.X();
donghui.baic2ec9ad2016-03-10 14:02:55 +08002715
2716 GenSystemArrayCopyAddresses(masm,
2717 Primitive::kPrimNot,
2718 src,
2719 src_pos,
2720 dest,
2721 dest_pos,
2722 length,
2723 src_curr_addr,
2724 dst_curr_addr,
2725 src_stop_addr);
2726
donghui.baic2ec9ad2016-03-10 14:02:55 +08002727 const int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
Roland Levillain0b671c02016-08-19 12:02:34 +01002728
2729 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
Roland Levillainba650a42017-03-06 13:52:32 +00002730 // TODO: Also convert this intrinsic to the IsGcMarking strategy?
2731
Roland Levillain0b671c02016-08-19 12:02:34 +01002732 // SystemArrayCopy implementation for Baker read barriers (see
2733 // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier):
2734 //
2735 // if (src_ptr != end_ptr) {
2736 // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState();
2737 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -07002738 // bool is_gray = (rb_state == ReadBarrier::GrayState());
Roland Levillain0b671c02016-08-19 12:02:34 +01002739 // if (is_gray) {
2740 // // Slow-path copy.
2741 // do {
2742 // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++)));
2743 // } while (src_ptr != end_ptr)
2744 // } else {
2745 // // Fast-path copy.
2746 // do {
2747 // *dest_ptr++ = *src_ptr++;
2748 // } while (src_ptr != end_ptr)
2749 // }
2750 // }
2751
2752 vixl::aarch64::Label loop, done;
2753
2754 // Don't enter copy loop if `length == 0`.
2755 __ Cmp(src_curr_addr, src_stop_addr);
2756 __ B(&done, eq);
2757
Roland Levillain0b671c02016-08-19 12:02:34 +01002758 // Make sure `tmp` is not IP0, as it is clobbered by
2759 // ReadBarrierMarkRegX entry points in
2760 // ReadBarrierSystemArrayCopySlowPathARM64.
Roland Levillain54f869e2017-03-06 13:54:11 +00002761 temps.Exclude(ip0);
2762 Register tmp = temps.AcquireW();
Roland Levillain0b671c02016-08-19 12:02:34 +01002763 DCHECK_NE(LocationFrom(tmp).reg(), IP0);
2764
2765 // /* int32_t */ monitor = src->monitor_
2766 __ Ldr(tmp, HeapOperand(src.W(), monitor_offset));
2767 // /* LockWord */ lock_word = LockWord(monitor)
2768 static_assert(sizeof(LockWord) == sizeof(int32_t),
2769 "art::LockWord and int32_t have different sizes.");
2770
2771 // Introduce a dependency on the lock_word including rb_state,
2772 // to prevent load-load reordering, and without using
2773 // a memory barrier (which would be more expensive).
2774 // `src` is unchanged by this operation, but its value now depends
2775 // on `tmp`.
2776 __ Add(src.X(), src.X(), Operand(tmp.X(), LSR, 32));
2777
2778 // Slow path used to copy array when `src` is gray.
2779 SlowPathCodeARM64* read_barrier_slow_path =
2780 new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARM64(invoke, LocationFrom(tmp));
2781 codegen_->AddSlowPath(read_barrier_slow_path);
2782
2783 // Given the numeric representation, it's enough to check the low bit of the rb_state.
Hiroshi Yamauchi12b58b22016-11-01 11:55:29 -07002784 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
2785 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
Roland Levillain0b671c02016-08-19 12:02:34 +01002786 __ Tbnz(tmp, LockWord::kReadBarrierStateShift, read_barrier_slow_path->GetEntryLabel());
2787
2788 // Fast-path copy.
2789 // Iterate over the arrays and do a raw copy of the objects. We don't need to
2790 // poison/unpoison.
2791 __ Bind(&loop);
Scott Wakeling97c72b72016-06-24 16:19:36 +01002792 __ Ldr(tmp, MemOperand(src_curr_addr, element_size, PostIndex));
2793 __ Str(tmp, MemOperand(dst_curr_addr, element_size, PostIndex));
Roland Levillain0b671c02016-08-19 12:02:34 +01002794 __ Cmp(src_curr_addr, src_stop_addr);
2795 __ B(&loop, ne);
2796
2797 __ Bind(read_barrier_slow_path->GetExitLabel());
2798 __ Bind(&done);
2799 } else {
2800 // Non read barrier code.
2801
2802 // Iterate over the arrays and do a raw copy of the objects. We don't need to
2803 // poison/unpoison.
2804 vixl::aarch64::Label loop, done;
2805 __ Bind(&loop);
2806 __ Cmp(src_curr_addr, src_stop_addr);
2807 __ B(&done, eq);
2808 {
2809 Register tmp = temps.AcquireW();
2810 __ Ldr(tmp, MemOperand(src_curr_addr, element_size, PostIndex));
2811 __ Str(tmp, MemOperand(dst_curr_addr, element_size, PostIndex));
2812 }
2813 __ B(&loop);
2814 __ Bind(&done);
donghui.baic2ec9ad2016-03-10 14:02:55 +08002815 }
donghui.baic2ec9ad2016-03-10 14:02:55 +08002816 }
2817 // We only need one card marking on the destination array.
2818 codegen_->MarkGCCard(dest.W(), Register(), /* value_can_be_null */ false);
2819
Roland Levillain0b671c02016-08-19 12:02:34 +01002820 __ Bind(intrinsic_slow_path->GetExitLabel());
donghui.baic2ec9ad2016-03-10 14:02:55 +08002821}
2822
Anton Kirilova3ffea22016-04-07 17:02:37 +01002823static void GenIsInfinite(LocationSummary* locations,
2824 bool is64bit,
Scott Wakeling97c72b72016-06-24 16:19:36 +01002825 MacroAssembler* masm) {
Anton Kirilova3ffea22016-04-07 17:02:37 +01002826 Operand infinity;
2827 Register out;
2828
2829 if (is64bit) {
2830 infinity = kPositiveInfinityDouble;
2831 out = XRegisterFrom(locations->Out());
2832 } else {
2833 infinity = kPositiveInfinityFloat;
2834 out = WRegisterFrom(locations->Out());
2835 }
2836
Scott Wakeling97c72b72016-06-24 16:19:36 +01002837 const Register zero = vixl::aarch64::Assembler::AppropriateZeroRegFor(out);
Anton Kirilova3ffea22016-04-07 17:02:37 +01002838
2839 MoveFPToInt(locations, is64bit, masm);
2840 __ Eor(out, out, infinity);
2841 // We don't care about the sign bit, so shift left.
2842 __ Cmp(zero, Operand(out, LSL, 1));
2843 __ Cset(out, eq);
2844}
2845
2846void IntrinsicLocationsBuilderARM64::VisitFloatIsInfinite(HInvoke* invoke) {
2847 CreateFPToIntLocations(arena_, invoke);
2848}
2849
2850void IntrinsicCodeGeneratorARM64::VisitFloatIsInfinite(HInvoke* invoke) {
2851 GenIsInfinite(invoke->GetLocations(), /* is64bit */ false, GetVIXLAssembler());
2852}
2853
2854void IntrinsicLocationsBuilderARM64::VisitDoubleIsInfinite(HInvoke* invoke) {
2855 CreateFPToIntLocations(arena_, invoke);
2856}
2857
2858void IntrinsicCodeGeneratorARM64::VisitDoubleIsInfinite(HInvoke* invoke) {
2859 GenIsInfinite(invoke->GetLocations(), /* is64bit */ true, GetVIXLAssembler());
2860}
2861
TatWai Chongd8c052a2016-11-02 16:12:48 +08002862void IntrinsicLocationsBuilderARM64::VisitReferenceGetReferent(HInvoke* invoke) {
2863 if (kEmitCompilerReadBarrier) {
2864 // Do not intrinsify this call with the read barrier configuration.
2865 return;
2866 }
2867 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2868 LocationSummary::kCallOnSlowPath,
2869 kIntrinsified);
2870 locations->SetInAt(0, Location::RequiresRegister());
2871 locations->SetOut(Location::SameAsFirstInput());
2872 locations->AddTemp(Location::RequiresRegister());
2873}
2874
2875void IntrinsicCodeGeneratorARM64::VisitReferenceGetReferent(HInvoke* invoke) {
2876 DCHECK(!kEmitCompilerReadBarrier);
2877 MacroAssembler* masm = GetVIXLAssembler();
2878 LocationSummary* locations = invoke->GetLocations();
2879
2880 Register obj = InputRegisterAt(invoke, 0);
2881 Register out = OutputRegister(invoke);
2882
2883 SlowPathCodeARM64* slow_path = new (GetAllocator()) IntrinsicSlowPathARM64(invoke);
2884 codegen_->AddSlowPath(slow_path);
2885
2886 // Load ArtMethod first.
2887 HInvokeStaticOrDirect* invoke_direct = invoke->AsInvokeStaticOrDirect();
2888 DCHECK(invoke_direct != nullptr);
2889 Register temp0 = XRegisterFrom(codegen_->GenerateCalleeMethodStaticOrDirectCall(
2890 invoke_direct, locations->GetTemp(0)));
2891
2892 // Now get declaring class.
2893 __ Ldr(temp0.W(), MemOperand(temp0, ArtMethod::DeclaringClassOffset().Int32Value()));
2894
2895 uint32_t slow_path_flag_offset = codegen_->GetReferenceSlowFlagOffset();
2896 uint32_t disable_flag_offset = codegen_->GetReferenceDisableFlagOffset();
2897 DCHECK_NE(slow_path_flag_offset, 0u);
2898 DCHECK_NE(disable_flag_offset, 0u);
2899 DCHECK_NE(slow_path_flag_offset, disable_flag_offset);
2900
2901 // Check static flags that prevent using intrinsic.
2902 if (slow_path_flag_offset == disable_flag_offset + 1) {
2903 // Load two adjacent flags in one 64-bit load.
2904 __ Ldr(temp0, MemOperand(temp0, disable_flag_offset));
2905 } else {
2906 UseScratchRegisterScope temps(masm);
2907 Register temp1 = temps.AcquireW();
2908 __ Ldr(temp1.W(), MemOperand(temp0, disable_flag_offset));
2909 __ Ldr(temp0.W(), MemOperand(temp0, slow_path_flag_offset));
2910 __ Orr(temp0, temp1, temp0);
2911 }
2912 __ Cbnz(temp0, slow_path->GetEntryLabel());
2913
Artem Serov914d7a82017-02-07 14:33:49 +00002914 {
2915 // Ensure that between load and MaybeRecordImplicitNullCheck there are no pools emitted.
2916 vixl::EmissionCheckScope guard(codegen_->GetVIXLAssembler(), kMaxMacroInstructionSizeInBytes);
2917 // Fast path.
2918 __ Ldr(out, HeapOperand(obj, mirror::Reference::ReferentOffset().Int32Value()));
2919 codegen_->MaybeRecordImplicitNullCheck(invoke);
2920 }
TatWai Chongd8c052a2016-11-02 16:12:48 +08002921 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(out);
2922 __ Bind(slow_path->GetExitLabel());
2923}
2924
Nicolas Geoffray331605a2017-03-01 11:01:41 +00002925void IntrinsicLocationsBuilderARM64::VisitIntegerValueOf(HInvoke* invoke) {
2926 InvokeRuntimeCallingConvention calling_convention;
2927 IntrinsicVisitor::ComputeIntegerValueOfLocations(
2928 invoke,
2929 codegen_,
2930 calling_convention.GetReturnLocation(Primitive::kPrimNot),
2931 Location::RegisterLocation(calling_convention.GetRegisterAt(0).GetCode()));
2932}
2933
2934void IntrinsicCodeGeneratorARM64::VisitIntegerValueOf(HInvoke* invoke) {
2935 IntrinsicVisitor::IntegerValueOfInfo info = IntrinsicVisitor::ComputeIntegerValueOfInfo();
2936 LocationSummary* locations = invoke->GetLocations();
2937 MacroAssembler* masm = GetVIXLAssembler();
2938
2939 Register out = RegisterFrom(locations->Out(), Primitive::kPrimNot);
2940 UseScratchRegisterScope temps(masm);
2941 Register temp = temps.AcquireW();
2942 InvokeRuntimeCallingConvention calling_convention;
2943 Register argument = calling_convention.GetRegisterAt(0);
2944 if (invoke->InputAt(0)->IsConstant()) {
2945 int32_t value = invoke->InputAt(0)->AsIntConstant()->GetValue();
2946 if (value >= info.low && value <= info.high) {
2947 // Just embed the j.l.Integer in the code.
2948 ScopedObjectAccess soa(Thread::Current());
2949 mirror::Object* boxed = info.cache->Get(value + (-info.low));
2950 DCHECK(boxed != nullptr && Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(boxed));
2951 uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(boxed));
2952 __ Ldr(out.W(), codegen_->DeduplicateBootImageAddressLiteral(address));
2953 } else {
2954 // Allocate and initialize a new j.l.Integer.
2955 // TODO: If we JIT, we could allocate the j.l.Integer now, and store it in the
2956 // JIT object table.
2957 uint32_t address =
2958 dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer));
2959 __ Ldr(argument.W(), codegen_->DeduplicateBootImageAddressLiteral(address));
2960 codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc());
2961 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
2962 __ Mov(temp.W(), value);
2963 __ Str(temp.W(), HeapOperand(out.W(), info.value_offset));
2964 // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation
2965 // one.
2966 codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
2967 }
2968 } else {
2969 Register in = RegisterFrom(locations->InAt(0), Primitive::kPrimInt);
2970 // Check bounds of our cache.
2971 __ Add(out.W(), in.W(), -info.low);
2972 __ Cmp(out.W(), info.high - info.low + 1);
2973 vixl::aarch64::Label allocate, done;
2974 __ B(&allocate, hs);
2975 // If the value is within the bounds, load the j.l.Integer directly from the array.
2976 uint32_t data_offset = mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
2977 uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.cache));
2978 __ Ldr(temp.W(), codegen_->DeduplicateBootImageAddressLiteral(data_offset + address));
2979 MemOperand source = HeapOperand(
2980 temp, out.X(), LSL, Primitive::ComponentSizeShift(Primitive::kPrimNot));
2981 codegen_->Load(Primitive::kPrimNot, out, source);
2982 codegen_->GetAssembler()->MaybeUnpoisonHeapReference(out);
2983 __ B(&done);
2984 __ Bind(&allocate);
2985 // Otherwise allocate and initialize a new j.l.Integer.
2986 address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer));
2987 __ Ldr(argument.W(), codegen_->DeduplicateBootImageAddressLiteral(address));
2988 codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc());
2989 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
2990 __ Str(in.W(), HeapOperand(out.W(), info.value_offset));
2991 // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation
2992 // one.
2993 codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
2994 __ Bind(&done);
2995 }
2996}
2997
Aart Bik2f9fcc92016-03-01 15:16:54 -08002998UNIMPLEMENTED_INTRINSIC(ARM64, IntegerHighestOneBit)
2999UNIMPLEMENTED_INTRINSIC(ARM64, LongHighestOneBit)
3000UNIMPLEMENTED_INTRINSIC(ARM64, IntegerLowestOneBit)
3001UNIMPLEMENTED_INTRINSIC(ARM64, LongLowestOneBit)
Andreas Gampe878d58c2015-01-15 23:24:00 -08003002
Aart Bikff7d89c2016-11-07 08:49:28 -08003003UNIMPLEMENTED_INTRINSIC(ARM64, StringStringIndexOf);
3004UNIMPLEMENTED_INTRINSIC(ARM64, StringStringIndexOfAfter);
Aart Bik71bf7b42016-11-16 10:17:46 -08003005UNIMPLEMENTED_INTRINSIC(ARM64, StringBufferAppend);
3006UNIMPLEMENTED_INTRINSIC(ARM64, StringBufferLength);
3007UNIMPLEMENTED_INTRINSIC(ARM64, StringBufferToString);
3008UNIMPLEMENTED_INTRINSIC(ARM64, StringBuilderAppend);
3009UNIMPLEMENTED_INTRINSIC(ARM64, StringBuilderLength);
3010UNIMPLEMENTED_INTRINSIC(ARM64, StringBuilderToString);
Aart Bikff7d89c2016-11-07 08:49:28 -08003011
Aart Bik0e54c012016-03-04 12:08:31 -08003012// 1.8.
3013UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndAddInt)
3014UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndAddLong)
3015UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetInt)
3016UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetLong)
3017UNIMPLEMENTED_INTRINSIC(ARM64, UnsafeGetAndSetObject)
Aart Bik0e54c012016-03-04 12:08:31 -08003018
Aart Bik2f9fcc92016-03-01 15:16:54 -08003019UNREACHABLE_INTRINSICS(ARM64)
Roland Levillain4d027112015-07-01 15:41:14 +01003020
3021#undef __
3022
Andreas Gampe878d58c2015-01-15 23:24:00 -08003023} // namespace arm64
3024} // namespace art