blob: eefc64278f69534da58f8458c3b2687e980261f3 [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
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001289 codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path);
Roland Levillain42ad2882016-02-29 18:26:54 +00001290 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001291
1292 if (slow_path != nullptr) {
1293 __ Bind(slow_path->GetExitLabel());
1294 }
1295}
1296
1297void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) {
1298 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001299 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001300 kIntrinsified);
1301 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1302 // best to align the inputs accordingly.
1303 InvokeRuntimeCallingConvention calling_convention;
1304 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1305 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1306 locations->SetOut(Location::RegisterLocation(R0));
1307
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001308 // Need to send start-index=0.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001309 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1310}
1311
1312void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001313 GenerateVisitStringIndexOf(
1314 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001315}
1316
1317void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1318 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001319 LocationSummary::kCallOnMainAndSlowPath,
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001320 kIntrinsified);
1321 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1322 // best to align the inputs accordingly.
1323 InvokeRuntimeCallingConvention calling_convention;
1324 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1325 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1326 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1327 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001328}
1329
1330void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001331 GenerateVisitStringIndexOf(
1332 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001333}
1334
Jeff Hao848f70a2014-01-15 13:49:50 -08001335void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1336 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001337 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001338 kIntrinsified);
1339 InvokeRuntimeCallingConvention calling_convention;
1340 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1341 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1342 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1343 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1344 locations->SetOut(Location::RegisterLocation(R0));
1345}
1346
1347void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1348 ArmAssembler* assembler = GetAssembler();
1349 LocationSummary* locations = invoke->GetLocations();
1350
1351 Register byte_array = locations->InAt(0).AsRegister<Register>();
1352 __ cmp(byte_array, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001353 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001354 codegen_->AddSlowPath(slow_path);
1355 __ b(slow_path->GetEntryLabel(), EQ);
1356
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001357 codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path);
Roland Levillainf969a202016-03-09 16:14:00 +00001358 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001359 __ Bind(slow_path->GetExitLabel());
1360}
1361
1362void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1363 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001364 LocationSummary::kCallOnMainOnly,
Jeff Hao848f70a2014-01-15 13:49:50 -08001365 kIntrinsified);
1366 InvokeRuntimeCallingConvention calling_convention;
1367 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1368 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1369 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1370 locations->SetOut(Location::RegisterLocation(R0));
1371}
1372
1373void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) {
Roland Levillaincc3839c2016-02-29 16:23:48 +00001374 // No need to emit code checking whether `locations->InAt(2)` is a null
1375 // pointer, as callers of the native method
1376 //
1377 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1378 //
1379 // all include a null check on `data` before calling that method.
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001380 codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc());
Roland Levillainf969a202016-03-09 16:14:00 +00001381 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001382}
1383
1384void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) {
1385 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00001386 LocationSummary::kCallOnMainAndSlowPath,
Jeff Hao848f70a2014-01-15 13:49:50 -08001387 kIntrinsified);
1388 InvokeRuntimeCallingConvention calling_convention;
1389 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1390 locations->SetOut(Location::RegisterLocation(R0));
1391}
1392
1393void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) {
1394 ArmAssembler* assembler = GetAssembler();
1395 LocationSummary* locations = invoke->GetLocations();
1396
1397 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1398 __ cmp(string_to_copy, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001399 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001400 codegen_->AddSlowPath(slow_path);
1401 __ b(slow_path->GetEntryLabel(), EQ);
1402
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001403 codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc(), slow_path);
Roland Levillainf969a202016-03-09 16:14:00 +00001404 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001405
Jeff Hao848f70a2014-01-15 13:49:50 -08001406 __ Bind(slow_path->GetExitLabel());
1407}
1408
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001409void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001410 // The only read barrier implementation supporting the
1411 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1412 if (kEmitCompilerReadBarrier && !kUseBakerReadBarrier) {
Roland Levillain3d312422016-06-23 13:53:42 +01001413 return;
1414 }
1415
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001416 CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke);
1417 LocationSummary* locations = invoke->GetLocations();
1418 if (locations == nullptr) {
1419 return;
1420 }
1421
1422 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
1423 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
1424 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
1425
1426 if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) {
1427 locations->SetInAt(1, Location::RequiresRegister());
1428 }
1429 if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) {
1430 locations->SetInAt(3, Location::RequiresRegister());
1431 }
1432 if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) {
1433 locations->SetInAt(4, Location::RequiresRegister());
1434 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001435 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1436 // Temporary register IP cannot be used in
Roland Levillain16d9f942016-08-25 17:27:56 +01001437 // ReadBarrierSystemArrayCopySlowPathARM (because that register
Roland Levillain0b671c02016-08-19 12:02:34 +01001438 // is clobbered by ReadBarrierMarkRegX entry points). Get an extra
1439 // temporary register from the register allocator.
1440 locations->AddTemp(Location::RequiresRegister());
1441 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001442}
1443
1444static void CheckPosition(ArmAssembler* assembler,
1445 Location pos,
1446 Register input,
1447 Location length,
1448 SlowPathCode* slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001449 Register temp,
1450 bool length_is_input_length = false) {
1451 // Where is the length in the Array?
1452 const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value();
1453
1454 if (pos.IsConstant()) {
1455 int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue();
1456 if (pos_const == 0) {
1457 if (!length_is_input_length) {
1458 // Check that length(input) >= length.
1459 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1460 if (length.IsConstant()) {
1461 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1462 } else {
1463 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1464 }
1465 __ b(slow_path->GetEntryLabel(), LT);
1466 }
1467 } else {
1468 // Check that length(input) >= pos.
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001469 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1470 __ subs(temp, temp, ShifterOperand(pos_const));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001471 __ b(slow_path->GetEntryLabel(), LT);
1472
1473 // Check that (length(input) - pos) >= length.
1474 if (length.IsConstant()) {
1475 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1476 } else {
1477 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1478 }
1479 __ b(slow_path->GetEntryLabel(), LT);
1480 }
1481 } else if (length_is_input_length) {
1482 // The only way the copy can succeed is if pos is zero.
1483 Register pos_reg = pos.AsRegister<Register>();
1484 __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel());
1485 } else {
1486 // Check that pos >= 0.
1487 Register pos_reg = pos.AsRegister<Register>();
1488 __ cmp(pos_reg, ShifterOperand(0));
1489 __ b(slow_path->GetEntryLabel(), LT);
1490
1491 // Check that pos <= length(input).
1492 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1493 __ subs(temp, temp, ShifterOperand(pos_reg));
1494 __ b(slow_path->GetEntryLabel(), LT);
1495
1496 // Check that (length(input) - pos) >= length.
1497 if (length.IsConstant()) {
1498 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1499 } else {
1500 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1501 }
1502 __ b(slow_path->GetEntryLabel(), LT);
1503 }
1504}
1505
1506void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) {
Roland Levillain0b671c02016-08-19 12:02:34 +01001507 // The only read barrier implementation supporting the
1508 // SystemArrayCopy intrinsic is the Baker-style read barriers.
1509 DCHECK(!kEmitCompilerReadBarrier || kUseBakerReadBarrier);
Roland Levillain3d312422016-06-23 13:53:42 +01001510
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001511 ArmAssembler* assembler = GetAssembler();
1512 LocationSummary* locations = invoke->GetLocations();
1513
1514 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1515 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
1516 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
1517 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001518 uint32_t monitor_offset = mirror::Object::MonitorOffset().Int32Value();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001519
1520 Register src = locations->InAt(0).AsRegister<Register>();
1521 Location src_pos = locations->InAt(1);
1522 Register dest = locations->InAt(2).AsRegister<Register>();
1523 Location dest_pos = locations->InAt(3);
1524 Location length = locations->InAt(4);
Roland Levillain0b671c02016-08-19 12:02:34 +01001525 Location temp1_loc = locations->GetTemp(0);
1526 Register temp1 = temp1_loc.AsRegister<Register>();
1527 Location temp2_loc = locations->GetTemp(1);
1528 Register temp2 = temp2_loc.AsRegister<Register>();
1529 Location temp3_loc = locations->GetTemp(2);
1530 Register temp3 = temp3_loc.AsRegister<Register>();
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001531
Roland Levillain0b671c02016-08-19 12:02:34 +01001532 SlowPathCode* intrinsic_slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1533 codegen_->AddSlowPath(intrinsic_slow_path);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001534
Roland Levillainebea3d22016-04-12 15:42:57 +01001535 Label conditions_on_positions_validated;
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001536 SystemArrayCopyOptimizations optimizations(invoke);
1537
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001538 // If source and destination are the same, we go to slow path if we need to do
1539 // forward copying.
1540 if (src_pos.IsConstant()) {
1541 int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1542 if (dest_pos.IsConstant()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001543 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1544 if (optimizations.GetDestinationIsSource()) {
1545 // Checked when building locations.
1546 DCHECK_GE(src_pos_constant, dest_pos_constant);
1547 } else if (src_pos_constant < dest_pos_constant) {
1548 __ cmp(src, ShifterOperand(dest));
Roland Levillain0b671c02016-08-19 12:02:34 +01001549 __ b(intrinsic_slow_path->GetEntryLabel(), EQ);
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001550 }
1551
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001552 // Checked when building locations.
1553 DCHECK(!optimizations.GetDestinationIsSource()
1554 || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue()));
1555 } else {
1556 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001557 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001558 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001559 }
1560 __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant));
Roland Levillain0b671c02016-08-19 12:02:34 +01001561 __ b(intrinsic_slow_path->GetEntryLabel(), GT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001562 }
1563 } else {
1564 if (!optimizations.GetDestinationIsSource()) {
Nicolas Geoffray9f65db82016-07-07 12:07:42 +01001565 __ cmp(src, ShifterOperand(dest));
Roland Levillainebea3d22016-04-12 15:42:57 +01001566 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001567 }
1568 if (dest_pos.IsConstant()) {
1569 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1570 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant));
1571 } else {
1572 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>()));
1573 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001574 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001575 }
1576
Roland Levillainebea3d22016-04-12 15:42:57 +01001577 __ Bind(&conditions_on_positions_validated);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001578
1579 if (!optimizations.GetSourceIsNotNull()) {
1580 // Bail out if the source is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001581 __ CompareAndBranchIfZero(src, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001582 }
1583
1584 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
1585 // Bail out if the destination is null.
Roland Levillain0b671c02016-08-19 12:02:34 +01001586 __ CompareAndBranchIfZero(dest, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001587 }
1588
1589 // If the length is negative, bail out.
1590 // We have already checked in the LocationsBuilder for the constant case.
1591 if (!length.IsConstant() &&
1592 !optimizations.GetCountIsSourceLength() &&
1593 !optimizations.GetCountIsDestinationLength()) {
1594 __ cmp(length.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain0b671c02016-08-19 12:02:34 +01001595 __ b(intrinsic_slow_path->GetEntryLabel(), LT);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001596 }
1597
1598 // Validity checks: source.
1599 CheckPosition(assembler,
1600 src_pos,
1601 src,
1602 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001603 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001604 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001605 optimizations.GetCountIsSourceLength());
1606
1607 // Validity checks: dest.
1608 CheckPosition(assembler,
1609 dest_pos,
1610 dest,
1611 length,
Roland Levillain0b671c02016-08-19 12:02:34 +01001612 intrinsic_slow_path,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001613 temp1,
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001614 optimizations.GetCountIsDestinationLength());
1615
1616 if (!optimizations.GetDoesNotNeedTypeCheck()) {
1617 // Check whether all elements of the source array are assignable to the component
1618 // type of the destination array. We do two checks: the classes are the same,
1619 // or the destination is Object[]. If none of these checks succeed, we go to the
1620 // slow path.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001621
Roland Levillain0b671c02016-08-19 12:02:34 +01001622 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1623 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1624 // /* HeapReference<Class> */ temp1 = src->klass_
1625 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1626 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1627 // Bail out if the source is not a non primitive array.
1628 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1629 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1630 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1631 __ CompareAndBranchIfZero(temp1, intrinsic_slow_path->GetEntryLabel());
1632 // If heap poisoning is enabled, `temp1` has been unpoisoned
1633 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1634 // /* uint16_t */ temp1 = static_cast<uint16>(temp1->primitive_type_);
1635 __ LoadFromOffset(kLoadUnsignedHalfword, temp1, temp1, primitive_offset);
1636 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1637 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001638 }
Roland Levillain0b671c02016-08-19 12:02:34 +01001639
1640 // /* HeapReference<Class> */ temp1 = dest->klass_
1641 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1642 invoke, temp1_loc, dest, class_offset, temp2_loc, /* needs_null_check */ false);
1643
1644 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1645 // Bail out if the destination is not a non primitive array.
1646 //
1647 // Register `temp1` is not trashed by the read barrier emitted
1648 // by GenerateFieldLoadWithBakerReadBarrier below, as that
1649 // method produces a call to a ReadBarrierMarkRegX entry point,
1650 // which saves all potentially live registers, including
1651 // temporaries such a `temp1`.
1652 // /* HeapReference<Class> */ temp2 = temp1->component_type_
1653 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1654 invoke, temp2_loc, temp1, component_offset, temp3_loc, /* needs_null_check */ false);
1655 __ CompareAndBranchIfZero(temp2, intrinsic_slow_path->GetEntryLabel());
1656 // If heap poisoning is enabled, `temp2` has been unpoisoned
1657 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1658 // /* uint16_t */ temp2 = static_cast<uint16>(temp2->primitive_type_);
1659 __ LoadFromOffset(kLoadUnsignedHalfword, temp2, temp2, primitive_offset);
1660 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1661 __ CompareAndBranchIfNonZero(temp2, intrinsic_slow_path->GetEntryLabel());
1662 }
1663
1664 // For the same reason given earlier, `temp1` is not trashed by the
1665 // read barrier emitted by GenerateFieldLoadWithBakerReadBarrier below.
1666 // /* HeapReference<Class> */ temp2 = src->klass_
1667 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1668 invoke, temp2_loc, src, class_offset, temp3_loc, /* needs_null_check */ false);
1669 // Note: if heap poisoning is on, we are comparing two unpoisoned references here.
1670 __ cmp(temp1, ShifterOperand(temp2));
1671
1672 if (optimizations.GetDestinationIsTypedObjectArray()) {
1673 Label do_copy;
1674 __ b(&do_copy, EQ);
1675 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1676 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1677 invoke, temp1_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1678 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1679 // We do not need to emit a read barrier for the following
1680 // heap reference load, as `temp1` is only used in a
1681 // comparison with null below, and this reference is not
1682 // kept afterwards.
1683 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1684 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1685 __ Bind(&do_copy);
1686 } else {
1687 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1688 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001689 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001690 // Non read barrier code.
1691
1692 // /* HeapReference<Class> */ temp1 = dest->klass_
1693 __ LoadFromOffset(kLoadWord, temp1, dest, class_offset);
1694 // /* HeapReference<Class> */ temp2 = src->klass_
1695 __ LoadFromOffset(kLoadWord, temp2, src, class_offset);
1696 bool did_unpoison = false;
1697 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
1698 !optimizations.GetSourceIsNonPrimitiveArray()) {
1699 // One or two of the references need to be unpoisoned. Unpoison them
1700 // both to make the identity check valid.
1701 __ MaybeUnpoisonHeapReference(temp1);
1702 __ MaybeUnpoisonHeapReference(temp2);
1703 did_unpoison = true;
1704 }
1705
1706 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1707 // Bail out if the destination is not a non primitive array.
1708 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1709 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1710 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1711 __ MaybeUnpoisonHeapReference(temp3);
1712 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1713 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1714 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1715 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1716 }
1717
1718 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1719 // Bail out if the source is not a non primitive array.
1720 // /* HeapReference<Class> */ temp3 = temp2->component_type_
1721 __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset);
1722 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1723 __ MaybeUnpoisonHeapReference(temp3);
1724 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
1725 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1726 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1727 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
1728 }
1729
1730 __ cmp(temp1, ShifterOperand(temp2));
1731
1732 if (optimizations.GetDestinationIsTypedObjectArray()) {
1733 Label do_copy;
1734 __ b(&do_copy, EQ);
1735 if (!did_unpoison) {
1736 __ MaybeUnpoisonHeapReference(temp1);
1737 }
1738 // /* HeapReference<Class> */ temp1 = temp1->component_type_
1739 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
1740 __ MaybeUnpoisonHeapReference(temp1);
1741 // /* HeapReference<Class> */ temp1 = temp1->super_class_
1742 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1743 // No need to unpoison the result, we're comparing against null.
1744 __ CompareAndBranchIfNonZero(temp1, intrinsic_slow_path->GetEntryLabel());
1745 __ Bind(&do_copy);
1746 } else {
1747 __ b(intrinsic_slow_path->GetEntryLabel(), NE);
1748 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001749 }
1750 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1751 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
1752 // Bail out if the source is not a non primitive array.
Roland Levillain0b671c02016-08-19 12:02:34 +01001753 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1754 // /* HeapReference<Class> */ temp1 = src->klass_
1755 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1756 invoke, temp1_loc, src, class_offset, temp2_loc, /* needs_null_check */ false);
1757 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1758 codegen_->GenerateFieldLoadWithBakerReadBarrier(
1759 invoke, temp3_loc, temp1, component_offset, temp2_loc, /* needs_null_check */ false);
1760 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1761 // If heap poisoning is enabled, `temp3` has been unpoisoned
1762 // by the the previous call to GenerateFieldLoadWithBakerReadBarrier.
1763 } else {
1764 // /* HeapReference<Class> */ temp1 = src->klass_
1765 __ LoadFromOffset(kLoadWord, temp1, src, class_offset);
1766 __ MaybeUnpoisonHeapReference(temp1);
1767 // /* HeapReference<Class> */ temp3 = temp1->component_type_
1768 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1769 __ CompareAndBranchIfZero(temp3, intrinsic_slow_path->GetEntryLabel());
1770 __ MaybeUnpoisonHeapReference(temp3);
1771 }
1772 // /* uint16_t */ temp3 = static_cast<uint16>(temp3->primitive_type_);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001773 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1774 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
Roland Levillain0b671c02016-08-19 12:02:34 +01001775 __ CompareAndBranchIfNonZero(temp3, intrinsic_slow_path->GetEntryLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001776 }
1777
Nicolas Geoffrayfea1abd2016-07-06 12:09:12 +01001778 int32_t element_size = Primitive::ComponentSize(Primitive::kPrimNot);
Roland Levillain0b671c02016-08-19 12:02:34 +01001779 uint32_t element_size_shift = Primitive::ComponentSizeShift(Primitive::kPrimNot);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001780 uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value();
Roland Levillain0b671c02016-08-19 12:02:34 +01001781
1782 // Compute the base source address in `temp1`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001783 if (src_pos.IsConstant()) {
1784 int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1785 __ AddConstant(temp1, src, element_size * constant + offset);
1786 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001787 __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001788 __ AddConstant(temp1, offset);
1789 }
1790
Roland Levillain0b671c02016-08-19 12:02:34 +01001791 // Compute the end source address in `temp3`.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001792 if (length.IsConstant()) {
1793 int32_t constant = length.GetConstant()->AsIntConstant()->GetValue();
1794 __ AddConstant(temp3, temp1, element_size * constant);
1795 } else {
Roland Levillain0b671c02016-08-19 12:02:34 +01001796 __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, element_size_shift));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001797 }
1798
Roland Levillain0b671c02016-08-19 12:02:34 +01001799 if (kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
1800 // The base destination address is computed later, as `temp2` is
1801 // used for intermediate computations.
1802
1803 // SystemArrayCopy implementation for Baker read barriers (see
1804 // also CodeGeneratorARM::GenerateReferenceLoadWithBakerReadBarrier):
1805 //
1806 // if (src_ptr != end_ptr) {
1807 // uint32_t rb_state = Lockword(src->monitor_).ReadBarrierState();
1808 // lfence; // Load fence or artificial data dependency to prevent load-load reordering
1809 // bool is_gray = (rb_state == ReadBarrier::gray_ptr_);
1810 // if (is_gray) {
1811 // // Slow-path copy.
1812 // do {
1813 // *dest_ptr++ = MaybePoison(ReadBarrier::Mark(MaybeUnpoison(*src_ptr++)));
1814 // } while (src_ptr != end_ptr)
1815 // } else {
1816 // // Fast-path copy.
1817 // do {
1818 // *dest_ptr++ = *src_ptr++;
1819 // } while (src_ptr != end_ptr)
1820 // }
1821 // }
1822
1823 Label loop, done;
1824
1825 // Don't enter copy loop if `length == 0`.
1826 __ cmp(temp1, ShifterOperand(temp3));
1827 __ b(&done, EQ);
1828
1829 // /* int32_t */ monitor = src->monitor_
1830 __ LoadFromOffset(kLoadWord, temp2, src, monitor_offset);
1831 // /* LockWord */ lock_word = LockWord(monitor)
1832 static_assert(sizeof(LockWord) == sizeof(int32_t),
1833 "art::LockWord and int32_t have different sizes.");
1834
1835 // Introduce a dependency on the lock_word including the rb_state,
1836 // which shall prevent load-load reordering without using
1837 // a memory barrier (which would be more expensive).
1838 // `src` is unchanged by this operation, but its value now depends
1839 // on `temp2`.
1840 __ add(src, src, ShifterOperand(temp2, LSR, 32));
1841
1842 // Slow path used to copy array when `src` is gray.
1843 SlowPathCode* read_barrier_slow_path =
1844 new (GetAllocator()) ReadBarrierSystemArrayCopySlowPathARM(invoke);
1845 codegen_->AddSlowPath(read_barrier_slow_path);
1846
1847 // Given the numeric representation, it's enough to check the low bit of the
1848 // rb_state. We do that by shifting the bit out of the lock word with LSRS
1849 // which can be a 16-bit instruction unlike the TST immediate.
1850 static_assert(ReadBarrier::white_ptr_ == 0, "Expecting white to have value 0");
1851 static_assert(ReadBarrier::gray_ptr_ == 1, "Expecting gray to have value 1");
1852 static_assert(ReadBarrier::black_ptr_ == 2, "Expecting black to have value 2");
1853 __ Lsrs(temp2, temp2, LockWord::kReadBarrierStateShift + 1);
1854 // Carry flag is the last bit shifted out by LSRS.
1855 __ b(read_barrier_slow_path->GetEntryLabel(), CS);
1856
1857 // Fast-path copy.
1858
1859 // Compute the base destination address in `temp2`.
1860 if (dest_pos.IsConstant()) {
1861 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1862 __ AddConstant(temp2, dest, element_size * constant + offset);
1863 } else {
1864 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1865 __ AddConstant(temp2, offset);
1866 }
1867
1868 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1869 // poison/unpoison.
1870 __ Bind(&loop);
1871 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1872 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1873 __ cmp(temp1, ShifterOperand(temp3));
1874 __ b(&loop, NE);
1875
1876 __ Bind(read_barrier_slow_path->GetExitLabel());
1877 __ Bind(&done);
1878 } else {
1879 // Non read barrier code.
1880
1881 // Compute the base destination address in `temp2`.
1882 if (dest_pos.IsConstant()) {
1883 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1884 __ AddConstant(temp2, dest, element_size * constant + offset);
1885 } else {
1886 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, element_size_shift));
1887 __ AddConstant(temp2, offset);
1888 }
1889
1890 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1891 // poison/unpoison.
1892 Label loop, done;
1893 __ cmp(temp1, ShifterOperand(temp3));
1894 __ b(&done, EQ);
1895 __ Bind(&loop);
1896 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1897 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1898 __ cmp(temp1, ShifterOperand(temp3));
1899 __ b(&loop, NE);
1900 __ Bind(&done);
1901 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001902
1903 // We only need one card marking on the destination array.
1904 codegen_->MarkGCCard(temp1,
1905 temp2,
1906 dest,
1907 Register(kNoRegister),
Roland Levillainebea3d22016-04-12 15:42:57 +01001908 /* value_can_be_null */ false);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001909
Roland Levillain0b671c02016-08-19 12:02:34 +01001910 __ Bind(intrinsic_slow_path->GetExitLabel());
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001911}
1912
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001913static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1914 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1915 // the code generator. Furthermore, the register allocator creates fixed live intervals
1916 // for all caller-saved registers because we are doing a function call. As a result, if
1917 // the input and output locations are unallocated, the register allocator runs out of
1918 // registers and fails; however, a debuggable graph is not the common case.
1919 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1920 return;
1921 }
1922
1923 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1924 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1925 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1926
1927 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001928 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001929 kIntrinsified);
1930 const InvokeRuntimeCallingConvention calling_convention;
1931
1932 locations->SetInAt(0, Location::RequiresFpuRegister());
1933 locations->SetOut(Location::RequiresFpuRegister());
1934 // Native code uses the soft float ABI.
1935 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1936 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1937}
1938
1939static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1940 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1941 // the code generator. Furthermore, the register allocator creates fixed live intervals
1942 // for all caller-saved registers because we are doing a function call. As a result, if
1943 // the input and output locations are unallocated, the register allocator runs out of
1944 // registers and fails; however, a debuggable graph is not the common case.
1945 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1946 return;
1947 }
1948
1949 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1950 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1951 DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble);
1952 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1953
1954 LocationSummary* const locations = new (arena) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01001955 LocationSummary::kCallOnMainOnly,
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001956 kIntrinsified);
1957 const InvokeRuntimeCallingConvention calling_convention;
1958
1959 locations->SetInAt(0, Location::RequiresFpuRegister());
1960 locations->SetInAt(1, Location::RequiresFpuRegister());
1961 locations->SetOut(Location::RequiresFpuRegister());
1962 // Native code uses the soft float ABI.
1963 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1964 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1965 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1966 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1967}
1968
1969static void GenFPToFPCall(HInvoke* invoke,
1970 ArmAssembler* assembler,
1971 CodeGeneratorARM* codegen,
1972 QuickEntrypointEnum entry) {
1973 LocationSummary* const locations = invoke->GetLocations();
1974 const InvokeRuntimeCallingConvention calling_convention;
1975
1976 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1977 DCHECK(locations->WillCall() && locations->Intrinsified());
1978 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
1979 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
1980
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001981 // Native code uses the soft float ABI.
1982 __ vmovrrd(calling_convention.GetRegisterAt(0),
1983 calling_convention.GetRegisterAt(1),
1984 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01001985 codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001986 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
1987 calling_convention.GetRegisterAt(0),
1988 calling_convention.GetRegisterAt(1));
1989}
1990
1991static void GenFPFPToFPCall(HInvoke* invoke,
1992 ArmAssembler* assembler,
1993 CodeGeneratorARM* codegen,
1994 QuickEntrypointEnum entry) {
1995 LocationSummary* const locations = invoke->GetLocations();
1996 const InvokeRuntimeCallingConvention calling_convention;
1997
1998 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1999 DCHECK(locations->WillCall() && locations->Intrinsified());
2000 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
2001 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
2002 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2)));
2003 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3)));
2004
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00002005 // Native code uses the soft float ABI.
2006 __ vmovrrd(calling_convention.GetRegisterAt(0),
2007 calling_convention.GetRegisterAt(1),
2008 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2009 __ vmovrrd(calling_convention.GetRegisterAt(2),
2010 calling_convention.GetRegisterAt(3),
2011 FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()));
Serban Constantinescu4bb30ac2016-06-22 17:04:45 +01002012 codegen->InvokeRuntime(entry, invoke, invoke->GetDexPc());
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00002013 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
2014 calling_convention.GetRegisterAt(0),
2015 calling_convention.GetRegisterAt(1));
2016}
2017
2018void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) {
2019 CreateFPToFPCallLocations(arena_, invoke);
2020}
2021
2022void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) {
2023 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos);
2024}
2025
2026void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) {
2027 CreateFPToFPCallLocations(arena_, invoke);
2028}
2029
2030void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) {
2031 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin);
2032}
2033
2034void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) {
2035 CreateFPToFPCallLocations(arena_, invoke);
2036}
2037
2038void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) {
2039 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos);
2040}
2041
2042void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) {
2043 CreateFPToFPCallLocations(arena_, invoke);
2044}
2045
2046void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) {
2047 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin);
2048}
2049
2050void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) {
2051 CreateFPToFPCallLocations(arena_, invoke);
2052}
2053
2054void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) {
2055 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan);
2056}
2057
2058void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) {
2059 CreateFPToFPCallLocations(arena_, invoke);
2060}
2061
2062void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) {
2063 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt);
2064}
2065
2066void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) {
2067 CreateFPToFPCallLocations(arena_, invoke);
2068}
2069
2070void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) {
2071 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh);
2072}
2073
2074void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) {
2075 CreateFPToFPCallLocations(arena_, invoke);
2076}
2077
2078void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) {
2079 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp);
2080}
2081
2082void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) {
2083 CreateFPToFPCallLocations(arena_, invoke);
2084}
2085
2086void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) {
2087 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1);
2088}
2089
2090void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) {
2091 CreateFPToFPCallLocations(arena_, invoke);
2092}
2093
2094void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) {
2095 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog);
2096}
2097
2098void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) {
2099 CreateFPToFPCallLocations(arena_, invoke);
2100}
2101
2102void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) {
2103 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10);
2104}
2105
2106void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) {
2107 CreateFPToFPCallLocations(arena_, invoke);
2108}
2109
2110void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) {
2111 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh);
2112}
2113
2114void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) {
2115 CreateFPToFPCallLocations(arena_, invoke);
2116}
2117
2118void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) {
2119 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan);
2120}
2121
2122void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) {
2123 CreateFPToFPCallLocations(arena_, invoke);
2124}
2125
2126void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) {
2127 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh);
2128}
2129
2130void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) {
2131 CreateFPFPToFPCallLocations(arena_, invoke);
2132}
2133
2134void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) {
2135 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2);
2136}
2137
2138void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) {
2139 CreateFPFPToFPCallLocations(arena_, invoke);
2140}
2141
2142void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) {
2143 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot);
2144}
2145
2146void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) {
2147 CreateFPFPToFPCallLocations(arena_, invoke);
2148}
2149
2150void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) {
2151 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter);
2152}
2153
Artem Serovc257da72016-02-02 13:49:43 +00002154void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) {
2155 CreateIntToIntLocations(arena_, invoke);
2156}
2157
2158void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) {
2159 ArmAssembler* assembler = GetAssembler();
2160 LocationSummary* locations = invoke->GetLocations();
2161
2162 Register out = locations->Out().AsRegister<Register>();
2163 Register in = locations->InAt(0).AsRegister<Register>();
2164
2165 __ rbit(out, in);
2166}
2167
2168void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) {
2169 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2170 LocationSummary::kNoCall,
2171 kIntrinsified);
2172 locations->SetInAt(0, Location::RequiresRegister());
2173 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2174}
2175
2176void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) {
2177 ArmAssembler* assembler = GetAssembler();
2178 LocationSummary* locations = invoke->GetLocations();
2179
2180 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2181 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2182 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2183 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2184
2185 __ rbit(out_reg_lo, in_reg_hi);
2186 __ rbit(out_reg_hi, in_reg_lo);
2187}
2188
2189void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2190 CreateIntToIntLocations(arena_, invoke);
2191}
2192
2193void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) {
2194 ArmAssembler* assembler = GetAssembler();
2195 LocationSummary* locations = invoke->GetLocations();
2196
2197 Register out = locations->Out().AsRegister<Register>();
2198 Register in = locations->InAt(0).AsRegister<Register>();
2199
2200 __ rev(out, in);
2201}
2202
2203void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) {
2204 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2205 LocationSummary::kNoCall,
2206 kIntrinsified);
2207 locations->SetInAt(0, Location::RequiresRegister());
2208 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2209}
2210
2211void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) {
2212 ArmAssembler* assembler = GetAssembler();
2213 LocationSummary* locations = invoke->GetLocations();
2214
2215 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2216 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2217 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2218 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2219
2220 __ rev(out_reg_lo, in_reg_hi);
2221 __ rev(out_reg_hi, in_reg_lo);
2222}
2223
2224void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) {
2225 CreateIntToIntLocations(arena_, invoke);
2226}
2227
2228void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) {
2229 ArmAssembler* assembler = GetAssembler();
2230 LocationSummary* locations = invoke->GetLocations();
2231
2232 Register out = locations->Out().AsRegister<Register>();
2233 Register in = locations->InAt(0).AsRegister<Register>();
2234
2235 __ revsh(out, in);
2236}
2237
xueliang.zhongf1073c82016-07-05 15:28:19 +01002238static void GenBitCount(HInvoke* instr, Primitive::Type type, ArmAssembler* assembler) {
2239 DCHECK(Primitive::IsIntOrLongType(type)) << type;
2240 DCHECK_EQ(instr->GetType(), Primitive::kPrimInt);
2241 DCHECK_EQ(Primitive::PrimitiveKind(instr->InputAt(0)->GetType()), type);
2242
2243 bool is_long = type == Primitive::kPrimLong;
2244 LocationSummary* locations = instr->GetLocations();
2245 Location in = locations->InAt(0);
2246 Register src_0 = is_long ? in.AsRegisterPairLow<Register>() : in.AsRegister<Register>();
2247 Register src_1 = is_long ? in.AsRegisterPairHigh<Register>() : src_0;
2248 SRegister tmp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
2249 DRegister tmp_d = FromLowSToD(tmp_s);
2250 Register out_r = locations->Out().AsRegister<Register>();
2251
2252 // Move data from core register(s) to temp D-reg for bit count calculation, then move back.
2253 // According to Cortex A57 and A72 optimization guides, compared to transferring to full D-reg,
2254 // transferring data from core reg to upper or lower half of vfp D-reg requires extra latency,
2255 // That's why for integer bit count, we use 'vmov d0, r0, r0' instead of 'vmov d0[0], r0'.
2256 __ vmovdrr(tmp_d, src_1, src_0); // Temp DReg |--src_1|--src_0|
2257 __ vcntd(tmp_d, tmp_d); // Temp DReg |c|c|c|c|c|c|c|c|
2258 __ vpaddld(tmp_d, tmp_d, 8, /* is_unsigned */ true); // Temp DReg |--c|--c|--c|--c|
2259 __ vpaddld(tmp_d, tmp_d, 16, /* is_unsigned */ true); // Temp DReg |------c|------c|
2260 if (is_long) {
2261 __ vpaddld(tmp_d, tmp_d, 32, /* is_unsigned */ true); // Temp DReg |--------------c|
2262 }
2263 __ vmovrs(out_r, tmp_s);
2264}
2265
2266void IntrinsicLocationsBuilderARM::VisitIntegerBitCount(HInvoke* invoke) {
2267 CreateIntToIntLocations(arena_, invoke);
2268 invoke->GetLocations()->AddTemp(Location::RequiresFpuRegister());
2269}
2270
2271void IntrinsicCodeGeneratorARM::VisitIntegerBitCount(HInvoke* invoke) {
2272 GenBitCount(invoke, Primitive::kPrimInt, GetAssembler());
2273}
2274
2275void IntrinsicLocationsBuilderARM::VisitLongBitCount(HInvoke* invoke) {
2276 VisitIntegerBitCount(invoke);
2277}
2278
2279void IntrinsicCodeGeneratorARM::VisitLongBitCount(HInvoke* invoke) {
2280 GenBitCount(invoke, Primitive::kPrimLong, GetAssembler());
2281}
2282
Tim Zhang25abd6c2016-01-19 23:39:24 +08002283void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2284 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2285 LocationSummary::kNoCall,
2286 kIntrinsified);
2287 locations->SetInAt(0, Location::RequiresRegister());
2288 locations->SetInAt(1, Location::RequiresRegister());
2289 locations->SetInAt(2, Location::RequiresRegister());
2290 locations->SetInAt(3, Location::RequiresRegister());
2291 locations->SetInAt(4, Location::RequiresRegister());
2292
Scott Wakeling3fdab772016-04-25 11:32:37 +01002293 // Temporary registers to store lengths of strings and for calculations.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002294 locations->AddTemp(Location::RequiresRegister());
2295 locations->AddTemp(Location::RequiresRegister());
2296 locations->AddTemp(Location::RequiresRegister());
2297}
2298
2299void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2300 ArmAssembler* assembler = GetAssembler();
2301 LocationSummary* locations = invoke->GetLocations();
2302
2303 // Check assumption that sizeof(Char) is 2 (used in scaling below).
2304 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
2305 DCHECK_EQ(char_size, 2u);
2306
2307 // Location of data in char array buffer.
2308 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
2309
2310 // Location of char array data in string.
2311 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
2312
2313 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
2314 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
2315 Register srcObj = locations->InAt(0).AsRegister<Register>();
2316 Register srcBegin = locations->InAt(1).AsRegister<Register>();
2317 Register srcEnd = locations->InAt(2).AsRegister<Register>();
2318 Register dstObj = locations->InAt(3).AsRegister<Register>();
2319 Register dstBegin = locations->InAt(4).AsRegister<Register>();
2320
Scott Wakeling3fdab772016-04-25 11:32:37 +01002321 Register num_chr = locations->GetTemp(0).AsRegister<Register>();
2322 Register src_ptr = locations->GetTemp(1).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002323 Register dst_ptr = locations->GetTemp(2).AsRegister<Register>();
Tim Zhang25abd6c2016-01-19 23:39:24 +08002324
2325 // src range to copy.
2326 __ add(src_ptr, srcObj, ShifterOperand(value_offset));
Tim Zhang25abd6c2016-01-19 23:39:24 +08002327 __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1));
2328
2329 // dst to be copied.
2330 __ add(dst_ptr, dstObj, ShifterOperand(data_offset));
2331 __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1));
2332
Scott Wakeling3fdab772016-04-25 11:32:37 +01002333 __ subs(num_chr, srcEnd, ShifterOperand(srcBegin));
2334
Tim Zhang25abd6c2016-01-19 23:39:24 +08002335 // Do the copy.
Scott Wakeling3fdab772016-04-25 11:32:37 +01002336 Label loop, remainder, done;
2337
2338 // Early out for valid zero-length retrievals.
Tim Zhang25abd6c2016-01-19 23:39:24 +08002339 __ b(&done, EQ);
Scott Wakeling3fdab772016-04-25 11:32:37 +01002340
2341 // Save repairing the value of num_chr on the < 4 character path.
2342 __ subs(IP, num_chr, ShifterOperand(4));
2343 __ b(&remainder, LT);
2344
2345 // Keep the result of the earlier subs, we are going to fetch at least 4 characters.
2346 __ mov(num_chr, ShifterOperand(IP));
2347
2348 // Main loop used for longer fetches loads and stores 4x16-bit characters at a time.
2349 // (LDRD/STRD fault on unaligned addresses and it's not worth inlining extra code
2350 // to rectify these everywhere this intrinsic applies.)
2351 __ Bind(&loop);
2352 __ ldr(IP, Address(src_ptr, char_size * 2));
2353 __ subs(num_chr, num_chr, ShifterOperand(4));
2354 __ str(IP, Address(dst_ptr, char_size * 2));
2355 __ ldr(IP, Address(src_ptr, char_size * 4, Address::PostIndex));
2356 __ str(IP, Address(dst_ptr, char_size * 4, Address::PostIndex));
2357 __ b(&loop, GE);
2358
2359 __ adds(num_chr, num_chr, ShifterOperand(4));
2360 __ b(&done, EQ);
2361
2362 // Main loop for < 4 character case and remainder handling. Loads and stores one
2363 // 16-bit Java character at a time.
2364 __ Bind(&remainder);
2365 __ ldrh(IP, Address(src_ptr, char_size, Address::PostIndex));
2366 __ subs(num_chr, num_chr, ShifterOperand(1));
2367 __ strh(IP, Address(dst_ptr, char_size, Address::PostIndex));
2368 __ b(&remainder, GT);
2369
Tim Zhang25abd6c2016-01-19 23:39:24 +08002370 __ Bind(&done);
2371}
2372
Anton Kirilova3ffea22016-04-07 17:02:37 +01002373void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) {
2374 CreateFPToIntLocations(arena_, invoke);
2375}
2376
2377void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) {
2378 ArmAssembler* const assembler = GetAssembler();
2379 LocationSummary* const locations = invoke->GetLocations();
2380 const Register out = locations->Out().AsRegister<Register>();
2381 // Shifting left by 1 bit makes the value encodable as an immediate operand;
2382 // we don't care about the sign bit anyway.
2383 constexpr uint32_t infinity = kPositiveInfinityFloat << 1U;
2384
2385 __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>());
2386 // We don't care about the sign bit, so shift left.
2387 __ Lsl(out, out, 1);
2388 __ eor(out, out, ShifterOperand(infinity));
2389 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2390 __ clz(out, out);
2391 // Any number less than 32 logically shifted right by 5 bits results in 0;
2392 // the same operation on 32 yields 1.
2393 __ Lsr(out, out, 5);
2394}
2395
2396void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2397 CreateFPToIntLocations(arena_, invoke);
2398}
2399
2400void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2401 ArmAssembler* const assembler = GetAssembler();
2402 LocationSummary* const locations = invoke->GetLocations();
2403 const Register out = locations->Out().AsRegister<Register>();
2404 // The highest 32 bits of double precision positive infinity separated into
2405 // two constants encodable as immediate operands.
2406 constexpr uint32_t infinity_high = 0x7f000000U;
2407 constexpr uint32_t infinity_high2 = 0x00f00000U;
2408
2409 static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U),
2410 "The constants do not add up to the high 32 bits of double precision positive infinity.");
2411 __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2412 __ eor(out, out, ShifterOperand(infinity_high));
2413 __ eor(out, out, ShifterOperand(infinity_high2));
2414 // We don't care about the sign bit, so shift left.
2415 __ orr(out, IP, ShifterOperand(out, LSL, 1));
2416 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2417 __ clz(out, out);
2418 // Any number less than 32 logically shifted right by 5 bits results in 0;
2419 // the same operation on 32 yields 1.
2420 __ Lsr(out, out, 5);
2421}
2422
Aart Bik2f9fcc92016-03-01 15:16:54 -08002423UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble)
2424UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat)
2425UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble)
2426UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat)
2427UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong)
2428UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong)
2429UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe?
2430UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe?
2431UNIMPLEMENTED_INTRINSIC(ARM, MathRint)
2432UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe?
2433UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe?
2434UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure.
2435UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar)
2436UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002437UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit)
2438UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit)
2439UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit)
2440UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit)
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002441
Aart Bik0e54c012016-03-04 12:08:31 -08002442// 1.8.
2443UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt)
2444UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong)
2445UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt)
2446UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong)
2447UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject)
Aart Bik0e54c012016-03-04 12:08:31 -08002448
Aart Bik2f9fcc92016-03-01 15:16:54 -08002449UNREACHABLE_INTRINSICS(ARM)
Roland Levillain4d027112015-07-01 15:41:14 +01002450
2451#undef __
2452
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002453} // namespace arm
2454} // namespace art