blob: 29f7672b0ae910f4d730a48fe71738873db31e82 [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
44bool IntrinsicLocationsBuilderARM::TryDispatch(HInvoke* invoke) {
45 Dispatch(invoke);
46 LocationSummary* res = invoke->GetLocations();
Roland Levillain3b359c72015-11-17 19:35:12 +000047 if (res == nullptr) {
48 return false;
49 }
50 if (kEmitCompilerReadBarrier && res->CanCall()) {
51 // Generating an intrinsic for this HInvoke may produce an
52 // IntrinsicSlowPathARM slow path. Currently this approach
53 // does not work when using read barriers, as the emitted
54 // calling sequence will make use of another slow path
55 // (ReadBarrierForRootSlowPathARM for HInvokeStaticOrDirect,
56 // ReadBarrierSlowPathARM for HInvokeVirtual). So we bail
57 // out in this case.
58 //
59 // TODO: Find a way to have intrinsics work with read barriers.
60 invoke->SetLocations(nullptr);
61 return false;
62 }
63 return res->Intrinsified();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -080064}
65
66#define __ assembler->
67
68static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
69 LocationSummary* locations = new (arena) LocationSummary(invoke,
70 LocationSummary::kNoCall,
71 kIntrinsified);
72 locations->SetInAt(0, Location::RequiresFpuRegister());
73 locations->SetOut(Location::RequiresRegister());
74}
75
76static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
77 LocationSummary* locations = new (arena) LocationSummary(invoke,
78 LocationSummary::kNoCall,
79 kIntrinsified);
80 locations->SetInAt(0, Location::RequiresRegister());
81 locations->SetOut(Location::RequiresFpuRegister());
82}
83
84static void MoveFPToInt(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
85 Location input = locations->InAt(0);
86 Location output = locations->Out();
87 if (is64bit) {
88 __ vmovrrd(output.AsRegisterPairLow<Register>(),
89 output.AsRegisterPairHigh<Register>(),
90 FromLowSToD(input.AsFpuRegisterPairLow<SRegister>()));
91 } else {
92 __ vmovrs(output.AsRegister<Register>(), input.AsFpuRegister<SRegister>());
93 }
94}
95
96static void MoveIntToFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
97 Location input = locations->InAt(0);
98 Location output = locations->Out();
99 if (is64bit) {
100 __ vmovdrr(FromLowSToD(output.AsFpuRegisterPairLow<SRegister>()),
101 input.AsRegisterPairLow<Register>(),
102 input.AsRegisterPairHigh<Register>());
103 } else {
104 __ vmovsr(output.AsFpuRegister<SRegister>(), input.AsRegister<Register>());
105 }
106}
107
108void IntrinsicLocationsBuilderARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
109 CreateFPToIntLocations(arena_, invoke);
110}
111void IntrinsicLocationsBuilderARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
112 CreateIntToFPLocations(arena_, invoke);
113}
114
115void IntrinsicCodeGeneratorARM::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000116 MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800117}
118void IntrinsicCodeGeneratorARM::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000119 MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800120}
121
122void IntrinsicLocationsBuilderARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
123 CreateFPToIntLocations(arena_, invoke);
124}
125void IntrinsicLocationsBuilderARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
126 CreateIntToFPLocations(arena_, invoke);
127}
128
129void IntrinsicCodeGeneratorARM::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000130 MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800131}
132void IntrinsicCodeGeneratorARM::VisitFloatIntBitsToFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000133 MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800134}
135
136static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
137 LocationSummary* locations = new (arena) LocationSummary(invoke,
138 LocationSummary::kNoCall,
139 kIntrinsified);
140 locations->SetInAt(0, Location::RequiresRegister());
141 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
142}
143
144static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
145 LocationSummary* locations = new (arena) LocationSummary(invoke,
146 LocationSummary::kNoCall,
147 kIntrinsified);
148 locations->SetInAt(0, Location::RequiresFpuRegister());
149 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
150}
151
Scott Wakeling611d3392015-07-10 11:42:06 +0100152static void GenNumberOfLeadingZeros(LocationSummary* locations,
153 Primitive::Type type,
154 ArmAssembler* assembler) {
155 Location in = locations->InAt(0);
156 Register out = locations->Out().AsRegister<Register>();
157
158 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
159
160 if (type == Primitive::kPrimLong) {
161 Register in_reg_lo = in.AsRegisterPairLow<Register>();
162 Register in_reg_hi = in.AsRegisterPairHigh<Register>();
163 Label end;
164 __ clz(out, in_reg_hi);
165 __ CompareAndBranchIfNonZero(in_reg_hi, &end);
166 __ clz(out, in_reg_lo);
167 __ AddConstant(out, 32);
168 __ Bind(&end);
169 } else {
170 __ clz(out, in.AsRegister<Register>());
171 }
172}
173
174void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
175 CreateIntToIntLocations(arena_, invoke);
176}
177
178void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
179 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
180}
181
182void IntrinsicLocationsBuilderARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
183 LocationSummary* locations = new (arena_) LocationSummary(invoke,
184 LocationSummary::kNoCall,
185 kIntrinsified);
186 locations->SetInAt(0, Location::RequiresRegister());
187 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
188}
189
190void IntrinsicCodeGeneratorARM::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
191 GenNumberOfLeadingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
192}
193
Scott Wakeling9ee23f42015-07-23 10:44:35 +0100194static void GenNumberOfTrailingZeros(LocationSummary* locations,
195 Primitive::Type type,
196 ArmAssembler* assembler) {
197 DCHECK((type == Primitive::kPrimInt) || (type == Primitive::kPrimLong));
198
199 Register out = locations->Out().AsRegister<Register>();
200
201 if (type == Primitive::kPrimLong) {
202 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
203 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
204 Label end;
205 __ rbit(out, in_reg_lo);
206 __ clz(out, out);
207 __ CompareAndBranchIfNonZero(in_reg_lo, &end);
208 __ rbit(out, in_reg_hi);
209 __ clz(out, out);
210 __ AddConstant(out, 32);
211 __ Bind(&end);
212 } else {
213 Register in = locations->InAt(0).AsRegister<Register>();
214 __ rbit(out, in);
215 __ clz(out, out);
216 }
217}
218
219void IntrinsicLocationsBuilderARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
220 LocationSummary* locations = new (arena_) LocationSummary(invoke,
221 LocationSummary::kNoCall,
222 kIntrinsified);
223 locations->SetInAt(0, Location::RequiresRegister());
224 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
225}
226
227void IntrinsicCodeGeneratorARM::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
228 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
229}
230
231void IntrinsicLocationsBuilderARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
232 LocationSummary* locations = new (arena_) LocationSummary(invoke,
233 LocationSummary::kNoCall,
234 kIntrinsified);
235 locations->SetInAt(0, Location::RequiresRegister());
236 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
237}
238
239void IntrinsicCodeGeneratorARM::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
240 GenNumberOfTrailingZeros(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
241}
242
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800243static void MathAbsFP(LocationSummary* locations, bool is64bit, ArmAssembler* assembler) {
244 Location in = locations->InAt(0);
245 Location out = locations->Out();
246
247 if (is64bit) {
248 __ vabsd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
249 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
250 } else {
251 __ vabss(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
252 }
253}
254
255void IntrinsicLocationsBuilderARM::VisitMathAbsDouble(HInvoke* invoke) {
256 CreateFPToFPLocations(arena_, invoke);
257}
258
259void IntrinsicCodeGeneratorARM::VisitMathAbsDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000260 MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800261}
262
263void IntrinsicLocationsBuilderARM::VisitMathAbsFloat(HInvoke* invoke) {
264 CreateFPToFPLocations(arena_, invoke);
265}
266
267void IntrinsicCodeGeneratorARM::VisitMathAbsFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000268 MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800269}
270
271static void CreateIntToIntPlusTemp(ArenaAllocator* arena, HInvoke* invoke) {
272 LocationSummary* locations = new (arena) LocationSummary(invoke,
273 LocationSummary::kNoCall,
274 kIntrinsified);
275 locations->SetInAt(0, Location::RequiresRegister());
276 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
277
278 locations->AddTemp(Location::RequiresRegister());
279}
280
281static void GenAbsInteger(LocationSummary* locations,
282 bool is64bit,
283 ArmAssembler* assembler) {
284 Location in = locations->InAt(0);
285 Location output = locations->Out();
286
287 Register mask = locations->GetTemp(0).AsRegister<Register>();
288
289 if (is64bit) {
290 Register in_reg_lo = in.AsRegisterPairLow<Register>();
291 Register in_reg_hi = in.AsRegisterPairHigh<Register>();
292 Register out_reg_lo = output.AsRegisterPairLow<Register>();
293 Register out_reg_hi = output.AsRegisterPairHigh<Register>();
294
295 DCHECK_NE(out_reg_lo, in_reg_hi) << "Diagonal overlap unexpected.";
296
297 __ Asr(mask, in_reg_hi, 31);
298 __ adds(out_reg_lo, in_reg_lo, ShifterOperand(mask));
299 __ adc(out_reg_hi, in_reg_hi, ShifterOperand(mask));
300 __ eor(out_reg_lo, mask, ShifterOperand(out_reg_lo));
301 __ eor(out_reg_hi, mask, ShifterOperand(out_reg_hi));
302 } else {
303 Register in_reg = in.AsRegister<Register>();
304 Register out_reg = output.AsRegister<Register>();
305
306 __ Asr(mask, in_reg, 31);
307 __ add(out_reg, in_reg, ShifterOperand(mask));
308 __ eor(out_reg, mask, ShifterOperand(out_reg));
309 }
310}
311
312void IntrinsicLocationsBuilderARM::VisitMathAbsInt(HInvoke* invoke) {
313 CreateIntToIntPlusTemp(arena_, invoke);
314}
315
316void IntrinsicCodeGeneratorARM::VisitMathAbsInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000317 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800318}
319
320
321void IntrinsicLocationsBuilderARM::VisitMathAbsLong(HInvoke* invoke) {
322 CreateIntToIntPlusTemp(arena_, invoke);
323}
324
325void IntrinsicCodeGeneratorARM::VisitMathAbsLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000326 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800327}
328
329static void GenMinMax(LocationSummary* locations,
330 bool is_min,
331 ArmAssembler* assembler) {
332 Register op1 = locations->InAt(0).AsRegister<Register>();
333 Register op2 = locations->InAt(1).AsRegister<Register>();
334 Register out = locations->Out().AsRegister<Register>();
335
336 __ cmp(op1, ShifterOperand(op2));
337
338 __ it((is_min) ? Condition::LT : Condition::GT, kItElse);
339 __ mov(out, ShifterOperand(op1), is_min ? Condition::LT : Condition::GT);
340 __ mov(out, ShifterOperand(op2), is_min ? Condition::GE : Condition::LE);
341}
342
343static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
344 LocationSummary* locations = new (arena) LocationSummary(invoke,
345 LocationSummary::kNoCall,
346 kIntrinsified);
347 locations->SetInAt(0, Location::RequiresRegister());
348 locations->SetInAt(1, Location::RequiresRegister());
349 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
350}
351
352void IntrinsicLocationsBuilderARM::VisitMathMinIntInt(HInvoke* invoke) {
353 CreateIntIntToIntLocations(arena_, invoke);
354}
355
356void IntrinsicCodeGeneratorARM::VisitMathMinIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000357 GenMinMax(invoke->GetLocations(), /* is_min */ true, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800358}
359
360void IntrinsicLocationsBuilderARM::VisitMathMaxIntInt(HInvoke* invoke) {
361 CreateIntIntToIntLocations(arena_, invoke);
362}
363
364void IntrinsicCodeGeneratorARM::VisitMathMaxIntInt(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000365 GenMinMax(invoke->GetLocations(), /* is_min */ false, GetAssembler());
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800366}
367
368void IntrinsicLocationsBuilderARM::VisitMathSqrt(HInvoke* invoke) {
369 CreateFPToFPLocations(arena_, invoke);
370}
371
372void IntrinsicCodeGeneratorARM::VisitMathSqrt(HInvoke* invoke) {
373 LocationSummary* locations = invoke->GetLocations();
374 ArmAssembler* assembler = GetAssembler();
375 __ vsqrtd(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
376 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
377}
378
379void IntrinsicLocationsBuilderARM::VisitMemoryPeekByte(HInvoke* invoke) {
380 CreateIntToIntLocations(arena_, invoke);
381}
382
383void IntrinsicCodeGeneratorARM::VisitMemoryPeekByte(HInvoke* invoke) {
384 ArmAssembler* assembler = GetAssembler();
385 // Ignore upper 4B of long address.
386 __ ldrsb(invoke->GetLocations()->Out().AsRegister<Register>(),
387 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
388}
389
390void IntrinsicLocationsBuilderARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
391 CreateIntToIntLocations(arena_, invoke);
392}
393
394void IntrinsicCodeGeneratorARM::VisitMemoryPeekIntNative(HInvoke* invoke) {
395 ArmAssembler* assembler = GetAssembler();
396 // Ignore upper 4B of long address.
397 __ ldr(invoke->GetLocations()->Out().AsRegister<Register>(),
398 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
399}
400
401void IntrinsicLocationsBuilderARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
402 CreateIntToIntLocations(arena_, invoke);
403}
404
405void IntrinsicCodeGeneratorARM::VisitMemoryPeekLongNative(HInvoke* invoke) {
406 ArmAssembler* assembler = GetAssembler();
407 // Ignore upper 4B of long address.
408 Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
409 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
410 // exception. So we can't use ldrd as addr may be unaligned.
411 Register lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>();
412 Register hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>();
413 if (addr == lo) {
414 __ ldr(hi, Address(addr, 4));
415 __ ldr(lo, Address(addr, 0));
416 } else {
417 __ ldr(lo, Address(addr, 0));
418 __ ldr(hi, Address(addr, 4));
419 }
420}
421
422void IntrinsicLocationsBuilderARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
423 CreateIntToIntLocations(arena_, invoke);
424}
425
426void IntrinsicCodeGeneratorARM::VisitMemoryPeekShortNative(HInvoke* invoke) {
427 ArmAssembler* assembler = GetAssembler();
428 // Ignore upper 4B of long address.
429 __ ldrsh(invoke->GetLocations()->Out().AsRegister<Register>(),
430 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
431}
432
433static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
434 LocationSummary* locations = new (arena) LocationSummary(invoke,
435 LocationSummary::kNoCall,
436 kIntrinsified);
437 locations->SetInAt(0, Location::RequiresRegister());
438 locations->SetInAt(1, Location::RequiresRegister());
439}
440
441void IntrinsicLocationsBuilderARM::VisitMemoryPokeByte(HInvoke* invoke) {
442 CreateIntIntToVoidLocations(arena_, invoke);
443}
444
445void IntrinsicCodeGeneratorARM::VisitMemoryPokeByte(HInvoke* invoke) {
446 ArmAssembler* assembler = GetAssembler();
447 __ strb(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
448 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
449}
450
451void IntrinsicLocationsBuilderARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
452 CreateIntIntToVoidLocations(arena_, invoke);
453}
454
455void IntrinsicCodeGeneratorARM::VisitMemoryPokeIntNative(HInvoke* invoke) {
456 ArmAssembler* assembler = GetAssembler();
457 __ str(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
458 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
459}
460
461void IntrinsicLocationsBuilderARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
462 CreateIntIntToVoidLocations(arena_, invoke);
463}
464
465void IntrinsicCodeGeneratorARM::VisitMemoryPokeLongNative(HInvoke* invoke) {
466 ArmAssembler* assembler = GetAssembler();
467 // Ignore upper 4B of long address.
468 Register addr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
469 // Worst case: Control register bit SCTLR.A = 0. Then unaligned accesses throw a processor
470 // exception. So we can't use ldrd as addr may be unaligned.
471 __ str(invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>(), Address(addr, 0));
472 __ str(invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>(), Address(addr, 4));
473}
474
475void IntrinsicLocationsBuilderARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
476 CreateIntIntToVoidLocations(arena_, invoke);
477}
478
479void IntrinsicCodeGeneratorARM::VisitMemoryPokeShortNative(HInvoke* invoke) {
480 ArmAssembler* assembler = GetAssembler();
481 __ strh(invoke->GetLocations()->InAt(1).AsRegister<Register>(),
482 Address(invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>()));
483}
484
485void IntrinsicLocationsBuilderARM::VisitThreadCurrentThread(HInvoke* invoke) {
486 LocationSummary* locations = new (arena_) LocationSummary(invoke,
487 LocationSummary::kNoCall,
488 kIntrinsified);
489 locations->SetOut(Location::RequiresRegister());
490}
491
492void IntrinsicCodeGeneratorARM::VisitThreadCurrentThread(HInvoke* invoke) {
493 ArmAssembler* assembler = GetAssembler();
494 __ LoadFromOffset(kLoadWord,
495 invoke->GetLocations()->Out().AsRegister<Register>(),
496 TR,
497 Thread::PeerOffset<kArmPointerSize>().Int32Value());
498}
499
500static void GenUnsafeGet(HInvoke* invoke,
501 Primitive::Type type,
502 bool is_volatile,
503 CodeGeneratorARM* codegen) {
504 LocationSummary* locations = invoke->GetLocations();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800505 ArmAssembler* assembler = codegen->GetAssembler();
Roland Levillain3b359c72015-11-17 19:35:12 +0000506 Location base_loc = locations->InAt(1);
507 Register base = base_loc.AsRegister<Register>(); // Object pointer.
508 Location offset_loc = locations->InAt(2);
509 Register offset = offset_loc.AsRegisterPairLow<Register>(); // Long offset, lo part only.
510 Location trg_loc = locations->Out();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800511
Roland Levillainc9285912015-12-18 10:38:42 +0000512 switch (type) {
513 case Primitive::kPrimInt: {
514 Register trg = trg_loc.AsRegister<Register>();
515 __ ldr(trg, Address(base, offset));
516 if (is_volatile) {
517 __ dmb(ISH);
518 }
519 break;
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800520 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800521
Roland Levillainc9285912015-12-18 10:38:42 +0000522 case Primitive::kPrimNot: {
523 Register trg = trg_loc.AsRegister<Register>();
524 if (kEmitCompilerReadBarrier) {
525 if (kUseBakerReadBarrier) {
526 Location temp = locations->GetTemp(0);
527 codegen->GenerateArrayLoadWithBakerReadBarrier(
528 invoke, trg_loc, base, 0U, offset_loc, temp, /* needs_null_check */ false);
529 if (is_volatile) {
530 __ dmb(ISH);
531 }
532 } else {
533 __ ldr(trg, Address(base, offset));
534 if (is_volatile) {
535 __ dmb(ISH);
536 }
537 codegen->GenerateReadBarrierSlow(invoke, trg_loc, trg_loc, base_loc, 0U, offset_loc);
538 }
539 } else {
540 __ ldr(trg, Address(base, offset));
541 if (is_volatile) {
542 __ dmb(ISH);
543 }
544 __ MaybeUnpoisonHeapReference(trg);
545 }
546 break;
547 }
Roland Levillain4d027112015-07-01 15:41:14 +0100548
Roland Levillainc9285912015-12-18 10:38:42 +0000549 case Primitive::kPrimLong: {
550 Register trg_lo = trg_loc.AsRegisterPairLow<Register>();
551 __ add(IP, base, ShifterOperand(offset));
552 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
553 Register trg_hi = trg_loc.AsRegisterPairHigh<Register>();
554 __ ldrexd(trg_lo, trg_hi, IP);
555 } else {
556 __ ldrd(trg_lo, Address(IP));
557 }
558 if (is_volatile) {
559 __ dmb(ISH);
560 }
561 break;
562 }
563
564 default:
565 LOG(FATAL) << "Unexpected type " << type;
566 UNREACHABLE();
Roland Levillain4d027112015-07-01 15:41:14 +0100567 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800568}
569
Roland Levillainc9285912015-12-18 10:38:42 +0000570static void CreateIntIntIntToIntLocations(ArenaAllocator* arena,
571 HInvoke* invoke,
572 Primitive::Type type) {
Roland Levillain3b359c72015-11-17 19:35:12 +0000573 bool can_call = kEmitCompilerReadBarrier &&
574 (invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject ||
575 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800576 LocationSummary* locations = new (arena) LocationSummary(invoke,
Roland Levillain3b359c72015-11-17 19:35:12 +0000577 can_call ?
578 LocationSummary::kCallOnSlowPath :
579 LocationSummary::kNoCall,
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800580 kIntrinsified);
581 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
582 locations->SetInAt(1, Location::RequiresRegister());
583 locations->SetInAt(2, Location::RequiresRegister());
584 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Roland Levillainc9285912015-12-18 10:38:42 +0000585 if (type == Primitive::kPrimNot && kEmitCompilerReadBarrier && kUseBakerReadBarrier) {
586 // We need a temporary register for the read barrier marking slow
587 // path in InstructionCodeGeneratorARM::GenerateArrayLoadWithBakerReadBarrier.
588 locations->AddTemp(Location::RequiresRegister());
589 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800590}
591
592void IntrinsicLocationsBuilderARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000593 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800594}
595void IntrinsicLocationsBuilderARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000596 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800597}
598void IntrinsicLocationsBuilderARM::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000599 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800600}
601void IntrinsicLocationsBuilderARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000602 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimLong);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800603}
604void IntrinsicLocationsBuilderARM::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000605 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800606}
607void IntrinsicLocationsBuilderARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainc9285912015-12-18 10:38:42 +0000608 CreateIntIntIntToIntLocations(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800609}
610
611void IntrinsicCodeGeneratorARM::VisitUnsafeGet(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000612 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800613}
614void IntrinsicCodeGeneratorARM::VisitUnsafeGetVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000615 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800616}
617void IntrinsicCodeGeneratorARM::VisitUnsafeGetLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000618 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800619}
620void IntrinsicCodeGeneratorARM::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000621 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800622}
623void IntrinsicCodeGeneratorARM::VisitUnsafeGetObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000624 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800625}
626void IntrinsicCodeGeneratorARM::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000627 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800628}
629
630static void CreateIntIntIntIntToVoid(ArenaAllocator* arena,
631 const ArmInstructionSetFeatures& features,
632 Primitive::Type type,
633 bool is_volatile,
634 HInvoke* invoke) {
635 LocationSummary* locations = new (arena) LocationSummary(invoke,
636 LocationSummary::kNoCall,
637 kIntrinsified);
638 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
639 locations->SetInAt(1, Location::RequiresRegister());
640 locations->SetInAt(2, Location::RequiresRegister());
641 locations->SetInAt(3, Location::RequiresRegister());
642
643 if (type == Primitive::kPrimLong) {
644 // Potentially need temps for ldrexd-strexd loop.
645 if (is_volatile && !features.HasAtomicLdrdAndStrd()) {
646 locations->AddTemp(Location::RequiresRegister()); // Temp_lo.
647 locations->AddTemp(Location::RequiresRegister()); // Temp_hi.
648 }
649 } else if (type == Primitive::kPrimNot) {
650 // Temps for card-marking.
651 locations->AddTemp(Location::RequiresRegister()); // Temp.
652 locations->AddTemp(Location::RequiresRegister()); // Card.
653 }
654}
655
656void IntrinsicLocationsBuilderARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000657 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800658}
659void IntrinsicLocationsBuilderARM::VisitUnsafePutOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000660 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800661}
662void IntrinsicLocationsBuilderARM::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000663 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimInt, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800664}
665void IntrinsicLocationsBuilderARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000666 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800667}
668void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000669 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800670}
671void IntrinsicLocationsBuilderARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000672 CreateIntIntIntIntToVoid(arena_, features_, Primitive::kPrimNot, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800673}
674void IntrinsicLocationsBuilderARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000675 CreateIntIntIntIntToVoid(
676 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800677}
678void IntrinsicLocationsBuilderARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000679 CreateIntIntIntIntToVoid(
680 arena_, features_, Primitive::kPrimLong, /* is_volatile */ false, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800681}
682void IntrinsicLocationsBuilderARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000683 CreateIntIntIntIntToVoid(
684 arena_, features_, Primitive::kPrimLong, /* is_volatile */ true, invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800685}
686
687static void GenUnsafePut(LocationSummary* locations,
688 Primitive::Type type,
689 bool is_volatile,
690 bool is_ordered,
691 CodeGeneratorARM* codegen) {
692 ArmAssembler* assembler = codegen->GetAssembler();
693
694 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
695 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Long offset, lo part only.
696 Register value;
697
698 if (is_volatile || is_ordered) {
699 __ dmb(ISH);
700 }
701
702 if (type == Primitive::kPrimLong) {
703 Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>();
704 value = value_lo;
705 if (is_volatile && !codegen->GetInstructionSetFeatures().HasAtomicLdrdAndStrd()) {
706 Register temp_lo = locations->GetTemp(0).AsRegister<Register>();
707 Register temp_hi = locations->GetTemp(1).AsRegister<Register>();
708 Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>();
709
710 __ add(IP, base, ShifterOperand(offset));
711 Label loop_head;
712 __ Bind(&loop_head);
713 __ ldrexd(temp_lo, temp_hi, IP);
714 __ strexd(temp_lo, value_lo, value_hi, IP);
715 __ cmp(temp_lo, ShifterOperand(0));
716 __ b(&loop_head, NE);
717 } else {
718 __ add(IP, base, ShifterOperand(offset));
719 __ strd(value_lo, Address(IP));
720 }
721 } else {
Roland Levillain4d027112015-07-01 15:41:14 +0100722 value = locations->InAt(3).AsRegister<Register>();
723 Register source = value;
724 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
725 Register temp = locations->GetTemp(0).AsRegister<Register>();
726 __ Mov(temp, value);
727 __ PoisonHeapReference(temp);
728 source = temp;
729 }
730 __ str(source, Address(base, offset));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800731 }
732
733 if (is_volatile) {
734 __ dmb(ISH);
735 }
736
737 if (type == Primitive::kPrimNot) {
738 Register temp = locations->GetTemp(0).AsRegister<Register>();
739 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100740 bool value_can_be_null = true; // TODO: Worth finding out this information?
741 codegen->MarkGCCard(temp, card, base, value, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800742 }
743}
744
745void IntrinsicCodeGeneratorARM::VisitUnsafePut(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000746 GenUnsafePut(invoke->GetLocations(),
747 Primitive::kPrimInt,
748 /* is_volatile */ false,
749 /* is_ordered */ false,
750 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800751}
752void IntrinsicCodeGeneratorARM::VisitUnsafePutOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000753 GenUnsafePut(invoke->GetLocations(),
754 Primitive::kPrimInt,
755 /* is_volatile */ false,
756 /* is_ordered */ true,
757 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800758}
759void IntrinsicCodeGeneratorARM::VisitUnsafePutVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000760 GenUnsafePut(invoke->GetLocations(),
761 Primitive::kPrimInt,
762 /* is_volatile */ true,
763 /* is_ordered */ false,
764 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800765}
766void IntrinsicCodeGeneratorARM::VisitUnsafePutObject(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000767 GenUnsafePut(invoke->GetLocations(),
768 Primitive::kPrimNot,
769 /* is_volatile */ false,
770 /* is_ordered */ false,
771 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800772}
773void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000774 GenUnsafePut(invoke->GetLocations(),
775 Primitive::kPrimNot,
776 /* is_volatile */ false,
777 /* is_ordered */ true,
778 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800779}
780void IntrinsicCodeGeneratorARM::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000781 GenUnsafePut(invoke->GetLocations(),
782 Primitive::kPrimNot,
783 /* is_volatile */ true,
784 /* is_ordered */ false,
785 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800786}
787void IntrinsicCodeGeneratorARM::VisitUnsafePutLong(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000788 GenUnsafePut(invoke->GetLocations(),
789 Primitive::kPrimLong,
790 /* is_volatile */ false,
791 /* is_ordered */ false,
792 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800793}
794void IntrinsicCodeGeneratorARM::VisitUnsafePutLongOrdered(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000795 GenUnsafePut(invoke->GetLocations(),
796 Primitive::kPrimLong,
797 /* is_volatile */ false,
798 /* is_ordered */ true,
799 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800800}
801void IntrinsicCodeGeneratorARM::VisitUnsafePutLongVolatile(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000802 GenUnsafePut(invoke->GetLocations(),
803 Primitive::kPrimLong,
804 /* is_volatile */ true,
805 /* is_ordered */ false,
806 codegen_);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800807}
808
809static void CreateIntIntIntIntIntToIntPlusTemps(ArenaAllocator* arena,
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000810 HInvoke* invoke,
811 Primitive::Type type) {
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800812 LocationSummary* locations = new (arena) LocationSummary(invoke,
813 LocationSummary::kNoCall,
814 kIntrinsified);
815 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
816 locations->SetInAt(1, Location::RequiresRegister());
817 locations->SetInAt(2, Location::RequiresRegister());
818 locations->SetInAt(3, Location::RequiresRegister());
819 locations->SetInAt(4, Location::RequiresRegister());
820
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000821 // If heap poisoning is enabled, we don't want the unpoisoning
822 // operations to potentially clobber the output.
823 Location::OutputOverlap overlaps = (kPoisonHeapReferences && type == Primitive::kPrimNot)
824 ? Location::kOutputOverlap
825 : Location::kNoOutputOverlap;
826 locations->SetOut(Location::RequiresRegister(), overlaps);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800827
828 locations->AddTemp(Location::RequiresRegister()); // Pointer.
829 locations->AddTemp(Location::RequiresRegister()); // Temp 1.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800830}
831
832static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorARM* codegen) {
833 DCHECK_NE(type, Primitive::kPrimLong);
834
835 ArmAssembler* assembler = codegen->GetAssembler();
836
837 Register out = locations->Out().AsRegister<Register>(); // Boolean result.
838
839 Register base = locations->InAt(1).AsRegister<Register>(); // Object pointer.
840 Register offset = locations->InAt(2).AsRegisterPairLow<Register>(); // Offset (discard high 4B).
841 Register expected_lo = locations->InAt(3).AsRegister<Register>(); // Expected.
842 Register value_lo = locations->InAt(4).AsRegister<Register>(); // Value.
843
844 Register tmp_ptr = locations->GetTemp(0).AsRegister<Register>(); // Pointer to actual memory.
845 Register tmp_lo = locations->GetTemp(1).AsRegister<Register>(); // Value in memory.
846
847 if (type == Primitive::kPrimNot) {
848 // Mark card for object assuming new value is stored. Worst case we will mark an unchanged
849 // object and scan the receiver at the next GC for nothing.
Nicolas Geoffray07276db2015-05-18 14:22:09 +0100850 bool value_can_be_null = true; // TODO: Worth finding out this information?
851 codegen->MarkGCCard(tmp_ptr, tmp_lo, base, value_lo, value_can_be_null);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800852 }
853
854 // Prevent reordering with prior memory operations.
Roland Levillain4bedb382016-01-12 12:01:04 +0000855 // Emit a DMB ISH instruction instead of an DMB ISHST one, as the
856 // latter allows a preceding load to be delayed past the STXR
857 // instruction below.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800858 __ dmb(ISH);
859
860 __ add(tmp_ptr, base, ShifterOperand(offset));
861
Roland Levillain4d027112015-07-01 15:41:14 +0100862 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
863 codegen->GetAssembler()->PoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000864 if (value_lo == expected_lo) {
865 // Do not poison `value_lo`, as it is the same register as
866 // `expected_lo`, which has just been poisoned.
867 } else {
868 codegen->GetAssembler()->PoisonHeapReference(value_lo);
869 }
Roland Levillain4d027112015-07-01 15:41:14 +0100870 }
871
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800872 // do {
873 // tmp = [r_ptr] - expected;
874 // } while (tmp == 0 && failure([r_ptr] <- r_new_value));
875 // result = tmp != 0;
876
877 Label loop_head;
878 __ Bind(&loop_head);
879
Roland Levillain391b8662015-12-18 11:43:38 +0000880 // TODO: When `type == Primitive::kPrimNot`, add a read barrier for
881 // the reference stored in the object before attempting the CAS,
882 // similar to the one in the art::Unsafe_compareAndSwapObject JNI
883 // implementation.
884 //
885 // Note that this code is not (yet) used when read barriers are
886 // enabled (see IntrinsicLocationsBuilderARM::VisitUnsafeCASObject).
887 DCHECK(!(type == Primitive::kPrimNot && kEmitCompilerReadBarrier));
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800888 __ ldrex(tmp_lo, tmp_ptr);
889
890 __ subs(tmp_lo, tmp_lo, ShifterOperand(expected_lo));
891
892 __ it(EQ, ItState::kItT);
893 __ strex(tmp_lo, value_lo, tmp_ptr, EQ);
894 __ cmp(tmp_lo, ShifterOperand(1), EQ);
895
896 __ b(&loop_head, EQ);
897
898 __ dmb(ISH);
899
900 __ rsbs(out, tmp_lo, ShifterOperand(1));
901 __ it(CC);
902 __ mov(out, ShifterOperand(0), CC);
Roland Levillain4d027112015-07-01 15:41:14 +0100903
904 if (kPoisonHeapReferences && type == Primitive::kPrimNot) {
Roland Levillain4d027112015-07-01 15:41:14 +0100905 codegen->GetAssembler()->UnpoisonHeapReference(expected_lo);
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000906 if (value_lo == expected_lo) {
907 // Do not unpoison `value_lo`, as it is the same register as
908 // `expected_lo`, which has just been unpoisoned.
909 } else {
910 codegen->GetAssembler()->UnpoisonHeapReference(value_lo);
911 }
Roland Levillain4d027112015-07-01 15:41:14 +0100912 }
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800913}
914
Andreas Gampeca714582015-04-03 19:41:34 -0700915void IntrinsicLocationsBuilderARM::VisitUnsafeCASInt(HInvoke* invoke) {
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000916 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimInt);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800917}
Andreas Gampeca714582015-04-03 19:41:34 -0700918void IntrinsicLocationsBuilderARM::VisitUnsafeCASObject(HInvoke* invoke) {
Roland Levillain391b8662015-12-18 11:43:38 +0000919 // The UnsafeCASObject intrinsic is missing a read barrier, and
920 // therefore sometimes does not work as expected (b/25883050).
921 // Turn it off temporarily as a quick fix, until the read barrier is
922 // implemented (see TODO in GenCAS below).
923 //
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000924 // TODO(rpl): Fix this issue and re-enable this intrinsic with read barriers.
925 if (kEmitCompilerReadBarrier) {
Roland Levillain985ff702015-10-23 13:25:35 +0100926 return;
927 }
928
Roland Levillain2e50ecb2016-01-27 14:08:33 +0000929 CreateIntIntIntIntIntToIntPlusTemps(arena_, invoke, Primitive::kPrimNot);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800930}
931void IntrinsicCodeGeneratorARM::VisitUnsafeCASInt(HInvoke* invoke) {
932 GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
933}
934void IntrinsicCodeGeneratorARM::VisitUnsafeCASObject(HInvoke* invoke) {
935 GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
936}
937
938void IntrinsicLocationsBuilderARM::VisitStringCharAt(HInvoke* invoke) {
939 LocationSummary* locations = new (arena_) LocationSummary(invoke,
940 LocationSummary::kCallOnSlowPath,
941 kIntrinsified);
942 locations->SetInAt(0, Location::RequiresRegister());
943 locations->SetInAt(1, Location::RequiresRegister());
944 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
945
946 locations->AddTemp(Location::RequiresRegister());
947 locations->AddTemp(Location::RequiresRegister());
948}
949
950void IntrinsicCodeGeneratorARM::VisitStringCharAt(HInvoke* invoke) {
951 ArmAssembler* assembler = GetAssembler();
952 LocationSummary* locations = invoke->GetLocations();
953
954 // Location of reference to data array
955 const MemberOffset value_offset = mirror::String::ValueOffset();
956 // Location of count
957 const MemberOffset count_offset = mirror::String::CountOffset();
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800958
959 Register obj = locations->InAt(0).AsRegister<Register>(); // String object pointer.
960 Register idx = locations->InAt(1).AsRegister<Register>(); // Index of character.
961 Register out = locations->Out().AsRegister<Register>(); // Result character.
962
963 Register temp = locations->GetTemp(0).AsRegister<Register>();
964 Register array_temp = locations->GetTemp(1).AsRegister<Register>();
965
966 // TODO: Maybe we can support range check elimination. Overall, though, I think it's not worth
967 // the cost.
968 // TODO: For simplicity, the index parameter is requested in a register, so different from Quick
969 // we will not optimize the code for constants (which would save a register).
970
Andreas Gampe85b62f22015-09-09 13:15:38 -0700971 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800972 codegen_->AddSlowPath(slow_path);
973
974 __ ldr(temp, Address(obj, count_offset.Int32Value())); // temp = str.length.
975 codegen_->MaybeRecordImplicitNullCheck(invoke);
976 __ cmp(idx, ShifterOperand(temp));
977 __ b(slow_path->GetEntryLabel(), CS);
978
Jeff Hao848f70a2014-01-15 13:49:50 -0800979 __ add(array_temp, obj, ShifterOperand(value_offset.Int32Value())); // array_temp := str.value.
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800980
981 // Load the value.
Jeff Hao848f70a2014-01-15 13:49:50 -0800982 __ ldrh(out, Address(array_temp, idx, LSL, 1)); // out := array_temp[idx].
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800983
984 __ Bind(slow_path->GetExitLabel());
985}
986
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +0000987void IntrinsicLocationsBuilderARM::VisitStringCompareTo(HInvoke* invoke) {
988 // The inputs plus one temp.
989 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Scott Wakelingc25cbf12016-04-18 09:00:11 +0100990 invoke->InputAt(1)->CanBeNull()
991 ? LocationSummary::kCallOnSlowPath
992 : LocationSummary::kNoCall,
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +0000993 kIntrinsified);
Scott Wakelingc25cbf12016-04-18 09:00:11 +0100994 locations->SetInAt(0, Location::RequiresRegister());
995 locations->SetInAt(1, Location::RequiresRegister());
996 locations->AddTemp(Location::RequiresRegister());
997 locations->AddTemp(Location::RequiresRegister());
998 locations->AddTemp(Location::RequiresRegister());
999 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001000}
1001
1002void IntrinsicCodeGeneratorARM::VisitStringCompareTo(HInvoke* invoke) {
1003 ArmAssembler* assembler = GetAssembler();
1004 LocationSummary* locations = invoke->GetLocations();
1005
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001006 Register str = locations->InAt(0).AsRegister<Register>();
1007 Register arg = locations->InAt(1).AsRegister<Register>();
1008 Register out = locations->Out().AsRegister<Register>();
1009
1010 Register temp0 = locations->GetTemp(0).AsRegister<Register>();
1011 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1012 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1013
1014 Label loop;
1015 Label find_char_diff;
1016 Label end;
1017
1018 // Get offsets of count and value fields within a string object.
1019 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1020 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1021
Nicolas Geoffray512e04d2015-03-27 17:21:24 +00001022 // Note that the null check must have been done earlier.
Calin Juravle641547a2015-04-21 22:08:51 +01001023 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001024
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001025 // Take slow path and throw if input can be and is null.
1026 SlowPathCode* slow_path = nullptr;
1027 const bool can_slow_path = invoke->InputAt(1)->CanBeNull();
1028 if (can_slow_path) {
1029 slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1030 codegen_->AddSlowPath(slow_path);
1031 __ CompareAndBranchIfZero(arg, slow_path->GetEntryLabel());
1032 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001033
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001034 // Reference equality check, return 0 if same reference.
1035 __ subs(out, str, ShifterOperand(arg));
1036 __ b(&end, EQ);
1037 // Load lengths of this and argument strings.
1038 __ ldr(temp2, Address(str, count_offset));
1039 __ ldr(temp1, Address(arg, count_offset));
1040 // out = length diff.
1041 __ subs(out, temp2, ShifterOperand(temp1));
1042 // temp0 = min(len(str), len(arg)).
1043 __ it(Condition::LT, kItElse);
1044 __ mov(temp0, ShifterOperand(temp2), Condition::LT);
1045 __ mov(temp0, ShifterOperand(temp1), Condition::GE);
1046 // Shorter string is empty?
1047 __ CompareAndBranchIfZero(temp0, &end);
1048
1049 // Store offset of string value in preparation for comparison loop.
1050 __ mov(temp1, ShifterOperand(value_offset));
1051
1052 // Assertions that must hold in order to compare multiple characters at a time.
1053 CHECK_ALIGNED(value_offset, 8);
1054 static_assert(IsAligned<8>(kObjectAlignment),
1055 "String data must be 8-byte aligned for unrolled CompareTo loop.");
1056
1057 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
1058 DCHECK_EQ(char_size, 2u);
1059
1060 // Unrolled loop comparing 4x16-bit chars per iteration (ok because of string data alignment).
1061 __ Bind(&loop);
1062 __ ldr(IP, Address(str, temp1));
1063 __ ldr(temp2, Address(arg, temp1));
1064 __ cmp(IP, ShifterOperand(temp2));
1065 __ b(&find_char_diff, NE);
1066 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1067 __ sub(temp0, temp0, ShifterOperand(2));
1068
1069 __ ldr(IP, Address(str, temp1));
1070 __ ldr(temp2, Address(arg, temp1));
1071 __ cmp(IP, ShifterOperand(temp2));
1072 __ b(&find_char_diff, NE);
1073 __ add(temp1, temp1, ShifterOperand(char_size * 2));
1074 __ subs(temp0, temp0, ShifterOperand(2));
1075
1076 __ b(&loop, GT);
1077 __ b(&end);
1078
1079 // Find the single 16-bit character difference.
1080 __ Bind(&find_char_diff);
1081 // Get the bit position of the first character that differs.
1082 __ eor(temp1, temp2, ShifterOperand(IP));
1083 __ rbit(temp1, temp1);
1084 __ clz(temp1, temp1);
1085
1086 // temp0 = number of 16-bit characters remaining to compare.
1087 // (it could be < 1 if a difference is found after the first SUB in the comparison loop, and
1088 // after the end of the shorter string data).
1089
1090 // (temp1 >> 4) = character where difference occurs between the last two words compared, on the
1091 // interval [0,1] (0 for low half-word different, 1 for high half-word different).
1092
1093 // If temp0 <= (temp1 >> 4), the difference occurs outside the remaining string data, so just
1094 // return length diff (out).
1095 __ cmp(temp0, ShifterOperand(temp1, LSR, 4));
1096 __ b(&end, LE);
1097 // Extract the characters and calculate the difference.
1098 __ bic(temp1, temp1, ShifterOperand(0xf));
1099 __ Lsr(temp2, temp2, temp1);
1100 __ Lsr(IP, IP, temp1);
1101 __ movt(temp2, 0);
1102 __ movt(IP, 0);
1103 __ sub(out, IP, ShifterOperand(temp2));
1104
1105 __ Bind(&end);
1106
1107 if (can_slow_path) {
1108 __ Bind(slow_path->GetExitLabel());
1109 }
Nicolas Geoffrayd75948a2015-03-27 09:53:16 +00001110}
1111
Agi Csaki289cd552015-08-18 17:10:38 -07001112void IntrinsicLocationsBuilderARM::VisitStringEquals(HInvoke* invoke) {
1113 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1114 LocationSummary::kNoCall,
1115 kIntrinsified);
1116 InvokeRuntimeCallingConvention calling_convention;
1117 locations->SetInAt(0, Location::RequiresRegister());
1118 locations->SetInAt(1, Location::RequiresRegister());
1119 // Temporary registers to store lengths of strings and for calculations.
1120 // Using instruction cbz requires a low register, so explicitly set a temp to be R0.
1121 locations->AddTemp(Location::RegisterLocation(R0));
1122 locations->AddTemp(Location::RequiresRegister());
1123 locations->AddTemp(Location::RequiresRegister());
1124
1125 locations->SetOut(Location::RequiresRegister());
1126}
1127
1128void IntrinsicCodeGeneratorARM::VisitStringEquals(HInvoke* invoke) {
1129 ArmAssembler* assembler = GetAssembler();
1130 LocationSummary* locations = invoke->GetLocations();
1131
1132 Register str = locations->InAt(0).AsRegister<Register>();
1133 Register arg = locations->InAt(1).AsRegister<Register>();
1134 Register out = locations->Out().AsRegister<Register>();
1135
1136 Register temp = locations->GetTemp(0).AsRegister<Register>();
1137 Register temp1 = locations->GetTemp(1).AsRegister<Register>();
1138 Register temp2 = locations->GetTemp(2).AsRegister<Register>();
1139
1140 Label loop;
1141 Label end;
1142 Label return_true;
1143 Label return_false;
1144
1145 // Get offsets of count, value, and class fields within a string object.
1146 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1147 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1148 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1149
1150 // Note that the null check must have been done earlier.
1151 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1152
Vladimir Marko53b52002016-05-24 19:30:45 +01001153 StringEqualsOptimizations optimizations(invoke);
1154 if (!optimizations.GetArgumentNotNull()) {
1155 // Check if input is null, return false if it is.
1156 __ CompareAndBranchIfZero(arg, &return_false);
1157 }
Agi Csaki289cd552015-08-18 17:10:38 -07001158
Vladimir Marko53b52002016-05-24 19:30:45 +01001159 if (!optimizations.GetArgumentIsString()) {
1160 // Instanceof check for the argument by comparing class fields.
1161 // All string objects must have the same type since String cannot be subclassed.
1162 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1163 // If the argument is a string object, its class field must be equal to receiver's class field.
1164 __ ldr(temp, Address(str, class_offset));
1165 __ ldr(temp1, Address(arg, class_offset));
1166 __ cmp(temp, ShifterOperand(temp1));
1167 __ b(&return_false, NE);
1168 }
Agi Csaki289cd552015-08-18 17:10:38 -07001169
1170 // Load lengths of this and argument strings.
1171 __ ldr(temp, Address(str, count_offset));
1172 __ ldr(temp1, Address(arg, count_offset));
1173 // Check if lengths are equal, return false if they're not.
1174 __ cmp(temp, ShifterOperand(temp1));
1175 __ b(&return_false, NE);
1176 // Return true if both strings are empty.
1177 __ cbz(temp, &return_true);
1178
1179 // Reference equality check, return true if same reference.
1180 __ cmp(str, ShifterOperand(arg));
1181 __ b(&return_true, EQ);
1182
1183 // Assertions that must hold in order to compare strings 2 characters at a time.
1184 DCHECK_ALIGNED(value_offset, 4);
Scott Wakelingc25cbf12016-04-18 09:00:11 +01001185 static_assert(IsAligned<4>(kObjectAlignment), "String data must be aligned for fast compare.");
Agi Csaki289cd552015-08-18 17:10:38 -07001186
Agi Csaki289cd552015-08-18 17:10:38 -07001187 __ LoadImmediate(temp1, value_offset);
Agi Csaki289cd552015-08-18 17:10:38 -07001188
1189 // Loop to compare strings 2 characters at a time starting at the front of the string.
1190 // Ok to do this because strings with an odd length are zero-padded.
1191 __ Bind(&loop);
1192 __ ldr(out, Address(str, temp1));
1193 __ ldr(temp2, Address(arg, temp1));
1194 __ cmp(out, ShifterOperand(temp2));
1195 __ b(&return_false, NE);
1196 __ add(temp1, temp1, ShifterOperand(sizeof(uint32_t)));
Vladimir Markoa63f0d42015-09-01 13:36:35 +01001197 __ subs(temp, temp, ShifterOperand(sizeof(uint32_t) / sizeof(uint16_t)));
1198 __ b(&loop, GT);
Agi Csaki289cd552015-08-18 17:10:38 -07001199
1200 // Return true and exit the function.
1201 // If loop does not result in returning false, we return true.
1202 __ Bind(&return_true);
1203 __ LoadImmediate(out, 1);
1204 __ b(&end);
1205
1206 // Return false and exit the function.
1207 __ Bind(&return_false);
1208 __ LoadImmediate(out, 0);
1209 __ Bind(&end);
1210}
1211
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001212static void GenerateVisitStringIndexOf(HInvoke* invoke,
1213 ArmAssembler* assembler,
1214 CodeGeneratorARM* codegen,
1215 ArenaAllocator* allocator,
1216 bool start_at_zero) {
1217 LocationSummary* locations = invoke->GetLocations();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001218
1219 // Note that the null check must have been done earlier.
1220 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1221
1222 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001223 // 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 -07001224 SlowPathCode* slow_path = nullptr;
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001225 HInstruction* code_point = invoke->InputAt(1);
1226 if (code_point->IsIntConstant()) {
Vladimir Markoda051082016-05-17 16:10:20 +01001227 if (static_cast<uint32_t>(code_point->AsIntConstant()->GetValue()) >
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001228 std::numeric_limits<uint16_t>::max()) {
1229 // Always needs the slow-path. We could directly dispatch to it, but this case should be
1230 // rare, so for simplicity just put the full slow-path down and branch unconditionally.
1231 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1232 codegen->AddSlowPath(slow_path);
1233 __ b(slow_path->GetEntryLabel());
1234 __ Bind(slow_path->GetExitLabel());
1235 return;
1236 }
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001237 } else if (code_point->GetType() != Primitive::kPrimChar) {
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001238 Register char_reg = locations->InAt(1).AsRegister<Register>();
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001239 // 0xffff is not modified immediate but 0x10000 is, so use `>= 0x10000` instead of `> 0xffff`.
1240 __ cmp(char_reg,
1241 ShifterOperand(static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001242 slow_path = new (allocator) IntrinsicSlowPathARM(invoke);
1243 codegen->AddSlowPath(slow_path);
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001244 __ b(slow_path->GetEntryLabel(), HS);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001245 }
1246
1247 if (start_at_zero) {
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001248 Register tmp_reg = locations->GetTemp(0).AsRegister<Register>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001249 DCHECK_EQ(tmp_reg, R2);
1250 // Start-index = 0.
1251 __ LoadImmediate(tmp_reg, 0);
1252 }
1253
1254 __ LoadFromOffset(kLoadWord, LR, TR,
1255 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pIndexOf).Int32Value());
Roland Levillain42ad2882016-02-29 18:26:54 +00001256 CheckEntrypointTypes<kQuickIndexOf, int32_t, void*, uint32_t, uint32_t>();
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001257 __ blx(LR);
1258
1259 if (slow_path != nullptr) {
1260 __ Bind(slow_path->GetExitLabel());
1261 }
1262}
1263
1264void IntrinsicLocationsBuilderARM::VisitStringIndexOf(HInvoke* invoke) {
1265 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1266 LocationSummary::kCall,
1267 kIntrinsified);
1268 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1269 // best to align the inputs accordingly.
1270 InvokeRuntimeCallingConvention calling_convention;
1271 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1272 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1273 locations->SetOut(Location::RegisterLocation(R0));
1274
Vladimir Markofb6c90a2016-05-06 15:52:12 +01001275 // Need to send start-index=0.
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001276 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1277}
1278
1279void IntrinsicCodeGeneratorARM::VisitStringIndexOf(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001280 GenerateVisitStringIndexOf(
1281 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ true);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001282}
1283
1284void IntrinsicLocationsBuilderARM::VisitStringIndexOfAfter(HInvoke* invoke) {
1285 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1286 LocationSummary::kCall,
1287 kIntrinsified);
1288 // We have a hand-crafted assembly stub that follows the runtime calling convention. So it's
1289 // best to align the inputs accordingly.
1290 InvokeRuntimeCallingConvention calling_convention;
1291 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1292 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1293 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1294 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001295}
1296
1297void IntrinsicCodeGeneratorARM::VisitStringIndexOfAfter(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +00001298 GenerateVisitStringIndexOf(
1299 invoke, GetAssembler(), codegen_, GetAllocator(), /* start_at_zero */ false);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -07001300}
1301
Jeff Hao848f70a2014-01-15 13:49:50 -08001302void IntrinsicLocationsBuilderARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1303 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1304 LocationSummary::kCall,
1305 kIntrinsified);
1306 InvokeRuntimeCallingConvention calling_convention;
1307 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1308 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1309 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1310 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1311 locations->SetOut(Location::RegisterLocation(R0));
1312}
1313
1314void IntrinsicCodeGeneratorARM::VisitStringNewStringFromBytes(HInvoke* invoke) {
1315 ArmAssembler* assembler = GetAssembler();
1316 LocationSummary* locations = invoke->GetLocations();
1317
1318 Register byte_array = locations->InAt(0).AsRegister<Register>();
1319 __ cmp(byte_array, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001320 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001321 codegen_->AddSlowPath(slow_path);
1322 __ b(slow_path->GetEntryLabel(), EQ);
1323
1324 __ LoadFromOffset(
1325 kLoadWord, LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromBytes).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001326 CheckEntrypointTypes<kQuickAllocStringFromBytes, void*, void*, int32_t, int32_t, int32_t>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001327 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001328 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001329 __ Bind(slow_path->GetExitLabel());
1330}
1331
1332void IntrinsicLocationsBuilderARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1333 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1334 LocationSummary::kCall,
1335 kIntrinsified);
1336 InvokeRuntimeCallingConvention calling_convention;
1337 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1338 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1339 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1340 locations->SetOut(Location::RegisterLocation(R0));
1341}
1342
1343void IntrinsicCodeGeneratorARM::VisitStringNewStringFromChars(HInvoke* invoke) {
1344 ArmAssembler* assembler = GetAssembler();
1345
Roland Levillaincc3839c2016-02-29 16:23:48 +00001346 // No need to emit code checking whether `locations->InAt(2)` is a null
1347 // pointer, as callers of the native method
1348 //
1349 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1350 //
1351 // all include a null check on `data` before calling that method.
Jeff Hao848f70a2014-01-15 13:49:50 -08001352 __ LoadFromOffset(
1353 kLoadWord, LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromChars).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001354 CheckEntrypointTypes<kQuickAllocStringFromChars, void*, int32_t, int32_t, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001355 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001356 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001357}
1358
1359void IntrinsicLocationsBuilderARM::VisitStringNewStringFromString(HInvoke* invoke) {
1360 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1361 LocationSummary::kCall,
1362 kIntrinsified);
1363 InvokeRuntimeCallingConvention calling_convention;
1364 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1365 locations->SetOut(Location::RegisterLocation(R0));
1366}
1367
1368void IntrinsicCodeGeneratorARM::VisitStringNewStringFromString(HInvoke* invoke) {
1369 ArmAssembler* assembler = GetAssembler();
1370 LocationSummary* locations = invoke->GetLocations();
1371
1372 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1373 __ cmp(string_to_copy, ShifterOperand(0));
Andreas Gampe85b62f22015-09-09 13:15:38 -07001374 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
Jeff Hao848f70a2014-01-15 13:49:50 -08001375 codegen_->AddSlowPath(slow_path);
1376 __ b(slow_path->GetEntryLabel(), EQ);
1377
1378 __ LoadFromOffset(kLoadWord,
1379 LR, TR, QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pAllocStringFromString).Int32Value());
Roland Levillainf969a202016-03-09 16:14:00 +00001380 CheckEntrypointTypes<kQuickAllocStringFromString, void*, void*>();
Jeff Hao848f70a2014-01-15 13:49:50 -08001381 __ blx(LR);
Roland Levillainf969a202016-03-09 16:14:00 +00001382 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Jeff Hao848f70a2014-01-15 13:49:50 -08001383 __ Bind(slow_path->GetExitLabel());
1384}
1385
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001386void IntrinsicLocationsBuilderARM::VisitSystemArrayCopy(HInvoke* invoke) {
1387 CodeGenerator::CreateSystemArrayCopyLocationSummary(invoke);
1388 LocationSummary* locations = invoke->GetLocations();
1389 if (locations == nullptr) {
1390 return;
1391 }
1392
1393 HIntConstant* src_pos = invoke->InputAt(1)->AsIntConstant();
1394 HIntConstant* dest_pos = invoke->InputAt(3)->AsIntConstant();
1395 HIntConstant* length = invoke->InputAt(4)->AsIntConstant();
1396
1397 if (src_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(src_pos->GetValue())) {
1398 locations->SetInAt(1, Location::RequiresRegister());
1399 }
1400 if (dest_pos != nullptr && !assembler_->ShifterOperandCanAlwaysHold(dest_pos->GetValue())) {
1401 locations->SetInAt(3, Location::RequiresRegister());
1402 }
1403 if (length != nullptr && !assembler_->ShifterOperandCanAlwaysHold(length->GetValue())) {
1404 locations->SetInAt(4, Location::RequiresRegister());
1405 }
1406}
1407
1408static void CheckPosition(ArmAssembler* assembler,
1409 Location pos,
1410 Register input,
1411 Location length,
1412 SlowPathCode* slow_path,
1413 Register input_len,
1414 Register temp,
1415 bool length_is_input_length = false) {
1416 // Where is the length in the Array?
1417 const uint32_t length_offset = mirror::Array::LengthOffset().Uint32Value();
1418
1419 if (pos.IsConstant()) {
1420 int32_t pos_const = pos.GetConstant()->AsIntConstant()->GetValue();
1421 if (pos_const == 0) {
1422 if (!length_is_input_length) {
1423 // Check that length(input) >= length.
1424 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1425 if (length.IsConstant()) {
1426 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1427 } else {
1428 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1429 }
1430 __ b(slow_path->GetEntryLabel(), LT);
1431 }
1432 } else {
1433 // Check that length(input) >= pos.
1434 __ LoadFromOffset(kLoadWord, input_len, input, length_offset);
1435 __ subs(temp, input_len, ShifterOperand(pos_const));
1436 __ b(slow_path->GetEntryLabel(), LT);
1437
1438 // Check that (length(input) - pos) >= length.
1439 if (length.IsConstant()) {
1440 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1441 } else {
1442 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1443 }
1444 __ b(slow_path->GetEntryLabel(), LT);
1445 }
1446 } else if (length_is_input_length) {
1447 // The only way the copy can succeed is if pos is zero.
1448 Register pos_reg = pos.AsRegister<Register>();
1449 __ CompareAndBranchIfNonZero(pos_reg, slow_path->GetEntryLabel());
1450 } else {
1451 // Check that pos >= 0.
1452 Register pos_reg = pos.AsRegister<Register>();
1453 __ cmp(pos_reg, ShifterOperand(0));
1454 __ b(slow_path->GetEntryLabel(), LT);
1455
1456 // Check that pos <= length(input).
1457 __ LoadFromOffset(kLoadWord, temp, input, length_offset);
1458 __ subs(temp, temp, ShifterOperand(pos_reg));
1459 __ b(slow_path->GetEntryLabel(), LT);
1460
1461 // Check that (length(input) - pos) >= length.
1462 if (length.IsConstant()) {
1463 __ cmp(temp, ShifterOperand(length.GetConstant()->AsIntConstant()->GetValue()));
1464 } else {
1465 __ cmp(temp, ShifterOperand(length.AsRegister<Register>()));
1466 }
1467 __ b(slow_path->GetEntryLabel(), LT);
1468 }
1469}
1470
Roland Levillain3b359c72015-11-17 19:35:12 +00001471// TODO: Implement read barriers in the SystemArrayCopy intrinsic.
1472// Note that this code path is not used (yet) because we do not
1473// intrinsify methods that can go into the IntrinsicSlowPathARM
1474// slow path.
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001475void IntrinsicCodeGeneratorARM::VisitSystemArrayCopy(HInvoke* invoke) {
1476 ArmAssembler* assembler = GetAssembler();
1477 LocationSummary* locations = invoke->GetLocations();
1478
1479 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1480 uint32_t super_offset = mirror::Class::SuperClassOffset().Int32Value();
1481 uint32_t component_offset = mirror::Class::ComponentTypeOffset().Int32Value();
1482 uint32_t primitive_offset = mirror::Class::PrimitiveTypeOffset().Int32Value();
1483
1484 Register src = locations->InAt(0).AsRegister<Register>();
1485 Location src_pos = locations->InAt(1);
1486 Register dest = locations->InAt(2).AsRegister<Register>();
1487 Location dest_pos = locations->InAt(3);
1488 Location length = locations->InAt(4);
1489 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
1490 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
1491 Register temp3 = locations->GetTemp(2).AsRegister<Register>();
1492
1493 SlowPathCode* slow_path = new (GetAllocator()) IntrinsicSlowPathARM(invoke);
1494 codegen_->AddSlowPath(slow_path);
1495
Roland Levillainebea3d22016-04-12 15:42:57 +01001496 Label conditions_on_positions_validated;
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001497 SystemArrayCopyOptimizations optimizations(invoke);
1498
Roland Levillainebea3d22016-04-12 15:42:57 +01001499 if (!optimizations.GetDestinationIsSource() &&
1500 (!src_pos.IsConstant() || !dest_pos.IsConstant())) {
1501 __ cmp(src, ShifterOperand(dest));
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001502 }
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001503 // If source and destination are the same, we go to slow path if we need to do
1504 // forward copying.
1505 if (src_pos.IsConstant()) {
1506 int32_t src_pos_constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1507 if (dest_pos.IsConstant()) {
1508 // Checked when building locations.
1509 DCHECK(!optimizations.GetDestinationIsSource()
1510 || (src_pos_constant >= dest_pos.GetConstant()->AsIntConstant()->GetValue()));
1511 } else {
1512 if (!optimizations.GetDestinationIsSource()) {
Roland Levillainebea3d22016-04-12 15:42:57 +01001513 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001514 }
1515 __ cmp(dest_pos.AsRegister<Register>(), ShifterOperand(src_pos_constant));
1516 __ b(slow_path->GetEntryLabel(), GT);
1517 }
1518 } else {
1519 if (!optimizations.GetDestinationIsSource()) {
Roland Levillainebea3d22016-04-12 15:42:57 +01001520 __ b(&conditions_on_positions_validated, NE);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001521 }
1522 if (dest_pos.IsConstant()) {
1523 int32_t dest_pos_constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1524 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos_constant));
1525 } else {
1526 __ cmp(src_pos.AsRegister<Register>(), ShifterOperand(dest_pos.AsRegister<Register>()));
1527 }
1528 __ b(slow_path->GetEntryLabel(), LT);
1529 }
1530
Roland Levillainebea3d22016-04-12 15:42:57 +01001531 __ Bind(&conditions_on_positions_validated);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001532
1533 if (!optimizations.GetSourceIsNotNull()) {
1534 // Bail out if the source is null.
1535 __ CompareAndBranchIfZero(src, slow_path->GetEntryLabel());
1536 }
1537
1538 if (!optimizations.GetDestinationIsNotNull() && !optimizations.GetDestinationIsSource()) {
1539 // Bail out if the destination is null.
1540 __ CompareAndBranchIfZero(dest, slow_path->GetEntryLabel());
1541 }
1542
1543 // If the length is negative, bail out.
1544 // We have already checked in the LocationsBuilder for the constant case.
1545 if (!length.IsConstant() &&
1546 !optimizations.GetCountIsSourceLength() &&
1547 !optimizations.GetCountIsDestinationLength()) {
1548 __ cmp(length.AsRegister<Register>(), ShifterOperand(0));
1549 __ b(slow_path->GetEntryLabel(), LT);
1550 }
1551
1552 // Validity checks: source.
1553 CheckPosition(assembler,
1554 src_pos,
1555 src,
1556 length,
1557 slow_path,
1558 temp1,
1559 temp2,
1560 optimizations.GetCountIsSourceLength());
1561
1562 // Validity checks: dest.
1563 CheckPosition(assembler,
1564 dest_pos,
1565 dest,
1566 length,
1567 slow_path,
1568 temp1,
1569 temp2,
1570 optimizations.GetCountIsDestinationLength());
1571
1572 if (!optimizations.GetDoesNotNeedTypeCheck()) {
1573 // Check whether all elements of the source array are assignable to the component
1574 // type of the destination array. We do two checks: the classes are the same,
1575 // or the destination is Object[]. If none of these checks succeed, we go to the
1576 // slow path.
1577 __ LoadFromOffset(kLoadWord, temp1, dest, class_offset);
1578 __ LoadFromOffset(kLoadWord, temp2, src, class_offset);
1579 bool did_unpoison = false;
1580 if (!optimizations.GetDestinationIsNonPrimitiveArray() ||
1581 !optimizations.GetSourceIsNonPrimitiveArray()) {
Roland Levillainebea3d22016-04-12 15:42:57 +01001582 // One or two of the references need to be unpoisoned. Unpoison them
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001583 // both to make the identity check valid.
1584 __ MaybeUnpoisonHeapReference(temp1);
1585 __ MaybeUnpoisonHeapReference(temp2);
1586 did_unpoison = true;
1587 }
1588
1589 if (!optimizations.GetDestinationIsNonPrimitiveArray()) {
1590 // Bail out if the destination is not a non primitive array.
Roland Levillainebea3d22016-04-12 15:42:57 +01001591 // /* HeapReference<Class> */ temp3 = temp1->component_type_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001592 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1593 __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel());
1594 __ MaybeUnpoisonHeapReference(temp3);
1595 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1596 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1597 __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel());
1598 }
1599
1600 if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1601 // Bail out if the source is not a non primitive array.
Roland Levillainebea3d22016-04-12 15:42:57 +01001602 // /* HeapReference<Class> */ temp3 = temp2->component_type_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001603 __ LoadFromOffset(kLoadWord, temp3, temp2, component_offset);
1604 __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel());
1605 __ MaybeUnpoisonHeapReference(temp3);
1606 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1607 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1608 __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel());
1609 }
1610
1611 __ cmp(temp1, ShifterOperand(temp2));
1612
1613 if (optimizations.GetDestinationIsTypedObjectArray()) {
1614 Label do_copy;
1615 __ b(&do_copy, EQ);
1616 if (!did_unpoison) {
1617 __ MaybeUnpoisonHeapReference(temp1);
1618 }
Roland Levillainebea3d22016-04-12 15:42:57 +01001619 // /* HeapReference<Class> */ temp1 = temp1->component_type_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001620 __ LoadFromOffset(kLoadWord, temp1, temp1, component_offset);
1621 __ MaybeUnpoisonHeapReference(temp1);
Roland Levillainebea3d22016-04-12 15:42:57 +01001622 // /* HeapReference<Class> */ temp1 = temp1->super_class_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001623 __ LoadFromOffset(kLoadWord, temp1, temp1, super_offset);
1624 // No need to unpoison the result, we're comparing against null.
1625 __ CompareAndBranchIfNonZero(temp1, slow_path->GetEntryLabel());
1626 __ Bind(&do_copy);
1627 } else {
1628 __ b(slow_path->GetEntryLabel(), NE);
1629 }
1630 } else if (!optimizations.GetSourceIsNonPrimitiveArray()) {
1631 DCHECK(optimizations.GetDestinationIsNonPrimitiveArray());
1632 // Bail out if the source is not a non primitive array.
Roland Levillainebea3d22016-04-12 15:42:57 +01001633 // /* HeapReference<Class> */ temp1 = src->klass_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001634 __ LoadFromOffset(kLoadWord, temp1, src, class_offset);
1635 __ MaybeUnpoisonHeapReference(temp1);
Roland Levillainebea3d22016-04-12 15:42:57 +01001636 // /* HeapReference<Class> */ temp3 = temp1->component_type_
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001637 __ LoadFromOffset(kLoadWord, temp3, temp1, component_offset);
1638 __ CompareAndBranchIfZero(temp3, slow_path->GetEntryLabel());
1639 __ MaybeUnpoisonHeapReference(temp3);
1640 __ LoadFromOffset(kLoadUnsignedHalfword, temp3, temp3, primitive_offset);
1641 static_assert(Primitive::kPrimNot == 0, "Expected 0 for kPrimNot");
1642 __ CompareAndBranchIfNonZero(temp3, slow_path->GetEntryLabel());
1643 }
1644
1645 // Compute base source address, base destination address, and end source address.
1646
1647 uint32_t element_size = sizeof(int32_t);
1648 uint32_t offset = mirror::Array::DataOffset(element_size).Uint32Value();
1649 if (src_pos.IsConstant()) {
1650 int32_t constant = src_pos.GetConstant()->AsIntConstant()->GetValue();
1651 __ AddConstant(temp1, src, element_size * constant + offset);
1652 } else {
1653 __ add(temp1, src, ShifterOperand(src_pos.AsRegister<Register>(), LSL, 2));
1654 __ AddConstant(temp1, offset);
1655 }
1656
1657 if (dest_pos.IsConstant()) {
1658 int32_t constant = dest_pos.GetConstant()->AsIntConstant()->GetValue();
1659 __ AddConstant(temp2, dest, element_size * constant + offset);
1660 } else {
1661 __ add(temp2, dest, ShifterOperand(dest_pos.AsRegister<Register>(), LSL, 2));
1662 __ AddConstant(temp2, offset);
1663 }
1664
1665 if (length.IsConstant()) {
1666 int32_t constant = length.GetConstant()->AsIntConstant()->GetValue();
1667 __ AddConstant(temp3, temp1, element_size * constant);
1668 } else {
1669 __ add(temp3, temp1, ShifterOperand(length.AsRegister<Register>(), LSL, 2));
1670 }
1671
1672 // Iterate over the arrays and do a raw copy of the objects. We don't need to
1673 // poison/unpoison, nor do any read barrier as the next uses of the destination
1674 // array will do it.
1675 Label loop, done;
1676 __ cmp(temp1, ShifterOperand(temp3));
1677 __ b(&done, EQ);
1678 __ Bind(&loop);
1679 __ ldr(IP, Address(temp1, element_size, Address::PostIndex));
1680 __ str(IP, Address(temp2, element_size, Address::PostIndex));
1681 __ cmp(temp1, ShifterOperand(temp3));
1682 __ b(&loop, NE);
1683 __ Bind(&done);
1684
1685 // We only need one card marking on the destination array.
1686 codegen_->MarkGCCard(temp1,
1687 temp2,
1688 dest,
1689 Register(kNoRegister),
Roland Levillainebea3d22016-04-12 15:42:57 +01001690 /* value_can_be_null */ false);
Nicolas Geoffray5bd05a52015-10-13 09:48:30 +01001691
1692 __ Bind(slow_path->GetExitLabel());
1693}
1694
Anton Kirilovd70dc9d2016-02-04 14:59:04 +00001695static void CreateFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1696 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1697 // the code generator. Furthermore, the register allocator creates fixed live intervals
1698 // for all caller-saved registers because we are doing a function call. As a result, if
1699 // the input and output locations are unallocated, the register allocator runs out of
1700 // registers and fails; however, a debuggable graph is not the common case.
1701 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1702 return;
1703 }
1704
1705 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1706 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1707 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1708
1709 LocationSummary* const locations = new (arena) LocationSummary(invoke,
1710 LocationSummary::kCall,
1711 kIntrinsified);
1712 const InvokeRuntimeCallingConvention calling_convention;
1713
1714 locations->SetInAt(0, Location::RequiresFpuRegister());
1715 locations->SetOut(Location::RequiresFpuRegister());
1716 // Native code uses the soft float ABI.
1717 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1718 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1719}
1720
1721static void CreateFPFPToFPCallLocations(ArenaAllocator* arena, HInvoke* invoke) {
1722 // If the graph is debuggable, all callee-saved floating-point registers are blocked by
1723 // the code generator. Furthermore, the register allocator creates fixed live intervals
1724 // for all caller-saved registers because we are doing a function call. As a result, if
1725 // the input and output locations are unallocated, the register allocator runs out of
1726 // registers and fails; however, a debuggable graph is not the common case.
1727 if (invoke->GetBlock()->GetGraph()->IsDebuggable()) {
1728 return;
1729 }
1730
1731 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1732 DCHECK_EQ(invoke->InputAt(0)->GetType(), Primitive::kPrimDouble);
1733 DCHECK_EQ(invoke->InputAt(1)->GetType(), Primitive::kPrimDouble);
1734 DCHECK_EQ(invoke->GetType(), Primitive::kPrimDouble);
1735
1736 LocationSummary* const locations = new (arena) LocationSummary(invoke,
1737 LocationSummary::kCall,
1738 kIntrinsified);
1739 const InvokeRuntimeCallingConvention calling_convention;
1740
1741 locations->SetInAt(0, Location::RequiresFpuRegister());
1742 locations->SetInAt(1, Location::RequiresFpuRegister());
1743 locations->SetOut(Location::RequiresFpuRegister());
1744 // Native code uses the soft float ABI.
1745 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1746 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1747 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1748 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1749}
1750
1751static void GenFPToFPCall(HInvoke* invoke,
1752 ArmAssembler* assembler,
1753 CodeGeneratorARM* codegen,
1754 QuickEntrypointEnum entry) {
1755 LocationSummary* const locations = invoke->GetLocations();
1756 const InvokeRuntimeCallingConvention calling_convention;
1757
1758 DCHECK_EQ(invoke->GetNumberOfArguments(), 1U);
1759 DCHECK(locations->WillCall() && locations->Intrinsified());
1760 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
1761 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
1762
1763 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmWordSize>(entry).Int32Value());
1764 // Native code uses the soft float ABI.
1765 __ vmovrrd(calling_convention.GetRegisterAt(0),
1766 calling_convention.GetRegisterAt(1),
1767 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
1768 __ blx(LR);
1769 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
1770 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
1771 calling_convention.GetRegisterAt(0),
1772 calling_convention.GetRegisterAt(1));
1773}
1774
1775static void GenFPFPToFPCall(HInvoke* invoke,
1776 ArmAssembler* assembler,
1777 CodeGeneratorARM* codegen,
1778 QuickEntrypointEnum entry) {
1779 LocationSummary* const locations = invoke->GetLocations();
1780 const InvokeRuntimeCallingConvention calling_convention;
1781
1782 DCHECK_EQ(invoke->GetNumberOfArguments(), 2U);
1783 DCHECK(locations->WillCall() && locations->Intrinsified());
1784 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(0)));
1785 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(1)));
1786 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(2)));
1787 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(calling_convention.GetRegisterAt(3)));
1788
1789 __ LoadFromOffset(kLoadWord, LR, TR, GetThreadOffset<kArmWordSize>(entry).Int32Value());
1790 // Native code uses the soft float ABI.
1791 __ vmovrrd(calling_convention.GetRegisterAt(0),
1792 calling_convention.GetRegisterAt(1),
1793 FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
1794 __ vmovrrd(calling_convention.GetRegisterAt(2),
1795 calling_convention.GetRegisterAt(3),
1796 FromLowSToD(locations->InAt(1).AsFpuRegisterPairLow<SRegister>()));
1797 __ blx(LR);
1798 codegen->RecordPcInfo(invoke, invoke->GetDexPc());
1799 __ vmovdrr(FromLowSToD(locations->Out().AsFpuRegisterPairLow<SRegister>()),
1800 calling_convention.GetRegisterAt(0),
1801 calling_convention.GetRegisterAt(1));
1802}
1803
1804void IntrinsicLocationsBuilderARM::VisitMathCos(HInvoke* invoke) {
1805 CreateFPToFPCallLocations(arena_, invoke);
1806}
1807
1808void IntrinsicCodeGeneratorARM::VisitMathCos(HInvoke* invoke) {
1809 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCos);
1810}
1811
1812void IntrinsicLocationsBuilderARM::VisitMathSin(HInvoke* invoke) {
1813 CreateFPToFPCallLocations(arena_, invoke);
1814}
1815
1816void IntrinsicCodeGeneratorARM::VisitMathSin(HInvoke* invoke) {
1817 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSin);
1818}
1819
1820void IntrinsicLocationsBuilderARM::VisitMathAcos(HInvoke* invoke) {
1821 CreateFPToFPCallLocations(arena_, invoke);
1822}
1823
1824void IntrinsicCodeGeneratorARM::VisitMathAcos(HInvoke* invoke) {
1825 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAcos);
1826}
1827
1828void IntrinsicLocationsBuilderARM::VisitMathAsin(HInvoke* invoke) {
1829 CreateFPToFPCallLocations(arena_, invoke);
1830}
1831
1832void IntrinsicCodeGeneratorARM::VisitMathAsin(HInvoke* invoke) {
1833 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAsin);
1834}
1835
1836void IntrinsicLocationsBuilderARM::VisitMathAtan(HInvoke* invoke) {
1837 CreateFPToFPCallLocations(arena_, invoke);
1838}
1839
1840void IntrinsicCodeGeneratorARM::VisitMathAtan(HInvoke* invoke) {
1841 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan);
1842}
1843
1844void IntrinsicLocationsBuilderARM::VisitMathCbrt(HInvoke* invoke) {
1845 CreateFPToFPCallLocations(arena_, invoke);
1846}
1847
1848void IntrinsicCodeGeneratorARM::VisitMathCbrt(HInvoke* invoke) {
1849 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCbrt);
1850}
1851
1852void IntrinsicLocationsBuilderARM::VisitMathCosh(HInvoke* invoke) {
1853 CreateFPToFPCallLocations(arena_, invoke);
1854}
1855
1856void IntrinsicCodeGeneratorARM::VisitMathCosh(HInvoke* invoke) {
1857 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickCosh);
1858}
1859
1860void IntrinsicLocationsBuilderARM::VisitMathExp(HInvoke* invoke) {
1861 CreateFPToFPCallLocations(arena_, invoke);
1862}
1863
1864void IntrinsicCodeGeneratorARM::VisitMathExp(HInvoke* invoke) {
1865 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExp);
1866}
1867
1868void IntrinsicLocationsBuilderARM::VisitMathExpm1(HInvoke* invoke) {
1869 CreateFPToFPCallLocations(arena_, invoke);
1870}
1871
1872void IntrinsicCodeGeneratorARM::VisitMathExpm1(HInvoke* invoke) {
1873 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickExpm1);
1874}
1875
1876void IntrinsicLocationsBuilderARM::VisitMathLog(HInvoke* invoke) {
1877 CreateFPToFPCallLocations(arena_, invoke);
1878}
1879
1880void IntrinsicCodeGeneratorARM::VisitMathLog(HInvoke* invoke) {
1881 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog);
1882}
1883
1884void IntrinsicLocationsBuilderARM::VisitMathLog10(HInvoke* invoke) {
1885 CreateFPToFPCallLocations(arena_, invoke);
1886}
1887
1888void IntrinsicCodeGeneratorARM::VisitMathLog10(HInvoke* invoke) {
1889 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickLog10);
1890}
1891
1892void IntrinsicLocationsBuilderARM::VisitMathSinh(HInvoke* invoke) {
1893 CreateFPToFPCallLocations(arena_, invoke);
1894}
1895
1896void IntrinsicCodeGeneratorARM::VisitMathSinh(HInvoke* invoke) {
1897 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickSinh);
1898}
1899
1900void IntrinsicLocationsBuilderARM::VisitMathTan(HInvoke* invoke) {
1901 CreateFPToFPCallLocations(arena_, invoke);
1902}
1903
1904void IntrinsicCodeGeneratorARM::VisitMathTan(HInvoke* invoke) {
1905 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTan);
1906}
1907
1908void IntrinsicLocationsBuilderARM::VisitMathTanh(HInvoke* invoke) {
1909 CreateFPToFPCallLocations(arena_, invoke);
1910}
1911
1912void IntrinsicCodeGeneratorARM::VisitMathTanh(HInvoke* invoke) {
1913 GenFPToFPCall(invoke, GetAssembler(), codegen_, kQuickTanh);
1914}
1915
1916void IntrinsicLocationsBuilderARM::VisitMathAtan2(HInvoke* invoke) {
1917 CreateFPFPToFPCallLocations(arena_, invoke);
1918}
1919
1920void IntrinsicCodeGeneratorARM::VisitMathAtan2(HInvoke* invoke) {
1921 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickAtan2);
1922}
1923
1924void IntrinsicLocationsBuilderARM::VisitMathHypot(HInvoke* invoke) {
1925 CreateFPFPToFPCallLocations(arena_, invoke);
1926}
1927
1928void IntrinsicCodeGeneratorARM::VisitMathHypot(HInvoke* invoke) {
1929 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickHypot);
1930}
1931
1932void IntrinsicLocationsBuilderARM::VisitMathNextAfter(HInvoke* invoke) {
1933 CreateFPFPToFPCallLocations(arena_, invoke);
1934}
1935
1936void IntrinsicCodeGeneratorARM::VisitMathNextAfter(HInvoke* invoke) {
1937 GenFPFPToFPCall(invoke, GetAssembler(), codegen_, kQuickNextAfter);
1938}
1939
Artem Serovc257da72016-02-02 13:49:43 +00001940void IntrinsicLocationsBuilderARM::VisitIntegerReverse(HInvoke* invoke) {
1941 CreateIntToIntLocations(arena_, invoke);
1942}
1943
1944void IntrinsicCodeGeneratorARM::VisitIntegerReverse(HInvoke* invoke) {
1945 ArmAssembler* assembler = GetAssembler();
1946 LocationSummary* locations = invoke->GetLocations();
1947
1948 Register out = locations->Out().AsRegister<Register>();
1949 Register in = locations->InAt(0).AsRegister<Register>();
1950
1951 __ rbit(out, in);
1952}
1953
1954void IntrinsicLocationsBuilderARM::VisitLongReverse(HInvoke* invoke) {
1955 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1956 LocationSummary::kNoCall,
1957 kIntrinsified);
1958 locations->SetInAt(0, Location::RequiresRegister());
1959 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1960}
1961
1962void IntrinsicCodeGeneratorARM::VisitLongReverse(HInvoke* invoke) {
1963 ArmAssembler* assembler = GetAssembler();
1964 LocationSummary* locations = invoke->GetLocations();
1965
1966 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1967 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1968 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
1969 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
1970
1971 __ rbit(out_reg_lo, in_reg_hi);
1972 __ rbit(out_reg_hi, in_reg_lo);
1973}
1974
1975void IntrinsicLocationsBuilderARM::VisitIntegerReverseBytes(HInvoke* invoke) {
1976 CreateIntToIntLocations(arena_, invoke);
1977}
1978
1979void IntrinsicCodeGeneratorARM::VisitIntegerReverseBytes(HInvoke* invoke) {
1980 ArmAssembler* assembler = GetAssembler();
1981 LocationSummary* locations = invoke->GetLocations();
1982
1983 Register out = locations->Out().AsRegister<Register>();
1984 Register in = locations->InAt(0).AsRegister<Register>();
1985
1986 __ rev(out, in);
1987}
1988
1989void IntrinsicLocationsBuilderARM::VisitLongReverseBytes(HInvoke* invoke) {
1990 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1991 LocationSummary::kNoCall,
1992 kIntrinsified);
1993 locations->SetInAt(0, Location::RequiresRegister());
1994 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
1995}
1996
1997void IntrinsicCodeGeneratorARM::VisitLongReverseBytes(HInvoke* invoke) {
1998 ArmAssembler* assembler = GetAssembler();
1999 LocationSummary* locations = invoke->GetLocations();
2000
2001 Register in_reg_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2002 Register in_reg_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2003 Register out_reg_lo = locations->Out().AsRegisterPairLow<Register>();
2004 Register out_reg_hi = locations->Out().AsRegisterPairHigh<Register>();
2005
2006 __ rev(out_reg_lo, in_reg_hi);
2007 __ rev(out_reg_hi, in_reg_lo);
2008}
2009
2010void IntrinsicLocationsBuilderARM::VisitShortReverseBytes(HInvoke* invoke) {
2011 CreateIntToIntLocations(arena_, invoke);
2012}
2013
2014void IntrinsicCodeGeneratorARM::VisitShortReverseBytes(HInvoke* invoke) {
2015 ArmAssembler* assembler = GetAssembler();
2016 LocationSummary* locations = invoke->GetLocations();
2017
2018 Register out = locations->Out().AsRegister<Register>();
2019 Register in = locations->InAt(0).AsRegister<Register>();
2020
2021 __ revsh(out, in);
2022}
2023
Tim Zhang25abd6c2016-01-19 23:39:24 +08002024void IntrinsicLocationsBuilderARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2025 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2026 LocationSummary::kNoCall,
2027 kIntrinsified);
2028 locations->SetInAt(0, Location::RequiresRegister());
2029 locations->SetInAt(1, Location::RequiresRegister());
2030 locations->SetInAt(2, Location::RequiresRegister());
2031 locations->SetInAt(3, Location::RequiresRegister());
2032 locations->SetInAt(4, Location::RequiresRegister());
2033
2034 locations->AddTemp(Location::RequiresRegister());
2035 locations->AddTemp(Location::RequiresRegister());
2036 locations->AddTemp(Location::RequiresRegister());
2037 locations->AddTemp(Location::RequiresRegister());
2038}
2039
2040void IntrinsicCodeGeneratorARM::VisitStringGetCharsNoCheck(HInvoke* invoke) {
2041 ArmAssembler* assembler = GetAssembler();
2042 LocationSummary* locations = invoke->GetLocations();
2043
2044 // Check assumption that sizeof(Char) is 2 (used in scaling below).
2045 const size_t char_size = Primitive::ComponentSize(Primitive::kPrimChar);
2046 DCHECK_EQ(char_size, 2u);
2047
2048 // Location of data in char array buffer.
2049 const uint32_t data_offset = mirror::Array::DataOffset(char_size).Uint32Value();
2050
2051 // Location of char array data in string.
2052 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
2053
2054 // void getCharsNoCheck(int srcBegin, int srcEnd, char[] dst, int dstBegin);
2055 // Since getChars() calls getCharsNoCheck() - we use registers rather than constants.
2056 Register srcObj = locations->InAt(0).AsRegister<Register>();
2057 Register srcBegin = locations->InAt(1).AsRegister<Register>();
2058 Register srcEnd = locations->InAt(2).AsRegister<Register>();
2059 Register dstObj = locations->InAt(3).AsRegister<Register>();
2060 Register dstBegin = locations->InAt(4).AsRegister<Register>();
2061
2062 Register src_ptr = locations->GetTemp(0).AsRegister<Register>();
2063 Register src_ptr_end = locations->GetTemp(1).AsRegister<Register>();
2064 Register dst_ptr = locations->GetTemp(2).AsRegister<Register>();
2065 Register tmp = locations->GetTemp(3).AsRegister<Register>();
2066
2067 // src range to copy.
2068 __ add(src_ptr, srcObj, ShifterOperand(value_offset));
2069 __ add(src_ptr_end, src_ptr, ShifterOperand(srcEnd, LSL, 1));
2070 __ add(src_ptr, src_ptr, ShifterOperand(srcBegin, LSL, 1));
2071
2072 // dst to be copied.
2073 __ add(dst_ptr, dstObj, ShifterOperand(data_offset));
2074 __ add(dst_ptr, dst_ptr, ShifterOperand(dstBegin, LSL, 1));
2075
2076 // Do the copy.
2077 Label loop, done;
2078 __ Bind(&loop);
2079 __ cmp(src_ptr, ShifterOperand(src_ptr_end));
2080 __ b(&done, EQ);
2081 __ ldrh(tmp, Address(src_ptr, char_size, Address::PostIndex));
2082 __ strh(tmp, Address(dst_ptr, char_size, Address::PostIndex));
2083 __ b(&loop);
2084 __ Bind(&done);
2085}
2086
Anton Kirilova3ffea22016-04-07 17:02:37 +01002087void IntrinsicLocationsBuilderARM::VisitFloatIsInfinite(HInvoke* invoke) {
2088 CreateFPToIntLocations(arena_, invoke);
2089}
2090
2091void IntrinsicCodeGeneratorARM::VisitFloatIsInfinite(HInvoke* invoke) {
2092 ArmAssembler* const assembler = GetAssembler();
2093 LocationSummary* const locations = invoke->GetLocations();
2094 const Register out = locations->Out().AsRegister<Register>();
2095 // Shifting left by 1 bit makes the value encodable as an immediate operand;
2096 // we don't care about the sign bit anyway.
2097 constexpr uint32_t infinity = kPositiveInfinityFloat << 1U;
2098
2099 __ vmovrs(out, locations->InAt(0).AsFpuRegister<SRegister>());
2100 // We don't care about the sign bit, so shift left.
2101 __ Lsl(out, out, 1);
2102 __ eor(out, out, ShifterOperand(infinity));
2103 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2104 __ clz(out, out);
2105 // Any number less than 32 logically shifted right by 5 bits results in 0;
2106 // the same operation on 32 yields 1.
2107 __ Lsr(out, out, 5);
2108}
2109
2110void IntrinsicLocationsBuilderARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2111 CreateFPToIntLocations(arena_, invoke);
2112}
2113
2114void IntrinsicCodeGeneratorARM::VisitDoubleIsInfinite(HInvoke* invoke) {
2115 ArmAssembler* const assembler = GetAssembler();
2116 LocationSummary* const locations = invoke->GetLocations();
2117 const Register out = locations->Out().AsRegister<Register>();
2118 // The highest 32 bits of double precision positive infinity separated into
2119 // two constants encodable as immediate operands.
2120 constexpr uint32_t infinity_high = 0x7f000000U;
2121 constexpr uint32_t infinity_high2 = 0x00f00000U;
2122
2123 static_assert((infinity_high | infinity_high2) == static_cast<uint32_t>(kPositiveInfinityDouble >> 32U),
2124 "The constants do not add up to the high 32 bits of double precision positive infinity.");
2125 __ vmovrrd(IP, out, FromLowSToD(locations->InAt(0).AsFpuRegisterPairLow<SRegister>()));
2126 __ eor(out, out, ShifterOperand(infinity_high));
2127 __ eor(out, out, ShifterOperand(infinity_high2));
2128 // We don't care about the sign bit, so shift left.
2129 __ orr(out, IP, ShifterOperand(out, LSL, 1));
2130 // If the result is 0, then it has 32 leading zeros, and less than that otherwise.
2131 __ clz(out, out);
2132 // Any number less than 32 logically shifted right by 5 bits results in 0;
2133 // the same operation on 32 yields 1.
2134 __ Lsr(out, out, 5);
2135}
2136
Aart Bik2f9fcc92016-03-01 15:16:54 -08002137UNIMPLEMENTED_INTRINSIC(ARM, IntegerBitCount)
2138UNIMPLEMENTED_INTRINSIC(ARM, LongBitCount)
2139UNIMPLEMENTED_INTRINSIC(ARM, MathMinDoubleDouble)
2140UNIMPLEMENTED_INTRINSIC(ARM, MathMinFloatFloat)
2141UNIMPLEMENTED_INTRINSIC(ARM, MathMaxDoubleDouble)
2142UNIMPLEMENTED_INTRINSIC(ARM, MathMaxFloatFloat)
2143UNIMPLEMENTED_INTRINSIC(ARM, MathMinLongLong)
2144UNIMPLEMENTED_INTRINSIC(ARM, MathMaxLongLong)
2145UNIMPLEMENTED_INTRINSIC(ARM, MathCeil) // Could be done by changing rounding mode, maybe?
2146UNIMPLEMENTED_INTRINSIC(ARM, MathFloor) // Could be done by changing rounding mode, maybe?
2147UNIMPLEMENTED_INTRINSIC(ARM, MathRint)
2148UNIMPLEMENTED_INTRINSIC(ARM, MathRoundDouble) // Could be done by changing rounding mode, maybe?
2149UNIMPLEMENTED_INTRINSIC(ARM, MathRoundFloat) // Could be done by changing rounding mode, maybe?
2150UNIMPLEMENTED_INTRINSIC(ARM, UnsafeCASLong) // High register pressure.
2151UNIMPLEMENTED_INTRINSIC(ARM, SystemArrayCopyChar)
2152UNIMPLEMENTED_INTRINSIC(ARM, ReferenceGetReferent)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002153UNIMPLEMENTED_INTRINSIC(ARM, IntegerHighestOneBit)
2154UNIMPLEMENTED_INTRINSIC(ARM, LongHighestOneBit)
2155UNIMPLEMENTED_INTRINSIC(ARM, IntegerLowestOneBit)
2156UNIMPLEMENTED_INTRINSIC(ARM, LongLowestOneBit)
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002157
Aart Bik0e54c012016-03-04 12:08:31 -08002158// 1.8.
2159UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddInt)
2160UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndAddLong)
2161UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetInt)
2162UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetLong)
2163UNIMPLEMENTED_INTRINSIC(ARM, UnsafeGetAndSetObject)
Aart Bik0e54c012016-03-04 12:08:31 -08002164
Aart Bik2f9fcc92016-03-01 15:16:54 -08002165UNREACHABLE_INTRINSICS(ARM)
Roland Levillain4d027112015-07-01 15:41:14 +01002166
2167#undef __
2168
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -08002169} // namespace arm
2170} // namespace art