blob: 78924ba954ad3dacce5debbc349050c6273ad345 [file] [log] [blame]
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "intrinsics_arm.h"
18
19#include "arch/arm/instruction_set_features_arm.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070020#include "art_method.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080021#include "code_generator_arm.h"
22#include "entrypoints/quick/quick_entrypoints.h"
23#include "intrinsics.h"
Andreas Gampe85b62f22015-09-09 13:15:38 -070024#include "intrinsics_utils.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080025#include "mirror/array-inl.h"
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080026#include "mirror/string.h"
27#include "thread.h"
28#include "utils/arm/assembler_arm.h"
29
30namespace art {
31
32namespace arm {
33
34ArmAssembler* IntrinsicCodeGeneratorARM::GetAssembler() {
35 return codegen_->GetAssembler();
36}
37
38ArenaAllocator* IntrinsicCodeGeneratorARM::GetAllocator() {
39 return codegen_->GetGraph()->GetArena();
40}
41
Andreas Gampe85b62f22015-09-09 13:15:38 -070042using IntrinsicSlowPathARM = IntrinsicSlowPath<InvokeDexCallingConventionVisitorARM>;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080043
Roland Levillain0b671c02016-08-19 12:02:34 +010044// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
45#define __ down_cast<ArmAssembler*>(codegen->GetAssembler())-> // NOLINT
46
47// Slow path implementing the SystemArrayCopy intrinsic copy loop with read barriers.
48class ReadBarrierSystemArrayCopySlowPathARM : public SlowPathCode {
49 public:
50 explicit ReadBarrierSystemArrayCopySlowPathARM(HInstruction* instruction)
51 : SlowPathCode(instruction) {
52 DCHECK(kEmitCompilerReadBarrier);
53 DCHECK(kUseBakerReadBarrier);
54 }
55
56 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
57 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
58 LocationSummary* locations = instruction_->GetLocations();
59 DCHECK(locations->CanCall());
60 DCHECK(instruction_->IsInvokeStaticOrDirect())
61 << "Unexpected instruction in read barrier arraycopy slow path: "
62 << instruction_->DebugName();
63 DCHECK(instruction_->GetLocations()->Intrinsified());
64 DCHECK_EQ(instruction_->AsInvoke()->GetIntrinsic(), Intrinsics::kSystemArrayCopy);
65
66 int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
67 uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot);
68 uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value();
69
70 Register dest = locations->InAt(2).AsRegister<Register>();
71 Location dest_pos = locations->InAt(3);
72 Register src_curr_addr = locations->GetTemp(0).AsRegister<Register>();
73 Register dst_curr_addr = locations->GetTemp(1).AsRegister<Register>();
74 Register src_stop_addr = locations->GetTemp(2).AsRegister<Register>();
75 Register tmp = locations->GetTemp(3).AsRegister<Register>();
76
77 __ Bind(GetEntryLabel());
78 // Compute the base destination address in `dst_curr_addr`.
79 if (dest_pos.IsConstant()) {
80 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
81 __ AddConstant(dst_curr_addr, dest, element_size * constant + offset);
82 } else {
83 __ add(dst_curr_addr,
84 dest,
85 ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
86 __ AddConstant(dst_curr_addr, offset);
87 }
88
89 Label loop;
90 __ Bind(&loop);
91 __ ldr(tmp, Address(src_curr_addr, element_size, Address::PostIndex));
92 __ MaybeUnpoisonHeapReference(tmp);
93 // TODO: Inline the mark bit check before calling the runtime?
94 // tmp = ReadBarrier::Mark(tmp);
95 // No need to save live registers; it's taken care of by the
96 // entrypoint. Also, there is no need to update the stack mask,
97 // as this runtime call will not trigger a garbage collection.
98 // (See ReadBarrierMarkSlowPathARM::EmitNativeCode for more
99 // explanations.)
100 DCHECK_NE(tmp, SP);
101 DCHECK_NE(tmp, LR);
102 DCHECK_NE(tmp, PC);
103 // IP is used internally by the ReadBarrierMarkRegX entry point
104 // as a temporary (and not preserved). It thus cannot be used by
105 // any live register in this slow path.
106 DCHECK_NE(src_curr_addr, IP);
107 DCHECK_NE(dst_curr_addr, IP);
108 DCHECK_NE(src_stop_addr, IP);
109 DCHECK_NE(tmp, IP);
110 DCHECK(0 <= tmp && tmp < kNumberOfCoreRegisters) << tmp;
111 int32_t entry_point_offset =
112 CodeGenerator::GetReadBarrierMarkEntryPointsOffset<kArmPointerSize>(tmp);
113 // This runtime call does not require a stack map.
114 arm_codegen->InvokeRuntimeWithoutRecordingPcInfo(entry_point_offset, instruction_, this);
115 __ MaybePoisonHeapReference(tmp);
116 __ str(tmp, Address(dst_curr_addr, element_size, Address::PostIndex));
117 __ cmp(src_curr_addr, ShifterOperand(src_stop_addr));
118 __ b(&loop, NE);
119 __ b(GetExitLabel());
120 }
121
122 const char* GetDescription() const OVERRIDE { return "ReadBarrierSystemArrayCopySlowPathARM"; }
123
124 private:
125 DISALLOW_COPY_AND_ASSIGN(ReadBarrierSystemArrayCopySlowPathARM);
126};
127
128#undef __
129
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800130bool IntrinsicLocationsBuilderARM::TryDispatch(HInvoke* invoke) {
131 Dispatch(invoke);
132 LocationSummary* res = invoke->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +0000133 if (res == nullptr) {
134 return false;
135 }
Roland Levillain3b359c72015-11-17 19:35:12 +0000136 return res->Intrinsified();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800137}
138
139#define __ assembler->
140
141static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
142 LocationSummary* locations = new (arena) LocationSummary(invoke,
143 LocationSummary::kNoCall,
144 kIntrinsified);
145 locations->SetInAt(0, Location::RequiresFpuRegister());
146 locations->SetOut(Location::RequiresRegister());
147}
148
149static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
150 LocationSummary* locations = new (arena) LocationSummary(invoke,
151 LocationSummary::kNoCall,
152 kIntrinsified);
153 locations->SetInAt(0, Location::RequiresRegister());
154 locations->SetOut(Location::RequiresFpuRegister());
155}
156
157static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
158 Location input = locations->InAt(0);
159 Location output = locations->Out();
160 if (is64bit) {
161 __ vmovrrd(output.AsRegisterPairLow<Register>(),
162 output.AsRegisterPairHigh<Register>(),
163 FromLowSToD(input.AsFpuRegisterPairLow<SRegister>()));
164 } else {
165 __ vmovrs(output.AsRegister<Register>(), input.AsFpuRegister<SRegister>());
166 }
167}
168
169static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
170 Location input = locations->InAt(0);
171 Location output = locations->Out();
172 if (is64bit) {
173 __ vmovdrr(FromLowSToD(output.AsFpuRegisterPairLow<SRegister>()),
174 input.AsRegisterPairLow<Register>(),
175 input.AsRegisterPairHigh<Register>());
176 } else {
177 __ vmovsr(output.AsFpuRegister<SRegister>(), input.AsRegister<Register>());
178 }
179}
180
181void IntrinsicLocationsBuilderARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
182 CreateFPToIntLocations(arena_, invoke);
183}
184void IntrinsicLocationsBuilderARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
185 CreateIntToFPLocations(arena_, invoke);
186}
187
188void IntrinsicCodeGeneratorARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000189 MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800190}
191void IntrinsicCodeGeneratorARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000192 MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800193}
194
195void IntrinsicLocationsBuilderARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
196 CreateFPToIntLocations(arena_, invoke);
197}
198void IntrinsicLocationsBuilderARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
199 CreateIntToFPLocations(arena_, invoke);
200}
201
202void IntrinsicCodeGeneratorARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000203 MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800204}
205void IntrinsicCodeGeneratorARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000206 MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800207}
208
209static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
210 LocationSummary* locations = new (arena) LocationSummary(invoke,
211 LocationSummary::kNoCall,
212 kIntrinsified);
213 locations->SetInAt(0, Location::RequiresRegister());
214 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
215}
216
217static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
218 LocationSummary* locations = new (arena) LocationSummary(invoke,
219 LocationSummary::kNoCall,
220 kIntrinsified);
221 locations->SetInAt(0, Location::RequiresFpuRegister());
222 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
223}
224
Scott Wakeling611d3392015-07-10 11:42:06 +0100225static void GenNumberOfLeadingZeros(LocationSummary* locations,
226 Primitive::Type type,
227 ArmAssembler* assembler) {
228 Location in = locations->InAt(0);
229 Register out = locations->Out().AsRegister<Register>();
230
231 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
232
233 if (type == Primitive::kPrimLong) {
234 Register in_reg_lo = in.AsRegisterPairLow<Register>();
235 Register in_reg_hi = in.AsRegisterPairHigh<Register>();
236 Label end;
237 __ clz(out, in_reg_hi);
238 __ CompareAndBranchIfNonZero(in_reg_hi, &end);
239 __ clz(out, in_reg_lo);
240 __ AddConstant(out, 32);
241 __ Bind(&end);
242 } else {
243 __ clz(out, in.AsRegister<Register>());
244 }
245}
246
247void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
248 CreateIntToIntLocations(arena_, invoke);
249}
250
251void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
252 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
253}
254
255void IntrinsicLocationsBuilderARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
256 LocationSummary* locations = new (arena_) LocationSummary(invoke,
257 LocationSummary::kNoCall,
258 kIntrinsified);
259 locations->SetInAt(0, Location::RequiresRegister());
260 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
261}
262
263void IntrinsicCodeGeneratorARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
264 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
265}
266
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100267static void GenNumberOfTrailingZeros(LocationSummary* locations,
268 Primitive::Type type,
269 ArmAssembler* assembler) {
270 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
271
272 Register out = locations->Out().AsRegister<Register>();
273
274 if (type == Primitive::kPrimLong) {
275 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
276 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
277 Label end;
278 __ rbit(out, in_reg_lo);
279 __ clz(out, out);
280 __ CompareAndBranchIfNonZero(in_reg_lo, &end);
281 __ rbit(out, in_reg_hi);
282 __ clz(out, out);
283 __ AddConstant(out, 32);
284 __ Bind(&end);
285 } else {
286 Register in = locations->InAt(0).AsRegister<Register>();
287 __ rbit(out, in);
288 __ clz(out, out);
289 }
290}
291
292void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
293 LocationSummary* locations = new (arena_) LocationSummary(invoke,
294 LocationSummary::kNoCall,
295 kIntrinsified);
296 locations->SetInAt(0, Location::RequiresRegister());
297 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
298}
299
300void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
301 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
302}
303
304void IntrinsicLocationsBuilderARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
305 LocationSummary* locations = new (arena_) LocationSummary(invoke,
306 LocationSummary::kNoCall,
307 kIntrinsified);
308 locations->SetInAt(0, Location::RequiresRegister());
309 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
310}
311
312void IntrinsicCodeGeneratorARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
313 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
314}
315
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800316static void MathAbsFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
317 Location in = locations->InAt(0);
318 Location out = locations->Out();
319
320 if (is64bit) {
321 __ vabsd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
322 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
323 } else {
324 __ vabss(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
325 }
326}
327
328void IntrinsicLocationsBuilderARM::VisitMathAbsDouble(HInvoke* invoke) {
329 CreateFPToFPLocations(arena_, invoke);
330}
331
332void IntrinsicCodeGeneratorARM::VisitMathAbsDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000333 MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800334}
335
336void IntrinsicLocationsBuilderARM::VisitMathAbsFloat(HInvoke* invoke) {
337 CreateFPToFPLocations(arena_, invoke);
338}
339
340void IntrinsicCodeGeneratorARM::VisitMathAbsFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000341 MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800342}
343
344static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) {
345 LocationSummary* locations = new (arena) LocationSummary(invoke,
346 LocationSummary::kNoCall,
347 kIntrinsified);
348 locations->SetInAt(0, Location::RequiresRegister());
349 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
350
351 locations->AddTemp(Location::RequiresRegister());
352}
353
354static void GenAbsInteger(LocationSummary* locations,
355 bool is64bit,
356 ArmAssembler* assembler) {
357 Location in = locations->InAt(0);
358 Location output = locations->Out();
359
360 Register mask = locations->GetTemp(0).AsRegister<Register>();
361
362 if (is64bit) {
363 Register in_reg_lo = in.AsRegisterPairLow<Register>();
364 Register in_reg_hi = in.AsRegisterPairHigh<Register>();
365 Register out_reg_lo = output.AsRegisterPairLow<Register>();
366 Register out_reg_hi = output.AsRegisterPairHigh<Register>();
367
368 DCHECK_NE(out_reg_lo, in_reg_hi) << "Diagonal overlap unexpected.";
369
370 __ Asr(mask, in_reg_hi, 31);
371 __ adds(out_reg_lo, in_reg_lo, ShifterOperand(mask));
372 __ adc(out_reg_hi, in_reg_hi, ShifterOperand(mask));
373 __ eor(out_reg_lo, mask, ShifterOperand(out_reg_lo));
374 __ eor(out_reg_hi, mask, ShifterOperand(out_reg_hi));
375 } else {
376 Register in_reg = in.AsRegister<Register>();
377 Register out_reg = output.AsRegister<Register>();
378
379 __ Asr(mask, in_reg, 31);
380 __ add(out_reg, in_reg, ShifterOperand(mask));
381 __ eor(out_reg, mask, ShifterOperand(out_reg));
382 }
383}
384
385void IntrinsicLocationsBuilderARM::VisitMathAbsInt(HInvoke* invoke) {
386 CreateIntToIntPlusTemp(arena_, invoke);
387}
388
389void IntrinsicCodeGeneratorARM::VisitMathAbsInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000390 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800391}
392
393
394void IntrinsicLocationsBuilderARM::VisitMathAbsLong(HInvoke* invoke) {
395 CreateIntToIntPlusTemp(arena_, invoke);
396}
397
398void IntrinsicCodeGeneratorARM::VisitMathAbsLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000399 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800400}
401
402static void GenMinMax(LocationSummary* locations,
403 bool is_min,
404 ArmAssembler* assembler) {
405 Register op1 = locations->InAt(0).AsRegister<Register>();
406 Register op2 = locations->InAt(1).AsRegister<Register>();
407 Register out = locations->Out().AsRegister<Register>();
408
409 __ cmp(op1, ShifterOperand(op2));
410
411 __ it((is_min) ? Condition::LT : Condition::GT, kItElse);
412 __ mov(out, ShifterOperand(op1), is_min ? Condition::LT : Condition::GT);
413 __ mov(out, ShifterOperand(op2), is_min ? Condition::GE : Condition::LE);
414}
415
416static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
417 LocationSummary* locations = new (arena) LocationSummary(invoke,
418 LocationSummary::kNoCall,
419 kIntrinsified);
420 locations->SetInAt(0, Location::RequiresRegister());
421 locations->SetInAt(1, Location::RequiresRegister());
422 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
423}
424
425void IntrinsicLocationsBuilderARM::VisitMathMinIntInt(HInvoke* invoke) {
426 CreateIntIntToIntLocations(arena_, invoke);
427}
428
429void IntrinsicCodeGeneratorARM::VisitMathMinIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000430 GenMinMax(invoke->GetLocations(), /* is_min */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800431}
432
433void IntrinsicLocationsBuilderARM::VisitMathMaxIntInt(HInvoke* invoke) {
434 CreateIntIntToIntLocations(arena_, invoke);
435}
436
437void IntrinsicCodeGeneratorARM::VisitMathMaxIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000438 GenMinMax(invoke->GetLocations(), /* is_min */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800439}
440
441void IntrinsicLocationsBuilderARM::VisitMathSqrt(HInvoke* invoke) {
442 CreateFPToFPLocations(arena_, invoke);
443}
444
445void IntrinsicCodeGeneratorARM::VisitMathSqrt(HInvoke* invoke) {
446 LocationSummary* locations = invoke->GetLocations();
447 ArmAssembler* assembler = GetAssembler();
448 __ vsqrtd(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
449 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
450}
451
452void IntrinsicLocationsBuilderARM::VisitMemoryPeekByte(HInvoke* invoke) {
453 CreateIntToIntLocations(arena_, invoke);
454}
455
456void IntrinsicCodeGeneratorARM::VisitMemoryPeekByte(HInvoke* invoke) {
457 ArmAssembler* assembler = GetAssembler();
458 // Ignore upper 4B of long address.
459 __ ldrsb(invoke->GetLocations()->Out().AsRegister<Register>(),
460 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
461}
462
463void IntrinsicLocationsBuilderARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
464 CreateIntToIntLocations(arena_, invoke);
465}
466
467void IntrinsicCodeGeneratorARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
468 ArmAssembler* assembler = GetAssembler();
469 // Ignore upper 4B of long address.
470 __ ldr(invoke->GetLocations()->Out().AsRegister<Register>(),
471 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
472}
473
474void IntrinsicLocationsBuilderARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
475 CreateIntToIntLocations(arena_, invoke);
476}
477
478void IntrinsicCodeGeneratorARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
479 ArmAssembler* assembler = GetAssembler();
480 // Ignore upper 4B of long address.
481 Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
482 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
483 // exception. So we can't use ldrd as addr may be unaligned.
484 Register lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>();
485 Register hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>();
486 if (addr == lo) {
487 __ ldr(hi, Address(addr, 4));
488 __ ldr(lo, Address(addr, 0));
489 } else {
490 __ ldr(lo, Address(addr, 0));
491 __ ldr(hi, Address(addr, 4));
492 }
493}
494
495void IntrinsicLocationsBuilderARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
496 CreateIntToIntLocations(arena_, invoke);
497}
498
499void IntrinsicCodeGeneratorARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
500 ArmAssembler* assembler = GetAssembler();
501 // Ignore upper 4B of long address.
502 __ ldrsh(invoke->GetLocations()->Out().AsRegister<Register>(),
503 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
504}
505
506static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
507 LocationSummary* locations = new (arena) LocationSummary(invoke,
508 LocationSummary::kNoCall,
509 kIntrinsified);
510 locations->SetInAt(0, Location::RequiresRegister());
511 locations->SetInAt(1, Location::RequiresRegister());
512}
513
514void IntrinsicLocationsBuilderARM::VisitMemoryPokeByte(HInvoke* invoke) {
515 CreateIntIntToVoidLocations(arena_, invoke);
516}
517
518void IntrinsicCodeGeneratorARM::VisitMemoryPokeByte(HInvoke* invoke) {
519 ArmAssembler* assembler = GetAssembler();
520 __ strb(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
521 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
522}
523
524void IntrinsicLocationsBuilderARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
525 CreateIntIntToVoidLocations(arena_, invoke);
526}
527
528void IntrinsicCodeGeneratorARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
529 ArmAssembler* assembler = GetAssembler();
530 __ str(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
531 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
532}
533
534void IntrinsicLocationsBuilderARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
535 CreateIntIntToVoidLocations(arena_, invoke);
536}
537
538void IntrinsicCodeGeneratorARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
539 ArmAssembler* assembler = GetAssembler();
540 // Ignore upper 4B of long address.
541 Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
542 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
543 // exception. So we can't use ldrd as addr may be unaligned.
544 __ str(invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>(), Address(addr, 0));
545 __ str(invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>(), Address(addr, 4));
546}
547
548void IntrinsicLocationsBuilderARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
549 CreateIntIntToVoidLocations(arena_, invoke);
550}
551
552void IntrinsicCodeGeneratorARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
553 ArmAssembler* assembler = GetAssembler();
554 __ strh(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
555 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
556}
557
558void IntrinsicLocationsBuilderARM::VisitThreadCurrentThread(HInvoke* invoke) {
559 LocationSummary* locations = new (arena_) LocationSummary(invoke,
560 LocationSummary::kNoCall,
561 kIntrinsified);
562 locations->SetOut(Location::RequiresRegister());
563}
564
565void IntrinsicCodeGeneratorARM::VisitThreadCurrentThread(HInvoke* invoke) {
566 ArmAssembler* assembler = GetAssembler();
567 __ LoadFromOffset(kLoadWord,
568 invoke->GetLocations()->Out().AsRegister<Register>(),
569 TR,
570 Thread::PeerOffset<kArmPointerSize>().Int32Value());
571}
572
573static void GenUnsafeGet(HInvoke* invoke,
574 Primitive::Type type,
575 bool is_volatile,
576 CodeGeneratorARM* codegen) {
577 LocationSummary* locations = invoke->GetLocations();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800578 ArmAssembler* assembler = codegen->GetAssembler();
Roland Levillain3b359c72015-11-17 19:35:12 +0000579 Location base_loc = locations->InAt(1);
580 Register base = base_loc.AsRegister<Register>(); // Object pointer.
581 Location offset_loc = locations->InAt(2);
582 Register offset = offset_loc.AsRegisterPairLow<Register>(); // Long offset, lo part only.
583 Location trg_loc = locations->Out();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800584
Roland Levillainc9285912015-12-18 10:38:42 +0000585 switch (type) {
586 case Primitive::kPrimInt: {
587 Register trg = trg_loc.AsRegister<Register>();
588 __ ldr(trg, Address(base, offset));
589 if (is_volatile) {
590 __ dmb(ISH);
591 }
592 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800593 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800594
Roland Levillainc9285912015-12-18 10:38:42 +0000595 case Primitive::kPrimNot: {
596 Register trg = trg_loc.AsRegister<Register>();
597 if (kEmitCompilerReadBarrier) {
598 if (kUseBakerReadBarrier) {
599 Location temp = locations->GetTemp(0);
Roland Levillainbfea3352016-06-23 13:48:47 +0100600 codegen->GenerateReferenceLoadWithBakerReadBarrier(
601 invoke, trg_loc, base, 0U, offset_loc, TIMES_1, temp, /* needs_null_check */ false);
Roland Levillainc9285912015-12-18 10:38:42 +0000602 if (is_volatile) {
603 __ dmb(ISH);
604 }
605 } else {
606 __ ldr(trg, Address(base, offset));
607 if (is_volatile) {
608 __ dmb(ISH);
609 }
610 codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc);
611 }
612 } else {
613 __ ldr(trg, Address(base, offset));
614 if (is_volatile) {
615 __ dmb(ISH);
616 }
617 __ MaybeUnpoisonHeapReference(trg);
618 }
619 break;
620 }
Roland Levillain4d027112015-07-01 15:41:14 +0100621
Roland Levillainc9285912015-12-18 10:38:42 +0000622 case Primitive::kPrimLong: {
623 Register trg_lo = trg_loc.AsRegisterPairLow<Register>();
624 __ add(IP, base, ShifterOperand(offset));
625 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
626 Register trg_hi = trg_loc.AsRegisterPairHigh<Register>();
627 __ ldrexd(trg_lo, trg_hi, IP);
628 } else {
629 __ ldrd(trg_lo, Address(IP));
630 }
631 if (is_volatile) {
632 __ dmb(ISH);
633 }
634 break;
635 }
636
637 default:
638 LOG(FATAL) << "Unexpected type " << type;
639 UNREACHABLE();
Roland Levillain4d027112015-07-01 15:41:14 +0100640 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800641}
642
Roland Levillainc9285912015-12-18 10:38:42 +0000643static void CreateIntIntIntToIntLocations(ArenaAllocator* arena,
644 HInvoke* invoke,
645 Primitive::Type type) {
Roland Levillain3b359c72015-11-17 19:35:12 +0000646 bool can_call = kEmitCompilerReadBarrier &&
647 (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject ||
648 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800649 LocationSummary* locations = new (arena) LocationSummary(invoke,
Roland Levillain3b359c72015-11-17 19:35:12 +0000650 can_call ?
651 LocationSummary::kCallOnSlowPath :
652 LocationSummary::kNoCall,
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800653 kIntrinsified);
Vladimir Marko70e97462016-08-09 11:04:26 +0100654 if (can_call && kUseBakerReadBarrier) {
655 locations->SetCustomSlowPathCallerSaves(RegisterSet()); // No caller-save registers.
656 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800657 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
658 locations->SetInAt(1, Location::RequiresRegister());
659 locations->SetInAt(2, Location::RequiresRegister());
Roland Levillainbfea3352016-06-23 13:48:47 +0100660 locations->SetOut(Location::RequiresRegister(),
661 can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Roland Levillainc9285912015-12-18 10:38:42 +0000662 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
663 // We need a temporary register for the read barrier marking slow
Roland Levillainbfea3352016-06-23 13:48:47 +0100664 // path in InstructionCodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier.
Roland Levillainc9285912015-12-18 10:38:42 +0000665 locations->AddTemp(Location::RequiresRegister());
666 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800667}
668
669void IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000670 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800671}
672void IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000673 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800674}
675void IntrinsicLocationsBuilderARM::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000676 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800677}
678void IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000679 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800680}
681void IntrinsicLocationsBuilderARM::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000682 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800683}
684void IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000685 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800686}
687
688void IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000689 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800690}
691void IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000692 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800693}
694void IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000695 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800696}
697void IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000698 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800699}
700void IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000701 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800702}
703void IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000704 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800705}
706
707static void CreateIntIntIntIntToVoid(ArenaAllocator* arena,
708 const ArmInstructionSetFeatures& features,
709 Primitive::Type type,
710 bool is_volatile,
711 HInvoke* invoke) {
712 LocationSummary* locations = new (arena) LocationSummary(invoke,
713 LocationSummary::kNoCall,
714 kIntrinsified);
715 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
716 locations->SetInAt(1, Location::RequiresRegister());
717 locations->SetInAt(2, Location::RequiresRegister());
718 locations->SetInAt(3, Location::RequiresRegister());
719
720 if (type == Primitive::kPrimLong) {
721 // Potentially need temps for ldrexd-strexd loop.
722 if (is_volatile && !features.HasAtomicLdrdAndStrd()) {
723 locations->AddTemp(Location::RequiresRegister()); // Temp_lo.
724 locations->AddTemp(Location::RequiresRegister()); // Temp_hi.
725 }
726 } else if (type == Primitive::kPrimNot) {
727 // Temps for card-marking.
728 locations->AddTemp(Location::RequiresRegister()); // Temp.
729 locations->AddTemp(Location::RequiresRegister()); // Card.
730 }
731}
732
733void IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000734 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800735}
736void IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000737 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800738}
739void IntrinsicLocationsBuilderARM::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000740 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800741}
742void IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000743 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800744}
745void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000746 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800747}
748void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000749 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800750}
751void IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000752 CreateIntIntIntIntToVoid(
753 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800754}
755void IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000756 CreateIntIntIntIntToVoid(
757 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800758}
759void IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000760 CreateIntIntIntIntToVoid(
761 arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800762}
763
764static void GenUnsafePut(LocationSummary* locations,
765 Primitive::Type type,
766 bool is_volatile,
767 bool is_ordered,
768 CodeGeneratorARM* codegen) {
769 ArmAssembler* assembler = codegen->GetAssembler();
770
771 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
772 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Long offset, lo part only.
773 Register value;
774
775 if (is_volatile || is_ordered) {
776 __ dmb(ISH);
777 }
778
779 if (type == Primitive::kPrimLong) {
780 Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>();
781 value = value_lo;
782 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
783 Register temp_lo = locations->GetTemp(0).AsRegister<Register>();
784 Register temp_hi = locations->GetTemp(1).AsRegister<Register>();
785 Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>();
786
787 __ add(IP, base, ShifterOperand(offset));
788 Label loop_head;
789 __ Bind(&loop_head);
790 __ ldrexd(temp_lo, temp_hi, IP);
791 __ strexd(temp_lo, value_lo, value_hi, IP);
792 __ cmp(temp_lo, ShifterOperand(0));
793 __ b(&loop_head, NE);
794 } else {
795 __ add(IP, base, ShifterOperand(offset));
796 __ strd(value_lo, Address(IP));
797 }
798 } else {
Roland Levillain4d027112015-07-01 15:41:14 +0100799 value = locations->InAt(3).AsRegister<Register>();
800 Register source = value;
801 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
802 Register temp = locations->GetTemp(0).AsRegister<Register>();
803 __ Mov(temp, value);
804 __ PoisonHeapReference(temp);
805 source = temp;
806 }
807 __ str(source, Address(base, offset));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800808 }
809
810 if (is_volatile) {
811 __ dmb(ISH);
812 }
813
814 if (type == Primitive::kPrimNot) {
815 Register temp = locations->GetTemp(0).AsRegister<Register>();
816 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100817 bool value_can_be_null = true; // TODO: Worth finding out this information?
818 codegen->MarkGCCard(temp, card, base, value, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800819 }
820}
821
822void IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000823 GenUnsafePut(invoke->GetLocations(),
824 Primitive::kPrimInt,
825 /* is_volatile */ false,
826 /* is_ordered */ false,
827 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800828}
829void IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000830 GenUnsafePut(invoke->GetLocations(),
831 Primitive::kPrimInt,
832 /* is_volatile */ false,
833 /* is_ordered */ true,
834 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800835}
836void IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000837 GenUnsafePut(invoke->GetLocations(),
838 Primitive::kPrimInt,
839 /* is_volatile */ true,
840 /* is_ordered */ false,
841 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800842}
843void IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000844 GenUnsafePut(invoke->GetLocations(),
845 Primitive::kPrimNot,
846 /* is_volatile */ false,
847 /* is_ordered */ false,
848 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800849}
850void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000851 GenUnsafePut(invoke->GetLocations(),
852 Primitive::kPrimNot,
853 /* is_volatile */ false,
854 /* is_ordered */ true,
855 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800856}
857void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000858 GenUnsafePut(invoke->GetLocations(),
859 Primitive::kPrimNot,
860 /* is_volatile */ true,
861 /* is_ordered */ false,
862 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800863}
864void IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000865 GenUnsafePut(invoke->GetLocations(),
866 Primitive::kPrimLong,
867 /* is_volatile */ false,
868 /* is_ordered */ false,
869 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800870}
871void IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000872 GenUnsafePut(invoke->GetLocations(),
873 Primitive::kPrimLong,
874 /* is_volatile */ false,
875 /* is_ordered */ true,
876 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800877}
878void IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000879 GenUnsafePut(invoke->GetLocations(),
880 Primitive::kPrimLong,
881 /* is_volatile */ true,
882 /* is_ordered */ false,
883 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800884}
885
886static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena,
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000887 HInvoke* invoke,
888 Primitive::Type type) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800889 LocationSummary* locations = new (arena) LocationSummary(invoke,
890 LocationSummary::kNoCall,
891 kIntrinsified);
892 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
893 locations->SetInAt(1, Location::RequiresRegister());
894 locations->SetInAt(2, Location::RequiresRegister());
895 locations->SetInAt(3, Location::RequiresRegister());
896 locations->SetInAt(4, Location::RequiresRegister());
897
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000898 // If heap poisoning is enabled, we don't want the unpoisoning
899 // operations to potentially clobber the output.
900 Location::OutputOverlap overlaps = (kPoisonHeapReferences && type == Primitive::kPrimNot)
901 ? Location::kOutputOverlap
902 : Location::kNoOutputOverlap;
903 locations->SetOut(Location::RequiresRegister(), overlaps);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800904
905 locations->AddTemp(Location::RequiresRegister()); // Pointer.
906 locations->AddTemp(Location::RequiresRegister()); // Temp 1.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800907}
908
909static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM* codegen) {
910 DCHECK_NE(type, Primitive::kPrimLong);
911
912 ArmAssembler* assembler = codegen->GetAssembler();
913
914 Register out = locations->Out().AsRegister<Register>(); // Boolean result.
915
916 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
917 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Offset (discard high 4B).
918 Register expected_lo = locations->InAt(3).AsRegister<Register>(); // Expected.
919 Register value_lo = locations->InAt(4).AsRegister<Register>(); // Value.
920
921 Register tmp_ptr = locations->GetTemp(0).AsRegister<Register>(); // Pointer to actual memory.
922 Register tmp_lo = locations->GetTemp(1).AsRegister<Register>(); // Value in memory.
923
924 if (type == Primitive::kPrimNot) {
925 // Mark card for object assuming new value is stored. Worst case we will mark an unchanged
926 // object and scan the receiver at the next GC for nothing.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100927 bool value_can_be_null = true; // TODO: Worth finding out this information?
928 codegen->MarkGCCard(tmp_ptr, tmp_lo, base, value_lo, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800929 }
930
931 // Prevent reordering with prior memory operations.
Roland Levillain4bedb382016-01-12 12:01:04 +0000932 // Emit a DMB ISH instruction instead of an DMB ISHST one, as the
933 // latter allows a preceding load to be delayed past the STXR
934 // instruction below.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800935 __ dmb(ISH);
936
937 __ add(tmp_ptr, base, ShifterOperand(offset));
938
Roland Levillain4d027112015-07-01 15:41:14 +0100939 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
940 codegen->GetAssembler()->PoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000941 if (value_lo == expected_lo) {
942 // Do not poison `value_lo`, as it is the same register as
943 // `expected_lo`, which has just been poisoned.
944 } else {
945 codegen->GetAssembler()->PoisonHeapReference(value_lo);
946 }
Roland Levillain4d027112015-07-01 15:41:14 +0100947 }
948
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800949 // do {
950 // tmp = [r_ptr] - expected;
951 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
952 // result = tmp != 0;
953
954 Label loop_head;
955 __ Bind(&loop_head);
956
Roland Levillain391b8662015-12-18 11:43:38 +0000957 // TODO: When `type == Primitive::kPrimNot`, add a read barrier for
958 // the reference stored in the object before attempting the CAS,
959 // similar to the one in the art::Unsafe_compareAndSwapObject JNI
960 // implementation.
961 //
962 // Note that this code is not (yet) used when read barriers are
963 // enabled (see IntrinsicLocationsBuilderARM::VisitUnsafeCASObject).
964 DCHECK(!(type == Primitive::kPrimNot && kEmitCompilerReadBarrier));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800965 __ ldrex(tmp_lo, tmp_ptr);
966
967 __ subs(tmp_lo, tmp_lo, ShifterOperand(expected_lo));
968
969 __ it(EQ, ItState::kItT);
970 __ strex(tmp_lo, value_lo, tmp_ptr, EQ);
971 __ cmp(tmp_lo, ShifterOperand(1), EQ);
972
973 __ b(&loop_head, EQ);
974
975 __ dmb(ISH);
976
977 __ rsbs(out, tmp_lo, ShifterOperand(1));
978 __ it(CC);
979 __ mov(out, ShifterOperand(0), CC);
Roland Levillain4d027112015-07-01 15:41:14 +0100980
981 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
Roland Levillain4d027112015-07-01 15:41:14 +0100982 codegen->GetAssembler()->UnpoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000983 if (value_lo == expected_lo) {
984 // Do not unpoison `value_lo`, as it is the same register as
985 // `expected_lo`, which has just been unpoisoned.
986 } else {
987 codegen->GetAssembler()->UnpoisonHeapReference(value_lo);
988 }
Roland Levillain4d027112015-07-01 15:41:14 +0100989 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800990}
991
Andreas Gampeca714582015-04-03 19:41:34 -0700992void IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) {
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000993 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800994}
Andreas Gampeca714582015-04-03 19:41:34 -0700995void IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillain391b8662015-12-18 11:43:38 +0000996 // The UnsafeCASObject intrinsic is missing a read barrier, and
997 // therefore sometimes does not work as expected (b/25883050).
998 // Turn it off temporarily as a quick fix, until the read barrier is
Roland Levillain3d312422016-06-23 13:53:42 +0100999 // implemented (see TODO in GenCAS).
Roland Levillain391b8662015-12-18 11:43:38 +00001000 //
Roland Levillain3d312422016-06-23 13:53:42 +01001001 // TODO(rpl): Implement read barrier support in GenCAS and re-enable
1002 // this intrinsic.
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001003 if (kEmitCompilerReadBarrier) {
Roland Levillain985ff702015-10-23 13:25:35 +01001004 return;
1005 }
1006
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001007 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001008}
1009void IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) {
1010 GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
1011}
1012void IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillain3d312422016-06-23 13:53:42 +01001013 // The UnsafeCASObject intrinsic is missing a read barrier, and
1014 // therefore sometimes does not work as expected (b/25883050).
1015 // Turn it off temporarily as a quick fix, until the read barrier is
1016 // implemented (see TODO in GenCAS).
1017 //
1018 // TODO(rpl): Implement read barrier support in GenCAS and re-enable
1019 // this intrinsic.
1020 DCHECK(!kEmitCompilerReadBarrier);
1021
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001022 GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
1023}
1024
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001025void IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) {
1026 // The inputs plus one temp.
1027 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001028 invoke->InputAt(1)->CanBeNull()
1029 ? LocationSummary::kCallOnSlowPath
1030 : LocationSummary::kNoCall,
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001031 kIntrinsified);
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001032 locations->SetInAt(0, Location::RequiresRegister());
1033 locations->SetInAt(1, Location::RequiresRegister());
1034 locations->AddTemp(Location::RequiresRegister());
1035 locations->AddTemp(Location::RequiresRegister());
1036 locations->AddTemp(Location::RequiresRegister());
1037 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001038}
1039
1040void IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) {
1041 ArmAssembler* assembler = GetAssembler();
1042 LocationSummary* locations = invoke->GetLocations();
1043
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001044 Register str = locations->InAt(0).AsRegister<Register>();
1045 Register arg = locations->InAt(1).AsRegister<Register>();
1046 Register out = locations->Out().AsRegister<Register>();
1047
1048 Register temp0 = locations->GetTemp(0).AsRegister<Register>();
1049 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1050 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1051
1052 Label loop;
1053 Label find_char_diff;
1054 Label end;
1055
1056 // Get offsets of count and value fields within a string object.
1057 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1058 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1059
Nicolas Geoffray512e04d2015-03-27 17:21:24 +00001060 // Note that the null check must have been done earlier.
Calin Juravle641547a2015-04-21 22:08:51 +01001061 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001062
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001063 // Take slow path and throw if input can be and is null.
1064 SlowPathCode* slow_path = nullptr;
1065 const bool can_slow_path = invoke->InputAt(1)->CanBeNull();
1066 if (can_slow_path) {
1067 slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1068 codegen_->AddSlowPath(slow_path);
1069 __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel());
1070 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001071
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001072 // Reference equality check, return 0 if same reference.
1073 __ subs(out, str, ShifterOperand(arg));
1074 __ b(&end, EQ);
1075 // Load lengths of this and argument strings.
1076 __ ldr(temp2, Address(str, count_offset));
1077 __ ldr(temp1, Address(arg, count_offset));
1078 // out = length diff.
1079 __ subs(out, temp2, ShifterOperand(temp1));
1080 // temp0 = min(len(str), len(arg)).
1081 __ it(Condition::LT, kItElse);
1082 __ mov(temp0, ShifterOperand(temp2), Condition::LT);
1083 __ mov(temp0, ShifterOperand(temp1), Condition::GE);
1084 // Shorter string is empty?
1085 __ CompareAndBranchIfZero(temp0, &end);
1086
1087 // Store offset of string value in preparation for comparison loop.
1088 __ mov(temp1, ShifterOperand(value_offset));
1089
1090 // Assertions that must hold in order to compare multiple characters at a time.
1091 CHECK_ALIGNED(value_offset, 8);
1092 static_assert(IsAligned<8>(kObjectAlignment),
1093 "String data must be 8-byte aligned for unrolled CompareTo loop.");
1094
1095 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
1096 DCHECK_EQ(char_size, 2u);
1097
1098 // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment).
1099 __ Bind(&loop);
1100 __ ldr(IP, Address(str, temp1));
1101 __ ldr(temp2, Address(arg, temp1));
1102 __ cmp(IP, ShifterOperand(temp2));
1103 __ b(&find_char_diff, NE);
1104 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1105 __ sub(temp0, temp0, ShifterOperand(2));
1106
1107 __ ldr(IP, Address(str, temp1));
1108 __ ldr(temp2, Address(arg, temp1));
1109 __ cmp(IP, ShifterOperand(temp2));
1110 __ b(&find_char_diff, NE);
1111 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1112 __ subs(temp0, temp0, ShifterOperand(2));
1113
1114 __ b(&loop, GT);
1115 __ b(&end);
1116
1117 // Find the single 16-bit character difference.
1118 __ Bind(&find_char_diff);
1119 // Get the bit position of the first character that differs.
1120 __ eor(temp1, temp2, ShifterOperand(IP));
1121 __ rbit(temp1, temp1);
1122 __ clz(temp1, temp1);
1123
1124 // temp0 = number of 16-bit characters remaining to compare.
1125 // (it could be < 1 if a difference is found after the first SUB in the comparison loop, and
1126 // after the end of the shorter string data).
1127
1128 // (temp1 >> 4) = character where difference occurs between the last two words compared, on the
1129 // interval [0,1] (0 for low half-word different, 1 for high half-word different).
1130
1131 // If temp0 <= (temp1 >> 4), the difference occurs outside the remaining string data, so just
1132 // return length diff (out).
1133 __ cmp(temp0, ShifterOperand(temp1, LSR, 4));
1134 __ b(&end, LE);
1135 // Extract the characters and calculate the difference.
1136 __ bic(temp1, temp1, ShifterOperand(0xf));
1137 __ Lsr(temp2, temp2, temp1);
1138 __ Lsr(IP, IP, temp1);
1139 __ movt(temp2, 0);
1140 __ movt(IP, 0);
1141 __ sub(out, IP, ShifterOperand(temp2));
1142
1143 __ Bind(&end);
1144
1145 if (can_slow_path) {
1146 __ Bind(slow_path->GetExitLabel());
1147 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001148}
1149
Agi Csaki289cd552015-08-18 17:10:38 -07001150void IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) {
1151 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1152 LocationSummary::kNoCall,
1153 kIntrinsified);
1154 InvokeRuntimeCallingConvention calling_convention;
1155 locations->SetInAt(0, Location::RequiresRegister());
1156 locations->SetInAt(1, Location::RequiresRegister());
1157 // Temporary registers to store lengths of strings and for calculations.
1158 // Using instruction cbz requires a low register, so explicitly set a temp to be R0.
1159 locations->AddTemp(Location::RegisterLocation(R0));
1160 locations->AddTemp(Location::RequiresRegister());
1161 locations->AddTemp(Location::RequiresRegister());
1162
1163 locations->SetOut(Location::RequiresRegister());
1164}
1165
1166void IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) {
1167 ArmAssembler* assembler = GetAssembler();
1168 LocationSummary* locations = invoke->GetLocations();
1169
1170 Register str = locations->InAt(0).AsRegister<Register>();
1171 Register arg = locations->InAt(1).AsRegister<Register>();
1172 Register out = locations->Out().AsRegister<Register>();
1173
1174 Register temp = locations->GetTemp(0).AsRegister<Register>();
1175 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1176 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1177
1178 Label loop;
1179 Label end;
1180 Label return_true;
1181 Label return_false;
1182
1183 // Get offsets of count, value, and class fields within a string object.
1184 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1185 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1186 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1187
1188 // Note that the null check must have been done earlier.
1189 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1190
Vladimir Marko53b52002016-05-24 19:30:45 +01001191 StringEqualsOptimizations optimizations(invoke);
1192 if (!optimizations.GetArgumentNotNull()) {
1193 // Check if input is null, return false if it is.
1194 __ CompareAndBranchIfZero(arg, &return_false);
1195 }
Agi Csaki289cd552015-08-18 17:10:38 -07001196
Vladimir Marko53b52002016-05-24 19:30:45 +01001197 if (!optimizations.GetArgumentIsString()) {
1198 // Instanceof check for the argument by comparing class fields.
1199 // All string objects must have the same type since String cannot be subclassed.
1200 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1201 // If the argument is a string object, its class field must be equal to receiver's class field.
1202 __ ldr(temp, Address(str, class_offset));
1203 __ ldr(temp1, Address(arg, class_offset));
1204 __ cmp(temp, ShifterOperand(temp1));
1205 __ b(&return_false, NE);
1206 }
Agi Csaki289cd552015-08-18 17:10:38 -07001207
1208 // Load lengths of this and argument strings.
1209 __ ldr(temp, Address(str, count_offset));
1210 __ ldr(temp1, Address(arg, count_offset));
1211 // Check if lengths are equal, return false if they're not.
1212 __ cmp(temp, ShifterOperand(temp1));
1213 __ b(&return_false, NE);
1214 // Return true if both strings are empty.
1215 __ cbz(temp, &return_true);
1216
1217 // Reference equality check, return true if same reference.
1218 __ cmp(str, ShifterOperand(arg));
1219 __ b(&return_true, EQ);
1220
1221 // Assertions that must hold in order to compare strings 2 characters at a time.
1222 DCHECK_ALIGNED(value_offset, 4);
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001223 static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare.");
Agi Csaki289cd552015-08-18 17:10:38 -07001224
Agi Csaki289cd552015-08-18 17:10:38 -07001225 __ LoadImmediate(temp1, value_offset);
Agi Csaki289cd552015-08-18 17:10:38 -07001226
1227 // Loop to compare strings 2 characters at a time starting at the front of the string.
1228 // Ok to do this because strings with an odd length are zero-padded.
1229 __ Bind(&loop);
1230 __ ldr(out, Address(str, temp1));
1231 __ ldr(temp2, Address(arg, temp1));
1232 __ cmp(out, ShifterOperand(temp2));
1233 __ b(&return_false, NE);
1234 __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t)));
Vladimir Markoa63f0d42015-09-01 13:36:35 +01001235 __ subs(temp, temp, ShifterOperand(sizeof(uint32_t) / sizeof(uint16_t)));
1236 __ b(&loop, GT);
Agi Csaki289cd552015-08-18 17:10:38 -07001237
1238 // Return true and exit the function.
1239 // If loop does not result in returning false, we return true.
1240 __ Bind(&return_true);
1241 __ LoadImmediate(out, 1);
1242 __ b(&end);
1243
1244 // Return false and exit the function.
1245 __ Bind(&return_false);
1246 __ LoadImmediate(out, 0);
1247 __ Bind(&end);
1248}
1249
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001250static void GenerateVisitStringIndexOf(HInvoke* invoke,
1251 ArmAssembler* assembler,
1252 CodeGeneratorARM* codegen,
1253 ArenaAllocator* allocator,
1254 bool start_at_zero) {
1255 LocationSummary* locations = invoke->GetLocations();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001256
1257 // Note that the null check must have been done earlier.
1258 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1259
1260 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001261 // or directly dispatch for a large constant, or omit slow-path for a small constant or a char.
Andreas Gampe85b62f22015-09-09 13:15:38 -07001262 SlowPathCode* slow_path = nullptr;
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001263 HInstruction* code_point = invoke->InputAt(1);
1264 if (code_point->IsIntConstant()) {
Vladimir Markoda051082016-05-17 16:10:20 +01001265 if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) >
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001266 std::numeric_limits<uint16_t>::max()) {
1267 // Always needs the slow-path. We could directly dispatch to it, but this case should be
1268 // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1269 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1270 codegen->AddSlowPath(slow_path);
1271 __ b(slow_path->GetEntryLabel());
1272 __ Bind(slow_path->GetExitLabel());
1273 return;
1274 }
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001275 } else if (code_point->GetType() != Primitive::kPrimChar) {
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001276 Register char_reg = locations->InAt(1).AsRegister<Register>();
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001277 // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`.
1278 __ cmp(char_reg,
1279 ShifterOperand(static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001280 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1281 codegen->AddSlowPath(slow_path);
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001282 __ b(slow_path->GetEntryLabel(), HS);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001283 }
1284
1285 if (start_at_zero) {
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001286 Register tmp_reg = locations->GetTemp(0).AsRegister<Register>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001287 DCHECK_EQ(tmp_reg, R2);
1288 // Start-index = 0.
1289 __ LoadImmediate(tmp_reg, 0);
1290 }
1291
1292 __ LoadFromOffset(kLoadWord, LR, TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001293 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pIndexOf).Int32Value());
Roland Levillain42ad2882016-02-29 18:26:54 +00001294 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001295 __ blx(LR);
1296
1297 if (slow_path != nullptr) {
1298 __ Bind(slow_path->GetExitLabel());
1299 }
1300}
1301
1302void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) {
1303 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001304 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001305 kIntrinsified);
1306 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1307 // best to align the inputs accordingly.
1308 InvokeRuntimeCallingConvention calling_convention;
1309 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1310 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1311 locations->SetOut(Location::RegisterLocation(R0));
1312
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001313 // Need to send start-index=0.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001314 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1315}
1316
1317void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001318 GenerateVisitStringIndexOf(
1319 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001320}
1321
1322void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1323 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001324 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001325 kIntrinsified);
1326 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1327 // best to align the inputs accordingly.
1328 InvokeRuntimeCallingConvention calling_convention;
1329 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1330 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1331 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1332 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001333}
1334
1335void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001336 GenerateVisitStringIndexOf(
1337 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001338}
1339
Jeff Hao848f70a2014-01-15 13:49:50 -08001340void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1341 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001342 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001343 kIntrinsified);
1344 InvokeRuntimeCallingConvention calling_convention;
1345 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1346 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1347 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1348 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1349 locations->SetOut(Location::RegisterLocation(R0));
1350}
1351
1352void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1353 ArmAssembler* assembler = GetAssembler();
1354 LocationSummary* locations = invoke->GetLocations();
1355
1356 Register byte_array = locations->InAt(0).AsRegister<Register>();
1357 __ cmp(byte_array, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001358 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001359 codegen_->AddSlowPath(slow_path);
1360 __ b(slow_path->GetEntryLabel(), EQ);
1361
Andreas Gampe542451c2016-07-26 09:02:02 -07001362 __ LoadFromOffset(kLoadWord,
1363 LR,
1364 TR,
1365 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromBytes).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001366 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001367 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001368 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001369 __ Bind(slow_path->GetExitLabel());
1370}
1371
1372void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1373 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001374 LocationSummary::kCallOnMainOnly,
Jeff Hao848f70a2014-01-15 13:49:50 -08001375 kIntrinsified);
1376 InvokeRuntimeCallingConvention calling_convention;
1377 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1378 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1379 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1380 locations->SetOut(Location::RegisterLocation(R0));
1381}
1382
1383void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1384 ArmAssembler* assembler = GetAssembler();
1385
Roland Levillaincc3839c2016-02-29 16:23:48 +00001386 // No need to emit code checking whether `locations->InAt(2)` is a null
1387 // pointer, as callers of the native method
1388 //
1389 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1390 //
1391 // all include a null check on `data` before calling that method.
Andreas Gampe542451c2016-07-26 09:02:02 -07001392 __ LoadFromOffset(kLoadWord,
1393 LR,
1394 TR,
1395 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromChars).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001396 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001397 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001398 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001399}
1400
1401void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) {
1402 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001403 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001404 kIntrinsified);
1405 InvokeRuntimeCallingConvention calling_convention;
1406 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1407 locations->SetOut(Location::RegisterLocation(R0));
1408}
1409
1410void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) {
1411 ArmAssembler* assembler = GetAssembler();
1412 LocationSummary* locations = invoke->GetLocations();
1413
1414 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1415 __ cmp(string_to_copy, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001416 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001417 codegen_->AddSlowPath(slow_path);
1418 __ b(slow_path->GetEntryLabel(), EQ);
1419
1420 __ LoadFromOffset(kLoadWord,
Andreas Gampe542451c2016-07-26 09:02:02 -07001421 LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromString).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001422 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001423 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001424 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001425 __ Bind(slow_path->GetExitLabel());
1426}
1427
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001428void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001429 // The only read barrier implementation supporting the
1430 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1431 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
Roland Levillain3d312422016-06-23 13:53:42 +01001432 return;
1433 }
1434
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001435 CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke);
1436 LocationSummary* locations = invoke->GetLocations();
1437 if (locations == nullptr) {
1438 return;
1439 }
1440
1441 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
1442 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
1443 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
1444
1445 if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) {
1446 locations->SetInAt(1, Location::RequiresRegister());
1447 }
1448 if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) {
1449 locations->SetInAt(3, Location::RequiresRegister());
1450 }
1451 if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) {
1452 locations->SetInAt(4, Location::RequiresRegister());
1453 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001454 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1455 // Temporary register IP cannot be used in
1456 // ReadBarrierSystemArrayCopySlowPathARM64 (because that register
1457 // is clobbered by ReadBarrierMarkRegX entry points). Get an extra
1458 // temporary register from the register allocator.
1459 locations->AddTemp(Location::RequiresRegister());
1460 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001461}
1462
1463static void CheckPosition(ArmAssembler* assembler,
1464 Location pos,
1465 Register input,
1466 Location length,
1467 SlowPathCode* slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001468 Register temp,
1469 bool length_is_input_length = false) {
1470 // Where is the length in the Array?
1471 const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value();
1472
1473 if (pos.IsConstant()) {
1474 int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue();
1475 if (pos_const == 0) {
1476 if (!length_is_input_length) {
1477 // Check that length(input) >= length.
1478 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1479 if (length.IsConstant()) {
1480 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1481 } else {
1482 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1483 }
1484 __ b(slow_path->GetEntryLabel(), LT);
1485 }
1486 } else {
1487 // Check that length(input) >= pos.
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001488 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1489 __ subs(temp, temp, ShifterOperand(pos_const));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001490 __ b(slow_path->GetEntryLabel(), LT);
1491
1492 // Check that (length(input) - pos) >= length.
1493 if (length.IsConstant()) {
1494 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1495 } else {
1496 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1497 }
1498 __ b(slow_path->GetEntryLabel(), LT);
1499 }
1500 } else if (length_is_input_length) {
1501 // The only way the copy can succeed is if pos is zero.
1502 Register pos_reg = pos.AsRegister<Register>();
1503 __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel());
1504 } else {
1505 // Check that pos >= 0.
1506 Register pos_reg = pos.AsRegister<Register>();
1507 __ cmp(pos_reg, ShifterOperand(0));
1508 __ b(slow_path->GetEntryLabel(), LT);
1509
1510 // Check that pos <= length(input).
1511 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1512 __ subs(temp, temp, ShifterOperand(pos_reg));
1513 __ b(slow_path->GetEntryLabel(), LT);
1514
1515 // Check that (length(input) - pos) >= length.
1516 if (length.IsConstant()) {
1517 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1518 } else {
1519 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1520 }
1521 __ b(slow_path->GetEntryLabel(), LT);
1522 }
1523}
1524
1525void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001526 // The only read barrier implementation supporting the
1527 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1528 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
Roland Levillain3d312422016-06-23 13:53:42 +01001529
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001530 ArmAssembler* assembler = GetAssembler();
1531 LocationSummary* locations = invoke->GetLocations();
1532
1533 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1534 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
1535 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
1536 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001537 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001538
1539 Register src = locations->InAt(0).AsRegister<Register>();
1540 Location src_pos = locations->InAt(1);
1541 Register dest = locations->InAt(2).AsRegister<Register>();
1542 Location dest_pos = locations->InAt(3);
1543 Location length = locations->InAt(4);
Roland Levillain0b671c02016-08-19 12:02:34 +01001544 Location temp1_loc = locations->GetTemp(0);
1545 Register temp1 = temp1_loc.AsRegister<Register>();
1546 Location temp2_loc = locations->GetTemp(1);
1547 Register temp2 = temp2_loc.AsRegister<Register>();
1548 Location temp3_loc = locations->GetTemp(2);
1549 Register temp3 = temp3_loc.AsRegister<Register>();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001550
Roland Levillain0b671c02016-08-19 12:02:34 +01001551 SlowPathCode* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1552 codegen_->AddSlowPath(intrinsic_slow_path);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001553
Roland Levillainebea3d22016-04-12 15:42:57 +01001554 Label conditions_on_positions_validated;
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001555 SystemArrayCopyOptimizations optimizations(invoke);
1556
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001557 // If source and destination are the same, we go to slow path if we need to do
1558 // forward copying.
1559 if (src_pos.IsConstant()) {
1560 int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1561 if (dest_pos.IsConstant()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001562 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1563 if (optimizations.GetDestinationIsSource()) {
1564 // Checked when building locations.
1565 DCHECK_GE(src_pos_constant, dest_pos_constant);
1566 } else if (src_pos_constant < dest_pos_constant) {
1567 __ cmp(src, ShifterOperand(dest));
Roland Levillain0b671c02016-08-19 12:02:34 +01001568 __ b(intrinsic_slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001569 }
1570
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001571 // Checked when building locations.
1572 DCHECK(!optimizations.GetDestinationIsSource()
1573 || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue()));
1574 } else {
1575 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001576 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001577 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001578 }
1579 __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant));
Roland Levillain0b671c02016-08-19 12:02:34 +01001580 __ b(intrinsic_slow_path->GetEntryLabel(), GT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001581 }
1582 } else {
1583 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001584 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001585 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001586 }
1587 if (dest_pos.IsConstant()) {
1588 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1589 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant));
1590 } else {
1591 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>()));
1592 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001593 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001594 }
1595
Roland Levillainebea3d22016-04-12 15:42:57 +01001596 __ Bind(&conditions_on_positions_validated);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001597
1598 if (!optimizations.GetSourceIsNotNull()) {
1599 // Bail out if the source is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001600 __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001601 }
1602
1603 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
1604 // Bail out if the destination is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001605 __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001606 }
1607
1608 // If the length is negative, bail out.
1609 // We have already checked in the LocationsBuilder for the constant case.
1610 if (!length.IsConstant() &&
1611 !optimizations.GetCountIsSourceLength() &&
1612 !optimizations.GetCountIsDestinationLength()) {
1613 __ cmp(length.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain0b671c02016-08-19 12:02:34 +01001614 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001615 }
1616
1617 // Validity checks: source.
1618 CheckPosition(assembler,
1619 src_pos,
1620 src,
1621 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001622 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001623 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001624 optimizations.GetCountIsSourceLength());
1625
1626 // Validity checks: dest.
1627 CheckPosition(assembler,
1628 dest_pos,
1629 dest,
1630 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001631 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001632 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001633 optimizations.GetCountIsDestinationLength());
1634
1635 if (!optimizations.GetDoesNotNeedTypeCheck()) {
1636 // Check whether all elements of the source array are assignable to the component
1637 // type of the destination array. We do two checks: the classes are the same,
1638 // or the destination is Object[]. If none of these checks succeed, we go to the
1639 // slow path.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001640
Roland Levillain0b671c02016-08-19 12:02:34 +01001641 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1642 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1643 // /* HeapReference<Class> */ temp1 = src->klass_
1644 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1645 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1646 // Bail out if the source is not a non primitive array.
1647 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1648 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1649 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1650 __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel());
1651 // If heap poisoning is enabled, `temp1` has been unpoisoned
1652 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1653 // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_);
1654 __ LoadFromOffset(kLoadUnsignedHalfword, temp1, temp1, primitive_offset);
1655 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1656 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001657 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001658
1659 // /* HeapReference<Class> */ temp1 = dest->klass_
1660 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1661 invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false);
1662
1663 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1664 // Bail out if the destination is not a non primitive array.
1665 //
1666 // Register `temp1` is not trashed by the read barrier emitted
1667 // by GenerateFieldLoadWithBakerReadBarrier below, as that
1668 // method produces a call to a ReadBarrierMarkRegX entry point,
1669 // which saves all potentially live registers, including
1670 // temporaries such a `temp1`.
1671 // /* HeapReference<Class> */ temp2 = temp1->component_type_
1672 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1673 invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false);
1674 __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel());
1675 // If heap poisoning is enabled, `temp2` has been unpoisoned
1676 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1677 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
1678 __ LoadFromOffset(kLoadUnsignedHalfword, temp2, temp2, primitive_offset);
1679 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1680 __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel());
1681 }
1682
1683 // For the same reason given earlier, `temp1` is not trashed by the
1684 // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below.
1685 // /* HeapReference<Class> */ temp2 = src->klass_
1686 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1687 invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false);
1688 // Note: if heap poisoning is on, we are comparing two unpoisoned references here.
1689 __ cmp(temp1, ShifterOperand(temp2));
1690
1691 if (optimizations.GetDestinationIsTypedObjectArray()) {
1692 Label do_copy;
1693 __ b(&do_copy, EQ);
1694 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1695 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1696 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1697 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1698 // We do not need to emit a read barrier for the following
1699 // heap reference load, as `temp1` is only used in a
1700 // comparison with null below, and this reference is not
1701 // kept afterwards.
1702 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1703 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1704 __ Bind(&do_copy);
1705 } else {
1706 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1707 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001708 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001709 // Non read barrier code.
1710
1711 // /* HeapReference<Class> */ temp1 = dest->klass_
1712 __ LoadFromOffset(kLoadWord, temp1, dest, class_offset);
1713 // /* HeapReference<Class> */ temp2 = src->klass_
1714 __ LoadFromOffset(kLoadWord, temp2, src, class_offset);
1715 bool did_unpoison = false;
1716 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
1717 !optimizations.GetSourceIsNonPrimitiveArray()) {
1718 // One or two of the references need to be unpoisoned. Unpoison them
1719 // both to make the identity check valid.
1720 __ MaybeUnpoisonHeapReference(temp1);
1721 __ MaybeUnpoisonHeapReference(temp2);
1722 did_unpoison = true;
1723 }
1724
1725 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1726 // Bail out if the destination is not a non primitive array.
1727 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1728 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1729 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1730 __ MaybeUnpoisonHeapReference(temp3);
1731 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1732 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1733 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1734 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1735 }
1736
1737 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1738 // Bail out if the source is not a non primitive array.
1739 // /* HeapReference<Class> */ temp3 = temp2->component_type_
1740 __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset);
1741 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1742 __ MaybeUnpoisonHeapReference(temp3);
1743 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1744 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1745 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1746 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1747 }
1748
1749 __ cmp(temp1, ShifterOperand(temp2));
1750
1751 if (optimizations.GetDestinationIsTypedObjectArray()) {
1752 Label do_copy;
1753 __ b(&do_copy, EQ);
1754 if (!did_unpoison) {
1755 __ MaybeUnpoisonHeapReference(temp1);
1756 }
1757 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1758 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
1759 __ MaybeUnpoisonHeapReference(temp1);
1760 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1761 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1762 // No need to unpoison the result, we're comparing against null.
1763 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1764 __ Bind(&do_copy);
1765 } else {
1766 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1767 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001768 }
1769 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1770 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
1771 // Bail out if the source is not a non primitive array.
Roland Levillain0b671c02016-08-19 12:02:34 +01001772 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1773 // /* HeapReference<Class> */ temp1 = src->klass_
1774 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1775 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1776 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1777 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1778 invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1779 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1780 // If heap poisoning is enabled, `temp3` has been unpoisoned
1781 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1782 } else {
1783 // /* HeapReference<Class> */ temp1 = src->klass_
1784 __ LoadFromOffset(kLoadWord, temp1, src, class_offset);
1785 __ MaybeUnpoisonHeapReference(temp1);
1786 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1787 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1788 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1789 __ MaybeUnpoisonHeapReference(temp3);
1790 }
1791 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001792 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1793 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
Roland Levillain0b671c02016-08-19 12:02:34 +01001794 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001795 }
1796
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001797 int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
Roland Levillain0b671c02016-08-19 12:02:34 +01001798 uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001799 uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001800
1801 // Compute the base source address in `temp1`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001802 if (src_pos.IsConstant()) {
1803 int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1804 __ AddConstant(temp1, src, element_size * constant + offset);
1805 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001806 __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001807 __ AddConstant(temp1, offset);
1808 }
1809
Roland Levillain0b671c02016-08-19 12:02:34 +01001810 // Compute the end source address in `temp3`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001811 if (length.IsConstant()) {
1812 int32_t constant = length.GetConstant()->AsIntConstant()->GetValue();
1813 __ AddConstant(temp3, temp1, element_size * constant);
1814 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001815 __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001816 }
1817
Roland Levillain0b671c02016-08-19 12:02:34 +01001818 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1819 // The base destination address is computed later, as `temp2` is
1820 // used for intermediate computations.
1821
1822 // SystemArrayCopy implementation for Baker read barriers (see
1823 // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier):
1824 //
1825 // if (src_ptr != end_ptr) {
1826 // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState();
1827 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
1828 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
1829 // if (is_gray) {
1830 // // Slow-path copy.
1831 // do {
1832 // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++)));
1833 // } while (src_ptr != end_ptr)
1834 // } else {
1835 // // Fast-path copy.
1836 // do {
1837 // *dest_ptr++ = *src_ptr++;
1838 // } while (src_ptr != end_ptr)
1839 // }
1840 // }
1841
1842 Label loop, done;
1843
1844 // Don't enter copy loop if `length == 0`.
1845 __ cmp(temp1, ShifterOperand(temp3));
1846 __ b(&done, EQ);
1847
1848 // /* int32_t */ monitor = src->monitor_
1849 __ LoadFromOffset(kLoadWord, temp2, src, monitor_offset);
1850 // /* LockWord */ lock_word = LockWord(monitor)
1851 static_assert(sizeof(LockWord) == sizeof(int32_t),
1852 "art::LockWord and int32_t have different sizes.");
1853
1854 // Introduce a dependency on the lock_word including the rb_state,
1855 // which shall prevent load-load reordering without using
1856 // a memory barrier (which would be more expensive).
1857 // `src` is unchanged by this operation, but its value now depends
1858 // on `temp2`.
1859 __ add(src, src, ShifterOperand(temp2, LSR, 32));
1860
1861 // Slow path used to copy array when `src` is gray.
1862 SlowPathCode* read_barrier_slow_path =
1863 new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARM(invoke);
1864 codegen_->AddSlowPath(read_barrier_slow_path);
1865
1866 // Given the numeric representation, it's enough to check the low bit of the
1867 // rb_state. We do that by shifting the bit out of the lock word with LSRS
1868 // which can be a 16-bit instruction unlike the TST immediate.
1869 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
1870 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
1871 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
1872 __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1);
1873 // Carry flag is the last bit shifted out by LSRS.
1874 __ b(read_barrier_slow_path->GetEntryLabel(), CS);
1875
1876 // Fast-path copy.
1877
1878 // Compute the base destination address in `temp2`.
1879 if (dest_pos.IsConstant()) {
1880 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1881 __ AddConstant(temp2, dest, element_size * constant + offset);
1882 } else {
1883 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1884 __ AddConstant(temp2, offset);
1885 }
1886
1887 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1888 // poison/unpoison.
1889 __ Bind(&loop);
1890 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1891 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1892 __ cmp(temp1, ShifterOperand(temp3));
1893 __ b(&loop, NE);
1894
1895 __ Bind(read_barrier_slow_path->GetExitLabel());
1896 __ Bind(&done);
1897 } else {
1898 // Non read barrier code.
1899
1900 // Compute the base destination address in `temp2`.
1901 if (dest_pos.IsConstant()) {
1902 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1903 __ AddConstant(temp2, dest, element_size * constant + offset);
1904 } else {
1905 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1906 __ AddConstant(temp2, offset);
1907 }
1908
1909 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1910 // poison/unpoison.
1911 Label loop, done;
1912 __ cmp(temp1, ShifterOperand(temp3));
1913 __ b(&done, EQ);
1914 __ Bind(&loop);
1915 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1916 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1917 __ cmp(temp1, ShifterOperand(temp3));
1918 __ b(&loop, NE);
1919 __ Bind(&done);
1920 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001921
1922 // We only need one card marking on the destination array.
1923 codegen_->MarkGCCard(temp1,
1924 temp2,
1925 dest,
1926 Register(kNoRegister),
Roland Levillainebea3d22016-04-12 15:42:57 +01001927 /* value_can_be_null */ false);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001928
Roland Levillain0b671c02016-08-19 12:02:34 +01001929 __ Bind(intrinsic_slow_path->GetExitLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001930}
1931
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001932static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1933 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1934 // the code generator. Furthermore, the register allocator creates fixed live intervals
1935 // for all caller-saved registers because we are doing a function call. As a result, if
1936 // the input and output locations are unallocated, the register allocator runs out of
1937 // registers and fails; however, a debuggable graph is not the common case.
1938 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1939 return;
1940 }
1941
1942 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1943 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1944 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1945
1946 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001947 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001948 kIntrinsified);
1949 const InvokeRuntimeCallingConvention calling_convention;
1950
1951 locations->SetInAt(0, Location::RequiresFpuRegister());
1952 locations->SetOut(Location::RequiresFpuRegister());
1953 // Native code uses the soft float ABI.
1954 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1955 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1956}
1957
1958static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1959 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1960 // the code generator. Furthermore, the register allocator creates fixed live intervals
1961 // for all caller-saved registers because we are doing a function call. As a result, if
1962 // the input and output locations are unallocated, the register allocator runs out of
1963 // registers and fails; however, a debuggable graph is not the common case.
1964 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1965 return;
1966 }
1967
1968 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1969 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1970 DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble);
1971 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1972
1973 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001974 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001975 kIntrinsified);
1976 const InvokeRuntimeCallingConvention calling_convention;
1977
1978 locations->SetInAt(0, Location::RequiresFpuRegister());
1979 locations->SetInAt(1, Location::RequiresFpuRegister());
1980 locations->SetOut(Location::RequiresFpuRegister());
1981 // Native code uses the soft float ABI.
1982 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1983 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1984 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1985 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1986}
1987
1988static void GenFPToFPCall(HInvoke* invoke,
1989 ArmAssembler* assembler,
1990 CodeGeneratorARM* codegen,
1991 QuickEntrypointEnum entry) {
1992 LocationSummary* const locations = invoke->GetLocations();
1993 const InvokeRuntimeCallingConvention calling_convention;
1994
1995 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1996 DCHECK(locations->WillCall() && locations->Intrinsified());
1997 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
1998 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
1999
Andreas Gampe542451c2016-07-26 09:02:02 -07002000 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00002001 // Native code uses the soft float ABI.
2002 __ vmovrrd(calling_convention.GetRegisterAt(0),
2003 calling_convention.GetRegisterAt(1),
2004 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2005 __ blx(LR);
2006 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
2007 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
2008 calling_convention.GetRegisterAt(0),
2009 calling_convention.GetRegisterAt(1));
2010}
2011
2012static void GenFPFPToFPCall(HInvoke* invoke,
2013 ArmAssembler* assembler,
2014 CodeGeneratorARM* codegen,
2015 QuickEntrypointEnum entry) {
2016 LocationSummary* const locations = invoke->GetLocations();
2017 const InvokeRuntimeCallingConvention calling_convention;
2018
2019 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
2020 DCHECK(locations->WillCall() && locations->Intrinsified());
2021 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
2022 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
2023 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2)));
2024 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3)));
2025
Andreas Gampe542451c2016-07-26 09:02:02 -07002026 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00002027 // Native code uses the soft float ABI.
2028 __ vmovrrd(calling_convention.GetRegisterAt(0),
2029 calling_convention.GetRegisterAt(1),
2030 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2031 __ vmovrrd(calling_convention.GetRegisterAt(2),
2032 calling_convention.GetRegisterAt(3),
2033 FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()));
2034 __ blx(LR);
2035 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
2036 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
2037 calling_convention.GetRegisterAt(0),
2038 calling_convention.GetRegisterAt(1));
2039}
2040
2041void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) {
2042 CreateFPToFPCallLocations(arena_, invoke);
2043}
2044
2045void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) {
2046 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos);
2047}
2048
2049void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) {
2050 CreateFPToFPCallLocations(arena_, invoke);
2051}
2052
2053void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) {
2054 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin);
2055}
2056
2057void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) {
2058 CreateFPToFPCallLocations(arena_, invoke);
2059}
2060
2061void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) {
2062 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos);
2063}
2064
2065void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) {
2066 CreateFPToFPCallLocations(arena_, invoke);
2067}
2068
2069void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) {
2070 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin);
2071}
2072
2073void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) {
2074 CreateFPToFPCallLocations(arena_, invoke);
2075}
2076
2077void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) {
2078 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan);
2079}
2080
2081void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) {
2082 CreateFPToFPCallLocations(arena_, invoke);
2083}
2084
2085void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) {
2086 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt);
2087}
2088
2089void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) {
2090 CreateFPToFPCallLocations(arena_, invoke);
2091}
2092
2093void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) {
2094 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh);
2095}
2096
2097void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) {
2098 CreateFPToFPCallLocations(arena_, invoke);
2099}
2100
2101void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) {
2102 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp);
2103}
2104
2105void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) {
2106 CreateFPToFPCallLocations(arena_, invoke);
2107}
2108
2109void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) {
2110 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1);
2111}
2112
2113void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) {
2114 CreateFPToFPCallLocations(arena_, invoke);
2115}
2116
2117void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) {
2118 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog);
2119}
2120
2121void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) {
2122 CreateFPToFPCallLocations(arena_, invoke);
2123}
2124
2125void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) {
2126 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10);
2127}
2128
2129void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) {
2130 CreateFPToFPCallLocations(arena_, invoke);
2131}
2132
2133void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) {
2134 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh);
2135}
2136
2137void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) {
2138 CreateFPToFPCallLocations(arena_, invoke);
2139}
2140
2141void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) {
2142 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan);
2143}
2144
2145void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) {
2146 CreateFPToFPCallLocations(arena_, invoke);
2147}
2148
2149void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) {
2150 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh);
2151}
2152
2153void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) {
2154 CreateFPFPToFPCallLocations(arena_, invoke);
2155}
2156
2157void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) {
2158 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2);
2159}
2160
2161void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) {
2162 CreateFPFPToFPCallLocations(arena_, invoke);
2163}
2164
2165void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) {
2166 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot);
2167}
2168
2169void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) {
2170 CreateFPFPToFPCallLocations(arena_, invoke);
2171}
2172
2173void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) {
2174 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter);
2175}
2176
Artem Serovc257da72016-02-02 13:49:43 +00002177void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) {
2178 CreateIntToIntLocations(arena_, invoke);
2179}
2180
2181void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) {
2182 ArmAssembler* assembler = GetAssembler();
2183 LocationSummary* locations = invoke->GetLocations();
2184
2185 Register out = locations->Out().AsRegister<Register>();
2186 Register in = locations->InAt(0).AsRegister<Register>();
2187
2188 __ rbit(out, in);
2189}
2190
2191void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) {
2192 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2193 LocationSummary::kNoCall,
2194 kIntrinsified);
2195 locations->SetInAt(0, Location::RequiresRegister());
2196 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2197}
2198
2199void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) {
2200 ArmAssembler* assembler = GetAssembler();
2201 LocationSummary* locations = invoke->GetLocations();
2202
2203 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2204 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2205 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2206 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2207
2208 __ rbit(out_reg_lo, in_reg_hi);
2209 __ rbit(out_reg_hi, in_reg_lo);
2210}
2211
2212void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2213 CreateIntToIntLocations(arena_, invoke);
2214}
2215
2216void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2217 ArmAssembler* assembler = GetAssembler();
2218 LocationSummary* locations = invoke->GetLocations();
2219
2220 Register out = locations->Out().AsRegister<Register>();
2221 Register in = locations->InAt(0).AsRegister<Register>();
2222
2223 __ rev(out, in);
2224}
2225
2226void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) {
2227 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2228 LocationSummary::kNoCall,
2229 kIntrinsified);
2230 locations->SetInAt(0, Location::RequiresRegister());
2231 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2232}
2233
2234void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) {
2235 ArmAssembler* assembler = GetAssembler();
2236 LocationSummary* locations = invoke->GetLocations();
2237
2238 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2239 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2240 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2241 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2242
2243 __ rev(out_reg_lo, in_reg_hi);
2244 __ rev(out_reg_hi, in_reg_lo);
2245}
2246
2247void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) {
2248 CreateIntToIntLocations(arena_, invoke);
2249}
2250
2251void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) {
2252 ArmAssembler* assembler = GetAssembler();
2253 LocationSummary* locations = invoke->GetLocations();
2254
2255 Register out = locations->Out().AsRegister<Register>();
2256 Register in = locations->InAt(0).AsRegister<Register>();
2257
2258 __ revsh(out, in);
2259}
2260
xueliang.zhongf1073c82016-07-05 15:28:19 +01002261static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmAssembler* assembler) {
2262 DCHECK(Primitive::IsIntOrLongType(type)) << type;
2263 DCHECK_EQ(instr->GetType(), Primitive::kPrimInt);
2264 DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type);
2265
2266 bool is_long = type == Primitive::kPrimLong;
2267 LocationSummary* locations = instr->GetLocations();
2268 Location in = locations->InAt(0);
2269 Register src_0 = is_long ? in.AsRegisterPairLow<Register>() : in.AsRegister<Register>();
2270 Register src_1 = is_long ? in.AsRegisterPairHigh<Register>() : src_0;
2271 SRegister tmp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2272 DRegister tmp_d = FromLowSToD(tmp_s);
2273 Register out_r = locations->Out().AsRegister<Register>();
2274
2275 // Move data from core register(s) to temp D-reg for bit count calculation, then move back.
2276 // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg,
2277 // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency,
2278 // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'.
2279 __ vmovdrr(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0|
2280 __ vcntd(tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c|
2281 __ vpaddld(tmp_d, tmp_d, 8, /* is_unsigned */ true); // Temp DReg |--c|--c|--c|--c|
2282 __ vpaddld(tmp_d, tmp_d, 16, /* is_unsigned */ true); // Temp DReg |------c|------c|
2283 if (is_long) {
2284 __ vpaddld(tmp_d, tmp_d, 32, /* is_unsigned */ true); // Temp DReg |--------------c|
2285 }
2286 __ vmovrs(out_r, tmp_s);
2287}
2288
2289void IntrinsicLocationsBuilderARM::VisitIntegerBitCount(HInvoke* invoke) {
2290 CreateIntToIntLocations(arena_, invoke);
2291 invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister());
2292}
2293
2294void IntrinsicCodeGeneratorARM::VisitIntegerBitCount(HInvoke* invoke) {
2295 GenBitCount(invoke, Primitive::kPrimInt, GetAssembler());
2296}
2297
2298void IntrinsicLocationsBuilderARM::VisitLongBitCount(HInvoke* invoke) {
2299 VisitIntegerBitCount(invoke);
2300}
2301
2302void IntrinsicCodeGeneratorARM::VisitLongBitCount(HInvoke* invoke) {
2303 GenBitCount(invoke, Primitive::kPrimLong, GetAssembler());
2304}
2305
Tim Zhang25abd6c2016-01-19 23:39:24 +08002306void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2307 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2308 LocationSummary::kNoCall,
2309 kIntrinsified);
2310 locations->SetInAt(0, Location::RequiresRegister());
2311 locations->SetInAt(1, Location::RequiresRegister());
2312 locations->SetInAt(2, Location::RequiresRegister());
2313 locations->SetInAt(3, Location::RequiresRegister());
2314 locations->SetInAt(4, Location::RequiresRegister());
2315
Scott Wakeling3fdab772016-04-25 11:32:37 +01002316 // Temporary registers to store lengths of strings and for calculations.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002317 locations->AddTemp(Location::RequiresRegister());
2318 locations->AddTemp(Location::RequiresRegister());
2319 locations->AddTemp(Location::RequiresRegister());
2320}
2321
2322void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2323 ArmAssembler* assembler = GetAssembler();
2324 LocationSummary* locations = invoke->GetLocations();
2325
2326 // Check assumption that sizeof(Char) is 2 (used in scaling below).
2327 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
2328 DCHECK_EQ(char_size, 2u);
2329
2330 // Location of data in char array buffer.
2331 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
2332
2333 // Location of char array data in string.
2334 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
2335
2336 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
2337 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
2338 Register srcObj = locations->InAt(0).AsRegister<Register>();
2339 Register srcBegin = locations->InAt(1).AsRegister<Register>();
2340 Register srcEnd = locations->InAt(2).AsRegister<Register>();
2341 Register dstObj = locations->InAt(3).AsRegister<Register>();
2342 Register dstBegin = locations->InAt(4).AsRegister<Register>();
2343
Scott Wakeling3fdab772016-04-25 11:32:37 +01002344 Register num_chr = locations->GetTemp(0).AsRegister<Register>();
2345 Register src_ptr = locations->GetTemp(1).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002346 Register dst_ptr = locations->GetTemp(2).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002347
2348 // src range to copy.
2349 __ add(src_ptr, srcObj, ShifterOperand(value_offset));
Tim Zhang25abd6c2016-01-19 23:39:24 +08002350 __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1));
2351
2352 // dst to be copied.
2353 __ add(dst_ptr, dstObj, ShifterOperand(data_offset));
2354 __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1));
2355
Scott Wakeling3fdab772016-04-25 11:32:37 +01002356 __ subs(num_chr, srcEnd, ShifterOperand(srcBegin));
2357
Tim Zhang25abd6c2016-01-19 23:39:24 +08002358 // Do the copy.
Scott Wakeling3fdab772016-04-25 11:32:37 +01002359 Label loop, remainder, done;
2360
2361 // Early out for valid zero-length retrievals.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002362 __ b(&done, EQ);
Scott Wakeling3fdab772016-04-25 11:32:37 +01002363
2364 // Save repairing the value of num_chr on the < 4 character path.
2365 __ subs(IP, num_chr, ShifterOperand(4));
2366 __ b(&remainder, LT);
2367
2368 // Keep the result of the earlier subs, we are going to fetch at least 4 characters.
2369 __ mov(num_chr, ShifterOperand(IP));
2370
2371 // Main loop used for longer fetches loads and stores 4x16-bit characters at a time.
2372 // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code
2373 // to rectify these everywhere this intrinsic applies.)
2374 __ Bind(&loop);
2375 __ ldr(IP, Address(src_ptr, char_size * 2));
2376 __ subs(num_chr, num_chr, ShifterOperand(4));
2377 __ str(IP, Address(dst_ptr, char_size * 2));
2378 __ ldr(IP, Address(src_ptr, char_size * 4, Address::PostIndex));
2379 __ str(IP, Address(dst_ptr, char_size * 4, Address::PostIndex));
2380 __ b(&loop, GE);
2381
2382 __ adds(num_chr, num_chr, ShifterOperand(4));
2383 __ b(&done, EQ);
2384
2385 // Main loop for < 4 character case and remainder handling. Loads and stores one
2386 // 16-bit Java character at a time.
2387 __ Bind(&remainder);
2388 __ ldrh(IP, Address(src_ptr, char_size, Address::PostIndex));
2389 __ subs(num_chr, num_chr, ShifterOperand(1));
2390 __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex));
2391 __ b(&remainder, GT);
2392
Tim Zhang25abd6c2016-01-19 23:39:24 +08002393 __ Bind(&done);
2394}
2395
Anton Kirilova3ffea22016-04-07 17:02:37 +01002396void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) {
2397 CreateFPToIntLocations(arena_, invoke);
2398}
2399
2400void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) {
2401 ArmAssembler* const assembler = GetAssembler();
2402 LocationSummary* const locations = invoke->GetLocations();
2403 const Register out = locations->Out().AsRegister<Register>();
2404 // Shifting left by 1 bit makes the value encodable as an immediate operand;
2405 // we don't care about the sign bit anyway.
2406 constexpr uint32_t infinity = kPositiveInfinityFloat << 1U;
2407
2408 __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>());
2409 // We don't care about the sign bit, so shift left.
2410 __ Lsl(out, out, 1);
2411 __ eor(out, out, ShifterOperand(infinity));
2412 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2413 __ clz(out, out);
2414 // Any number less than 32 logically shifted right by 5 bits results in 0;
2415 // the same operation on 32 yields 1.
2416 __ Lsr(out, out, 5);
2417}
2418
2419void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2420 CreateFPToIntLocations(arena_, invoke);
2421}
2422
2423void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2424 ArmAssembler* const assembler = GetAssembler();
2425 LocationSummary* const locations = invoke->GetLocations();
2426 const Register out = locations->Out().AsRegister<Register>();
2427 // The highest 32 bits of double precision positive infinity separated into
2428 // two constants encodable as immediate operands.
2429 constexpr uint32_t infinity_high = 0x7f000000U;
2430 constexpr uint32_t infinity_high2 = 0x00f00000U;
2431
2432 static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U),
2433 "The constants do not add up to the high 32 bits of double precision positive infinity.");
2434 __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2435 __ eor(out, out, ShifterOperand(infinity_high));
2436 __ eor(out, out, ShifterOperand(infinity_high2));
2437 // We don't care about the sign bit, so shift left.
2438 __ orr(out, IP, ShifterOperand(out, LSL, 1));
2439 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2440 __ clz(out, out);
2441 // Any number less than 32 logically shifted right by 5 bits results in 0;
2442 // the same operation on 32 yields 1.
2443 __ Lsr(out, out, 5);
2444}
2445
Aart Bik2f9fcc92016-03-01 15:16:54 -08002446UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble)
2447UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat)
2448UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble)
2449UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat)
2450UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong)
2451UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong)
2452UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe?
2453UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe?
2454UNIMPLEMENTED_INTRINSIC(ARM, MathRint)
2455UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe?
2456UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe?
2457UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure.
2458UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar)
2459UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002460UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit)
2461UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit)
2462UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit)
2463UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit)
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002464
Aart Bik0e54c012016-03-04 12:08:31 -08002465// 1.8.
2466UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt)
2467UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong)
2468UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt)
2469UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong)
2470UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject)
Aart Bik0e54c012016-03-04 12:08:31 -08002471
Aart Bik2f9fcc92016-03-01 15:16:54 -08002472UNREACHABLE_INTRINSICS(ARM)
Roland Levillain4d027112015-07-01 15:41:14 +01002473
2474#undef __
2475
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002476} // namespace arm
2477} // namespace art