blob: c306cf93a1c9f97f94eb2270a9ca51f298e4c35a [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) {
617 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
618
619 Register out = locations->Out().AsRegister<Register>();
620
621 // https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
622 //
623 // A generalization of the best bit counting method to integers of
624 // bit-widths up to 128 (parameterized by type T) is this:
625 //
626 // v = v - ((v >> 1) & (T)~(T)0/3); // temp
627 // v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3); // temp
628 // v = (v + (v >> 4)) & (T)~(T)0/255*15; // temp
629 // c = (T)(v * ((T)~(T)0/255)) >> (sizeof(T) - 1) * BITS_PER_BYTE; // count
630 //
631 // For comparison, for 32-bit quantities, this algorithm can be executed
632 // using 20 MIPS instructions (the calls to LoadConst32() generate two
633 // machine instructions each for the values being used in this algorithm).
634 // A(n unrolled) loop-based algorithm required 25 instructions.
635 //
636 // For 64-bit quantities, this algorithm gets executed twice, (once
637 // for in_lo, and again for in_hi), but saves a few instructions
638 // because the mask values only have to be loaded once. Using this
639 // algorithm the count for a 64-bit operand can be performed in 33
640 // instructions compared to a loop-based algorithm which required 47
641 // instructions.
642
643 if (type == Primitive::kPrimInt) {
644 Register in = locations->InAt(0).AsRegister<Register>();
645
646 __ Srl(TMP, in, 1);
647 __ LoadConst32(AT, 0x55555555);
648 __ And(TMP, TMP, AT);
649 __ Subu(TMP, in, TMP);
650 __ LoadConst32(AT, 0x33333333);
651 __ And(out, TMP, AT);
652 __ Srl(TMP, TMP, 2);
653 __ And(TMP, TMP, AT);
654 __ Addu(TMP, out, TMP);
655 __ Srl(out, TMP, 4);
656 __ Addu(out, out, TMP);
657 __ LoadConst32(AT, 0x0F0F0F0F);
658 __ And(out, out, AT);
659 __ LoadConst32(TMP, 0x01010101);
660 if (isR6) {
661 __ MulR6(out, out, TMP);
662 } else {
663 __ MulR2(out, out, TMP);
664 }
665 __ Srl(out, out, 24);
666 } else if (type == Primitive::kPrimLong) {
667 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
668 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
669 Register tmp_hi = locations->GetTemp(0).AsRegister<Register>();
670 Register out_hi = locations->GetTemp(1).AsRegister<Register>();
671 Register tmp_lo = TMP;
672 Register out_lo = out;
673
674 __ Srl(tmp_lo, in_lo, 1);
675 __ Srl(tmp_hi, in_hi, 1);
676
677 __ LoadConst32(AT, 0x55555555);
678
679 __ And(tmp_lo, tmp_lo, AT);
680 __ Subu(tmp_lo, in_lo, tmp_lo);
681
682 __ And(tmp_hi, tmp_hi, AT);
683 __ Subu(tmp_hi, in_hi, tmp_hi);
684
685 __ LoadConst32(AT, 0x33333333);
686
687 __ And(out_lo, tmp_lo, AT);
688 __ Srl(tmp_lo, tmp_lo, 2);
689 __ And(tmp_lo, tmp_lo, AT);
690 __ Addu(tmp_lo, out_lo, tmp_lo);
691 __ Srl(out_lo, tmp_lo, 4);
692 __ Addu(out_lo, out_lo, tmp_lo);
693
694 __ And(out_hi, tmp_hi, AT);
695 __ Srl(tmp_hi, tmp_hi, 2);
696 __ And(tmp_hi, tmp_hi, AT);
697 __ Addu(tmp_hi, out_hi, tmp_hi);
698 __ Srl(out_hi, tmp_hi, 4);
699 __ Addu(out_hi, out_hi, tmp_hi);
700
701 __ LoadConst32(AT, 0x0F0F0F0F);
702
703 __ And(out_lo, out_lo, AT);
704 __ And(out_hi, out_hi, AT);
705
706 __ LoadConst32(AT, 0x01010101);
707
708 if (isR6) {
709 __ MulR6(out_lo, out_lo, AT);
710
711 __ MulR6(out_hi, out_hi, AT);
712 } else {
713 __ MulR2(out_lo, out_lo, AT);
714
715 __ MulR2(out_hi, out_hi, AT);
716 }
717
718 __ Srl(out_lo, out_lo, 24);
719 __ Srl(out_hi, out_hi, 24);
720
721 __ Addu(out, out_hi, out_lo);
722 }
723}
724
725// int java.lang.Integer.bitCount(int)
726void IntrinsicLocationsBuilderMIPS::VisitIntegerBitCount(HInvoke* invoke) {
727 CreateIntToIntLocations(arena_, invoke);
728}
729
730void IntrinsicCodeGeneratorMIPS::VisitIntegerBitCount(HInvoke* invoke) {
731 GenBitCount(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
732}
733
734// int java.lang.Long.bitCount(int)
735void IntrinsicLocationsBuilderMIPS::VisitLongBitCount(HInvoke* invoke) {
736 LocationSummary* locations = new (arena_) LocationSummary(invoke,
737 LocationSummary::kNoCall,
738 kIntrinsified);
739 locations->SetInAt(0, Location::RequiresRegister());
740 locations->SetOut(Location::RequiresRegister());
741 locations->AddTemp(Location::RequiresRegister());
742 locations->AddTemp(Location::RequiresRegister());
743}
744
745void IntrinsicCodeGeneratorMIPS::VisitLongBitCount(HInvoke* invoke) {
746 GenBitCount(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
747}
748
Chris Larsenb74353a2015-11-20 09:07:09 -0800749static void MathAbsFP(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
750 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
751 FRegister out = locations->Out().AsFpuRegister<FRegister>();
752
753 if (is64bit) {
754 __ AbsD(out, in);
755 } else {
756 __ AbsS(out, in);
757 }
758}
759
760// double java.lang.Math.abs(double)
761void IntrinsicLocationsBuilderMIPS::VisitMathAbsDouble(HInvoke* invoke) {
762 CreateFPToFPLocations(arena_, invoke);
763}
764
765void IntrinsicCodeGeneratorMIPS::VisitMathAbsDouble(HInvoke* invoke) {
766 MathAbsFP(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
767}
768
769// float java.lang.Math.abs(float)
770void IntrinsicLocationsBuilderMIPS::VisitMathAbsFloat(HInvoke* invoke) {
771 CreateFPToFPLocations(arena_, invoke);
772}
773
774void IntrinsicCodeGeneratorMIPS::VisitMathAbsFloat(HInvoke* invoke) {
775 MathAbsFP(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
776}
777
778static void GenAbsInteger(LocationSummary* locations, bool is64bit, MipsAssembler* assembler) {
779 if (is64bit) {
780 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
781 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
782 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
783 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
784
785 // The comments in this section show the analogous operations which would
786 // be performed if we had 64-bit registers "in", and "out".
787 // __ Dsra32(AT, in, 31);
788 __ Sra(AT, in_hi, 31);
789 // __ Xor(out, in, AT);
790 __ Xor(TMP, in_lo, AT);
791 __ Xor(out_hi, in_hi, AT);
792 // __ Dsubu(out, out, AT);
793 __ Subu(out_lo, TMP, AT);
794 __ Sltu(TMP, out_lo, TMP);
795 __ Addu(out_hi, out_hi, TMP);
796 } else {
797 Register in = locations->InAt(0).AsRegister<Register>();
798 Register out = locations->Out().AsRegister<Register>();
799
800 __ Sra(AT, in, 31);
801 __ Xor(out, in, AT);
802 __ Subu(out, out, AT);
803 }
804}
805
806// int java.lang.Math.abs(int)
807void IntrinsicLocationsBuilderMIPS::VisitMathAbsInt(HInvoke* invoke) {
808 CreateIntToIntLocations(arena_, invoke);
809}
810
811void IntrinsicCodeGeneratorMIPS::VisitMathAbsInt(HInvoke* invoke) {
812 GenAbsInteger(invoke->GetLocations(), /* is64bit */ false, GetAssembler());
813}
814
815// long java.lang.Math.abs(long)
816void IntrinsicLocationsBuilderMIPS::VisitMathAbsLong(HInvoke* invoke) {
817 CreateIntToIntLocations(arena_, invoke);
818}
819
820void IntrinsicCodeGeneratorMIPS::VisitMathAbsLong(HInvoke* invoke) {
821 GenAbsInteger(invoke->GetLocations(), /* is64bit */ true, GetAssembler());
822}
823
824static void GenMinMaxFP(LocationSummary* locations,
825 bool is_min,
826 Primitive::Type type,
827 bool is_R6,
828 MipsAssembler* assembler) {
829 FRegister out = locations->Out().AsFpuRegister<FRegister>();
830 FRegister a = locations->InAt(0).AsFpuRegister<FRegister>();
831 FRegister b = locations->InAt(1).AsFpuRegister<FRegister>();
832
833 if (is_R6) {
834 MipsLabel noNaNs;
835 MipsLabel done;
836 FRegister ftmp = ((out != a) && (out != b)) ? out : FTMP;
837
838 // When Java computes min/max it prefers a NaN to a number; the
839 // behavior of MIPSR6 is to prefer numbers to NaNs, i.e., if one of
840 // the inputs is a NaN and the other is a valid number, the MIPS
841 // instruction will return the number; Java wants the NaN value
842 // returned. This is why there is extra logic preceding the use of
843 // the MIPS min.fmt/max.fmt instructions. If either a, or b holds a
844 // NaN, return the NaN, otherwise return the min/max.
845 if (type == Primitive::kPrimDouble) {
846 __ CmpUnD(FTMP, a, b);
847 __ Bc1eqz(FTMP, &noNaNs);
848
849 // One of the inputs is a NaN
850 __ CmpEqD(ftmp, a, a);
851 // If a == a then b is the NaN, otherwise a is the NaN.
852 __ SelD(ftmp, a, b);
853
854 if (ftmp != out) {
855 __ MovD(out, ftmp);
856 }
857
858 __ B(&done);
859
860 __ Bind(&noNaNs);
861
862 if (is_min) {
863 __ MinD(out, a, b);
864 } else {
865 __ MaxD(out, a, b);
866 }
867 } else {
868 DCHECK_EQ(type, Primitive::kPrimFloat);
869 __ CmpUnS(FTMP, a, b);
870 __ Bc1eqz(FTMP, &noNaNs);
871
872 // One of the inputs is a NaN
873 __ CmpEqS(ftmp, a, a);
874 // If a == a then b is the NaN, otherwise a is the NaN.
875 __ SelS(ftmp, a, b);
876
877 if (ftmp != out) {
878 __ MovS(out, ftmp);
879 }
880
881 __ B(&done);
882
883 __ Bind(&noNaNs);
884
885 if (is_min) {
886 __ MinS(out, a, b);
887 } else {
888 __ MaxS(out, a, b);
889 }
890 }
891
892 __ Bind(&done);
893 } else {
894 MipsLabel ordered;
895 MipsLabel compare;
896 MipsLabel select;
897 MipsLabel done;
898
899 if (type == Primitive::kPrimDouble) {
900 __ CunD(a, b);
901 } else {
902 DCHECK_EQ(type, Primitive::kPrimFloat);
903 __ CunS(a, b);
904 }
905 __ Bc1f(&ordered);
906
907 // a or b (or both) is a NaN. Return one, which is a NaN.
908 if (type == Primitive::kPrimDouble) {
909 __ CeqD(b, b);
910 } else {
911 __ CeqS(b, b);
912 }
913 __ B(&select);
914
915 __ Bind(&ordered);
916
917 // Neither is a NaN.
918 // a == b? (-0.0 compares equal with +0.0)
919 // If equal, handle zeroes, else compare further.
920 if (type == Primitive::kPrimDouble) {
921 __ CeqD(a, b);
922 } else {
923 __ CeqS(a, b);
924 }
925 __ Bc1f(&compare);
926
927 // a == b either bit for bit or one is -0.0 and the other is +0.0.
928 if (type == Primitive::kPrimDouble) {
929 __ MoveFromFpuHigh(TMP, a);
930 __ MoveFromFpuHigh(AT, b);
931 } else {
932 __ Mfc1(TMP, a);
933 __ Mfc1(AT, b);
934 }
935
936 if (is_min) {
937 // -0.0 prevails over +0.0.
938 __ Or(TMP, TMP, AT);
939 } else {
940 // +0.0 prevails over -0.0.
941 __ And(TMP, TMP, AT);
942 }
943
944 if (type == Primitive::kPrimDouble) {
945 __ Mfc1(AT, a);
946 __ Mtc1(AT, out);
947 __ MoveToFpuHigh(TMP, out);
948 } else {
949 __ Mtc1(TMP, out);
950 }
951 __ B(&done);
952
953 __ Bind(&compare);
954
955 if (type == Primitive::kPrimDouble) {
956 if (is_min) {
957 // return (a <= b) ? a : b;
958 __ ColeD(a, b);
959 } else {
960 // return (a >= b) ? a : b;
961 __ ColeD(b, a); // b <= a
962 }
963 } else {
964 if (is_min) {
965 // return (a <= b) ? a : b;
966 __ ColeS(a, b);
967 } else {
968 // return (a >= b) ? a : b;
969 __ ColeS(b, a); // b <= a
970 }
971 }
972
973 __ Bind(&select);
974
975 if (type == Primitive::kPrimDouble) {
976 __ MovtD(out, a);
977 __ MovfD(out, b);
978 } else {
979 __ MovtS(out, a);
980 __ MovfS(out, b);
981 }
982
983 __ Bind(&done);
984 }
985}
986
987static void CreateFPFPToFPLocations(ArenaAllocator* arena, HInvoke* invoke) {
988 LocationSummary* locations = new (arena) LocationSummary(invoke,
989 LocationSummary::kNoCall,
990 kIntrinsified);
991 locations->SetInAt(0, Location::RequiresFpuRegister());
992 locations->SetInAt(1, Location::RequiresFpuRegister());
993 locations->SetOut(Location::RequiresFpuRegister(), Location::kOutputOverlap);
994}
995
996// double java.lang.Math.min(double, double)
997void IntrinsicLocationsBuilderMIPS::VisitMathMinDoubleDouble(HInvoke* invoke) {
998 CreateFPFPToFPLocations(arena_, invoke);
999}
1000
1001void IntrinsicCodeGeneratorMIPS::VisitMathMinDoubleDouble(HInvoke* invoke) {
1002 GenMinMaxFP(invoke->GetLocations(),
1003 /* is_min */ true,
1004 Primitive::kPrimDouble,
1005 IsR6(),
1006 GetAssembler());
1007}
1008
1009// float java.lang.Math.min(float, float)
1010void IntrinsicLocationsBuilderMIPS::VisitMathMinFloatFloat(HInvoke* invoke) {
1011 CreateFPFPToFPLocations(arena_, invoke);
1012}
1013
1014void IntrinsicCodeGeneratorMIPS::VisitMathMinFloatFloat(HInvoke* invoke) {
1015 GenMinMaxFP(invoke->GetLocations(),
1016 /* is_min */ true,
1017 Primitive::kPrimFloat,
1018 IsR6(),
1019 GetAssembler());
1020}
1021
1022// double java.lang.Math.max(double, double)
1023void IntrinsicLocationsBuilderMIPS::VisitMathMaxDoubleDouble(HInvoke* invoke) {
1024 CreateFPFPToFPLocations(arena_, invoke);
1025}
1026
1027void IntrinsicCodeGeneratorMIPS::VisitMathMaxDoubleDouble(HInvoke* invoke) {
1028 GenMinMaxFP(invoke->GetLocations(),
1029 /* is_min */ false,
1030 Primitive::kPrimDouble,
1031 IsR6(),
1032 GetAssembler());
1033}
1034
1035// float java.lang.Math.max(float, float)
1036void IntrinsicLocationsBuilderMIPS::VisitMathMaxFloatFloat(HInvoke* invoke) {
1037 CreateFPFPToFPLocations(arena_, invoke);
1038}
1039
1040void IntrinsicCodeGeneratorMIPS::VisitMathMaxFloatFloat(HInvoke* invoke) {
1041 GenMinMaxFP(invoke->GetLocations(),
1042 /* is_min */ false,
1043 Primitive::kPrimFloat,
1044 IsR6(),
1045 GetAssembler());
1046}
1047
1048static void CreateIntIntToIntLocations(ArenaAllocator* arena, HInvoke* invoke) {
1049 LocationSummary* locations = new (arena) LocationSummary(invoke,
1050 LocationSummary::kNoCall,
1051 kIntrinsified);
1052 locations->SetInAt(0, Location::RequiresRegister());
1053 locations->SetInAt(1, Location::RequiresRegister());
1054 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1055}
1056
1057static void GenMinMax(LocationSummary* locations,
1058 bool is_min,
1059 Primitive::Type type,
1060 bool is_R6,
1061 MipsAssembler* assembler) {
1062 if (is_R6) {
1063 // Some architectures, such as ARM and MIPS (prior to r6), have a
1064 // conditional move instruction which only changes the target
1065 // (output) register if the condition is true (MIPS prior to r6 had
1066 // MOVF, MOVT, MOVN, and MOVZ). The SELEQZ and SELNEZ instructions
1067 // always change the target (output) register. If the condition is
1068 // true the output register gets the contents of the "rs" register;
1069 // otherwise, the output register is set to zero. One consequence
1070 // of this is that to implement something like "rd = c==0 ? rs : rt"
1071 // MIPS64r6 needs to use a pair of SELEQZ/SELNEZ instructions.
1072 // After executing this pair of instructions one of the output
1073 // registers from the pair will necessarily contain zero. Then the
1074 // code ORs the output registers from the SELEQZ/SELNEZ instructions
1075 // to get the final result.
1076 //
1077 // The initial test to see if the output register is same as the
1078 // first input register is needed to make sure that value in the
1079 // first input register isn't clobbered before we've finished
1080 // computing the output value. The logic in the corresponding else
1081 // clause performs the same task but makes sure the second input
1082 // register isn't clobbered in the event that it's the same register
1083 // as the output register; the else clause also handles the case
1084 // where the output register is distinct from both the first, and the
1085 // second input registers.
1086 if (type == Primitive::kPrimLong) {
1087 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1088 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1089 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
1090 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
1091 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
1092 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
1093
1094 MipsLabel compare_done;
1095
1096 if (a_lo == b_lo) {
1097 if (out_lo != a_lo) {
1098 __ Move(out_lo, a_lo);
1099 __ Move(out_hi, a_hi);
1100 }
1101 } else {
1102 __ Slt(TMP, b_hi, a_hi);
1103 __ Bne(b_hi, a_hi, &compare_done);
1104
1105 __ Sltu(TMP, b_lo, a_lo);
1106
1107 __ Bind(&compare_done);
1108
1109 if (is_min) {
1110 __ Seleqz(AT, a_lo, TMP);
1111 __ Selnez(out_lo, b_lo, TMP); // Safe even if out_lo == a_lo/b_lo
1112 // because at this point we're
1113 // done using a_lo/b_lo.
1114 } else {
1115 __ Selnez(AT, a_lo, TMP);
1116 __ Seleqz(out_lo, b_lo, TMP); // ditto
1117 }
1118 __ Or(out_lo, out_lo, AT);
1119 if (is_min) {
1120 __ Seleqz(AT, a_hi, TMP);
1121 __ Selnez(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
1122 } else {
1123 __ Selnez(AT, a_hi, TMP);
1124 __ Seleqz(out_hi, b_hi, TMP); // ditto but for out_hi & a_hi/b_hi
1125 }
1126 __ Or(out_hi, out_hi, AT);
1127 }
1128 } else {
1129 DCHECK_EQ(type, Primitive::kPrimInt);
1130 Register a = locations->InAt(0).AsRegister<Register>();
1131 Register b = locations->InAt(1).AsRegister<Register>();
1132 Register out = locations->Out().AsRegister<Register>();
1133
1134 if (a == b) {
1135 if (out != a) {
1136 __ Move(out, a);
1137 }
1138 } else {
1139 __ Slt(AT, b, a);
1140 if (is_min) {
1141 __ Seleqz(TMP, a, AT);
1142 __ Selnez(AT, b, AT);
1143 } else {
1144 __ Selnez(TMP, a, AT);
1145 __ Seleqz(AT, b, AT);
1146 }
1147 __ Or(out, TMP, AT);
1148 }
1149 }
1150 } else {
1151 if (type == Primitive::kPrimLong) {
1152 Register a_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1153 Register a_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1154 Register b_lo = locations->InAt(1).AsRegisterPairLow<Register>();
1155 Register b_hi = locations->InAt(1).AsRegisterPairHigh<Register>();
1156 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
1157 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
1158
1159 MipsLabel compare_done;
1160
1161 if (a_lo == b_lo) {
1162 if (out_lo != a_lo) {
1163 __ Move(out_lo, a_lo);
1164 __ Move(out_hi, a_hi);
1165 }
1166 } else {
1167 __ Slt(TMP, a_hi, b_hi);
1168 __ Bne(a_hi, b_hi, &compare_done);
1169
1170 __ Sltu(TMP, a_lo, b_lo);
1171
1172 __ Bind(&compare_done);
1173
1174 if (is_min) {
1175 if (out_lo != a_lo) {
1176 __ Movn(out_hi, a_hi, TMP);
1177 __ Movn(out_lo, a_lo, TMP);
1178 }
1179 if (out_lo != b_lo) {
1180 __ Movz(out_hi, b_hi, TMP);
1181 __ Movz(out_lo, b_lo, TMP);
1182 }
1183 } else {
1184 if (out_lo != a_lo) {
1185 __ Movz(out_hi, a_hi, TMP);
1186 __ Movz(out_lo, a_lo, TMP);
1187 }
1188 if (out_lo != b_lo) {
1189 __ Movn(out_hi, b_hi, TMP);
1190 __ Movn(out_lo, b_lo, TMP);
1191 }
1192 }
1193 }
1194 } else {
1195 DCHECK_EQ(type, Primitive::kPrimInt);
1196 Register a = locations->InAt(0).AsRegister<Register>();
1197 Register b = locations->InAt(1).AsRegister<Register>();
1198 Register out = locations->Out().AsRegister<Register>();
1199
1200 if (a == b) {
1201 if (out != a) {
1202 __ Move(out, a);
1203 }
1204 } else {
1205 __ Slt(AT, a, b);
1206 if (is_min) {
1207 if (out != a) {
1208 __ Movn(out, a, AT);
1209 }
1210 if (out != b) {
1211 __ Movz(out, b, AT);
1212 }
1213 } else {
1214 if (out != a) {
1215 __ Movz(out, a, AT);
1216 }
1217 if (out != b) {
1218 __ Movn(out, b, AT);
1219 }
1220 }
1221 }
1222 }
1223 }
1224}
1225
1226// int java.lang.Math.min(int, int)
1227void IntrinsicLocationsBuilderMIPS::VisitMathMinIntInt(HInvoke* invoke) {
1228 CreateIntIntToIntLocations(arena_, invoke);
1229}
1230
1231void IntrinsicCodeGeneratorMIPS::VisitMathMinIntInt(HInvoke* invoke) {
1232 GenMinMax(invoke->GetLocations(),
1233 /* is_min */ true,
1234 Primitive::kPrimInt,
1235 IsR6(),
1236 GetAssembler());
1237}
1238
1239// long java.lang.Math.min(long, long)
1240void IntrinsicLocationsBuilderMIPS::VisitMathMinLongLong(HInvoke* invoke) {
1241 CreateIntIntToIntLocations(arena_, invoke);
1242}
1243
1244void IntrinsicCodeGeneratorMIPS::VisitMathMinLongLong(HInvoke* invoke) {
1245 GenMinMax(invoke->GetLocations(),
1246 /* is_min */ true,
1247 Primitive::kPrimLong,
1248 IsR6(),
1249 GetAssembler());
1250}
1251
1252// int java.lang.Math.max(int, int)
1253void IntrinsicLocationsBuilderMIPS::VisitMathMaxIntInt(HInvoke* invoke) {
1254 CreateIntIntToIntLocations(arena_, invoke);
1255}
1256
1257void IntrinsicCodeGeneratorMIPS::VisitMathMaxIntInt(HInvoke* invoke) {
1258 GenMinMax(invoke->GetLocations(),
1259 /* is_min */ false,
1260 Primitive::kPrimInt,
1261 IsR6(),
1262 GetAssembler());
1263}
1264
1265// long java.lang.Math.max(long, long)
1266void IntrinsicLocationsBuilderMIPS::VisitMathMaxLongLong(HInvoke* invoke) {
1267 CreateIntIntToIntLocations(arena_, invoke);
1268}
1269
1270void IntrinsicCodeGeneratorMIPS::VisitMathMaxLongLong(HInvoke* invoke) {
1271 GenMinMax(invoke->GetLocations(),
1272 /* is_min */ false,
1273 Primitive::kPrimLong,
1274 IsR6(),
1275 GetAssembler());
1276}
1277
1278// double java.lang.Math.sqrt(double)
1279void IntrinsicLocationsBuilderMIPS::VisitMathSqrt(HInvoke* invoke) {
1280 CreateFPToFPLocations(arena_, invoke);
1281}
1282
1283void IntrinsicCodeGeneratorMIPS::VisitMathSqrt(HInvoke* invoke) {
1284 LocationSummary* locations = invoke->GetLocations();
1285 MipsAssembler* assembler = GetAssembler();
1286 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
1287 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1288
1289 __ SqrtD(out, in);
1290}
1291
Chris Larsen3acee732015-11-18 13:31:08 -08001292// byte libcore.io.Memory.peekByte(long address)
1293void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekByte(HInvoke* invoke) {
1294 CreateIntToIntLocations(arena_, invoke);
1295}
1296
1297void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekByte(HInvoke* invoke) {
1298 MipsAssembler* assembler = GetAssembler();
1299 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1300 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1301
1302 __ Lb(out, adr, 0);
1303}
1304
1305// short libcore.io.Memory.peekShort(long address)
1306void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekShortNative(HInvoke* invoke) {
1307 CreateIntToIntLocations(arena_, invoke);
1308}
1309
1310void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekShortNative(HInvoke* invoke) {
1311 MipsAssembler* assembler = GetAssembler();
1312 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1313 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1314
1315 if (IsR6()) {
1316 __ Lh(out, adr, 0);
1317 } else if (IsR2OrNewer()) {
1318 // Unlike for words, there are no lhl/lhr instructions to load
1319 // unaligned halfwords so the code loads individual bytes, in case
1320 // the address isn't halfword-aligned, and assembles them into a
1321 // signed halfword.
1322 __ Lb(AT, adr, 1); // This byte must be sign-extended.
1323 __ Lb(out, adr, 0); // This byte can be either sign-extended, or
1324 // zero-extended because the following
1325 // instruction overwrites the sign bits.
1326 __ Ins(out, AT, 8, 24);
1327 } else {
1328 __ Lbu(AT, adr, 0); // This byte must be zero-extended. If it's not
1329 // the "or" instruction below will destroy the upper
1330 // 24 bits of the final result.
1331 __ Lb(out, adr, 1); // This byte must be sign-extended.
1332 __ Sll(out, out, 8);
1333 __ Or(out, out, AT);
1334 }
1335}
1336
1337// int libcore.io.Memory.peekInt(long address)
1338void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekIntNative(HInvoke* invoke) {
1339 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
1340}
1341
1342void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekIntNative(HInvoke* invoke) {
1343 MipsAssembler* assembler = GetAssembler();
1344 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1345 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1346
1347 if (IsR6()) {
1348 __ Lw(out, adr, 0);
1349 } else {
1350 __ Lwr(out, adr, 0);
1351 __ Lwl(out, adr, 3);
1352 }
1353}
1354
1355// long libcore.io.Memory.peekLong(long address)
1356void IntrinsicLocationsBuilderMIPS::VisitMemoryPeekLongNative(HInvoke* invoke) {
1357 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
1358}
1359
1360void IntrinsicCodeGeneratorMIPS::VisitMemoryPeekLongNative(HInvoke* invoke) {
1361 MipsAssembler* assembler = GetAssembler();
1362 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1363 Register out_lo = invoke->GetLocations()->Out().AsRegisterPairLow<Register>();
1364 Register out_hi = invoke->GetLocations()->Out().AsRegisterPairHigh<Register>();
1365
1366 if (IsR6()) {
1367 __ Lw(out_lo, adr, 0);
1368 __ Lw(out_hi, adr, 4);
1369 } else {
1370 __ Lwr(out_lo, adr, 0);
1371 __ Lwl(out_lo, adr, 3);
1372 __ Lwr(out_hi, adr, 4);
1373 __ Lwl(out_hi, adr, 7);
1374 }
1375}
1376
1377static void CreateIntIntToVoidLocations(ArenaAllocator* arena, HInvoke* invoke) {
1378 LocationSummary* locations = new (arena) LocationSummary(invoke,
1379 LocationSummary::kNoCall,
1380 kIntrinsified);
1381 locations->SetInAt(0, Location::RequiresRegister());
1382 locations->SetInAt(1, Location::RequiresRegister());
1383}
1384
1385// void libcore.io.Memory.pokeByte(long address, byte value)
1386void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeByte(HInvoke* invoke) {
1387 CreateIntIntToVoidLocations(arena_, invoke);
1388}
1389
1390void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeByte(HInvoke* invoke) {
1391 MipsAssembler* assembler = GetAssembler();
1392 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1393 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1394
1395 __ Sb(val, adr, 0);
1396}
1397
1398// void libcore.io.Memory.pokeShort(long address, short value)
1399void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeShortNative(HInvoke* invoke) {
1400 CreateIntIntToVoidLocations(arena_, invoke);
1401}
1402
1403void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeShortNative(HInvoke* invoke) {
1404 MipsAssembler* assembler = GetAssembler();
1405 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1406 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1407
1408 if (IsR6()) {
1409 __ Sh(val, adr, 0);
1410 } else {
1411 // Unlike for words, there are no shl/shr instructions to store
1412 // unaligned halfwords so the code stores individual bytes, in case
1413 // the address isn't halfword-aligned.
1414 __ Sb(val, adr, 0);
1415 __ Srl(AT, val, 8);
1416 __ Sb(AT, adr, 1);
1417 }
1418}
1419
1420// void libcore.io.Memory.pokeInt(long address, int value)
1421void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeIntNative(HInvoke* invoke) {
1422 CreateIntIntToVoidLocations(arena_, invoke);
1423}
1424
1425void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeIntNative(HInvoke* invoke) {
1426 MipsAssembler* assembler = GetAssembler();
1427 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1428 Register val = invoke->GetLocations()->InAt(1).AsRegister<Register>();
1429
1430 if (IsR6()) {
1431 __ Sw(val, adr, 0);
1432 } else {
1433 __ Swr(val, adr, 0);
1434 __ Swl(val, adr, 3);
1435 }
1436}
1437
1438// void libcore.io.Memory.pokeLong(long address, long value)
1439void IntrinsicLocationsBuilderMIPS::VisitMemoryPokeLongNative(HInvoke* invoke) {
1440 CreateIntIntToVoidLocations(arena_, invoke);
1441}
1442
1443void IntrinsicCodeGeneratorMIPS::VisitMemoryPokeLongNative(HInvoke* invoke) {
1444 MipsAssembler* assembler = GetAssembler();
1445 Register adr = invoke->GetLocations()->InAt(0).AsRegisterPairLow<Register>();
1446 Register val_lo = invoke->GetLocations()->InAt(1).AsRegisterPairLow<Register>();
1447 Register val_hi = invoke->GetLocations()->InAt(1).AsRegisterPairHigh<Register>();
1448
1449 if (IsR6()) {
1450 __ Sw(val_lo, adr, 0);
1451 __ Sw(val_hi, adr, 4);
1452 } else {
1453 __ Swr(val_lo, adr, 0);
1454 __ Swl(val_lo, adr, 3);
1455 __ Swr(val_hi, adr, 4);
1456 __ Swl(val_hi, adr, 7);
1457 }
1458}
1459
Chris Larsencf283da2016-01-19 16:45:35 -08001460// Thread java.lang.Thread.currentThread()
1461void IntrinsicLocationsBuilderMIPS::VisitThreadCurrentThread(HInvoke* invoke) {
1462 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1463 LocationSummary::kNoCall,
1464 kIntrinsified);
1465 locations->SetOut(Location::RequiresRegister());
1466}
1467
1468void IntrinsicCodeGeneratorMIPS::VisitThreadCurrentThread(HInvoke* invoke) {
1469 MipsAssembler* assembler = GetAssembler();
1470 Register out = invoke->GetLocations()->Out().AsRegister<Register>();
1471
1472 __ LoadFromOffset(kLoadWord,
1473 out,
1474 TR,
1475 Thread::PeerOffset<kMipsPointerSize>().Int32Value());
1476}
1477
Chris Larsen3acee732015-11-18 13:31:08 -08001478// char java.lang.String.charAt(int index)
1479void IntrinsicLocationsBuilderMIPS::VisitStringCharAt(HInvoke* invoke) {
1480 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1481 LocationSummary::kCallOnSlowPath,
1482 kIntrinsified);
1483 locations->SetInAt(0, Location::RequiresRegister());
1484 locations->SetInAt(1, Location::RequiresRegister());
Goran Jakovljevic31f477e2016-03-08 15:26:51 +01001485 // The inputs will be considered live at the last instruction and restored. This will overwrite
1486 // the output with kNoOutputOverlap.
1487 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
Chris Larsen3acee732015-11-18 13:31:08 -08001488}
1489
1490void IntrinsicCodeGeneratorMIPS::VisitStringCharAt(HInvoke* invoke) {
1491 LocationSummary* locations = invoke->GetLocations();
1492 MipsAssembler* assembler = GetAssembler();
1493
1494 // Location of reference to data array
1495 const int32_t value_offset = mirror::String::ValueOffset().Int32Value();
1496 // Location of count
1497 const int32_t count_offset = mirror::String::CountOffset().Int32Value();
1498
1499 Register obj = locations->InAt(0).AsRegister<Register>();
1500 Register idx = locations->InAt(1).AsRegister<Register>();
1501 Register out = locations->Out().AsRegister<Register>();
1502
1503 // TODO: Maybe we can support range check elimination. Overall,
1504 // though, I think it's not worth the cost.
1505 // TODO: For simplicity, the index parameter is requested in a
1506 // register, so different from Quick we will not optimize the
1507 // code for constants (which would save a register).
1508
1509 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
1510 codegen_->AddSlowPath(slow_path);
1511
1512 // Load the string size
1513 __ Lw(TMP, obj, count_offset);
1514 codegen_->MaybeRecordImplicitNullCheck(invoke);
1515 // Revert to slow path if idx is too large, or negative
1516 __ Bgeu(idx, TMP, slow_path->GetEntryLabel());
1517
1518 // out = obj[2*idx].
1519 __ Sll(TMP, idx, 1); // idx * 2
1520 __ Addu(TMP, TMP, obj); // Address of char at location idx
1521 __ Lhu(out, TMP, value_offset); // Load char at location idx
1522
1523 __ Bind(slow_path->GetExitLabel());
1524}
1525
Chris Larsencf283da2016-01-19 16:45:35 -08001526// int java.lang.String.compareTo(String anotherString)
1527void IntrinsicLocationsBuilderMIPS::VisitStringCompareTo(HInvoke* invoke) {
1528 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1529 LocationSummary::kCall,
1530 kIntrinsified);
1531 InvokeRuntimeCallingConvention calling_convention;
1532 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1533 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1534 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1535 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1536}
1537
1538void IntrinsicCodeGeneratorMIPS::VisitStringCompareTo(HInvoke* invoke) {
1539 MipsAssembler* assembler = GetAssembler();
1540 LocationSummary* locations = invoke->GetLocations();
1541
1542 // Note that the null check must have been done earlier.
1543 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1544
1545 Register argument = locations->InAt(1).AsRegister<Register>();
1546 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
1547 codegen_->AddSlowPath(slow_path);
1548 __ Beqz(argument, slow_path->GetEntryLabel());
1549
1550 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001551 T9,
Chris Larsencf283da2016-01-19 16:45:35 -08001552 TR,
1553 QUICK_ENTRYPOINT_OFFSET(kMipsWordSize,
1554 pStringCompareTo).Int32Value());
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001555 __ Jalr(T9);
Chris Larsencf283da2016-01-19 16:45:35 -08001556 __ Nop();
1557 __ Bind(slow_path->GetExitLabel());
1558}
1559
Chris Larsen16ba2b42015-11-02 10:58:31 -08001560// boolean java.lang.String.equals(Object anObject)
1561void IntrinsicLocationsBuilderMIPS::VisitStringEquals(HInvoke* invoke) {
1562 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1563 LocationSummary::kNoCall,
1564 kIntrinsified);
1565 locations->SetInAt(0, Location::RequiresRegister());
1566 locations->SetInAt(1, Location::RequiresRegister());
1567 locations->SetOut(Location::RequiresRegister());
1568
1569 // Temporary registers to store lengths of strings and for calculations.
1570 locations->AddTemp(Location::RequiresRegister());
1571 locations->AddTemp(Location::RequiresRegister());
1572 locations->AddTemp(Location::RequiresRegister());
1573}
1574
1575void IntrinsicCodeGeneratorMIPS::VisitStringEquals(HInvoke* invoke) {
1576 MipsAssembler* assembler = GetAssembler();
1577 LocationSummary* locations = invoke->GetLocations();
1578
1579 Register str = locations->InAt(0).AsRegister<Register>();
1580 Register arg = locations->InAt(1).AsRegister<Register>();
1581 Register out = locations->Out().AsRegister<Register>();
1582
1583 Register temp1 = locations->GetTemp(0).AsRegister<Register>();
1584 Register temp2 = locations->GetTemp(1).AsRegister<Register>();
1585 Register temp3 = locations->GetTemp(2).AsRegister<Register>();
1586
1587 MipsLabel loop;
1588 MipsLabel end;
1589 MipsLabel return_true;
1590 MipsLabel return_false;
1591
1592 // Get offsets of count, value, and class fields within a string object.
1593 const uint32_t count_offset = mirror::String::CountOffset().Uint32Value();
1594 const uint32_t value_offset = mirror::String::ValueOffset().Uint32Value();
1595 const uint32_t class_offset = mirror::Object::ClassOffset().Uint32Value();
1596
1597 // Note that the null check must have been done earlier.
1598 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1599
1600 // If the register containing the pointer to "this", and the register
1601 // containing the pointer to "anObject" are the same register then
1602 // "this", and "anObject" are the same object and we can
1603 // short-circuit the logic to a true result.
1604 if (str == arg) {
1605 __ LoadConst32(out, 1);
1606 return;
1607 }
1608
1609 // Check if input is null, return false if it is.
1610 __ Beqz(arg, &return_false);
1611
1612 // Reference equality check, return true if same reference.
1613 __ Beq(str, arg, &return_true);
1614
1615 // Instanceof check for the argument by comparing class fields.
1616 // All string objects must have the same type since String cannot be subclassed.
1617 // Receiver must be a string object, so its class field is equal to all strings' class fields.
1618 // If the argument is a string object, its class field must be equal to receiver's class field.
1619 __ Lw(temp1, str, class_offset);
1620 __ Lw(temp2, arg, class_offset);
1621 __ Bne(temp1, temp2, &return_false);
1622
1623 // Load lengths of this and argument strings.
1624 __ Lw(temp1, str, count_offset);
1625 __ Lw(temp2, arg, count_offset);
1626 // Check if lengths are equal, return false if they're not.
1627 __ Bne(temp1, temp2, &return_false);
1628 // Return true if both strings are empty.
1629 __ Beqz(temp1, &return_true);
1630
1631 // Don't overwrite input registers
1632 __ Move(TMP, str);
1633 __ Move(temp3, arg);
1634
1635 // Assertions that must hold in order to compare strings 2 characters at a time.
1636 DCHECK_ALIGNED(value_offset, 4);
1637 static_assert(IsAligned<4>(kObjectAlignment), "String of odd length is not zero padded");
1638
1639 // Loop to compare strings 2 characters at a time starting at the beginning of the string.
1640 // Ok to do this because strings are zero-padded.
1641 __ Bind(&loop);
1642 __ Lw(out, TMP, value_offset);
1643 __ Lw(temp2, temp3, value_offset);
1644 __ Bne(out, temp2, &return_false);
1645 __ Addiu(TMP, TMP, 4);
1646 __ Addiu(temp3, temp3, 4);
1647 __ Addiu(temp1, temp1, -2);
1648 __ Bgtz(temp1, &loop);
1649
1650 // Return true and exit the function.
1651 // If loop does not result in returning false, we return true.
1652 __ Bind(&return_true);
1653 __ LoadConst32(out, 1);
1654 __ B(&end);
1655
1656 // Return false and exit the function.
1657 __ Bind(&return_false);
1658 __ LoadConst32(out, 0);
1659 __ Bind(&end);
1660}
1661
Chris Larsencf283da2016-01-19 16:45:35 -08001662static void GenerateStringIndexOf(HInvoke* invoke,
1663 bool start_at_zero,
1664 MipsAssembler* assembler,
1665 CodeGeneratorMIPS* codegen,
1666 ArenaAllocator* allocator) {
1667 LocationSummary* locations = invoke->GetLocations();
1668 Register tmp_reg = start_at_zero ? locations->GetTemp(0).AsRegister<Register>() : TMP;
1669
1670 // Note that the null check must have been done earlier.
1671 DCHECK(!invoke->CanDoImplicitNullCheckOn(invoke->InputAt(0)));
1672
1673 // Check for code points > 0xFFFF. Either a slow-path check when we
1674 // don't know statically, or directly dispatch if we have a constant.
1675 SlowPathCodeMIPS* slow_path = nullptr;
1676 if (invoke->InputAt(1)->IsIntConstant()) {
1677 if (!IsUint<16>(invoke->InputAt(1)->AsIntConstant()->GetValue())) {
1678 // Always needs the slow-path. We could directly dispatch to it,
1679 // but this case should be rare, so for simplicity just put the
1680 // full slow-path down and branch unconditionally.
1681 slow_path = new (allocator) IntrinsicSlowPathMIPS(invoke);
1682 codegen->AddSlowPath(slow_path);
1683 __ B(slow_path->GetEntryLabel());
1684 __ Bind(slow_path->GetExitLabel());
1685 return;
1686 }
1687 } else {
1688 Register char_reg = locations->InAt(1).AsRegister<Register>();
1689 // The "bltu" conditional branch tests to see if the character value
1690 // fits in a valid 16-bit (MIPS halfword) value. If it doesn't then
1691 // the character being searched for, if it exists in the string, is
1692 // encoded using UTF-16 and stored in the string as two (16-bit)
1693 // halfwords. Currently the assembly code used to implement this
1694 // intrinsic doesn't support searching for a character stored as
1695 // two halfwords so we fallback to using the generic implementation
1696 // of indexOf().
1697 __ LoadConst32(tmp_reg, std::numeric_limits<uint16_t>::max());
1698 slow_path = new (allocator) IntrinsicSlowPathMIPS(invoke);
1699 codegen->AddSlowPath(slow_path);
1700 __ Bltu(tmp_reg, char_reg, slow_path->GetEntryLabel());
1701 }
1702
1703 if (start_at_zero) {
1704 DCHECK_EQ(tmp_reg, A2);
1705 // Start-index = 0.
1706 __ Clear(tmp_reg);
1707 }
1708
1709 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001710 T9,
Chris Larsencf283da2016-01-19 16:45:35 -08001711 TR,
1712 QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, pIndexOf).Int32Value());
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001713 __ Jalr(T9);
Chris Larsencf283da2016-01-19 16:45:35 -08001714 __ Nop();
1715
1716 if (slow_path != nullptr) {
1717 __ Bind(slow_path->GetExitLabel());
1718 }
1719}
1720
1721// int java.lang.String.indexOf(int ch)
1722void IntrinsicLocationsBuilderMIPS::VisitStringIndexOf(HInvoke* invoke) {
1723 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1724 LocationSummary::kCall,
1725 kIntrinsified);
1726 // We have a hand-crafted assembly stub that follows the runtime
1727 // calling convention. So it's best to align the inputs accordingly.
1728 InvokeRuntimeCallingConvention calling_convention;
1729 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1730 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1731 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1732 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1733
1734 // Need a temp for slow-path codepoint compare, and need to send start-index=0.
1735 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1736}
1737
1738void IntrinsicCodeGeneratorMIPS::VisitStringIndexOf(HInvoke* invoke) {
1739 GenerateStringIndexOf(invoke,
1740 /* start_at_zero */ true,
1741 GetAssembler(),
1742 codegen_,
1743 GetAllocator());
1744}
1745
1746// int java.lang.String.indexOf(int ch, int fromIndex)
1747void IntrinsicLocationsBuilderMIPS::VisitStringIndexOfAfter(HInvoke* invoke) {
1748 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1749 LocationSummary::kCall,
1750 kIntrinsified);
1751 // We have a hand-crafted assembly stub that follows the runtime
1752 // calling convention. So it's best to align the inputs accordingly.
1753 InvokeRuntimeCallingConvention calling_convention;
1754 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1755 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1756 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1757 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1758 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1759
1760 // Need a temp for slow-path codepoint compare.
1761 locations->AddTemp(Location::RequiresRegister());
1762}
1763
1764void IntrinsicCodeGeneratorMIPS::VisitStringIndexOfAfter(HInvoke* invoke) {
1765 GenerateStringIndexOf(invoke,
1766 /* start_at_zero */ false,
1767 GetAssembler(),
1768 codegen_,
1769 GetAllocator());
1770}
1771
1772// java.lang.StringFactory.newStringFromBytes(byte[] data, int high, int offset, int byteCount)
1773void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromBytes(HInvoke* invoke) {
1774 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1775 LocationSummary::kCall,
1776 kIntrinsified);
1777 InvokeRuntimeCallingConvention calling_convention;
1778 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1779 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1780 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1781 locations->SetInAt(3, Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
1782 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1783 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1784}
1785
1786void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromBytes(HInvoke* invoke) {
1787 MipsAssembler* assembler = GetAssembler();
1788 LocationSummary* locations = invoke->GetLocations();
1789
1790 Register byte_array = locations->InAt(0).AsRegister<Register>();
1791 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
1792 codegen_->AddSlowPath(slow_path);
1793 __ Beqz(byte_array, slow_path->GetEntryLabel());
1794
1795 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001796 T9,
Chris Larsencf283da2016-01-19 16:45:35 -08001797 TR,
1798 QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, pAllocStringFromBytes).Int32Value());
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001799 __ Jalr(T9);
Chris Larsencf283da2016-01-19 16:45:35 -08001800 __ Nop();
1801 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1802 __ Bind(slow_path->GetExitLabel());
1803}
1804
1805// java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1806void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromChars(HInvoke* invoke) {
1807 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1808 LocationSummary::kCall,
1809 kIntrinsified);
1810 InvokeRuntimeCallingConvention calling_convention;
1811 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1812 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1813 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1814 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1815 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1816}
1817
1818void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromChars(HInvoke* invoke) {
1819 MipsAssembler* assembler = GetAssembler();
1820
1821 // No need to emit code checking whether `locations->InAt(2)` is a null
1822 // pointer, as callers of the native method
1823 //
1824 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
1825 //
1826 // all include a null check on `data` before calling that method.
1827
1828 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001829 T9,
Chris Larsencf283da2016-01-19 16:45:35 -08001830 TR,
1831 QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, pAllocStringFromChars).Int32Value());
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001832 __ Jalr(T9);
Chris Larsencf283da2016-01-19 16:45:35 -08001833 __ Nop();
1834 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1835}
1836
1837// java.lang.StringFactory.newStringFromString(String toCopy)
1838void IntrinsicLocationsBuilderMIPS::VisitStringNewStringFromString(HInvoke* invoke) {
1839 LocationSummary* locations = new (arena_) LocationSummary(invoke,
1840 LocationSummary::kCall,
1841 kIntrinsified);
1842 InvokeRuntimeCallingConvention calling_convention;
1843 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1844 Location outLocation = calling_convention.GetReturnLocation(Primitive::kPrimInt);
1845 locations->SetOut(Location::RegisterLocation(outLocation.AsRegister<Register>()));
1846}
1847
1848void IntrinsicCodeGeneratorMIPS::VisitStringNewStringFromString(HInvoke* invoke) {
1849 MipsAssembler* assembler = GetAssembler();
1850 LocationSummary* locations = invoke->GetLocations();
1851
1852 Register string_to_copy = locations->InAt(0).AsRegister<Register>();
1853 SlowPathCodeMIPS* slow_path = new (GetAllocator()) IntrinsicSlowPathMIPS(invoke);
1854 codegen_->AddSlowPath(slow_path);
1855 __ Beqz(string_to_copy, slow_path->GetEntryLabel());
1856
1857 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001858 T9,
Chris Larsencf283da2016-01-19 16:45:35 -08001859 TR,
1860 QUICK_ENTRYPOINT_OFFSET(kMipsWordSize, pAllocStringFromString).Int32Value());
Goran Jakovljevicddc40552016-03-11 15:22:18 +01001861 __ Jalr(T9);
Chris Larsencf283da2016-01-19 16:45:35 -08001862 __ Nop();
1863 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1864 __ Bind(slow_path->GetExitLabel());
1865}
1866
Chris Larsen2714fe62016-02-11 14:23:53 -08001867static void GenIsInfinite(LocationSummary* locations,
1868 const Primitive::Type type,
1869 const bool isR6,
1870 MipsAssembler* assembler) {
1871 FRegister in = locations->InAt(0).AsFpuRegister<FRegister>();
1872 Register out = locations->Out().AsRegister<Register>();
1873
1874 DCHECK(type == Primitive::kPrimFloat || type == Primitive::kPrimDouble);
1875
1876 if (isR6) {
1877 if (type == Primitive::kPrimDouble) {
1878 __ ClassD(FTMP, in);
1879 } else {
1880 __ ClassS(FTMP, in);
1881 }
1882 __ Mfc1(out, FTMP);
1883 __ Andi(out, out, kPositiveInfinity | kNegativeInfinity);
1884 __ Sltu(out, ZERO, out);
1885 } else {
1886 // If one, or more, of the exponent bits is zero, then the number can't be infinite.
1887 if (type == Primitive::kPrimDouble) {
1888 __ MoveFromFpuHigh(TMP, in);
1889 __ LoadConst32(AT, 0x7FF00000);
1890 } else {
1891 __ Mfc1(TMP, in);
1892 __ LoadConst32(AT, 0x7F800000);
1893 }
1894 __ Xor(TMP, TMP, AT);
1895
1896 __ Sll(TMP, TMP, 1);
1897
1898 if (type == Primitive::kPrimDouble) {
1899 __ Mfc1(AT, in);
1900 __ Or(TMP, TMP, AT);
1901 }
1902 // If any of the significand bits are one, then the number is not infinite.
1903 __ Sltiu(out, TMP, 1);
1904 }
1905}
1906
1907// boolean java.lang.Float.isInfinite(float)
1908void IntrinsicLocationsBuilderMIPS::VisitFloatIsInfinite(HInvoke* invoke) {
1909 CreateFPToIntLocations(arena_, invoke);
1910}
1911
1912void IntrinsicCodeGeneratorMIPS::VisitFloatIsInfinite(HInvoke* invoke) {
1913 GenIsInfinite(invoke->GetLocations(), Primitive::kPrimFloat, IsR6(), GetAssembler());
1914}
1915
1916// boolean java.lang.Double.isInfinite(double)
1917void IntrinsicLocationsBuilderMIPS::VisitDoubleIsInfinite(HInvoke* invoke) {
1918 CreateFPToIntLocations(arena_, invoke);
1919}
1920
1921void IntrinsicCodeGeneratorMIPS::VisitDoubleIsInfinite(HInvoke* invoke) {
1922 GenIsInfinite(invoke->GetLocations(), Primitive::kPrimDouble, IsR6(), GetAssembler());
1923}
1924
Chris Larsen97759342016-02-16 17:10:40 -08001925static void GenHighestOneBit(LocationSummary* locations,
1926 const Primitive::Type type,
1927 bool isR6,
1928 MipsAssembler* assembler) {
1929 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
1930
1931 if (type == Primitive::kPrimLong) {
1932 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1933 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1934 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
1935 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
1936
1937 if (isR6) {
1938 __ ClzR6(TMP, in_hi);
1939 } else {
1940 __ ClzR2(TMP, in_hi);
1941 }
1942 __ LoadConst32(AT, 0x80000000);
1943 __ Srlv(out_hi, AT, TMP);
1944 __ And(out_hi, out_hi, in_hi);
1945 if (isR6) {
1946 __ ClzR6(TMP, in_lo);
1947 } else {
1948 __ ClzR2(TMP, in_lo);
1949 }
1950 __ Srlv(out_lo, AT, TMP);
1951 __ And(out_lo, out_lo, in_lo);
1952 if (isR6) {
1953 __ Seleqz(out_lo, out_lo, out_hi);
1954 } else {
1955 __ Movn(out_lo, ZERO, out_hi);
1956 }
1957 } else {
1958 Register in = locations->InAt(0).AsRegister<Register>();
1959 Register out = locations->Out().AsRegister<Register>();
1960
1961 if (isR6) {
1962 __ ClzR6(TMP, in);
1963 } else {
1964 __ ClzR2(TMP, in);
1965 }
1966 __ LoadConst32(AT, 0x80000000);
1967 __ Srlv(AT, AT, TMP); // Srlv shifts in the range of [0;31] bits (lower 5 bits of arg).
1968 __ And(out, AT, in); // So this is required for 0 (=shift by 32).
1969 }
1970}
1971
1972// int java.lang.Integer.highestOneBit(int)
1973void IntrinsicLocationsBuilderMIPS::VisitIntegerHighestOneBit(HInvoke* invoke) {
1974 CreateIntToIntLocations(arena_, invoke);
1975}
1976
1977void IntrinsicCodeGeneratorMIPS::VisitIntegerHighestOneBit(HInvoke* invoke) {
1978 GenHighestOneBit(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
1979}
1980
1981// long java.lang.Long.highestOneBit(long)
1982void IntrinsicLocationsBuilderMIPS::VisitLongHighestOneBit(HInvoke* invoke) {
1983 CreateIntToIntLocations(arena_, invoke, Location::kOutputOverlap);
1984}
1985
1986void IntrinsicCodeGeneratorMIPS::VisitLongHighestOneBit(HInvoke* invoke) {
1987 GenHighestOneBit(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
1988}
1989
1990static void GenLowestOneBit(LocationSummary* locations,
1991 const Primitive::Type type,
1992 bool isR6,
1993 MipsAssembler* assembler) {
1994 DCHECK(type == Primitive::kPrimInt || type == Primitive::kPrimLong);
1995
1996 if (type == Primitive::kPrimLong) {
1997 Register in_lo = locations->InAt(0).AsRegisterPairLow<Register>();
1998 Register in_hi = locations->InAt(0).AsRegisterPairHigh<Register>();
1999 Register out_lo = locations->Out().AsRegisterPairLow<Register>();
2000 Register out_hi = locations->Out().AsRegisterPairHigh<Register>();
2001
2002 __ Subu(TMP, ZERO, in_lo);
2003 __ And(out_lo, TMP, in_lo);
2004 __ Subu(TMP, ZERO, in_hi);
2005 __ And(out_hi, TMP, in_hi);
2006 if (isR6) {
2007 __ Seleqz(out_hi, out_hi, out_lo);
2008 } else {
2009 __ Movn(out_hi, ZERO, out_lo);
2010 }
2011 } else {
2012 Register in = locations->InAt(0).AsRegister<Register>();
2013 Register out = locations->Out().AsRegister<Register>();
2014
2015 __ Subu(TMP, ZERO, in);
2016 __ And(out, TMP, in);
2017 }
2018}
2019
2020// int java.lang.Integer.lowestOneBit(int)
2021void IntrinsicLocationsBuilderMIPS::VisitIntegerLowestOneBit(HInvoke* invoke) {
2022 CreateIntToIntLocations(arena_, invoke);
2023}
2024
2025void IntrinsicCodeGeneratorMIPS::VisitIntegerLowestOneBit(HInvoke* invoke) {
2026 GenLowestOneBit(invoke->GetLocations(), Primitive::kPrimInt, IsR6(), GetAssembler());
2027}
2028
2029// long java.lang.Long.lowestOneBit(long)
2030void IntrinsicLocationsBuilderMIPS::VisitLongLowestOneBit(HInvoke* invoke) {
2031 CreateIntToIntLocations(arena_, invoke);
2032}
2033
2034void IntrinsicCodeGeneratorMIPS::VisitLongLowestOneBit(HInvoke* invoke) {
2035 GenLowestOneBit(invoke->GetLocations(), Primitive::kPrimLong, IsR6(), GetAssembler());
2036}
2037
Chris Larsen2714fe62016-02-11 14:23:53 -08002038// Unimplemented intrinsics.
2039
Aart Bik2f9fcc92016-03-01 15:16:54 -08002040UNIMPLEMENTED_INTRINSIC(MIPS, MathCeil)
2041UNIMPLEMENTED_INTRINSIC(MIPS, MathFloor)
2042UNIMPLEMENTED_INTRINSIC(MIPS, MathRint)
2043UNIMPLEMENTED_INTRINSIC(MIPS, MathRoundDouble)
2044UNIMPLEMENTED_INTRINSIC(MIPS, MathRoundFloat)
Aart Bik2f9fcc92016-03-01 15:16:54 -08002045UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGet)
2046UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetVolatile)
2047UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetLong)
2048UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetLongVolatile)
2049UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetObject)
2050UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetObjectVolatile)
2051UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePut)
2052UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutOrdered)
2053UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutVolatile)
2054UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutObject)
2055UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutObjectOrdered)
2056UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutObjectVolatile)
2057UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutLong)
2058UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutLongOrdered)
2059UNIMPLEMENTED_INTRINSIC(MIPS, UnsafePutLongVolatile)
2060UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeCASInt)
2061UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeCASLong)
2062UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeCASObject)
Chris Larsen701566a2015-10-27 15:29:13 -07002063
Aart Bik2f9fcc92016-03-01 15:16:54 -08002064UNIMPLEMENTED_INTRINSIC(MIPS, ReferenceGetReferent)
2065UNIMPLEMENTED_INTRINSIC(MIPS, StringGetCharsNoCheck)
2066UNIMPLEMENTED_INTRINSIC(MIPS, SystemArrayCopyChar)
2067UNIMPLEMENTED_INTRINSIC(MIPS, SystemArrayCopy)
Aart Bik3f67e692016-01-15 14:35:12 -08002068
Aart Bik2f9fcc92016-03-01 15:16:54 -08002069UNIMPLEMENTED_INTRINSIC(MIPS, MathCos)
2070UNIMPLEMENTED_INTRINSIC(MIPS, MathSin)
2071UNIMPLEMENTED_INTRINSIC(MIPS, MathAcos)
2072UNIMPLEMENTED_INTRINSIC(MIPS, MathAsin)
2073UNIMPLEMENTED_INTRINSIC(MIPS, MathAtan)
2074UNIMPLEMENTED_INTRINSIC(MIPS, MathAtan2)
2075UNIMPLEMENTED_INTRINSIC(MIPS, MathCbrt)
2076UNIMPLEMENTED_INTRINSIC(MIPS, MathCosh)
2077UNIMPLEMENTED_INTRINSIC(MIPS, MathExp)
2078UNIMPLEMENTED_INTRINSIC(MIPS, MathExpm1)
2079UNIMPLEMENTED_INTRINSIC(MIPS, MathHypot)
2080UNIMPLEMENTED_INTRINSIC(MIPS, MathLog)
2081UNIMPLEMENTED_INTRINSIC(MIPS, MathLog10)
2082UNIMPLEMENTED_INTRINSIC(MIPS, MathNextAfter)
2083UNIMPLEMENTED_INTRINSIC(MIPS, MathSinh)
2084UNIMPLEMENTED_INTRINSIC(MIPS, MathTan)
2085UNIMPLEMENTED_INTRINSIC(MIPS, MathTanh)
Chris Larsen701566a2015-10-27 15:29:13 -07002086
Aart Bik0e54c012016-03-04 12:08:31 -08002087// 1.8.
2088UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndAddInt)
2089UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndAddLong)
2090UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetInt)
2091UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetLong)
2092UNIMPLEMENTED_INTRINSIC(MIPS, UnsafeGetAndSetObject)
Chris Larsen701566a2015-10-27 15:29:13 -07002093
Aart Bik0e54c012016-03-04 12:08:31 -08002094UNREACHABLE_INTRINSICS(MIPS)
Chris Larsen2714fe62016-02-11 14:23:53 -08002095
Chris Larsen701566a2015-10-27 15:29:13 -07002096#undef __
2097
2098} // namespace mips
2099} // namespace art