blob: d2dc88a73bfe6ad233f789148f252b651b54689e [file] [log] [blame]
Anton Kirilov5ec62182016-10-13 20:16:02 +01001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "intrinsics_arm_vixl.h"
18
19#include "arch/arm/instruction_set_features_arm.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080020#include "art_method.h"
Anton Kirilov5ec62182016-10-13 20:16:02 +010021#include "code_generator_arm_vixl.h"
22#include "common_arm.h"
23#include "lock_word.h"
24#include "mirror/array-inl.h"
Andreas Gampec15a2f42017-04-21 12:09:39 -070025#include "mirror/object_array-inl.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080026#include "mirror/reference.h"
27#include "mirror/string.h"
28#include "scoped_thread_state_change-inl.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070029#include "thread-current-inl.h"
Anton Kirilov5ec62182016-10-13 20:16:02 +010030
31#include "aarch32/constants-aarch32.h"
32
33namespace art {
34namespace arm {
35
36#define __ assembler->GetVIXLAssembler()->
37
38using helpers::DRegisterFrom;
39using helpers::HighRegisterFrom;
40using helpers::InputDRegisterAt;
41using helpers::InputRegisterAt;
42using helpers::InputSRegisterAt;
43using helpers::InputVRegisterAt;
44using helpers::Int32ConstantFrom;
45using helpers::LocationFrom;
46using helpers::LowRegisterFrom;
47using helpers::LowSRegisterFrom;
xueliang.zhong53463ba2017-02-16 15:18:03 +000048using helpers::HighSRegisterFrom;
Anton Kirilov5ec62182016-10-13 20:16:02 +010049using helpers::OutputDRegister;
xueliang.zhongc032e742016-03-28 16:44:32 +010050using helpers::OutputSRegister;
Anton Kirilov5ec62182016-10-13 20:16:02 +010051using helpers::OutputRegister;
52using helpers::OutputVRegister;
53using helpers::RegisterFrom;
54using helpers::SRegisterFrom;
xueliang.zhongc032e742016-03-28 16:44:32 +010055using helpers::DRegisterFromS;
Anton Kirilov5ec62182016-10-13 20:16:02 +010056
57using namespace vixl::aarch32; // NOLINT(build/namespaces)
58
Artem Serov0fb37192016-12-06 18:13:40 +000059using vixl::ExactAssemblyScope;
60using vixl::CodeBufferCheckScope;
61
Anton Kirilov5ec62182016-10-13 20:16:02 +010062ArmVIXLAssembler* IntrinsicCodeGeneratorARMVIXL::GetAssembler() {
63 return codegen_->GetAssembler();
64}
65
66ArenaAllocator* IntrinsicCodeGeneratorARMVIXL::GetAllocator() {
67 return codegen_->GetGraph()->GetArena();
68}
69
70// Default slow-path for fallback (calling the managed code to handle the intrinsic) in an
71// intrinsified call. This will copy the arguments into the positions for a regular call.
72//
73// Note: The actual parameters are required to be in the locations given by the invoke's location
74// summary. If an intrinsic modifies those locations before a slowpath call, they must be
75// restored!
76//
77// Note: If an invoke wasn't sharpened, we will put down an invoke-virtual here. That's potentially
78// sub-optimal (compared to a direct pointer call), but this is a slow-path.
79
80class IntrinsicSlowPathARMVIXL : public SlowPathCodeARMVIXL {
81 public:
82 explicit IntrinsicSlowPathARMVIXL(HInvoke* invoke)
83 : SlowPathCodeARMVIXL(invoke), invoke_(invoke) {}
84
85 Location MoveArguments(CodeGenerator* codegen) {
Artem Serovd4cc5b22016-11-04 11:19:09 +000086 InvokeDexCallingConventionVisitorARMVIXL calling_convention_visitor;
Anton Kirilov5ec62182016-10-13 20:16:02 +010087 IntrinsicVisitor::MoveArguments(invoke_, codegen, &calling_convention_visitor);
88 return calling_convention_visitor.GetMethodLocation();
89 }
90
91 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
92 ArmVIXLAssembler* assembler = down_cast<ArmVIXLAssembler*>(codegen->GetAssembler());
93 __ Bind(GetEntryLabel());
94
95 SaveLiveRegisters(codegen, invoke_->GetLocations());
96
97 Location method_loc = MoveArguments(codegen);
98
99 if (invoke_->IsInvokeStaticOrDirect()) {
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100100 codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(), method_loc, this);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100101 } else {
Vladimir Markoe7197bf2017-06-02 17:00:23 +0100102 codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), method_loc, this);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100103 }
Anton Kirilov5ec62182016-10-13 20:16:02 +0100104
105 // Copy the result back to the expected output.
106 Location out = invoke_->GetLocations()->Out();
107 if (out.IsValid()) {
108 DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory.
109 DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
110 codegen->MoveFromReturnRegister(out, invoke_->GetType());
111 }
112
113 RestoreLiveRegisters(codegen, invoke_->GetLocations());
114 __ B(GetExitLabel());
115 }
116
117 const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPath"; }
118
119 private:
120 // The instruction where this slow path is happening.
121 HInvoke* const invoke_;
122
123 DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathARMVIXL);
124};
125
Roland Levillain9cc0ea82017-03-16 11:25:59 +0000126// Compute base address for the System.arraycopy intrinsic in `base`.
127static void GenSystemArrayCopyBaseAddress(ArmVIXLAssembler* assembler,
128 Primitive::Type type,
129 const vixl32::Register& array,
130 const Location& pos,
131 const vixl32::Register& base) {
132 // This routine is only used by the SystemArrayCopy intrinsic at the
133 // moment. We can allow Primitive::kPrimNot as `type` to implement
134 // the SystemArrayCopyChar intrinsic.
135 DCHECK_EQ(type, Primitive::kPrimNot);
136 const int32_t element_size = Primitive::ComponentSize(type);
137 const uint32_t element_size_shift = Primitive::ComponentSizeShift(type);
138 const uint32_t data_offset = mirror::Array::DataOffset(element_size).Uint32Value();
139
140 if (pos.IsConstant()) {
141 int32_t constant = Int32ConstantFrom(pos);
142 __ Add(base, array, element_size * constant + data_offset);
143 } else {
144 __ Add(base, array, Operand(RegisterFrom(pos), vixl32::LSL, element_size_shift));
145 __ Add(base, base, data_offset);
146 }
147}
148
149// Compute end address for the System.arraycopy intrinsic in `end`.
150static void GenSystemArrayCopyEndAddress(ArmVIXLAssembler* assembler,
151 Primitive::Type type,
152 const Location& copy_length,
153 const vixl32::Register& base,
154 const vixl32::Register& end) {
155 // This routine is only used by the SystemArrayCopy intrinsic at the
156 // moment. We can allow Primitive::kPrimNot as `type` to implement
157 // the SystemArrayCopyChar intrinsic.
158 DCHECK_EQ(type, Primitive::kPrimNot);
159 const int32_t element_size = Primitive::ComponentSize(type);
160 const uint32_t element_size_shift = Primitive::ComponentSizeShift(type);
161
162 if (copy_length.IsConstant()) {
163 int32_t constant = Int32ConstantFrom(copy_length);
164 __ Add(end, base, element_size * constant);
165 } else {
166 __ Add(end, base, Operand(RegisterFrom(copy_length), vixl32::LSL, element_size_shift));
167 }
168}
169
Anton Kirilov5ec62182016-10-13 20:16:02 +0100170// Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers.
171class ReadBarrierSystemArrayCopySlowPathARMVIXL : public SlowPathCodeARMVIXL {
172 public:
173 explicit ReadBarrierSystemArrayCopySlowPathARMVIXL(HInstruction* instruction)
174 : SlowPathCodeARMVIXL(instruction) {
175 DCHECK(kEmitCompilerReadBarrier);
176 DCHECK(kUseBakerReadBarrier);
177 }
178
179 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
180 CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen);
181 ArmVIXLAssembler* assembler = arm_codegen->GetAssembler();
182 LocationSummary* locations = instruction_->GetLocations();
183 DCHECK(locations->CanCall());
184 DCHECK(instruction_->IsInvokeStaticOrDirect())
185 << "Unexpected instruction in read barrier arraycopy slow path: "
186 << instruction_->DebugName();
187 DCHECK(instruction_->GetLocations()->Intrinsified());
188 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy);
189
Roland Levillain9cc0ea82017-03-16 11:25:59 +0000190 Primitive::Type type = Primitive::kPrimNot;
191 const int32_t element_size = Primitive::ComponentSize(type);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100192
193 vixl32::Register dest = InputRegisterAt(instruction_, 2);
194 Location dest_pos = locations->InAt(3);
195 vixl32::Register src_curr_addr = RegisterFrom(locations->GetTemp(0));
196 vixl32::Register dst_curr_addr = RegisterFrom(locations->GetTemp(1));
197 vixl32::Register src_stop_addr = RegisterFrom(locations->GetTemp(2));
198 vixl32::Register tmp = RegisterFrom(locations->GetTemp(3));
199
200 __ Bind(GetEntryLabel());
201 // Compute the base destination address in `dst_curr_addr`.
Roland Levillain9cc0ea82017-03-16 11:25:59 +0000202 GenSystemArrayCopyBaseAddress(assembler, type, dest, dest_pos, dst_curr_addr);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100203
204 vixl32::Label loop;
205 __ Bind(&loop);
206 __ Ldr(tmp, MemOperand(src_curr_addr, element_size, PostIndex));
207 assembler->MaybeUnpoisonHeapReference(tmp);
208 // TODO: Inline the mark bit check before calling the runtime?
209 // tmp = ReadBarrier::Mark(tmp);
210 // No need to save live registers; it's taken care of by the
211 // entrypoint. Also, there is no need to update the stack mask,
212 // as this runtime call will not trigger a garbage collection.
213 // (See ReadBarrierMarkSlowPathARM::EmitNativeCode for more
214 // explanations.)
215 DCHECK(!tmp.IsSP());
216 DCHECK(!tmp.IsLR());
217 DCHECK(!tmp.IsPC());
218 // IP is used internally by the ReadBarrierMarkRegX entry point
219 // as a temporary (and not preserved). It thus cannot be used by
220 // any live register in this slow path.
221 DCHECK(!src_curr_addr.Is(ip));
222 DCHECK(!dst_curr_addr.Is(ip));
223 DCHECK(!src_stop_addr.Is(ip));
224 DCHECK(!tmp.Is(ip));
225 DCHECK(tmp.IsRegister()) << tmp;
Roland Levillain9cc0ea82017-03-16 11:25:59 +0000226 // TODO: Load the entrypoint once before the loop, instead of
227 // loading it at every iteration.
Anton Kirilov5ec62182016-10-13 20:16:02 +0100228 int32_t entry_point_offset =
Roland Levillain97c46462017-05-11 14:04:03 +0100229 Thread::ReadBarrierMarkEntryPointsOffset<kArmPointerSize>(tmp.GetCode());
Anton Kirilov5ec62182016-10-13 20:16:02 +0100230 // This runtime call does not require a stack map.
231 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
232 assembler->MaybePoisonHeapReference(tmp);
233 __ Str(tmp, MemOperand(dst_curr_addr, element_size, PostIndex));
234 __ Cmp(src_curr_addr, src_stop_addr);
Artem Serov517d9f62016-12-12 15:51:15 +0000235 __ B(ne, &loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100236 __ B(GetExitLabel());
237 }
238
239 const char* GetDescription() const OVERRIDE {
240 return "ReadBarrierSystemArrayCopySlowPathARMVIXL";
241 }
242
243 private:
244 DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathARMVIXL);
245};
246
247IntrinsicLocationsBuilderARMVIXL::IntrinsicLocationsBuilderARMVIXL(CodeGeneratorARMVIXL* codegen)
248 : arena_(codegen->GetGraph()->GetArena()),
Nicolas Geoffray331605a2017-03-01 11:01:41 +0000249 codegen_(codegen),
Anton Kirilov5ec62182016-10-13 20:16:02 +0100250 assembler_(codegen->GetAssembler()),
251 features_(codegen->GetInstructionSetFeatures()) {}
252
253bool IntrinsicLocationsBuilderARMVIXL::TryDispatch(HInvoke* invoke) {
254 Dispatch(invoke);
255 LocationSummary* res = invoke->GetLocations();
256 if (res == nullptr) {
257 return false;
258 }
259 return res->Intrinsified();
260}
261
262static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
263 LocationSummary* locations = new (arena) LocationSummary(invoke,
264 LocationSummary::kNoCall,
265 kIntrinsified);
266 locations->SetInAt(0, Location::RequiresFpuRegister());
267 locations->SetOut(Location::RequiresRegister());
268}
269
270static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
271 LocationSummary* locations = new (arena) LocationSummary(invoke,
272 LocationSummary::kNoCall,
273 kIntrinsified);
274 locations->SetInAt(0, Location::RequiresRegister());
275 locations->SetOut(Location::RequiresFpuRegister());
276}
277
278static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmVIXLAssembler* assembler) {
279 Location input = locations->InAt(0);
280 Location output = locations->Out();
281 if (is64bit) {
282 __ Vmov(LowRegisterFrom(output), HighRegisterFrom(output), DRegisterFrom(input));
283 } else {
284 __ Vmov(RegisterFrom(output), SRegisterFrom(input));
285 }
286}
287
288static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmVIXLAssembler* assembler) {
289 Location input = locations->InAt(0);
290 Location output = locations->Out();
291 if (is64bit) {
292 __ Vmov(DRegisterFrom(output), LowRegisterFrom(input), HighRegisterFrom(input));
293 } else {
294 __ Vmov(SRegisterFrom(output), RegisterFrom(input));
295 }
296}
297
298void IntrinsicLocationsBuilderARMVIXL::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
299 CreateFPToIntLocations(arena_, invoke);
300}
301void IntrinsicLocationsBuilderARMVIXL::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
302 CreateIntToFPLocations(arena_, invoke);
303}
304
305void IntrinsicCodeGeneratorARMVIXL::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
306 MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
307}
308void IntrinsicCodeGeneratorARMVIXL::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
309 MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
310}
311
312void IntrinsicLocationsBuilderARMVIXL::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
313 CreateFPToIntLocations(arena_, invoke);
314}
315void IntrinsicLocationsBuilderARMVIXL::VisitFloatIntBitsToFloat(HInvoke* invoke) {
316 CreateIntToFPLocations(arena_, invoke);
317}
318
319void IntrinsicCodeGeneratorARMVIXL::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
320 MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
321}
322void IntrinsicCodeGeneratorARMVIXL::VisitFloatIntBitsToFloat(HInvoke* invoke) {
323 MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
324}
325
326static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
327 LocationSummary* locations = new (arena) LocationSummary(invoke,
328 LocationSummary::kNoCall,
329 kIntrinsified);
330 locations->SetInAt(0, Location::RequiresRegister());
331 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
332}
333
Vladimir Marko1819e412017-08-29 17:02:56 +0100334static void CreateLongToLongLocationsWithOverlap(ArenaAllocator* arena, HInvoke* invoke) {
Petre-Ionut Tudor27292e62017-08-04 16:06:45 +0100335 LocationSummary* locations = new (arena) LocationSummary(invoke,
336 LocationSummary::kNoCall,
337 kIntrinsified);
338 locations->SetInAt(0, Location::RequiresRegister());
339 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
340}
341
Anton Kirilov5ec62182016-10-13 20:16:02 +0100342static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
343 LocationSummary* locations = new (arena) LocationSummary(invoke,
344 LocationSummary::kNoCall,
345 kIntrinsified);
346 locations->SetInAt(0, Location::RequiresFpuRegister());
347 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
348}
349
Anton Kirilov6f644202017-02-27 18:29:45 +0000350static void GenNumberOfLeadingZeros(HInvoke* invoke,
Anton Kirilov5ec62182016-10-13 20:16:02 +0100351 Primitive::Type type,
Anton Kirilov6f644202017-02-27 18:29:45 +0000352 CodeGeneratorARMVIXL* codegen) {
353 ArmVIXLAssembler* assembler = codegen->GetAssembler();
354 LocationSummary* locations = invoke->GetLocations();
Anton Kirilov5ec62182016-10-13 20:16:02 +0100355 Location in = locations->InAt(0);
356 vixl32::Register out = RegisterFrom(locations->Out());
357
358 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
359
360 if (type == Primitive::kPrimLong) {
361 vixl32::Register in_reg_lo = LowRegisterFrom(in);
362 vixl32::Register in_reg_hi = HighRegisterFrom(in);
363 vixl32::Label end;
Anton Kirilov6f644202017-02-27 18:29:45 +0000364 vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &end);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100365 __ Clz(out, in_reg_hi);
Anton Kirilov6f644202017-02-27 18:29:45 +0000366 __ CompareAndBranchIfNonZero(in_reg_hi, final_label, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100367 __ Clz(out, in_reg_lo);
368 __ Add(out, out, 32);
Anton Kirilov6f644202017-02-27 18:29:45 +0000369 if (end.IsReferenced()) {
370 __ Bind(&end);
371 }
Anton Kirilov5ec62182016-10-13 20:16:02 +0100372 } else {
373 __ Clz(out, RegisterFrom(in));
374 }
375}
376
377void IntrinsicLocationsBuilderARMVIXL::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
378 CreateIntToIntLocations(arena_, invoke);
379}
380
381void IntrinsicCodeGeneratorARMVIXL::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000382 GenNumberOfLeadingZeros(invoke, Primitive::kPrimInt, codegen_);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100383}
384
385void IntrinsicLocationsBuilderARMVIXL::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +0100386 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100387}
388
389void IntrinsicCodeGeneratorARMVIXL::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000390 GenNumberOfLeadingZeros(invoke, Primitive::kPrimLong, codegen_);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100391}
392
Anton Kirilov6f644202017-02-27 18:29:45 +0000393static void GenNumberOfTrailingZeros(HInvoke* invoke,
Anton Kirilov5ec62182016-10-13 20:16:02 +0100394 Primitive::Type type,
Anton Kirilov6f644202017-02-27 18:29:45 +0000395 CodeGeneratorARMVIXL* codegen) {
Anton Kirilov5ec62182016-10-13 20:16:02 +0100396 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
397
Anton Kirilov6f644202017-02-27 18:29:45 +0000398 ArmVIXLAssembler* assembler = codegen->GetAssembler();
399 LocationSummary* locations = invoke->GetLocations();
Anton Kirilov5ec62182016-10-13 20:16:02 +0100400 vixl32::Register out = RegisterFrom(locations->Out());
401
402 if (type == Primitive::kPrimLong) {
403 vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0));
404 vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0));
405 vixl32::Label end;
Anton Kirilov6f644202017-02-27 18:29:45 +0000406 vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &end);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100407 __ Rbit(out, in_reg_lo);
408 __ Clz(out, out);
Anton Kirilov6f644202017-02-27 18:29:45 +0000409 __ CompareAndBranchIfNonZero(in_reg_lo, final_label, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100410 __ Rbit(out, in_reg_hi);
411 __ Clz(out, out);
412 __ Add(out, out, 32);
Anton Kirilov6f644202017-02-27 18:29:45 +0000413 if (end.IsReferenced()) {
414 __ Bind(&end);
415 }
Anton Kirilov5ec62182016-10-13 20:16:02 +0100416 } else {
417 vixl32::Register in = RegisterFrom(locations->InAt(0));
418 __ Rbit(out, in);
419 __ Clz(out, out);
420 }
421}
422
423void IntrinsicLocationsBuilderARMVIXL::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +0100424 CreateIntToIntLocations(arena_, invoke);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100425}
426
427void IntrinsicCodeGeneratorARMVIXL::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000428 GenNumberOfTrailingZeros(invoke, Primitive::kPrimInt, codegen_);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100429}
430
431void IntrinsicLocationsBuilderARMVIXL::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +0100432 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100433}
434
435void IntrinsicCodeGeneratorARMVIXL::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000436 GenNumberOfTrailingZeros(invoke, Primitive::kPrimLong, codegen_);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100437}
438
439static void MathAbsFP(HInvoke* invoke, ArmVIXLAssembler* assembler) {
440 __ Vabs(OutputVRegister(invoke), InputVRegisterAt(invoke, 0));
441}
442
443void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsDouble(HInvoke* invoke) {
444 CreateFPToFPLocations(arena_, invoke);
445}
446
447void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsDouble(HInvoke* invoke) {
448 MathAbsFP(invoke, GetAssembler());
449}
450
451void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsFloat(HInvoke* invoke) {
452 CreateFPToFPLocations(arena_, invoke);
453}
454
455void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsFloat(HInvoke* invoke) {
456 MathAbsFP(invoke, GetAssembler());
457}
458
459static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) {
460 LocationSummary* locations = new (arena) LocationSummary(invoke,
461 LocationSummary::kNoCall,
462 kIntrinsified);
463 locations->SetInAt(0, Location::RequiresRegister());
464 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
465
466 locations->AddTemp(Location::RequiresRegister());
467}
468
469static void GenAbsInteger(LocationSummary* locations,
470 bool is64bit,
471 ArmVIXLAssembler* assembler) {
472 Location in = locations->InAt(0);
473 Location output = locations->Out();
474
475 vixl32::Register mask = RegisterFrom(locations->GetTemp(0));
476
477 if (is64bit) {
478 vixl32::Register in_reg_lo = LowRegisterFrom(in);
479 vixl32::Register in_reg_hi = HighRegisterFrom(in);
480 vixl32::Register out_reg_lo = LowRegisterFrom(output);
481 vixl32::Register out_reg_hi = HighRegisterFrom(output);
482
483 DCHECK(!out_reg_lo.Is(in_reg_hi)) << "Diagonal overlap unexpected.";
484
485 __ Asr(mask, in_reg_hi, 31);
486 __ Adds(out_reg_lo, in_reg_lo, mask);
487 __ Adc(out_reg_hi, in_reg_hi, mask);
488 __ Eor(out_reg_lo, mask, out_reg_lo);
489 __ Eor(out_reg_hi, mask, out_reg_hi);
490 } else {
491 vixl32::Register in_reg = RegisterFrom(in);
492 vixl32::Register out_reg = RegisterFrom(output);
493
494 __ Asr(mask, in_reg, 31);
495 __ Add(out_reg, in_reg, mask);
496 __ Eor(out_reg, mask, out_reg);
497 }
498}
499
500void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsInt(HInvoke* invoke) {
501 CreateIntToIntPlusTemp(arena_, invoke);
502}
503
504void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsInt(HInvoke* invoke) {
505 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
506}
507
508
509void IntrinsicLocationsBuilderARMVIXL::VisitMathAbsLong(HInvoke* invoke) {
510 CreateIntToIntPlusTemp(arena_, invoke);
511}
512
513void IntrinsicCodeGeneratorARMVIXL::VisitMathAbsLong(HInvoke* invoke) {
514 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
515}
516
Anton Kirilov6f644202017-02-27 18:29:45 +0000517static void GenMinMaxFloat(HInvoke* invoke, bool is_min, CodeGeneratorARMVIXL* codegen) {
518 ArmVIXLAssembler* assembler = codegen->GetAssembler();
xueliang.zhongc032e742016-03-28 16:44:32 +0100519 Location op1_loc = invoke->GetLocations()->InAt(0);
520 Location op2_loc = invoke->GetLocations()->InAt(1);
521 Location out_loc = invoke->GetLocations()->Out();
522
523 // Optimization: don't generate any code if inputs are the same.
524 if (op1_loc.Equals(op2_loc)) {
525 DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder.
526 return;
527 }
528
529 vixl32::SRegister op1 = SRegisterFrom(op1_loc);
530 vixl32::SRegister op2 = SRegisterFrom(op2_loc);
531 vixl32::SRegister out = OutputSRegister(invoke);
532 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
533 const vixl32::Register temp1 = temps.Acquire();
534 vixl32::Register temp2 = RegisterFrom(invoke->GetLocations()->GetTemp(0));
535 vixl32::Label nan, done;
Anton Kirilov6f644202017-02-27 18:29:45 +0000536 vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &done);
xueliang.zhongc032e742016-03-28 16:44:32 +0100537
538 DCHECK(op1.Is(out));
539
540 __ Vcmp(op1, op2);
541 __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR);
542 __ B(vs, &nan, /* far_target */ false); // if un-ordered, go to NaN handling.
543
544 // op1 <> op2
545 vixl32::ConditionType cond = is_min ? gt : lt;
546 {
547 ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(),
548 2 * kMaxInstructionSizeInBytes,
549 CodeBufferCheckScope::kMaximumSize);
550 __ it(cond);
551 __ vmov(cond, F32, out, op2);
552 }
Anton Kirilov6f644202017-02-27 18:29:45 +0000553 // for <>(not equal), we've done min/max calculation.
554 __ B(ne, final_label, /* far_target */ false);
xueliang.zhongc032e742016-03-28 16:44:32 +0100555
556 // handle op1 == op2, max(+0.0,-0.0), min(+0.0,-0.0).
557 __ Vmov(temp1, op1);
558 __ Vmov(temp2, op2);
559 if (is_min) {
560 __ Orr(temp1, temp1, temp2);
561 } else {
562 __ And(temp1, temp1, temp2);
563 }
564 __ Vmov(out, temp1);
Anton Kirilov6f644202017-02-27 18:29:45 +0000565 __ B(final_label);
xueliang.zhongc032e742016-03-28 16:44:32 +0100566
567 // handle NaN input.
568 __ Bind(&nan);
569 __ Movt(temp1, High16Bits(kNanFloat)); // 0x7FC0xxxx is a NaN.
570 __ Vmov(out, temp1);
571
Anton Kirilov6f644202017-02-27 18:29:45 +0000572 if (done.IsReferenced()) {
573 __ Bind(&done);
574 }
xueliang.zhongc032e742016-03-28 16:44:32 +0100575}
576
577static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
578 LocationSummary* locations = new (arena) LocationSummary(invoke,
579 LocationSummary::kNoCall,
580 kIntrinsified);
581 locations->SetInAt(0, Location::RequiresFpuRegister());
582 locations->SetInAt(1, Location::RequiresFpuRegister());
583 locations->SetOut(Location::SameAsFirstInput());
584}
585
586void IntrinsicLocationsBuilderARMVIXL::VisitMathMinFloatFloat(HInvoke* invoke) {
587 CreateFPFPToFPLocations(arena_, invoke);
588 invoke->GetLocations()->AddTemp(Location::RequiresRegister());
589}
590
591void IntrinsicCodeGeneratorARMVIXL::VisitMathMinFloatFloat(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000592 GenMinMaxFloat(invoke, /* is_min */ true, codegen_);
xueliang.zhongc032e742016-03-28 16:44:32 +0100593}
594
595void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxFloatFloat(HInvoke* invoke) {
596 CreateFPFPToFPLocations(arena_, invoke);
597 invoke->GetLocations()->AddTemp(Location::RequiresRegister());
598}
599
600void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxFloatFloat(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000601 GenMinMaxFloat(invoke, /* is_min */ false, codegen_);
xueliang.zhongc032e742016-03-28 16:44:32 +0100602}
603
Anton Kirilov6f644202017-02-27 18:29:45 +0000604static void GenMinMaxDouble(HInvoke* invoke, bool is_min, CodeGeneratorARMVIXL* codegen) {
605 ArmVIXLAssembler* assembler = codegen->GetAssembler();
xueliang.zhongc032e742016-03-28 16:44:32 +0100606 Location op1_loc = invoke->GetLocations()->InAt(0);
607 Location op2_loc = invoke->GetLocations()->InAt(1);
608 Location out_loc = invoke->GetLocations()->Out();
609
610 // Optimization: don't generate any code if inputs are the same.
611 if (op1_loc.Equals(op2_loc)) {
612 DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in.
613 return;
614 }
615
616 vixl32::DRegister op1 = DRegisterFrom(op1_loc);
617 vixl32::DRegister op2 = DRegisterFrom(op2_loc);
618 vixl32::DRegister out = OutputDRegister(invoke);
619 vixl32::Label handle_nan_eq, done;
Anton Kirilov6f644202017-02-27 18:29:45 +0000620 vixl32::Label* final_label = codegen->GetFinalLabel(invoke, &done);
xueliang.zhongc032e742016-03-28 16:44:32 +0100621
622 DCHECK(op1.Is(out));
623
624 __ Vcmp(op1, op2);
625 __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR);
626 __ B(vs, &handle_nan_eq, /* far_target */ false); // if un-ordered, go to NaN handling.
627
628 // op1 <> op2
629 vixl32::ConditionType cond = is_min ? gt : lt;
630 {
631 ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(),
632 2 * kMaxInstructionSizeInBytes,
633 CodeBufferCheckScope::kMaximumSize);
634 __ it(cond);
635 __ vmov(cond, F64, out, op2);
636 }
Anton Kirilov6f644202017-02-27 18:29:45 +0000637 // for <>(not equal), we've done min/max calculation.
638 __ B(ne, final_label, /* far_target */ false);
xueliang.zhongc032e742016-03-28 16:44:32 +0100639
640 // handle op1 == op2, max(+0.0,-0.0).
641 if (!is_min) {
642 __ Vand(F64, out, op1, op2);
Anton Kirilov6f644202017-02-27 18:29:45 +0000643 __ B(final_label);
xueliang.zhongc032e742016-03-28 16:44:32 +0100644 }
645
646 // handle op1 == op2, min(+0.0,-0.0), NaN input.
647 __ Bind(&handle_nan_eq);
648 __ Vorr(F64, out, op1, op2); // assemble op1/-0.0/NaN.
649
Anton Kirilov6f644202017-02-27 18:29:45 +0000650 if (done.IsReferenced()) {
651 __ Bind(&done);
652 }
xueliang.zhongc032e742016-03-28 16:44:32 +0100653}
654
655void IntrinsicLocationsBuilderARMVIXL::VisitMathMinDoubleDouble(HInvoke* invoke) {
656 CreateFPFPToFPLocations(arena_, invoke);
657}
658
659void IntrinsicCodeGeneratorARMVIXL::VisitMathMinDoubleDouble(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000660 GenMinMaxDouble(invoke, /* is_min */ true , codegen_);
xueliang.zhongc032e742016-03-28 16:44:32 +0100661}
662
663void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxDoubleDouble(HInvoke* invoke) {
664 CreateFPFPToFPLocations(arena_, invoke);
665}
666
667void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxDoubleDouble(HInvoke* invoke) {
Anton Kirilov6f644202017-02-27 18:29:45 +0000668 GenMinMaxDouble(invoke, /* is_min */ false, codegen_);
xueliang.zhongc032e742016-03-28 16:44:32 +0100669}
670
671static void GenMinMaxLong(HInvoke* invoke, bool is_min, ArmVIXLAssembler* assembler) {
672 Location op1_loc = invoke->GetLocations()->InAt(0);
673 Location op2_loc = invoke->GetLocations()->InAt(1);
674 Location out_loc = invoke->GetLocations()->Out();
675
676 // Optimization: don't generate any code if inputs are the same.
677 if (op1_loc.Equals(op2_loc)) {
678 DCHECK(out_loc.Equals(op1_loc)); // out_loc is set as SameAsFirstInput() in location builder.
679 return;
680 }
681
682 vixl32::Register op1_lo = LowRegisterFrom(op1_loc);
683 vixl32::Register op1_hi = HighRegisterFrom(op1_loc);
684 vixl32::Register op2_lo = LowRegisterFrom(op2_loc);
685 vixl32::Register op2_hi = HighRegisterFrom(op2_loc);
686 vixl32::Register out_lo = LowRegisterFrom(out_loc);
687 vixl32::Register out_hi = HighRegisterFrom(out_loc);
688 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
689 const vixl32::Register temp = temps.Acquire();
690
691 DCHECK(op1_lo.Is(out_lo));
692 DCHECK(op1_hi.Is(out_hi));
693
694 // Compare op1 >= op2, or op1 < op2.
695 __ Cmp(out_lo, op2_lo);
696 __ Sbcs(temp, out_hi, op2_hi);
697
698 // Now GE/LT condition code is correct for the long comparison.
699 {
700 vixl32::ConditionType cond = is_min ? ge : lt;
701 ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(),
702 3 * kMaxInstructionSizeInBytes,
703 CodeBufferCheckScope::kMaximumSize);
704 __ itt(cond);
705 __ mov(cond, out_lo, op2_lo);
706 __ mov(cond, out_hi, op2_hi);
707 }
708}
709
710static void CreateLongLongToLongLocations(ArenaAllocator* arena, HInvoke* invoke) {
711 LocationSummary* locations = new (arena) LocationSummary(invoke,
712 LocationSummary::kNoCall,
713 kIntrinsified);
714 locations->SetInAt(0, Location::RequiresRegister());
715 locations->SetInAt(1, Location::RequiresRegister());
716 locations->SetOut(Location::SameAsFirstInput());
717}
718
719void IntrinsicLocationsBuilderARMVIXL::VisitMathMinLongLong(HInvoke* invoke) {
720 CreateLongLongToLongLocations(arena_, invoke);
721}
722
723void IntrinsicCodeGeneratorARMVIXL::VisitMathMinLongLong(HInvoke* invoke) {
724 GenMinMaxLong(invoke, /* is_min */ true, GetAssembler());
725}
726
727void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxLongLong(HInvoke* invoke) {
728 CreateLongLongToLongLocations(arena_, invoke);
729}
730
731void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxLongLong(HInvoke* invoke) {
732 GenMinMaxLong(invoke, /* is_min */ false, GetAssembler());
733}
734
Anton Kirilov5ec62182016-10-13 20:16:02 +0100735static void GenMinMax(HInvoke* invoke, bool is_min, ArmVIXLAssembler* assembler) {
736 vixl32::Register op1 = InputRegisterAt(invoke, 0);
737 vixl32::Register op2 = InputRegisterAt(invoke, 1);
738 vixl32::Register out = OutputRegister(invoke);
739
740 __ Cmp(op1, op2);
741
742 {
Artem Serov0fb37192016-12-06 18:13:40 +0000743 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
744 3 * kMaxInstructionSizeInBytes,
745 CodeBufferCheckScope::kMaximumSize);
Anton Kirilov5ec62182016-10-13 20:16:02 +0100746
747 __ ite(is_min ? lt : gt);
748 __ mov(is_min ? lt : gt, out, op1);
749 __ mov(is_min ? ge : le, out, op2);
750 }
751}
752
753static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
754 LocationSummary* locations = new (arena) LocationSummary(invoke,
755 LocationSummary::kNoCall,
756 kIntrinsified);
757 locations->SetInAt(0, Location::RequiresRegister());
758 locations->SetInAt(1, Location::RequiresRegister());
759 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
760}
761
762void IntrinsicLocationsBuilderARMVIXL::VisitMathMinIntInt(HInvoke* invoke) {
763 CreateIntIntToIntLocations(arena_, invoke);
764}
765
766void IntrinsicCodeGeneratorARMVIXL::VisitMathMinIntInt(HInvoke* invoke) {
767 GenMinMax(invoke, /* is_min */ true, GetAssembler());
768}
769
770void IntrinsicLocationsBuilderARMVIXL::VisitMathMaxIntInt(HInvoke* invoke) {
771 CreateIntIntToIntLocations(arena_, invoke);
772}
773
774void IntrinsicCodeGeneratorARMVIXL::VisitMathMaxIntInt(HInvoke* invoke) {
775 GenMinMax(invoke, /* is_min */ false, GetAssembler());
776}
777
778void IntrinsicLocationsBuilderARMVIXL::VisitMathSqrt(HInvoke* invoke) {
779 CreateFPToFPLocations(arena_, invoke);
780}
781
782void IntrinsicCodeGeneratorARMVIXL::VisitMathSqrt(HInvoke* invoke) {
783 ArmVIXLAssembler* assembler = GetAssembler();
784 __ Vsqrt(OutputDRegister(invoke), InputDRegisterAt(invoke, 0));
785}
786
xueliang.zhong6099d5e2016-04-20 18:44:56 +0100787void IntrinsicLocationsBuilderARMVIXL::VisitMathRint(HInvoke* invoke) {
788 if (features_.HasARMv8AInstructions()) {
789 CreateFPToFPLocations(arena_, invoke);
790 }
791}
792
793void IntrinsicCodeGeneratorARMVIXL::VisitMathRint(HInvoke* invoke) {
794 DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions());
795 ArmVIXLAssembler* assembler = GetAssembler();
796 __ Vrintn(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0));
797}
798
xueliang.zhong53463ba2017-02-16 15:18:03 +0000799void IntrinsicLocationsBuilderARMVIXL::VisitMathRoundFloat(HInvoke* invoke) {
800 if (features_.HasARMv8AInstructions()) {
801 LocationSummary* locations = new (arena_) LocationSummary(invoke,
802 LocationSummary::kNoCall,
803 kIntrinsified);
804 locations->SetInAt(0, Location::RequiresFpuRegister());
805 locations->SetOut(Location::RequiresRegister());
806 locations->AddTemp(Location::RequiresFpuRegister());
807 }
808}
809
810void IntrinsicCodeGeneratorARMVIXL::VisitMathRoundFloat(HInvoke* invoke) {
811 DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions());
812
813 ArmVIXLAssembler* assembler = GetAssembler();
814 vixl32::SRegister in_reg = InputSRegisterAt(invoke, 0);
815 vixl32::Register out_reg = OutputRegister(invoke);
816 vixl32::SRegister temp1 = LowSRegisterFrom(invoke->GetLocations()->GetTemp(0));
817 vixl32::SRegister temp2 = HighSRegisterFrom(invoke->GetLocations()->GetTemp(0));
818 vixl32::Label done;
819 vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &done);
820
821 // Round to nearest integer, ties away from zero.
822 __ Vcvta(S32, F32, temp1, in_reg);
823 __ Vmov(out_reg, temp1);
824
825 // For positive, zero or NaN inputs, rounding is done.
826 __ Cmp(out_reg, 0);
827 __ B(ge, final_label, /* far_target */ false);
828
829 // Handle input < 0 cases.
830 // If input is negative but not a tie, previous result (round to nearest) is valid.
831 // If input is a negative tie, change rounding direction to positive infinity, out_reg += 1.
832 __ Vrinta(F32, F32, temp1, in_reg);
833 __ Vmov(temp2, 0.5);
834 __ Vsub(F32, temp1, in_reg, temp1);
835 __ Vcmp(F32, temp1, temp2);
836 __ Vmrs(RegisterOrAPSR_nzcv(kPcCode), FPSCR);
837 {
838 // Use ExactAsemblyScope here because we are using IT.
839 ExactAssemblyScope it_scope(assembler->GetVIXLAssembler(),
840 2 * kMaxInstructionSizeInBytes,
841 CodeBufferCheckScope::kMaximumSize);
842 __ it(eq);
843 __ add(eq, out_reg, out_reg, 1);
844 }
845
846 if (done.IsReferenced()) {
847 __ Bind(&done);
848 }
849}
850
Anton Kirilov5ec62182016-10-13 20:16:02 +0100851void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekByte(HInvoke* invoke) {
852 CreateIntToIntLocations(arena_, invoke);
853}
854
855void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekByte(HInvoke* invoke) {
856 ArmVIXLAssembler* assembler = GetAssembler();
857 // Ignore upper 4B of long address.
Scott Wakelingb77051e2016-11-21 19:46:00 +0000858 __ Ldrsb(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100859}
860
861void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekIntNative(HInvoke* invoke) {
862 CreateIntToIntLocations(arena_, invoke);
863}
864
865void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekIntNative(HInvoke* invoke) {
866 ArmVIXLAssembler* assembler = GetAssembler();
867 // Ignore upper 4B of long address.
Scott Wakelingb77051e2016-11-21 19:46:00 +0000868 __ Ldr(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100869}
870
871void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekLongNative(HInvoke* invoke) {
872 CreateIntToIntLocations(arena_, invoke);
873}
874
875void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekLongNative(HInvoke* invoke) {
876 ArmVIXLAssembler* assembler = GetAssembler();
877 // Ignore upper 4B of long address.
878 vixl32::Register addr = LowRegisterFrom(invoke->GetLocations()->InAt(0));
879 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
880 // exception. So we can't use ldrd as addr may be unaligned.
881 vixl32::Register lo = LowRegisterFrom(invoke->GetLocations()->Out());
882 vixl32::Register hi = HighRegisterFrom(invoke->GetLocations()->Out());
883 if (addr.Is(lo)) {
884 __ Ldr(hi, MemOperand(addr, 4));
Scott Wakelingb77051e2016-11-21 19:46:00 +0000885 __ Ldr(lo, MemOperand(addr));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100886 } else {
Scott Wakelingb77051e2016-11-21 19:46:00 +0000887 __ Ldr(lo, MemOperand(addr));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100888 __ Ldr(hi, MemOperand(addr, 4));
889 }
890}
891
892void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPeekShortNative(HInvoke* invoke) {
893 CreateIntToIntLocations(arena_, invoke);
894}
895
896void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPeekShortNative(HInvoke* invoke) {
897 ArmVIXLAssembler* assembler = GetAssembler();
898 // Ignore upper 4B of long address.
Scott Wakelingb77051e2016-11-21 19:46:00 +0000899 __ Ldrsh(OutputRegister(invoke), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100900}
901
902static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
903 LocationSummary* locations = new (arena) LocationSummary(invoke,
904 LocationSummary::kNoCall,
905 kIntrinsified);
906 locations->SetInAt(0, Location::RequiresRegister());
907 locations->SetInAt(1, Location::RequiresRegister());
908}
909
910void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeByte(HInvoke* invoke) {
911 CreateIntIntToVoidLocations(arena_, invoke);
912}
913
914void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeByte(HInvoke* invoke) {
915 ArmVIXLAssembler* assembler = GetAssembler();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000916 __ Strb(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100917}
918
919void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeIntNative(HInvoke* invoke) {
920 CreateIntIntToVoidLocations(arena_, invoke);
921}
922
923void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeIntNative(HInvoke* invoke) {
924 ArmVIXLAssembler* assembler = GetAssembler();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000925 __ Str(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100926}
927
928void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeLongNative(HInvoke* invoke) {
929 CreateIntIntToVoidLocations(arena_, invoke);
930}
931
932void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeLongNative(HInvoke* invoke) {
933 ArmVIXLAssembler* assembler = GetAssembler();
934 // Ignore upper 4B of long address.
935 vixl32::Register addr = LowRegisterFrom(invoke->GetLocations()->InAt(0));
936 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
937 // exception. So we can't use ldrd as addr may be unaligned.
Scott Wakelingb77051e2016-11-21 19:46:00 +0000938 __ Str(LowRegisterFrom(invoke->GetLocations()->InAt(1)), MemOperand(addr));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100939 __ Str(HighRegisterFrom(invoke->GetLocations()->InAt(1)), MemOperand(addr, 4));
940}
941
942void IntrinsicLocationsBuilderARMVIXL::VisitMemoryPokeShortNative(HInvoke* invoke) {
943 CreateIntIntToVoidLocations(arena_, invoke);
944}
945
946void IntrinsicCodeGeneratorARMVIXL::VisitMemoryPokeShortNative(HInvoke* invoke) {
947 ArmVIXLAssembler* assembler = GetAssembler();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000948 __ Strh(InputRegisterAt(invoke, 1), MemOperand(LowRegisterFrom(invoke->GetLocations()->InAt(0))));
Anton Kirilov5ec62182016-10-13 20:16:02 +0100949}
950
951void IntrinsicLocationsBuilderARMVIXL::VisitThreadCurrentThread(HInvoke* invoke) {
952 LocationSummary* locations = new (arena_) LocationSummary(invoke,
953 LocationSummary::kNoCall,
954 kIntrinsified);
955 locations->SetOut(Location::RequiresRegister());
956}
957
958void IntrinsicCodeGeneratorARMVIXL::VisitThreadCurrentThread(HInvoke* invoke) {
959 ArmVIXLAssembler* assembler = GetAssembler();
960 __ Ldr(OutputRegister(invoke),
961 MemOperand(tr, Thread::PeerOffset<kArmPointerSize>().Int32Value()));
962}
963
964static void GenUnsafeGet(HInvoke* invoke,
965 Primitive::Type type,
966 bool is_volatile,
967 CodeGeneratorARMVIXL* codegen) {
968 LocationSummary* locations = invoke->GetLocations();
969 ArmVIXLAssembler* assembler = codegen->GetAssembler();
970 Location base_loc = locations->InAt(1);
971 vixl32::Register base = InputRegisterAt(invoke, 1); // Object pointer.
972 Location offset_loc = locations->InAt(2);
973 vixl32::Register offset = LowRegisterFrom(offset_loc); // Long offset, lo part only.
974 Location trg_loc = locations->Out();
975
976 switch (type) {
977 case Primitive::kPrimInt: {
978 vixl32::Register trg = RegisterFrom(trg_loc);
979 __ Ldr(trg, MemOperand(base, offset));
980 if (is_volatile) {
981 __ Dmb(vixl32::ISH);
982 }
983 break;
984 }
985
986 case Primitive::kPrimNot: {
987 vixl32::Register trg = RegisterFrom(trg_loc);
988 if (kEmitCompilerReadBarrier) {
989 if (kUseBakerReadBarrier) {
990 Location temp = locations->GetTemp(0);
991 codegen->GenerateReferenceLoadWithBakerReadBarrier(
992 invoke, trg_loc, base, 0U, offset_loc, TIMES_1, temp, /* needs_null_check */ false);
993 if (is_volatile) {
994 __ Dmb(vixl32::ISH);
995 }
996 } else {
997 __ Ldr(trg, MemOperand(base, offset));
998 if (is_volatile) {
999 __ Dmb(vixl32::ISH);
1000 }
1001 codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc);
1002 }
1003 } else {
1004 __ Ldr(trg, MemOperand(base, offset));
1005 if (is_volatile) {
1006 __ Dmb(vixl32::ISH);
1007 }
1008 assembler->MaybeUnpoisonHeapReference(trg);
1009 }
1010 break;
1011 }
1012
1013 case Primitive::kPrimLong: {
1014 vixl32::Register trg_lo = LowRegisterFrom(trg_loc);
1015 vixl32::Register trg_hi = HighRegisterFrom(trg_loc);
1016 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
Artem Serov657022c2016-11-23 14:19:38 +00001017 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
1018 const vixl32::Register temp_reg = temps.Acquire();
1019 __ Add(temp_reg, base, offset);
1020 __ Ldrexd(trg_lo, trg_hi, MemOperand(temp_reg));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001021 } else {
1022 __ Ldrd(trg_lo, trg_hi, MemOperand(base, offset));
1023 }
1024 if (is_volatile) {
1025 __ Dmb(vixl32::ISH);
1026 }
1027 break;
1028 }
1029
1030 default:
1031 LOG(FATAL) << "Unexpected type " << type;
1032 UNREACHABLE();
1033 }
1034}
1035
1036static void CreateIntIntIntToIntLocations(ArenaAllocator* arena,
1037 HInvoke* invoke,
1038 Primitive::Type type) {
1039 bool can_call = kEmitCompilerReadBarrier &&
1040 (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject ||
1041 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile);
1042 LocationSummary* locations = new (arena) LocationSummary(invoke,
1043 (can_call
1044 ? LocationSummary::kCallOnSlowPath
1045 : LocationSummary::kNoCall),
1046 kIntrinsified);
1047 if (can_call && kUseBakerReadBarrier) {
1048 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
1049 }
1050 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1051 locations->SetInAt(1, Location::RequiresRegister());
1052 locations->SetInAt(2, Location::RequiresRegister());
1053 locations->SetOut(Location::RequiresRegister(),
1054 (can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap));
1055 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1056 // We need a temporary register for the read barrier marking slow
Roland Levillain9983e302017-07-14 14:34:22 +01001057 // path in CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001058 locations->AddTemp(Location::RequiresRegister());
1059 }
1060}
1061
1062void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGet(HInvoke* invoke) {
1063 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
1064}
1065void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetVolatile(HInvoke* invoke) {
1066 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
1067}
1068void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetLong(HInvoke* invoke) {
1069 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
1070}
1071void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1072 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
1073}
1074void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetObject(HInvoke* invoke) {
1075 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
1076}
1077void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1078 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
1079}
1080
1081void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGet(HInvoke* invoke) {
1082 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_);
1083}
1084void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetVolatile(HInvoke* invoke) {
1085 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_);
1086}
1087void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetLong(HInvoke* invoke) {
1088 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_);
1089}
1090void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1091 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_);
1092}
1093void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetObject(HInvoke* invoke) {
1094 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_);
1095}
1096void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1097 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_);
1098}
1099
1100static void CreateIntIntIntIntToVoid(ArenaAllocator* arena,
1101 const ArmInstructionSetFeatures& features,
1102 Primitive::Type type,
1103 bool is_volatile,
1104 HInvoke* invoke) {
1105 LocationSummary* locations = new (arena) LocationSummary(invoke,
1106 LocationSummary::kNoCall,
1107 kIntrinsified);
1108 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1109 locations->SetInAt(1, Location::RequiresRegister());
1110 locations->SetInAt(2, Location::RequiresRegister());
1111 locations->SetInAt(3, Location::RequiresRegister());
1112
1113 if (type == Primitive::kPrimLong) {
1114 // Potentially need temps for ldrexd-strexd loop.
1115 if (is_volatile && !features.HasAtomicLdrdAndStrd()) {
1116 locations->AddTemp(Location::RequiresRegister()); // Temp_lo.
1117 locations->AddTemp(Location::RequiresRegister()); // Temp_hi.
1118 }
1119 } else if (type == Primitive::kPrimNot) {
1120 // Temps for card-marking.
1121 locations->AddTemp(Location::RequiresRegister()); // Temp.
1122 locations->AddTemp(Location::RequiresRegister()); // Card.
1123 }
1124}
1125
1126void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePut(HInvoke* invoke) {
1127 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
1128}
1129void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutOrdered(HInvoke* invoke) {
1130 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
1131}
1132void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutVolatile(HInvoke* invoke) {
1133 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke);
1134}
1135void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObject(HInvoke* invoke) {
1136 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
1137}
1138void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1139 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
1140}
1141void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1142 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke);
1143}
1144void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLong(HInvoke* invoke) {
1145 CreateIntIntIntIntToVoid(
1146 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
1147}
1148void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1149 CreateIntIntIntIntToVoid(
1150 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
1151}
1152void IntrinsicLocationsBuilderARMVIXL::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1153 CreateIntIntIntIntToVoid(
1154 arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke);
1155}
1156
1157static void GenUnsafePut(LocationSummary* locations,
1158 Primitive::Type type,
1159 bool is_volatile,
1160 bool is_ordered,
1161 CodeGeneratorARMVIXL* codegen) {
1162 ArmVIXLAssembler* assembler = codegen->GetAssembler();
1163
1164 vixl32::Register base = RegisterFrom(locations->InAt(1)); // Object pointer.
1165 vixl32::Register offset = LowRegisterFrom(locations->InAt(2)); // Long offset, lo part only.
1166 vixl32::Register value;
1167
1168 if (is_volatile || is_ordered) {
1169 __ Dmb(vixl32::ISH);
1170 }
1171
1172 if (type == Primitive::kPrimLong) {
1173 vixl32::Register value_lo = LowRegisterFrom(locations->InAt(3));
1174 vixl32::Register value_hi = HighRegisterFrom(locations->InAt(3));
1175 value = value_lo;
1176 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
1177 vixl32::Register temp_lo = RegisterFrom(locations->GetTemp(0));
1178 vixl32::Register temp_hi = RegisterFrom(locations->GetTemp(1));
1179 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
1180 const vixl32::Register temp_reg = temps.Acquire();
1181
1182 __ Add(temp_reg, base, offset);
1183 vixl32::Label loop_head;
1184 __ Bind(&loop_head);
Scott Wakelingb77051e2016-11-21 19:46:00 +00001185 __ Ldrexd(temp_lo, temp_hi, MemOperand(temp_reg));
1186 __ Strexd(temp_lo, value_lo, value_hi, MemOperand(temp_reg));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001187 __ Cmp(temp_lo, 0);
Artem Serov517d9f62016-12-12 15:51:15 +00001188 __ B(ne, &loop_head, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001189 } else {
1190 __ Strd(value_lo, value_hi, MemOperand(base, offset));
1191 }
1192 } else {
1193 value = RegisterFrom(locations->InAt(3));
1194 vixl32::Register source = value;
1195 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
1196 vixl32::Register temp = RegisterFrom(locations->GetTemp(0));
1197 __ Mov(temp, value);
1198 assembler->PoisonHeapReference(temp);
1199 source = temp;
1200 }
1201 __ Str(source, MemOperand(base, offset));
1202 }
1203
1204 if (is_volatile) {
1205 __ Dmb(vixl32::ISH);
1206 }
1207
1208 if (type == Primitive::kPrimNot) {
1209 vixl32::Register temp = RegisterFrom(locations->GetTemp(0));
1210 vixl32::Register card = RegisterFrom(locations->GetTemp(1));
1211 bool value_can_be_null = true; // TODO: Worth finding out this information?
1212 codegen->MarkGCCard(temp, card, base, value, value_can_be_null);
1213 }
1214}
1215
1216void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePut(HInvoke* invoke) {
1217 GenUnsafePut(invoke->GetLocations(),
1218 Primitive::kPrimInt,
1219 /* is_volatile */ false,
1220 /* is_ordered */ false,
1221 codegen_);
1222}
1223void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutOrdered(HInvoke* invoke) {
1224 GenUnsafePut(invoke->GetLocations(),
1225 Primitive::kPrimInt,
1226 /* is_volatile */ false,
1227 /* is_ordered */ true,
1228 codegen_);
1229}
1230void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutVolatile(HInvoke* invoke) {
1231 GenUnsafePut(invoke->GetLocations(),
1232 Primitive::kPrimInt,
1233 /* is_volatile */ true,
1234 /* is_ordered */ false,
1235 codegen_);
1236}
1237void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObject(HInvoke* invoke) {
1238 GenUnsafePut(invoke->GetLocations(),
1239 Primitive::kPrimNot,
1240 /* is_volatile */ false,
1241 /* is_ordered */ false,
1242 codegen_);
1243}
1244void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1245 GenUnsafePut(invoke->GetLocations(),
1246 Primitive::kPrimNot,
1247 /* is_volatile */ false,
1248 /* is_ordered */ true,
1249 codegen_);
1250}
1251void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1252 GenUnsafePut(invoke->GetLocations(),
1253 Primitive::kPrimNot,
1254 /* is_volatile */ true,
1255 /* is_ordered */ false,
1256 codegen_);
1257}
1258void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLong(HInvoke* invoke) {
1259 GenUnsafePut(invoke->GetLocations(),
1260 Primitive::kPrimLong,
1261 /* is_volatile */ false,
1262 /* is_ordered */ false,
1263 codegen_);
1264}
1265void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1266 GenUnsafePut(invoke->GetLocations(),
1267 Primitive::kPrimLong,
1268 /* is_volatile */ false,
1269 /* is_ordered */ true,
1270 codegen_);
1271}
1272void IntrinsicCodeGeneratorARMVIXL::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1273 GenUnsafePut(invoke->GetLocations(),
1274 Primitive::kPrimLong,
1275 /* is_volatile */ true,
1276 /* is_ordered */ false,
1277 codegen_);
1278}
1279
1280static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena,
1281 HInvoke* invoke,
1282 Primitive::Type type) {
1283 bool can_call = kEmitCompilerReadBarrier &&
1284 kUseBakerReadBarrier &&
1285 (invoke->GetIntrinsic() == Intrinsics::kUnsafeCASObject);
1286 LocationSummary* locations = new (arena) LocationSummary(invoke,
1287 (can_call
1288 ? LocationSummary::kCallOnSlowPath
1289 : LocationSummary::kNoCall),
1290 kIntrinsified);
1291 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1292 locations->SetInAt(1, Location::RequiresRegister());
1293 locations->SetInAt(2, Location::RequiresRegister());
1294 locations->SetInAt(3, Location::RequiresRegister());
1295 locations->SetInAt(4, Location::RequiresRegister());
1296
1297 // If heap poisoning is enabled, we don't want the unpoisoning
1298 // operations to potentially clobber the output. Likewise when
1299 // emitting a (Baker) read barrier, which may call.
1300 Location::OutputOverlap overlaps =
1301 ((kPoisonHeapReferences && type == Primitive::kPrimNot) || can_call)
1302 ? Location::kOutputOverlap
1303 : Location::kNoOutputOverlap;
1304 locations->SetOut(Location::RequiresRegister(), overlaps);
1305
1306 // Temporary registers used in CAS. In the object case
1307 // (UnsafeCASObject intrinsic), these are also used for
1308 // card-marking, and possibly for (Baker) read barrier.
1309 locations->AddTemp(Location::RequiresRegister()); // Pointer.
1310 locations->AddTemp(Location::RequiresRegister()); // Temp 1.
1311}
1312
1313static void GenCas(HInvoke* invoke, Primitive::Type type, CodeGeneratorARMVIXL* codegen) {
1314 DCHECK_NE(type, Primitive::kPrimLong);
1315
1316 ArmVIXLAssembler* assembler = codegen->GetAssembler();
1317 LocationSummary* locations = invoke->GetLocations();
1318
1319 Location out_loc = locations->Out();
1320 vixl32::Register out = OutputRegister(invoke); // Boolean result.
1321
1322 vixl32::Register base = InputRegisterAt(invoke, 1); // Object pointer.
1323 Location offset_loc = locations->InAt(2);
1324 vixl32::Register offset = LowRegisterFrom(offset_loc); // Offset (discard high 4B).
1325 vixl32::Register expected = InputRegisterAt(invoke, 3); // Expected.
1326 vixl32::Register value = InputRegisterAt(invoke, 4); // Value.
1327
1328 Location tmp_ptr_loc = locations->GetTemp(0);
1329 vixl32::Register tmp_ptr = RegisterFrom(tmp_ptr_loc); // Pointer to actual memory.
1330 vixl32::Register tmp = RegisterFrom(locations->GetTemp(1)); // Value in memory.
1331
1332 if (type == Primitive::kPrimNot) {
1333 // The only read barrier implementation supporting the
1334 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1335 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
1336
1337 // Mark card for object assuming new value is stored. Worst case we will mark an unchanged
1338 // object and scan the receiver at the next GC for nothing.
1339 bool value_can_be_null = true; // TODO: Worth finding out this information?
1340 codegen->MarkGCCard(tmp_ptr, tmp, base, value, value_can_be_null);
1341
1342 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1343 // Need to make sure the reference stored in the field is a to-space
1344 // one before attempting the CAS or the CAS could fail incorrectly.
Roland Levillainff487002017-03-07 16:50:01 +00001345 codegen->UpdateReferenceFieldWithBakerReadBarrier(
Anton Kirilov5ec62182016-10-13 20:16:02 +01001346 invoke,
1347 out_loc, // Unused, used only as a "temporary" within the read barrier.
1348 base,
Roland Levillainff487002017-03-07 16:50:01 +00001349 /* field_offset */ offset_loc,
Anton Kirilov5ec62182016-10-13 20:16:02 +01001350 tmp_ptr_loc,
1351 /* needs_null_check */ false,
Roland Levillainff487002017-03-07 16:50:01 +00001352 tmp);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001353 }
1354 }
1355
1356 // Prevent reordering with prior memory operations.
1357 // Emit a DMB ISH instruction instead of an DMB ISHST one, as the
1358 // latter allows a preceding load to be delayed past the STXR
1359 // instruction below.
1360 __ Dmb(vixl32::ISH);
1361
1362 __ Add(tmp_ptr, base, offset);
1363
1364 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
1365 codegen->GetAssembler()->PoisonHeapReference(expected);
1366 if (value.Is(expected)) {
1367 // Do not poison `value`, as it is the same register as
1368 // `expected`, which has just been poisoned.
1369 } else {
1370 codegen->GetAssembler()->PoisonHeapReference(value);
1371 }
1372 }
1373
1374 // do {
1375 // tmp = [r_ptr] - expected;
1376 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
1377 // result = tmp != 0;
1378
1379 vixl32::Label loop_head;
1380 __ Bind(&loop_head);
1381
Scott Wakelingb77051e2016-11-21 19:46:00 +00001382 __ Ldrex(tmp, MemOperand(tmp_ptr));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001383
1384 __ Subs(tmp, tmp, expected);
1385
1386 {
Artem Serov0fb37192016-12-06 18:13:40 +00001387 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1388 3 * kMaxInstructionSizeInBytes,
1389 CodeBufferCheckScope::kMaximumSize);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001390
1391 __ itt(eq);
Scott Wakelingb77051e2016-11-21 19:46:00 +00001392 __ strex(eq, tmp, value, MemOperand(tmp_ptr));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001393 __ cmp(eq, tmp, 1);
1394 }
1395
Artem Serov517d9f62016-12-12 15:51:15 +00001396 __ B(eq, &loop_head, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001397
1398 __ Dmb(vixl32::ISH);
1399
1400 __ Rsbs(out, tmp, 1);
1401
1402 {
Artem Serov0fb37192016-12-06 18:13:40 +00001403 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1404 2 * kMaxInstructionSizeInBytes,
1405 CodeBufferCheckScope::kMaximumSize);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001406
1407 __ it(cc);
1408 __ mov(cc, out, 0);
1409 }
1410
1411 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
1412 codegen->GetAssembler()->UnpoisonHeapReference(expected);
1413 if (value.Is(expected)) {
1414 // Do not unpoison `value`, as it is the same register as
1415 // `expected`, which has just been unpoisoned.
1416 } else {
1417 codegen->GetAssembler()->UnpoisonHeapReference(value);
1418 }
1419 }
1420}
1421
1422void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeCASInt(HInvoke* invoke) {
1423 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt);
1424}
1425void IntrinsicLocationsBuilderARMVIXL::VisitUnsafeCASObject(HInvoke* invoke) {
1426 // The only read barrier implementation supporting the
1427 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1428 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
1429 return;
1430 }
1431
1432 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot);
1433}
1434void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeCASInt(HInvoke* invoke) {
1435 GenCas(invoke, Primitive::kPrimInt, codegen_);
1436}
1437void IntrinsicCodeGeneratorARMVIXL::VisitUnsafeCASObject(HInvoke* invoke) {
1438 // The only read barrier implementation supporting the
1439 // UnsafeCASObject intrinsic is the Baker-style read barriers.
1440 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
1441
1442 GenCas(invoke, Primitive::kPrimNot, codegen_);
1443}
1444
1445void IntrinsicLocationsBuilderARMVIXL::VisitStringCompareTo(HInvoke* invoke) {
1446 // The inputs plus one temp.
1447 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1448 invoke->InputAt(1)->CanBeNull()
1449 ? LocationSummary::kCallOnSlowPath
1450 : LocationSummary::kNoCall,
1451 kIntrinsified);
1452 locations->SetInAt(0, Location::RequiresRegister());
1453 locations->SetInAt(1, Location::RequiresRegister());
1454 locations->AddTemp(Location::RequiresRegister());
1455 locations->AddTemp(Location::RequiresRegister());
1456 locations->AddTemp(Location::RequiresRegister());
1457 // Need temporary registers for String compression's feature.
1458 if (mirror::kUseStringCompression) {
1459 locations->AddTemp(Location::RequiresRegister());
Anton Kirilov5ec62182016-10-13 20:16:02 +01001460 }
1461 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1462}
1463
1464void IntrinsicCodeGeneratorARMVIXL::VisitStringCompareTo(HInvoke* invoke) {
1465 ArmVIXLAssembler* assembler = GetAssembler();
1466 LocationSummary* locations = invoke->GetLocations();
1467
1468 vixl32::Register str = InputRegisterAt(invoke, 0);
1469 vixl32::Register arg = InputRegisterAt(invoke, 1);
1470 vixl32::Register out = OutputRegister(invoke);
1471
1472 vixl32::Register temp0 = RegisterFrom(locations->GetTemp(0));
1473 vixl32::Register temp1 = RegisterFrom(locations->GetTemp(1));
1474 vixl32::Register temp2 = RegisterFrom(locations->GetTemp(2));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001475 vixl32::Register temp3;
Anton Kirilov5ec62182016-10-13 20:16:02 +01001476 if (mirror::kUseStringCompression) {
1477 temp3 = RegisterFrom(locations->GetTemp(3));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001478 }
1479
1480 vixl32::Label loop;
1481 vixl32::Label find_char_diff;
1482 vixl32::Label end;
1483 vixl32::Label different_compression;
1484
1485 // Get offsets of count and value fields within a string object.
1486 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1487 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1488
1489 // Note that the null check must have been done earlier.
1490 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1491
1492 // Take slow path and throw if input can be and is null.
1493 SlowPathCodeARMVIXL* slow_path = nullptr;
1494 const bool can_slow_path = invoke->InputAt(1)->CanBeNull();
1495 if (can_slow_path) {
1496 slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke);
1497 codegen_->AddSlowPath(slow_path);
xueliang.zhongf51bc622016-11-04 09:23:32 +00001498 __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01001499 }
1500
1501 // Reference equality check, return 0 if same reference.
1502 __ Subs(out, str, arg);
1503 __ B(eq, &end);
1504
Anton Kirilov5ec62182016-10-13 20:16:02 +01001505 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001506 // Load `count` fields of this and argument strings.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001507 __ Ldr(temp3, MemOperand(str, count_offset));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001508 __ Ldr(temp2, MemOperand(arg, count_offset));
1509 // Extract lengths from the `count` fields.
1510 __ Lsr(temp0, temp3, 1u);
1511 __ Lsr(temp1, temp2, 1u);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001512 } else {
1513 // Load lengths of this and argument strings.
1514 __ Ldr(temp0, MemOperand(str, count_offset));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001515 __ Ldr(temp1, MemOperand(arg, count_offset));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001516 }
1517 // out = length diff.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001518 __ Subs(out, temp0, temp1);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001519 // temp0 = min(len(str), len(arg)).
1520
1521 {
Artem Serov0fb37192016-12-06 18:13:40 +00001522 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1523 2 * kMaxInstructionSizeInBytes,
1524 CodeBufferCheckScope::kMaximumSize);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001525
1526 __ it(gt);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001527 __ mov(gt, temp0, temp1);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001528 }
1529
Anton Kirilov5ec62182016-10-13 20:16:02 +01001530 // Shorter string is empty?
xueliang.zhongf51bc622016-11-04 09:23:32 +00001531 // Note that mirror::kUseStringCompression==true introduces lots of instructions,
1532 // which makes &end label far away from this branch and makes it not 'CBZ-encodable'.
1533 __ CompareAndBranchIfZero(temp0, &end, mirror::kUseStringCompression);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001534
1535 if (mirror::kUseStringCompression) {
1536 // Check if both strings using same compression style to use this comparison loop.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001537 __ Eors(temp2, temp2, temp3);
1538 __ Lsrs(temp2, temp2, 1u);
1539 __ B(cs, &different_compression);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001540 // For string compression, calculate the number of bytes to compare (not chars).
1541 // This could in theory exceed INT32_MAX, so treat temp0 as unsigned.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001542 __ Lsls(temp3, temp3, 31u); // Extract purely the compression flag.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001543
Artem Serov0fb37192016-12-06 18:13:40 +00001544 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1545 2 * kMaxInstructionSizeInBytes,
1546 CodeBufferCheckScope::kMaximumSize);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001547
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001548 __ it(ne);
1549 __ add(ne, temp0, temp0, temp0);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001550 }
1551
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001552 // Store offset of string value in preparation for comparison loop.
1553 __ Mov(temp1, value_offset);
1554
Anton Kirilov5ec62182016-10-13 20:16:02 +01001555 // Assertions that must hold in order to compare multiple characters at a time.
1556 CHECK_ALIGNED(value_offset, 8);
1557 static_assert(IsAligned<8>(kObjectAlignment),
1558 "String data must be 8-byte aligned for unrolled CompareTo loop.");
1559
Scott Wakelingb77051e2016-11-21 19:46:00 +00001560 const unsigned char_size = Primitive::ComponentSize(Primitive::kPrimChar);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001561 DCHECK_EQ(char_size, 2u);
1562
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001563 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
1564
Anton Kirilov5ec62182016-10-13 20:16:02 +01001565 vixl32::Label find_char_diff_2nd_cmp;
1566 // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment).
1567 __ Bind(&loop);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001568 vixl32::Register temp_reg = temps.Acquire();
Anton Kirilov5ec62182016-10-13 20:16:02 +01001569 __ Ldr(temp_reg, MemOperand(str, temp1));
1570 __ Ldr(temp2, MemOperand(arg, temp1));
1571 __ Cmp(temp_reg, temp2);
Artem Serov517d9f62016-12-12 15:51:15 +00001572 __ B(ne, &find_char_diff, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001573 __ Add(temp1, temp1, char_size * 2);
1574
1575 __ Ldr(temp_reg, MemOperand(str, temp1));
1576 __ Ldr(temp2, MemOperand(arg, temp1));
1577 __ Cmp(temp_reg, temp2);
Artem Serov517d9f62016-12-12 15:51:15 +00001578 __ B(ne, &find_char_diff_2nd_cmp, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001579 __ Add(temp1, temp1, char_size * 2);
1580 // With string compression, we have compared 8 bytes, otherwise 4 chars.
1581 __ Subs(temp0, temp0, (mirror::kUseStringCompression ? 8 : 4));
Artem Serov517d9f62016-12-12 15:51:15 +00001582 __ B(hi, &loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001583 __ B(&end);
1584
1585 __ Bind(&find_char_diff_2nd_cmp);
1586 if (mirror::kUseStringCompression) {
1587 __ Subs(temp0, temp0, 4); // 4 bytes previously compared.
Artem Serov517d9f62016-12-12 15:51:15 +00001588 __ B(ls, &end, /* far_target */ false); // Was the second comparison fully beyond the end?
Anton Kirilov5ec62182016-10-13 20:16:02 +01001589 } else {
1590 // Without string compression, we can start treating temp0 as signed
1591 // and rely on the signed comparison below.
1592 __ Sub(temp0, temp0, 2);
1593 }
1594
1595 // Find the single character difference.
1596 __ Bind(&find_char_diff);
1597 // Get the bit position of the first character that differs.
1598 __ Eor(temp1, temp2, temp_reg);
1599 __ Rbit(temp1, temp1);
1600 __ Clz(temp1, temp1);
1601
1602 // temp0 = number of characters remaining to compare.
1603 // (Without string compression, it could be < 1 if a difference is found by the second CMP
1604 // in the comparison loop, and after the end of the shorter string data).
1605
1606 // Without string compression (temp1 >> 4) = character where difference occurs between the last
1607 // two words compared, in the interval [0,1].
1608 // (0 for low half-word different, 1 for high half-word different).
1609 // With string compression, (temp1 << 3) = byte where the difference occurs,
1610 // in the interval [0,3].
1611
1612 // If temp0 <= (temp1 >> (kUseStringCompression ? 3 : 4)), the difference occurs outside
1613 // the remaining string data, so just return length diff (out).
1614 // The comparison is unsigned for string compression, otherwise signed.
1615 __ Cmp(temp0, Operand(temp1, vixl32::LSR, (mirror::kUseStringCompression ? 3 : 4)));
Artem Serov517d9f62016-12-12 15:51:15 +00001616 __ B((mirror::kUseStringCompression ? ls : le), &end, /* far_target */ false);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001617
Anton Kirilov5ec62182016-10-13 20:16:02 +01001618 // Extract the characters and calculate the difference.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001619 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001620 // For compressed strings we need to clear 0x7 from temp1, for uncompressed we need to clear
1621 // 0xf. We also need to prepare the character extraction mask `uncompressed ? 0xffffu : 0xffu`.
1622 // The compression flag is now in the highest bit of temp3, so let's play some tricks.
Anton Kirilovb88c4842016-11-14 14:37:00 +00001623 __ Orr(temp3, temp3, 0xffu << 23); // uncompressed ? 0xff800000u : 0x7ff80000u
1624 __ Bic(temp1, temp1, Operand(temp3, vixl32::LSR, 31 - 3)); // &= ~(uncompressed ? 0xfu : 0x7u)
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001625 __ Asr(temp3, temp3, 7u); // uncompressed ? 0xffff0000u : 0xff0000u.
1626 __ Lsr(temp2, temp2, temp1); // Extract second character.
1627 __ Lsr(temp3, temp3, 16u); // uncompressed ? 0xffffu : 0xffu
1628 __ Lsr(out, temp_reg, temp1); // Extract first character.
Anton Kirilovb88c4842016-11-14 14:37:00 +00001629 __ And(temp2, temp2, temp3);
1630 __ And(out, out, temp3);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001631 } else {
Anton Kirilovb88c4842016-11-14 14:37:00 +00001632 __ Bic(temp1, temp1, 0xf);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001633 __ Lsr(temp2, temp2, temp1);
1634 __ Lsr(out, temp_reg, temp1);
Anton Kirilovb88c4842016-11-14 14:37:00 +00001635 __ Movt(temp2, 0);
1636 __ Movt(out, 0);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001637 }
Anton Kirilov5ec62182016-10-13 20:16:02 +01001638
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001639 __ Sub(out, out, temp2);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001640 temps.Release(temp_reg);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001641
1642 if (mirror::kUseStringCompression) {
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001643 __ B(&end);
1644 __ Bind(&different_compression);
1645
1646 // Comparison for different compression style.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001647 const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte);
1648 DCHECK_EQ(c_char_size, 1u);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001649
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001650 // We want to free up the temp3, currently holding `str.count`, for comparison.
1651 // So, we move it to the bottom bit of the iteration count `temp0` which we tnen
1652 // need to treat as unsigned. Start by freeing the bit with an ADD and continue
1653 // further down by a LSRS+SBC which will flip the meaning of the flag but allow
1654 // `subs temp0, #2; bhi different_compression_loop` to serve as the loop condition.
Anton Kirilovb88c4842016-11-14 14:37:00 +00001655 __ Add(temp0, temp0, temp0); // Unlike LSL, this ADD is always 16-bit.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001656 // `temp1` will hold the compressed data pointer, `temp2` the uncompressed data pointer.
Anton Kirilovb88c4842016-11-14 14:37:00 +00001657 __ Mov(temp1, str);
1658 __ Mov(temp2, arg);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001659 __ Lsrs(temp3, temp3, 1u); // Continue the move of the compression flag.
1660 {
Artem Serov0fb37192016-12-06 18:13:40 +00001661 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1662 3 * kMaxInstructionSizeInBytes,
1663 CodeBufferCheckScope::kMaximumSize);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001664 __ itt(cs); // Interleave with selection of temp1 and temp2.
1665 __ mov(cs, temp1, arg); // Preserves flags.
1666 __ mov(cs, temp2, str); // Preserves flags.
1667 }
Anton Kirilovb88c4842016-11-14 14:37:00 +00001668 __ Sbc(temp0, temp0, 0); // Complete the move of the compression flag.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001669
1670 // Adjust temp1 and temp2 from string pointers to data pointers.
Anton Kirilovb88c4842016-11-14 14:37:00 +00001671 __ Add(temp1, temp1, value_offset);
1672 __ Add(temp2, temp2, value_offset);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001673
1674 vixl32::Label different_compression_loop;
1675 vixl32::Label different_compression_diff;
1676
1677 // Main loop for different compression.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001678 temp_reg = temps.Acquire();
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001679 __ Bind(&different_compression_loop);
1680 __ Ldrb(temp_reg, MemOperand(temp1, c_char_size, PostIndex));
1681 __ Ldrh(temp3, MemOperand(temp2, char_size, PostIndex));
Anton Kirilovb88c4842016-11-14 14:37:00 +00001682 __ Cmp(temp_reg, temp3);
Artem Serov517d9f62016-12-12 15:51:15 +00001683 __ B(ne, &different_compression_diff, /* far_target */ false);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001684 __ Subs(temp0, temp0, 2);
Artem Serov517d9f62016-12-12 15:51:15 +00001685 __ B(hi, &different_compression_loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001686 __ B(&end);
1687
1688 // Calculate the difference.
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001689 __ Bind(&different_compression_diff);
1690 __ Sub(out, temp_reg, temp3);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001691 temps.Release(temp_reg);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001692 // Flip the difference if the `arg` is compressed.
1693 // `temp0` contains inverted `str` compression flag, i.e the same as `arg` compression flag.
1694 __ Lsrs(temp0, temp0, 1u);
1695 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
1696 "Expecting 0=compressed, 1=uncompressed");
1697
Artem Serov0fb37192016-12-06 18:13:40 +00001698 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1699 2 * kMaxInstructionSizeInBytes,
1700 CodeBufferCheckScope::kMaximumSize);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001701 __ it(cc);
1702 __ rsb(cc, out, out, 0);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001703 }
1704
1705 __ Bind(&end);
1706
1707 if (can_slow_path) {
1708 __ Bind(slow_path->GetExitLabel());
1709 }
1710}
1711
Vladimir Marko984519c2017-08-23 10:45:29 +01001712// The cut off for unrolling the loop in String.equals() intrinsic for const strings.
1713// The normal loop plus the pre-header is 9 instructions (18-26 bytes) without string compression
1714// and 12 instructions (24-32 bytes) with string compression. We can compare up to 4 bytes in 4
1715// instructions (LDR+LDR+CMP+BNE) and up to 8 bytes in 6 instructions (LDRD+LDRD+CMP+BNE+CMP+BNE).
1716// Allow up to 12 instructions (32 bytes) for the unrolled loop.
1717constexpr size_t kShortConstStringEqualsCutoffInBytes = 16;
1718
1719static const char* GetConstString(HInstruction* candidate, uint32_t* utf16_length) {
1720 if (candidate->IsLoadString()) {
1721 HLoadString* load_string = candidate->AsLoadString();
1722 const DexFile& dex_file = load_string->GetDexFile();
1723 return dex_file.StringDataAndUtf16LengthByIdx(load_string->GetStringIndex(), utf16_length);
1724 }
1725 return nullptr;
1726}
1727
Anton Kirilov5ec62182016-10-13 20:16:02 +01001728void IntrinsicLocationsBuilderARMVIXL::VisitStringEquals(HInvoke* invoke) {
1729 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1730 LocationSummary::kNoCall,
1731 kIntrinsified);
1732 InvokeRuntimeCallingConventionARMVIXL calling_convention;
1733 locations->SetInAt(0, Location::RequiresRegister());
1734 locations->SetInAt(1, Location::RequiresRegister());
Vladimir Marko984519c2017-08-23 10:45:29 +01001735
Anton Kirilov5ec62182016-10-13 20:16:02 +01001736 // Temporary registers to store lengths of strings and for calculations.
1737 // Using instruction cbz requires a low register, so explicitly set a temp to be R0.
1738 locations->AddTemp(LocationFrom(r0));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001739
Vladimir Marko984519c2017-08-23 10:45:29 +01001740 // For the generic implementation and for long const strings we need an extra temporary.
1741 // We do not need it for short const strings, up to 4 bytes, see code generation below.
1742 uint32_t const_string_length = 0u;
1743 const char* const_string = GetConstString(invoke->InputAt(0), &const_string_length);
1744 if (const_string == nullptr) {
1745 const_string = GetConstString(invoke->InputAt(1), &const_string_length);
1746 }
1747 bool is_compressed =
1748 mirror::kUseStringCompression &&
1749 const_string != nullptr &&
1750 mirror::String::DexFileStringAllASCII(const_string, const_string_length);
1751 if (const_string == nullptr || const_string_length > (is_compressed ? 4u : 2u)) {
1752 locations->AddTemp(Location::RequiresRegister());
1753 }
1754
1755 // TODO: If the String.equals() is used only for an immediately following HIf, we can
1756 // mark it as emitted-at-use-site and emit branches directly to the appropriate blocks.
1757 // Then we shall need an extra temporary register instead of the output register.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001758 locations->SetOut(Location::RequiresRegister());
1759}
1760
1761void IntrinsicCodeGeneratorARMVIXL::VisitStringEquals(HInvoke* invoke) {
1762 ArmVIXLAssembler* assembler = GetAssembler();
1763 LocationSummary* locations = invoke->GetLocations();
1764
1765 vixl32::Register str = InputRegisterAt(invoke, 0);
1766 vixl32::Register arg = InputRegisterAt(invoke, 1);
1767 vixl32::Register out = OutputRegister(invoke);
1768
1769 vixl32::Register temp = RegisterFrom(locations->GetTemp(0));
Anton Kirilov5ec62182016-10-13 20:16:02 +01001770
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001771 vixl32::Label loop;
Anton Kirilov5ec62182016-10-13 20:16:02 +01001772 vixl32::Label end;
1773 vixl32::Label return_true;
1774 vixl32::Label return_false;
Anton Kirilov6f644202017-02-27 18:29:45 +00001775 vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &end);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001776
1777 // Get offsets of count, value, and class fields within a string object.
1778 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1779 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1780 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1781
1782 // Note that the null check must have been done earlier.
1783 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1784
1785 StringEqualsOptimizations optimizations(invoke);
1786 if (!optimizations.GetArgumentNotNull()) {
1787 // Check if input is null, return false if it is.
xueliang.zhongf51bc622016-11-04 09:23:32 +00001788 __ CompareAndBranchIfZero(arg, &return_false, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001789 }
1790
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001791 // Reference equality check, return true if same reference.
1792 __ Cmp(str, arg);
Artem Serov517d9f62016-12-12 15:51:15 +00001793 __ B(eq, &return_true, /* far_target */ false);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001794
Anton Kirilov5ec62182016-10-13 20:16:02 +01001795 if (!optimizations.GetArgumentIsString()) {
1796 // Instanceof check for the argument by comparing class fields.
1797 // All string objects must have the same type since String cannot be subclassed.
1798 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1799 // If the argument is a string object, its class field must be equal to receiver's class field.
1800 __ Ldr(temp, MemOperand(str, class_offset));
Vladimir Marko984519c2017-08-23 10:45:29 +01001801 __ Ldr(out, MemOperand(arg, class_offset));
1802 __ Cmp(temp, out);
Artem Serov517d9f62016-12-12 15:51:15 +00001803 __ B(ne, &return_false, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001804 }
1805
Vladimir Marko984519c2017-08-23 10:45:29 +01001806 // Check if one of the inputs is a const string. Do not special-case both strings
1807 // being const, such cases should be handled by constant folding if needed.
1808 uint32_t const_string_length = 0u;
1809 const char* const_string = GetConstString(invoke->InputAt(0), &const_string_length);
1810 if (const_string == nullptr) {
1811 const_string = GetConstString(invoke->InputAt(1), &const_string_length);
1812 if (const_string != nullptr) {
1813 std::swap(str, arg); // Make sure the const string is in `str`.
1814 }
1815 }
1816 bool is_compressed =
1817 mirror::kUseStringCompression &&
1818 const_string != nullptr &&
1819 mirror::String::DexFileStringAllASCII(const_string, const_string_length);
1820
1821 if (const_string != nullptr) {
1822 // Load `count` field of the argument string and check if it matches the const string.
1823 // Also compares the compression style, if differs return false.
1824 __ Ldr(temp, MemOperand(arg, count_offset));
1825 __ Cmp(temp, Operand(mirror::String::GetFlaggedCount(const_string_length, is_compressed)));
1826 __ B(ne, &return_false, /* far_target */ false);
1827 } else {
1828 // Load `count` fields of this and argument strings.
1829 __ Ldr(temp, MemOperand(str, count_offset));
1830 __ Ldr(out, MemOperand(arg, count_offset));
1831 // Check if `count` fields are equal, return false if they're not.
1832 // Also compares the compression style, if differs return false.
1833 __ Cmp(temp, out);
1834 __ B(ne, &return_false, /* far_target */ false);
1835 }
Anton Kirilov5ec62182016-10-13 20:16:02 +01001836
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001837 // Assertions that must hold in order to compare strings 4 bytes at a time.
Vladimir Marko984519c2017-08-23 10:45:29 +01001838 // Ok to do this because strings are zero-padded to kObjectAlignment.
Anton Kirilov5ec62182016-10-13 20:16:02 +01001839 DCHECK_ALIGNED(value_offset, 4);
1840 static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare.");
1841
Vladimir Marko984519c2017-08-23 10:45:29 +01001842 if (const_string != nullptr &&
1843 const_string_length <= (is_compressed ? kShortConstStringEqualsCutoffInBytes
1844 : kShortConstStringEqualsCutoffInBytes / 2u)) {
1845 // Load and compare the contents. Though we know the contents of the short const string
1846 // at compile time, materializing constants may be more code than loading from memory.
1847 int32_t offset = value_offset;
1848 size_t remaining_bytes =
1849 RoundUp(is_compressed ? const_string_length : const_string_length * 2u, 4u);
1850 while (remaining_bytes > sizeof(uint32_t)) {
1851 vixl32::Register temp1 = RegisterFrom(locations->GetTemp(1));
1852 UseScratchRegisterScope scratch_scope(assembler->GetVIXLAssembler());
1853 vixl32::Register temp2 = scratch_scope.Acquire();
1854 __ Ldrd(temp, temp1, MemOperand(str, offset));
1855 __ Ldrd(temp2, out, MemOperand(arg, offset));
1856 __ Cmp(temp, temp2);
1857 __ B(ne, &return_false, /* far_label */ false);
1858 __ Cmp(temp1, out);
1859 __ B(ne, &return_false, /* far_label */ false);
1860 offset += 2u * sizeof(uint32_t);
1861 remaining_bytes -= 2u * sizeof(uint32_t);
1862 }
1863 if (remaining_bytes != 0u) {
1864 __ Ldr(temp, MemOperand(str, offset));
1865 __ Ldr(out, MemOperand(arg, offset));
1866 __ Cmp(temp, out);
1867 __ B(ne, &return_false, /* far_label */ false);
1868 }
1869 } else {
1870 // Return true if both strings are empty. Even with string compression `count == 0` means empty.
1871 static_assert(static_cast<uint32_t>(mirror::StringCompressionFlag::kCompressed) == 0u,
1872 "Expecting 0=compressed, 1=uncompressed");
1873 __ CompareAndBranchIfZero(temp, &return_true, /* far_target */ false);
1874
1875 if (mirror::kUseStringCompression) {
1876 // For string compression, calculate the number of bytes to compare (not chars).
1877 // This could in theory exceed INT32_MAX, so treat temp as unsigned.
1878 __ Lsrs(temp, temp, 1u); // Extract length and check compression flag.
1879 ExactAssemblyScope aas(assembler->GetVIXLAssembler(),
1880 2 * kMaxInstructionSizeInBytes,
1881 CodeBufferCheckScope::kMaximumSize);
1882 __ it(cs); // If uncompressed,
1883 __ add(cs, temp, temp, temp); // double the byte count.
1884 }
1885
1886 vixl32::Register temp1 = RegisterFrom(locations->GetTemp(1));
1887 UseScratchRegisterScope scratch_scope(assembler->GetVIXLAssembler());
1888 vixl32::Register temp2 = scratch_scope.Acquire();
1889
1890 // Store offset of string value in preparation for comparison loop.
1891 __ Mov(temp1, value_offset);
1892
1893 // Loop to compare strings 4 bytes at a time starting at the front of the string.
1894 __ Bind(&loop);
1895 __ Ldr(out, MemOperand(str, temp1));
1896 __ Ldr(temp2, MemOperand(arg, temp1));
1897 __ Add(temp1, temp1, Operand::From(sizeof(uint32_t)));
1898 __ Cmp(out, temp2);
1899 __ B(ne, &return_false, /* far_target */ false);
1900 // With string compression, we have compared 4 bytes, otherwise 2 chars.
1901 __ Subs(temp, temp, mirror::kUseStringCompression ? 4 : 2);
1902 __ B(hi, &loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001903 }
Vladimir Markofdaf0f42016-10-13 19:29:53 +01001904
Anton Kirilov5ec62182016-10-13 20:16:02 +01001905 // Return true and exit the function.
1906 // If loop does not result in returning false, we return true.
1907 __ Bind(&return_true);
1908 __ Mov(out, 1);
Anton Kirilov6f644202017-02-27 18:29:45 +00001909 __ B(final_label);
Anton Kirilov5ec62182016-10-13 20:16:02 +01001910
1911 // Return false and exit the function.
1912 __ Bind(&return_false);
1913 __ Mov(out, 0);
Anton Kirilov6f644202017-02-27 18:29:45 +00001914
1915 if (end.IsReferenced()) {
1916 __ Bind(&end);
1917 }
Anton Kirilov5ec62182016-10-13 20:16:02 +01001918}
1919
1920static void GenerateVisitStringIndexOf(HInvoke* invoke,
1921 ArmVIXLAssembler* assembler,
1922 CodeGeneratorARMVIXL* codegen,
1923 ArenaAllocator* allocator,
1924 bool start_at_zero) {
1925 LocationSummary* locations = invoke->GetLocations();
1926
1927 // Note that the null check must have been done earlier.
1928 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1929
1930 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
1931 // or directly dispatch for a large constant, or omit slow-path for a small constant or a char.
1932 SlowPathCodeARMVIXL* slow_path = nullptr;
1933 HInstruction* code_point = invoke->InputAt(1);
1934 if (code_point->IsIntConstant()) {
Anton Kirilov644032c2016-12-06 17:51:43 +00001935 if (static_cast<uint32_t>(Int32ConstantFrom(code_point)) >
Anton Kirilov5ec62182016-10-13 20:16:02 +01001936 std::numeric_limits<uint16_t>::max()) {
1937 // Always needs the slow-path. We could directly dispatch to it, but this case should be
1938 // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1939 slow_path = new (allocator) IntrinsicSlowPathARMVIXL(invoke);
1940 codegen->AddSlowPath(slow_path);
1941 __ B(slow_path->GetEntryLabel());
1942 __ Bind(slow_path->GetExitLabel());
1943 return;
1944 }
1945 } else if (code_point->GetType() != Primitive::kPrimChar) {
1946 vixl32::Register char_reg = InputRegisterAt(invoke, 1);
1947 // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`.
1948 __ Cmp(char_reg, static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1);
1949 slow_path = new (allocator) IntrinsicSlowPathARMVIXL(invoke);
1950 codegen->AddSlowPath(slow_path);
1951 __ B(hs, slow_path->GetEntryLabel());
1952 }
1953
1954 if (start_at_zero) {
1955 vixl32::Register tmp_reg = RegisterFrom(locations->GetTemp(0));
1956 DCHECK(tmp_reg.Is(r2));
1957 // Start-index = 0.
1958 __ Mov(tmp_reg, 0);
1959 }
1960
1961 codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path);
1962 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
1963
1964 if (slow_path != nullptr) {
1965 __ Bind(slow_path->GetExitLabel());
1966 }
1967}
1968
1969void IntrinsicLocationsBuilderARMVIXL::VisitStringIndexOf(HInvoke* invoke) {
1970 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1971 LocationSummary::kCallOnMainAndSlowPath,
1972 kIntrinsified);
1973 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1974 // best to align the inputs accordingly.
1975 InvokeRuntimeCallingConventionARMVIXL calling_convention;
1976 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1977 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1978 locations->SetOut(LocationFrom(r0));
1979
1980 // Need to send start-index=0.
1981 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
1982}
1983
1984void IntrinsicCodeGeneratorARMVIXL::VisitStringIndexOf(HInvoke* invoke) {
1985 GenerateVisitStringIndexOf(
1986 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
1987}
1988
1989void IntrinsicLocationsBuilderARMVIXL::VisitStringIndexOfAfter(HInvoke* invoke) {
1990 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1991 LocationSummary::kCallOnMainAndSlowPath,
1992 kIntrinsified);
1993 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1994 // best to align the inputs accordingly.
1995 InvokeRuntimeCallingConventionARMVIXL calling_convention;
1996 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
1997 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
1998 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
1999 locations->SetOut(LocationFrom(r0));
2000}
2001
2002void IntrinsicCodeGeneratorARMVIXL::VisitStringIndexOfAfter(HInvoke* invoke) {
2003 GenerateVisitStringIndexOf(
2004 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
2005}
2006
2007void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromBytes(HInvoke* invoke) {
2008 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2009 LocationSummary::kCallOnMainAndSlowPath,
2010 kIntrinsified);
2011 InvokeRuntimeCallingConventionARMVIXL calling_convention;
2012 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2013 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
2014 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
2015 locations->SetInAt(3, LocationFrom(calling_convention.GetRegisterAt(3)));
2016 locations->SetOut(LocationFrom(r0));
2017}
2018
2019void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromBytes(HInvoke* invoke) {
2020 ArmVIXLAssembler* assembler = GetAssembler();
2021 vixl32::Register byte_array = InputRegisterAt(invoke, 0);
2022 __ Cmp(byte_array, 0);
2023 SlowPathCodeARMVIXL* slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke);
2024 codegen_->AddSlowPath(slow_path);
2025 __ B(eq, slow_path->GetEntryLabel());
2026
2027 codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path);
2028 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
2029 __ Bind(slow_path->GetExitLabel());
2030}
2031
2032void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromChars(HInvoke* invoke) {
2033 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2034 LocationSummary::kCallOnMainOnly,
2035 kIntrinsified);
2036 InvokeRuntimeCallingConventionARMVIXL calling_convention;
2037 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2038 locations->SetInAt(1, LocationFrom(calling_convention.GetRegisterAt(1)));
2039 locations->SetInAt(2, LocationFrom(calling_convention.GetRegisterAt(2)));
2040 locations->SetOut(LocationFrom(r0));
2041}
2042
2043void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromChars(HInvoke* invoke) {
2044 // No need to emit code checking whether `locations->InAt(2)` is a null
2045 // pointer, as callers of the native method
2046 //
2047 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
2048 //
2049 // all include a null check on `data` before calling that method.
2050 codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc());
2051 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
2052}
2053
2054void IntrinsicLocationsBuilderARMVIXL::VisitStringNewStringFromString(HInvoke* invoke) {
2055 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2056 LocationSummary::kCallOnMainAndSlowPath,
2057 kIntrinsified);
2058 InvokeRuntimeCallingConventionARMVIXL calling_convention;
2059 locations->SetInAt(0, LocationFrom(calling_convention.GetRegisterAt(0)));
2060 locations->SetOut(LocationFrom(r0));
2061}
2062
2063void IntrinsicCodeGeneratorARMVIXL::VisitStringNewStringFromString(HInvoke* invoke) {
2064 ArmVIXLAssembler* assembler = GetAssembler();
2065 vixl32::Register string_to_copy = InputRegisterAt(invoke, 0);
2066 __ Cmp(string_to_copy, 0);
2067 SlowPathCodeARMVIXL* slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke);
2068 codegen_->AddSlowPath(slow_path);
2069 __ B(eq, slow_path->GetEntryLabel());
2070
2071 codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc(), slow_path);
2072 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
2073
2074 __ Bind(slow_path->GetExitLabel());
2075}
2076
2077void IntrinsicLocationsBuilderARMVIXL::VisitSystemArrayCopy(HInvoke* invoke) {
2078 // The only read barrier implementation supporting the
2079 // SystemArrayCopy intrinsic is the Baker-style read barriers.
2080 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
2081 return;
2082 }
2083
2084 CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke);
2085 LocationSummary* locations = invoke->GetLocations();
2086 if (locations == nullptr) {
2087 return;
2088 }
2089
2090 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
2091 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
2092 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
2093
2094 if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) {
2095 locations->SetInAt(1, Location::RequiresRegister());
2096 }
2097 if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) {
2098 locations->SetInAt(3, Location::RequiresRegister());
2099 }
2100 if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) {
2101 locations->SetInAt(4, Location::RequiresRegister());
2102 }
2103 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2104 // Temporary register IP cannot be used in
2105 // ReadBarrierSystemArrayCopySlowPathARM (because that register
2106 // is clobbered by ReadBarrierMarkRegX entry points). Get an extra
2107 // temporary register from the register allocator.
2108 locations->AddTemp(Location::RequiresRegister());
Vladimir Markoeee1c0e2017-04-21 17:58:41 +01002109 CodeGeneratorARMVIXL* arm_codegen = down_cast<CodeGeneratorARMVIXL*>(codegen_);
2110 arm_codegen->MaybeAddBakerCcEntrypointTempForFields(locations);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002111 }
2112}
2113
2114static void CheckPosition(ArmVIXLAssembler* assembler,
2115 Location pos,
2116 vixl32::Register input,
2117 Location length,
2118 SlowPathCodeARMVIXL* slow_path,
2119 vixl32::Register temp,
2120 bool length_is_input_length = false) {
2121 // Where is the length in the Array?
2122 const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value();
2123
2124 if (pos.IsConstant()) {
2125 int32_t pos_const = Int32ConstantFrom(pos);
2126 if (pos_const == 0) {
2127 if (!length_is_input_length) {
2128 // Check that length(input) >= length.
2129 __ Ldr(temp, MemOperand(input, length_offset));
2130 if (length.IsConstant()) {
2131 __ Cmp(temp, Int32ConstantFrom(length));
2132 } else {
2133 __ Cmp(temp, RegisterFrom(length));
2134 }
2135 __ B(lt, slow_path->GetEntryLabel());
2136 }
2137 } else {
2138 // Check that length(input) >= pos.
2139 __ Ldr(temp, MemOperand(input, length_offset));
2140 __ Subs(temp, temp, pos_const);
2141 __ B(lt, slow_path->GetEntryLabel());
2142
2143 // Check that (length(input) - pos) >= length.
2144 if (length.IsConstant()) {
2145 __ Cmp(temp, Int32ConstantFrom(length));
2146 } else {
2147 __ Cmp(temp, RegisterFrom(length));
2148 }
2149 __ B(lt, slow_path->GetEntryLabel());
2150 }
2151 } else if (length_is_input_length) {
2152 // The only way the copy can succeed is if pos is zero.
2153 vixl32::Register pos_reg = RegisterFrom(pos);
xueliang.zhongf51bc622016-11-04 09:23:32 +00002154 __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002155 } else {
2156 // Check that pos >= 0.
2157 vixl32::Register pos_reg = RegisterFrom(pos);
2158 __ Cmp(pos_reg, 0);
2159 __ B(lt, slow_path->GetEntryLabel());
2160
2161 // Check that pos <= length(input).
2162 __ Ldr(temp, MemOperand(input, length_offset));
2163 __ Subs(temp, temp, pos_reg);
2164 __ B(lt, slow_path->GetEntryLabel());
2165
2166 // Check that (length(input) - pos) >= length.
2167 if (length.IsConstant()) {
2168 __ Cmp(temp, Int32ConstantFrom(length));
2169 } else {
2170 __ Cmp(temp, RegisterFrom(length));
2171 }
2172 __ B(lt, slow_path->GetEntryLabel());
2173 }
2174}
2175
2176void IntrinsicCodeGeneratorARMVIXL::VisitSystemArrayCopy(HInvoke* invoke) {
2177 // The only read barrier implementation supporting the
2178 // SystemArrayCopy intrinsic is the Baker-style read barriers.
2179 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
2180
2181 ArmVIXLAssembler* assembler = GetAssembler();
2182 LocationSummary* locations = invoke->GetLocations();
2183
2184 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
2185 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
2186 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
2187 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
2188 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
2189
2190 vixl32::Register src = InputRegisterAt(invoke, 0);
2191 Location src_pos = locations->InAt(1);
2192 vixl32::Register dest = InputRegisterAt(invoke, 2);
2193 Location dest_pos = locations->InAt(3);
2194 Location length = locations->InAt(4);
2195 Location temp1_loc = locations->GetTemp(0);
2196 vixl32::Register temp1 = RegisterFrom(temp1_loc);
2197 Location temp2_loc = locations->GetTemp(1);
2198 vixl32::Register temp2 = RegisterFrom(temp2_loc);
2199 Location temp3_loc = locations->GetTemp(2);
2200 vixl32::Register temp3 = RegisterFrom(temp3_loc);
2201
2202 SlowPathCodeARMVIXL* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARMVIXL(invoke);
2203 codegen_->AddSlowPath(intrinsic_slow_path);
2204
2205 vixl32::Label conditions_on_positions_validated;
2206 SystemArrayCopyOptimizations optimizations(invoke);
2207
2208 // If source and destination are the same, we go to slow path if we need to do
2209 // forward copying.
2210 if (src_pos.IsConstant()) {
2211 int32_t src_pos_constant = Int32ConstantFrom(src_pos);
2212 if (dest_pos.IsConstant()) {
2213 int32_t dest_pos_constant = Int32ConstantFrom(dest_pos);
2214 if (optimizations.GetDestinationIsSource()) {
2215 // Checked when building locations.
2216 DCHECK_GE(src_pos_constant, dest_pos_constant);
2217 } else if (src_pos_constant < dest_pos_constant) {
2218 __ Cmp(src, dest);
2219 __ B(eq, intrinsic_slow_path->GetEntryLabel());
2220 }
2221
2222 // Checked when building locations.
2223 DCHECK(!optimizations.GetDestinationIsSource()
2224 || (src_pos_constant >= Int32ConstantFrom(dest_pos)));
2225 } else {
2226 if (!optimizations.GetDestinationIsSource()) {
2227 __ Cmp(src, dest);
Artem Serov517d9f62016-12-12 15:51:15 +00002228 __ B(ne, &conditions_on_positions_validated, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002229 }
2230 __ Cmp(RegisterFrom(dest_pos), src_pos_constant);
2231 __ B(gt, intrinsic_slow_path->GetEntryLabel());
2232 }
2233 } else {
2234 if (!optimizations.GetDestinationIsSource()) {
2235 __ Cmp(src, dest);
Artem Serov517d9f62016-12-12 15:51:15 +00002236 __ B(ne, &conditions_on_positions_validated, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002237 }
2238 if (dest_pos.IsConstant()) {
2239 int32_t dest_pos_constant = Int32ConstantFrom(dest_pos);
2240 __ Cmp(RegisterFrom(src_pos), dest_pos_constant);
2241 } else {
2242 __ Cmp(RegisterFrom(src_pos), RegisterFrom(dest_pos));
2243 }
2244 __ B(lt, intrinsic_slow_path->GetEntryLabel());
2245 }
2246
2247 __ Bind(&conditions_on_positions_validated);
2248
2249 if (!optimizations.GetSourceIsNotNull()) {
2250 // Bail out if the source is null.
xueliang.zhongf51bc622016-11-04 09:23:32 +00002251 __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002252 }
2253
2254 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
2255 // Bail out if the destination is null.
xueliang.zhongf51bc622016-11-04 09:23:32 +00002256 __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002257 }
2258
2259 // If the length is negative, bail out.
2260 // We have already checked in the LocationsBuilder for the constant case.
2261 if (!length.IsConstant() &&
2262 !optimizations.GetCountIsSourceLength() &&
2263 !optimizations.GetCountIsDestinationLength()) {
2264 __ Cmp(RegisterFrom(length), 0);
2265 __ B(lt, intrinsic_slow_path->GetEntryLabel());
2266 }
2267
2268 // Validity checks: source.
2269 CheckPosition(assembler,
2270 src_pos,
2271 src,
2272 length,
2273 intrinsic_slow_path,
2274 temp1,
2275 optimizations.GetCountIsSourceLength());
2276
2277 // Validity checks: dest.
2278 CheckPosition(assembler,
2279 dest_pos,
2280 dest,
2281 length,
2282 intrinsic_slow_path,
2283 temp1,
2284 optimizations.GetCountIsDestinationLength());
2285
2286 if (!optimizations.GetDoesNotNeedTypeCheck()) {
2287 // Check whether all elements of the source array are assignable to the component
2288 // type of the destination array. We do two checks: the classes are the same,
2289 // or the destination is Object[]. If none of these checks succeed, we go to the
2290 // slow path.
2291
2292 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2293 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2294 // /* HeapReference<Class> */ temp1 = src->klass_
2295 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2296 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
2297 // Bail out if the source is not a non primitive array.
2298 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2299 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2300 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
xueliang.zhongf51bc622016-11-04 09:23:32 +00002301 __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002302 // If heap poisoning is enabled, `temp1` has been unpoisoned
2303 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2304 // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_);
2305 __ Ldrh(temp1, MemOperand(temp1, primitive_offset));
2306 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
xueliang.zhongf51bc622016-11-04 09:23:32 +00002307 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002308 }
2309
2310 // /* HeapReference<Class> */ temp1 = dest->klass_
2311 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2312 invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false);
2313
2314 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
2315 // Bail out if the destination is not a non primitive array.
2316 //
2317 // Register `temp1` is not trashed by the read barrier emitted
2318 // by GenerateFieldLoadWithBakerReadBarrier below, as that
2319 // method produces a call to a ReadBarrierMarkRegX entry point,
2320 // which saves all potentially live registers, including
2321 // temporaries such a `temp1`.
2322 // /* HeapReference<Class> */ temp2 = temp1->component_type_
2323 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2324 invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false);
xueliang.zhongf51bc622016-11-04 09:23:32 +00002325 __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002326 // If heap poisoning is enabled, `temp2` has been unpoisoned
2327 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2328 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
2329 __ Ldrh(temp2, MemOperand(temp2, primitive_offset));
2330 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
xueliang.zhongf51bc622016-11-04 09:23:32 +00002331 __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002332 }
2333
2334 // For the same reason given earlier, `temp1` is not trashed by the
2335 // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below.
2336 // /* HeapReference<Class> */ temp2 = src->klass_
2337 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2338 invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false);
2339 // Note: if heap poisoning is on, we are comparing two unpoisoned references here.
2340 __ Cmp(temp1, temp2);
2341
2342 if (optimizations.GetDestinationIsTypedObjectArray()) {
2343 vixl32::Label do_copy;
Artem Serov517d9f62016-12-12 15:51:15 +00002344 __ B(eq, &do_copy, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002345 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2346 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2347 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
2348 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2349 // We do not need to emit a read barrier for the following
2350 // heap reference load, as `temp1` is only used in a
2351 // comparison with null below, and this reference is not
2352 // kept afterwards.
2353 __ Ldr(temp1, MemOperand(temp1, super_offset));
xueliang.zhongf51bc622016-11-04 09:23:32 +00002354 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002355 __ Bind(&do_copy);
2356 } else {
2357 __ B(ne, intrinsic_slow_path->GetEntryLabel());
2358 }
2359 } else {
2360 // Non read barrier code.
2361
2362 // /* HeapReference<Class> */ temp1 = dest->klass_
2363 __ Ldr(temp1, MemOperand(dest, class_offset));
2364 // /* HeapReference<Class> */ temp2 = src->klass_
2365 __ Ldr(temp2, MemOperand(src, class_offset));
2366 bool did_unpoison = false;
2367 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
2368 !optimizations.GetSourceIsNonPrimitiveArray()) {
2369 // One or two of the references need to be unpoisoned. Unpoison them
2370 // both to make the identity check valid.
2371 assembler->MaybeUnpoisonHeapReference(temp1);
2372 assembler->MaybeUnpoisonHeapReference(temp2);
2373 did_unpoison = true;
2374 }
2375
2376 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
2377 // Bail out if the destination is not a non primitive array.
2378 // /* HeapReference<Class> */ temp3 = temp1->component_type_
2379 __ Ldr(temp3, MemOperand(temp1, component_offset));
xueliang.zhongf51bc622016-11-04 09:23:32 +00002380 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002381 assembler->MaybeUnpoisonHeapReference(temp3);
2382 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
2383 __ Ldrh(temp3, MemOperand(temp3, primitive_offset));
2384 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
xueliang.zhongf51bc622016-11-04 09:23:32 +00002385 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002386 }
2387
2388 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2389 // Bail out if the source is not a non primitive array.
2390 // /* HeapReference<Class> */ temp3 = temp2->component_type_
2391 __ Ldr(temp3, MemOperand(temp2, component_offset));
xueliang.zhongf51bc622016-11-04 09:23:32 +00002392 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002393 assembler->MaybeUnpoisonHeapReference(temp3);
2394 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
2395 __ Ldrh(temp3, MemOperand(temp3, primitive_offset));
2396 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
xueliang.zhongf51bc622016-11-04 09:23:32 +00002397 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002398 }
2399
2400 __ Cmp(temp1, temp2);
2401
2402 if (optimizations.GetDestinationIsTypedObjectArray()) {
2403 vixl32::Label do_copy;
Artem Serov517d9f62016-12-12 15:51:15 +00002404 __ B(eq, &do_copy, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002405 if (!did_unpoison) {
2406 assembler->MaybeUnpoisonHeapReference(temp1);
2407 }
2408 // /* HeapReference<Class> */ temp1 = temp1->component_type_
2409 __ Ldr(temp1, MemOperand(temp1, component_offset));
2410 assembler->MaybeUnpoisonHeapReference(temp1);
2411 // /* HeapReference<Class> */ temp1 = temp1->super_class_
2412 __ Ldr(temp1, MemOperand(temp1, super_offset));
2413 // No need to unpoison the result, we're comparing against null.
xueliang.zhongf51bc622016-11-04 09:23:32 +00002414 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002415 __ Bind(&do_copy);
2416 } else {
2417 __ B(ne, intrinsic_slow_path->GetEntryLabel());
2418 }
2419 }
2420 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
2421 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
2422 // Bail out if the source is not a non primitive array.
2423 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2424 // /* HeapReference<Class> */ temp1 = src->klass_
2425 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2426 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
2427 // /* HeapReference<Class> */ temp3 = temp1->component_type_
2428 codegen_->GenerateFieldLoadWithBakerReadBarrier(
2429 invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
xueliang.zhongf51bc622016-11-04 09:23:32 +00002430 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002431 // If heap poisoning is enabled, `temp3` has been unpoisoned
2432 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
2433 } else {
2434 // /* HeapReference<Class> */ temp1 = src->klass_
2435 __ Ldr(temp1, MemOperand(src, class_offset));
2436 assembler->MaybeUnpoisonHeapReference(temp1);
2437 // /* HeapReference<Class> */ temp3 = temp1->component_type_
2438 __ Ldr(temp3, MemOperand(temp1, component_offset));
xueliang.zhongf51bc622016-11-04 09:23:32 +00002439 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002440 assembler->MaybeUnpoisonHeapReference(temp3);
2441 }
2442 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
2443 __ Ldrh(temp3, MemOperand(temp3, primitive_offset));
2444 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
xueliang.zhongf51bc622016-11-04 09:23:32 +00002445 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Anton Kirilov5ec62182016-10-13 20:16:02 +01002446 }
2447
Roland Levillain1663d162017-03-17 15:15:21 +00002448 if (length.IsConstant() && Int32ConstantFrom(length) == 0) {
2449 // Null constant length: not need to emit the loop code at all.
Anton Kirilov5ec62182016-10-13 20:16:02 +01002450 } else {
Roland Levillain1663d162017-03-17 15:15:21 +00002451 vixl32::Label done;
2452 const Primitive::Type type = Primitive::kPrimNot;
2453 const int32_t element_size = Primitive::ComponentSize(type);
2454
2455 if (length.IsRegister()) {
2456 // Don't enter the copy loop if the length is null.
2457 __ CompareAndBranchIfZero(RegisterFrom(length), &done, /* is_far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002458 }
Roland Levillain1663d162017-03-17 15:15:21 +00002459
2460 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
2461 // TODO: Also convert this intrinsic to the IsGcMarking strategy?
2462
2463 // SystemArrayCopy implementation for Baker read barriers (see
Roland Levillain9983e302017-07-14 14:34:22 +01002464 // also CodeGeneratorARMVIXL::GenerateReferenceLoadWithBakerReadBarrier):
Roland Levillain1663d162017-03-17 15:15:21 +00002465 //
2466 // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState();
2467 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
2468 // bool is_gray = (rb_state == ReadBarrier::GrayState());
2469 // if (is_gray) {
2470 // // Slow-path copy.
2471 // do {
2472 // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++)));
2473 // } while (src_ptr != end_ptr)
2474 // } else {
2475 // // Fast-path copy.
2476 // do {
2477 // *dest_ptr++ = *src_ptr++;
2478 // } while (src_ptr != end_ptr)
2479 // }
2480
2481 // /* int32_t */ monitor = src->monitor_
2482 __ Ldr(temp2, MemOperand(src, monitor_offset));
2483 // /* LockWord */ lock_word = LockWord(monitor)
2484 static_assert(sizeof(LockWord) == sizeof(int32_t),
2485 "art::LockWord and int32_t have different sizes.");
2486
2487 // Introduce a dependency on the lock_word including the rb_state,
2488 // which shall prevent load-load reordering without using
2489 // a memory barrier (which would be more expensive).
2490 // `src` is unchanged by this operation, but its value now depends
2491 // on `temp2`.
2492 __ Add(src, src, Operand(temp2, vixl32::LSR, 32));
2493
2494 // Compute the base source address in `temp1`.
2495 // Note that `temp1` (the base source address) is computed from
2496 // `src` (and `src_pos`) here, and thus honors the artificial
2497 // dependency of `src` on `temp2`.
2498 GenSystemArrayCopyBaseAddress(GetAssembler(), type, src, src_pos, temp1);
2499 // Compute the end source address in `temp3`.
2500 GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3);
2501 // The base destination address is computed later, as `temp2` is
2502 // used for intermediate computations.
2503
2504 // Slow path used to copy array when `src` is gray.
2505 // Note that the base destination address is computed in `temp2`
2506 // by the slow path code.
2507 SlowPathCodeARMVIXL* read_barrier_slow_path =
2508 new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARMVIXL(invoke);
2509 codegen_->AddSlowPath(read_barrier_slow_path);
2510
2511 // Given the numeric representation, it's enough to check the low bit of the
2512 // rb_state. We do that by shifting the bit out of the lock word with LSRS
2513 // which can be a 16-bit instruction unlike the TST immediate.
2514 static_assert(ReadBarrier::WhiteState() == 0, "Expecting white to have value 0");
2515 static_assert(ReadBarrier::GrayState() == 1, "Expecting gray to have value 1");
2516 __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1);
2517 // Carry flag is the last bit shifted out by LSRS.
2518 __ B(cs, read_barrier_slow_path->GetEntryLabel());
2519
2520 // Fast-path copy.
2521 // Compute the base destination address in `temp2`.
2522 GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2);
2523 // Iterate over the arrays and do a raw copy of the objects. We don't need to
2524 // poison/unpoison.
2525 vixl32::Label loop;
2526 __ Bind(&loop);
2527 {
2528 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
2529 const vixl32::Register temp_reg = temps.Acquire();
2530 __ Ldr(temp_reg, MemOperand(temp1, element_size, PostIndex));
2531 __ Str(temp_reg, MemOperand(temp2, element_size, PostIndex));
2532 }
2533 __ Cmp(temp1, temp3);
2534 __ B(ne, &loop, /* far_target */ false);
2535
2536 __ Bind(read_barrier_slow_path->GetExitLabel());
2537 } else {
2538 // Non read barrier code.
2539 // Compute the base source address in `temp1`.
2540 GenSystemArrayCopyBaseAddress(GetAssembler(), type, src, src_pos, temp1);
2541 // Compute the base destination address in `temp2`.
2542 GenSystemArrayCopyBaseAddress(GetAssembler(), type, dest, dest_pos, temp2);
2543 // Compute the end source address in `temp3`.
2544 GenSystemArrayCopyEndAddress(GetAssembler(), type, length, temp1, temp3);
2545 // Iterate over the arrays and do a raw copy of the objects. We don't need to
2546 // poison/unpoison.
2547 vixl32::Label loop;
2548 __ Bind(&loop);
2549 {
2550 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
2551 const vixl32::Register temp_reg = temps.Acquire();
2552 __ Ldr(temp_reg, MemOperand(temp1, element_size, PostIndex));
2553 __ Str(temp_reg, MemOperand(temp2, element_size, PostIndex));
2554 }
2555 __ Cmp(temp1, temp3);
2556 __ B(ne, &loop, /* far_target */ false);
2557 }
Anton Kirilov5ec62182016-10-13 20:16:02 +01002558 __ Bind(&done);
2559 }
2560
2561 // We only need one card marking on the destination array.
2562 codegen_->MarkGCCard(temp1, temp2, dest, NoReg, /* value_can_be_null */ false);
2563
2564 __ Bind(intrinsic_slow_path->GetExitLabel());
2565}
2566
2567static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
2568 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
2569 // the code generator. Furthermore, the register allocator creates fixed live intervals
2570 // for all caller-saved registers because we are doing a function call. As a result, if
2571 // the input and output locations are unallocated, the register allocator runs out of
2572 // registers and fails; however, a debuggable graph is not the common case.
2573 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
2574 return;
2575 }
2576
2577 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
2578 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
2579 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
2580
2581 LocationSummary* const locations = new (arena) LocationSummary(invoke,
2582 LocationSummary::kCallOnMainOnly,
2583 kIntrinsified);
2584 const InvokeRuntimeCallingConventionARMVIXL calling_convention;
2585
2586 locations->SetInAt(0, Location::RequiresFpuRegister());
2587 locations->SetOut(Location::RequiresFpuRegister());
2588 // Native code uses the soft float ABI.
2589 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2590 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2591}
2592
2593static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
2594 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
2595 // the code generator. Furthermore, the register allocator creates fixed live intervals
2596 // for all caller-saved registers because we are doing a function call. As a result, if
2597 // the input and output locations are unallocated, the register allocator runs out of
2598 // registers and fails; however, a debuggable graph is not the common case.
2599 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
2600 return;
2601 }
2602
2603 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
2604 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
2605 DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble);
2606 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
2607
2608 LocationSummary* const locations = new (arena) LocationSummary(invoke,
2609 LocationSummary::kCallOnMainOnly,
2610 kIntrinsified);
2611 const InvokeRuntimeCallingConventionARMVIXL calling_convention;
2612
2613 locations->SetInAt(0, Location::RequiresFpuRegister());
2614 locations->SetInAt(1, Location::RequiresFpuRegister());
2615 locations->SetOut(Location::RequiresFpuRegister());
2616 // Native code uses the soft float ABI.
2617 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(0)));
2618 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(1)));
2619 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(2)));
2620 locations->AddTemp(LocationFrom(calling_convention.GetRegisterAt(3)));
2621}
2622
2623static void GenFPToFPCall(HInvoke* invoke,
2624 ArmVIXLAssembler* assembler,
2625 CodeGeneratorARMVIXL* codegen,
2626 QuickEntrypointEnum entry) {
2627 LocationSummary* const locations = invoke->GetLocations();
2628
2629 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
2630 DCHECK(locations->WillCall() && locations->Intrinsified());
2631
2632 // Native code uses the soft float ABI.
2633 __ Vmov(RegisterFrom(locations->GetTemp(0)),
2634 RegisterFrom(locations->GetTemp(1)),
2635 InputDRegisterAt(invoke, 0));
2636 codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc());
2637 __ Vmov(OutputDRegister(invoke),
2638 RegisterFrom(locations->GetTemp(0)),
2639 RegisterFrom(locations->GetTemp(1)));
2640}
2641
2642static void GenFPFPToFPCall(HInvoke* invoke,
2643 ArmVIXLAssembler* assembler,
2644 CodeGeneratorARMVIXL* codegen,
2645 QuickEntrypointEnum entry) {
2646 LocationSummary* const locations = invoke->GetLocations();
2647
2648 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
2649 DCHECK(locations->WillCall() && locations->Intrinsified());
2650
2651 // Native code uses the soft float ABI.
2652 __ Vmov(RegisterFrom(locations->GetTemp(0)),
2653 RegisterFrom(locations->GetTemp(1)),
2654 InputDRegisterAt(invoke, 0));
2655 __ Vmov(RegisterFrom(locations->GetTemp(2)),
2656 RegisterFrom(locations->GetTemp(3)),
2657 InputDRegisterAt(invoke, 1));
2658 codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc());
2659 __ Vmov(OutputDRegister(invoke),
2660 RegisterFrom(locations->GetTemp(0)),
2661 RegisterFrom(locations->GetTemp(1)));
2662}
2663
2664void IntrinsicLocationsBuilderARMVIXL::VisitMathCos(HInvoke* invoke) {
2665 CreateFPToFPCallLocations(arena_, invoke);
2666}
2667
2668void IntrinsicCodeGeneratorARMVIXL::VisitMathCos(HInvoke* invoke) {
2669 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos);
2670}
2671
2672void IntrinsicLocationsBuilderARMVIXL::VisitMathSin(HInvoke* invoke) {
2673 CreateFPToFPCallLocations(arena_, invoke);
2674}
2675
2676void IntrinsicCodeGeneratorARMVIXL::VisitMathSin(HInvoke* invoke) {
2677 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin);
2678}
2679
2680void IntrinsicLocationsBuilderARMVIXL::VisitMathAcos(HInvoke* invoke) {
2681 CreateFPToFPCallLocations(arena_, invoke);
2682}
2683
2684void IntrinsicCodeGeneratorARMVIXL::VisitMathAcos(HInvoke* invoke) {
2685 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos);
2686}
2687
2688void IntrinsicLocationsBuilderARMVIXL::VisitMathAsin(HInvoke* invoke) {
2689 CreateFPToFPCallLocations(arena_, invoke);
2690}
2691
2692void IntrinsicCodeGeneratorARMVIXL::VisitMathAsin(HInvoke* invoke) {
2693 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin);
2694}
2695
2696void IntrinsicLocationsBuilderARMVIXL::VisitMathAtan(HInvoke* invoke) {
2697 CreateFPToFPCallLocations(arena_, invoke);
2698}
2699
2700void IntrinsicCodeGeneratorARMVIXL::VisitMathAtan(HInvoke* invoke) {
2701 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan);
2702}
2703
2704void IntrinsicLocationsBuilderARMVIXL::VisitMathCbrt(HInvoke* invoke) {
2705 CreateFPToFPCallLocations(arena_, invoke);
2706}
2707
2708void IntrinsicCodeGeneratorARMVIXL::VisitMathCbrt(HInvoke* invoke) {
2709 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt);
2710}
2711
2712void IntrinsicLocationsBuilderARMVIXL::VisitMathCosh(HInvoke* invoke) {
2713 CreateFPToFPCallLocations(arena_, invoke);
2714}
2715
2716void IntrinsicCodeGeneratorARMVIXL::VisitMathCosh(HInvoke* invoke) {
2717 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh);
2718}
2719
2720void IntrinsicLocationsBuilderARMVIXL::VisitMathExp(HInvoke* invoke) {
2721 CreateFPToFPCallLocations(arena_, invoke);
2722}
2723
2724void IntrinsicCodeGeneratorARMVIXL::VisitMathExp(HInvoke* invoke) {
2725 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp);
2726}
2727
2728void IntrinsicLocationsBuilderARMVIXL::VisitMathExpm1(HInvoke* invoke) {
2729 CreateFPToFPCallLocations(arena_, invoke);
2730}
2731
2732void IntrinsicCodeGeneratorARMVIXL::VisitMathExpm1(HInvoke* invoke) {
2733 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1);
2734}
2735
2736void IntrinsicLocationsBuilderARMVIXL::VisitMathLog(HInvoke* invoke) {
2737 CreateFPToFPCallLocations(arena_, invoke);
2738}
2739
2740void IntrinsicCodeGeneratorARMVIXL::VisitMathLog(HInvoke* invoke) {
2741 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog);
2742}
2743
2744void IntrinsicLocationsBuilderARMVIXL::VisitMathLog10(HInvoke* invoke) {
2745 CreateFPToFPCallLocations(arena_, invoke);
2746}
2747
2748void IntrinsicCodeGeneratorARMVIXL::VisitMathLog10(HInvoke* invoke) {
2749 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10);
2750}
2751
2752void IntrinsicLocationsBuilderARMVIXL::VisitMathSinh(HInvoke* invoke) {
2753 CreateFPToFPCallLocations(arena_, invoke);
2754}
2755
2756void IntrinsicCodeGeneratorARMVIXL::VisitMathSinh(HInvoke* invoke) {
2757 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh);
2758}
2759
2760void IntrinsicLocationsBuilderARMVIXL::VisitMathTan(HInvoke* invoke) {
2761 CreateFPToFPCallLocations(arena_, invoke);
2762}
2763
2764void IntrinsicCodeGeneratorARMVIXL::VisitMathTan(HInvoke* invoke) {
2765 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan);
2766}
2767
2768void IntrinsicLocationsBuilderARMVIXL::VisitMathTanh(HInvoke* invoke) {
2769 CreateFPToFPCallLocations(arena_, invoke);
2770}
2771
2772void IntrinsicCodeGeneratorARMVIXL::VisitMathTanh(HInvoke* invoke) {
2773 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh);
2774}
2775
2776void IntrinsicLocationsBuilderARMVIXL::VisitMathAtan2(HInvoke* invoke) {
2777 CreateFPFPToFPCallLocations(arena_, invoke);
2778}
2779
2780void IntrinsicCodeGeneratorARMVIXL::VisitMathAtan2(HInvoke* invoke) {
2781 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2);
2782}
2783
2784void IntrinsicLocationsBuilderARMVIXL::VisitMathHypot(HInvoke* invoke) {
2785 CreateFPFPToFPCallLocations(arena_, invoke);
2786}
2787
2788void IntrinsicCodeGeneratorARMVIXL::VisitMathHypot(HInvoke* invoke) {
2789 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot);
2790}
2791
2792void IntrinsicLocationsBuilderARMVIXL::VisitMathNextAfter(HInvoke* invoke) {
2793 CreateFPFPToFPCallLocations(arena_, invoke);
2794}
2795
2796void IntrinsicCodeGeneratorARMVIXL::VisitMathNextAfter(HInvoke* invoke) {
2797 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter);
2798}
2799
2800void IntrinsicLocationsBuilderARMVIXL::VisitIntegerReverse(HInvoke* invoke) {
2801 CreateIntToIntLocations(arena_, invoke);
2802}
2803
2804void IntrinsicCodeGeneratorARMVIXL::VisitIntegerReverse(HInvoke* invoke) {
2805 ArmVIXLAssembler* assembler = GetAssembler();
2806 __ Rbit(OutputRegister(invoke), InputRegisterAt(invoke, 0));
2807}
2808
2809void IntrinsicLocationsBuilderARMVIXL::VisitLongReverse(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +01002810 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002811}
2812
2813void IntrinsicCodeGeneratorARMVIXL::VisitLongReverse(HInvoke* invoke) {
2814 ArmVIXLAssembler* assembler = GetAssembler();
2815 LocationSummary* locations = invoke->GetLocations();
2816
2817 vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0));
2818 vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0));
2819 vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out());
2820 vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out());
2821
2822 __ Rbit(out_reg_lo, in_reg_hi);
2823 __ Rbit(out_reg_hi, in_reg_lo);
2824}
2825
2826void IntrinsicLocationsBuilderARMVIXL::VisitIntegerReverseBytes(HInvoke* invoke) {
2827 CreateIntToIntLocations(arena_, invoke);
2828}
2829
2830void IntrinsicCodeGeneratorARMVIXL::VisitIntegerReverseBytes(HInvoke* invoke) {
2831 ArmVIXLAssembler* assembler = GetAssembler();
2832 __ Rev(OutputRegister(invoke), InputRegisterAt(invoke, 0));
2833}
2834
2835void IntrinsicLocationsBuilderARMVIXL::VisitLongReverseBytes(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +01002836 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Anton Kirilov5ec62182016-10-13 20:16:02 +01002837}
2838
2839void IntrinsicCodeGeneratorARMVIXL::VisitLongReverseBytes(HInvoke* invoke) {
2840 ArmVIXLAssembler* assembler = GetAssembler();
2841 LocationSummary* locations = invoke->GetLocations();
2842
2843 vixl32::Register in_reg_lo = LowRegisterFrom(locations->InAt(0));
2844 vixl32::Register in_reg_hi = HighRegisterFrom(locations->InAt(0));
2845 vixl32::Register out_reg_lo = LowRegisterFrom(locations->Out());
2846 vixl32::Register out_reg_hi = HighRegisterFrom(locations->Out());
2847
2848 __ Rev(out_reg_lo, in_reg_hi);
2849 __ Rev(out_reg_hi, in_reg_lo);
2850}
2851
2852void IntrinsicLocationsBuilderARMVIXL::VisitShortReverseBytes(HInvoke* invoke) {
2853 CreateIntToIntLocations(arena_, invoke);
2854}
2855
2856void IntrinsicCodeGeneratorARMVIXL::VisitShortReverseBytes(HInvoke* invoke) {
2857 ArmVIXLAssembler* assembler = GetAssembler();
2858 __ Revsh(OutputRegister(invoke), InputRegisterAt(invoke, 0));
2859}
2860
2861static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmVIXLAssembler* assembler) {
2862 DCHECK(Primitive::IsIntOrLongType(type)) << type;
2863 DCHECK_EQ(instr->GetType(), Primitive::kPrimInt);
2864 DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type);
2865
2866 bool is_long = type == Primitive::kPrimLong;
2867 LocationSummary* locations = instr->GetLocations();
2868 Location in = locations->InAt(0);
2869 vixl32::Register src_0 = is_long ? LowRegisterFrom(in) : RegisterFrom(in);
2870 vixl32::Register src_1 = is_long ? HighRegisterFrom(in) : src_0;
2871 vixl32::SRegister tmp_s = LowSRegisterFrom(locations->GetTemp(0));
2872 vixl32::DRegister tmp_d = DRegisterFrom(locations->GetTemp(0));
2873 vixl32::Register out_r = OutputRegister(instr);
2874
2875 // Move data from core register(s) to temp D-reg for bit count calculation, then move back.
2876 // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg,
2877 // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency,
2878 // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'.
2879 __ Vmov(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0|
2880 __ Vcnt(Untyped8, tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c|
2881 __ Vpaddl(U8, tmp_d, tmp_d); // Temp DReg |--c|--c|--c|--c|
2882 __ Vpaddl(U16, tmp_d, tmp_d); // Temp DReg |------c|------c|
2883 if (is_long) {
2884 __ Vpaddl(U32, tmp_d, tmp_d); // Temp DReg |--------------c|
2885 }
2886 __ Vmov(out_r, tmp_s);
2887}
2888
2889void IntrinsicLocationsBuilderARMVIXL::VisitIntegerBitCount(HInvoke* invoke) {
2890 CreateIntToIntLocations(arena_, invoke);
2891 invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister());
2892}
2893
2894void IntrinsicCodeGeneratorARMVIXL::VisitIntegerBitCount(HInvoke* invoke) {
2895 GenBitCount(invoke, Primitive::kPrimInt, GetAssembler());
2896}
2897
2898void IntrinsicLocationsBuilderARMVIXL::VisitLongBitCount(HInvoke* invoke) {
2899 VisitIntegerBitCount(invoke);
2900}
2901
2902void IntrinsicCodeGeneratorARMVIXL::VisitLongBitCount(HInvoke* invoke) {
2903 GenBitCount(invoke, Primitive::kPrimLong, GetAssembler());
2904}
2905
Petre-Ionut Tudor27292e62017-08-04 16:06:45 +01002906static void GenHighestOneBit(HInvoke* invoke,
2907 Primitive::Type type,
2908 CodeGeneratorARMVIXL* codegen) {
2909 DCHECK(Primitive::IsIntOrLongType(type));
2910
2911 ArmVIXLAssembler* assembler = codegen->GetAssembler();
2912 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
2913 const vixl32::Register temp = temps.Acquire();
2914
2915 if (type == Primitive::kPrimLong) {
2916 LocationSummary* locations = invoke->GetLocations();
2917 Location in = locations->InAt(0);
2918 Location out = locations->Out();
2919
2920 vixl32::Register in_reg_lo = LowRegisterFrom(in);
2921 vixl32::Register in_reg_hi = HighRegisterFrom(in);
2922 vixl32::Register out_reg_lo = LowRegisterFrom(out);
2923 vixl32::Register out_reg_hi = HighRegisterFrom(out);
2924
2925 __ Mov(temp, 0x80000000); // Modified immediate.
2926 __ Clz(out_reg_lo, in_reg_lo);
2927 __ Clz(out_reg_hi, in_reg_hi);
2928 __ Lsr(out_reg_lo, temp, out_reg_lo);
2929 __ Lsrs(out_reg_hi, temp, out_reg_hi);
2930
2931 // Discard result for lowest 32 bits if highest 32 bits are not zero.
2932 // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8,
2933 // we check that the output is in a low register, so that a 16-bit MOV
2934 // encoding can be used. If output is in a high register, then we generate
2935 // 4 more bytes of code to avoid a branch.
2936 Operand mov_src(0);
2937 if (!out_reg_lo.IsLow()) {
2938 __ Mov(LeaveFlags, temp, 0);
2939 mov_src = Operand(temp);
2940 }
2941 ExactAssemblyScope it_scope(codegen->GetVIXLAssembler(),
2942 2 * vixl32::k16BitT32InstructionSizeInBytes,
2943 CodeBufferCheckScope::kExactSize);
2944 __ it(ne);
2945 __ mov(ne, out_reg_lo, mov_src);
2946 } else {
2947 vixl32::Register out = OutputRegister(invoke);
2948 vixl32::Register in = InputRegisterAt(invoke, 0);
2949
2950 __ Mov(temp, 0x80000000); // Modified immediate.
2951 __ Clz(out, in);
2952 __ Lsr(out, temp, out);
2953 }
2954}
2955
2956void IntrinsicLocationsBuilderARMVIXL::VisitIntegerHighestOneBit(HInvoke* invoke) {
2957 CreateIntToIntLocations(arena_, invoke);
2958}
2959
2960void IntrinsicCodeGeneratorARMVIXL::VisitIntegerHighestOneBit(HInvoke* invoke) {
2961 GenHighestOneBit(invoke, Primitive::kPrimInt, codegen_);
2962}
2963
2964void IntrinsicLocationsBuilderARMVIXL::VisitLongHighestOneBit(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +01002965 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Petre-Ionut Tudor27292e62017-08-04 16:06:45 +01002966}
2967
2968void IntrinsicCodeGeneratorARMVIXL::VisitLongHighestOneBit(HInvoke* invoke) {
2969 GenHighestOneBit(invoke, Primitive::kPrimLong, codegen_);
2970}
2971
2972static void GenLowestOneBit(HInvoke* invoke,
2973 Primitive::Type type,
2974 CodeGeneratorARMVIXL* codegen) {
2975 DCHECK(Primitive::IsIntOrLongType(type));
2976
2977 ArmVIXLAssembler* assembler = codegen->GetAssembler();
2978 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
2979 const vixl32::Register temp = temps.Acquire();
2980
2981 if (type == Primitive::kPrimLong) {
2982 LocationSummary* locations = invoke->GetLocations();
2983 Location in = locations->InAt(0);
2984 Location out = locations->Out();
2985
2986 vixl32::Register in_reg_lo = LowRegisterFrom(in);
2987 vixl32::Register in_reg_hi = HighRegisterFrom(in);
2988 vixl32::Register out_reg_lo = LowRegisterFrom(out);
2989 vixl32::Register out_reg_hi = HighRegisterFrom(out);
2990
2991 __ Rsb(out_reg_hi, in_reg_hi, 0);
2992 __ Rsb(out_reg_lo, in_reg_lo, 0);
2993 __ And(out_reg_hi, out_reg_hi, in_reg_hi);
2994 // The result of this operation is 0 iff in_reg_lo is 0
2995 __ Ands(out_reg_lo, out_reg_lo, in_reg_lo);
2996
2997 // Discard result for highest 32 bits if lowest 32 bits are not zero.
2998 // Since IT blocks longer than a 16-bit instruction are deprecated by ARMv8,
2999 // we check that the output is in a low register, so that a 16-bit MOV
3000 // encoding can be used. If output is in a high register, then we generate
3001 // 4 more bytes of code to avoid a branch.
3002 Operand mov_src(0);
3003 if (!out_reg_lo.IsLow()) {
3004 __ Mov(LeaveFlags, temp, 0);
3005 mov_src = Operand(temp);
3006 }
3007 ExactAssemblyScope it_scope(codegen->GetVIXLAssembler(),
3008 2 * vixl32::k16BitT32InstructionSizeInBytes,
3009 CodeBufferCheckScope::kExactSize);
3010 __ it(ne);
3011 __ mov(ne, out_reg_hi, mov_src);
3012 } else {
3013 vixl32::Register out = OutputRegister(invoke);
3014 vixl32::Register in = InputRegisterAt(invoke, 0);
3015
3016 __ Rsb(temp, in, 0);
3017 __ And(out, temp, in);
3018 }
3019}
3020
3021void IntrinsicLocationsBuilderARMVIXL::VisitIntegerLowestOneBit(HInvoke* invoke) {
3022 CreateIntToIntLocations(arena_, invoke);
3023}
3024
3025void IntrinsicCodeGeneratorARMVIXL::VisitIntegerLowestOneBit(HInvoke* invoke) {
3026 GenLowestOneBit(invoke, Primitive::kPrimInt, codegen_);
3027}
3028
3029void IntrinsicLocationsBuilderARMVIXL::VisitLongLowestOneBit(HInvoke* invoke) {
Vladimir Marko1819e412017-08-29 17:02:56 +01003030 CreateLongToLongLocationsWithOverlap(arena_, invoke);
Petre-Ionut Tudor27292e62017-08-04 16:06:45 +01003031}
3032
3033void IntrinsicCodeGeneratorARMVIXL::VisitLongLowestOneBit(HInvoke* invoke) {
3034 GenLowestOneBit(invoke, Primitive::kPrimLong, codegen_);
3035}
3036
Anton Kirilov5ec62182016-10-13 20:16:02 +01003037void IntrinsicLocationsBuilderARMVIXL::VisitStringGetCharsNoCheck(HInvoke* invoke) {
3038 LocationSummary* locations = new (arena_) LocationSummary(invoke,
3039 LocationSummary::kNoCall,
3040 kIntrinsified);
3041 locations->SetInAt(0, Location::RequiresRegister());
3042 locations->SetInAt(1, Location::RequiresRegister());
3043 locations->SetInAt(2, Location::RequiresRegister());
3044 locations->SetInAt(3, Location::RequiresRegister());
3045 locations->SetInAt(4, Location::RequiresRegister());
3046
3047 // Temporary registers to store lengths of strings and for calculations.
3048 locations->AddTemp(Location::RequiresRegister());
3049 locations->AddTemp(Location::RequiresRegister());
3050 locations->AddTemp(Location::RequiresRegister());
3051}
3052
3053void IntrinsicCodeGeneratorARMVIXL::VisitStringGetCharsNoCheck(HInvoke* invoke) {
3054 ArmVIXLAssembler* assembler = GetAssembler();
3055 LocationSummary* locations = invoke->GetLocations();
3056
3057 // Check assumption that sizeof(Char) is 2 (used in scaling below).
3058 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
3059 DCHECK_EQ(char_size, 2u);
3060
3061 // Location of data in char array buffer.
3062 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
3063
3064 // Location of char array data in string.
3065 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
3066
3067 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
3068 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
3069 vixl32::Register srcObj = InputRegisterAt(invoke, 0);
3070 vixl32::Register srcBegin = InputRegisterAt(invoke, 1);
3071 vixl32::Register srcEnd = InputRegisterAt(invoke, 2);
3072 vixl32::Register dstObj = InputRegisterAt(invoke, 3);
3073 vixl32::Register dstBegin = InputRegisterAt(invoke, 4);
3074
3075 vixl32::Register num_chr = RegisterFrom(locations->GetTemp(0));
3076 vixl32::Register src_ptr = RegisterFrom(locations->GetTemp(1));
3077 vixl32::Register dst_ptr = RegisterFrom(locations->GetTemp(2));
3078
3079 vixl32::Label done, compressed_string_loop;
Anton Kirilov6f644202017-02-27 18:29:45 +00003080 vixl32::Label* final_label = codegen_->GetFinalLabel(invoke, &done);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003081 // dst to be copied.
3082 __ Add(dst_ptr, dstObj, data_offset);
3083 __ Add(dst_ptr, dst_ptr, Operand(dstBegin, vixl32::LSL, 1));
3084
3085 __ Subs(num_chr, srcEnd, srcBegin);
3086 // Early out for valid zero-length retrievals.
Anton Kirilov6f644202017-02-27 18:29:45 +00003087 __ B(eq, final_label, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003088
3089 // src range to copy.
3090 __ Add(src_ptr, srcObj, value_offset);
3091
3092 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
3093 vixl32::Register temp;
3094 vixl32::Label compressed_string_preloop;
3095 if (mirror::kUseStringCompression) {
3096 // Location of count in string.
3097 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
3098 temp = temps.Acquire();
3099 // String's length.
3100 __ Ldr(temp, MemOperand(srcObj, count_offset));
Vladimir Markofdaf0f42016-10-13 19:29:53 +01003101 __ Tst(temp, 1);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003102 temps.Release(temp);
Artem Serov517d9f62016-12-12 15:51:15 +00003103 __ B(eq, &compressed_string_preloop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003104 }
3105 __ Add(src_ptr, src_ptr, Operand(srcBegin, vixl32::LSL, 1));
3106
3107 // Do the copy.
3108 vixl32::Label loop, remainder;
3109
3110 temp = temps.Acquire();
3111 // Save repairing the value of num_chr on the < 4 character path.
3112 __ Subs(temp, num_chr, 4);
Artem Serov517d9f62016-12-12 15:51:15 +00003113 __ B(lt, &remainder, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003114
3115 // Keep the result of the earlier subs, we are going to fetch at least 4 characters.
3116 __ Mov(num_chr, temp);
3117
3118 // Main loop used for longer fetches loads and stores 4x16-bit characters at a time.
3119 // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code
3120 // to rectify these everywhere this intrinsic applies.)
3121 __ Bind(&loop);
3122 __ Ldr(temp, MemOperand(src_ptr, char_size * 2));
3123 __ Subs(num_chr, num_chr, 4);
3124 __ Str(temp, MemOperand(dst_ptr, char_size * 2));
3125 __ Ldr(temp, MemOperand(src_ptr, char_size * 4, PostIndex));
3126 __ Str(temp, MemOperand(dst_ptr, char_size * 4, PostIndex));
3127 temps.Release(temp);
Artem Serov517d9f62016-12-12 15:51:15 +00003128 __ B(ge, &loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003129
3130 __ Adds(num_chr, num_chr, 4);
Anton Kirilov6f644202017-02-27 18:29:45 +00003131 __ B(eq, final_label, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003132
3133 // Main loop for < 4 character case and remainder handling. Loads and stores one
3134 // 16-bit Java character at a time.
3135 __ Bind(&remainder);
3136 temp = temps.Acquire();
3137 __ Ldrh(temp, MemOperand(src_ptr, char_size, PostIndex));
3138 __ Subs(num_chr, num_chr, 1);
3139 __ Strh(temp, MemOperand(dst_ptr, char_size, PostIndex));
3140 temps.Release(temp);
Artem Serov517d9f62016-12-12 15:51:15 +00003141 __ B(gt, &remainder, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003142
3143 if (mirror::kUseStringCompression) {
Anton Kirilov6f644202017-02-27 18:29:45 +00003144 __ B(final_label);
Vladimir Markofdaf0f42016-10-13 19:29:53 +01003145
Anton Kirilov5ec62182016-10-13 20:16:02 +01003146 const size_t c_char_size = Primitive::ComponentSize(Primitive::kPrimByte);
3147 DCHECK_EQ(c_char_size, 1u);
3148 // Copy loop for compressed src, copying 1 character (8-bit) to (16-bit) at a time.
3149 __ Bind(&compressed_string_preloop);
3150 __ Add(src_ptr, src_ptr, srcBegin);
3151 __ Bind(&compressed_string_loop);
3152 temp = temps.Acquire();
3153 __ Ldrb(temp, MemOperand(src_ptr, c_char_size, PostIndex));
3154 __ Strh(temp, MemOperand(dst_ptr, char_size, PostIndex));
3155 temps.Release(temp);
3156 __ Subs(num_chr, num_chr, 1);
Artem Serov517d9f62016-12-12 15:51:15 +00003157 __ B(gt, &compressed_string_loop, /* far_target */ false);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003158 }
3159
Anton Kirilov6f644202017-02-27 18:29:45 +00003160 if (done.IsReferenced()) {
3161 __ Bind(&done);
3162 }
Anton Kirilov5ec62182016-10-13 20:16:02 +01003163}
3164
3165void IntrinsicLocationsBuilderARMVIXL::VisitFloatIsInfinite(HInvoke* invoke) {
3166 CreateFPToIntLocations(arena_, invoke);
3167}
3168
3169void IntrinsicCodeGeneratorARMVIXL::VisitFloatIsInfinite(HInvoke* invoke) {
3170 ArmVIXLAssembler* const assembler = GetAssembler();
3171 const vixl32::Register out = OutputRegister(invoke);
3172 // Shifting left by 1 bit makes the value encodable as an immediate operand;
3173 // we don't care about the sign bit anyway.
3174 constexpr uint32_t infinity = kPositiveInfinityFloat << 1U;
3175
3176 __ Vmov(out, InputSRegisterAt(invoke, 0));
3177 // We don't care about the sign bit, so shift left.
3178 __ Lsl(out, out, 1);
3179 __ Eor(out, out, infinity);
Anton Kirilov5601d4e2017-05-11 19:33:50 +01003180 codegen_->GenerateConditionWithZero(kCondEQ, out, out);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003181}
3182
3183void IntrinsicLocationsBuilderARMVIXL::VisitDoubleIsInfinite(HInvoke* invoke) {
3184 CreateFPToIntLocations(arena_, invoke);
3185}
3186
3187void IntrinsicCodeGeneratorARMVIXL::VisitDoubleIsInfinite(HInvoke* invoke) {
3188 ArmVIXLAssembler* const assembler = GetAssembler();
3189 const vixl32::Register out = OutputRegister(invoke);
3190 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
3191 const vixl32::Register temp = temps.Acquire();
3192 // The highest 32 bits of double precision positive infinity separated into
3193 // two constants encodable as immediate operands.
3194 constexpr uint32_t infinity_high = 0x7f000000U;
3195 constexpr uint32_t infinity_high2 = 0x00f00000U;
3196
3197 static_assert((infinity_high | infinity_high2) ==
3198 static_cast<uint32_t>(kPositiveInfinityDouble >> 32U),
3199 "The constants do not add up to the high 32 bits of double "
3200 "precision positive infinity.");
3201 __ Vmov(temp, out, InputDRegisterAt(invoke, 0));
3202 __ Eor(out, out, infinity_high);
3203 __ Eor(out, out, infinity_high2);
3204 // We don't care about the sign bit, so shift left.
3205 __ Orr(out, temp, Operand(out, vixl32::LSL, 1));
Anton Kirilov5601d4e2017-05-11 19:33:50 +01003206 codegen_->GenerateConditionWithZero(kCondEQ, out, out);
Anton Kirilov5ec62182016-10-13 20:16:02 +01003207}
3208
Artem Serov9aee2d42017-01-06 15:58:31 +00003209void IntrinsicLocationsBuilderARMVIXL::VisitMathCeil(HInvoke* invoke) {
3210 if (features_.HasARMv8AInstructions()) {
3211 CreateFPToFPLocations(arena_, invoke);
3212 }
3213}
3214
3215void IntrinsicCodeGeneratorARMVIXL::VisitMathCeil(HInvoke* invoke) {
3216 ArmVIXLAssembler* assembler = GetAssembler();
3217 DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions());
3218 __ Vrintp(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0));
3219}
3220
3221void IntrinsicLocationsBuilderARMVIXL::VisitMathFloor(HInvoke* invoke) {
3222 if (features_.HasARMv8AInstructions()) {
3223 CreateFPToFPLocations(arena_, invoke);
3224 }
3225}
3226
3227void IntrinsicCodeGeneratorARMVIXL::VisitMathFloor(HInvoke* invoke) {
3228 ArmVIXLAssembler* assembler = GetAssembler();
3229 DCHECK(codegen_->GetInstructionSetFeatures().HasARMv8AInstructions());
3230 __ Vrintm(F64, F64, OutputDRegister(invoke), InputDRegisterAt(invoke, 0));
3231}
3232
Nicolas Geoffray331605a2017-03-01 11:01:41 +00003233void IntrinsicLocationsBuilderARMVIXL::VisitIntegerValueOf(HInvoke* invoke) {
3234 InvokeRuntimeCallingConventionARMVIXL calling_convention;
3235 IntrinsicVisitor::ComputeIntegerValueOfLocations(
3236 invoke,
3237 codegen_,
3238 LocationFrom(r0),
3239 LocationFrom(calling_convention.GetRegisterAt(0)));
3240}
3241
3242void IntrinsicCodeGeneratorARMVIXL::VisitIntegerValueOf(HInvoke* invoke) {
3243 IntrinsicVisitor::IntegerValueOfInfo info = IntrinsicVisitor::ComputeIntegerValueOfInfo();
3244 LocationSummary* locations = invoke->GetLocations();
3245 ArmVIXLAssembler* const assembler = GetAssembler();
3246
3247 vixl32::Register out = RegisterFrom(locations->Out());
3248 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
3249 vixl32::Register temp = temps.Acquire();
3250 InvokeRuntimeCallingConventionARMVIXL calling_convention;
3251 vixl32::Register argument = calling_convention.GetRegisterAt(0);
3252 if (invoke->InputAt(0)->IsConstant()) {
3253 int32_t value = invoke->InputAt(0)->AsIntConstant()->GetValue();
3254 if (value >= info.low && value <= info.high) {
3255 // Just embed the j.l.Integer in the code.
3256 ScopedObjectAccess soa(Thread::Current());
3257 mirror::Object* boxed = info.cache->Get(value + (-info.low));
3258 DCHECK(boxed != nullptr && Runtime::Current()->GetHeap()->ObjectIsInBootImageSpace(boxed));
3259 uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(boxed));
3260 __ Ldr(out, codegen_->DeduplicateBootImageAddressLiteral(address));
3261 } else {
3262 // Allocate and initialize a new j.l.Integer.
3263 // TODO: If we JIT, we could allocate the j.l.Integer now, and store it in the
3264 // JIT object table.
3265 uint32_t address =
3266 dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer));
3267 __ Ldr(argument, codegen_->DeduplicateBootImageAddressLiteral(address));
3268 codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc());
3269 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
3270 __ Mov(temp, value);
3271 assembler->StoreToOffset(kStoreWord, temp, out, info.value_offset);
3272 // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation
3273 // one.
3274 codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
3275 }
3276 } else {
3277 vixl32::Register in = RegisterFrom(locations->InAt(0));
3278 // Check bounds of our cache.
3279 __ Add(out, in, -info.low);
3280 __ Cmp(out, info.high - info.low + 1);
3281 vixl32::Label allocate, done;
Anton Kirilovfd522532017-05-10 12:46:57 +01003282 __ B(hs, &allocate, /* is_far_target */ false);
Nicolas Geoffray331605a2017-03-01 11:01:41 +00003283 // If the value is within the bounds, load the j.l.Integer directly from the array.
3284 uint32_t data_offset = mirror::Array::DataOffset(kHeapReferenceSize).Uint32Value();
3285 uint32_t address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.cache));
3286 __ Ldr(temp, codegen_->DeduplicateBootImageAddressLiteral(data_offset + address));
3287 codegen_->LoadFromShiftedRegOffset(Primitive::kPrimNot, locations->Out(), temp, out);
3288 assembler->MaybeUnpoisonHeapReference(out);
3289 __ B(&done);
3290 __ Bind(&allocate);
3291 // Otherwise allocate and initialize a new j.l.Integer.
3292 address = dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(info.integer));
3293 __ Ldr(argument, codegen_->DeduplicateBootImageAddressLiteral(address));
3294 codegen_->InvokeRuntime(kQuickAllocObjectInitialized, invoke, invoke->GetDexPc());
3295 CheckEntrypointTypes<kQuickAllocObjectWithChecks, void*, mirror::Class*>();
3296 assembler->StoreToOffset(kStoreWord, in, out, info.value_offset);
3297 // `value` is a final field :-( Ideally, we'd merge this memory barrier with the allocation
3298 // one.
3299 codegen_->GenerateMemoryBarrier(MemBarrierKind::kStoreStore);
3300 __ Bind(&done);
3301 }
3302}
3303
Nicolas Geoffray365719c2017-03-08 13:11:50 +00003304void IntrinsicLocationsBuilderARMVIXL::VisitThreadInterrupted(HInvoke* invoke) {
3305 LocationSummary* locations = new (arena_) LocationSummary(invoke,
3306 LocationSummary::kNoCall,
3307 kIntrinsified);
3308 locations->SetOut(Location::RequiresRegister());
3309}
3310
3311void IntrinsicCodeGeneratorARMVIXL::VisitThreadInterrupted(HInvoke* invoke) {
3312 ArmVIXLAssembler* assembler = GetAssembler();
3313 vixl32::Register out = RegisterFrom(invoke->GetLocations()->Out());
3314 int32_t offset = Thread::InterruptedOffset<kArmPointerSize>().Int32Value();
3315 __ Ldr(out, MemOperand(tr, offset));
3316 UseScratchRegisterScope temps(assembler->GetVIXLAssembler());
3317 vixl32::Register temp = temps.Acquire();
3318 vixl32::Label done;
Anton Kirilovfd522532017-05-10 12:46:57 +01003319 vixl32::Label* const final_label = codegen_->GetFinalLabel(invoke, &done);
3320 __ CompareAndBranchIfZero(out, final_label, /* far_target */ false);
Nicolas Geoffray365719c2017-03-08 13:11:50 +00003321 __ Dmb(vixl32::ISH);
3322 __ Mov(temp, 0);
3323 assembler->StoreToOffset(kStoreWord, temp, tr, offset);
3324 __ Dmb(vixl32::ISH);
Anton Kirilovfd522532017-05-10 12:46:57 +01003325 if (done.IsReferenced()) {
3326 __ Bind(&done);
3327 }
Nicolas Geoffray365719c2017-03-08 13:11:50 +00003328}
3329
Anton Kirilov5ec62182016-10-13 20:16:02 +01003330UNIMPLEMENTED_INTRINSIC(ARMVIXL, MathRoundDouble) // Could be done by changing rounding mode, maybe?
Anton Kirilov5ec62182016-10-13 20:16:02 +01003331UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeCASLong) // High register pressure.
3332UNIMPLEMENTED_INTRINSIC(ARMVIXL, SystemArrayCopyChar)
Vladimir Markod254f5c2017-06-02 15:18:36 +00003333UNIMPLEMENTED_INTRINSIC(ARMVIXL, ReferenceGetReferent)
Anton Kirilov5ec62182016-10-13 20:16:02 +01003334
Aart Bikff7d89c2016-11-07 08:49:28 -08003335UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringStringIndexOf);
3336UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringStringIndexOfAfter);
Aart Bik71bf7b42016-11-16 10:17:46 -08003337UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferAppend);
3338UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferLength);
3339UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBufferToString);
3340UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderAppend);
3341UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderLength);
3342UNIMPLEMENTED_INTRINSIC(ARMVIXL, StringBuilderToString);
Aart Bikff7d89c2016-11-07 08:49:28 -08003343
Anton Kirilov5ec62182016-10-13 20:16:02 +01003344// 1.8.
3345UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndAddInt)
3346UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndAddLong)
3347UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetInt)
3348UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetLong)
3349UNIMPLEMENTED_INTRINSIC(ARMVIXL, UnsafeGetAndSetObject)
3350
3351UNREACHABLE_INTRINSICS(ARMVIXL)
3352
3353#undef __
3354
3355} // namespace arm
3356} // namespace art