blob: e1a6454b5ad698a816e0618c51461ae3c8e05710 [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);
654 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
655 locations->SetInAt(1, Location::RequiresRegister());
656 locations->SetInAt(2, Location::RequiresRegister());
Roland Levillainbfea3352016-06-23 13:48:47 +0100657 locations->SetOut(Location::RequiresRegister(),
658 can_call ? Location::kOutputOverlap : Location::kNoOutputOverlap);
Roland Levillainc9285912015-12-18 10:38:42 +0000659 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
660 // We need a temporary register for the read barrier marking slow
Roland Levillainbfea3352016-06-23 13:48:47 +0100661 // path in InstructionCodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier.
Roland Levillainc9285912015-12-18 10:38:42 +0000662 locations->AddTemp(Location::RequiresRegister());
663 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800664}
665
666void IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000667 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800668}
669void IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(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::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000673 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800674}
675void IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(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::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000679 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800680}
681void IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000682 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800683}
684
685void IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000686 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800687}
688void IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000689 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800690}
691void IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000692 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800693}
694void IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000695 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800696}
697void IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000698 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800699}
700void IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000701 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800702}
703
704static void CreateIntIntIntIntToVoid(ArenaAllocator* arena,
705 const ArmInstructionSetFeatures& features,
706 Primitive::Type type,
707 bool is_volatile,
708 HInvoke* invoke) {
709 LocationSummary* locations = new (arena) LocationSummary(invoke,
710 LocationSummary::kNoCall,
711 kIntrinsified);
712 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
713 locations->SetInAt(1, Location::RequiresRegister());
714 locations->SetInAt(2, Location::RequiresRegister());
715 locations->SetInAt(3, Location::RequiresRegister());
716
717 if (type == Primitive::kPrimLong) {
718 // Potentially need temps for ldrexd-strexd loop.
719 if (is_volatile && !features.HasAtomicLdrdAndStrd()) {
720 locations->AddTemp(Location::RequiresRegister()); // Temp_lo.
721 locations->AddTemp(Location::RequiresRegister()); // Temp_hi.
722 }
723 } else if (type == Primitive::kPrimNot) {
724 // Temps for card-marking.
725 locations->AddTemp(Location::RequiresRegister()); // Temp.
726 locations->AddTemp(Location::RequiresRegister()); // Card.
727 }
728}
729
730void IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000731 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800732}
733void IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(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::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000737 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800738}
739void IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000740 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800741}
742void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(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::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000746 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800747}
748void IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000749 CreateIntIntIntIntToVoid(
750 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800751}
752void IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000753 CreateIntIntIntIntToVoid(
754 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800755}
756void IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000757 CreateIntIntIntIntToVoid(
758 arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800759}
760
761static void GenUnsafePut(LocationSummary* locations,
762 Primitive::Type type,
763 bool is_volatile,
764 bool is_ordered,
765 CodeGeneratorARM* codegen) {
766 ArmAssembler* assembler = codegen->GetAssembler();
767
768 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
769 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Long offset, lo part only.
770 Register value;
771
772 if (is_volatile || is_ordered) {
773 __ dmb(ISH);
774 }
775
776 if (type == Primitive::kPrimLong) {
777 Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>();
778 value = value_lo;
779 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
780 Register temp_lo = locations->GetTemp(0).AsRegister<Register>();
781 Register temp_hi = locations->GetTemp(1).AsRegister<Register>();
782 Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>();
783
784 __ add(IP, base, ShifterOperand(offset));
785 Label loop_head;
786 __ Bind(&loop_head);
787 __ ldrexd(temp_lo, temp_hi, IP);
788 __ strexd(temp_lo, value_lo, value_hi, IP);
789 __ cmp(temp_lo, ShifterOperand(0));
790 __ b(&loop_head, NE);
791 } else {
792 __ add(IP, base, ShifterOperand(offset));
793 __ strd(value_lo, Address(IP));
794 }
795 } else {
Roland Levillain4d027112015-07-01 15:41:14 +0100796 value = locations->InAt(3).AsRegister<Register>();
797 Register source = value;
798 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
799 Register temp = locations->GetTemp(0).AsRegister<Register>();
800 __ Mov(temp, value);
801 __ PoisonHeapReference(temp);
802 source = temp;
803 }
804 __ str(source, Address(base, offset));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800805 }
806
807 if (is_volatile) {
808 __ dmb(ISH);
809 }
810
811 if (type == Primitive::kPrimNot) {
812 Register temp = locations->GetTemp(0).AsRegister<Register>();
813 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100814 bool value_can_be_null = true; // TODO: Worth finding out this information?
815 codegen->MarkGCCard(temp, card, base, value, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800816 }
817}
818
819void IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000820 GenUnsafePut(invoke->GetLocations(),
821 Primitive::kPrimInt,
822 /* is_volatile */ false,
823 /* is_ordered */ false,
824 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800825}
826void IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000827 GenUnsafePut(invoke->GetLocations(),
828 Primitive::kPrimInt,
829 /* is_volatile */ false,
830 /* is_ordered */ true,
831 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800832}
833void IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000834 GenUnsafePut(invoke->GetLocations(),
835 Primitive::kPrimInt,
836 /* is_volatile */ true,
837 /* is_ordered */ false,
838 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800839}
840void IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000841 GenUnsafePut(invoke->GetLocations(),
842 Primitive::kPrimNot,
843 /* is_volatile */ false,
844 /* is_ordered */ false,
845 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800846}
847void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000848 GenUnsafePut(invoke->GetLocations(),
849 Primitive::kPrimNot,
850 /* is_volatile */ false,
851 /* is_ordered */ true,
852 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800853}
854void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000855 GenUnsafePut(invoke->GetLocations(),
856 Primitive::kPrimNot,
857 /* is_volatile */ true,
858 /* is_ordered */ false,
859 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800860}
861void IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000862 GenUnsafePut(invoke->GetLocations(),
863 Primitive::kPrimLong,
864 /* is_volatile */ false,
865 /* is_ordered */ false,
866 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800867}
868void IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000869 GenUnsafePut(invoke->GetLocations(),
870 Primitive::kPrimLong,
871 /* is_volatile */ false,
872 /* is_ordered */ true,
873 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800874}
875void IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000876 GenUnsafePut(invoke->GetLocations(),
877 Primitive::kPrimLong,
878 /* is_volatile */ true,
879 /* is_ordered */ false,
880 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800881}
882
883static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena,
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000884 HInvoke* invoke,
885 Primitive::Type type) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800886 LocationSummary* locations = new (arena) LocationSummary(invoke,
887 LocationSummary::kNoCall,
888 kIntrinsified);
889 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
890 locations->SetInAt(1, Location::RequiresRegister());
891 locations->SetInAt(2, Location::RequiresRegister());
892 locations->SetInAt(3, Location::RequiresRegister());
893 locations->SetInAt(4, Location::RequiresRegister());
894
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000895 // If heap poisoning is enabled, we don't want the unpoisoning
896 // operations to potentially clobber the output.
897 Location::OutputOverlap overlaps = (kPoisonHeapReferences && type == Primitive::kPrimNot)
898 ? Location::kOutputOverlap
899 : Location::kNoOutputOverlap;
900 locations->SetOut(Location::RequiresRegister(), overlaps);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800901
902 locations->AddTemp(Location::RequiresRegister()); // Pointer.
903 locations->AddTemp(Location::RequiresRegister()); // Temp 1.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800904}
905
906static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM* codegen) {
907 DCHECK_NE(type, Primitive::kPrimLong);
908
909 ArmAssembler* assembler = codegen->GetAssembler();
910
911 Register out = locations->Out().AsRegister<Register>(); // Boolean result.
912
913 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
914 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Offset (discard high 4B).
915 Register expected_lo = locations->InAt(3).AsRegister<Register>(); // Expected.
916 Register value_lo = locations->InAt(4).AsRegister<Register>(); // Value.
917
918 Register tmp_ptr = locations->GetTemp(0).AsRegister<Register>(); // Pointer to actual memory.
919 Register tmp_lo = locations->GetTemp(1).AsRegister<Register>(); // Value in memory.
920
921 if (type == Primitive::kPrimNot) {
922 // Mark card for object assuming new value is stored. Worst case we will mark an unchanged
923 // object and scan the receiver at the next GC for nothing.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100924 bool value_can_be_null = true; // TODO: Worth finding out this information?
925 codegen->MarkGCCard(tmp_ptr, tmp_lo, base, value_lo, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800926 }
927
928 // Prevent reordering with prior memory operations.
Roland Levillain4bedb382016-01-12 12:01:04 +0000929 // Emit a DMB ISH instruction instead of an DMB ISHST one, as the
930 // latter allows a preceding load to be delayed past the STXR
931 // instruction below.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800932 __ dmb(ISH);
933
934 __ add(tmp_ptr, base, ShifterOperand(offset));
935
Roland Levillain4d027112015-07-01 15:41:14 +0100936 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
937 codegen->GetAssembler()->PoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000938 if (value_lo == expected_lo) {
939 // Do not poison `value_lo`, as it is the same register as
940 // `expected_lo`, which has just been poisoned.
941 } else {
942 codegen->GetAssembler()->PoisonHeapReference(value_lo);
943 }
Roland Levillain4d027112015-07-01 15:41:14 +0100944 }
945
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800946 // do {
947 // tmp = [r_ptr] - expected;
948 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
949 // result = tmp != 0;
950
951 Label loop_head;
952 __ Bind(&loop_head);
953
Roland Levillain391b8662015-12-18 11:43:38 +0000954 // TODO: When `type == Primitive::kPrimNot`, add a read barrier for
955 // the reference stored in the object before attempting the CAS,
956 // similar to the one in the art::Unsafe_compareAndSwapObject JNI
957 // implementation.
958 //
959 // Note that this code is not (yet) used when read barriers are
960 // enabled (see IntrinsicLocationsBuilderARM::VisitUnsafeCASObject).
961 DCHECK(!(type == Primitive::kPrimNot && kEmitCompilerReadBarrier));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800962 __ ldrex(tmp_lo, tmp_ptr);
963
964 __ subs(tmp_lo, tmp_lo, ShifterOperand(expected_lo));
965
966 __ it(EQ, ItState::kItT);
967 __ strex(tmp_lo, value_lo, tmp_ptr, EQ);
968 __ cmp(tmp_lo, ShifterOperand(1), EQ);
969
970 __ b(&loop_head, EQ);
971
972 __ dmb(ISH);
973
974 __ rsbs(out, tmp_lo, ShifterOperand(1));
975 __ it(CC);
976 __ mov(out, ShifterOperand(0), CC);
Roland Levillain4d027112015-07-01 15:41:14 +0100977
978 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
Roland Levillain4d027112015-07-01 15:41:14 +0100979 codegen->GetAssembler()->UnpoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000980 if (value_lo == expected_lo) {
981 // Do not unpoison `value_lo`, as it is the same register as
982 // `expected_lo`, which has just been unpoisoned.
983 } else {
984 codegen->GetAssembler()->UnpoisonHeapReference(value_lo);
985 }
Roland Levillain4d027112015-07-01 15:41:14 +0100986 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800987}
988
Andreas Gampeca714582015-04-03 19:41:34 -0700989void IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) {
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000990 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800991}
Andreas Gampeca714582015-04-03 19:41:34 -0700992void IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillain391b8662015-12-18 11:43:38 +0000993 // The UnsafeCASObject intrinsic is missing a read barrier, and
994 // therefore sometimes does not work as expected (b/25883050).
995 // Turn it off temporarily as a quick fix, until the read barrier is
Roland Levillain3d312422016-06-23 13:53:42 +0100996 // implemented (see TODO in GenCAS).
Roland Levillain391b8662015-12-18 11:43:38 +0000997 //
Roland Levillain3d312422016-06-23 13:53:42 +0100998 // TODO(rpl): Implement read barrier support in GenCAS and re-enable
999 // this intrinsic.
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001000 if (kEmitCompilerReadBarrier) {
Roland Levillain985ff702015-10-23 13:25:35 +01001001 return;
1002 }
1003
Roland Levillain2e50ecb2016-01-27 14:08:33 +00001004 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001005}
1006void IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) {
1007 GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
1008}
1009void IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillain3d312422016-06-23 13:53:42 +01001010 // The UnsafeCASObject intrinsic is missing a read barrier, and
1011 // therefore sometimes does not work as expected (b/25883050).
1012 // Turn it off temporarily as a quick fix, until the read barrier is
1013 // implemented (see TODO in GenCAS).
1014 //
1015 // TODO(rpl): Implement read barrier support in GenCAS and re-enable
1016 // this intrinsic.
1017 DCHECK(!kEmitCompilerReadBarrier);
1018
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08001019 GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
1020}
1021
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001022void IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) {
1023 // The inputs plus one temp.
1024 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001025 invoke->InputAt(1)->CanBeNull()
1026 ? LocationSummary::kCallOnSlowPath
1027 : LocationSummary::kNoCall,
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001028 kIntrinsified);
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001029 locations->SetInAt(0, Location::RequiresRegister());
1030 locations->SetInAt(1, Location::RequiresRegister());
1031 locations->AddTemp(Location::RequiresRegister());
1032 locations->AddTemp(Location::RequiresRegister());
1033 locations->AddTemp(Location::RequiresRegister());
1034 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001035}
1036
1037void IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) {
1038 ArmAssembler* assembler = GetAssembler();
1039 LocationSummary* locations = invoke->GetLocations();
1040
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001041 Register str = locations->InAt(0).AsRegister<Register>();
1042 Register arg = locations->InAt(1).AsRegister<Register>();
1043 Register out = locations->Out().AsRegister<Register>();
1044
1045 Register temp0 = locations->GetTemp(0).AsRegister<Register>();
1046 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1047 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1048
1049 Label loop;
1050 Label find_char_diff;
1051 Label end;
1052
1053 // Get offsets of count and value fields within a string object.
1054 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1055 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1056
Nicolas Geoffray512e04d2015-03-27 17:21:24 +00001057 // Note that the null check must have been done earlier.
Calin Juravle641547a2015-04-21 22:08:51 +01001058 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001059
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001060 // Take slow path and throw if input can be and is null.
1061 SlowPathCode* slow_path = nullptr;
1062 const bool can_slow_path = invoke->InputAt(1)->CanBeNull();
1063 if (can_slow_path) {
1064 slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1065 codegen_->AddSlowPath(slow_path);
1066 __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel());
1067 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001068
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001069 // Reference equality check, return 0 if same reference.
1070 __ subs(out, str, ShifterOperand(arg));
1071 __ b(&end, EQ);
1072 // Load lengths of this and argument strings.
1073 __ ldr(temp2, Address(str, count_offset));
1074 __ ldr(temp1, Address(arg, count_offset));
1075 // out = length diff.
1076 __ subs(out, temp2, ShifterOperand(temp1));
1077 // temp0 = min(len(str), len(arg)).
1078 __ it(Condition::LT, kItElse);
1079 __ mov(temp0, ShifterOperand(temp2), Condition::LT);
1080 __ mov(temp0, ShifterOperand(temp1), Condition::GE);
1081 // Shorter string is empty?
1082 __ CompareAndBranchIfZero(temp0, &end);
1083
1084 // Store offset of string value in preparation for comparison loop.
1085 __ mov(temp1, ShifterOperand(value_offset));
1086
1087 // Assertions that must hold in order to compare multiple characters at a time.
1088 CHECK_ALIGNED(value_offset, 8);
1089 static_assert(IsAligned<8>(kObjectAlignment),
1090 "String data must be 8-byte aligned for unrolled CompareTo loop.");
1091
1092 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
1093 DCHECK_EQ(char_size, 2u);
1094
1095 // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment).
1096 __ Bind(&loop);
1097 __ ldr(IP, Address(str, temp1));
1098 __ ldr(temp2, Address(arg, temp1));
1099 __ cmp(IP, ShifterOperand(temp2));
1100 __ b(&find_char_diff, NE);
1101 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1102 __ sub(temp0, temp0, ShifterOperand(2));
1103
1104 __ ldr(IP, Address(str, temp1));
1105 __ ldr(temp2, Address(arg, temp1));
1106 __ cmp(IP, ShifterOperand(temp2));
1107 __ b(&find_char_diff, NE);
1108 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1109 __ subs(temp0, temp0, ShifterOperand(2));
1110
1111 __ b(&loop, GT);
1112 __ b(&end);
1113
1114 // Find the single 16-bit character difference.
1115 __ Bind(&find_char_diff);
1116 // Get the bit position of the first character that differs.
1117 __ eor(temp1, temp2, ShifterOperand(IP));
1118 __ rbit(temp1, temp1);
1119 __ clz(temp1, temp1);
1120
1121 // temp0 = number of 16-bit characters remaining to compare.
1122 // (it could be < 1 if a difference is found after the first SUB in the comparison loop, and
1123 // after the end of the shorter string data).
1124
1125 // (temp1 >> 4) = character where difference occurs between the last two words compared, on the
1126 // interval [0,1] (0 for low half-word different, 1 for high half-word different).
1127
1128 // If temp0 <= (temp1 >> 4), the difference occurs outside the remaining string data, so just
1129 // return length diff (out).
1130 __ cmp(temp0, ShifterOperand(temp1, LSR, 4));
1131 __ b(&end, LE);
1132 // Extract the characters and calculate the difference.
1133 __ bic(temp1, temp1, ShifterOperand(0xf));
1134 __ Lsr(temp2, temp2, temp1);
1135 __ Lsr(IP, IP, temp1);
1136 __ movt(temp2, 0);
1137 __ movt(IP, 0);
1138 __ sub(out, IP, ShifterOperand(temp2));
1139
1140 __ Bind(&end);
1141
1142 if (can_slow_path) {
1143 __ Bind(slow_path->GetExitLabel());
1144 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001145}
1146
Agi Csaki289cd552015-08-18 17:10:38 -07001147void IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) {
1148 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1149 LocationSummary::kNoCall,
1150 kIntrinsified);
1151 InvokeRuntimeCallingConvention calling_convention;
1152 locations->SetInAt(0, Location::RequiresRegister());
1153 locations->SetInAt(1, Location::RequiresRegister());
1154 // Temporary registers to store lengths of strings and for calculations.
1155 // Using instruction cbz requires a low register, so explicitly set a temp to be R0.
1156 locations->AddTemp(Location::RegisterLocation(R0));
1157 locations->AddTemp(Location::RequiresRegister());
1158 locations->AddTemp(Location::RequiresRegister());
1159
1160 locations->SetOut(Location::RequiresRegister());
1161}
1162
1163void IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) {
1164 ArmAssembler* assembler = GetAssembler();
1165 LocationSummary* locations = invoke->GetLocations();
1166
1167 Register str = locations->InAt(0).AsRegister<Register>();
1168 Register arg = locations->InAt(1).AsRegister<Register>();
1169 Register out = locations->Out().AsRegister<Register>();
1170
1171 Register temp = locations->GetTemp(0).AsRegister<Register>();
1172 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1173 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1174
1175 Label loop;
1176 Label end;
1177 Label return_true;
1178 Label return_false;
1179
1180 // Get offsets of count, value, and class fields within a string object.
1181 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1182 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1183 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1184
1185 // Note that the null check must have been done earlier.
1186 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1187
Vladimir Marko53b52002016-05-24 19:30:45 +01001188 StringEqualsOptimizations optimizations(invoke);
1189 if (!optimizations.GetArgumentNotNull()) {
1190 // Check if input is null, return false if it is.
1191 __ CompareAndBranchIfZero(arg, &return_false);
1192 }
Agi Csaki289cd552015-08-18 17:10:38 -07001193
Vladimir Marko53b52002016-05-24 19:30:45 +01001194 if (!optimizations.GetArgumentIsString()) {
1195 // Instanceof check for the argument by comparing class fields.
1196 // All string objects must have the same type since String cannot be subclassed.
1197 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1198 // If the argument is a string object, its class field must be equal to receiver's class field.
1199 __ ldr(temp, Address(str, class_offset));
1200 __ ldr(temp1, Address(arg, class_offset));
1201 __ cmp(temp, ShifterOperand(temp1));
1202 __ b(&return_false, NE);
1203 }
Agi Csaki289cd552015-08-18 17:10:38 -07001204
1205 // Load lengths of this and argument strings.
1206 __ ldr(temp, Address(str, count_offset));
1207 __ ldr(temp1, Address(arg, count_offset));
1208 // Check if lengths are equal, return false if they're not.
1209 __ cmp(temp, ShifterOperand(temp1));
1210 __ b(&return_false, NE);
1211 // Return true if both strings are empty.
1212 __ cbz(temp, &return_true);
1213
1214 // Reference equality check, return true if same reference.
1215 __ cmp(str, ShifterOperand(arg));
1216 __ b(&return_true, EQ);
1217
1218 // Assertions that must hold in order to compare strings 2 characters at a time.
1219 DCHECK_ALIGNED(value_offset, 4);
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001220 static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare.");
Agi Csaki289cd552015-08-18 17:10:38 -07001221
Agi Csaki289cd552015-08-18 17:10:38 -07001222 __ LoadImmediate(temp1, value_offset);
Agi Csaki289cd552015-08-18 17:10:38 -07001223
1224 // Loop to compare strings 2 characters at a time starting at the front of the string.
1225 // Ok to do this because strings with an odd length are zero-padded.
1226 __ Bind(&loop);
1227 __ ldr(out, Address(str, temp1));
1228 __ ldr(temp2, Address(arg, temp1));
1229 __ cmp(out, ShifterOperand(temp2));
1230 __ b(&return_false, NE);
1231 __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t)));
Vladimir Markoa63f0d42015-09-01 13:36:35 +01001232 __ subs(temp, temp, ShifterOperand(sizeof(uint32_t) / sizeof(uint16_t)));
1233 __ b(&loop, GT);
Agi Csaki289cd552015-08-18 17:10:38 -07001234
1235 // Return true and exit the function.
1236 // If loop does not result in returning false, we return true.
1237 __ Bind(&return_true);
1238 __ LoadImmediate(out, 1);
1239 __ b(&end);
1240
1241 // Return false and exit the function.
1242 __ Bind(&return_false);
1243 __ LoadImmediate(out, 0);
1244 __ Bind(&end);
1245}
1246
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001247static void GenerateVisitStringIndexOf(HInvoke* invoke,
1248 ArmAssembler* assembler,
1249 CodeGeneratorARM* codegen,
1250 ArenaAllocator* allocator,
1251 bool start_at_zero) {
1252 LocationSummary* locations = invoke->GetLocations();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001253
1254 // Note that the null check must have been done earlier.
1255 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1256
1257 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001258 // 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 -07001259 SlowPathCode* slow_path = nullptr;
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001260 HInstruction* code_point = invoke->InputAt(1);
1261 if (code_point->IsIntConstant()) {
Vladimir Markoda051082016-05-17 16:10:20 +01001262 if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) >
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001263 std::numeric_limits<uint16_t>::max()) {
1264 // Always needs the slow-path. We could directly dispatch to it, but this case should be
1265 // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1266 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1267 codegen->AddSlowPath(slow_path);
1268 __ b(slow_path->GetEntryLabel());
1269 __ Bind(slow_path->GetExitLabel());
1270 return;
1271 }
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001272 } else if (code_point->GetType() != Primitive::kPrimChar) {
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001273 Register char_reg = locations->InAt(1).AsRegister<Register>();
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001274 // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`.
1275 __ cmp(char_reg,
1276 ShifterOperand(static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001277 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1278 codegen->AddSlowPath(slow_path);
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001279 __ b(slow_path->GetEntryLabel(), HS);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001280 }
1281
1282 if (start_at_zero) {
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001283 Register tmp_reg = locations->GetTemp(0).AsRegister<Register>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001284 DCHECK_EQ(tmp_reg, R2);
1285 // Start-index = 0.
1286 __ LoadImmediate(tmp_reg, 0);
1287 }
1288
1289 __ LoadFromOffset(kLoadWord, LR, TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001290 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pIndexOf).Int32Value());
Roland Levillain42ad2882016-02-29 18:26:54 +00001291 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001292 __ blx(LR);
1293
1294 if (slow_path != nullptr) {
1295 __ Bind(slow_path->GetExitLabel());
1296 }
1297}
1298
1299void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) {
1300 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001301 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001302 kIntrinsified);
1303 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1304 // best to align the inputs accordingly.
1305 InvokeRuntimeCallingConvention calling_convention;
1306 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1307 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1308 locations->SetOut(Location::RegisterLocation(R0));
1309
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001310 // Need to send start-index=0.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001311 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1312}
1313
1314void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001315 GenerateVisitStringIndexOf(
1316 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001317}
1318
1319void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1320 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001321 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001322 kIntrinsified);
1323 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1324 // best to align the inputs accordingly.
1325 InvokeRuntimeCallingConvention calling_convention;
1326 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1327 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1328 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1329 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001330}
1331
1332void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001333 GenerateVisitStringIndexOf(
1334 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001335}
1336
Jeff Hao848f70a2014-01-15 13:49:50 -08001337void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1338 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001339 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001340 kIntrinsified);
1341 InvokeRuntimeCallingConvention calling_convention;
1342 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1343 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1344 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1345 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1346 locations->SetOut(Location::RegisterLocation(R0));
1347}
1348
1349void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1350 ArmAssembler* assembler = GetAssembler();
1351 LocationSummary* locations = invoke->GetLocations();
1352
1353 Register byte_array = locations->InAt(0).AsRegister<Register>();
1354 __ cmp(byte_array, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001355 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001356 codegen_->AddSlowPath(slow_path);
1357 __ b(slow_path->GetEntryLabel(), EQ);
1358
Andreas Gampe542451c2016-07-26 09:02:02 -07001359 __ LoadFromOffset(kLoadWord,
1360 LR,
1361 TR,
1362 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromBytes).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001363 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001364 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001365 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001366 __ Bind(slow_path->GetExitLabel());
1367}
1368
1369void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1370 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001371 LocationSummary::kCallOnMainOnly,
Jeff Hao848f70a2014-01-15 13:49:50 -08001372 kIntrinsified);
1373 InvokeRuntimeCallingConvention calling_convention;
1374 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1375 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1376 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1377 locations->SetOut(Location::RegisterLocation(R0));
1378}
1379
1380void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1381 ArmAssembler* assembler = GetAssembler();
1382
Roland Levillaincc3839c2016-02-29 16:23:48 +00001383 // No need to emit code checking whether `locations->InAt(2)` is a null
1384 // pointer, as callers of the native method
1385 //
1386 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1387 //
1388 // all include a null check on `data` before calling that method.
Andreas Gampe542451c2016-07-26 09:02:02 -07001389 __ LoadFromOffset(kLoadWord,
1390 LR,
1391 TR,
1392 QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromChars).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001393 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001394 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001395 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001396}
1397
1398void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) {
1399 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001400 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001401 kIntrinsified);
1402 InvokeRuntimeCallingConvention calling_convention;
1403 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1404 locations->SetOut(Location::RegisterLocation(R0));
1405}
1406
1407void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) {
1408 ArmAssembler* assembler = GetAssembler();
1409 LocationSummary* locations = invoke->GetLocations();
1410
1411 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1412 __ cmp(string_to_copy, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001413 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001414 codegen_->AddSlowPath(slow_path);
1415 __ b(slow_path->GetEntryLabel(), EQ);
1416
1417 __ LoadFromOffset(kLoadWord,
Andreas Gampe542451c2016-07-26 09:02:02 -07001418 LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmPointerSize, pAllocStringFromString).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001419 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001420 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001421 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001422 __ Bind(slow_path->GetExitLabel());
1423}
1424
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001425void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001426 // The only read barrier implementation supporting the
1427 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1428 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
Roland Levillain3d312422016-06-23 13:53:42 +01001429 return;
1430 }
1431
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001432 CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke);
1433 LocationSummary* locations = invoke->GetLocations();
1434 if (locations == nullptr) {
1435 return;
1436 }
1437
1438 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
1439 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
1440 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
1441
1442 if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) {
1443 locations->SetInAt(1, Location::RequiresRegister());
1444 }
1445 if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) {
1446 locations->SetInAt(3, Location::RequiresRegister());
1447 }
1448 if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) {
1449 locations->SetInAt(4, Location::RequiresRegister());
1450 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001451 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1452 // Temporary register IP cannot be used in
Roland Levillain16d9f942016-08-25 17:27:56 +01001453 // ReadBarrierSystemArrayCopySlowPathARM (because that register
Roland Levillain0b671c02016-08-19 12:02:34 +01001454 // is clobbered by ReadBarrierMarkRegX entry points). Get an extra
1455 // temporary register from the register allocator.
1456 locations->AddTemp(Location::RequiresRegister());
1457 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001458}
1459
1460static void CheckPosition(ArmAssembler* assembler,
1461 Location pos,
1462 Register input,
1463 Location length,
1464 SlowPathCode* slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001465 Register temp,
1466 bool length_is_input_length = false) {
1467 // Where is the length in the Array?
1468 const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value();
1469
1470 if (pos.IsConstant()) {
1471 int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue();
1472 if (pos_const == 0) {
1473 if (!length_is_input_length) {
1474 // Check that length(input) >= length.
1475 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1476 if (length.IsConstant()) {
1477 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1478 } else {
1479 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1480 }
1481 __ b(slow_path->GetEntryLabel(), LT);
1482 }
1483 } else {
1484 // Check that length(input) >= pos.
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001485 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1486 __ subs(temp, temp, ShifterOperand(pos_const));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001487 __ b(slow_path->GetEntryLabel(), LT);
1488
1489 // Check that (length(input) - pos) >= length.
1490 if (length.IsConstant()) {
1491 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1492 } else {
1493 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1494 }
1495 __ b(slow_path->GetEntryLabel(), LT);
1496 }
1497 } else if (length_is_input_length) {
1498 // The only way the copy can succeed is if pos is zero.
1499 Register pos_reg = pos.AsRegister<Register>();
1500 __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel());
1501 } else {
1502 // Check that pos >= 0.
1503 Register pos_reg = pos.AsRegister<Register>();
1504 __ cmp(pos_reg, ShifterOperand(0));
1505 __ b(slow_path->GetEntryLabel(), LT);
1506
1507 // Check that pos <= length(input).
1508 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1509 __ subs(temp, temp, ShifterOperand(pos_reg));
1510 __ b(slow_path->GetEntryLabel(), LT);
1511
1512 // Check that (length(input) - pos) >= length.
1513 if (length.IsConstant()) {
1514 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1515 } else {
1516 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1517 }
1518 __ b(slow_path->GetEntryLabel(), LT);
1519 }
1520}
1521
1522void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001523 // The only read barrier implementation supporting the
1524 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1525 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
Roland Levillain3d312422016-06-23 13:53:42 +01001526
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001527 ArmAssembler* assembler = GetAssembler();
1528 LocationSummary* locations = invoke->GetLocations();
1529
1530 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1531 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
1532 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
1533 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001534 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001535
1536 Register src = locations->InAt(0).AsRegister<Register>();
1537 Location src_pos = locations->InAt(1);
1538 Register dest = locations->InAt(2).AsRegister<Register>();
1539 Location dest_pos = locations->InAt(3);
1540 Location length = locations->InAt(4);
Roland Levillain0b671c02016-08-19 12:02:34 +01001541 Location temp1_loc = locations->GetTemp(0);
1542 Register temp1 = temp1_loc.AsRegister<Register>();
1543 Location temp2_loc = locations->GetTemp(1);
1544 Register temp2 = temp2_loc.AsRegister<Register>();
1545 Location temp3_loc = locations->GetTemp(2);
1546 Register temp3 = temp3_loc.AsRegister<Register>();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001547
Roland Levillain0b671c02016-08-19 12:02:34 +01001548 SlowPathCode* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1549 codegen_->AddSlowPath(intrinsic_slow_path);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001550
Roland Levillainebea3d22016-04-12 15:42:57 +01001551 Label conditions_on_positions_validated;
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001552 SystemArrayCopyOptimizations optimizations(invoke);
1553
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001554 // If source and destination are the same, we go to slow path if we need to do
1555 // forward copying.
1556 if (src_pos.IsConstant()) {
1557 int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1558 if (dest_pos.IsConstant()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001559 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1560 if (optimizations.GetDestinationIsSource()) {
1561 // Checked when building locations.
1562 DCHECK_GE(src_pos_constant, dest_pos_constant);
1563 } else if (src_pos_constant < dest_pos_constant) {
1564 __ cmp(src, ShifterOperand(dest));
Roland Levillain0b671c02016-08-19 12:02:34 +01001565 __ b(intrinsic_slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001566 }
1567
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001568 // Checked when building locations.
1569 DCHECK(!optimizations.GetDestinationIsSource()
1570 || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue()));
1571 } else {
1572 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001573 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001574 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001575 }
1576 __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant));
Roland Levillain0b671c02016-08-19 12:02:34 +01001577 __ b(intrinsic_slow_path->GetEntryLabel(), GT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001578 }
1579 } else {
1580 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001581 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001582 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001583 }
1584 if (dest_pos.IsConstant()) {
1585 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1586 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant));
1587 } else {
1588 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>()));
1589 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001590 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001591 }
1592
Roland Levillainebea3d22016-04-12 15:42:57 +01001593 __ Bind(&conditions_on_positions_validated);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001594
1595 if (!optimizations.GetSourceIsNotNull()) {
1596 // Bail out if the source is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001597 __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001598 }
1599
1600 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
1601 // Bail out if the destination is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001602 __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001603 }
1604
1605 // If the length is negative, bail out.
1606 // We have already checked in the LocationsBuilder for the constant case.
1607 if (!length.IsConstant() &&
1608 !optimizations.GetCountIsSourceLength() &&
1609 !optimizations.GetCountIsDestinationLength()) {
1610 __ cmp(length.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain0b671c02016-08-19 12:02:34 +01001611 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001612 }
1613
1614 // Validity checks: source.
1615 CheckPosition(assembler,
1616 src_pos,
1617 src,
1618 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001619 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001620 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001621 optimizations.GetCountIsSourceLength());
1622
1623 // Validity checks: dest.
1624 CheckPosition(assembler,
1625 dest_pos,
1626 dest,
1627 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001628 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001629 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001630 optimizations.GetCountIsDestinationLength());
1631
1632 if (!optimizations.GetDoesNotNeedTypeCheck()) {
1633 // Check whether all elements of the source array are assignable to the component
1634 // type of the destination array. We do two checks: the classes are the same,
1635 // or the destination is Object[]. If none of these checks succeed, we go to the
1636 // slow path.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001637
Roland Levillain0b671c02016-08-19 12:02:34 +01001638 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1639 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1640 // /* HeapReference<Class> */ temp1 = src->klass_
1641 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1642 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1643 // Bail out if the source is not a non primitive array.
1644 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1645 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1646 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1647 __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel());
1648 // If heap poisoning is enabled, `temp1` has been unpoisoned
1649 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1650 // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_);
1651 __ LoadFromOffset(kLoadUnsignedHalfword, temp1, temp1, primitive_offset);
1652 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1653 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001654 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001655
1656 // /* HeapReference<Class> */ temp1 = dest->klass_
1657 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1658 invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false);
1659
1660 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1661 // Bail out if the destination is not a non primitive array.
1662 //
1663 // Register `temp1` is not trashed by the read barrier emitted
1664 // by GenerateFieldLoadWithBakerReadBarrier below, as that
1665 // method produces a call to a ReadBarrierMarkRegX entry point,
1666 // which saves all potentially live registers, including
1667 // temporaries such a `temp1`.
1668 // /* HeapReference<Class> */ temp2 = temp1->component_type_
1669 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1670 invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false);
1671 __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel());
1672 // If heap poisoning is enabled, `temp2` has been unpoisoned
1673 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1674 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
1675 __ LoadFromOffset(kLoadUnsignedHalfword, temp2, temp2, primitive_offset);
1676 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1677 __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel());
1678 }
1679
1680 // For the same reason given earlier, `temp1` is not trashed by the
1681 // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below.
1682 // /* HeapReference<Class> */ temp2 = src->klass_
1683 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1684 invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false);
1685 // Note: if heap poisoning is on, we are comparing two unpoisoned references here.
1686 __ cmp(temp1, ShifterOperand(temp2));
1687
1688 if (optimizations.GetDestinationIsTypedObjectArray()) {
1689 Label do_copy;
1690 __ b(&do_copy, EQ);
1691 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1692 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1693 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1694 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1695 // We do not need to emit a read barrier for the following
1696 // heap reference load, as `temp1` is only used in a
1697 // comparison with null below, and this reference is not
1698 // kept afterwards.
1699 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1700 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1701 __ Bind(&do_copy);
1702 } else {
1703 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1704 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001705 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001706 // Non read barrier code.
1707
1708 // /* HeapReference<Class> */ temp1 = dest->klass_
1709 __ LoadFromOffset(kLoadWord, temp1, dest, class_offset);
1710 // /* HeapReference<Class> */ temp2 = src->klass_
1711 __ LoadFromOffset(kLoadWord, temp2, src, class_offset);
1712 bool did_unpoison = false;
1713 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
1714 !optimizations.GetSourceIsNonPrimitiveArray()) {
1715 // One or two of the references need to be unpoisoned. Unpoison them
1716 // both to make the identity check valid.
1717 __ MaybeUnpoisonHeapReference(temp1);
1718 __ MaybeUnpoisonHeapReference(temp2);
1719 did_unpoison = true;
1720 }
1721
1722 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1723 // Bail out if the destination is not a non primitive array.
1724 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1725 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1726 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1727 __ MaybeUnpoisonHeapReference(temp3);
1728 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1729 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1730 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1731 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1732 }
1733
1734 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1735 // Bail out if the source is not a non primitive array.
1736 // /* HeapReference<Class> */ temp3 = temp2->component_type_
1737 __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset);
1738 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1739 __ MaybeUnpoisonHeapReference(temp3);
1740 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1741 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1742 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1743 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1744 }
1745
1746 __ cmp(temp1, ShifterOperand(temp2));
1747
1748 if (optimizations.GetDestinationIsTypedObjectArray()) {
1749 Label do_copy;
1750 __ b(&do_copy, EQ);
1751 if (!did_unpoison) {
1752 __ MaybeUnpoisonHeapReference(temp1);
1753 }
1754 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1755 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
1756 __ MaybeUnpoisonHeapReference(temp1);
1757 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1758 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1759 // No need to unpoison the result, we're comparing against null.
1760 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1761 __ Bind(&do_copy);
1762 } else {
1763 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1764 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001765 }
1766 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1767 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
1768 // Bail out if the source is not a non primitive array.
Roland Levillain0b671c02016-08-19 12:02:34 +01001769 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1770 // /* HeapReference<Class> */ temp1 = src->klass_
1771 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1772 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1773 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1774 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1775 invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1776 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1777 // If heap poisoning is enabled, `temp3` has been unpoisoned
1778 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1779 } else {
1780 // /* HeapReference<Class> */ temp1 = src->klass_
1781 __ LoadFromOffset(kLoadWord, temp1, src, class_offset);
1782 __ MaybeUnpoisonHeapReference(temp1);
1783 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1784 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1785 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1786 __ MaybeUnpoisonHeapReference(temp3);
1787 }
1788 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001789 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1790 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
Roland Levillain0b671c02016-08-19 12:02:34 +01001791 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001792 }
1793
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001794 int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
Roland Levillain0b671c02016-08-19 12:02:34 +01001795 uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001796 uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001797
1798 // Compute the base source address in `temp1`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001799 if (src_pos.IsConstant()) {
1800 int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1801 __ AddConstant(temp1, src, element_size * constant + offset);
1802 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001803 __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001804 __ AddConstant(temp1, offset);
1805 }
1806
Roland Levillain0b671c02016-08-19 12:02:34 +01001807 // Compute the end source address in `temp3`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001808 if (length.IsConstant()) {
1809 int32_t constant = length.GetConstant()->AsIntConstant()->GetValue();
1810 __ AddConstant(temp3, temp1, element_size * constant);
1811 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001812 __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001813 }
1814
Roland Levillain0b671c02016-08-19 12:02:34 +01001815 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1816 // The base destination address is computed later, as `temp2` is
1817 // used for intermediate computations.
1818
1819 // SystemArrayCopy implementation for Baker read barriers (see
1820 // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier):
1821 //
1822 // if (src_ptr != end_ptr) {
1823 // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState();
1824 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
1825 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
1826 // if (is_gray) {
1827 // // Slow-path copy.
1828 // do {
1829 // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++)));
1830 // } while (src_ptr != end_ptr)
1831 // } else {
1832 // // Fast-path copy.
1833 // do {
1834 // *dest_ptr++ = *src_ptr++;
1835 // } while (src_ptr != end_ptr)
1836 // }
1837 // }
1838
1839 Label loop, done;
1840
1841 // Don't enter copy loop if `length == 0`.
1842 __ cmp(temp1, ShifterOperand(temp3));
1843 __ b(&done, EQ);
1844
1845 // /* int32_t */ monitor = src->monitor_
1846 __ LoadFromOffset(kLoadWord, temp2, src, monitor_offset);
1847 // /* LockWord */ lock_word = LockWord(monitor)
1848 static_assert(sizeof(LockWord) == sizeof(int32_t),
1849 "art::LockWord and int32_t have different sizes.");
1850
1851 // Introduce a dependency on the lock_word including the rb_state,
1852 // which shall prevent load-load reordering without using
1853 // a memory barrier (which would be more expensive).
1854 // `src` is unchanged by this operation, but its value now depends
1855 // on `temp2`.
1856 __ add(src, src, ShifterOperand(temp2, LSR, 32));
1857
1858 // Slow path used to copy array when `src` is gray.
1859 SlowPathCode* read_barrier_slow_path =
1860 new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARM(invoke);
1861 codegen_->AddSlowPath(read_barrier_slow_path);
1862
1863 // Given the numeric representation, it's enough to check the low bit of the
1864 // rb_state. We do that by shifting the bit out of the lock word with LSRS
1865 // which can be a 16-bit instruction unlike the TST immediate.
1866 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
1867 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
1868 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
1869 __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1);
1870 // Carry flag is the last bit shifted out by LSRS.
1871 __ b(read_barrier_slow_path->GetEntryLabel(), CS);
1872
1873 // Fast-path copy.
1874
1875 // Compute the base destination address in `temp2`.
1876 if (dest_pos.IsConstant()) {
1877 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1878 __ AddConstant(temp2, dest, element_size * constant + offset);
1879 } else {
1880 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1881 __ AddConstant(temp2, offset);
1882 }
1883
1884 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1885 // poison/unpoison.
1886 __ Bind(&loop);
1887 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1888 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1889 __ cmp(temp1, ShifterOperand(temp3));
1890 __ b(&loop, NE);
1891
1892 __ Bind(read_barrier_slow_path->GetExitLabel());
1893 __ Bind(&done);
1894 } else {
1895 // Non read barrier code.
1896
1897 // Compute the base destination address in `temp2`.
1898 if (dest_pos.IsConstant()) {
1899 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1900 __ AddConstant(temp2, dest, element_size * constant + offset);
1901 } else {
1902 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1903 __ AddConstant(temp2, offset);
1904 }
1905
1906 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1907 // poison/unpoison.
1908 Label loop, done;
1909 __ cmp(temp1, ShifterOperand(temp3));
1910 __ b(&done, EQ);
1911 __ Bind(&loop);
1912 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1913 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1914 __ cmp(temp1, ShifterOperand(temp3));
1915 __ b(&loop, NE);
1916 __ Bind(&done);
1917 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001918
1919 // We only need one card marking on the destination array.
1920 codegen_->MarkGCCard(temp1,
1921 temp2,
1922 dest,
1923 Register(kNoRegister),
Roland Levillainebea3d22016-04-12 15:42:57 +01001924 /* value_can_be_null */ false);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001925
Roland Levillain0b671c02016-08-19 12:02:34 +01001926 __ Bind(intrinsic_slow_path->GetExitLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001927}
1928
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001929static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1930 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1931 // the code generator. Furthermore, the register allocator creates fixed live intervals
1932 // for all caller-saved registers because we are doing a function call. As a result, if
1933 // the input and output locations are unallocated, the register allocator runs out of
1934 // registers and fails; however, a debuggable graph is not the common case.
1935 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1936 return;
1937 }
1938
1939 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1940 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1941 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1942
1943 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001944 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001945 kIntrinsified);
1946 const InvokeRuntimeCallingConvention calling_convention;
1947
1948 locations->SetInAt(0, Location::RequiresFpuRegister());
1949 locations->SetOut(Location::RequiresFpuRegister());
1950 // Native code uses the soft float ABI.
1951 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1952 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1953}
1954
1955static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1956 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1957 // the code generator. Furthermore, the register allocator creates fixed live intervals
1958 // for all caller-saved registers because we are doing a function call. As a result, if
1959 // the input and output locations are unallocated, the register allocator runs out of
1960 // registers and fails; however, a debuggable graph is not the common case.
1961 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1962 return;
1963 }
1964
1965 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1966 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1967 DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble);
1968 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1969
1970 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001971 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001972 kIntrinsified);
1973 const InvokeRuntimeCallingConvention calling_convention;
1974
1975 locations->SetInAt(0, Location::RequiresFpuRegister());
1976 locations->SetInAt(1, Location::RequiresFpuRegister());
1977 locations->SetOut(Location::RequiresFpuRegister());
1978 // Native code uses the soft float ABI.
1979 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1980 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1981 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1982 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1983}
1984
1985static void GenFPToFPCall(HInvoke* invoke,
1986 ArmAssembler* assembler,
1987 CodeGeneratorARM* codegen,
1988 QuickEntrypointEnum entry) {
1989 LocationSummary* const locations = invoke->GetLocations();
1990 const InvokeRuntimeCallingConvention calling_convention;
1991
1992 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1993 DCHECK(locations->WillCall() && locations->Intrinsified());
1994 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
1995 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
1996
Andreas Gampe542451c2016-07-26 09:02:02 -07001997 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001998 // Native code uses the soft float ABI.
1999 __ vmovrrd(calling_convention.GetRegisterAt(0),
2000 calling_convention.GetRegisterAt(1),
2001 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2002 __ blx(LR);
2003 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
2004 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
2005 calling_convention.GetRegisterAt(0),
2006 calling_convention.GetRegisterAt(1));
2007}
2008
2009static void GenFPFPToFPCall(HInvoke* invoke,
2010 ArmAssembler* assembler,
2011 CodeGeneratorARM* codegen,
2012 QuickEntrypointEnum entry) {
2013 LocationSummary* const locations = invoke->GetLocations();
2014 const InvokeRuntimeCallingConvention calling_convention;
2015
2016 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
2017 DCHECK(locations->WillCall() && locations->Intrinsified());
2018 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
2019 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
2020 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2)));
2021 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3)));
2022
Andreas Gampe542451c2016-07-26 09:02:02 -07002023 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmPointerSize>(entry).Int32Value());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00002024 // Native code uses the soft float ABI.
2025 __ vmovrrd(calling_convention.GetRegisterAt(0),
2026 calling_convention.GetRegisterAt(1),
2027 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2028 __ vmovrrd(calling_convention.GetRegisterAt(2),
2029 calling_convention.GetRegisterAt(3),
2030 FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()));
2031 __ blx(LR);
2032 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
2033 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
2034 calling_convention.GetRegisterAt(0),
2035 calling_convention.GetRegisterAt(1));
2036}
2037
2038void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) {
2039 CreateFPToFPCallLocations(arena_, invoke);
2040}
2041
2042void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) {
2043 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos);
2044}
2045
2046void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) {
2047 CreateFPToFPCallLocations(arena_, invoke);
2048}
2049
2050void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) {
2051 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin);
2052}
2053
2054void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) {
2055 CreateFPToFPCallLocations(arena_, invoke);
2056}
2057
2058void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) {
2059 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos);
2060}
2061
2062void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) {
2063 CreateFPToFPCallLocations(arena_, invoke);
2064}
2065
2066void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) {
2067 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin);
2068}
2069
2070void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) {
2071 CreateFPToFPCallLocations(arena_, invoke);
2072}
2073
2074void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) {
2075 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan);
2076}
2077
2078void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) {
2079 CreateFPToFPCallLocations(arena_, invoke);
2080}
2081
2082void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) {
2083 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt);
2084}
2085
2086void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) {
2087 CreateFPToFPCallLocations(arena_, invoke);
2088}
2089
2090void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) {
2091 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh);
2092}
2093
2094void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) {
2095 CreateFPToFPCallLocations(arena_, invoke);
2096}
2097
2098void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) {
2099 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp);
2100}
2101
2102void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) {
2103 CreateFPToFPCallLocations(arena_, invoke);
2104}
2105
2106void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) {
2107 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1);
2108}
2109
2110void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) {
2111 CreateFPToFPCallLocations(arena_, invoke);
2112}
2113
2114void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) {
2115 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog);
2116}
2117
2118void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) {
2119 CreateFPToFPCallLocations(arena_, invoke);
2120}
2121
2122void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) {
2123 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10);
2124}
2125
2126void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) {
2127 CreateFPToFPCallLocations(arena_, invoke);
2128}
2129
2130void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) {
2131 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh);
2132}
2133
2134void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) {
2135 CreateFPToFPCallLocations(arena_, invoke);
2136}
2137
2138void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) {
2139 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan);
2140}
2141
2142void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) {
2143 CreateFPToFPCallLocations(arena_, invoke);
2144}
2145
2146void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) {
2147 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh);
2148}
2149
2150void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) {
2151 CreateFPFPToFPCallLocations(arena_, invoke);
2152}
2153
2154void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) {
2155 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2);
2156}
2157
2158void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) {
2159 CreateFPFPToFPCallLocations(arena_, invoke);
2160}
2161
2162void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) {
2163 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot);
2164}
2165
2166void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) {
2167 CreateFPFPToFPCallLocations(arena_, invoke);
2168}
2169
2170void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) {
2171 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter);
2172}
2173
Artem Serovc257da72016-02-02 13:49:43 +00002174void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) {
2175 CreateIntToIntLocations(arena_, invoke);
2176}
2177
2178void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) {
2179 ArmAssembler* assembler = GetAssembler();
2180 LocationSummary* locations = invoke->GetLocations();
2181
2182 Register out = locations->Out().AsRegister<Register>();
2183 Register in = locations->InAt(0).AsRegister<Register>();
2184
2185 __ rbit(out, in);
2186}
2187
2188void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) {
2189 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2190 LocationSummary::kNoCall,
2191 kIntrinsified);
2192 locations->SetInAt(0, Location::RequiresRegister());
2193 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2194}
2195
2196void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) {
2197 ArmAssembler* assembler = GetAssembler();
2198 LocationSummary* locations = invoke->GetLocations();
2199
2200 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2201 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2202 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2203 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2204
2205 __ rbit(out_reg_lo, in_reg_hi);
2206 __ rbit(out_reg_hi, in_reg_lo);
2207}
2208
2209void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2210 CreateIntToIntLocations(arena_, invoke);
2211}
2212
2213void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2214 ArmAssembler* assembler = GetAssembler();
2215 LocationSummary* locations = invoke->GetLocations();
2216
2217 Register out = locations->Out().AsRegister<Register>();
2218 Register in = locations->InAt(0).AsRegister<Register>();
2219
2220 __ rev(out, in);
2221}
2222
2223void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) {
2224 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2225 LocationSummary::kNoCall,
2226 kIntrinsified);
2227 locations->SetInAt(0, Location::RequiresRegister());
2228 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2229}
2230
2231void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) {
2232 ArmAssembler* assembler = GetAssembler();
2233 LocationSummary* locations = invoke->GetLocations();
2234
2235 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2236 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2237 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2238 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2239
2240 __ rev(out_reg_lo, in_reg_hi);
2241 __ rev(out_reg_hi, in_reg_lo);
2242}
2243
2244void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) {
2245 CreateIntToIntLocations(arena_, invoke);
2246}
2247
2248void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) {
2249 ArmAssembler* assembler = GetAssembler();
2250 LocationSummary* locations = invoke->GetLocations();
2251
2252 Register out = locations->Out().AsRegister<Register>();
2253 Register in = locations->InAt(0).AsRegister<Register>();
2254
2255 __ revsh(out, in);
2256}
2257
xueliang.zhongf1073c82016-07-05 15:28:19 +01002258static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmAssembler* assembler) {
2259 DCHECK(Primitive::IsIntOrLongType(type)) << type;
2260 DCHECK_EQ(instr->GetType(), Primitive::kPrimInt);
2261 DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type);
2262
2263 bool is_long = type == Primitive::kPrimLong;
2264 LocationSummary* locations = instr->GetLocations();
2265 Location in = locations->InAt(0);
2266 Register src_0 = is_long ? in.AsRegisterPairLow<Register>() : in.AsRegister<Register>();
2267 Register src_1 = is_long ? in.AsRegisterPairHigh<Register>() : src_0;
2268 SRegister tmp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2269 DRegister tmp_d = FromLowSToD(tmp_s);
2270 Register out_r = locations->Out().AsRegister<Register>();
2271
2272 // Move data from core register(s) to temp D-reg for bit count calculation, then move back.
2273 // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg,
2274 // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency,
2275 // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'.
2276 __ vmovdrr(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0|
2277 __ vcntd(tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c|
2278 __ vpaddld(tmp_d, tmp_d, 8, /* is_unsigned */ true); // Temp DReg |--c|--c|--c|--c|
2279 __ vpaddld(tmp_d, tmp_d, 16, /* is_unsigned */ true); // Temp DReg |------c|------c|
2280 if (is_long) {
2281 __ vpaddld(tmp_d, tmp_d, 32, /* is_unsigned */ true); // Temp DReg |--------------c|
2282 }
2283 __ vmovrs(out_r, tmp_s);
2284}
2285
2286void IntrinsicLocationsBuilderARM::VisitIntegerBitCount(HInvoke* invoke) {
2287 CreateIntToIntLocations(arena_, invoke);
2288 invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister());
2289}
2290
2291void IntrinsicCodeGeneratorARM::VisitIntegerBitCount(HInvoke* invoke) {
2292 GenBitCount(invoke, Primitive::kPrimInt, GetAssembler());
2293}
2294
2295void IntrinsicLocationsBuilderARM::VisitLongBitCount(HInvoke* invoke) {
2296 VisitIntegerBitCount(invoke);
2297}
2298
2299void IntrinsicCodeGeneratorARM::VisitLongBitCount(HInvoke* invoke) {
2300 GenBitCount(invoke, Primitive::kPrimLong, GetAssembler());
2301}
2302
Tim Zhang25abd6c2016-01-19 23:39:24 +08002303void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2304 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2305 LocationSummary::kNoCall,
2306 kIntrinsified);
2307 locations->SetInAt(0, Location::RequiresRegister());
2308 locations->SetInAt(1, Location::RequiresRegister());
2309 locations->SetInAt(2, Location::RequiresRegister());
2310 locations->SetInAt(3, Location::RequiresRegister());
2311 locations->SetInAt(4, Location::RequiresRegister());
2312
Scott Wakeling3fdab772016-04-25 11:32:37 +01002313 // Temporary registers to store lengths of strings and for calculations.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002314 locations->AddTemp(Location::RequiresRegister());
2315 locations->AddTemp(Location::RequiresRegister());
2316 locations->AddTemp(Location::RequiresRegister());
2317}
2318
2319void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2320 ArmAssembler* assembler = GetAssembler();
2321 LocationSummary* locations = invoke->GetLocations();
2322
2323 // Check assumption that sizeof(Char) is 2 (used in scaling below).
2324 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
2325 DCHECK_EQ(char_size, 2u);
2326
2327 // Location of data in char array buffer.
2328 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
2329
2330 // Location of char array data in string.
2331 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
2332
2333 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
2334 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
2335 Register srcObj = locations->InAt(0).AsRegister<Register>();
2336 Register srcBegin = locations->InAt(1).AsRegister<Register>();
2337 Register srcEnd = locations->InAt(2).AsRegister<Register>();
2338 Register dstObj = locations->InAt(3).AsRegister<Register>();
2339 Register dstBegin = locations->InAt(4).AsRegister<Register>();
2340
Scott Wakeling3fdab772016-04-25 11:32:37 +01002341 Register num_chr = locations->GetTemp(0).AsRegister<Register>();
2342 Register src_ptr = locations->GetTemp(1).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002343 Register dst_ptr = locations->GetTemp(2).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002344
2345 // src range to copy.
2346 __ add(src_ptr, srcObj, ShifterOperand(value_offset));
Tim Zhang25abd6c2016-01-19 23:39:24 +08002347 __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1));
2348
2349 // dst to be copied.
2350 __ add(dst_ptr, dstObj, ShifterOperand(data_offset));
2351 __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1));
2352
Scott Wakeling3fdab772016-04-25 11:32:37 +01002353 __ subs(num_chr, srcEnd, ShifterOperand(srcBegin));
2354
Tim Zhang25abd6c2016-01-19 23:39:24 +08002355 // Do the copy.
Scott Wakeling3fdab772016-04-25 11:32:37 +01002356 Label loop, remainder, done;
2357
2358 // Early out for valid zero-length retrievals.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002359 __ b(&done, EQ);
Scott Wakeling3fdab772016-04-25 11:32:37 +01002360
2361 // Save repairing the value of num_chr on the < 4 character path.
2362 __ subs(IP, num_chr, ShifterOperand(4));
2363 __ b(&remainder, LT);
2364
2365 // Keep the result of the earlier subs, we are going to fetch at least 4 characters.
2366 __ mov(num_chr, ShifterOperand(IP));
2367
2368 // Main loop used for longer fetches loads and stores 4x16-bit characters at a time.
2369 // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code
2370 // to rectify these everywhere this intrinsic applies.)
2371 __ Bind(&loop);
2372 __ ldr(IP, Address(src_ptr, char_size * 2));
2373 __ subs(num_chr, num_chr, ShifterOperand(4));
2374 __ str(IP, Address(dst_ptr, char_size * 2));
2375 __ ldr(IP, Address(src_ptr, char_size * 4, Address::PostIndex));
2376 __ str(IP, Address(dst_ptr, char_size * 4, Address::PostIndex));
2377 __ b(&loop, GE);
2378
2379 __ adds(num_chr, num_chr, ShifterOperand(4));
2380 __ b(&done, EQ);
2381
2382 // Main loop for < 4 character case and remainder handling. Loads and stores one
2383 // 16-bit Java character at a time.
2384 __ Bind(&remainder);
2385 __ ldrh(IP, Address(src_ptr, char_size, Address::PostIndex));
2386 __ subs(num_chr, num_chr, ShifterOperand(1));
2387 __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex));
2388 __ b(&remainder, GT);
2389
Tim Zhang25abd6c2016-01-19 23:39:24 +08002390 __ Bind(&done);
2391}
2392
Anton Kirilova3ffea22016-04-07 17:02:37 +01002393void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) {
2394 CreateFPToIntLocations(arena_, invoke);
2395}
2396
2397void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) {
2398 ArmAssembler* const assembler = GetAssembler();
2399 LocationSummary* const locations = invoke->GetLocations();
2400 const Register out = locations->Out().AsRegister<Register>();
2401 // Shifting left by 1 bit makes the value encodable as an immediate operand;
2402 // we don't care about the sign bit anyway.
2403 constexpr uint32_t infinity = kPositiveInfinityFloat << 1U;
2404
2405 __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>());
2406 // We don't care about the sign bit, so shift left.
2407 __ Lsl(out, out, 1);
2408 __ eor(out, out, ShifterOperand(infinity));
2409 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2410 __ clz(out, out);
2411 // Any number less than 32 logically shifted right by 5 bits results in 0;
2412 // the same operation on 32 yields 1.
2413 __ Lsr(out, out, 5);
2414}
2415
2416void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2417 CreateFPToIntLocations(arena_, invoke);
2418}
2419
2420void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2421 ArmAssembler* const assembler = GetAssembler();
2422 LocationSummary* const locations = invoke->GetLocations();
2423 const Register out = locations->Out().AsRegister<Register>();
2424 // The highest 32 bits of double precision positive infinity separated into
2425 // two constants encodable as immediate operands.
2426 constexpr uint32_t infinity_high = 0x7f000000U;
2427 constexpr uint32_t infinity_high2 = 0x00f00000U;
2428
2429 static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U),
2430 "The constants do not add up to the high 32 bits of double precision positive infinity.");
2431 __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2432 __ eor(out, out, ShifterOperand(infinity_high));
2433 __ eor(out, out, ShifterOperand(infinity_high2));
2434 // We don't care about the sign bit, so shift left.
2435 __ orr(out, IP, ShifterOperand(out, LSL, 1));
2436 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2437 __ clz(out, out);
2438 // Any number less than 32 logically shifted right by 5 bits results in 0;
2439 // the same operation on 32 yields 1.
2440 __ Lsr(out, out, 5);
2441}
2442
Aart Bik2f9fcc92016-03-01 15:16:54 -08002443UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble)
2444UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat)
2445UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble)
2446UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat)
2447UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong)
2448UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong)
2449UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe?
2450UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe?
2451UNIMPLEMENTED_INTRINSIC(ARM, MathRint)
2452UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe?
2453UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe?
2454UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure.
2455UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar)
2456UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002457UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit)
2458UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit)
2459UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit)
2460UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit)
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002461
Aart Bik0e54c012016-03-04 12:08:31 -08002462// 1.8.
2463UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt)
2464UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong)
2465UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt)
2466UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong)
2467UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject)
Aart Bik0e54c012016-03-04 12:08:31 -08002468
Aart Bik2f9fcc92016-03-01 15:16:54 -08002469UNREACHABLE_INTRINSICS(ARM)
Roland Levillain4d027112015-07-01 15:41:14 +01002470
2471#undef __
2472
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002473} // namespace arm
2474} // namespace art