blob: 7c81588cda6b41749a96f80ff387f11bff1b0670 [file] [log] [blame]
Chris Larsen701566a2015-10-27 15:29:13 -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_mips.h"
18
19#include "arch/mips/instruction_set_features_mips.h"
20#include "art_method.h"
21#include "code_generator_mips.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/mips/assembler_mips.h"
28#include "utils/mips/constants_mips.h"
29
30namespace art {
31
32namespace mips {
33
34IntrinsicLocationsBuilderMIPS::IntrinsicLocationsBuilderMIPS(CodeGeneratorMIPS* codegen)
35 : arena_(codegen->GetGraph()->GetArena()) {
36}
37
38MipsAssembler* IntrinsicCodeGeneratorMIPS::GetAssembler() {
39 return reinterpret_cast<MipsAssembler*>(codegen_->GetAssembler());
40}
41
42ArenaAllocator* IntrinsicCodeGeneratorMIPS::GetAllocator() {
43 return codegen_->GetGraph()->GetArena();
44}
45
Alexey Frunzebb9863a2016-01-11 15:51:16 -080046inline bool IntrinsicCodeGeneratorMIPS::IsR2OrNewer() const {
Chris Larsene16ce5a2015-11-18 12:30:20 -080047 return codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
48}
49
Alexey Frunzebb9863a2016-01-11 15:51:16 -080050inline bool IntrinsicCodeGeneratorMIPS::IsR6() const {
Chris Larsene16ce5a2015-11-18 12:30:20 -080051 return codegen_->GetInstructionSetFeatures().IsR6();
52}
53
Alexey Frunzebb9863a2016-01-11 15:51:16 -080054inline bool IntrinsicCodeGeneratorMIPS::Is32BitFPU() const {
55 return codegen_->GetInstructionSetFeatures().Is32BitFloatingPoint();
56}
57
Chris Larsen701566a2015-10-27 15:29:13 -070058#define __ codegen->GetAssembler()->
59
60static void MoveFromReturnRegister(Location trg,
61 Primitive::Type type,
62 CodeGeneratorMIPS* codegen) {
63 if (!trg.IsValid()) {
64 DCHECK_EQ(type, Primitive::kPrimVoid);
65 return;
66 }
67
68 DCHECK_NE(type, Primitive::kPrimVoid);
69
70 if (Primitive::IsIntegralType(type) || type == Primitive::kPrimNot) {
71 Register trg_reg = trg.AsRegister<Register>();
72 if (trg_reg != V0) {
73 __ Move(V0, trg_reg);
74 }
75 } else {
76 FRegister trg_reg = trg.AsFpuRegister<FRegister>();
77 if (trg_reg != F0) {
78 if (type == Primitive::kPrimFloat) {
79 __ MovS(F0, trg_reg);
80 } else {
81 __ MovD(F0, trg_reg);
82 }
83 }
84 }
85}
86
87static void MoveArguments(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
88 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
89 IntrinsicVisitor::MoveArguments(invoke, codegen, &calling_convention_visitor);
90}
91
92// Slow-path for fallback (calling the managed code to handle the
93// intrinsic) in an intrinsified call. This will copy the arguments
94// into the positions for a regular call.
95//
96// Note: The actual parameters are required to be in the locations
97// given by the invoke's location summary. If an intrinsic
98// modifies those locations before a slowpath call, they must be
99// restored!
100class IntrinsicSlowPathMIPS : public SlowPathCodeMIPS {
101 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000102 explicit IntrinsicSlowPathMIPS(HInvoke* invoke) : SlowPathCodeMIPS(invoke), invoke_(invoke) { }
Chris Larsen701566a2015-10-27 15:29:13 -0700103
104 void EmitNativeCode(CodeGenerator* codegen_in) OVERRIDE {
105 CodeGeneratorMIPS* codegen = down_cast<CodeGeneratorMIPS*>(codegen_in);
106
107 __ Bind(GetEntryLabel());
108
109 SaveLiveRegisters(codegen, invoke_->GetLocations());
110
111 MoveArguments(invoke_, codegen);
112
113 if (invoke_->IsInvokeStaticOrDirect()) {
114 codegen->GenerateStaticOrDirectCall(invoke_->AsInvokeStaticOrDirect(),
115 Location::RegisterLocation(A0));
Chris Larsen701566a2015-10-27 15:29:13 -0700116 } else {
Chris Larsen3acee732015-11-18 13:31:08 -0800117 codegen->GenerateVirtualCall(invoke_->AsInvokeVirtual(), Location::RegisterLocation(A0));
Chris Larsen701566a2015-10-27 15:29:13 -0700118 }
Chris Larsen3acee732015-11-18 13:31:08 -0800119 codegen->RecordPcInfo(invoke_, invoke_->GetDexPc(), this);
Chris Larsen701566a2015-10-27 15:29:13 -0700120
121 // Copy the result back to the expected output.
122 Location out = invoke_->GetLocations()->Out();
123 if (out.IsValid()) {
124 DCHECK(out.IsRegister()); // TODO: Replace this when we support output in memory.
125 DCHECK(!invoke_->GetLocations()->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
126 MoveFromReturnRegister(out, invoke_->GetType(), codegen);
127 }
128
129 RestoreLiveRegisters(codegen, invoke_->GetLocations());
130 __ B(GetExitLabel());
131 }
132
133 const char* GetDescription() const OVERRIDE { return "IntrinsicSlowPathMIPS"; }
134
135 private:
136 // The instruction where this slow path is happening.
137 HInvoke* const invoke_;
138
139 DISALLOW_COPY_AND_ASSIGN(IntrinsicSlowPathMIPS);
140};
141
142#undef __
143
144bool IntrinsicLocationsBuilderMIPS::TryDispatch(HInvoke* invoke) {
145 Dispatch(invoke);
146 LocationSummary* res = invoke->GetLocations();
147 return res != nullptr && res->Intrinsified();
148}
149
150#define __ assembler->
151
Chris Larsen3f8bf652015-10-28 10:08:56 -0700152static void CreateFPToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
153 LocationSummary* locations = new (arena) LocationSummary(invoke,
154 LocationSummary::kNoCall,
155 kIntrinsified);
156 locations->SetInAt(0, Location::RequiresFpuRegister());
157 locations->SetOut(Location::RequiresRegister());
158}
159
160static void MoveFPToInt(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
161 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
162
163 if (is64bit) {
164 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
165 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
166
167 __ Mfc1(out_lo, in);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800168 __ MoveFromFpuHigh(out_hi, in);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700169 } else {
170 Register out = locations->Out().AsRegister<Register>();
171
172 __ Mfc1(out, in);
173 }
174}
175
176// long java.lang.Double.doubleToRawLongBits(double)
177void IntrinsicLocationsBuilderMIPS::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
178 CreateFPToIntLocations(arena_, invoke);
179}
180
181void IntrinsicCodeGeneratorMIPS::VisitDoubleDoubleToRawLongBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000182 MoveFPToInt(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700183}
184
185// int java.lang.Float.floatToRawIntBits(float)
186void IntrinsicLocationsBuilderMIPS::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
187 CreateFPToIntLocations(arena_, invoke);
188}
189
190void IntrinsicCodeGeneratorMIPS::VisitFloatFloatToRawIntBits(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000191 MoveFPToInt(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700192}
193
194static void CreateIntToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
195 LocationSummary* locations = new (arena) LocationSummary(invoke,
196 LocationSummary::kNoCall,
197 kIntrinsified);
198 locations->SetInAt(0, Location::RequiresRegister());
199 locations->SetOut(Location::RequiresFpuRegister());
200}
201
202static void MoveIntToFP(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
203 FRegister out = locations->Out().AsFpuRegister<FRegister>();
204
205 if (is64bit) {
206 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
207 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
208
209 __ Mtc1(in_lo, out);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800210 __ MoveToFpuHigh(in_hi, out);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700211 } else {
212 Register in = locations->InAt(0).AsRegister<Register>();
213
214 __ Mtc1(in, out);
215 }
216}
217
218// double java.lang.Double.longBitsToDouble(long)
219void IntrinsicLocationsBuilderMIPS::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
220 CreateIntToFPLocations(arena_, invoke);
221}
222
223void IntrinsicCodeGeneratorMIPS::VisitDoubleLongBitsToDouble(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000224 MoveIntToFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700225}
226
227// float java.lang.Float.intBitsToFloat(int)
228void IntrinsicLocationsBuilderMIPS::VisitFloatIntBitsToFloat(HInvoke* invoke) {
229 CreateIntToFPLocations(arena_, invoke);
230}
231
232void IntrinsicCodeGeneratorMIPS::VisitFloatIntBitsToFloat(HInvoke* invoke) {
Roland Levillainbf84a3d2015-12-04 14:33:02 +0000233 MoveIntToFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700234}
235
Chris Larsen86829602015-11-18 12:27:52 -0800236static void CreateIntToIntLocations(ArenaAllocator* arena,
237 HInvoke* invoke,
238 Location::OutputOverlap overlaps = Location::kNoOutputOverlap) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700239 LocationSummary* locations = new (arena) LocationSummary(invoke,
240 LocationSummary::kNoCall,
241 kIntrinsified);
242 locations->SetInAt(0, Location::RequiresRegister());
Chris Larsen86829602015-11-18 12:27:52 -0800243 locations->SetOut(Location::RequiresRegister(), overlaps);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700244}
245
Chris Larsen70014c82015-11-18 12:26:08 -0800246static void GenReverse(LocationSummary* locations,
247 Primitive::Type type,
248 bool isR2OrNewer,
249 bool isR6,
250 bool reverseBits,
251 MipsAssembler* assembler) {
Chris Larsen3f8bf652015-10-28 10:08:56 -0700252 DCHECK(type == Primitive::kPrimShort ||
253 type == Primitive::kPrimInt ||
254 type == Primitive::kPrimLong);
Chris Larsen70014c82015-11-18 12:26:08 -0800255 DCHECK(type != Primitive::kPrimShort || !reverseBits);
Chris Larsen3f8bf652015-10-28 10:08:56 -0700256
257 if (type == Primitive::kPrimShort) {
258 Register in = locations->InAt(0).AsRegister<Register>();
259 Register out = locations->Out().AsRegister<Register>();
260
261 if (isR2OrNewer) {
262 __ Wsbh(out, in);
263 __ Seh(out, out);
264 } else {
265 __ Sll(TMP, in, 24);
266 __ Sra(TMP, TMP, 16);
267 __ Sll(out, in, 16);
268 __ Srl(out, out, 24);
269 __ Or(out, out, TMP);
270 }
271 } else if (type == Primitive::kPrimInt) {
272 Register in = locations->InAt(0).AsRegister<Register>();
273 Register out = locations->Out().AsRegister<Register>();
274
275 if (isR2OrNewer) {
276 __ Rotr(out, in, 16);
277 __ Wsbh(out, out);
278 } else {
279 // MIPS32r1
280 // __ Rotr(out, in, 16);
281 __ Sll(TMP, in, 16);
282 __ Srl(out, in, 16);
283 __ Or(out, out, TMP);
284 // __ Wsbh(out, out);
285 __ LoadConst32(AT, 0x00FF00FF);
286 __ And(TMP, out, AT);
287 __ Sll(TMP, TMP, 8);
288 __ Srl(out, out, 8);
289 __ And(out, out, AT);
290 __ Or(out, out, TMP);
291 }
Chris Larsen70014c82015-11-18 12:26:08 -0800292 if (reverseBits) {
293 if (isR6) {
294 __ Bitswap(out, out);
295 } else {
296 __ LoadConst32(AT, 0x0F0F0F0F);
297 __ And(TMP, out, AT);
298 __ Sll(TMP, TMP, 4);
299 __ Srl(out, out, 4);
300 __ And(out, out, AT);
301 __ Or(out, TMP, out);
302 __ LoadConst32(AT, 0x33333333);
303 __ And(TMP, out, AT);
304 __ Sll(TMP, TMP, 2);
305 __ Srl(out, out, 2);
306 __ And(out, out, AT);
307 __ Or(out, TMP, out);
308 __ LoadConst32(AT, 0x55555555);
309 __ And(TMP, out, AT);
310 __ Sll(TMP, TMP, 1);
311 __ Srl(out, out, 1);
312 __ And(out, out, AT);
313 __ Or(out, TMP, out);
314 }
315 }
Chris Larsen3f8bf652015-10-28 10:08:56 -0700316 } else if (type == Primitive::kPrimLong) {
317 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
318 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
319 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
320 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
321
322 if (isR2OrNewer) {
323 __ Rotr(AT, in_hi, 16);
324 __ Rotr(TMP, in_lo, 16);
325 __ Wsbh(out_lo, AT);
326 __ Wsbh(out_hi, TMP);
327 } else {
328 // When calling CreateIntToIntLocations() we promised that the
329 // use of the out_lo/out_hi wouldn't overlap with the use of
330 // in_lo/in_hi. Be very careful not to write to out_lo/out_hi
331 // until we're completely done reading from in_lo/in_hi.
332 // __ Rotr(TMP, in_lo, 16);
333 __ Sll(TMP, in_lo, 16);
334 __ Srl(AT, in_lo, 16);
335 __ Or(TMP, TMP, AT); // Hold in TMP until it's safe
336 // to write to out_hi.
337 // __ Rotr(out_lo, in_hi, 16);
338 __ Sll(AT, in_hi, 16);
339 __ Srl(out_lo, in_hi, 16); // Here we are finally done reading
340 // from in_lo/in_hi so it's okay to
341 // write to out_lo/out_hi.
342 __ Or(out_lo, out_lo, AT);
343 // __ Wsbh(out_hi, out_hi);
344 __ LoadConst32(AT, 0x00FF00FF);
345 __ And(out_hi, TMP, AT);
346 __ Sll(out_hi, out_hi, 8);
347 __ Srl(TMP, TMP, 8);
348 __ And(TMP, TMP, AT);
349 __ Or(out_hi, out_hi, TMP);
350 // __ Wsbh(out_lo, out_lo);
351 __ And(TMP, out_lo, AT); // AT already holds the correct mask value
352 __ Sll(TMP, TMP, 8);
353 __ Srl(out_lo, out_lo, 8);
354 __ And(out_lo, out_lo, AT);
355 __ Or(out_lo, out_lo, TMP);
356 }
Chris Larsen70014c82015-11-18 12:26:08 -0800357 if (reverseBits) {
358 if (isR6) {
359 __ Bitswap(out_hi, out_hi);
360 __ Bitswap(out_lo, out_lo);
361 } else {
362 __ LoadConst32(AT, 0x0F0F0F0F);
363 __ And(TMP, out_hi, AT);
364 __ Sll(TMP, TMP, 4);
365 __ Srl(out_hi, out_hi, 4);
366 __ And(out_hi, out_hi, AT);
367 __ Or(out_hi, TMP, out_hi);
368 __ And(TMP, out_lo, AT);
369 __ Sll(TMP, TMP, 4);
370 __ Srl(out_lo, out_lo, 4);
371 __ And(out_lo, out_lo, AT);
372 __ Or(out_lo, TMP, out_lo);
373 __ LoadConst32(AT, 0x33333333);
374 __ And(TMP, out_hi, AT);
375 __ Sll(TMP, TMP, 2);
376 __ Srl(out_hi, out_hi, 2);
377 __ And(out_hi, out_hi, AT);
378 __ Or(out_hi, TMP, out_hi);
379 __ And(TMP, out_lo, AT);
380 __ Sll(TMP, TMP, 2);
381 __ Srl(out_lo, out_lo, 2);
382 __ And(out_lo, out_lo, AT);
383 __ Or(out_lo, TMP, out_lo);
384 __ LoadConst32(AT, 0x55555555);
385 __ And(TMP, out_hi, AT);
386 __ Sll(TMP, TMP, 1);
387 __ Srl(out_hi, out_hi, 1);
388 __ And(out_hi, out_hi, AT);
389 __ Or(out_hi, TMP, out_hi);
390 __ And(TMP, out_lo, AT);
391 __ Sll(TMP, TMP, 1);
392 __ Srl(out_lo, out_lo, 1);
393 __ And(out_lo, out_lo, AT);
394 __ Or(out_lo, TMP, out_lo);
395 }
396 }
Chris Larsen3f8bf652015-10-28 10:08:56 -0700397 }
398}
399
400// int java.lang.Integer.reverseBytes(int)
401void IntrinsicLocationsBuilderMIPS::VisitIntegerReverseBytes(HInvoke* invoke) {
402 CreateIntToIntLocations(arena_, invoke);
403}
404
405void IntrinsicCodeGeneratorMIPS::VisitIntegerReverseBytes(HInvoke* invoke) {
Chris Larsen70014c82015-11-18 12:26:08 -0800406 GenReverse(invoke->GetLocations(),
407 Primitive::kPrimInt,
Chris Larsene16ce5a2015-11-18 12:30:20 -0800408 IsR2OrNewer(),
409 IsR6(),
Chris Larsenb74353a2015-11-20 09:07:09 -0800410 /* reverseBits */ false,
Chris Larsen70014c82015-11-18 12:26:08 -0800411 GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700412}
413
414// long java.lang.Long.reverseBytes(long)
415void IntrinsicLocationsBuilderMIPS::VisitLongReverseBytes(HInvoke* invoke) {
416 CreateIntToIntLocations(arena_, invoke);
417}
418
419void IntrinsicCodeGeneratorMIPS::VisitLongReverseBytes(HInvoke* invoke) {
Chris Larsen70014c82015-11-18 12:26:08 -0800420 GenReverse(invoke->GetLocations(),
421 Primitive::kPrimLong,
Chris Larsene16ce5a2015-11-18 12:30:20 -0800422 IsR2OrNewer(),
423 IsR6(),
Chris Larsenb74353a2015-11-20 09:07:09 -0800424 /* reverseBits */ false,
Chris Larsen70014c82015-11-18 12:26:08 -0800425 GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700426}
427
428// short java.lang.Short.reverseBytes(short)
429void IntrinsicLocationsBuilderMIPS::VisitShortReverseBytes(HInvoke* invoke) {
430 CreateIntToIntLocations(arena_, invoke);
431}
432
433void IntrinsicCodeGeneratorMIPS::VisitShortReverseBytes(HInvoke* invoke) {
Chris Larsen70014c82015-11-18 12:26:08 -0800434 GenReverse(invoke->GetLocations(),
435 Primitive::kPrimShort,
Chris Larsene16ce5a2015-11-18 12:30:20 -0800436 IsR2OrNewer(),
437 IsR6(),
Chris Larsenb74353a2015-11-20 09:07:09 -0800438 /* reverseBits */ false,
Chris Larsen70014c82015-11-18 12:26:08 -0800439 GetAssembler());
440}
441
Chris Larsene3845472015-11-18 12:27:15 -0800442static void GenNumberOfLeadingZeroes(LocationSummary* locations,
443 bool is64bit,
444 bool isR6,
445 MipsAssembler* assembler) {
446 Register out = locations->Out().AsRegister<Register>();
447 if (is64bit) {
448 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
449 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
450
451 if (isR6) {
452 __ ClzR6(AT, in_hi);
453 __ ClzR6(TMP, in_lo);
454 __ Seleqz(TMP, TMP, in_hi);
455 } else {
456 __ ClzR2(AT, in_hi);
457 __ ClzR2(TMP, in_lo);
458 __ Movn(TMP, ZERO, in_hi);
459 }
460 __ Addu(out, AT, TMP);
461 } else {
462 Register in = locations->InAt(0).AsRegister<Register>();
463
464 if (isR6) {
465 __ ClzR6(out, in);
466 } else {
467 __ ClzR2(out, in);
468 }
469 }
470}
471
472// int java.lang.Integer.numberOfLeadingZeros(int i)
473void IntrinsicLocationsBuilderMIPS::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
474 CreateIntToIntLocations(arena_, invoke);
475}
476
477void IntrinsicCodeGeneratorMIPS::VisitIntegerNumberOfLeadingZeros(HInvoke* invoke) {
Chris Larsenb74353a2015-11-20 09:07:09 -0800478 GenNumberOfLeadingZeroes(invoke->GetLocations(), /* is64bit */ false, IsR6(), GetAssembler());
Chris Larsene3845472015-11-18 12:27:15 -0800479}
480
481// int java.lang.Long.numberOfLeadingZeros(long i)
482void IntrinsicLocationsBuilderMIPS::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
483 CreateIntToIntLocations(arena_, invoke);
484}
485
486void IntrinsicCodeGeneratorMIPS::VisitLongNumberOfLeadingZeros(HInvoke* invoke) {
Chris Larsenb74353a2015-11-20 09:07:09 -0800487 GenNumberOfLeadingZeroes(invoke->GetLocations(), /* is64bit */ true, IsR6(), GetAssembler());
Chris Larsene3845472015-11-18 12:27:15 -0800488}
489
Chris Larsen86829602015-11-18 12:27:52 -0800490static void GenNumberOfTrailingZeroes(LocationSummary* locations,
491 bool is64bit,
492 bool isR6,
Chris Larsen86829602015-11-18 12:27:52 -0800493 MipsAssembler* assembler) {
494 Register out = locations->Out().AsRegister<Register>();
495 Register in_lo;
496 Register in;
497
498 if (is64bit) {
Chris Larsen86829602015-11-18 12:27:52 -0800499 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
500
501 in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
502
503 // If in_lo is zero then count the number of trailing zeroes in in_hi;
504 // otherwise count the number of trailing zeroes in in_lo.
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800505 // out = in_lo ? in_lo : in_hi;
Chris Larsen86829602015-11-18 12:27:52 -0800506 if (isR6) {
507 __ Seleqz(out, in_hi, in_lo);
508 __ Selnez(TMP, in_lo, in_lo);
509 __ Or(out, out, TMP);
510 } else {
511 __ Movz(out, in_hi, in_lo);
512 __ Movn(out, in_lo, in_lo);
513 }
514
515 in = out;
516 } else {
517 in = locations->InAt(0).AsRegister<Register>();
518 // Give in_lo a dummy value to keep the compiler from complaining.
519 // Since we only get here in the 32-bit case, this value will never
520 // be used.
521 in_lo = in;
522 }
523
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800524 if (isR6) {
525 // We don't have an instruction to count the number of trailing zeroes.
526 // Start by flipping the bits end-for-end so we can count the number of
527 // leading zeroes instead.
Chris Larsen86829602015-11-18 12:27:52 -0800528 __ Rotr(out, in, 16);
529 __ Wsbh(out, out);
Chris Larsen86829602015-11-18 12:27:52 -0800530 __ Bitswap(out, out);
531 __ ClzR6(out, out);
532 } else {
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800533 // Convert trailing zeroes to trailing ones, and bits to their left
534 // to zeroes.
535 __ Addiu(TMP, in, -1);
536 __ Xor(out, TMP, in);
537 __ And(out, out, TMP);
538 // Count number of leading zeroes.
Chris Larsen86829602015-11-18 12:27:52 -0800539 __ ClzR2(out, out);
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800540 // Subtract number of leading zeroes from 32 to get number of trailing ones.
541 // Remember that the trailing ones were formerly trailing zeroes.
542 __ LoadConst32(TMP, 32);
543 __ Subu(out, TMP, out);
Chris Larsen86829602015-11-18 12:27:52 -0800544 }
545
546 if (is64bit) {
547 // If in_lo is zero, then we counted the number of trailing zeroes in in_hi so we must add the
548 // number of trailing zeroes in in_lo (32) to get the correct final count
549 __ LoadConst32(TMP, 32);
550 if (isR6) {
551 __ Seleqz(TMP, TMP, in_lo);
552 } else {
553 __ Movn(TMP, ZERO, in_lo);
554 }
555 __ Addu(out, out, TMP);
556 }
557}
558
559// int java.lang.Integer.numberOfTrailingZeros(int i)
560void IntrinsicLocationsBuilderMIPS::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
561 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
562}
563
564void IntrinsicCodeGeneratorMIPS::VisitIntegerNumberOfTrailingZeros(HInvoke* invoke) {
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800565 GenNumberOfTrailingZeroes(invoke->GetLocations(), /* is64bit */ false, IsR6(), GetAssembler());
Chris Larsen86829602015-11-18 12:27:52 -0800566}
567
568// int java.lang.Long.numberOfTrailingZeros(long i)
569void IntrinsicLocationsBuilderMIPS::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
570 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
571}
572
573void IntrinsicCodeGeneratorMIPS::VisitLongNumberOfTrailingZeros(HInvoke* invoke) {
Chris Larsenbbb2ebe2016-02-17 17:44:58 -0800574 GenNumberOfTrailingZeroes(invoke->GetLocations(), /* is64bit */ true, IsR6(), GetAssembler());
Chris Larsene16ce5a2015-11-18 12:30:20 -0800575}
576
Chris Larsen70014c82015-11-18 12:26:08 -0800577// int java.lang.Integer.reverse(int)
578void IntrinsicLocationsBuilderMIPS::VisitIntegerReverse(HInvoke* invoke) {
579 CreateIntToIntLocations(arena_, invoke);
580}
581
582void IntrinsicCodeGeneratorMIPS::VisitIntegerReverse(HInvoke* invoke) {
583 GenReverse(invoke->GetLocations(),
584 Primitive::kPrimInt,
Chris Larsene16ce5a2015-11-18 12:30:20 -0800585 IsR2OrNewer(),
586 IsR6(),
Chris Larsenb74353a2015-11-20 09:07:09 -0800587 /* reverseBits */ true,
Chris Larsen70014c82015-11-18 12:26:08 -0800588 GetAssembler());
589}
590
591// long java.lang.Long.reverse(long)
592void IntrinsicLocationsBuilderMIPS::VisitLongReverse(HInvoke* invoke) {
593 CreateIntToIntLocations(arena_, invoke);
594}
595
596void IntrinsicCodeGeneratorMIPS::VisitLongReverse(HInvoke* invoke) {
597 GenReverse(invoke->GetLocations(),
598 Primitive::kPrimLong,
Chris Larsene16ce5a2015-11-18 12:30:20 -0800599 IsR2OrNewer(),
600 IsR6(),
Chris Larsenb74353a2015-11-20 09:07:09 -0800601 /* reverseBits */ true,
Chris Larsen70014c82015-11-18 12:26:08 -0800602 GetAssembler());
Chris Larsen3f8bf652015-10-28 10:08:56 -0700603}
604
Chris Larsenb74353a2015-11-20 09:07:09 -0800605static void CreateFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
606 LocationSummary* locations = new (arena) LocationSummary(invoke,
607 LocationSummary::kNoCall,
608 kIntrinsified);
609 locations->SetInAt(0, Location::RequiresFpuRegister());
610 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
611}
612
Chris Larsenedc16452016-02-12 17:59:00 -0800613static void GenBitCount(LocationSummary* locations,
614 Primitive::Type type,
615 bool isR6,
616 MipsAssembler* assembler) {
Chris Larsenedc16452016-02-12 17:59:00 -0800617 Register out = locations->Out().AsRegister<Register>();
618
619 // https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
620 //
621 // A generalization of the best bit counting method to integers of
622 // bit-widths up to 128 (parameterized by type T) is this:
623 //
624 // v = v - ((v >> 1) & (T)~(T)0/3); // temp
625 // v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3); // temp
626 // v = (v + (v >> 4)) & (T)~(T)0/255*15; // temp
627 // c = (T)(v * ((T)~(T)0/255)) >> (sizeof(T) - 1) * BITS_PER_BYTE; // count
628 //
629 // For comparison, for 32-bit quantities, this algorithm can be executed
630 // using 20 MIPS instructions (the calls to LoadConst32() generate two
631 // machine instructions each for the values being used in this algorithm).
632 // A(n unrolled) loop-based algorithm required 25 instructions.
633 //
634 // For 64-bit quantities, this algorithm gets executed twice, (once
635 // for in_lo, and again for in_hi), but saves a few instructions
636 // because the mask values only have to be loaded once. Using this
Chris Larsen8ca4f972016-04-14 16:16:29 -0700637 // algorithm the count for a 64-bit operand can be performed in 29
Chris Larsenedc16452016-02-12 17:59:00 -0800638 // instructions compared to a loop-based algorithm which required 47
639 // instructions.
640
641 if (type == Primitive::kPrimInt) {
642 Register in = locations->InAt(0).AsRegister<Register>();
643
644 __ Srl(TMP, in, 1);
645 __ LoadConst32(AT, 0x55555555);
646 __ And(TMP, TMP, AT);
647 __ Subu(TMP, in, TMP);
648 __ LoadConst32(AT, 0x33333333);
649 __ And(out, TMP, AT);
650 __ Srl(TMP, TMP, 2);
651 __ And(TMP, TMP, AT);
652 __ Addu(TMP, out, TMP);
653 __ Srl(out, TMP, 4);
654 __ Addu(out, out, TMP);
655 __ LoadConst32(AT, 0x0F0F0F0F);
656 __ And(out, out, AT);
657 __ LoadConst32(TMP, 0x01010101);
658 if (isR6) {
659 __ MulR6(out, out, TMP);
660 } else {
661 __ MulR2(out, out, TMP);
662 }
663 __ Srl(out, out, 24);
Roland Levillainfa3912e2016-04-01 18:21:55 +0100664 } else {
665 DCHECK_EQ(type, Primitive::kPrimLong);
Chris Larsenedc16452016-02-12 17:59:00 -0800666 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
667 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
668 Register tmp_hi = locations->GetTemp(0).AsRegister<Register>();
669 Register out_hi = locations->GetTemp(1).AsRegister<Register>();
670 Register tmp_lo = TMP;
671 Register out_lo = out;
672
673 __ Srl(tmp_lo, in_lo, 1);
674 __ Srl(tmp_hi, in_hi, 1);
675
676 __ LoadConst32(AT, 0x55555555);
677
678 __ And(tmp_lo, tmp_lo, AT);
679 __ Subu(tmp_lo, in_lo, tmp_lo);
680
681 __ And(tmp_hi, tmp_hi, AT);
682 __ Subu(tmp_hi, in_hi, tmp_hi);
683
684 __ LoadConst32(AT, 0x33333333);
685
686 __ And(out_lo, tmp_lo, AT);
687 __ Srl(tmp_lo, tmp_lo, 2);
688 __ And(tmp_lo, tmp_lo, AT);
689 __ Addu(tmp_lo, out_lo, tmp_lo);
Chris Larsenedc16452016-02-12 17:59:00 -0800690
691 __ And(out_hi, tmp_hi, AT);
692 __ Srl(tmp_hi, tmp_hi, 2);
693 __ And(tmp_hi, tmp_hi, AT);
694 __ Addu(tmp_hi, out_hi, tmp_hi);
Chris Larsenedc16452016-02-12 17:59:00 -0800695
Chris Larsen8ca4f972016-04-14 16:16:29 -0700696 // Here we deviate from the original algorithm a bit. We've reached
697 // the stage where the bitfields holding the subtotals are large
698 // enough to hold the combined subtotals for both the low word, and
699 // the high word. This means that we can add the subtotals for the
700 // the high, and low words into a single word, and compute the final
701 // result for both the high, and low words using fewer instructions.
Chris Larsenedc16452016-02-12 17:59:00 -0800702 __ LoadConst32(AT, 0x0F0F0F0F);
703
Chris Larsen8ca4f972016-04-14 16:16:29 -0700704 __ Addu(TMP, tmp_hi, tmp_lo);
705
706 __ Srl(out, TMP, 4);
707 __ And(out, out, AT);
708 __ And(TMP, TMP, AT);
709 __ Addu(out, out, TMP);
Chris Larsenedc16452016-02-12 17:59:00 -0800710
711 __ LoadConst32(AT, 0x01010101);
712
713 if (isR6) {
Chris Larsen8ca4f972016-04-14 16:16:29 -0700714 __ MulR6(out, out, AT);
Chris Larsenedc16452016-02-12 17:59:00 -0800715 } else {
Chris Larsen8ca4f972016-04-14 16:16:29 -0700716 __ MulR2(out, out, AT);
Chris Larsenedc16452016-02-12 17:59:00 -0800717 }
718
Chris Larsen8ca4f972016-04-14 16:16:29 -0700719 __ Srl(out, out, 24);
Chris Larsenedc16452016-02-12 17:59:00 -0800720 }
721}
722
723// int java.lang.Integer.bitCount(int)
724void IntrinsicLocationsBuilderMIPS::VisitIntegerBitCount(HInvoke* invoke) {
725 CreateIntToIntLocations(arena_, invoke);
726}
727
728void IntrinsicCodeGeneratorMIPS::VisitIntegerBitCount(HInvoke* invoke) {
729 GenBitCount(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
730}
731
732// int java.lang.Long.bitCount(int)
733void IntrinsicLocationsBuilderMIPS::VisitLongBitCount(HInvoke* invoke) {
734 LocationSummary* locations = new (arena_) LocationSummary(invoke,
735 LocationSummary::kNoCall,
736 kIntrinsified);
737 locations->SetInAt(0, Location::RequiresRegister());
738 locations->SetOut(Location::RequiresRegister());
739 locations->AddTemp(Location::RequiresRegister());
740 locations->AddTemp(Location::RequiresRegister());
741}
742
743void IntrinsicCodeGeneratorMIPS::VisitLongBitCount(HInvoke* invoke) {
744 GenBitCount(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
745}
746
Chris Larsenb74353a2015-11-20 09:07:09 -0800747static void MathAbsFP(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
748 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
749 FRegister out = locations->Out().AsFpuRegister<FRegister>();
750
751 if (is64bit) {
752 __ AbsD(out, in);
753 } else {
754 __ AbsS(out, in);
755 }
756}
757
758// double java.lang.Math.abs(double)
759void IntrinsicLocationsBuilderMIPS::VisitMathAbsDouble(HInvoke* invoke) {
760 CreateFPToFPLocations(arena_, invoke);
761}
762
763void IntrinsicCodeGeneratorMIPS::VisitMathAbsDouble(HInvoke* invoke) {
764 MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
765}
766
767// float java.lang.Math.abs(float)
768void IntrinsicLocationsBuilderMIPS::VisitMathAbsFloat(HInvoke* invoke) {
769 CreateFPToFPLocations(arena_, invoke);
770}
771
772void IntrinsicCodeGeneratorMIPS::VisitMathAbsFloat(HInvoke* invoke) {
773 MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
774}
775
776static void GenAbsInteger(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
777 if (is64bit) {
778 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
779 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
780 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
781 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
782
783 // The comments in this section show the analogous operations which would
784 // be performed if we had 64-bit registers "in", and "out".
785 // __ Dsra32(AT, in, 31);
786 __ Sra(AT, in_hi, 31);
787 // __ Xor(out, in, AT);
788 __ Xor(TMP, in_lo, AT);
789 __ Xor(out_hi, in_hi, AT);
790 // __ Dsubu(out, out, AT);
791 __ Subu(out_lo, TMP, AT);
792 __ Sltu(TMP, out_lo, TMP);
793 __ Addu(out_hi, out_hi, TMP);
794 } else {
795 Register in = locations->InAt(0).AsRegister<Register>();
796 Register out = locations->Out().AsRegister<Register>();
797
798 __ Sra(AT, in, 31);
799 __ Xor(out, in, AT);
800 __ Subu(out, out, AT);
801 }
802}
803
804// int java.lang.Math.abs(int)
805void IntrinsicLocationsBuilderMIPS::VisitMathAbsInt(HInvoke* invoke) {
806 CreateIntToIntLocations(arena_, invoke);
807}
808
809void IntrinsicCodeGeneratorMIPS::VisitMathAbsInt(HInvoke* invoke) {
810 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
811}
812
813// long java.lang.Math.abs(long)
814void IntrinsicLocationsBuilderMIPS::VisitMathAbsLong(HInvoke* invoke) {
815 CreateIntToIntLocations(arena_, invoke);
816}
817
818void IntrinsicCodeGeneratorMIPS::VisitMathAbsLong(HInvoke* invoke) {
819 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
820}
821
822static void GenMinMaxFP(LocationSummary* locations,
823 bool is_min,
824 Primitive::Type type,
825 bool is_R6,
826 MipsAssembler* assembler) {
827 FRegister out = locations->Out().AsFpuRegister<FRegister>();
828 FRegister a = locations->InAt(0).AsFpuRegister<FRegister>();
829 FRegister b = locations->InAt(1).AsFpuRegister<FRegister>();
830
831 if (is_R6) {
832 MipsLabel noNaNs;
833 MipsLabel done;
834 FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP;
835
836 // When Java computes min/max it prefers a NaN to a number; the
837 // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of
838 // the inputs is a NaN and the other is a valid number, the MIPS
839 // instruction will return the number; Java wants the NaN value
840 // returned. This is why there is extra logic preceding the use of
841 // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a
842 // NaN, return the NaN, otherwise return the min/max.
843 if (type == Primitive::kPrimDouble) {
844 __ CmpUnD(FTMP, a, b);
845 __ Bc1eqz(FTMP, &noNaNs);
846
847 // One of the inputs is a NaN
848 __ CmpEqD(ftmp, a, a);
849 // If a == a then b is the NaN, otherwise a is the NaN.
850 __ SelD(ftmp, a, b);
851
852 if (ftmp != out) {
853 __ MovD(out, ftmp);
854 }
855
856 __ B(&done);
857
858 __ Bind(&noNaNs);
859
860 if (is_min) {
861 __ MinD(out, a, b);
862 } else {
863 __ MaxD(out, a, b);
864 }
865 } else {
866 DCHECK_EQ(type, Primitive::kPrimFloat);
867 __ CmpUnS(FTMP, a, b);
868 __ Bc1eqz(FTMP, &noNaNs);
869
870 // One of the inputs is a NaN
871 __ CmpEqS(ftmp, a, a);
872 // If a == a then b is the NaN, otherwise a is the NaN.
873 __ SelS(ftmp, a, b);
874
875 if (ftmp != out) {
876 __ MovS(out, ftmp);
877 }
878
879 __ B(&done);
880
881 __ Bind(&noNaNs);
882
883 if (is_min) {
884 __ MinS(out, a, b);
885 } else {
886 __ MaxS(out, a, b);
887 }
888 }
889
890 __ Bind(&done);
891 } else {
892 MipsLabel ordered;
893 MipsLabel compare;
894 MipsLabel select;
895 MipsLabel done;
896
897 if (type == Primitive::kPrimDouble) {
898 __ CunD(a, b);
899 } else {
900 DCHECK_EQ(type, Primitive::kPrimFloat);
901 __ CunS(a, b);
902 }
903 __ Bc1f(&ordered);
904
905 // a or b (or both) is a NaN. Return one, which is a NaN.
906 if (type == Primitive::kPrimDouble) {
907 __ CeqD(b, b);
908 } else {
909 __ CeqS(b, b);
910 }
911 __ B(&select);
912
913 __ Bind(&ordered);
914
915 // Neither is a NaN.
916 // a == b? (-0.0 compares equal with +0.0)
917 // If equal, handle zeroes, else compare further.
918 if (type == Primitive::kPrimDouble) {
919 __ CeqD(a, b);
920 } else {
921 __ CeqS(a, b);
922 }
923 __ Bc1f(&compare);
924
925 // a == b either bit for bit or one is -0.0 and the other is +0.0.
926 if (type == Primitive::kPrimDouble) {
927 __ MoveFromFpuHigh(TMP, a);
928 __ MoveFromFpuHigh(AT, b);
929 } else {
930 __ Mfc1(TMP, a);
931 __ Mfc1(AT, b);
932 }
933
934 if (is_min) {
935 // -0.0 prevails over +0.0.
936 __ Or(TMP, TMP, AT);
937 } else {
938 // +0.0 prevails over -0.0.
939 __ And(TMP, TMP, AT);
940 }
941
942 if (type == Primitive::kPrimDouble) {
943 __ Mfc1(AT, a);
944 __ Mtc1(AT, out);
945 __ MoveToFpuHigh(TMP, out);
946 } else {
947 __ Mtc1(TMP, out);
948 }
949 __ B(&done);
950
951 __ Bind(&compare);
952
953 if (type == Primitive::kPrimDouble) {
954 if (is_min) {
955 // return (a <= b) ? a : b;
956 __ ColeD(a, b);
957 } else {
958 // return (a >= b) ? a : b;
959 __ ColeD(b, a); // b <= a
960 }
961 } else {
962 if (is_min) {
963 // return (a <= b) ? a : b;
964 __ ColeS(a, b);
965 } else {
966 // return (a >= b) ? a : b;
967 __ ColeS(b, a); // b <= a
968 }
969 }
970
971 __ Bind(&select);
972
973 if (type == Primitive::kPrimDouble) {
974 __ MovtD(out, a);
975 __ MovfD(out, b);
976 } else {
977 __ MovtS(out, a);
978 __ MovfS(out, b);
979 }
980
981 __ Bind(&done);
982 }
983}
984
985static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
986 LocationSummary* locations = new (arena) LocationSummary(invoke,
987 LocationSummary::kNoCall,
988 kIntrinsified);
989 locations->SetInAt(0, Location::RequiresFpuRegister());
990 locations->SetInAt(1, Location::RequiresFpuRegister());
991 locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap);
992}
993
994// double java.lang.Math.min(double, double)
995void IntrinsicLocationsBuilderMIPS::VisitMathMinDoubleDouble(HInvoke* invoke) {
996 CreateFPFPToFPLocations(arena_, invoke);
997}
998
999void IntrinsicCodeGeneratorMIPS::VisitMathMinDoubleDouble(HInvoke* invoke) {
1000 GenMinMaxFP(invoke->GetLocations(),
1001 /* is_min */ true,
1002 Primitive::kPrimDouble,
1003 IsR6(),
1004 GetAssembler());
1005}
1006
1007// float java.lang.Math.min(float, float)
1008void IntrinsicLocationsBuilderMIPS::VisitMathMinFloatFloat(HInvoke* invoke) {
1009 CreateFPFPToFPLocations(arena_, invoke);
1010}
1011
1012void IntrinsicCodeGeneratorMIPS::VisitMathMinFloatFloat(HInvoke* invoke) {
1013 GenMinMaxFP(invoke->GetLocations(),
1014 /* is_min */ true,
1015 Primitive::kPrimFloat,
1016 IsR6(),
1017 GetAssembler());
1018}
1019
1020// double java.lang.Math.max(double, double)
1021void IntrinsicLocationsBuilderMIPS::VisitMathMaxDoubleDouble(HInvoke* invoke) {
1022 CreateFPFPToFPLocations(arena_, invoke);
1023}
1024
1025void IntrinsicCodeGeneratorMIPS::VisitMathMaxDoubleDouble(HInvoke* invoke) {
1026 GenMinMaxFP(invoke->GetLocations(),
1027 /* is_min */ false,
1028 Primitive::kPrimDouble,
1029 IsR6(),
1030 GetAssembler());
1031}
1032
1033// float java.lang.Math.max(float, float)
1034void IntrinsicLocationsBuilderMIPS::VisitMathMaxFloatFloat(HInvoke* invoke) {
1035 CreateFPFPToFPLocations(arena_, invoke);
1036}
1037
1038void IntrinsicCodeGeneratorMIPS::VisitMathMaxFloatFloat(HInvoke* invoke) {
1039 GenMinMaxFP(invoke->GetLocations(),
1040 /* is_min */ false,
1041 Primitive::kPrimFloat,
1042 IsR6(),
1043 GetAssembler());
1044}
1045
1046static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
1047 LocationSummary* locations = new (arena) LocationSummary(invoke,
1048 LocationSummary::kNoCall,
1049 kIntrinsified);
1050 locations->SetInAt(0, Location::RequiresRegister());
1051 locations->SetInAt(1, Location::RequiresRegister());
1052 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1053}
1054
1055static void GenMinMax(LocationSummary* locations,
1056 bool is_min,
1057 Primitive::Type type,
1058 bool is_R6,
1059 MipsAssembler* assembler) {
1060 if (is_R6) {
1061 // Some architectures, such as ARM and MIPS (prior to r6), have a
1062 // conditional move instruction which only changes the target
1063 // (output) register if the condition is true (MIPS prior to r6 had
1064 // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions
1065 // always change the target (output) register. If the condition is
1066 // true the output register gets the contents of the "rs" register;
1067 // otherwise, the output register is set to zero. One consequence
1068 // of this is that to implement something like "rd = c==0 ? rs : rt"
1069 // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions.
1070 // After executing this pair of instructions one of the output
1071 // registers from the pair will necessarily contain zero. Then the
1072 // code ORs the output registers from the SELEQZ/SELNEZ instructions
1073 // to get the final result.
1074 //
1075 // The initial test to see if the output register is same as the
1076 // first input register is needed to make sure that value in the
1077 // first input register isn't clobbered before we've finished
1078 // computing the output value. The logic in the corresponding else
1079 // clause performs the same task but makes sure the second input
1080 // register isn't clobbered in the event that it's the same register
1081 // as the output register; the else clause also handles the case
1082 // where the output register is distinct from both the first, and the
1083 // second input registers.
1084 if (type == Primitive::kPrimLong) {
1085 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1086 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1087 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
1088 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
1089 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
1090 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
1091
1092 MipsLabel compare_done;
1093
1094 if (a_lo == b_lo) {
1095 if (out_lo != a_lo) {
1096 __ Move(out_lo, a_lo);
1097 __ Move(out_hi, a_hi);
1098 }
1099 } else {
1100 __ Slt(TMP, b_hi, a_hi);
1101 __ Bne(b_hi, a_hi, &compare_done);
1102
1103 __ Sltu(TMP, b_lo, a_lo);
1104
1105 __ Bind(&compare_done);
1106
1107 if (is_min) {
1108 __ Seleqz(AT, a_lo, TMP);
1109 __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo
1110 // because at this point we're
1111 // done using a_lo/b_lo.
1112 } else {
1113 __ Selnez(AT, a_lo, TMP);
1114 __ Seleqz(out_lo, b_lo, TMP); // ditto
1115 }
1116 __ Or(out_lo, out_lo, AT);
1117 if (is_min) {
1118 __ Seleqz(AT, a_hi, TMP);
1119 __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
1120 } else {
1121 __ Selnez(AT, a_hi, TMP);
1122 __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
1123 }
1124 __ Or(out_hi, out_hi, AT);
1125 }
1126 } else {
1127 DCHECK_EQ(type, Primitive::kPrimInt);
1128 Register a = locations->InAt(0).AsRegister<Register>();
1129 Register b = locations->InAt(1).AsRegister<Register>();
1130 Register out = locations->Out().AsRegister<Register>();
1131
1132 if (a == b) {
1133 if (out != a) {
1134 __ Move(out, a);
1135 }
1136 } else {
1137 __ Slt(AT, b, a);
1138 if (is_min) {
1139 __ Seleqz(TMP, a, AT);
1140 __ Selnez(AT, b, AT);
1141 } else {
1142 __ Selnez(TMP, a, AT);
1143 __ Seleqz(AT, b, AT);
1144 }
1145 __ Or(out, TMP, AT);
1146 }
1147 }
1148 } else {
1149 if (type == Primitive::kPrimLong) {
1150 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1151 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1152 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
1153 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
1154 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
1155 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
1156
1157 MipsLabel compare_done;
1158
1159 if (a_lo == b_lo) {
1160 if (out_lo != a_lo) {
1161 __ Move(out_lo, a_lo);
1162 __ Move(out_hi, a_hi);
1163 }
1164 } else {
1165 __ Slt(TMP, a_hi, b_hi);
1166 __ Bne(a_hi, b_hi, &compare_done);
1167
1168 __ Sltu(TMP, a_lo, b_lo);
1169
1170 __ Bind(&compare_done);
1171
1172 if (is_min) {
1173 if (out_lo != a_lo) {
1174 __ Movn(out_hi, a_hi, TMP);
1175 __ Movn(out_lo, a_lo, TMP);
1176 }
1177 if (out_lo != b_lo) {
1178 __ Movz(out_hi, b_hi, TMP);
1179 __ Movz(out_lo, b_lo, TMP);
1180 }
1181 } else {
1182 if (out_lo != a_lo) {
1183 __ Movz(out_hi, a_hi, TMP);
1184 __ Movz(out_lo, a_lo, TMP);
1185 }
1186 if (out_lo != b_lo) {
1187 __ Movn(out_hi, b_hi, TMP);
1188 __ Movn(out_lo, b_lo, TMP);
1189 }
1190 }
1191 }
1192 } else {
1193 DCHECK_EQ(type, Primitive::kPrimInt);
1194 Register a = locations->InAt(0).AsRegister<Register>();
1195 Register b = locations->InAt(1).AsRegister<Register>();
1196 Register out = locations->Out().AsRegister<Register>();
1197
1198 if (a == b) {
1199 if (out != a) {
1200 __ Move(out, a);
1201 }
1202 } else {
1203 __ Slt(AT, a, b);
1204 if (is_min) {
1205 if (out != a) {
1206 __ Movn(out, a, AT);
1207 }
1208 if (out != b) {
1209 __ Movz(out, b, AT);
1210 }
1211 } else {
1212 if (out != a) {
1213 __ Movz(out, a, AT);
1214 }
1215 if (out != b) {
1216 __ Movn(out, b, AT);
1217 }
1218 }
1219 }
1220 }
1221 }
1222}
1223
1224// int java.lang.Math.min(int, int)
1225void IntrinsicLocationsBuilderMIPS::VisitMathMinIntInt(HInvoke* invoke) {
1226 CreateIntIntToIntLocations(arena_, invoke);
1227}
1228
1229void IntrinsicCodeGeneratorMIPS::VisitMathMinIntInt(HInvoke* invoke) {
1230 GenMinMax(invoke->GetLocations(),
1231 /* is_min */ true,
1232 Primitive::kPrimInt,
1233 IsR6(),
1234 GetAssembler());
1235}
1236
1237// long java.lang.Math.min(long, long)
1238void IntrinsicLocationsBuilderMIPS::VisitMathMinLongLong(HInvoke* invoke) {
1239 CreateIntIntToIntLocations(arena_, invoke);
1240}
1241
1242void IntrinsicCodeGeneratorMIPS::VisitMathMinLongLong(HInvoke* invoke) {
1243 GenMinMax(invoke->GetLocations(),
1244 /* is_min */ true,
1245 Primitive::kPrimLong,
1246 IsR6(),
1247 GetAssembler());
1248}
1249
1250// int java.lang.Math.max(int, int)
1251void IntrinsicLocationsBuilderMIPS::VisitMathMaxIntInt(HInvoke* invoke) {
1252 CreateIntIntToIntLocations(arena_, invoke);
1253}
1254
1255void IntrinsicCodeGeneratorMIPS::VisitMathMaxIntInt(HInvoke* invoke) {
1256 GenMinMax(invoke->GetLocations(),
1257 /* is_min */ false,
1258 Primitive::kPrimInt,
1259 IsR6(),
1260 GetAssembler());
1261}
1262
1263// long java.lang.Math.max(long, long)
1264void IntrinsicLocationsBuilderMIPS::VisitMathMaxLongLong(HInvoke* invoke) {
1265 CreateIntIntToIntLocations(arena_, invoke);
1266}
1267
1268void IntrinsicCodeGeneratorMIPS::VisitMathMaxLongLong(HInvoke* invoke) {
1269 GenMinMax(invoke->GetLocations(),
1270 /* is_min */ false,
1271 Primitive::kPrimLong,
1272 IsR6(),
1273 GetAssembler());
1274}
1275
1276// double java.lang.Math.sqrt(double)
1277void IntrinsicLocationsBuilderMIPS::VisitMathSqrt(HInvoke* invoke) {
1278 CreateFPToFPLocations(arena_, invoke);
1279}
1280
1281void IntrinsicCodeGeneratorMIPS::VisitMathSqrt(HInvoke* invoke) {
1282 LocationSummary* locations = invoke->GetLocations();
1283 MipsAssembler* assembler = GetAssembler();
1284 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
1285 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1286
1287 __ SqrtD(out, in);
1288}
1289
Chris Larsen3acee732015-11-18 13:31:08 -08001290// byte libcore.io.Memory.peekByte(long address)
1291void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekByte(HInvoke* invoke) {
1292 CreateIntToIntLocations(arena_, invoke);
1293}
1294
1295void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekByte(HInvoke* invoke) {
1296 MipsAssembler* assembler = GetAssembler();
1297 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1298 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1299
1300 __ Lb(out, adr, 0);
1301}
1302
1303// short libcore.io.Memory.peekShort(long address)
1304void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekShortNative(HInvoke* invoke) {
1305 CreateIntToIntLocations(arena_, invoke);
1306}
1307
1308void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekShortNative(HInvoke* invoke) {
1309 MipsAssembler* assembler = GetAssembler();
1310 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1311 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1312
1313 if (IsR6()) {
1314 __ Lh(out, adr, 0);
1315 } else if (IsR2OrNewer()) {
1316 // Unlike for words, there are no lhl/lhr instructions to load
1317 // unaligned halfwords so the code loads individual bytes, in case
1318 // the address isn't halfword-aligned, and assembles them into a
1319 // signed halfword.
1320 __ Lb(AT, adr, 1); // This byte must be sign-extended.
1321 __ Lb(out, adr, 0); // This byte can be either sign-extended, or
1322 // zero-extended because the following
1323 // instruction overwrites the sign bits.
1324 __ Ins(out, AT, 8, 24);
1325 } else {
1326 __ Lbu(AT, adr, 0); // This byte must be zero-extended. If it's not
1327 // the "or" instruction below will destroy the upper
1328 // 24 bits of the final result.
1329 __ Lb(out, adr, 1); // This byte must be sign-extended.
1330 __ Sll(out, out, 8);
1331 __ Or(out, out, AT);
1332 }
1333}
1334
1335// int libcore.io.Memory.peekInt(long address)
1336void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekIntNative(HInvoke* invoke) {
1337 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
1338}
1339
1340void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekIntNative(HInvoke* invoke) {
1341 MipsAssembler* assembler = GetAssembler();
1342 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1343 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1344
1345 if (IsR6()) {
1346 __ Lw(out, adr, 0);
1347 } else {
1348 __ Lwr(out, adr, 0);
1349 __ Lwl(out, adr, 3);
1350 }
1351}
1352
1353// long libcore.io.Memory.peekLong(long address)
1354void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekLongNative(HInvoke* invoke) {
1355 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
1356}
1357
1358void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekLongNative(HInvoke* invoke) {
1359 MipsAssembler* assembler = GetAssembler();
1360 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1361 Register out_lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>();
1362 Register out_hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>();
1363
1364 if (IsR6()) {
1365 __ Lw(out_lo, adr, 0);
1366 __ Lw(out_hi, adr, 4);
1367 } else {
1368 __ Lwr(out_lo, adr, 0);
1369 __ Lwl(out_lo, adr, 3);
1370 __ Lwr(out_hi, adr, 4);
1371 __ Lwl(out_hi, adr, 7);
1372 }
1373}
1374
1375static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
1376 LocationSummary* locations = new (arena) LocationSummary(invoke,
1377 LocationSummary::kNoCall,
1378 kIntrinsified);
1379 locations->SetInAt(0, Location::RequiresRegister());
1380 locations->SetInAt(1, Location::RequiresRegister());
1381}
1382
1383// void libcore.io.Memory.pokeByte(long address, byte value)
1384void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeByte(HInvoke* invoke) {
1385 CreateIntIntToVoidLocations(arena_, invoke);
1386}
1387
1388void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeByte(HInvoke* invoke) {
1389 MipsAssembler* assembler = GetAssembler();
1390 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1391 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1392
1393 __ Sb(val, adr, 0);
1394}
1395
1396// void libcore.io.Memory.pokeShort(long address, short value)
1397void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeShortNative(HInvoke* invoke) {
1398 CreateIntIntToVoidLocations(arena_, invoke);
1399}
1400
1401void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeShortNative(HInvoke* invoke) {
1402 MipsAssembler* assembler = GetAssembler();
1403 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1404 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1405
1406 if (IsR6()) {
1407 __ Sh(val, adr, 0);
1408 } else {
1409 // Unlike for words, there are no shl/shr instructions to store
1410 // unaligned halfwords so the code stores individual bytes, in case
1411 // the address isn't halfword-aligned.
1412 __ Sb(val, adr, 0);
1413 __ Srl(AT, val, 8);
1414 __ Sb(AT, adr, 1);
1415 }
1416}
1417
1418// void libcore.io.Memory.pokeInt(long address, int value)
1419void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeIntNative(HInvoke* invoke) {
1420 CreateIntIntToVoidLocations(arena_, invoke);
1421}
1422
1423void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeIntNative(HInvoke* invoke) {
1424 MipsAssembler* assembler = GetAssembler();
1425 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1426 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1427
1428 if (IsR6()) {
1429 __ Sw(val, adr, 0);
1430 } else {
1431 __ Swr(val, adr, 0);
1432 __ Swl(val, adr, 3);
1433 }
1434}
1435
1436// void libcore.io.Memory.pokeLong(long address, long value)
1437void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeLongNative(HInvoke* invoke) {
1438 CreateIntIntToVoidLocations(arena_, invoke);
1439}
1440
1441void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeLongNative(HInvoke* invoke) {
1442 MipsAssembler* assembler = GetAssembler();
1443 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1444 Register val_lo = invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>();
1445 Register val_hi = invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>();
1446
1447 if (IsR6()) {
1448 __ Sw(val_lo, adr, 0);
1449 __ Sw(val_hi, adr, 4);
1450 } else {
1451 __ Swr(val_lo, adr, 0);
1452 __ Swl(val_lo, adr, 3);
1453 __ Swr(val_hi, adr, 4);
1454 __ Swl(val_hi, adr, 7);
1455 }
1456}
1457
Chris Larsencf283da2016-01-19 16:45:35 -08001458// Thread java.lang.Thread.currentThread()
1459void IntrinsicLocationsBuilderMIPS::VisitThreadCurrentThread(HInvoke* invoke) {
1460 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1461 LocationSummary::kNoCall,
1462 kIntrinsified);
1463 locations->SetOut(Location::RequiresRegister());
1464}
1465
1466void IntrinsicCodeGeneratorMIPS::VisitThreadCurrentThread(HInvoke* invoke) {
1467 MipsAssembler* assembler = GetAssembler();
1468 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1469
1470 __ LoadFromOffset(kLoadWord,
1471 out,
1472 TR,
1473 Thread::PeerOffset<kMipsPointerSize>().Int32Value());
1474}
1475
Chris Larsen4fdc6d92015-12-14 13:26:14 -08001476static void CreateIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
1477 bool can_call =
1478 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObject ||
1479 invoke->GetIntrinsic() == Intrinsics::kUnsafeGetObjectVolatile;
1480 LocationSummary* locations = new (arena) LocationSummary(invoke,
1481 can_call ?
1482 LocationSummary::kCallOnSlowPath :
1483 LocationSummary::kNoCall,
1484 kIntrinsified);
1485 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1486 locations->SetInAt(1, Location::RequiresRegister());
1487 locations->SetInAt(2, Location::RequiresRegister());
1488 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1489}
1490
1491static void GenUnsafeGet(HInvoke* invoke,
1492 Primitive::Type type,
1493 bool is_volatile,
1494 bool is_R6,
1495 CodeGeneratorMIPS* codegen) {
1496 LocationSummary* locations = invoke->GetLocations();
1497 DCHECK((type == Primitive::kPrimInt) ||
1498 (type == Primitive::kPrimLong) ||
1499 (type == Primitive::kPrimNot)) << type;
1500 MipsAssembler* assembler = codegen->GetAssembler();
1501 // Object pointer.
1502 Register base = locations->InAt(1).AsRegister<Register>();
1503 // The "offset" argument is passed as a "long". Since this code is for
1504 // a 32-bit processor, we can only use 32-bit addresses, so we only
1505 // need the low 32-bits of offset.
1506 Register offset_lo = invoke->GetLocations()->InAt(2).AsRegisterPairLow<Register>();
1507
1508 __ Addu(TMP, base, offset_lo);
1509 if (is_volatile) {
1510 __ Sync(0);
1511 }
1512 if (type == Primitive::kPrimLong) {
1513 Register trg_lo = locations->Out().AsRegisterPairLow<Register>();
1514 Register trg_hi = locations->Out().AsRegisterPairHigh<Register>();
1515
1516 if (is_R6) {
1517 __ Lw(trg_lo, TMP, 0);
1518 __ Lw(trg_hi, TMP, 4);
1519 } else {
1520 __ Lwr(trg_lo, TMP, 0);
1521 __ Lwl(trg_lo, TMP, 3);
1522 __ Lwr(trg_hi, TMP, 4);
1523 __ Lwl(trg_hi, TMP, 7);
1524 }
1525 } else {
1526 Register trg = locations->Out().AsRegister<Register>();
1527
1528 if (is_R6) {
1529 __ Lw(trg, TMP, 0);
1530 } else {
1531 __ Lwr(trg, TMP, 0);
1532 __ Lwl(trg, TMP, 3);
1533 }
1534 }
1535}
1536
1537// int sun.misc.Unsafe.getInt(Object o, long offset)
1538void IntrinsicLocationsBuilderMIPS::VisitUnsafeGet(HInvoke* invoke) {
1539 CreateIntIntIntToIntLocations(arena_, invoke);
1540}
1541
1542void IntrinsicCodeGeneratorMIPS::VisitUnsafeGet(HInvoke* invoke) {
1543 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ false, IsR6(), codegen_);
1544}
1545
1546// int sun.misc.Unsafe.getIntVolatile(Object o, long offset)
1547void IntrinsicLocationsBuilderMIPS::VisitUnsafeGetVolatile(HInvoke* invoke) {
1548 CreateIntIntIntToIntLocations(arena_, invoke);
1549}
1550
1551void IntrinsicCodeGeneratorMIPS::VisitUnsafeGetVolatile(HInvoke* invoke) {
1552 GenUnsafeGet(invoke, Primitive::kPrimInt, /* is_volatile */ true, IsR6(), codegen_);
1553}
1554
1555// long sun.misc.Unsafe.getLong(Object o, long offset)
1556void IntrinsicLocationsBuilderMIPS::VisitUnsafeGetLong(HInvoke* invoke) {
1557 CreateIntIntIntToIntLocations(arena_, invoke);
1558}
1559
1560void IntrinsicCodeGeneratorMIPS::VisitUnsafeGetLong(HInvoke* invoke) {
1561 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ false, IsR6(), codegen_);
1562}
1563
1564// long sun.misc.Unsafe.getLongVolatile(Object o, long offset)
1565void IntrinsicLocationsBuilderMIPS::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1566 CreateIntIntIntToIntLocations(arena_, invoke);
1567}
1568
1569void IntrinsicCodeGeneratorMIPS::VisitUnsafeGetLongVolatile(HInvoke* invoke) {
1570 GenUnsafeGet(invoke, Primitive::kPrimLong, /* is_volatile */ true, IsR6(), codegen_);
1571}
1572
1573// Object sun.misc.Unsafe.getObject(Object o, long offset)
1574void IntrinsicLocationsBuilderMIPS::VisitUnsafeGetObject(HInvoke* invoke) {
1575 CreateIntIntIntToIntLocations(arena_, invoke);
1576}
1577
1578void IntrinsicCodeGeneratorMIPS::VisitUnsafeGetObject(HInvoke* invoke) {
1579 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ false, IsR6(), codegen_);
1580}
1581
1582// Object sun.misc.Unsafe.getObjectVolatile(Object o, long offset)
1583void IntrinsicLocationsBuilderMIPS::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1584 CreateIntIntIntToIntLocations(arena_, invoke);
1585}
1586
1587void IntrinsicCodeGeneratorMIPS::VisitUnsafeGetObjectVolatile(HInvoke* invoke) {
1588 GenUnsafeGet(invoke, Primitive::kPrimNot, /* is_volatile */ true, IsR6(), codegen_);
1589}
1590
1591static void CreateIntIntIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
1592 LocationSummary* locations = new (arena) LocationSummary(invoke,
1593 LocationSummary::kNoCall,
1594 kIntrinsified);
1595 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1596 locations->SetInAt(1, Location::RequiresRegister());
1597 locations->SetInAt(2, Location::RequiresRegister());
1598 locations->SetInAt(3, Location::RequiresRegister());
1599}
1600
1601static void GenUnsafePut(LocationSummary* locations,
1602 Primitive::Type type,
1603 bool is_volatile,
1604 bool is_ordered,
1605 bool is_R6,
1606 CodeGeneratorMIPS* codegen) {
1607 DCHECK((type == Primitive::kPrimInt) ||
1608 (type == Primitive::kPrimLong) ||
1609 (type == Primitive::kPrimNot)) << type;
1610 MipsAssembler* assembler = codegen->GetAssembler();
1611 // Object pointer.
1612 Register base = locations->InAt(1).AsRegister<Register>();
1613 // The "offset" argument is passed as a "long", i.e., it's 64-bits in
1614 // size. Since this code is for a 32-bit processor, we can only use
1615 // 32-bit addresses, so we only need the low 32-bits of offset.
1616 Register offset_lo = locations->InAt(2).AsRegisterPairLow<Register>();
1617
1618 __ Addu(TMP, base, offset_lo);
1619 if (is_volatile || is_ordered) {
1620 __ Sync(0);
1621 }
1622 if ((type == Primitive::kPrimInt) || (type == Primitive::kPrimNot)) {
1623 Register value = locations->InAt(3).AsRegister<Register>();
1624
1625 if (is_R6) {
1626 __ Sw(value, TMP, 0);
1627 } else {
1628 __ Swr(value, TMP, 0);
1629 __ Swl(value, TMP, 3);
1630 }
1631 } else {
1632 Register value_lo = locations->InAt(3).AsRegisterPairLow<Register>();
1633 Register value_hi = locations->InAt(3).AsRegisterPairHigh<Register>();
1634
1635 if (is_R6) {
1636 __ Sw(value_lo, TMP, 0);
1637 __ Sw(value_hi, TMP, 4);
1638 } else {
1639 __ Swr(value_lo, TMP, 0);
1640 __ Swl(value_lo, TMP, 3);
1641 __ Swr(value_hi, TMP, 4);
1642 __ Swl(value_hi, TMP, 7);
1643 }
1644 }
1645
1646 if (is_volatile) {
1647 __ Sync(0);
1648 }
1649
1650 if (type == Primitive::kPrimNot) {
1651 codegen->MarkGCCard(base, locations->InAt(3).AsRegister<Register>());
1652 }
1653}
1654
1655// void sun.misc.Unsafe.putInt(Object o, long offset, int x)
1656void IntrinsicLocationsBuilderMIPS::VisitUnsafePut(HInvoke* invoke) {
1657 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1658}
1659
1660void IntrinsicCodeGeneratorMIPS::VisitUnsafePut(HInvoke* invoke) {
1661 GenUnsafePut(invoke->GetLocations(),
1662 Primitive::kPrimInt,
1663 /* is_volatile */ false,
1664 /* is_ordered */ false,
1665 IsR6(),
1666 codegen_);
1667}
1668
1669// void sun.misc.Unsafe.putOrderedInt(Object o, long offset, int x)
1670void IntrinsicLocationsBuilderMIPS::VisitUnsafePutOrdered(HInvoke* invoke) {
1671 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1672}
1673
1674void IntrinsicCodeGeneratorMIPS::VisitUnsafePutOrdered(HInvoke* invoke) {
1675 GenUnsafePut(invoke->GetLocations(),
1676 Primitive::kPrimInt,
1677 /* is_volatile */ false,
1678 /* is_ordered */ true,
1679 IsR6(),
1680 codegen_);
1681}
1682
1683// void sun.misc.Unsafe.putIntVolatile(Object o, long offset, int x)
1684void IntrinsicLocationsBuilderMIPS::VisitUnsafePutVolatile(HInvoke* invoke) {
1685 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1686}
1687
1688void IntrinsicCodeGeneratorMIPS::VisitUnsafePutVolatile(HInvoke* invoke) {
1689 GenUnsafePut(invoke->GetLocations(),
1690 Primitive::kPrimInt,
1691 /* is_volatile */ true,
1692 /* is_ordered */ false,
1693 IsR6(),
1694 codegen_);
1695}
1696
1697// void sun.misc.Unsafe.putObject(Object o, long offset, Object x)
1698void IntrinsicLocationsBuilderMIPS::VisitUnsafePutObject(HInvoke* invoke) {
1699 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1700}
1701
1702void IntrinsicCodeGeneratorMIPS::VisitUnsafePutObject(HInvoke* invoke) {
1703 GenUnsafePut(invoke->GetLocations(),
1704 Primitive::kPrimNot,
1705 /* is_volatile */ false,
1706 /* is_ordered */ false,
1707 IsR6(),
1708 codegen_);
1709}
1710
1711// void sun.misc.Unsafe.putOrderedObject(Object o, long offset, Object x)
1712void IntrinsicLocationsBuilderMIPS::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1713 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1714}
1715
1716void IntrinsicCodeGeneratorMIPS::VisitUnsafePutObjectOrdered(HInvoke* invoke) {
1717 GenUnsafePut(invoke->GetLocations(),
1718 Primitive::kPrimNot,
1719 /* is_volatile */ false,
1720 /* is_ordered */ true,
1721 IsR6(),
1722 codegen_);
1723}
1724
1725// void sun.misc.Unsafe.putObjectVolatile(Object o, long offset, Object x)
1726void IntrinsicLocationsBuilderMIPS::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1727 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1728}
1729
1730void IntrinsicCodeGeneratorMIPS::VisitUnsafePutObjectVolatile(HInvoke* invoke) {
1731 GenUnsafePut(invoke->GetLocations(),
1732 Primitive::kPrimNot,
1733 /* is_volatile */ true,
1734 /* is_ordered */ false,
1735 IsR6(),
1736 codegen_);
1737}
1738
1739// void sun.misc.Unsafe.putLong(Object o, long offset, long x)
1740void IntrinsicLocationsBuilderMIPS::VisitUnsafePutLong(HInvoke* invoke) {
1741 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1742}
1743
1744void IntrinsicCodeGeneratorMIPS::VisitUnsafePutLong(HInvoke* invoke) {
1745 GenUnsafePut(invoke->GetLocations(),
1746 Primitive::kPrimLong,
1747 /* is_volatile */ false,
1748 /* is_ordered */ false,
1749 IsR6(),
1750 codegen_);
1751}
1752
1753// void sun.misc.Unsafe.putOrderedLong(Object o, long offset, long x)
1754void IntrinsicLocationsBuilderMIPS::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1755 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1756}
1757
1758void IntrinsicCodeGeneratorMIPS::VisitUnsafePutLongOrdered(HInvoke* invoke) {
1759 GenUnsafePut(invoke->GetLocations(),
1760 Primitive::kPrimLong,
1761 /* is_volatile */ false,
1762 /* is_ordered */ true,
1763 IsR6(),
1764 codegen_);
1765}
1766
1767// void sun.misc.Unsafe.putLongVolatile(Object o, long offset, long x)
1768void IntrinsicLocationsBuilderMIPS::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1769 CreateIntIntIntIntToVoidLocations(arena_, invoke);
1770}
1771
1772void IntrinsicCodeGeneratorMIPS::VisitUnsafePutLongVolatile(HInvoke* invoke) {
1773 GenUnsafePut(invoke->GetLocations(),
1774 Primitive::kPrimLong,
1775 /* is_volatile */ true,
1776 /* is_ordered */ false,
1777 IsR6(),
1778 codegen_);
1779}
1780
Alexey Frunze51aff3a2016-03-17 17:21:45 -07001781static void CreateIntIntIntIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
1782 LocationSummary* locations = new (arena) LocationSummary(invoke,
1783 LocationSummary::kNoCall,
1784 kIntrinsified);
1785 locations->SetInAt(0, Location::NoLocation()); // Unused receiver.
1786 locations->SetInAt(1, Location::RequiresRegister());
1787 locations->SetInAt(2, Location::RequiresRegister());
1788 locations->SetInAt(3, Location::RequiresRegister());
1789 locations->SetInAt(4, Location::RequiresRegister());
1790
1791 locations->SetOut(Location::RequiresRegister());
1792}
1793
1794static void GenCas(LocationSummary* locations, Primitive::Type type, CodeGeneratorMIPS* codegen) {
1795 MipsAssembler* assembler = codegen->GetAssembler();
1796 bool isR6 = codegen->GetInstructionSetFeatures().IsR6();
1797 Register base = locations->InAt(1).AsRegister<Register>();
1798 Register offset_lo = locations->InAt(2).AsRegisterPairLow<Register>();
1799 Register expected = locations->InAt(3).AsRegister<Register>();
1800 Register value = locations->InAt(4).AsRegister<Register>();
1801 Register out = locations->Out().AsRegister<Register>();
1802
1803 DCHECK_NE(base, out);
1804 DCHECK_NE(offset_lo, out);
1805 DCHECK_NE(expected, out);
1806
1807 if (type == Primitive::kPrimNot) {
1808 // Mark card for object assuming new value is stored.
1809 codegen->MarkGCCard(base, value);
1810 }
1811
1812 // do {
1813 // tmp_value = [tmp_ptr] - expected;
1814 // } while (tmp_value == 0 && failure([tmp_ptr] <- r_new_value));
1815 // result = tmp_value != 0;
1816
1817 MipsLabel loop_head, exit_loop;
1818 __ Addu(TMP, base, offset_lo);
1819 __ Sync(0);
1820 __ Bind(&loop_head);
1821 if ((type == Primitive::kPrimInt) || (type == Primitive::kPrimNot)) {
1822 if (isR6) {
1823 __ LlR6(out, TMP);
1824 } else {
1825 __ LlR2(out, TMP);
1826 }
1827 } else {
1828 LOG(FATAL) << "Unsupported op size " << type;
1829 UNREACHABLE();
1830 }
1831 __ Subu(out, out, expected); // If we didn't get the 'expected'
1832 __ Sltiu(out, out, 1); // value, set 'out' to false, and
1833 __ Beqz(out, &exit_loop); // return.
1834 __ Move(out, value); // Use 'out' for the 'store conditional' instruction.
1835 // If we use 'value' directly, we would lose 'value'
1836 // in the case that the store fails. Whether the
1837 // store succeeds, or fails, it will load the
1838 // correct boolean value into the 'out' register.
1839 // This test isn't really necessary. We only support Primitive::kPrimInt,
1840 // Primitive::kPrimNot, and we already verified that we're working on one
1841 // of those two types. It's left here in case the code needs to support
1842 // other types in the future.
1843 if ((type == Primitive::kPrimInt) || (type == Primitive::kPrimNot)) {
1844 if (isR6) {
1845 __ ScR6(out, TMP);
1846 } else {
1847 __ ScR2(out, TMP);
1848 }
1849 }
1850 __ Beqz(out, &loop_head); // If we couldn't do the read-modify-write
1851 // cycle atomically then retry.
1852 __ Bind(&exit_loop);
1853 __ Sync(0);
1854}
1855
1856// boolean sun.misc.Unsafe.compareAndSwapInt(Object o, long offset, int expected, int x)
1857void IntrinsicLocationsBuilderMIPS::VisitUnsafeCASInt(HInvoke* invoke) {
1858 CreateIntIntIntIntIntToIntLocations(arena_, invoke);
1859}
1860
1861void IntrinsicCodeGeneratorMIPS::VisitUnsafeCASInt(HInvoke* invoke) {
1862 GenCas(invoke->GetLocations(), Primitive::kPrimInt, codegen_);
1863}
1864
1865// boolean sun.misc.Unsafe.compareAndSwapObject(Object o, long offset, Object expected, Object x)
1866void IntrinsicLocationsBuilderMIPS::VisitUnsafeCASObject(HInvoke* invoke) {
1867 CreateIntIntIntIntIntToIntLocations(arena_, invoke);
1868}
1869
1870void IntrinsicCodeGeneratorMIPS::VisitUnsafeCASObject(HInvoke* invoke) {
1871 GenCas(invoke->GetLocations(), Primitive::kPrimNot, codegen_);
1872}
1873
Chris Larsencf283da2016-01-19 16:45:35 -08001874// int java.lang.String.compareTo(String anotherString)
1875void IntrinsicLocationsBuilderMIPS::VisitStringCompareTo(HInvoke* invoke) {
1876 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescufca16662016-07-14 09:21:59 +01001877 LocationSummary::kCallOnMainAndSlowPath,
Chris Larsencf283da2016-01-19 16:45:35 -08001878 kIntrinsified);
1879 InvokeRuntimeCallingConvention calling_convention;
1880 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1881 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1882 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1883 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1884}
1885
1886void IntrinsicCodeGeneratorMIPS::VisitStringCompareTo(HInvoke* invoke) {
1887 MipsAssembler* assembler = GetAssembler();
1888 LocationSummary* locations = invoke->GetLocations();
1889
1890 // Note that the null check must have been done earlier.
1891 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1892
1893 Register argument = locations->InAt(1).AsRegister<Register>();
1894 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
1895 codegen_->AddSlowPath(slow_path);
1896 __ Beqz(argument, slow_path->GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +01001897 codegen_->InvokeRuntime(kQuickStringCompareTo, invoke, invoke->GetDexPc(), slow_path);
Chris Larsencf283da2016-01-19 16:45:35 -08001898 __ Bind(slow_path->GetExitLabel());
1899}
1900
Chris Larsen16ba2b42015-11-02 10:58:31 -08001901// boolean java.lang.String.equals(Object anObject)
1902void IntrinsicLocationsBuilderMIPS::VisitStringEquals(HInvoke* invoke) {
1903 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1904 LocationSummary::kNoCall,
1905 kIntrinsified);
1906 locations->SetInAt(0, Location::RequiresRegister());
1907 locations->SetInAt(1, Location::RequiresRegister());
1908 locations->SetOut(Location::RequiresRegister());
1909
1910 // Temporary registers to store lengths of strings and for calculations.
1911 locations->AddTemp(Location::RequiresRegister());
1912 locations->AddTemp(Location::RequiresRegister());
1913 locations->AddTemp(Location::RequiresRegister());
1914}
1915
1916void IntrinsicCodeGeneratorMIPS::VisitStringEquals(HInvoke* invoke) {
1917 MipsAssembler* assembler = GetAssembler();
1918 LocationSummary* locations = invoke->GetLocations();
1919
1920 Register str = locations->InAt(0).AsRegister<Register>();
1921 Register arg = locations->InAt(1).AsRegister<Register>();
1922 Register out = locations->Out().AsRegister<Register>();
1923
1924 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
1925 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
1926 Register temp3 = locations->GetTemp(2).AsRegister<Register>();
1927
1928 MipsLabel loop;
1929 MipsLabel end;
1930 MipsLabel return_true;
1931 MipsLabel return_false;
1932
1933 // Get offsets of count, value, and class fields within a string object.
1934 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1935 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1936 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1937
1938 // Note that the null check must have been done earlier.
1939 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1940
1941 // If the register containing the pointer to "this", and the register
1942 // containing the pointer to "anObject" are the same register then
1943 // "this", and "anObject" are the same object and we can
1944 // short-circuit the logic to a true result.
1945 if (str == arg) {
1946 __ LoadConst32(out, 1);
1947 return;
1948 }
1949
1950 // Check if input is null, return false if it is.
1951 __ Beqz(arg, &return_false);
1952
1953 // Reference equality check, return true if same reference.
1954 __ Beq(str, arg, &return_true);
1955
1956 // Instanceof check for the argument by comparing class fields.
1957 // All string objects must have the same type since String cannot be subclassed.
1958 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1959 // If the argument is a string object, its class field must be equal to receiver's class field.
1960 __ Lw(temp1, str, class_offset);
1961 __ Lw(temp2, arg, class_offset);
1962 __ Bne(temp1, temp2, &return_false);
1963
1964 // Load lengths of this and argument strings.
1965 __ Lw(temp1, str, count_offset);
1966 __ Lw(temp2, arg, count_offset);
1967 // Check if lengths are equal, return false if they're not.
1968 __ Bne(temp1, temp2, &return_false);
1969 // Return true if both strings are empty.
1970 __ Beqz(temp1, &return_true);
1971
1972 // Don't overwrite input registers
1973 __ Move(TMP, str);
1974 __ Move(temp3, arg);
1975
1976 // Assertions that must hold in order to compare strings 2 characters at a time.
1977 DCHECK_ALIGNED(value_offset, 4);
1978 static_assert(IsAligned<4>(kObjectAlignment), "String of odd length is not zero padded");
1979
1980 // Loop to compare strings 2 characters at a time starting at the beginning of the string.
1981 // Ok to do this because strings are zero-padded.
1982 __ Bind(&loop);
1983 __ Lw(out, TMP, value_offset);
1984 __ Lw(temp2, temp3, value_offset);
1985 __ Bne(out, temp2, &return_false);
1986 __ Addiu(TMP, TMP, 4);
1987 __ Addiu(temp3, temp3, 4);
1988 __ Addiu(temp1, temp1, -2);
1989 __ Bgtz(temp1, &loop);
1990
1991 // Return true and exit the function.
1992 // If loop does not result in returning false, we return true.
1993 __ Bind(&return_true);
1994 __ LoadConst32(out, 1);
1995 __ B(&end);
1996
1997 // Return false and exit the function.
1998 __ Bind(&return_false);
1999 __ LoadConst32(out, 0);
2000 __ Bind(&end);
2001}
2002
Chris Larsencf283da2016-01-19 16:45:35 -08002003static void GenerateStringIndexOf(HInvoke* invoke,
2004 bool start_at_zero,
2005 MipsAssembler* assembler,
2006 CodeGeneratorMIPS* codegen,
2007 ArenaAllocator* allocator) {
2008 LocationSummary* locations = invoke->GetLocations();
2009 Register tmp_reg = start_at_zero ? locations->GetTemp(0).AsRegister<Register>() : TMP;
2010
2011 // Note that the null check must have been done earlier.
2012 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
2013
Vladimir Markofb6c90a2016-05-06 15:52:12 +01002014 // Check for code points > 0xFFFF. Either a slow-path check when we don't know statically,
2015 // or directly dispatch for a large constant, or omit slow-path for a small constant or a char.
Chris Larsencf283da2016-01-19 16:45:35 -08002016 SlowPathCodeMIPS* slow_path = nullptr;
Vladimir Markofb6c90a2016-05-06 15:52:12 +01002017 HInstruction* code_point = invoke->InputAt(1);
2018 if (code_point->IsIntConstant()) {
Vladimir Markoda051082016-05-17 16:10:20 +01002019 if (!IsUint<16>(code_point->AsIntConstant()->GetValue())) {
Chris Larsencf283da2016-01-19 16:45:35 -08002020 // Always needs the slow-path. We could directly dispatch to it,
2021 // but this case should be rare, so for simplicity just put the
2022 // full slow-path down and branch unconditionally.
2023 slow_path = new (allocator) IntrinsicSlowPathMIPS(invoke);
2024 codegen->AddSlowPath(slow_path);
2025 __ B(slow_path->GetEntryLabel());
2026 __ Bind(slow_path->GetExitLabel());
2027 return;
2028 }
Vladimir Markofb6c90a2016-05-06 15:52:12 +01002029 } else if (code_point->GetType() != Primitive::kPrimChar) {
Chris Larsencf283da2016-01-19 16:45:35 -08002030 Register char_reg = locations->InAt(1).AsRegister<Register>();
2031 // The "bltu" conditional branch tests to see if the character value
2032 // fits in a valid 16-bit (MIPS halfword) value. If it doesn't then
2033 // the character being searched for, if it exists in the string, is
2034 // encoded using UTF-16 and stored in the string as two (16-bit)
2035 // halfwords. Currently the assembly code used to implement this
2036 // intrinsic doesn't support searching for a character stored as
2037 // two halfwords so we fallback to using the generic implementation
2038 // of indexOf().
2039 __ LoadConst32(tmp_reg, std::numeric_limits<uint16_t>::max());
2040 slow_path = new (allocator) IntrinsicSlowPathMIPS(invoke);
2041 codegen->AddSlowPath(slow_path);
2042 __ Bltu(tmp_reg, char_reg, slow_path->GetEntryLabel());
2043 }
2044
2045 if (start_at_zero) {
2046 DCHECK_EQ(tmp_reg, A2);
2047 // Start-index = 0.
2048 __ Clear(tmp_reg);
2049 }
2050
Serban Constantinescufca16662016-07-14 09:21:59 +01002051 codegen->InvokeRuntime(kQuickIndexOf, invoke, invoke->GetDexPc(), slow_path);
Chris Larsencf283da2016-01-19 16:45:35 -08002052 if (slow_path != nullptr) {
2053 __ Bind(slow_path->GetExitLabel());
2054 }
2055}
2056
2057// int java.lang.String.indexOf(int ch)
2058void IntrinsicLocationsBuilderMIPS::VisitStringIndexOf(HInvoke* invoke) {
2059 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00002060 LocationSummary::kCallOnMainAndSlowPath,
Chris Larsencf283da2016-01-19 16:45:35 -08002061 kIntrinsified);
2062 // We have a hand-crafted assembly stub that follows the runtime
2063 // calling convention. So it's best to align the inputs accordingly.
2064 InvokeRuntimeCallingConvention calling_convention;
2065 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2066 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2067 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
2068 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
2069
2070 // Need a temp for slow-path codepoint compare, and need to send start-index=0.
2071 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2072}
2073
2074void IntrinsicCodeGeneratorMIPS::VisitStringIndexOf(HInvoke* invoke) {
2075 GenerateStringIndexOf(invoke,
2076 /* start_at_zero */ true,
2077 GetAssembler(),
2078 codegen_,
2079 GetAllocator());
2080}
2081
2082// int java.lang.String.indexOf(int ch, int fromIndex)
2083void IntrinsicLocationsBuilderMIPS::VisitStringIndexOfAfter(HInvoke* invoke) {
2084 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00002085 LocationSummary::kCallOnMainAndSlowPath,
Chris Larsencf283da2016-01-19 16:45:35 -08002086 kIntrinsified);
2087 // We have a hand-crafted assembly stub that follows the runtime
2088 // calling convention. So it's best to align the inputs accordingly.
2089 InvokeRuntimeCallingConvention calling_convention;
2090 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2091 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2092 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2093 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
2094 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
2095
2096 // Need a temp for slow-path codepoint compare.
2097 locations->AddTemp(Location::RequiresRegister());
2098}
2099
2100void IntrinsicCodeGeneratorMIPS::VisitStringIndexOfAfter(HInvoke* invoke) {
2101 GenerateStringIndexOf(invoke,
2102 /* start_at_zero */ false,
2103 GetAssembler(),
2104 codegen_,
2105 GetAllocator());
2106}
2107
2108// java.lang.StringFactory.newStringFromBytes(byte[] data, int high, int offset, int byteCount)
2109void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromBytes(HInvoke* invoke) {
2110 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00002111 LocationSummary::kCallOnMainAndSlowPath,
Chris Larsencf283da2016-01-19 16:45:35 -08002112 kIntrinsified);
2113 InvokeRuntimeCallingConvention calling_convention;
2114 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2115 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2116 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2117 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
2118 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
2119 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
2120}
2121
2122void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromBytes(HInvoke* invoke) {
2123 MipsAssembler* assembler = GetAssembler();
2124 LocationSummary* locations = invoke->GetLocations();
2125
2126 Register byte_array = locations->InAt(0).AsRegister<Register>();
2127 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
2128 codegen_->AddSlowPath(slow_path);
2129 __ Beqz(byte_array, slow_path->GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +01002130 codegen_->InvokeRuntime(kQuickAllocStringFromBytes, invoke, invoke->GetDexPc(), slow_path);
Chris Larsencf283da2016-01-19 16:45:35 -08002131 __ Bind(slow_path->GetExitLabel());
2132}
2133
2134// java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
2135void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromChars(HInvoke* invoke) {
2136 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002137 LocationSummary::kCallOnMainOnly,
Chris Larsencf283da2016-01-19 16:45:35 -08002138 kIntrinsified);
2139 InvokeRuntimeCallingConvention calling_convention;
2140 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2141 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2142 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2143 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
2144 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
2145}
2146
2147void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromChars(HInvoke* invoke) {
Chris Larsencf283da2016-01-19 16:45:35 -08002148 // No need to emit code checking whether `locations->InAt(2)` is a null
2149 // pointer, as callers of the native method
2150 //
2151 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
2152 //
2153 // all include a null check on `data` before calling that method.
Serban Constantinescufca16662016-07-14 09:21:59 +01002154 codegen_->InvokeRuntime(kQuickAllocStringFromChars, invoke, invoke->GetDexPc());
Chris Larsencf283da2016-01-19 16:45:35 -08002155}
2156
2157// java.lang.StringFactory.newStringFromString(String toCopy)
2158void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromString(HInvoke* invoke) {
2159 LocationSummary* locations = new (arena_) LocationSummary(invoke,
Serban Constantinescu806f0122016-03-09 11:10:16 +00002160 LocationSummary::kCallOnMainAndSlowPath,
Chris Larsencf283da2016-01-19 16:45:35 -08002161 kIntrinsified);
2162 InvokeRuntimeCallingConvention calling_convention;
2163 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2164 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
2165 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
2166}
2167
2168void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromString(HInvoke* invoke) {
2169 MipsAssembler* assembler = GetAssembler();
2170 LocationSummary* locations = invoke->GetLocations();
2171
2172 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
2173 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
2174 codegen_->AddSlowPath(slow_path);
2175 __ Beqz(string_to_copy, slow_path->GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +01002176 codegen_->InvokeRuntime(kQuickAllocStringFromString, invoke, invoke->GetDexPc());
Chris Larsencf283da2016-01-19 16:45:35 -08002177 __ Bind(slow_path->GetExitLabel());
2178}
2179
Chris Larsen2714fe62016-02-11 14:23:53 -08002180static void GenIsInfinite(LocationSummary* locations,
2181 const Primitive::Type type,
2182 const bool isR6,
2183 MipsAssembler* assembler) {
2184 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
2185 Register out = locations->Out().AsRegister<Register>();
2186
2187 DCHECK(type == Primitive::kPrimFloat || type == Primitive::kPrimDouble);
2188
2189 if (isR6) {
2190 if (type == Primitive::kPrimDouble) {
2191 __ ClassD(FTMP, in);
2192 } else {
2193 __ ClassS(FTMP, in);
2194 }
2195 __ Mfc1(out, FTMP);
2196 __ Andi(out, out, kPositiveInfinity | kNegativeInfinity);
2197 __ Sltu(out, ZERO, out);
2198 } else {
2199 // If one, or more, of the exponent bits is zero, then the number can't be infinite.
2200 if (type == Primitive::kPrimDouble) {
2201 __ MoveFromFpuHigh(TMP, in);
Anton Kirilova3ffea22016-04-07 17:02:37 +01002202 __ LoadConst32(AT, High32Bits(kPositiveInfinityDouble));
Chris Larsen2714fe62016-02-11 14:23:53 -08002203 } else {
2204 __ Mfc1(TMP, in);
Anton Kirilova3ffea22016-04-07 17:02:37 +01002205 __ LoadConst32(AT, kPositiveInfinityFloat);
Chris Larsen2714fe62016-02-11 14:23:53 -08002206 }
2207 __ Xor(TMP, TMP, AT);
2208
2209 __ Sll(TMP, TMP, 1);
2210
2211 if (type == Primitive::kPrimDouble) {
2212 __ Mfc1(AT, in);
2213 __ Or(TMP, TMP, AT);
2214 }
2215 // If any of the significand bits are one, then the number is not infinite.
2216 __ Sltiu(out, TMP, 1);
2217 }
2218}
2219
2220// boolean java.lang.Float.isInfinite(float)
2221void IntrinsicLocationsBuilderMIPS::VisitFloatIsInfinite(HInvoke* invoke) {
2222 CreateFPToIntLocations(arena_, invoke);
2223}
2224
2225void IntrinsicCodeGeneratorMIPS::VisitFloatIsInfinite(HInvoke* invoke) {
2226 GenIsInfinite(invoke->GetLocations(), Primitive::kPrimFloat, IsR6(), GetAssembler());
2227}
2228
2229// boolean java.lang.Double.isInfinite(double)
2230void IntrinsicLocationsBuilderMIPS::VisitDoubleIsInfinite(HInvoke* invoke) {
2231 CreateFPToIntLocations(arena_, invoke);
2232}
2233
2234void IntrinsicCodeGeneratorMIPS::VisitDoubleIsInfinite(HInvoke* invoke) {
2235 GenIsInfinite(invoke->GetLocations(), Primitive::kPrimDouble, IsR6(), GetAssembler());
2236}
2237
Chris Larsen97759342016-02-16 17:10:40 -08002238static void GenHighestOneBit(LocationSummary* locations,
2239 const Primitive::Type type,
2240 bool isR6,
2241 MipsAssembler* assembler) {
2242 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
2243
2244 if (type == Primitive::kPrimLong) {
2245 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2246 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2247 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
2248 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
2249
2250 if (isR6) {
2251 __ ClzR6(TMP, in_hi);
2252 } else {
2253 __ ClzR2(TMP, in_hi);
2254 }
2255 __ LoadConst32(AT, 0x80000000);
2256 __ Srlv(out_hi, AT, TMP);
2257 __ And(out_hi, out_hi, in_hi);
2258 if (isR6) {
2259 __ ClzR6(TMP, in_lo);
2260 } else {
2261 __ ClzR2(TMP, in_lo);
2262 }
2263 __ Srlv(out_lo, AT, TMP);
2264 __ And(out_lo, out_lo, in_lo);
2265 if (isR6) {
2266 __ Seleqz(out_lo, out_lo, out_hi);
2267 } else {
2268 __ Movn(out_lo, ZERO, out_hi);
2269 }
2270 } else {
2271 Register in = locations->InAt(0).AsRegister<Register>();
2272 Register out = locations->Out().AsRegister<Register>();
2273
2274 if (isR6) {
2275 __ ClzR6(TMP, in);
2276 } else {
2277 __ ClzR2(TMP, in);
2278 }
2279 __ LoadConst32(AT, 0x80000000);
2280 __ Srlv(AT, AT, TMP); // Srlv shifts in the range of [0;31] bits (lower 5 bits of arg).
2281 __ And(out, AT, in); // So this is required for 0 (=shift by 32).
2282 }
2283}
2284
2285// int java.lang.Integer.highestOneBit(int)
2286void IntrinsicLocationsBuilderMIPS::VisitIntegerHighestOneBit(HInvoke* invoke) {
2287 CreateIntToIntLocations(arena_, invoke);
2288}
2289
2290void IntrinsicCodeGeneratorMIPS::VisitIntegerHighestOneBit(HInvoke* invoke) {
2291 GenHighestOneBit(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
2292}
2293
2294// long java.lang.Long.highestOneBit(long)
2295void IntrinsicLocationsBuilderMIPS::VisitLongHighestOneBit(HInvoke* invoke) {
2296 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
2297}
2298
2299void IntrinsicCodeGeneratorMIPS::VisitLongHighestOneBit(HInvoke* invoke) {
2300 GenHighestOneBit(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
2301}
2302
2303static void GenLowestOneBit(LocationSummary* locations,
2304 const Primitive::Type type,
2305 bool isR6,
2306 MipsAssembler* assembler) {
2307 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
2308
2309 if (type == Primitive::kPrimLong) {
2310 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
2311 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
2312 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
2313 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
2314
2315 __ Subu(TMP, ZERO, in_lo);
2316 __ And(out_lo, TMP, in_lo);
2317 __ Subu(TMP, ZERO, in_hi);
2318 __ And(out_hi, TMP, in_hi);
2319 if (isR6) {
2320 __ Seleqz(out_hi, out_hi, out_lo);
2321 } else {
2322 __ Movn(out_hi, ZERO, out_lo);
2323 }
2324 } else {
2325 Register in = locations->InAt(0).AsRegister<Register>();
2326 Register out = locations->Out().AsRegister<Register>();
2327
2328 __ Subu(TMP, ZERO, in);
2329 __ And(out, TMP, in);
2330 }
2331}
2332
2333// int java.lang.Integer.lowestOneBit(int)
2334void IntrinsicLocationsBuilderMIPS::VisitIntegerLowestOneBit(HInvoke* invoke) {
2335 CreateIntToIntLocations(arena_, invoke);
2336}
2337
2338void IntrinsicCodeGeneratorMIPS::VisitIntegerLowestOneBit(HInvoke* invoke) {
2339 GenLowestOneBit(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
2340}
2341
2342// long java.lang.Long.lowestOneBit(long)
2343void IntrinsicLocationsBuilderMIPS::VisitLongLowestOneBit(HInvoke* invoke) {
2344 CreateIntToIntLocations(arena_, invoke);
2345}
2346
2347void IntrinsicCodeGeneratorMIPS::VisitLongLowestOneBit(HInvoke* invoke) {
2348 GenLowestOneBit(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
2349}
2350
Chris Larsenf09d5322016-04-22 12:06:34 -07002351// int java.lang.Math.round(float)
2352void IntrinsicLocationsBuilderMIPS::VisitMathRoundFloat(HInvoke* invoke) {
2353 LocationSummary* locations = new (arena_) LocationSummary(invoke,
2354 LocationSummary::kNoCall,
2355 kIntrinsified);
2356 locations->SetInAt(0, Location::RequiresFpuRegister());
2357 locations->AddTemp(Location::RequiresFpuRegister());
2358 locations->SetOut(Location::RequiresRegister());
2359}
2360
2361void IntrinsicCodeGeneratorMIPS::VisitMathRoundFloat(HInvoke* invoke) {
2362 LocationSummary* locations = invoke->GetLocations();
2363 MipsAssembler* assembler = GetAssembler();
2364 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
2365 FRegister half = locations->GetTemp(0).AsFpuRegister<FRegister>();
2366 Register out = locations->Out().AsRegister<Register>();
2367
2368 MipsLabel done;
2369 MipsLabel finite;
2370 MipsLabel add;
2371
2372 // if (in.isNaN) {
2373 // return 0;
2374 // }
2375 //
2376 // out = floor.w.s(in);
2377 //
2378 // /*
2379 // * This "if" statement is only needed for the pre-R6 version of floor.w.s
2380 // * which outputs Integer.MAX_VALUE for negative numbers with magnitudes
2381 // * too large to fit in a 32-bit integer.
2382 // *
2383 // * Starting with MIPSR6, which always sets FCSR.NAN2008=1, negative
2384 // * numbers which are too large to be represented in a 32-bit signed
2385 // * integer will be processed by floor.w.s to output Integer.MIN_VALUE,
2386 // * and will no longer be processed by this "if" statement.
2387 // */
2388 // if (out == Integer.MAX_VALUE) {
2389 // TMP = (in < 0.0f) ? 1 : 0;
2390 // /*
2391 // * If TMP is 1, then adding it to out will wrap its value from
2392 // * Integer.MAX_VALUE to Integer.MIN_VALUE.
2393 // */
2394 // return out += TMP;
2395 // }
2396 //
2397 // /*
2398 // * For negative values not handled by the previous "if" statement the
2399 // * test here will correctly set the value of TMP.
2400 // */
2401 // TMP = ((in - out) >= 0.5f) ? 1 : 0;
2402 // return out += TMP;
2403
2404 // Test for NaN.
2405 if (IsR6()) {
2406 __ CmpUnS(FTMP, in, in);
2407 } else {
2408 __ CunS(in, in);
2409 }
2410
2411 // Return zero for NaN.
2412 __ Move(out, ZERO);
2413 if (IsR6()) {
2414 __ Bc1nez(FTMP, &done);
2415 } else {
2416 __ Bc1t(&done);
2417 }
2418
2419 // out = floor(in);
2420 __ FloorWS(FTMP, in);
2421 __ Mfc1(out, FTMP);
2422
Chris Larsen07f712f2016-06-10 16:06:02 -07002423 if (!IsR6()) {
2424 __ LoadConst32(TMP, -1);
2425 }
Chris Larsenf09d5322016-04-22 12:06:34 -07002426
Chris Larsen07f712f2016-06-10 16:06:02 -07002427 // TMP = (out = java.lang.Integer.MAX_VALUE) ? -1 : 0;
Chris Larsenf09d5322016-04-22 12:06:34 -07002428 __ LoadConst32(AT, std::numeric_limits<int32_t>::max());
2429 __ Bne(AT, out, &finite);
2430
2431 __ Mtc1(ZERO, FTMP);
2432 if (IsR6()) {
2433 __ CmpLtS(FTMP, in, FTMP);
Chris Larsen07f712f2016-06-10 16:06:02 -07002434 __ Mfc1(TMP, FTMP);
Chris Larsenf09d5322016-04-22 12:06:34 -07002435 } else {
2436 __ ColtS(in, FTMP);
2437 }
2438
2439 __ B(&add);
2440
2441 __ Bind(&finite);
2442
Chris Larsen07f712f2016-06-10 16:06:02 -07002443 // TMP = (0.5f <= (in - out)) ? -1 : 0;
Chris Larsenf09d5322016-04-22 12:06:34 -07002444 __ Cvtsw(FTMP, FTMP); // Convert output of floor.w.s back to "float".
2445 __ LoadConst32(AT, bit_cast<int32_t, float>(0.5f));
2446 __ SubS(FTMP, in, FTMP);
2447 __ Mtc1(AT, half);
2448 if (IsR6()) {
2449 __ CmpLeS(FTMP, half, FTMP);
Chris Larsen07f712f2016-06-10 16:06:02 -07002450 __ Mfc1(TMP, FTMP);
Chris Larsenf09d5322016-04-22 12:06:34 -07002451 } else {
2452 __ ColeS(half, FTMP);
2453 }
2454
2455 __ Bind(&add);
2456
Chris Larsen07f712f2016-06-10 16:06:02 -07002457 if (!IsR6()) {
Chris Larsenf09d5322016-04-22 12:06:34 -07002458 __ Movf(TMP, ZERO);
2459 }
2460
Chris Larsen07f712f2016-06-10 16:06:02 -07002461 // Return out -= TMP.
2462 __ Subu(out, out, TMP);
Chris Larsenf09d5322016-04-22 12:06:34 -07002463
2464 __ Bind(&done);
2465}
2466
Chris Larsen2714fe62016-02-11 14:23:53 -08002467// Unimplemented intrinsics.
2468
Aart Bik2f9fcc92016-03-01 15:16:54 -08002469UNIMPLEMENTED_INTRINSIC(MIPS, MathCeil)
2470UNIMPLEMENTED_INTRINSIC(MIPS, MathFloor)
2471UNIMPLEMENTED_INTRINSIC(MIPS, MathRint)
2472UNIMPLEMENTED_INTRINSIC(MIPS, MathRoundDouble)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002473UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeCASLong)
Chris Larsen701566a2015-10-27 15:29:13 -07002474
Aart Bik2f9fcc92016-03-01 15:16:54 -08002475UNIMPLEMENTED_INTRINSIC(MIPS, ReferenceGetReferent)
2476UNIMPLEMENTED_INTRINSIC(MIPS, StringGetCharsNoCheck)
2477UNIMPLEMENTED_INTRINSIC(MIPS, SystemArrayCopyChar)
2478UNIMPLEMENTED_INTRINSIC(MIPS, SystemArrayCopy)
Aart Bik3f67e692016-01-15 14:35:12 -08002479
Aart Bik2f9fcc92016-03-01 15:16:54 -08002480UNIMPLEMENTED_INTRINSIC(MIPS, MathCos)
2481UNIMPLEMENTED_INTRINSIC(MIPS, MathSin)
2482UNIMPLEMENTED_INTRINSIC(MIPS, MathAcos)
2483UNIMPLEMENTED_INTRINSIC(MIPS, MathAsin)
2484UNIMPLEMENTED_INTRINSIC(MIPS, MathAtan)
2485UNIMPLEMENTED_INTRINSIC(MIPS, MathAtan2)
2486UNIMPLEMENTED_INTRINSIC(MIPS, MathCbrt)
2487UNIMPLEMENTED_INTRINSIC(MIPS, MathCosh)
2488UNIMPLEMENTED_INTRINSIC(MIPS, MathExp)
2489UNIMPLEMENTED_INTRINSIC(MIPS, MathExpm1)
2490UNIMPLEMENTED_INTRINSIC(MIPS, MathHypot)
2491UNIMPLEMENTED_INTRINSIC(MIPS, MathLog)
2492UNIMPLEMENTED_INTRINSIC(MIPS, MathLog10)
2493UNIMPLEMENTED_INTRINSIC(MIPS, MathNextAfter)
2494UNIMPLEMENTED_INTRINSIC(MIPS, MathSinh)
2495UNIMPLEMENTED_INTRINSIC(MIPS, MathTan)
2496UNIMPLEMENTED_INTRINSIC(MIPS, MathTanh)
Chris Larsen701566a2015-10-27 15:29:13 -07002497
Aart Bikff7d89c2016-11-07 08:49:28 -08002498UNIMPLEMENTED_INTRINSIC(MIPS, StringStringIndexOf);
2499UNIMPLEMENTED_INTRINSIC(MIPS, StringStringIndexOfAfter);
2500
Aart Bik0e54c012016-03-04 12:08:31 -08002501// 1.8.
2502UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndAddInt)
2503UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndAddLong)
2504UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetInt)
2505UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetLong)
2506UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetObject)
Chris Larsen701566a2015-10-27 15:29:13 -07002507
Aart Bik0e54c012016-03-04 12:08:31 -08002508UNREACHABLE_INTRINSICS(MIPS)
Chris Larsen2714fe62016-02-11 14:23:53 -08002509
Chris Larsen701566a2015-10-27 15:29:13 -07002510#undef __
2511
2512} // namespace mips
2513} // namespace art