blob: ff843ebb1ec52e2ca7e9244664a94f7f0d88df36 [file] [log] [blame]
Chris Larsen3039e382015-08-26 07:54:08 -07001/*
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_mips64.h"
18
19#include "arch/mips64/instruction_set_features_mips64.h"
20#include "art_method.h"
21#include "code_generator_mips64.h"
22#include "entrypoints/quick/quick_entrypoints.h"
23#include "intrinsics.h"
24#include "mirror/array-inl.h"
25#include "mirror/string.h"
26#include "thread.h"
27#include "utils/mips64/assembler_mips64.h"
28#include "utils/mips64/constants_mips64.h"
29
30namespace art {
31
32namespace mips64 {
33
34IntrinsicLocationsBuilderMIPS64::IntrinsicLocationsBuilderMIPS64(CodeGeneratorMIPS64* codegen)
35 : arena_(codegen->GetGraph()->GetArena()) {
36}
37
38Mips64Assembler* IntrinsicCodeGeneratorMIPS64::GetAssembler() {
39 return reinterpret_cast<Mips64Assembler*>(codegen_->GetAssembler());
40}
41
42ArenaAllocator* IntrinsicCodeGeneratorMIPS64::GetAllocator() {
43 return codegen_->GetGraph()->GetArena();
44}
45
Chris Larsen9701c2e2015-09-04 17:22:47 -070046#define __ codegen->GetAssembler()->
47
48static void MoveFromReturnRegister(Location trg,
49 Primitive::Type type,
50 CodeGeneratorMIPS64* codegen) {
51 if (!trg.IsValid()) {
52 DCHECK_EQ(type, Primitive::kPrimVoid);
53 return;
54 }
55
56 DCHECK_NE(type, Primitive::kPrimVoid);
57
58 if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) {
59 GpuRegister trg_reg = trg.AsRegister<GpuRegister>();
60 if (trg_reg != V0) {
61 __ Move(V0, trg_reg);
62 }
63 } else {
64 FpuRegister trg_reg = trg.AsFpuRegister<FpuRegister>();
65 if (trg_reg != F0) {
66 if (type == Primitive::kPrimFloat) {
67 __ MovS(F0, trg_reg);
68 } else {
69 __ MovD(F0, trg_reg);
70 }
71 }
72 }
73}
74
75static void MoveArguments(HInvoke* invoke, CodeGeneratorMIPS64* codegen) {
76 InvokeDexCallingConventionVisitorMIPS64 calling_convention_visitor;
77 IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor);
78}
79
80// Slow-path for fallback (calling the managed code to handle the
81// intrinsic) in an intrinsified call. This will copy the arguments
82// into the positions for a regular call.
83//
84// Note: The actual parameters are required to be in the locations
85// given by the invoke's location summary. If an intrinsic
86// modifies those locations before a slowpath call, they must be
87// restored!
88class IntrinsicSlowPathMIPS64 : public SlowPathCodeMIPS64 {
89 public:
90 explicit IntrinsicSlowPathMIPS64(HInvoke* invoke) : invoke_(invoke) { }
91
92 void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE {
93 CodeGeneratorMIPS64* codegen = down_cast<CodeGeneratorMIPS64*>(codegen_in);
94
95 __ Bind(GetEntryLabel());
96
97 SaveLiveRegisters(codegen, invoke_->GetLocations());
98
99 MoveArguments(invoke_, codegen);
100
101 if (invoke_->IsInvokeStaticOrDirect()) {
102 codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(),
103 Location::RegisterLocation(A0));
Chris Larsen9701c2e2015-09-04 17:22:47 -0700104 } else {
Alexey Frunze53afca12015-11-05 16:34:23 -0800105 codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), Location::RegisterLocation(A0));
Chris Larsen9701c2e2015-09-04 17:22:47 -0700106 }
Alexey Frunze53afca12015-11-05 16:34:23 -0800107 codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this);
Chris Larsen9701c2e2015-09-04 17:22:47 -0700108
109 // Copy the result back to the expected output.
110 Location out = invoke_->GetLocations()->Out();
111 if (out.IsValid()) {
112 DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory.
113 DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
114 MoveFromReturnRegister(out, invoke_->GetType(), codegen);
115 }
116
117 RestoreLiveRegisters(codegen, invoke_->GetLocations());
118 __ B(GetExitLabel());
119 }
120
121 const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathMIPS64"; }
122
123 private:
124 // The instruction where this slow path is happening.
125 HInvoke* const invoke_;
126
127 DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathMIPS64);
128};
129
130#undef __
131
Chris Larsen3039e382015-08-26 07:54:08 -0700132bool IntrinsicLocationsBuilderMIPS64::TryDispatch(HInvoke* invoke) {
133 Dispatch(invoke);
134 LocationSummary* res = invoke->GetLocations();
135 return res != nullptr && res->Intrinsified();
136}
137
138#define __ assembler->
139
140static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
141 LocationSummary* locations = new (arena) LocationSummary(invoke,
142 LocationSummary::kNoCall,
143 kIntrinsified);
144 locations->SetInAt(0, Location::RequiresFpuRegister());
145 locations->SetOut(Location::RequiresRegister());
146}
147
148static void MoveFPToInt(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
149 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
150 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
151
152 if (is64bit) {
153 __ Dmfc1(out, in);
154 } else {
155 __ Mfc1(out, in);
156 }
157}
158
159// long java.lang.Double.doubleToRawLongBits(double)
160void IntrinsicLocationsBuilderMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
161 CreateFPToIntLocations(arena_, invoke);
162}
163
164void IntrinsicCodeGeneratorMIPS64::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
165 MoveFPToInt(invoke->GetLocations(), true, GetAssembler());
166}
167
168// int java.lang.Float.floatToRawIntBits(float)
169void IntrinsicLocationsBuilderMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
170 CreateFPToIntLocations(arena_, invoke);
171}
172
173void IntrinsicCodeGeneratorMIPS64::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
174 MoveFPToInt(invoke->GetLocations(), false, GetAssembler());
175}
176
177static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
178 LocationSummary* locations = new (arena) LocationSummary(invoke,
179 LocationSummary::kNoCall,
180 kIntrinsified);
181 locations->SetInAt(0, Location::RequiresRegister());
182 locations->SetOut(Location::RequiresFpuRegister());
183}
184
185static void MoveIntToFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
186 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
187 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
188
189 if (is64bit) {
190 __ Dmtc1(in, out);
191 } else {
192 __ Mtc1(in, out);
193 }
194}
195
196// double java.lang.Double.longBitsToDouble(long)
197void IntrinsicLocationsBuilderMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
198 CreateIntToFPLocations(arena_, invoke);
199}
200
201void IntrinsicCodeGeneratorMIPS64::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
202 MoveIntToFP(invoke->GetLocations(), true, GetAssembler());
203}
204
205// float java.lang.Float.intBitsToFloat(int)
206void IntrinsicLocationsBuilderMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
207 CreateIntToFPLocations(arena_, invoke);
208}
209
210void IntrinsicCodeGeneratorMIPS64::VisitFloatIntBitsToFloat(HInvoke* invoke) {
211 MoveIntToFP(invoke->GetLocations(), false, GetAssembler());
212}
213
214static void CreateIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
215 LocationSummary* locations = new (arena) LocationSummary(invoke,
216 LocationSummary::kNoCall,
217 kIntrinsified);
218 locations->SetInAt(0, Location::RequiresRegister());
219 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
220}
221
222static void GenReverseBytes(LocationSummary* locations,
223 Primitive::Type type,
224 Mips64Assembler* assembler) {
225 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
226 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
227
228 switch (type) {
229 case Primitive::kPrimShort:
230 __ Dsbh(out, in);
231 __ Seh(out, out);
232 break;
233 case Primitive::kPrimInt:
234 __ Rotr(out, in, 16);
235 __ Wsbh(out, out);
236 break;
237 case Primitive::kPrimLong:
238 __ Dsbh(out, in);
239 __ Dshd(out, out);
240 break;
241 default:
242 LOG(FATAL) << "Unexpected size for reverse-bytes: " << type;
243 UNREACHABLE();
244 }
245}
246
247// int java.lang.Integer.reverseBytes(int)
248void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) {
249 CreateIntToIntLocations(arena_, invoke);
250}
251
252void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverseBytes(HInvoke* invoke) {
253 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
254}
255
256// long java.lang.Long.reverseBytes(long)
257void IntrinsicLocationsBuilderMIPS64::VisitLongReverseBytes(HInvoke* invoke) {
258 CreateIntToIntLocations(arena_, invoke);
259}
260
261void IntrinsicCodeGeneratorMIPS64::VisitLongReverseBytes(HInvoke* invoke) {
262 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
263}
264
265// short java.lang.Short.reverseBytes(short)
266void IntrinsicLocationsBuilderMIPS64::VisitShortReverseBytes(HInvoke* invoke) {
267 CreateIntToIntLocations(arena_, invoke);
268}
269
270void IntrinsicCodeGeneratorMIPS64::VisitShortReverseBytes(HInvoke* invoke) {
271 GenReverseBytes(invoke->GetLocations(), Primitive::kPrimShort, GetAssembler());
272}
273
Chris Larsen81284372015-10-21 15:28:53 -0700274static void GenNumberOfLeadingZeroes(LocationSummary* locations,
275 bool is64bit,
276 Mips64Assembler* assembler) {
Chris Larsen3039e382015-08-26 07:54:08 -0700277 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
278 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
279
280 if (is64bit) {
281 __ Dclz(out, in);
282 } else {
283 __ Clz(out, in);
284 }
285}
286
287// int java.lang.Integer.numberOfLeadingZeros(int i)
288void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
289 CreateIntToIntLocations(arena_, invoke);
290}
291
292void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
Chris Larsen0646da72015-09-22 16:02:40 -0700293 GenNumberOfLeadingZeroes(invoke->GetLocations(), false, GetAssembler());
Chris Larsen3039e382015-08-26 07:54:08 -0700294}
295
296// int java.lang.Long.numberOfLeadingZeros(long i)
297void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
298 CreateIntToIntLocations(arena_, invoke);
299}
300
301void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
Chris Larsen0646da72015-09-22 16:02:40 -0700302 GenNumberOfLeadingZeroes(invoke->GetLocations(), true, GetAssembler());
303}
304
Chris Larsen81284372015-10-21 15:28:53 -0700305static void GenNumberOfTrailingZeroes(LocationSummary* locations,
306 bool is64bit,
307 Mips64Assembler* assembler) {
Chris Larsen0646da72015-09-22 16:02:40 -0700308 Location in = locations->InAt(0);
309 Location out = locations->Out();
310
311 if (is64bit) {
312 __ Dsbh(out.AsRegister<GpuRegister>(), in.AsRegister<GpuRegister>());
313 __ Dshd(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
314 __ Dbitswap(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
315 __ Dclz(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
316 } else {
317 __ Rotr(out.AsRegister<GpuRegister>(), in.AsRegister<GpuRegister>(), 16);
318 __ Wsbh(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
319 __ Bitswap(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
320 __ Clz(out.AsRegister<GpuRegister>(), out.AsRegister<GpuRegister>());
321 }
322}
323
324// int java.lang.Integer.numberOfTrailingZeros(int i)
325void IntrinsicLocationsBuilderMIPS64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
326 CreateIntToIntLocations(arena_, invoke);
327}
328
329void IntrinsicCodeGeneratorMIPS64::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
330 GenNumberOfTrailingZeroes(invoke->GetLocations(), false, GetAssembler());
331}
332
333// int java.lang.Long.numberOfTrailingZeros(long i)
334void IntrinsicLocationsBuilderMIPS64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
335 CreateIntToIntLocations(arena_, invoke);
336}
337
338void IntrinsicCodeGeneratorMIPS64::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
339 GenNumberOfTrailingZeroes(invoke->GetLocations(), true, GetAssembler());
Chris Larsen3039e382015-08-26 07:54:08 -0700340}
341
Chris Larsen9aebff22015-09-22 17:54:15 -0700342static void GenRotateRight(HInvoke* invoke,
343 Primitive::Type type,
344 Mips64Assembler* assembler) {
345 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
346
347 LocationSummary* locations = invoke->GetLocations();
348 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
349 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
350
351 if (invoke->InputAt(1)->IsIntConstant()) {
352 uint32_t shift = static_cast<uint32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue());
353 if (type == Primitive::kPrimInt) {
354 shift &= 0x1f;
355 __ Rotr(out, in, shift);
356 } else {
357 shift &= 0x3f;
358 if (shift < 32) {
359 __ Drotr(out, in, shift);
360 } else {
361 shift &= 0x1f;
362 __ Drotr32(out, in, shift);
363 }
364 }
365 } else {
366 GpuRegister shamt = locations->InAt(1).AsRegister<GpuRegister>();
367 if (type == Primitive::kPrimInt) {
368 __ Rotrv(out, in, shamt);
369 } else {
370 __ Drotrv(out, in, shamt);
371 }
372 }
373}
374
375// int java.lang.Integer.rotateRight(int i, int distance)
376void IntrinsicLocationsBuilderMIPS64::VisitIntegerRotateRight(HInvoke* invoke) {
377 LocationSummary* locations = new (arena_) LocationSummary(invoke,
378 LocationSummary::kNoCall,
379 kIntrinsified);
380 locations->SetInAt(0, Location::RequiresRegister());
381 locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
382 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
383}
384
385void IntrinsicCodeGeneratorMIPS64::VisitIntegerRotateRight(HInvoke* invoke) {
386 GenRotateRight(invoke, Primitive::kPrimInt, GetAssembler());
387}
388
Chris Larsen81284372015-10-21 15:28:53 -0700389// long java.lang.Long.rotateRight(long i, int distance)
Chris Larsen9aebff22015-09-22 17:54:15 -0700390void IntrinsicLocationsBuilderMIPS64::VisitLongRotateRight(HInvoke* invoke) {
391 LocationSummary* locations = new (arena_) LocationSummary(invoke,
392 LocationSummary::kNoCall,
393 kIntrinsified);
394 locations->SetInAt(0, Location::RequiresRegister());
395 locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
396 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
397}
398
399void IntrinsicCodeGeneratorMIPS64::VisitLongRotateRight(HInvoke* invoke) {
400 GenRotateRight(invoke, Primitive::kPrimLong, GetAssembler());
401}
402
Chris Larsen0f8f8642015-10-02 17:25:58 -0700403static void GenRotateLeft(HInvoke* invoke,
404 Primitive::Type type,
405 Mips64Assembler* assembler) {
406 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
407
408 LocationSummary* locations = invoke->GetLocations();
409 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
410 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
411
412 if (invoke->InputAt(1)->IsIntConstant()) {
413 int32_t shift = -static_cast<int32_t>(invoke->InputAt(1)->AsIntConstant()->GetValue());
414 if (type == Primitive::kPrimInt) {
415 shift &= 0x1f;
416 __ Rotr(out, in, shift);
417 } else {
418 shift &= 0x3f;
419 if (shift < 32) {
420 __ Drotr(out, in, shift);
421 } else {
422 shift &= 0x1f;
423 __ Drotr32(out, in, shift);
424 }
425 }
426 } else {
427 GpuRegister shamt = locations->InAt(1).AsRegister<GpuRegister>();
428 if (type == Primitive::kPrimInt) {
429 __ Subu(TMP, ZERO, shamt);
430 __ Rotrv(out, in, TMP);
431 } else {
432 __ Dsubu(TMP, ZERO, shamt);
433 __ Drotrv(out, in, TMP);
434 }
435 }
436}
437
438// int java.lang.Integer.rotateLeft(int i, int distance)
439void IntrinsicLocationsBuilderMIPS64::VisitIntegerRotateLeft(HInvoke* invoke) {
440 LocationSummary* locations = new (arena_) LocationSummary(invoke,
441 LocationSummary::kNoCall,
442 kIntrinsified);
443 locations->SetInAt(0, Location::RequiresRegister());
444 locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
445 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
446}
447
448void IntrinsicCodeGeneratorMIPS64::VisitIntegerRotateLeft(HInvoke* invoke) {
449 GenRotateLeft(invoke, Primitive::kPrimInt, GetAssembler());
450}
451
Chris Larsen81284372015-10-21 15:28:53 -0700452// long java.lang.Long.rotateLeft(long i, int distance)
Chris Larsen0f8f8642015-10-02 17:25:58 -0700453void IntrinsicLocationsBuilderMIPS64::VisitLongRotateLeft(HInvoke* invoke) {
454 LocationSummary* locations = new (arena_) LocationSummary(invoke,
455 LocationSummary::kNoCall,
456 kIntrinsified);
457 locations->SetInAt(0, Location::RequiresRegister());
458 locations->SetInAt(1, Location::RegisterOrConstant(invoke->InputAt(1)));
459 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
460}
461
462void IntrinsicCodeGeneratorMIPS64::VisitLongRotateLeft(HInvoke* invoke) {
463 GenRotateLeft(invoke, Primitive::kPrimLong, GetAssembler());
464}
465
Chris Larsen3039e382015-08-26 07:54:08 -0700466static void GenReverse(LocationSummary* locations,
467 Primitive::Type type,
468 Mips64Assembler* assembler) {
469 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
470
471 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
472 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
473
474 if (type == Primitive::kPrimInt) {
475 __ Rotr(out, in, 16);
476 __ Wsbh(out, out);
477 __ Bitswap(out, out);
478 } else {
479 __ Dsbh(out, in);
480 __ Dshd(out, out);
481 __ Dbitswap(out, out);
482 }
483}
484
485// int java.lang.Integer.reverse(int)
486void IntrinsicLocationsBuilderMIPS64::VisitIntegerReverse(HInvoke* invoke) {
487 CreateIntToIntLocations(arena_, invoke);
488}
489
490void IntrinsicCodeGeneratorMIPS64::VisitIntegerReverse(HInvoke* invoke) {
491 GenReverse(invoke->GetLocations(), Primitive::kPrimInt, GetAssembler());
492}
493
494// long java.lang.Long.reverse(long)
495void IntrinsicLocationsBuilderMIPS64::VisitLongReverse(HInvoke* invoke) {
496 CreateIntToIntLocations(arena_, invoke);
497}
498
499void IntrinsicCodeGeneratorMIPS64::VisitLongReverse(HInvoke* invoke) {
500 GenReverse(invoke->GetLocations(), Primitive::kPrimLong, GetAssembler());
501}
502
Chris Larsen0b7ac982015-09-04 12:54:28 -0700503static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
504 LocationSummary* locations = new (arena) LocationSummary(invoke,
505 LocationSummary::kNoCall,
506 kIntrinsified);
507 locations->SetInAt(0, Location::RequiresFpuRegister());
508 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
509}
510
511static void MathAbsFP(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
512 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
513 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
514
515 if (is64bit) {
516 __ AbsD(out, in);
517 } else {
518 __ AbsS(out, in);
519 }
520}
521
522// double java.lang.Math.abs(double)
523void IntrinsicLocationsBuilderMIPS64::VisitMathAbsDouble(HInvoke* invoke) {
524 CreateFPToFPLocations(arena_, invoke);
525}
526
527void IntrinsicCodeGeneratorMIPS64::VisitMathAbsDouble(HInvoke* invoke) {
528 MathAbsFP(invoke->GetLocations(), true, GetAssembler());
529}
530
531// float java.lang.Math.abs(float)
532void IntrinsicLocationsBuilderMIPS64::VisitMathAbsFloat(HInvoke* invoke) {
533 CreateFPToFPLocations(arena_, invoke);
534}
535
536void IntrinsicCodeGeneratorMIPS64::VisitMathAbsFloat(HInvoke* invoke) {
537 MathAbsFP(invoke->GetLocations(), false, GetAssembler());
538}
539
540static void CreateIntToInt(ArenaAllocator* arena, HInvoke* invoke) {
541 LocationSummary* locations = new (arena) LocationSummary(invoke,
542 LocationSummary::kNoCall,
543 kIntrinsified);
544 locations->SetInAt(0, Location::RequiresRegister());
545 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
546}
547
548static void GenAbsInteger(LocationSummary* locations, bool is64bit, Mips64Assembler* assembler) {
549 GpuRegister in = locations->InAt(0).AsRegister<GpuRegister>();
550 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
551
552 if (is64bit) {
553 __ Dsra32(AT, in, 31);
554 __ Xor(out, in, AT);
555 __ Dsubu(out, out, AT);
556 } else {
557 __ Sra(AT, in, 31);
558 __ Xor(out, in, AT);
559 __ Subu(out, out, AT);
560 }
561}
562
563// int java.lang.Math.abs(int)
564void IntrinsicLocationsBuilderMIPS64::VisitMathAbsInt(HInvoke* invoke) {
565 CreateIntToInt(arena_, invoke);
566}
567
568void IntrinsicCodeGeneratorMIPS64::VisitMathAbsInt(HInvoke* invoke) {
569 GenAbsInteger(invoke->GetLocations(), false, GetAssembler());
570}
571
572// long java.lang.Math.abs(long)
573void IntrinsicLocationsBuilderMIPS64::VisitMathAbsLong(HInvoke* invoke) {
574 CreateIntToInt(arena_, invoke);
575}
576
577void IntrinsicCodeGeneratorMIPS64::VisitMathAbsLong(HInvoke* invoke) {
578 GenAbsInteger(invoke->GetLocations(), true, GetAssembler());
579}
580
581static void GenMinMaxFP(LocationSummary* locations,
582 bool is_min,
583 bool is_double,
584 Mips64Assembler* assembler) {
585 FpuRegister lhs = locations->InAt(0).AsFpuRegister<FpuRegister>();
586 FpuRegister rhs = locations->InAt(1).AsFpuRegister<FpuRegister>();
587 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
588
589 if (is_double) {
590 if (is_min) {
591 __ MinD(out, lhs, rhs);
592 } else {
593 __ MaxD(out, lhs, rhs);
594 }
595 } else {
596 if (is_min) {
597 __ MinS(out, lhs, rhs);
598 } else {
599 __ MaxS(out, lhs, rhs);
600 }
601 }
602}
603
604static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
605 LocationSummary* locations = new (arena) LocationSummary(invoke,
606 LocationSummary::kNoCall,
607 kIntrinsified);
608 locations->SetInAt(0, Location::RequiresFpuRegister());
609 locations->SetInAt(1, Location::RequiresFpuRegister());
610 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
611}
612
613// double java.lang.Math.min(double, double)
614void IntrinsicLocationsBuilderMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) {
615 CreateFPFPToFPLocations(arena_, invoke);
616}
617
618void IntrinsicCodeGeneratorMIPS64::VisitMathMinDoubleDouble(HInvoke* invoke) {
619 GenMinMaxFP(invoke->GetLocations(), true, true, GetAssembler());
620}
621
622// float java.lang.Math.min(float, float)
623void IntrinsicLocationsBuilderMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) {
624 CreateFPFPToFPLocations(arena_, invoke);
625}
626
627void IntrinsicCodeGeneratorMIPS64::VisitMathMinFloatFloat(HInvoke* invoke) {
628 GenMinMaxFP(invoke->GetLocations(), true, false, GetAssembler());
629}
630
631// double java.lang.Math.max(double, double)
632void IntrinsicLocationsBuilderMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) {
633 CreateFPFPToFPLocations(arena_, invoke);
634}
635
636void IntrinsicCodeGeneratorMIPS64::VisitMathMaxDoubleDouble(HInvoke* invoke) {
637 GenMinMaxFP(invoke->GetLocations(), false, true, GetAssembler());
638}
639
640// float java.lang.Math.max(float, float)
641void IntrinsicLocationsBuilderMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) {
642 CreateFPFPToFPLocations(arena_, invoke);
643}
644
645void IntrinsicCodeGeneratorMIPS64::VisitMathMaxFloatFloat(HInvoke* invoke) {
646 GenMinMaxFP(invoke->GetLocations(), false, false, GetAssembler());
647}
648
649static void GenMinMax(LocationSummary* locations,
650 bool is_min,
651 Mips64Assembler* assembler) {
652 GpuRegister lhs = locations->InAt(0).AsRegister<GpuRegister>();
653 GpuRegister rhs = locations->InAt(1).AsRegister<GpuRegister>();
654 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
655
Chris Larsen14500822015-10-01 11:35:18 -0700656 // Some architectures, such as ARM and MIPS (prior to r6), have a
657 // conditional move instruction which only changes the target
658 // (output) register if the condition is true (MIPS prior to r6 had
659 // MOVF, MOVT, and MOVZ). The SELEQZ and SELNEZ instructions always
660 // change the target (output) register. If the condition is true the
661 // output register gets the contents of the "rs" register; otherwise,
662 // the output register is set to zero. One consequence of this is
663 // that to implement something like "rd = c==0 ? rs : rt" MIPS64r6
664 // needs to use a pair of SELEQZ/SELNEZ instructions. After
665 // executing this pair of instructions one of the output registers
666 // from the pair will necessarily contain zero. Then the code ORs the
667 // output registers from the SELEQZ/SELNEZ instructions to get the
668 // final result.
669 //
670 // The initial test to see if the output register is same as the
671 // first input register is needed to make sure that value in the
672 // first input register isn't clobbered before we've finished
673 // computing the output value. The logic in the corresponding else
674 // clause performs the same task but makes sure the second input
675 // register isn't clobbered in the event that it's the same register
676 // as the output register; the else clause also handles the case
677 // where the output register is distinct from both the first, and the
678 // second input registers.
Chris Larsen0b7ac982015-09-04 12:54:28 -0700679 if (out == lhs) {
680 __ Slt(AT, rhs, lhs);
681 if (is_min) {
682 __ Seleqz(out, lhs, AT);
683 __ Selnez(AT, rhs, AT);
684 } else {
685 __ Selnez(out, lhs, AT);
686 __ Seleqz(AT, rhs, AT);
687 }
688 } else {
689 __ Slt(AT, lhs, rhs);
690 if (is_min) {
691 __ Seleqz(out, rhs, AT);
692 __ Selnez(AT, lhs, AT);
693 } else {
694 __ Selnez(out, rhs, AT);
695 __ Seleqz(AT, lhs, AT);
696 }
697 }
698 __ Or(out, out, AT);
699}
700
701static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
702 LocationSummary* locations = new (arena) LocationSummary(invoke,
703 LocationSummary::kNoCall,
704 kIntrinsified);
705 locations->SetInAt(0, Location::RequiresRegister());
706 locations->SetInAt(1, Location::RequiresRegister());
707 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
708}
709
710// int java.lang.Math.min(int, int)
711void IntrinsicLocationsBuilderMIPS64::VisitMathMinIntInt(HInvoke* invoke) {
712 CreateIntIntToIntLocations(arena_, invoke);
713}
714
715void IntrinsicCodeGeneratorMIPS64::VisitMathMinIntInt(HInvoke* invoke) {
716 GenMinMax(invoke->GetLocations(), true, GetAssembler());
717}
718
719// long java.lang.Math.min(long, long)
720void IntrinsicLocationsBuilderMIPS64::VisitMathMinLongLong(HInvoke* invoke) {
721 CreateIntIntToIntLocations(arena_, invoke);
722}
723
724void IntrinsicCodeGeneratorMIPS64::VisitMathMinLongLong(HInvoke* invoke) {
725 GenMinMax(invoke->GetLocations(), true, GetAssembler());
726}
727
728// int java.lang.Math.max(int, int)
729void IntrinsicLocationsBuilderMIPS64::VisitMathMaxIntInt(HInvoke* invoke) {
730 CreateIntIntToIntLocations(arena_, invoke);
731}
732
733void IntrinsicCodeGeneratorMIPS64::VisitMathMaxIntInt(HInvoke* invoke) {
734 GenMinMax(invoke->GetLocations(), false, GetAssembler());
735}
736
737// long java.lang.Math.max(long, long)
738void IntrinsicLocationsBuilderMIPS64::VisitMathMaxLongLong(HInvoke* invoke) {
739 CreateIntIntToIntLocations(arena_, invoke);
740}
741
742void IntrinsicCodeGeneratorMIPS64::VisitMathMaxLongLong(HInvoke* invoke) {
743 GenMinMax(invoke->GetLocations(), false, GetAssembler());
744}
745
746// double java.lang.Math.sqrt(double)
747void IntrinsicLocationsBuilderMIPS64::VisitMathSqrt(HInvoke* invoke) {
748 CreateFPToFPLocations(arena_, invoke);
749}
750
751void IntrinsicCodeGeneratorMIPS64::VisitMathSqrt(HInvoke* invoke) {
752 LocationSummary* locations = invoke->GetLocations();
753 Mips64Assembler* assembler = GetAssembler();
754 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
755 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
756
757 __ SqrtD(out, in);
758}
759
Chris Larsen81284372015-10-21 15:28:53 -0700760static void CreateFPToFP(ArenaAllocator* arena,
761 HInvoke* invoke,
762 Location::OutputOverlap overlaps = Location::kOutputOverlap) {
Chris Larsen0b7ac982015-09-04 12:54:28 -0700763 LocationSummary* locations = new (arena) LocationSummary(invoke,
764 LocationSummary::kNoCall,
765 kIntrinsified);
766 locations->SetInAt(0, Location::RequiresFpuRegister());
Chris Larsen81284372015-10-21 15:28:53 -0700767 locations->SetOut(Location::RequiresFpuRegister(), overlaps);
Chris Larsen0b7ac982015-09-04 12:54:28 -0700768}
769
770// double java.lang.Math.rint(double)
771void IntrinsicLocationsBuilderMIPS64::VisitMathRint(HInvoke* invoke) {
Chris Larsen81284372015-10-21 15:28:53 -0700772 CreateFPToFP(arena_, invoke, Location::kNoOutputOverlap);
Chris Larsen0b7ac982015-09-04 12:54:28 -0700773}
774
775void IntrinsicCodeGeneratorMIPS64::VisitMathRint(HInvoke* invoke) {
776 LocationSummary* locations = invoke->GetLocations();
777 Mips64Assembler* assembler = GetAssembler();
778 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
779 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
780
781 __ RintD(out, in);
782}
783
784// double java.lang.Math.floor(double)
785void IntrinsicLocationsBuilderMIPS64::VisitMathFloor(HInvoke* invoke) {
786 CreateFPToFP(arena_, invoke);
787}
788
Chris Larsen14500822015-10-01 11:35:18 -0700789const constexpr uint16_t kFPLeaveUnchanged = kPositiveZero |
790 kPositiveInfinity |
791 kNegativeZero |
792 kNegativeInfinity |
793 kQuietNaN |
794 kSignalingNaN;
Chris Larsen0b7ac982015-09-04 12:54:28 -0700795
Chris Larsen81284372015-10-21 15:28:53 -0700796enum FloatRoundingMode {
797 kFloor,
798 kCeil,
799};
800
801static void GenRoundingMode(LocationSummary* locations,
802 FloatRoundingMode mode,
803 Mips64Assembler* assembler) {
Chris Larsen0b7ac982015-09-04 12:54:28 -0700804 FpuRegister in = locations->InAt(0).AsFpuRegister<FpuRegister>();
805 FpuRegister out = locations->Out().AsFpuRegister<FpuRegister>();
806
Chris Larsen81284372015-10-21 15:28:53 -0700807 DCHECK_NE(in, out);
808
Chris Larsen0b7ac982015-09-04 12:54:28 -0700809 Label done;
810
Chris Larsen81284372015-10-21 15:28:53 -0700811 // double floor/ceil(double in) {
Chris Larsen0b7ac982015-09-04 12:54:28 -0700812 // if in.isNaN || in.isInfinite || in.isZero {
813 // return in;
814 // }
815 __ ClassD(out, in);
816 __ Dmfc1(AT, out);
Chris Larsen14500822015-10-01 11:35:18 -0700817 __ Andi(AT, AT, kFPLeaveUnchanged); // +0.0 | +Inf | -0.0 | -Inf | qNaN | sNaN
Chris Larsen0b7ac982015-09-04 12:54:28 -0700818 __ MovD(out, in);
819 __ Bnezc(AT, &done);
820
Chris Larsen81284372015-10-21 15:28:53 -0700821 // Long outLong = floor/ceil(in);
Chris Larsen0b7ac982015-09-04 12:54:28 -0700822 // if outLong == Long.MAX_VALUE {
Chris Larsen81284372015-10-21 15:28:53 -0700823 // // floor()/ceil() has almost certainly returned a value
824 // // which can't be successfully represented as a signed
825 // // 64-bit number. Java expects that the input value will
826 // // be returned in these cases.
827 // // There is also a small probability that floor(in)/ceil(in)
828 // // correctly truncates/rounds up the input value to
829 // // Long.MAX_VALUE. In that case, this exception handling
830 // // code still does the correct thing.
Chris Larsen0b7ac982015-09-04 12:54:28 -0700831 // return in;
832 // }
Chris Larsen81284372015-10-21 15:28:53 -0700833 if (mode == kFloor) {
834 __ FloorLD(out, in);
835 } else if (mode == kCeil) {
836 __ CeilLD(out, in);
837 }
Chris Larsen0b7ac982015-09-04 12:54:28 -0700838 __ Dmfc1(AT, out);
839 __ MovD(out, in);
840 __ LoadConst64(TMP, kPrimLongMax);
841 __ Beqc(AT, TMP, &done);
842
843 // double out = outLong;
844 // return out;
845 __ Dmtc1(AT, out);
846 __ Cvtdl(out, out);
847 __ Bind(&done);
848 // }
849}
850
Chris Larsen81284372015-10-21 15:28:53 -0700851void IntrinsicCodeGeneratorMIPS64::VisitMathFloor(HInvoke* invoke) {
852 GenRoundingMode(invoke->GetLocations(), kFloor, GetAssembler());
853}
854
Chris Larsen0b7ac982015-09-04 12:54:28 -0700855// double java.lang.Math.ceil(double)
856void IntrinsicLocationsBuilderMIPS64::VisitMathCeil(HInvoke* invoke) {
857 CreateFPToFP(arena_, invoke);
858}
859
860void IntrinsicCodeGeneratorMIPS64::VisitMathCeil(HInvoke* invoke) {
Chris Larsen81284372015-10-21 15:28:53 -0700861 GenRoundingMode(invoke->GetLocations(), kCeil, GetAssembler());
Chris Larsen0b7ac982015-09-04 12:54:28 -0700862}
863
Chris Larsen70fb1f42015-09-04 10:15:27 -0700864// byte libcore.io.Memory.peekByte(long address)
865void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekByte(HInvoke* invoke) {
866 CreateIntToIntLocations(arena_, invoke);
867}
868
869void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekByte(HInvoke* invoke) {
870 Mips64Assembler* assembler = GetAssembler();
871 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
872 GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>();
873
874 __ Lb(out, adr, 0);
875}
876
877// short libcore.io.Memory.peekShort(long address)
878void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) {
879 CreateIntToIntLocations(arena_, invoke);
880}
881
882void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekShortNative(HInvoke* invoke) {
883 Mips64Assembler* assembler = GetAssembler();
884 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
885 GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>();
886
887 __ Lh(out, adr, 0);
888}
889
890// int libcore.io.Memory.peekInt(long address)
891void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) {
892 CreateIntToIntLocations(arena_, invoke);
893}
894
895void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekIntNative(HInvoke* invoke) {
896 Mips64Assembler* assembler = GetAssembler();
897 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
898 GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>();
899
900 __ Lw(out, adr, 0);
901}
902
903// long libcore.io.Memory.peekLong(long address)
904void IntrinsicLocationsBuilderMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) {
905 CreateIntToIntLocations(arena_, invoke);
906}
907
908void IntrinsicCodeGeneratorMIPS64::VisitMemoryPeekLongNative(HInvoke* invoke) {
909 Mips64Assembler* assembler = GetAssembler();
910 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
911 GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>();
912
913 __ Ld(out, adr, 0);
914}
915
916static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
917 LocationSummary* locations = new (arena) LocationSummary(invoke,
918 LocationSummary::kNoCall,
919 kIntrinsified);
920 locations->SetInAt(0, Location::RequiresRegister());
921 locations->SetInAt(1, Location::RequiresRegister());
922}
923
924// void libcore.io.Memory.pokeByte(long address, byte value)
925void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeByte(HInvoke* invoke) {
926 CreateIntIntToVoidLocations(arena_, invoke);
927}
928
929void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeByte(HInvoke* invoke) {
930 Mips64Assembler* assembler = GetAssembler();
931 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
932 GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>();
933
934 __ Sb(val, adr, 0);
935}
936
937// void libcore.io.Memory.pokeShort(long address, short value)
938void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) {
939 CreateIntIntToVoidLocations(arena_, invoke);
940}
941
942void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeShortNative(HInvoke* invoke) {
943 Mips64Assembler* assembler = GetAssembler();
944 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
945 GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>();
946
947 __ Sh(val, adr, 0);
948}
949
950// void libcore.io.Memory.pokeInt(long address, int value)
951void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) {
952 CreateIntIntToVoidLocations(arena_, invoke);
953}
954
955void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeIntNative(HInvoke* invoke) {
956 Mips64Assembler* assembler = GetAssembler();
957 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
958 GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>();
959
960 __ Sw(val, adr, 00);
961}
962
963// void libcore.io.Memory.pokeLong(long address, long value)
964void IntrinsicLocationsBuilderMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) {
965 CreateIntIntToVoidLocations(arena_, invoke);
966}
967
968void IntrinsicCodeGeneratorMIPS64::VisitMemoryPokeLongNative(HInvoke* invoke) {
969 Mips64Assembler* assembler = GetAssembler();
970 GpuRegister adr = invoke->GetLocations()->InAt(0).AsRegister<GpuRegister>();
971 GpuRegister val = invoke->GetLocations()->InAt(1).AsRegister<GpuRegister>();
972
973 __ Sd(val, adr, 0);
974}
975
Chris Larsen49e55392015-09-04 16:04:03 -0700976// Thread java.lang.Thread.currentThread()
977void IntrinsicLocationsBuilderMIPS64::VisitThreadCurrentThread(HInvoke* invoke) {
978 LocationSummary* locations = new (arena_) LocationSummary(invoke,
979 LocationSummary::kNoCall,
980 kIntrinsified);
981 locations->SetOut(Location::RequiresRegister());
982}
983
984void IntrinsicCodeGeneratorMIPS64::VisitThreadCurrentThread(HInvoke* invoke) {
985 Mips64Assembler* assembler = GetAssembler();
986 GpuRegister out = invoke->GetLocations()->Out().AsRegister<GpuRegister>();
987
988 __ LoadFromOffset(kLoadUnsignedWord,
989 out,
990 TR,
991 Thread::PeerOffset<kMips64PointerSize>().Int32Value());
992}
993
Chris Larsen1360ada2015-09-04 23:38:16 -0700994static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
995 LocationSummary* locations = new (arena) LocationSummary(invoke,
996 LocationSummary::kNoCall,
997 kIntrinsified);
998 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
999 locations->SetInAt(1, Location::RequiresRegister());
1000 locations->SetInAt(2, Location::RequiresRegister());
1001 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1002}
1003
1004static void GenUnsafeGet(HInvoke* invoke,
1005 Primitive::Type type,
1006 bool is_volatile,
1007 CodeGeneratorMIPS64* codegen) {
1008 LocationSummary* locations = invoke->GetLocations();
1009 DCHECK((type == Primitive::kPrimInt) ||
1010 (type == Primitive::kPrimLong) ||
1011 (type == Primitive::kPrimNot));
1012 Mips64Assembler* assembler = codegen->GetAssembler();
1013 // Object pointer.
1014 GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>();
1015 // Long offset.
1016 GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>();
1017 GpuRegister trg = locations->Out().AsRegister<GpuRegister>();
1018
1019 __ Daddu(TMP, base, offset);
1020 if (is_volatile) {
1021 __ Sync(0);
1022 }
1023 switch (type) {
1024 case Primitive::kPrimInt:
1025 __ Lw(trg, TMP, 0);
1026 break;
1027
1028 case Primitive::kPrimNot:
1029 __ Lwu(trg, TMP, 0);
1030 break;
1031
1032 case Primitive::kPrimLong:
1033 __ Ld(trg, TMP, 0);
1034 break;
1035
1036 default:
1037 LOG(FATAL) << "Unsupported op size " << type;
1038 UNREACHABLE();
1039 }
1040}
1041
1042// int sun.misc.Unsafe.getInt(Object o, long offset)
1043void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGet(HInvoke* invoke) {
1044 CreateIntIntIntToIntLocations(arena_, invoke);
1045}
1046
1047void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGet(HInvoke* invoke) {
1048 GenUnsafeGet(invoke, Primitive::kPrimInt, false, codegen_);
1049}
1050
1051// int sun.misc.Unsafe.getIntVolatile(Object o, long offset)
1052void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) {
1053 CreateIntIntIntToIntLocations(arena_, invoke);
1054}
1055
1056void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetVolatile(HInvoke* invoke) {
1057 GenUnsafeGet(invoke, Primitive::kPrimInt, true, codegen_);
1058}
1059
1060// long sun.misc.Unsafe.getLong(Object o, long offset)
1061void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLong(HInvoke* invoke) {
1062 CreateIntIntIntToIntLocations(arena_, invoke);
1063}
1064
1065void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLong(HInvoke* invoke) {
1066 GenUnsafeGet(invoke, Primitive::kPrimLong, false, codegen_);
1067}
1068
1069// long sun.misc.Unsafe.getLongVolatile(Object o, long offset)
1070void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1071 CreateIntIntIntToIntLocations(arena_, invoke);
1072}
1073
1074void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1075 GenUnsafeGet(invoke, Primitive::kPrimLong, true, codegen_);
1076}
1077
1078// Object sun.misc.Unsafe.getObject(Object o, long offset)
1079void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObject(HInvoke* invoke) {
1080 CreateIntIntIntToIntLocations(arena_, invoke);
1081}
1082
1083void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObject(HInvoke* invoke) {
1084 GenUnsafeGet(invoke, Primitive::kPrimNot, false, codegen_);
1085}
1086
1087// Object sun.misc.Unsafe.getObjectVolatile(Object o, long offset)
1088void IntrinsicLocationsBuilderMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1089 CreateIntIntIntToIntLocations(arena_, invoke);
1090}
1091
1092void IntrinsicCodeGeneratorMIPS64::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1093 GenUnsafeGet(invoke, Primitive::kPrimNot, true, codegen_);
1094}
1095
1096static void CreateIntIntIntIntToVoid(ArenaAllocator* arena, HInvoke* invoke) {
1097 LocationSummary* locations = new (arena) LocationSummary(invoke,
1098 LocationSummary::kNoCall,
1099 kIntrinsified);
1100 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1101 locations->SetInAt(1, Location::RequiresRegister());
1102 locations->SetInAt(2, Location::RequiresRegister());
1103 locations->SetInAt(3, Location::RequiresRegister());
1104}
1105
1106static void GenUnsafePut(LocationSummary* locations,
1107 Primitive::Type type,
1108 bool is_volatile,
1109 bool is_ordered,
1110 CodeGeneratorMIPS64* codegen) {
1111 DCHECK((type == Primitive::kPrimInt) ||
1112 (type == Primitive::kPrimLong) ||
1113 (type == Primitive::kPrimNot));
1114 Mips64Assembler* assembler = codegen->GetAssembler();
1115 // Object pointer.
1116 GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>();
1117 // Long offset.
1118 GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>();
1119 GpuRegister value = locations->InAt(3).AsRegister<GpuRegister>();
1120
1121 __ Daddu(TMP, base, offset);
1122 if (is_volatile || is_ordered) {
1123 __ Sync(0);
1124 }
1125 switch (type) {
1126 case Primitive::kPrimInt:
1127 case Primitive::kPrimNot:
1128 __ Sw(value, TMP, 0);
1129 break;
1130
1131 case Primitive::kPrimLong:
1132 __ Sd(value, TMP, 0);
1133 break;
1134
1135 default:
1136 LOG(FATAL) << "Unsupported op size " << type;
1137 UNREACHABLE();
1138 }
1139 if (is_volatile) {
1140 __ Sync(0);
1141 }
1142
1143 if (type == Primitive::kPrimNot) {
1144 codegen->MarkGCCard(base, value);
1145 }
1146}
1147
1148// void sun.misc.Unsafe.putInt(Object o, long offset, int x)
1149void IntrinsicLocationsBuilderMIPS64::VisitUnsafePut(HInvoke* invoke) {
1150 CreateIntIntIntIntToVoid(arena_, invoke);
1151}
1152
1153void IntrinsicCodeGeneratorMIPS64::VisitUnsafePut(HInvoke* invoke) {
1154 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, false, codegen_);
1155}
1156
1157// void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x)
1158void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) {
1159 CreateIntIntIntIntToVoid(arena_, invoke);
1160}
1161
1162void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutOrdered(HInvoke* invoke) {
1163 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, false, true, codegen_);
1164}
1165
1166// void sun.misc.Unsafe.putIntVolatile(Object o, long offset, int x)
1167void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) {
1168 CreateIntIntIntIntToVoid(arena_, invoke);
1169}
1170
1171void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutVolatile(HInvoke* invoke) {
1172 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimInt, true, false, codegen_);
1173}
1174
1175// void sun.misc.Unsafe.putObject(Object o, long offset, Object x)
1176void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObject(HInvoke* invoke) {
1177 CreateIntIntIntIntToVoid(arena_, invoke);
1178}
1179
1180void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObject(HInvoke* invoke) {
1181 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, false, codegen_);
1182}
1183
1184// void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x)
1185void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1186 CreateIntIntIntIntToVoid(arena_, invoke);
1187}
1188
1189void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1190 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, false, true, codegen_);
1191}
1192
1193// void sun.misc.Unsafe.putObjectVolatile(Object o, long offset, Object x)
1194void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1195 CreateIntIntIntIntToVoid(arena_, invoke);
1196}
1197
1198void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1199 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimNot, true, false, codegen_);
1200}
1201
1202// void sun.misc.Unsafe.putLong(Object o, long offset, long x)
1203void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLong(HInvoke* invoke) {
1204 CreateIntIntIntIntToVoid(arena_, invoke);
1205}
1206
1207void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLong(HInvoke* invoke) {
1208 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, false, codegen_);
1209}
1210
1211// void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x)
1212void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1213 CreateIntIntIntIntToVoid(arena_, invoke);
1214}
1215
1216void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1217 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, false, true, codegen_);
1218}
1219
1220// void sun.misc.Unsafe.putLongVolatile(Object o, long offset, long x)
1221void IntrinsicLocationsBuilderMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1222 CreateIntIntIntIntToVoid(arena_, invoke);
1223}
1224
1225void IntrinsicCodeGeneratorMIPS64::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1226 GenUnsafePut(invoke->GetLocations(), Primitive::kPrimLong, true, false, codegen_);
1227}
1228
Chris Larsen36427492015-10-23 02:19:38 -07001229static void CreateIntIntIntIntIntToInt(ArenaAllocator* arena, HInvoke* invoke) {
1230 LocationSummary* locations = new (arena) LocationSummary(invoke,
1231 LocationSummary::kNoCall,
1232 kIntrinsified);
1233 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1234 locations->SetInAt(1, Location::RequiresRegister());
1235 locations->SetInAt(2, Location::RequiresRegister());
1236 locations->SetInAt(3, Location::RequiresRegister());
1237 locations->SetInAt(4, Location::RequiresRegister());
1238
1239 locations->SetOut(Location::RequiresRegister());
1240}
1241
1242static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorMIPS64* codegen) {
1243 Mips64Assembler* assembler = codegen->GetAssembler();
1244 GpuRegister base = locations->InAt(1).AsRegister<GpuRegister>();
1245 GpuRegister offset = locations->InAt(2).AsRegister<GpuRegister>();
1246 GpuRegister expected = locations->InAt(3).AsRegister<GpuRegister>();
1247 GpuRegister value = locations->InAt(4).AsRegister<GpuRegister>();
1248 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1249
1250 DCHECK_NE(base, out);
1251 DCHECK_NE(offset, out);
1252 DCHECK_NE(expected, out);
1253
1254 // do {
1255 // tmp_value = [tmp_ptr] - expected;
1256 // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value));
1257 // result = tmp_value != 0;
1258
1259 Label loop_head, exit_loop;
1260 __ Daddu(TMP, base, offset);
1261 __ Sync(0);
1262 __ Bind(&loop_head);
1263 if (type == Primitive::kPrimLong) {
1264 __ Lld(out, TMP);
1265 } else {
1266 __ Ll(out, TMP);
1267 }
1268 __ Dsubu(out, out, expected); // If we didn't get the 'expected'
1269 __ Sltiu(out, out, 1); // value, set 'out' to false, and
1270 __ Beqzc(out, &exit_loop); // return.
1271 __ Move(out, value); // Use 'out' for the 'store conditional' instruction.
1272 // If we use 'value' directly, we would lose 'value'
1273 // in the case that the store fails. Whether the
1274 // store succeeds, or fails, it will load the
1275 // correct boolean value into the 'out' register.
1276 if (type == Primitive::kPrimLong) {
1277 __ Scd(out, TMP);
1278 } else {
1279 __ Sc(out, TMP);
1280 }
1281 __ Beqzc(out, &loop_head); // If we couldn't do the read-modify-write
1282 // cycle atomically then retry.
1283 __ Bind(&exit_loop);
1284 __ Sync(0);
1285}
1286
1287// boolean sun.misc.Unsafe.compareAndSwapInt(Object o, long offset, int expected, int x)
1288void IntrinsicLocationsBuilderMIPS64::VisitUnsafeCASInt(HInvoke* invoke) {
1289 CreateIntIntIntIntIntToInt(arena_, invoke);
1290}
1291
1292void IntrinsicCodeGeneratorMIPS64::VisitUnsafeCASInt(HInvoke* invoke) {
1293 GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
1294}
1295
1296// boolean sun.misc.Unsafe.compareAndSwapLong(Object o, long offset, long expected, long x)
1297void IntrinsicLocationsBuilderMIPS64::VisitUnsafeCASLong(HInvoke* invoke) {
1298 CreateIntIntIntIntIntToInt(arena_, invoke);
1299}
1300
1301void IntrinsicCodeGeneratorMIPS64::VisitUnsafeCASLong(HInvoke* invoke) {
1302 GenCas(invoke->GetLocations(), Primitive::kPrimLong, codegen_);
1303}
1304
1305// boolean sun.misc.Unsafe.compareAndSwapObject(Object o, long offset, Object expected, Object x)
1306void IntrinsicLocationsBuilderMIPS64::VisitUnsafeCASObject(HInvoke* invoke) {
1307 CreateIntIntIntIntIntToInt(arena_, invoke);
1308}
1309
1310void IntrinsicCodeGeneratorMIPS64::VisitUnsafeCASObject(HInvoke* invoke) {
1311 GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
1312}
1313
Chris Larsen9701c2e2015-09-04 17:22:47 -07001314// char java.lang.String.charAt(int index)
1315void IntrinsicLocationsBuilderMIPS64::VisitStringCharAt(HInvoke* invoke) {
1316 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1317 LocationSummary::kCallOnSlowPath,
1318 kIntrinsified);
1319 locations->SetInAt(0, Location::RequiresRegister());
1320 locations->SetInAt(1, Location::RequiresRegister());
1321 locations->SetOut(Location::SameAsFirstInput());
1322}
1323
1324void IntrinsicCodeGeneratorMIPS64::VisitStringCharAt(HInvoke* invoke) {
1325 LocationSummary* locations = invoke->GetLocations();
1326 Mips64Assembler* assembler = GetAssembler();
1327
1328 // Location of reference to data array
1329 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1330 // Location of count
1331 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1332
1333 GpuRegister obj = locations->InAt(0).AsRegister<GpuRegister>();
1334 GpuRegister idx = locations->InAt(1).AsRegister<GpuRegister>();
1335 GpuRegister out = locations->Out().AsRegister<GpuRegister>();
1336
1337 // TODO: Maybe we can support range check elimination. Overall,
1338 // though, I think it's not worth the cost.
1339 // TODO: For simplicity, the index parameter is requested in a
1340 // register, so different from Quick we will not optimize the
1341 // code for constants (which would save a register).
1342
1343 SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke);
1344 codegen_->AddSlowPath(slow_path);
1345
1346 // Load the string size
1347 __ Lw(TMP, obj, count_offset);
1348 codegen_->MaybeRecordImplicitNullCheck(invoke);
1349 // Revert to slow path if idx is too large, or negative
1350 __ Bgeuc(idx, TMP, slow_path->GetEntryLabel());
1351
1352 // out = obj[2*idx].
1353 __ Sll(TMP, idx, 1); // idx * 2
1354 __ Daddu(TMP, TMP, obj); // Address of char at location idx
1355 __ Lhu(out, TMP, value_offset); // Load char at location idx
1356
1357 __ Bind(slow_path->GetExitLabel());
1358}
1359
1360// int java.lang.String.compareTo(String anotherString)
1361void IntrinsicLocationsBuilderMIPS64::VisitStringCompareTo(HInvoke* invoke) {
1362 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1363 LocationSummary::kCall,
1364 kIntrinsified);
1365 InvokeRuntimeCallingConvention calling_convention;
1366 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1367 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1368 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1369 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1370}
1371
1372void IntrinsicCodeGeneratorMIPS64::VisitStringCompareTo(HInvoke* invoke) {
1373 Mips64Assembler* assembler = GetAssembler();
1374 LocationSummary* locations = invoke->GetLocations();
1375
1376 // Note that the null check must have been done earlier.
1377 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1378
1379 GpuRegister argument = locations->InAt(1).AsRegister<GpuRegister>();
1380 SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke);
1381 codegen_->AddSlowPath(slow_path);
1382 __ Beqzc(argument, slow_path->GetEntryLabel());
1383
1384 __ LoadFromOffset(kLoadDoubleword,
1385 TMP,
1386 TR,
1387 QUICK_ENTRYPOINT_OFFSET(kMips64WordSize,
1388 pStringCompareTo).Int32Value());
1389 __ Jalr(TMP);
1390 __ Nop();
1391 __ Bind(slow_path->GetExitLabel());
1392}
1393
1394static void GenerateStringIndexOf(HInvoke* invoke,
1395 Mips64Assembler* assembler,
1396 CodeGeneratorMIPS64* codegen,
1397 ArenaAllocator* allocator,
1398 bool start_at_zero) {
1399 LocationSummary* locations = invoke->GetLocations();
1400 GpuRegister tmp_reg = start_at_zero ? locations->GetTemp(0).AsRegister<GpuRegister>() : TMP;
1401
1402 // Note that the null check must have been done earlier.
1403 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1404
1405 // Check for code points > 0xFFFF. Either a slow-path check when we
1406 // don't know statically, or directly dispatch if we have a constant.
1407 SlowPathCodeMIPS64* slow_path = nullptr;
1408 if (invoke->InputAt(1)->IsIntConstant()) {
1409 if (!IsUint<16>(invoke->InputAt(1)->AsIntConstant()->GetValue())) {
1410 // Always needs the slow-path. We could directly dispatch to it,
1411 // but this case should be rare, so for simplicity just put the
1412 // full slow-path down and branch unconditionally.
1413 slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke);
1414 codegen->AddSlowPath(slow_path);
1415 __ B(slow_path->GetEntryLabel());
1416 __ Bind(slow_path->GetExitLabel());
1417 return;
1418 }
1419 } else {
1420 GpuRegister char_reg = locations->InAt(1).AsRegister<GpuRegister>();
1421 __ LoadConst32(tmp_reg, std::numeric_limits<uint16_t>::max());
1422 slow_path = new (allocator) IntrinsicSlowPathMIPS64(invoke);
1423 codegen->AddSlowPath(slow_path);
1424 __ Bltuc(tmp_reg, char_reg, slow_path->GetEntryLabel()); // UTF-16 required
1425 }
1426
1427 if (start_at_zero) {
1428 DCHECK_EQ(tmp_reg, A2);
1429 // Start-index = 0.
1430 __ Clear(tmp_reg);
1431 } else {
1432 __ Slt(TMP, A2, ZERO); // if fromIndex < 0
1433 __ Seleqz(A2, A2, TMP); // fromIndex = 0
1434 }
1435
1436 __ LoadFromOffset(kLoadDoubleword,
1437 TMP,
1438 TR,
1439 QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pIndexOf).Int32Value());
1440 __ Jalr(TMP);
1441 __ Nop();
1442
1443 if (slow_path != nullptr) {
1444 __ Bind(slow_path->GetExitLabel());
1445 }
1446}
1447
1448// int java.lang.String.indexOf(int ch)
1449void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOf(HInvoke* invoke) {
1450 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1451 LocationSummary::kCall,
1452 kIntrinsified);
1453 // We have a hand-crafted assembly stub that follows the runtime
1454 // calling convention. So it's best to align the inputs accordingly.
1455 InvokeRuntimeCallingConvention calling_convention;
1456 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1457 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1458 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1459 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1460
1461 // Need a temp for slow-path codepoint compare, and need to send start-index=0.
1462 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1463}
1464
1465void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOf(HInvoke* invoke) {
1466 GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), true);
1467}
1468
1469// int java.lang.String.indexOf(int ch, int fromIndex)
1470void IntrinsicLocationsBuilderMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) {
1471 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1472 LocationSummary::kCall,
1473 kIntrinsified);
1474 // We have a hand-crafted assembly stub that follows the runtime
1475 // calling convention. So it's best to align the inputs accordingly.
1476 InvokeRuntimeCallingConvention calling_convention;
1477 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1478 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1479 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1480 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1481 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1482}
1483
1484void IntrinsicCodeGeneratorMIPS64::VisitStringIndexOfAfter(HInvoke* invoke) {
1485 GenerateStringIndexOf(invoke, GetAssembler(), codegen_, GetAllocator(), false);
1486}
1487
1488// java.lang.String.String(byte[] bytes)
1489void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) {
1490 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1491 LocationSummary::kCall,
1492 kIntrinsified);
1493 InvokeRuntimeCallingConvention calling_convention;
1494 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1495 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1496 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1497 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1498 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1499 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1500}
1501
1502void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromBytes(HInvoke* invoke) {
1503 Mips64Assembler* assembler = GetAssembler();
1504 LocationSummary* locations = invoke->GetLocations();
1505
1506 GpuRegister byte_array = locations->InAt(0).AsRegister<GpuRegister>();
1507 SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke);
1508 codegen_->AddSlowPath(slow_path);
1509 __ Beqzc(byte_array, slow_path->GetEntryLabel());
1510
1511 __ LoadFromOffset(kLoadDoubleword,
1512 TMP,
1513 TR,
1514 QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromBytes).Int32Value());
1515 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1516 __ Jalr(TMP);
1517 __ Nop();
1518 __ Bind(slow_path->GetExitLabel());
1519}
1520
1521// java.lang.String.String(char[] value)
1522void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) {
1523 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1524 LocationSummary::kCall,
1525 kIntrinsified);
1526 InvokeRuntimeCallingConvention calling_convention;
1527 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1528 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1529 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1530 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1531 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1532}
1533
1534void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromChars(HInvoke* invoke) {
1535 Mips64Assembler* assembler = GetAssembler();
1536
1537 __ LoadFromOffset(kLoadDoubleword,
1538 TMP,
1539 TR,
1540 QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromChars).Int32Value());
1541 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1542 __ Jalr(TMP);
1543 __ Nop();
1544}
1545
1546// java.lang.String.String(String original)
1547void IntrinsicLocationsBuilderMIPS64::VisitStringNewStringFromString(HInvoke* invoke) {
1548 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1549 LocationSummary::kCall,
1550 kIntrinsified);
1551 InvokeRuntimeCallingConvention calling_convention;
1552 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1553 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1554 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1555 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1556 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<GpuRegister>()));
1557}
1558
1559void IntrinsicCodeGeneratorMIPS64::VisitStringNewStringFromString(HInvoke* invoke) {
1560 Mips64Assembler* assembler = GetAssembler();
1561 LocationSummary* locations = invoke->GetLocations();
1562
1563 GpuRegister string_to_copy = locations->InAt(0).AsRegister<GpuRegister>();
1564 SlowPathCodeMIPS64* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS64(invoke);
1565 codegen_->AddSlowPath(slow_path);
1566 __ Beqzc(string_to_copy, slow_path->GetEntryLabel());
1567
1568 __ LoadFromOffset(kLoadDoubleword,
1569 TMP,
1570 TR,
1571 QUICK_ENTRYPOINT_OFFSET(kMips64WordSize, pAllocStringFromString).Int32Value());
1572 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1573 __ Jalr(TMP);
1574 __ Nop();
1575 __ Bind(slow_path->GetExitLabel());
1576}
1577
Chris Larsen3039e382015-08-26 07:54:08 -07001578// Unimplemented intrinsics.
1579
1580#define UNIMPLEMENTED_INTRINSIC(Name) \
1581void IntrinsicLocationsBuilderMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
1582} \
1583void IntrinsicCodeGeneratorMIPS64::Visit ## Name(HInvoke* invoke ATTRIBUTE_UNUSED) { \
1584}
1585
Chris Larsen3039e382015-08-26 07:54:08 -07001586UNIMPLEMENTED_INTRINSIC(MathRoundDouble)
1587UNIMPLEMENTED_INTRINSIC(MathRoundFloat)
Chris Larsen0b7ac982015-09-04 12:54:28 -07001588
Chris Larsen3039e382015-08-26 07:54:08 -07001589UNIMPLEMENTED_INTRINSIC(StringEquals)
Chris Larsen3039e382015-08-26 07:54:08 -07001590
1591UNIMPLEMENTED_INTRINSIC(ReferenceGetReferent)
1592UNIMPLEMENTED_INTRINSIC(StringGetCharsNoCheck)
1593UNIMPLEMENTED_INTRINSIC(SystemArrayCopyChar)
Nicolas Geoffrayee3cf072015-10-06 11:45:02 +01001594UNIMPLEMENTED_INTRINSIC(SystemArrayCopy)
Chris Larsen3039e382015-08-26 07:54:08 -07001595
1596#undef UNIMPLEMENTED_INTRINSIC
1597
1598#undef __
1599
1600} // namespace mips64
1601} // namespace art