blob: bab702a949c1317cdc656b1899f4ce609b33a980 [file] [log] [blame]
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001/*
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 "code_generator_mips.h"
18
19#include "arch/mips/entrypoints_direct_mips.h"
20#include "arch/mips/instruction_set_features_mips.h"
21#include "art_method.h"
Chris Larsen701566a2015-10-27 15:29:13 -070022#include "code_generator_utils.h"
Vladimir Marko3a21e382016-09-02 12:38:38 +010023#include "compiled_method.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020024#include "entrypoints/quick/quick_entrypoints.h"
25#include "entrypoints/quick/quick_entrypoints_enum.h"
26#include "gc/accounting/card_table.h"
27#include "intrinsics.h"
Chris Larsen701566a2015-10-27 15:29:13 -070028#include "intrinsics_mips.h"
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020029#include "mirror/array-inl.h"
30#include "mirror/class-inl.h"
31#include "offsets.h"
32#include "thread.h"
33#include "utils/assembler.h"
34#include "utils/mips/assembler_mips.h"
35#include "utils/stack_checks.h"
36
37namespace art {
38namespace mips {
39
40static constexpr int kCurrentMethodStackOffset = 0;
41static constexpr Register kMethodRegisterArgument = A0;
42
Alexey Frunzee3fb2452016-05-10 16:08:05 -070043// We'll maximize the range of a single load instruction for dex cache array accesses
44// by aligning offset -32768 with the offset of the first used element.
45static constexpr uint32_t kDexCacheArrayLwOffset = 0x8000;
46
Goran Jakovljevicf652cec2015-08-25 16:11:42 +020047Location MipsReturnLocation(Primitive::Type return_type) {
48 switch (return_type) {
49 case Primitive::kPrimBoolean:
50 case Primitive::kPrimByte:
51 case Primitive::kPrimChar:
52 case Primitive::kPrimShort:
53 case Primitive::kPrimInt:
54 case Primitive::kPrimNot:
55 return Location::RegisterLocation(V0);
56
57 case Primitive::kPrimLong:
58 return Location::RegisterPairLocation(V0, V1);
59
60 case Primitive::kPrimFloat:
61 case Primitive::kPrimDouble:
62 return Location::FpuRegisterLocation(F0);
63
64 case Primitive::kPrimVoid:
65 return Location();
66 }
67 UNREACHABLE();
68}
69
70Location InvokeDexCallingConventionVisitorMIPS::GetReturnLocation(Primitive::Type type) const {
71 return MipsReturnLocation(type);
72}
73
74Location InvokeDexCallingConventionVisitorMIPS::GetMethodLocation() const {
75 return Location::RegisterLocation(kMethodRegisterArgument);
76}
77
78Location InvokeDexCallingConventionVisitorMIPS::GetNextLocation(Primitive::Type type) {
79 Location next_location;
80
81 switch (type) {
82 case Primitive::kPrimBoolean:
83 case Primitive::kPrimByte:
84 case Primitive::kPrimChar:
85 case Primitive::kPrimShort:
86 case Primitive::kPrimInt:
87 case Primitive::kPrimNot: {
88 uint32_t gp_index = gp_index_++;
89 if (gp_index < calling_convention.GetNumberOfRegisters()) {
90 next_location = Location::RegisterLocation(calling_convention.GetRegisterAt(gp_index));
91 } else {
92 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
93 next_location = Location::StackSlot(stack_offset);
94 }
95 break;
96 }
97
98 case Primitive::kPrimLong: {
99 uint32_t gp_index = gp_index_;
100 gp_index_ += 2;
101 if (gp_index + 1 < calling_convention.GetNumberOfRegisters()) {
102 if (calling_convention.GetRegisterAt(gp_index) == A1) {
103 gp_index_++; // Skip A1, and use A2_A3 instead.
104 gp_index++;
105 }
106 Register low_even = calling_convention.GetRegisterAt(gp_index);
107 Register high_odd = calling_convention.GetRegisterAt(gp_index + 1);
108 DCHECK_EQ(low_even + 1, high_odd);
109 next_location = Location::RegisterPairLocation(low_even, high_odd);
110 } else {
111 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
112 next_location = Location::DoubleStackSlot(stack_offset);
113 }
114 break;
115 }
116
117 // Note: both float and double types are stored in even FPU registers. On 32 bit FPU, double
118 // will take up the even/odd pair, while floats are stored in even regs only.
119 // On 64 bit FPU, both double and float are stored in even registers only.
120 case Primitive::kPrimFloat:
121 case Primitive::kPrimDouble: {
122 uint32_t float_index = float_index_++;
123 if (float_index < calling_convention.GetNumberOfFpuRegisters()) {
124 next_location = Location::FpuRegisterLocation(
125 calling_convention.GetFpuRegisterAt(float_index));
126 } else {
127 size_t stack_offset = calling_convention.GetStackOffsetOf(stack_index_);
128 next_location = Primitive::Is64BitType(type) ? Location::DoubleStackSlot(stack_offset)
129 : Location::StackSlot(stack_offset);
130 }
131 break;
132 }
133
134 case Primitive::kPrimVoid:
135 LOG(FATAL) << "Unexpected parameter type " << type;
136 break;
137 }
138
139 // Space on the stack is reserved for all arguments.
140 stack_index_ += Primitive::Is64BitType(type) ? 2 : 1;
141
142 return next_location;
143}
144
145Location InvokeRuntimeCallingConvention::GetReturnLocation(Primitive::Type type) {
146 return MipsReturnLocation(type);
147}
148
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100149// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
150#define __ down_cast<CodeGeneratorMIPS*>(codegen)->GetAssembler()-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700151#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200152
153class BoundsCheckSlowPathMIPS : public SlowPathCodeMIPS {
154 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000155 explicit BoundsCheckSlowPathMIPS(HBoundsCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200156
157 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
158 LocationSummary* locations = instruction_->GetLocations();
159 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
160 __ Bind(GetEntryLabel());
161 if (instruction_->CanThrowIntoCatchBlock()) {
162 // Live registers will be restored in the catch block if caught.
163 SaveLiveRegisters(codegen, instruction_->GetLocations());
164 }
165 // We're moving two locations to locations that could overlap, so we need a parallel
166 // move resolver.
167 InvokeRuntimeCallingConvention calling_convention;
168 codegen->EmitParallelMoves(locations->InAt(0),
169 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
170 Primitive::kPrimInt,
171 locations->InAt(1),
172 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
173 Primitive::kPrimInt);
Serban Constantinescufca16662016-07-14 09:21:59 +0100174 QuickEntrypointEnum entrypoint = instruction_->AsBoundsCheck()->IsStringCharAt()
175 ? kQuickThrowStringBounds
176 : kQuickThrowArrayBounds;
177 mips_codegen->InvokeRuntime(entrypoint, instruction_, instruction_->GetDexPc(), this);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100178 CheckEntrypointTypes<kQuickThrowStringBounds, void, int32_t, int32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200179 CheckEntrypointTypes<kQuickThrowArrayBounds, void, int32_t, int32_t>();
180 }
181
182 bool IsFatal() const OVERRIDE { return true; }
183
184 const char* GetDescription() const OVERRIDE { return "BoundsCheckSlowPathMIPS"; }
185
186 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200187 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathMIPS);
188};
189
190class DivZeroCheckSlowPathMIPS : public SlowPathCodeMIPS {
191 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000192 explicit DivZeroCheckSlowPathMIPS(HDivZeroCheck* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200193
194 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
195 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
196 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100197 mips_codegen->InvokeRuntime(kQuickThrowDivZero, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200198 CheckEntrypointTypes<kQuickThrowDivZero, void, void>();
199 }
200
201 bool IsFatal() const OVERRIDE { return true; }
202
203 const char* GetDescription() const OVERRIDE { return "DivZeroCheckSlowPathMIPS"; }
204
205 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200206 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathMIPS);
207};
208
209class LoadClassSlowPathMIPS : public SlowPathCodeMIPS {
210 public:
211 LoadClassSlowPathMIPS(HLoadClass* cls,
212 HInstruction* at,
213 uint32_t dex_pc,
214 bool do_clinit)
David Srbecky9cd6d372016-02-09 15:24:47 +0000215 : SlowPathCodeMIPS(at), cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200216 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
217 }
218
219 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
220 LocationSummary* locations = at_->GetLocations();
221 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
222
223 __ Bind(GetEntryLabel());
224 SaveLiveRegisters(codegen, locations);
225
226 InvokeRuntimeCallingConvention calling_convention;
227 __ LoadConst32(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
228
Serban Constantinescufca16662016-07-14 09:21:59 +0100229 QuickEntrypointEnum entrypoint = do_clinit_ ? kQuickInitializeStaticStorage
230 : kQuickInitializeType;
231 mips_codegen->InvokeRuntime(entrypoint, at_, dex_pc_, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200232 if (do_clinit_) {
233 CheckEntrypointTypes<kQuickInitializeStaticStorage, void*, uint32_t>();
234 } else {
235 CheckEntrypointTypes<kQuickInitializeType, void*, uint32_t>();
236 }
237
238 // Move the class to the desired location.
239 Location out = locations->Out();
240 if (out.IsValid()) {
241 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
242 Primitive::Type type = at_->GetType();
243 mips_codegen->MoveLocation(out, calling_convention.GetReturnLocation(type), type);
244 }
245
246 RestoreLiveRegisters(codegen, locations);
247 __ B(GetExitLabel());
248 }
249
250 const char* GetDescription() const OVERRIDE { return "LoadClassSlowPathMIPS"; }
251
252 private:
253 // The class this slow path will load.
254 HLoadClass* const cls_;
255
256 // The instruction where this slow path is happening.
257 // (Might be the load class or an initialization check).
258 HInstruction* const at_;
259
260 // The dex PC of `at_`.
261 const uint32_t dex_pc_;
262
263 // Whether to initialize the class.
264 const bool do_clinit_;
265
266 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathMIPS);
267};
268
269class LoadStringSlowPathMIPS : public SlowPathCodeMIPS {
270 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000271 explicit LoadStringSlowPathMIPS(HLoadString* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200272
273 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
274 LocationSummary* locations = instruction_->GetLocations();
275 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
276 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
277
278 __ Bind(GetEntryLabel());
279 SaveLiveRegisters(codegen, locations);
280
281 InvokeRuntimeCallingConvention calling_convention;
Vladimir Markoaad75c62016-10-03 08:46:48 +0000282 HLoadString* load = instruction_->AsLoadString();
283 const uint32_t string_index = load->GetStringIndex();
David Srbecky9cd6d372016-02-09 15:24:47 +0000284 __ LoadConst32(calling_convention.GetRegisterAt(0), string_index);
Serban Constantinescufca16662016-07-14 09:21:59 +0100285 mips_codegen->InvokeRuntime(kQuickResolveString, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200286 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
287 Primitive::Type type = instruction_->GetType();
288 mips_codegen->MoveLocation(locations->Out(),
289 calling_convention.GetReturnLocation(type),
290 type);
291
292 RestoreLiveRegisters(codegen, locations);
Vladimir Markoaad75c62016-10-03 08:46:48 +0000293
294 // Store the resolved String to the BSS entry.
295 // TODO: Change art_quick_resolve_string to kSaveEverything and use a temporary for the
296 // .bss entry address in the fast path, so that we can avoid another calculation here.
297 bool isR6 = mips_codegen->GetInstructionSetFeatures().IsR6();
298 Register base = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
299 Register out = locations->Out().AsRegister<Register>();
300 DCHECK_NE(out, AT);
301 CodeGeneratorMIPS::PcRelativePatchInfo* info =
302 mips_codegen->NewPcRelativeStringPatch(load->GetDexFile(), string_index);
303 mips_codegen->EmitPcRelativeAddressPlaceholder(info, TMP, base);
304 __ StoreToOffset(kStoreWord, out, TMP, 0);
305
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200306 __ B(GetExitLabel());
307 }
308
309 const char* GetDescription() const OVERRIDE { return "LoadStringSlowPathMIPS"; }
310
311 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200312 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathMIPS);
313};
314
315class NullCheckSlowPathMIPS : public SlowPathCodeMIPS {
316 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000317 explicit NullCheckSlowPathMIPS(HNullCheck* instr) : SlowPathCodeMIPS(instr) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200318
319 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
320 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
321 __ Bind(GetEntryLabel());
322 if (instruction_->CanThrowIntoCatchBlock()) {
323 // Live registers will be restored in the catch block if caught.
324 SaveLiveRegisters(codegen, instruction_->GetLocations());
325 }
Serban Constantinescufca16662016-07-14 09:21:59 +0100326 mips_codegen->InvokeRuntime(kQuickThrowNullPointer,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200327 instruction_,
328 instruction_->GetDexPc(),
Serban Constantinescufca16662016-07-14 09:21:59 +0100329 this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200330 CheckEntrypointTypes<kQuickThrowNullPointer, void, void>();
331 }
332
333 bool IsFatal() const OVERRIDE { return true; }
334
335 const char* GetDescription() const OVERRIDE { return "NullCheckSlowPathMIPS"; }
336
337 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200338 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathMIPS);
339};
340
341class SuspendCheckSlowPathMIPS : public SlowPathCodeMIPS {
342 public:
343 SuspendCheckSlowPathMIPS(HSuspendCheck* instruction, HBasicBlock* successor)
David Srbecky9cd6d372016-02-09 15:24:47 +0000344 : SlowPathCodeMIPS(instruction), successor_(successor) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200345
346 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
347 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
348 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100349 mips_codegen->InvokeRuntime(kQuickTestSuspend, instruction_, instruction_->GetDexPc(), this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200350 CheckEntrypointTypes<kQuickTestSuspend, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200351 if (successor_ == nullptr) {
352 __ B(GetReturnLabel());
353 } else {
354 __ B(mips_codegen->GetLabelOf(successor_));
355 }
356 }
357
358 MipsLabel* GetReturnLabel() {
359 DCHECK(successor_ == nullptr);
360 return &return_label_;
361 }
362
363 const char* GetDescription() const OVERRIDE { return "SuspendCheckSlowPathMIPS"; }
364
365 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200366 // If not null, the block to branch to after the suspend check.
367 HBasicBlock* const successor_;
368
369 // If `successor_` is null, the label to branch to after the suspend check.
370 MipsLabel return_label_;
371
372 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathMIPS);
373};
374
375class TypeCheckSlowPathMIPS : public SlowPathCodeMIPS {
376 public:
David Srbecky9cd6d372016-02-09 15:24:47 +0000377 explicit TypeCheckSlowPathMIPS(HInstruction* instruction) : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200378
379 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
380 LocationSummary* locations = instruction_->GetLocations();
381 Location object_class = instruction_->IsCheckCast() ? locations->GetTemp(0) : locations->Out();
382 uint32_t dex_pc = instruction_->GetDexPc();
383 DCHECK(instruction_->IsCheckCast()
384 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
385 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
386
387 __ Bind(GetEntryLabel());
388 SaveLiveRegisters(codegen, locations);
389
390 // We're moving two locations to locations that could overlap, so we need a parallel
391 // move resolver.
392 InvokeRuntimeCallingConvention calling_convention;
393 codegen->EmitParallelMoves(locations->InAt(1),
394 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
395 Primitive::kPrimNot,
396 object_class,
397 Location::RegisterLocation(calling_convention.GetRegisterAt(1)),
398 Primitive::kPrimNot);
399
400 if (instruction_->IsInstanceOf()) {
Serban Constantinescufca16662016-07-14 09:21:59 +0100401 mips_codegen->InvokeRuntime(kQuickInstanceofNonTrivial, instruction_, dex_pc, this);
Roland Levillain888d0672015-11-23 18:53:50 +0000402 CheckEntrypointTypes<
Andreas Gampe67409972016-07-19 22:34:53 -0700403 kQuickInstanceofNonTrivial, size_t, const mirror::Class*, const mirror::Class*>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200404 Primitive::Type ret_type = instruction_->GetType();
405 Location ret_loc = calling_convention.GetReturnLocation(ret_type);
406 mips_codegen->MoveLocation(locations->Out(), ret_loc, ret_type);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200407 } else {
408 DCHECK(instruction_->IsCheckCast());
Serban Constantinescufca16662016-07-14 09:21:59 +0100409 mips_codegen->InvokeRuntime(kQuickCheckCast, instruction_, dex_pc, this);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200410 CheckEntrypointTypes<kQuickCheckCast, void, const mirror::Class*, const mirror::Class*>();
411 }
412
413 RestoreLiveRegisters(codegen, locations);
414 __ B(GetExitLabel());
415 }
416
417 const char* GetDescription() const OVERRIDE { return "TypeCheckSlowPathMIPS"; }
418
419 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200420 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathMIPS);
421};
422
423class DeoptimizationSlowPathMIPS : public SlowPathCodeMIPS {
424 public:
Aart Bik42249c32016-01-07 15:33:50 -0800425 explicit DeoptimizationSlowPathMIPS(HDeoptimize* instruction)
David Srbecky9cd6d372016-02-09 15:24:47 +0000426 : SlowPathCodeMIPS(instruction) {}
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200427
428 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Aart Bik42249c32016-01-07 15:33:50 -0800429 CodeGeneratorMIPS* mips_codegen = down_cast<CodeGeneratorMIPS*>(codegen);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200430 __ Bind(GetEntryLabel());
Serban Constantinescufca16662016-07-14 09:21:59 +0100431 mips_codegen->InvokeRuntime(kQuickDeoptimize, instruction_, instruction_->GetDexPc(), this);
Roland Levillain888d0672015-11-23 18:53:50 +0000432 CheckEntrypointTypes<kQuickDeoptimize, void, void>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200433 }
434
435 const char* GetDescription() const OVERRIDE { return "DeoptimizationSlowPathMIPS"; }
436
437 private:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200438 DISALLOW_COPY_AND_ASSIGN(DeoptimizationSlowPathMIPS);
439};
440
441CodeGeneratorMIPS::CodeGeneratorMIPS(HGraph* graph,
442 const MipsInstructionSetFeatures& isa_features,
443 const CompilerOptions& compiler_options,
444 OptimizingCompilerStats* stats)
445 : CodeGenerator(graph,
446 kNumberOfCoreRegisters,
447 kNumberOfFRegisters,
448 kNumberOfRegisterPairs,
449 ComputeRegisterMask(reinterpret_cast<const int*>(kCoreCalleeSaves),
450 arraysize(kCoreCalleeSaves)),
451 ComputeRegisterMask(reinterpret_cast<const int*>(kFpuCalleeSaves),
452 arraysize(kFpuCalleeSaves)),
453 compiler_options,
454 stats),
455 block_labels_(nullptr),
456 location_builder_(graph, this),
457 instruction_visitor_(graph, this),
458 move_resolver_(graph->GetArena(), this),
Vladimir Marko93205e32016-04-13 11:59:46 +0100459 assembler_(graph->GetArena(), &isa_features),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700460 isa_features_(isa_features),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700461 uint32_literals_(std::less<uint32_t>(),
462 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700463 method_patches_(MethodReferenceComparator(),
464 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
465 call_patches_(MethodReferenceComparator(),
466 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
Alexey Frunze06a46c42016-07-19 15:00:40 -0700467 pc_relative_dex_cache_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
468 boot_image_string_patches_(StringReferenceValueComparator(),
469 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
470 pc_relative_string_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
471 boot_image_type_patches_(TypeReferenceValueComparator(),
472 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
473 pc_relative_type_patches_(graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
474 boot_image_address_patches_(std::less<uint32_t>(),
475 graph->GetArena()->Adapter(kArenaAllocCodeGenerator)),
476 clobbered_ra_(false) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200477 // Save RA (containing the return address) to mimic Quick.
478 AddAllocatedRegister(Location::RegisterLocation(RA));
479}
480
481#undef __
Roland Levillain7cbd27f2016-08-11 23:53:33 +0100482// NOLINT on __ macro to suppress wrong warning/fix (misc-macro-parentheses) from clang-tidy.
483#define __ down_cast<MipsAssembler*>(GetAssembler())-> // NOLINT
Andreas Gampe542451c2016-07-26 09:02:02 -0700484#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kMipsPointerSize, x).Int32Value()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200485
486void CodeGeneratorMIPS::Finalize(CodeAllocator* allocator) {
487 // Ensure that we fix up branches.
488 __ FinalizeCode();
489
490 // Adjust native pc offsets in stack maps.
491 for (size_t i = 0, num = stack_map_stream_.GetNumberOfStackMaps(); i != num; ++i) {
492 uint32_t old_position = stack_map_stream_.GetStackMap(i).native_pc_offset;
493 uint32_t new_position = __ GetAdjustedPosition(old_position);
494 DCHECK_GE(new_position, old_position);
495 stack_map_stream_.SetStackMapNativePcOffset(i, new_position);
496 }
497
498 // Adjust pc offsets for the disassembly information.
499 if (disasm_info_ != nullptr) {
500 GeneratedCodeInterval* frame_entry_interval = disasm_info_->GetFrameEntryInterval();
501 frame_entry_interval->start = __ GetAdjustedPosition(frame_entry_interval->start);
502 frame_entry_interval->end = __ GetAdjustedPosition(frame_entry_interval->end);
503 for (auto& it : *disasm_info_->GetInstructionIntervals()) {
504 it.second.start = __ GetAdjustedPosition(it.second.start);
505 it.second.end = __ GetAdjustedPosition(it.second.end);
506 }
507 for (auto& it : *disasm_info_->GetSlowPathIntervals()) {
508 it.code_interval.start = __ GetAdjustedPosition(it.code_interval.start);
509 it.code_interval.end = __ GetAdjustedPosition(it.code_interval.end);
510 }
511 }
512
513 CodeGenerator::Finalize(allocator);
514}
515
516MipsAssembler* ParallelMoveResolverMIPS::GetAssembler() const {
517 return codegen_->GetAssembler();
518}
519
520void ParallelMoveResolverMIPS::EmitMove(size_t index) {
521 DCHECK_LT(index, moves_.size());
522 MoveOperands* move = moves_[index];
523 codegen_->MoveLocation(move->GetDestination(), move->GetSource(), move->GetType());
524}
525
526void ParallelMoveResolverMIPS::EmitSwap(size_t index) {
527 DCHECK_LT(index, moves_.size());
528 MoveOperands* move = moves_[index];
529 Primitive::Type type = move->GetType();
530 Location loc1 = move->GetDestination();
531 Location loc2 = move->GetSource();
532
533 DCHECK(!loc1.IsConstant());
534 DCHECK(!loc2.IsConstant());
535
536 if (loc1.Equals(loc2)) {
537 return;
538 }
539
540 if (loc1.IsRegister() && loc2.IsRegister()) {
541 // Swap 2 GPRs.
542 Register r1 = loc1.AsRegister<Register>();
543 Register r2 = loc2.AsRegister<Register>();
544 __ Move(TMP, r2);
545 __ Move(r2, r1);
546 __ Move(r1, TMP);
547 } else if (loc1.IsFpuRegister() && loc2.IsFpuRegister()) {
548 FRegister f1 = loc1.AsFpuRegister<FRegister>();
549 FRegister f2 = loc2.AsFpuRegister<FRegister>();
550 if (type == Primitive::kPrimFloat) {
551 __ MovS(FTMP, f2);
552 __ MovS(f2, f1);
553 __ MovS(f1, FTMP);
554 } else {
555 DCHECK_EQ(type, Primitive::kPrimDouble);
556 __ MovD(FTMP, f2);
557 __ MovD(f2, f1);
558 __ MovD(f1, FTMP);
559 }
560 } else if ((loc1.IsRegister() && loc2.IsFpuRegister()) ||
561 (loc1.IsFpuRegister() && loc2.IsRegister())) {
562 // Swap FPR and GPR.
563 DCHECK_EQ(type, Primitive::kPrimFloat); // Can only swap a float.
564 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
565 : loc2.AsFpuRegister<FRegister>();
566 Register r2 = loc1.IsRegister() ? loc1.AsRegister<Register>()
567 : loc2.AsRegister<Register>();
568 __ Move(TMP, r2);
569 __ Mfc1(r2, f1);
570 __ Mtc1(TMP, f1);
571 } else if (loc1.IsRegisterPair() && loc2.IsRegisterPair()) {
572 // Swap 2 GPR register pairs.
573 Register r1 = loc1.AsRegisterPairLow<Register>();
574 Register r2 = loc2.AsRegisterPairLow<Register>();
575 __ Move(TMP, r2);
576 __ Move(r2, r1);
577 __ Move(r1, TMP);
578 r1 = loc1.AsRegisterPairHigh<Register>();
579 r2 = loc2.AsRegisterPairHigh<Register>();
580 __ Move(TMP, r2);
581 __ Move(r2, r1);
582 __ Move(r1, TMP);
583 } else if ((loc1.IsRegisterPair() && loc2.IsFpuRegister()) ||
584 (loc1.IsFpuRegister() && loc2.IsRegisterPair())) {
585 // Swap FPR and GPR register pair.
586 DCHECK_EQ(type, Primitive::kPrimDouble);
587 FRegister f1 = loc1.IsFpuRegister() ? loc1.AsFpuRegister<FRegister>()
588 : loc2.AsFpuRegister<FRegister>();
589 Register r2_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
590 : loc2.AsRegisterPairLow<Register>();
591 Register r2_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
592 : loc2.AsRegisterPairHigh<Register>();
593 // Use 2 temporary registers because we can't first swap the low 32 bits of an FPR and
594 // then swap the high 32 bits of the same FPR. mtc1 makes the high 32 bits of an FPR
595 // unpredictable and the following mfch1 will fail.
596 __ Mfc1(TMP, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800597 __ MoveFromFpuHigh(AT, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200598 __ Mtc1(r2_l, f1);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800599 __ MoveToFpuHigh(r2_h, f1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200600 __ Move(r2_l, TMP);
601 __ Move(r2_h, AT);
602 } else if (loc1.IsStackSlot() && loc2.IsStackSlot()) {
603 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ false);
604 } else if (loc1.IsDoubleStackSlot() && loc2.IsDoubleStackSlot()) {
605 Exchange(loc1.GetStackIndex(), loc2.GetStackIndex(), /* double_slot */ true);
David Brazdilcc0f3112016-01-28 17:14:52 +0000606 } else if ((loc1.IsRegister() && loc2.IsStackSlot()) ||
607 (loc1.IsStackSlot() && loc2.IsRegister())) {
608 Register reg = loc1.IsRegister() ? loc1.AsRegister<Register>()
609 : loc2.AsRegister<Register>();
610 intptr_t offset = loc1.IsStackSlot() ? loc1.GetStackIndex()
611 : loc2.GetStackIndex();
612 __ Move(TMP, reg);
613 __ LoadFromOffset(kLoadWord, reg, SP, offset);
614 __ StoreToOffset(kStoreWord, TMP, SP, offset);
615 } else if ((loc1.IsRegisterPair() && loc2.IsDoubleStackSlot()) ||
616 (loc1.IsDoubleStackSlot() && loc2.IsRegisterPair())) {
617 Register reg_l = loc1.IsRegisterPair() ? loc1.AsRegisterPairLow<Register>()
618 : loc2.AsRegisterPairLow<Register>();
619 Register reg_h = loc1.IsRegisterPair() ? loc1.AsRegisterPairHigh<Register>()
620 : loc2.AsRegisterPairHigh<Register>();
621 intptr_t offset_l = loc1.IsDoubleStackSlot() ? loc1.GetStackIndex()
622 : loc2.GetStackIndex();
623 intptr_t offset_h = loc1.IsDoubleStackSlot() ? loc1.GetHighStackIndex(kMipsWordSize)
624 : loc2.GetHighStackIndex(kMipsWordSize);
625 __ Move(TMP, reg_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000626 __ LoadFromOffset(kLoadWord, reg_l, SP, offset_l);
David Brazdilcc0f3112016-01-28 17:14:52 +0000627 __ StoreToOffset(kStoreWord, TMP, SP, offset_l);
David Brazdil04d3e872016-01-29 09:50:09 +0000628 __ Move(TMP, reg_h);
629 __ LoadFromOffset(kLoadWord, reg_h, SP, offset_h);
630 __ StoreToOffset(kStoreWord, TMP, SP, offset_h);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200631 } else {
632 LOG(FATAL) << "Swap between " << loc1 << " and " << loc2 << " is unsupported";
633 }
634}
635
636void ParallelMoveResolverMIPS::RestoreScratch(int reg) {
637 __ Pop(static_cast<Register>(reg));
638}
639
640void ParallelMoveResolverMIPS::SpillScratch(int reg) {
641 __ Push(static_cast<Register>(reg));
642}
643
644void ParallelMoveResolverMIPS::Exchange(int index1, int index2, bool double_slot) {
645 // Allocate a scratch register other than TMP, if available.
646 // Else, spill V0 (arbitrary choice) and use it as a scratch register (it will be
647 // automatically unspilled when the scratch scope object is destroyed).
648 ScratchRegisterScope ensure_scratch(this, TMP, V0, codegen_->GetNumberOfCoreRegisters());
649 // If V0 spills onto the stack, SP-relative offsets need to be adjusted.
650 int stack_offset = ensure_scratch.IsSpilled() ? kMipsWordSize : 0;
651 for (int i = 0; i <= (double_slot ? 1 : 0); i++, stack_offset += kMipsWordSize) {
652 __ LoadFromOffset(kLoadWord,
653 Register(ensure_scratch.GetRegister()),
654 SP,
655 index1 + stack_offset);
656 __ LoadFromOffset(kLoadWord,
657 TMP,
658 SP,
659 index2 + stack_offset);
660 __ StoreToOffset(kStoreWord,
661 Register(ensure_scratch.GetRegister()),
662 SP,
663 index2 + stack_offset);
664 __ StoreToOffset(kStoreWord, TMP, SP, index1 + stack_offset);
665 }
666}
667
Alexey Frunze73296a72016-06-03 22:51:46 -0700668void CodeGeneratorMIPS::ComputeSpillMask() {
669 core_spill_mask_ = allocated_registers_.GetCoreRegisters() & core_callee_save_mask_;
670 fpu_spill_mask_ = allocated_registers_.GetFloatingPointRegisters() & fpu_callee_save_mask_;
671 DCHECK_NE(core_spill_mask_, 0u) << "At least the return address register must be saved";
672 // If there're FPU callee-saved registers and there's an odd number of GPR callee-saved
673 // registers, include the ZERO register to force alignment of FPU callee-saved registers
674 // within the stack frame.
675 if ((fpu_spill_mask_ != 0) && (POPCOUNT(core_spill_mask_) % 2 != 0)) {
676 core_spill_mask_ |= (1 << ZERO);
677 }
Alexey Frunze58320ce2016-08-30 21:40:46 -0700678}
679
680bool CodeGeneratorMIPS::HasAllocatedCalleeSaveRegisters() const {
Alexey Frunze06a46c42016-07-19 15:00:40 -0700681 // If RA is clobbered by PC-relative operations on R2 and it's the only spilled register
Alexey Frunze58320ce2016-08-30 21:40:46 -0700682 // (this can happen in leaf methods), force CodeGenerator::InitializeCodeGeneration()
683 // into the path that creates a stack frame so that RA can be explicitly saved and restored.
684 // RA can't otherwise be saved/restored when it's the only spilled register.
Alexey Frunze06a46c42016-07-19 15:00:40 -0700685 // TODO: Can this be improved? It causes creation of a stack frame (while RA might be
686 // saved in an unused temporary register) and saving of RA and the current method pointer
687 // in the frame.
Alexey Frunze58320ce2016-08-30 21:40:46 -0700688 return CodeGenerator::HasAllocatedCalleeSaveRegisters() || clobbered_ra_;
Alexey Frunze73296a72016-06-03 22:51:46 -0700689}
690
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200691static dwarf::Reg DWARFReg(Register reg) {
692 return dwarf::Reg::MipsCore(static_cast<int>(reg));
693}
694
695// TODO: mapping of floating-point registers to DWARF.
696
697void CodeGeneratorMIPS::GenerateFrameEntry() {
698 __ Bind(&frame_entry_label_);
699
700 bool do_overflow_check = FrameNeedsStackCheck(GetFrameSize(), kMips) || !IsLeafMethod();
701
702 if (do_overflow_check) {
703 __ LoadFromOffset(kLoadWord,
704 ZERO,
705 SP,
706 -static_cast<int32_t>(GetStackOverflowReservedBytes(kMips)));
707 RecordPcInfo(nullptr, 0);
708 }
709
710 if (HasEmptyFrame()) {
Alexey Frunze58320ce2016-08-30 21:40:46 -0700711 CHECK_EQ(fpu_spill_mask_, 0u);
712 CHECK_EQ(core_spill_mask_, 1u << RA);
713 CHECK(!clobbered_ra_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200714 return;
715 }
716
717 // Make sure the frame size isn't unreasonably large.
718 if (GetFrameSize() > GetStackOverflowReservedBytes(kMips)) {
719 LOG(FATAL) << "Stack frame larger than " << GetStackOverflowReservedBytes(kMips) << " bytes";
720 }
721
722 // Spill callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200723
Alexey Frunze73296a72016-06-03 22:51:46 -0700724 uint32_t ofs = GetFrameSize();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200725 __ IncreaseFrameSize(ofs);
726
Alexey Frunze73296a72016-06-03 22:51:46 -0700727 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
728 Register reg = static_cast<Register>(MostSignificantBit(mask));
729 mask ^= 1u << reg;
730 ofs -= kMipsWordSize;
731 // The ZERO register is only included for alignment.
732 if (reg != ZERO) {
733 __ StoreToOffset(kStoreWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200734 __ cfi().RelOffset(DWARFReg(reg), ofs);
735 }
736 }
737
Alexey Frunze73296a72016-06-03 22:51:46 -0700738 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
739 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
740 mask ^= 1u << reg;
741 ofs -= kMipsDoublewordSize;
742 __ StoreDToOffset(reg, SP, ofs);
743 // TODO: __ cfi().RelOffset(DWARFReg(reg), ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200744 }
745
Nicolas Geoffray96eeb4e2016-10-12 22:03:31 +0100746 // Save the current method if we need it. Note that we do not
747 // do this in HCurrentMethod, as the instruction might have been removed
748 // in the SSA graph.
749 if (RequiresCurrentMethod()) {
750 __ StoreToOffset(kStoreWord, kMethodRegisterArgument, SP, kCurrentMethodStackOffset);
751 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200752}
753
754void CodeGeneratorMIPS::GenerateFrameExit() {
755 __ cfi().RememberState();
756
757 if (!HasEmptyFrame()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200758 // Restore callee-saved registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200759
Alexey Frunze73296a72016-06-03 22:51:46 -0700760 // For better instruction scheduling restore RA before other registers.
761 uint32_t ofs = GetFrameSize();
762 for (uint32_t mask = core_spill_mask_; mask != 0; ) {
763 Register reg = static_cast<Register>(MostSignificantBit(mask));
764 mask ^= 1u << reg;
765 ofs -= kMipsWordSize;
766 // The ZERO register is only included for alignment.
767 if (reg != ZERO) {
768 __ LoadFromOffset(kLoadWord, reg, SP, ofs);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200769 __ cfi().Restore(DWARFReg(reg));
770 }
771 }
772
Alexey Frunze73296a72016-06-03 22:51:46 -0700773 for (uint32_t mask = fpu_spill_mask_; mask != 0; ) {
774 FRegister reg = static_cast<FRegister>(MostSignificantBit(mask));
775 mask ^= 1u << reg;
776 ofs -= kMipsDoublewordSize;
777 __ LoadDFromOffset(reg, SP, ofs);
778 // TODO: __ cfi().Restore(DWARFReg(reg));
779 }
780
Alexey Frunze57eb0f52016-07-29 22:04:46 -0700781 size_t frame_size = GetFrameSize();
782 // Adjust the stack pointer in the delay slot if doing so doesn't break CFI.
783 bool exchange = IsInt<16>(static_cast<int32_t>(frame_size));
784 bool reordering = __ SetReorder(false);
785 if (exchange) {
786 __ Jr(RA);
787 __ DecreaseFrameSize(frame_size); // Single instruction in delay slot.
788 } else {
789 __ DecreaseFrameSize(frame_size);
790 __ Jr(RA);
791 __ Nop(); // In delay slot.
792 }
793 __ SetReorder(reordering);
794 } else {
795 __ Jr(RA);
796 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200797 }
798
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200799 __ cfi().RestoreState();
800 __ cfi().DefCFAOffset(GetFrameSize());
801}
802
803void CodeGeneratorMIPS::Bind(HBasicBlock* block) {
804 __ Bind(GetLabelOf(block));
805}
806
807void CodeGeneratorMIPS::MoveLocation(Location dst, Location src, Primitive::Type dst_type) {
808 if (src.Equals(dst)) {
809 return;
810 }
811
812 if (src.IsConstant()) {
813 MoveConstant(dst, src.GetConstant());
814 } else {
815 if (Primitive::Is64BitType(dst_type)) {
816 Move64(dst, src);
817 } else {
818 Move32(dst, src);
819 }
820 }
821}
822
823void CodeGeneratorMIPS::Move32(Location destination, Location source) {
824 if (source.Equals(destination)) {
825 return;
826 }
827
828 if (destination.IsRegister()) {
829 if (source.IsRegister()) {
830 __ Move(destination.AsRegister<Register>(), source.AsRegister<Register>());
831 } else if (source.IsFpuRegister()) {
832 __ Mfc1(destination.AsRegister<Register>(), source.AsFpuRegister<FRegister>());
833 } else {
834 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
835 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
836 }
837 } else if (destination.IsFpuRegister()) {
838 if (source.IsRegister()) {
839 __ Mtc1(source.AsRegister<Register>(), destination.AsFpuRegister<FRegister>());
840 } else if (source.IsFpuRegister()) {
841 __ MovS(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
842 } else {
843 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
844 __ LoadSFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
845 }
846 } else {
847 DCHECK(destination.IsStackSlot()) << destination;
848 if (source.IsRegister()) {
849 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
850 } else if (source.IsFpuRegister()) {
851 __ StoreSToOffset(source.AsFpuRegister<FRegister>(), SP, destination.GetStackIndex());
852 } else {
853 DCHECK(source.IsStackSlot()) << "Cannot move from " << source << " to " << destination;
854 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
855 __ StoreToOffset(kStoreWord, TMP, SP, destination.GetStackIndex());
856 }
857 }
858}
859
860void CodeGeneratorMIPS::Move64(Location destination, Location source) {
861 if (source.Equals(destination)) {
862 return;
863 }
864
865 if (destination.IsRegisterPair()) {
866 if (source.IsRegisterPair()) {
867 __ Move(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
868 __ Move(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
869 } else if (source.IsFpuRegister()) {
870 Register dst_high = destination.AsRegisterPairHigh<Register>();
871 Register dst_low = destination.AsRegisterPairLow<Register>();
872 FRegister src = source.AsFpuRegister<FRegister>();
873 __ Mfc1(dst_low, src);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800874 __ MoveFromFpuHigh(dst_high, src);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200875 } else {
876 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
877 int32_t off = source.GetStackIndex();
878 Register r = destination.AsRegisterPairLow<Register>();
879 __ LoadFromOffset(kLoadDoubleword, r, SP, off);
880 }
881 } else if (destination.IsFpuRegister()) {
882 if (source.IsRegisterPair()) {
883 FRegister dst = destination.AsFpuRegister<FRegister>();
884 Register src_high = source.AsRegisterPairHigh<Register>();
885 Register src_low = source.AsRegisterPairLow<Register>();
886 __ Mtc1(src_low, dst);
Alexey Frunzebb9863a2016-01-11 15:51:16 -0800887 __ MoveToFpuHigh(src_high, dst);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200888 } else if (source.IsFpuRegister()) {
889 __ MovD(destination.AsFpuRegister<FRegister>(), source.AsFpuRegister<FRegister>());
890 } else {
891 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
892 __ LoadDFromOffset(destination.AsFpuRegister<FRegister>(), SP, source.GetStackIndex());
893 }
894 } else {
895 DCHECK(destination.IsDoubleStackSlot()) << destination;
896 int32_t off = destination.GetStackIndex();
897 if (source.IsRegisterPair()) {
898 __ StoreToOffset(kStoreDoubleword, source.AsRegisterPairLow<Register>(), SP, off);
899 } else if (source.IsFpuRegister()) {
900 __ StoreDToOffset(source.AsFpuRegister<FRegister>(), SP, off);
901 } else {
902 DCHECK(source.IsDoubleStackSlot()) << "Cannot move from " << source << " to " << destination;
903 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex());
904 __ StoreToOffset(kStoreWord, TMP, SP, off);
905 __ LoadFromOffset(kLoadWord, TMP, SP, source.GetStackIndex() + 4);
906 __ StoreToOffset(kStoreWord, TMP, SP, off + 4);
907 }
908 }
909}
910
911void CodeGeneratorMIPS::MoveConstant(Location destination, HConstant* c) {
912 if (c->IsIntConstant() || c->IsNullConstant()) {
913 // Move 32 bit constant.
914 int32_t value = GetInt32ValueOf(c);
915 if (destination.IsRegister()) {
916 Register dst = destination.AsRegister<Register>();
917 __ LoadConst32(dst, value);
918 } else {
919 DCHECK(destination.IsStackSlot())
920 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700921 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200922 }
923 } else if (c->IsLongConstant()) {
924 // Move 64 bit constant.
925 int64_t value = GetInt64ValueOf(c);
926 if (destination.IsRegisterPair()) {
927 Register r_h = destination.AsRegisterPairHigh<Register>();
928 Register r_l = destination.AsRegisterPairLow<Register>();
929 __ LoadConst64(r_h, r_l, value);
930 } else {
931 DCHECK(destination.IsDoubleStackSlot())
932 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700933 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200934 }
935 } else if (c->IsFloatConstant()) {
936 // Move 32 bit float constant.
937 int32_t value = GetInt32ValueOf(c);
938 if (destination.IsFpuRegister()) {
939 __ LoadSConst32(destination.AsFpuRegister<FRegister>(), value, TMP);
940 } else {
941 DCHECK(destination.IsStackSlot())
942 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700943 __ StoreConstToOffset(kStoreWord, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200944 }
945 } else {
946 // Move 64 bit double constant.
947 DCHECK(c->IsDoubleConstant()) << c->DebugName();
948 int64_t value = GetInt64ValueOf(c);
949 if (destination.IsFpuRegister()) {
950 FRegister fd = destination.AsFpuRegister<FRegister>();
951 __ LoadDConst64(fd, value, TMP);
952 } else {
953 DCHECK(destination.IsDoubleStackSlot())
954 << "Cannot move " << c->DebugName() << " to " << destination;
Alexey Frunzef58b2482016-09-02 22:14:06 -0700955 __ StoreConstToOffset(kStoreDoubleword, value, SP, destination.GetStackIndex(), TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200956 }
957 }
958}
959
960void CodeGeneratorMIPS::MoveConstant(Location destination, int32_t value) {
961 DCHECK(destination.IsRegister());
962 Register dst = destination.AsRegister<Register>();
963 __ LoadConst32(dst, value);
964}
965
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200966void CodeGeneratorMIPS::AddLocationAsTemp(Location location, LocationSummary* locations) {
967 if (location.IsRegister()) {
968 locations->AddTemp(location);
Alexey Frunzec9e94f32015-10-26 16:11:39 -0700969 } else if (location.IsRegisterPair()) {
970 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairLow<Register>()));
971 locations->AddTemp(Location::RegisterLocation(location.AsRegisterPairHigh<Register>()));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +0200972 } else {
973 UNIMPLEMENTED(FATAL) << "AddLocationAsTemp not implemented for location " << location;
974 }
975}
976
Vladimir Markoaad75c62016-10-03 08:46:48 +0000977template <LinkerPatch (*Factory)(size_t, const DexFile*, uint32_t, uint32_t)>
978inline void CodeGeneratorMIPS::EmitPcRelativeLinkerPatches(
979 const ArenaDeque<PcRelativePatchInfo>& infos,
980 ArenaVector<LinkerPatch>* linker_patches) {
981 for (const PcRelativePatchInfo& info : infos) {
982 const DexFile& dex_file = info.target_dex_file;
983 size_t offset_or_index = info.offset_or_index;
984 DCHECK(info.high_label.IsBound());
985 uint32_t high_offset = __ GetLabelLocation(&info.high_label);
986 // On R2 we use HMipsComputeBaseMethodAddress and patch relative to
987 // the assembler's base label used for PC-relative addressing.
988 uint32_t pc_rel_offset = info.pc_rel_label.IsBound()
989 ? __ GetLabelLocation(&info.pc_rel_label)
990 : __ GetPcRelBaseLabelLocation();
991 linker_patches->push_back(Factory(high_offset, &dex_file, pc_rel_offset, offset_or_index));
992 }
993}
994
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700995void CodeGeneratorMIPS::EmitLinkerPatches(ArenaVector<LinkerPatch>* linker_patches) {
996 DCHECK(linker_patches->empty());
997 size_t size =
998 method_patches_.size() +
999 call_patches_.size() +
Alexey Frunze06a46c42016-07-19 15:00:40 -07001000 pc_relative_dex_cache_patches_.size() +
1001 pc_relative_string_patches_.size() +
1002 pc_relative_type_patches_.size() +
1003 boot_image_string_patches_.size() +
1004 boot_image_type_patches_.size() +
1005 boot_image_address_patches_.size();
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001006 linker_patches->reserve(size);
1007 for (const auto& entry : method_patches_) {
1008 const MethodReference& target_method = entry.first;
1009 Literal* literal = entry.second;
1010 DCHECK(literal->GetLabel()->IsBound());
1011 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1012 linker_patches->push_back(LinkerPatch::MethodPatch(literal_offset,
1013 target_method.dex_file,
1014 target_method.dex_method_index));
1015 }
1016 for (const auto& entry : call_patches_) {
1017 const MethodReference& target_method = entry.first;
1018 Literal* literal = entry.second;
1019 DCHECK(literal->GetLabel()->IsBound());
1020 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1021 linker_patches->push_back(LinkerPatch::CodePatch(literal_offset,
1022 target_method.dex_file,
1023 target_method.dex_method_index));
1024 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00001025 EmitPcRelativeLinkerPatches<LinkerPatch::DexCacheArrayPatch>(pc_relative_dex_cache_patches_,
1026 linker_patches);
1027 if (!GetCompilerOptions().IsBootImage()) {
1028 EmitPcRelativeLinkerPatches<LinkerPatch::StringBssEntryPatch>(pc_relative_string_patches_,
1029 linker_patches);
1030 } else {
1031 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeStringPatch>(pc_relative_string_patches_,
1032 linker_patches);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001033 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00001034 EmitPcRelativeLinkerPatches<LinkerPatch::RelativeTypePatch>(pc_relative_type_patches_,
1035 linker_patches);
Alexey Frunze06a46c42016-07-19 15:00:40 -07001036 for (const auto& entry : boot_image_string_patches_) {
1037 const StringReference& target_string = entry.first;
1038 Literal* literal = entry.second;
1039 DCHECK(literal->GetLabel()->IsBound());
1040 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1041 linker_patches->push_back(LinkerPatch::StringPatch(literal_offset,
1042 target_string.dex_file,
1043 target_string.string_index));
1044 }
1045 for (const auto& entry : boot_image_type_patches_) {
1046 const TypeReference& target_type = entry.first;
1047 Literal* literal = entry.second;
1048 DCHECK(literal->GetLabel()->IsBound());
1049 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1050 linker_patches->push_back(LinkerPatch::TypePatch(literal_offset,
1051 target_type.dex_file,
1052 target_type.type_index));
1053 }
1054 for (const auto& entry : boot_image_address_patches_) {
1055 DCHECK(GetCompilerOptions().GetIncludePatchInformation());
1056 Literal* literal = entry.second;
1057 DCHECK(literal->GetLabel()->IsBound());
1058 uint32_t literal_offset = __ GetLabelLocation(literal->GetLabel());
1059 linker_patches->push_back(LinkerPatch::RecordPosition(literal_offset));
1060 }
1061}
1062
1063CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeStringPatch(
1064 const DexFile& dex_file, uint32_t string_index) {
1065 return NewPcRelativePatch(dex_file, string_index, &pc_relative_string_patches_);
1066}
1067
1068CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeTypePatch(
1069 const DexFile& dex_file, uint32_t type_index) {
1070 return NewPcRelativePatch(dex_file, type_index, &pc_relative_type_patches_);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001071}
1072
1073CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativeDexCacheArrayPatch(
1074 const DexFile& dex_file, uint32_t element_offset) {
1075 return NewPcRelativePatch(dex_file, element_offset, &pc_relative_dex_cache_patches_);
1076}
1077
1078CodeGeneratorMIPS::PcRelativePatchInfo* CodeGeneratorMIPS::NewPcRelativePatch(
1079 const DexFile& dex_file, uint32_t offset_or_index, ArenaDeque<PcRelativePatchInfo>* patches) {
1080 patches->emplace_back(dex_file, offset_or_index);
1081 return &patches->back();
1082}
1083
Alexey Frunze06a46c42016-07-19 15:00:40 -07001084Literal* CodeGeneratorMIPS::DeduplicateUint32Literal(uint32_t value, Uint32ToLiteralMap* map) {
1085 return map->GetOrCreate(
1086 value,
1087 [this, value]() { return __ NewLiteral<uint32_t>(value); });
1088}
1089
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001090Literal* CodeGeneratorMIPS::DeduplicateMethodLiteral(MethodReference target_method,
1091 MethodToLiteralMap* map) {
1092 return map->GetOrCreate(
1093 target_method,
1094 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1095}
1096
1097Literal* CodeGeneratorMIPS::DeduplicateMethodAddressLiteral(MethodReference target_method) {
1098 return DeduplicateMethodLiteral(target_method, &method_patches_);
1099}
1100
1101Literal* CodeGeneratorMIPS::DeduplicateMethodCodeLiteral(MethodReference target_method) {
1102 return DeduplicateMethodLiteral(target_method, &call_patches_);
1103}
1104
Alexey Frunze06a46c42016-07-19 15:00:40 -07001105Literal* CodeGeneratorMIPS::DeduplicateBootImageStringLiteral(const DexFile& dex_file,
1106 uint32_t string_index) {
1107 return boot_image_string_patches_.GetOrCreate(
1108 StringReference(&dex_file, string_index),
1109 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1110}
1111
1112Literal* CodeGeneratorMIPS::DeduplicateBootImageTypeLiteral(const DexFile& dex_file,
1113 uint32_t type_index) {
1114 return boot_image_type_patches_.GetOrCreate(
1115 TypeReference(&dex_file, type_index),
1116 [this]() { return __ NewLiteral<uint32_t>(/* placeholder */ 0u); });
1117}
1118
1119Literal* CodeGeneratorMIPS::DeduplicateBootImageAddressLiteral(uint32_t address) {
1120 bool needs_patch = GetCompilerOptions().GetIncludePatchInformation();
1121 Uint32ToLiteralMap* map = needs_patch ? &boot_image_address_patches_ : &uint32_literals_;
1122 return DeduplicateUint32Literal(dchecked_integral_cast<uint32_t>(address), map);
1123}
1124
Vladimir Markoaad75c62016-10-03 08:46:48 +00001125void CodeGeneratorMIPS::EmitPcRelativeAddressPlaceholder(
1126 PcRelativePatchInfo* info, Register out, Register base) {
1127 bool reordering = __ SetReorder(false);
1128 if (GetInstructionSetFeatures().IsR6()) {
1129 DCHECK_EQ(base, ZERO);
1130 __ Bind(&info->high_label);
1131 __ Bind(&info->pc_rel_label);
1132 // Add a 32-bit offset to PC.
1133 __ Auipc(out, /* placeholder */ 0x1234);
1134 __ Addiu(out, out, /* placeholder */ 0x5678);
1135 } else {
1136 // If base is ZERO, emit NAL to obtain the actual base.
1137 if (base == ZERO) {
1138 // Generate a dummy PC-relative call to obtain PC.
1139 __ Nal();
1140 }
1141 __ Bind(&info->high_label);
1142 __ Lui(out, /* placeholder */ 0x1234);
1143 // If we emitted the NAL, bind the pc_rel_label, otherwise base is a register holding
1144 // the HMipsComputeBaseMethodAddress which has its own label stored in MipsAssembler.
1145 if (base == ZERO) {
1146 __ Bind(&info->pc_rel_label);
1147 }
1148 __ Ori(out, out, /* placeholder */ 0x5678);
1149 // Add a 32-bit offset to PC.
1150 __ Addu(out, out, (base == ZERO) ? RA : base);
1151 }
1152 __ SetReorder(reordering);
1153}
1154
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001155void CodeGeneratorMIPS::MarkGCCard(Register object, Register value) {
1156 MipsLabel done;
1157 Register card = AT;
1158 Register temp = TMP;
1159 __ Beqz(value, &done);
1160 __ LoadFromOffset(kLoadWord,
1161 card,
1162 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001163 Thread::CardTableOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001164 __ Srl(temp, object, gc::accounting::CardTable::kCardShift);
1165 __ Addu(temp, card, temp);
1166 __ Sb(card, temp, 0);
1167 __ Bind(&done);
1168}
1169
David Brazdil58282f42016-01-14 12:45:10 +00001170void CodeGeneratorMIPS::SetupBlockedRegisters() const {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001171 // ZERO, K0, K1, GP, SP, RA are always reserved and can't be allocated.
1172 blocked_core_registers_[ZERO] = true;
1173 blocked_core_registers_[K0] = true;
1174 blocked_core_registers_[K1] = true;
1175 blocked_core_registers_[GP] = true;
1176 blocked_core_registers_[SP] = true;
1177 blocked_core_registers_[RA] = true;
1178
1179 // AT and TMP(T8) are used as temporary/scratch registers
1180 // (similar to how AT is used by MIPS assemblers).
1181 blocked_core_registers_[AT] = true;
1182 blocked_core_registers_[TMP] = true;
1183 blocked_fpu_registers_[FTMP] = true;
1184
1185 // Reserve suspend and thread registers.
1186 blocked_core_registers_[S0] = true;
1187 blocked_core_registers_[TR] = true;
1188
1189 // Reserve T9 for function calls
1190 blocked_core_registers_[T9] = true;
1191
1192 // Reserve odd-numbered FPU registers.
1193 for (size_t i = 1; i < kNumberOfFRegisters; i += 2) {
1194 blocked_fpu_registers_[i] = true;
1195 }
1196
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02001197 if (GetGraph()->IsDebuggable()) {
1198 // Stubs do not save callee-save floating point registers. If the graph
1199 // is debuggable, we need to deal with these registers differently. For
1200 // now, just block them.
1201 for (size_t i = 0; i < arraysize(kFpuCalleeSaves); ++i) {
1202 blocked_fpu_registers_[kFpuCalleeSaves[i]] = true;
1203 }
1204 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001205}
1206
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001207size_t CodeGeneratorMIPS::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
1208 __ StoreToOffset(kStoreWord, Register(reg_id), SP, stack_index);
1209 return kMipsWordSize;
1210}
1211
1212size_t CodeGeneratorMIPS::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
1213 __ LoadFromOffset(kLoadWord, Register(reg_id), SP, stack_index);
1214 return kMipsWordSize;
1215}
1216
1217size_t CodeGeneratorMIPS::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1218 __ StoreDToOffset(FRegister(reg_id), SP, stack_index);
1219 return kMipsDoublewordSize;
1220}
1221
1222size_t CodeGeneratorMIPS::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
1223 __ LoadDFromOffset(FRegister(reg_id), SP, stack_index);
1224 return kMipsDoublewordSize;
1225}
1226
1227void CodeGeneratorMIPS::DumpCoreRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001228 stream << Register(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001229}
1230
1231void CodeGeneratorMIPS::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Vladimir Marko623a7a22016-02-02 18:14:52 +00001232 stream << FRegister(reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001233}
1234
Serban Constantinescufca16662016-07-14 09:21:59 +01001235constexpr size_t kMipsDirectEntrypointRuntimeOffset = 16;
1236
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001237void CodeGeneratorMIPS::InvokeRuntime(QuickEntrypointEnum entrypoint,
1238 HInstruction* instruction,
1239 uint32_t dex_pc,
1240 SlowPathCode* slow_path) {
Alexandre Rames91a65162016-09-19 13:54:30 +01001241 ValidateInvokeRuntime(entrypoint, instruction, slow_path);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001242 bool reordering = __ SetReorder(false);
Serban Constantinescufca16662016-07-14 09:21:59 +01001243 __ LoadFromOffset(kLoadWord, T9, TR, GetThreadOffset<kMipsPointerSize>(entrypoint).Int32Value());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001244 __ Jalr(T9);
Serban Constantinescufca16662016-07-14 09:21:59 +01001245 if (IsDirectEntrypoint(entrypoint)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001246 // Reserve argument space on stack (for $a0-$a3) for
1247 // entrypoints that directly reference native implementations.
1248 // Called function may use this space to store $a0-$a3 regs.
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001249 __ IncreaseFrameSize(kMipsDirectEntrypointRuntimeOffset); // Single instruction in delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001250 __ DecreaseFrameSize(kMipsDirectEntrypointRuntimeOffset);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001251 } else {
1252 __ Nop(); // In delay slot.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001253 }
Alexey Frunze57eb0f52016-07-29 22:04:46 -07001254 __ SetReorder(reordering);
Serban Constantinescufca16662016-07-14 09:21:59 +01001255 if (EntrypointRequiresStackMap(entrypoint)) {
1256 RecordPcInfo(instruction, dex_pc, slow_path);
1257 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001258}
1259
1260void InstructionCodeGeneratorMIPS::GenerateClassInitializationCheck(SlowPathCodeMIPS* slow_path,
1261 Register class_reg) {
1262 __ LoadFromOffset(kLoadWord, TMP, class_reg, mirror::Class::StatusOffset().Int32Value());
1263 __ LoadConst32(AT, mirror::Class::kStatusInitialized);
1264 __ Blt(TMP, AT, slow_path->GetEntryLabel());
1265 // Even if the initialized flag is set, we need to ensure consistent memory ordering.
1266 __ Sync(0);
1267 __ Bind(slow_path->GetExitLabel());
1268}
1269
1270void InstructionCodeGeneratorMIPS::GenerateMemoryBarrier(MemBarrierKind kind ATTRIBUTE_UNUSED) {
1271 __ Sync(0); // Only stype 0 is supported.
1272}
1273
1274void InstructionCodeGeneratorMIPS::GenerateSuspendCheck(HSuspendCheck* instruction,
1275 HBasicBlock* successor) {
1276 SuspendCheckSlowPathMIPS* slow_path =
1277 new (GetGraph()->GetArena()) SuspendCheckSlowPathMIPS(instruction, successor);
1278 codegen_->AddSlowPath(slow_path);
1279
1280 __ LoadFromOffset(kLoadUnsignedHalfword,
1281 TMP,
1282 TR,
Andreas Gampe542451c2016-07-26 09:02:02 -07001283 Thread::ThreadFlagsOffset<kMipsPointerSize>().Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001284 if (successor == nullptr) {
1285 __ Bnez(TMP, slow_path->GetEntryLabel());
1286 __ Bind(slow_path->GetReturnLabel());
1287 } else {
1288 __ Beqz(TMP, codegen_->GetLabelOf(successor));
1289 __ B(slow_path->GetEntryLabel());
1290 // slow_path will return to GetLabelOf(successor).
1291 }
1292}
1293
1294InstructionCodeGeneratorMIPS::InstructionCodeGeneratorMIPS(HGraph* graph,
1295 CodeGeneratorMIPS* codegen)
Aart Bik42249c32016-01-07 15:33:50 -08001296 : InstructionCodeGenerator(graph, codegen),
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001297 assembler_(codegen->GetAssembler()),
1298 codegen_(codegen) {}
1299
1300void LocationsBuilderMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1301 DCHECK_EQ(instruction->InputCount(), 2U);
1302 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1303 Primitive::Type type = instruction->GetResultType();
1304 switch (type) {
1305 case Primitive::kPrimInt: {
1306 locations->SetInAt(0, Location::RequiresRegister());
1307 HInstruction* right = instruction->InputAt(1);
1308 bool can_use_imm = false;
1309 if (right->IsConstant()) {
1310 int32_t imm = CodeGenerator::GetInt32ValueOf(right->AsConstant());
1311 if (instruction->IsAnd() || instruction->IsOr() || instruction->IsXor()) {
1312 can_use_imm = IsUint<16>(imm);
1313 } else if (instruction->IsAdd()) {
1314 can_use_imm = IsInt<16>(imm);
1315 } else {
1316 DCHECK(instruction->IsSub());
1317 can_use_imm = IsInt<16>(-imm);
1318 }
1319 }
1320 if (can_use_imm)
1321 locations->SetInAt(1, Location::ConstantLocation(right->AsConstant()));
1322 else
1323 locations->SetInAt(1, Location::RequiresRegister());
1324 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1325 break;
1326 }
1327
1328 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001329 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001330 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1331 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001332 break;
1333 }
1334
1335 case Primitive::kPrimFloat:
1336 case Primitive::kPrimDouble:
1337 DCHECK(instruction->IsAdd() || instruction->IsSub());
1338 locations->SetInAt(0, Location::RequiresFpuRegister());
1339 locations->SetInAt(1, Location::RequiresFpuRegister());
1340 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1341 break;
1342
1343 default:
1344 LOG(FATAL) << "Unexpected " << instruction->DebugName() << " type " << type;
1345 }
1346}
1347
1348void InstructionCodeGeneratorMIPS::HandleBinaryOp(HBinaryOperation* instruction) {
1349 Primitive::Type type = instruction->GetType();
1350 LocationSummary* locations = instruction->GetLocations();
1351
1352 switch (type) {
1353 case Primitive::kPrimInt: {
1354 Register dst = locations->Out().AsRegister<Register>();
1355 Register lhs = locations->InAt(0).AsRegister<Register>();
1356 Location rhs_location = locations->InAt(1);
1357
1358 Register rhs_reg = ZERO;
1359 int32_t rhs_imm = 0;
1360 bool use_imm = rhs_location.IsConstant();
1361 if (use_imm) {
1362 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
1363 } else {
1364 rhs_reg = rhs_location.AsRegister<Register>();
1365 }
1366
1367 if (instruction->IsAnd()) {
1368 if (use_imm)
1369 __ Andi(dst, lhs, rhs_imm);
1370 else
1371 __ And(dst, lhs, rhs_reg);
1372 } else if (instruction->IsOr()) {
1373 if (use_imm)
1374 __ Ori(dst, lhs, rhs_imm);
1375 else
1376 __ Or(dst, lhs, rhs_reg);
1377 } else if (instruction->IsXor()) {
1378 if (use_imm)
1379 __ Xori(dst, lhs, rhs_imm);
1380 else
1381 __ Xor(dst, lhs, rhs_reg);
1382 } else if (instruction->IsAdd()) {
1383 if (use_imm)
1384 __ Addiu(dst, lhs, rhs_imm);
1385 else
1386 __ Addu(dst, lhs, rhs_reg);
1387 } else {
1388 DCHECK(instruction->IsSub());
1389 if (use_imm)
1390 __ Addiu(dst, lhs, -rhs_imm);
1391 else
1392 __ Subu(dst, lhs, rhs_reg);
1393 }
1394 break;
1395 }
1396
1397 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001398 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1399 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1400 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1401 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001402 Location rhs_location = locations->InAt(1);
1403 bool use_imm = rhs_location.IsConstant();
1404 if (!use_imm) {
1405 Register rhs_high = rhs_location.AsRegisterPairHigh<Register>();
1406 Register rhs_low = rhs_location.AsRegisterPairLow<Register>();
1407 if (instruction->IsAnd()) {
1408 __ And(dst_low, lhs_low, rhs_low);
1409 __ And(dst_high, lhs_high, rhs_high);
1410 } else if (instruction->IsOr()) {
1411 __ Or(dst_low, lhs_low, rhs_low);
1412 __ Or(dst_high, lhs_high, rhs_high);
1413 } else if (instruction->IsXor()) {
1414 __ Xor(dst_low, lhs_low, rhs_low);
1415 __ Xor(dst_high, lhs_high, rhs_high);
1416 } else if (instruction->IsAdd()) {
1417 if (lhs_low == rhs_low) {
1418 // Special case for lhs = rhs and the sum potentially overwriting both lhs and rhs.
1419 __ Slt(TMP, lhs_low, ZERO);
1420 __ Addu(dst_low, lhs_low, rhs_low);
1421 } else {
1422 __ Addu(dst_low, lhs_low, rhs_low);
1423 // If the sum overwrites rhs, lhs remains unchanged, otherwise rhs remains unchanged.
1424 __ Sltu(TMP, dst_low, (dst_low == rhs_low) ? lhs_low : rhs_low);
1425 }
1426 __ Addu(dst_high, lhs_high, rhs_high);
1427 __ Addu(dst_high, dst_high, TMP);
1428 } else {
1429 DCHECK(instruction->IsSub());
1430 __ Sltu(TMP, lhs_low, rhs_low);
1431 __ Subu(dst_low, lhs_low, rhs_low);
1432 __ Subu(dst_high, lhs_high, rhs_high);
1433 __ Subu(dst_high, dst_high, TMP);
1434 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001435 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001436 int64_t value = CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()->AsConstant());
1437 if (instruction->IsOr()) {
1438 uint32_t low = Low32Bits(value);
1439 uint32_t high = High32Bits(value);
1440 if (IsUint<16>(low)) {
1441 if (dst_low != lhs_low || low != 0) {
1442 __ Ori(dst_low, lhs_low, low);
1443 }
1444 } else {
1445 __ LoadConst32(TMP, low);
1446 __ Or(dst_low, lhs_low, TMP);
1447 }
1448 if (IsUint<16>(high)) {
1449 if (dst_high != lhs_high || high != 0) {
1450 __ Ori(dst_high, lhs_high, high);
1451 }
1452 } else {
1453 if (high != low) {
1454 __ LoadConst32(TMP, high);
1455 }
1456 __ Or(dst_high, lhs_high, TMP);
1457 }
1458 } else if (instruction->IsXor()) {
1459 uint32_t low = Low32Bits(value);
1460 uint32_t high = High32Bits(value);
1461 if (IsUint<16>(low)) {
1462 if (dst_low != lhs_low || low != 0) {
1463 __ Xori(dst_low, lhs_low, low);
1464 }
1465 } else {
1466 __ LoadConst32(TMP, low);
1467 __ Xor(dst_low, lhs_low, TMP);
1468 }
1469 if (IsUint<16>(high)) {
1470 if (dst_high != lhs_high || high != 0) {
1471 __ Xori(dst_high, lhs_high, high);
1472 }
1473 } else {
1474 if (high != low) {
1475 __ LoadConst32(TMP, high);
1476 }
1477 __ Xor(dst_high, lhs_high, TMP);
1478 }
1479 } else if (instruction->IsAnd()) {
1480 uint32_t low = Low32Bits(value);
1481 uint32_t high = High32Bits(value);
1482 if (IsUint<16>(low)) {
1483 __ Andi(dst_low, lhs_low, low);
1484 } else if (low != 0xFFFFFFFF) {
1485 __ LoadConst32(TMP, low);
1486 __ And(dst_low, lhs_low, TMP);
1487 } else if (dst_low != lhs_low) {
1488 __ Move(dst_low, lhs_low);
1489 }
1490 if (IsUint<16>(high)) {
1491 __ Andi(dst_high, lhs_high, high);
1492 } else if (high != 0xFFFFFFFF) {
1493 if (high != low) {
1494 __ LoadConst32(TMP, high);
1495 }
1496 __ And(dst_high, lhs_high, TMP);
1497 } else if (dst_high != lhs_high) {
1498 __ Move(dst_high, lhs_high);
1499 }
1500 } else {
1501 if (instruction->IsSub()) {
1502 value = -value;
1503 } else {
1504 DCHECK(instruction->IsAdd());
1505 }
1506 int32_t low = Low32Bits(value);
1507 int32_t high = High32Bits(value);
1508 if (IsInt<16>(low)) {
1509 if (dst_low != lhs_low || low != 0) {
1510 __ Addiu(dst_low, lhs_low, low);
1511 }
1512 if (low != 0) {
1513 __ Sltiu(AT, dst_low, low);
1514 }
1515 } else {
1516 __ LoadConst32(TMP, low);
1517 __ Addu(dst_low, lhs_low, TMP);
1518 __ Sltu(AT, dst_low, TMP);
1519 }
1520 if (IsInt<16>(high)) {
1521 if (dst_high != lhs_high || high != 0) {
1522 __ Addiu(dst_high, lhs_high, high);
1523 }
1524 } else {
1525 if (high != low) {
1526 __ LoadConst32(TMP, high);
1527 }
1528 __ Addu(dst_high, lhs_high, TMP);
1529 }
1530 if (low != 0) {
1531 __ Addu(dst_high, dst_high, AT);
1532 }
1533 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001534 }
1535 break;
1536 }
1537
1538 case Primitive::kPrimFloat:
1539 case Primitive::kPrimDouble: {
1540 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
1541 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
1542 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
1543 if (instruction->IsAdd()) {
1544 if (type == Primitive::kPrimFloat) {
1545 __ AddS(dst, lhs, rhs);
1546 } else {
1547 __ AddD(dst, lhs, rhs);
1548 }
1549 } else {
1550 DCHECK(instruction->IsSub());
1551 if (type == Primitive::kPrimFloat) {
1552 __ SubS(dst, lhs, rhs);
1553 } else {
1554 __ SubD(dst, lhs, rhs);
1555 }
1556 }
1557 break;
1558 }
1559
1560 default:
1561 LOG(FATAL) << "Unexpected binary operation type " << type;
1562 }
1563}
1564
1565void LocationsBuilderMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001566 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001567
1568 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instr);
1569 Primitive::Type type = instr->GetResultType();
1570 switch (type) {
1571 case Primitive::kPrimInt:
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001572 locations->SetInAt(0, Location::RequiresRegister());
1573 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1574 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1575 break;
1576 case Primitive::kPrimLong:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001577 locations->SetInAt(0, Location::RequiresRegister());
1578 locations->SetInAt(1, Location::RegisterOrConstant(instr->InputAt(1)));
1579 locations->SetOut(Location::RequiresRegister());
1580 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001581 default:
1582 LOG(FATAL) << "Unexpected shift type " << type;
1583 }
1584}
1585
1586static constexpr size_t kMipsBitsPerWord = kMipsWordSize * kBitsPerByte;
1587
1588void InstructionCodeGeneratorMIPS::HandleShift(HBinaryOperation* instr) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001589 DCHECK(instr->IsShl() || instr->IsShr() || instr->IsUShr() || instr->IsRor());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001590 LocationSummary* locations = instr->GetLocations();
1591 Primitive::Type type = instr->GetType();
1592
1593 Location rhs_location = locations->InAt(1);
1594 bool use_imm = rhs_location.IsConstant();
1595 Register rhs_reg = use_imm ? ZERO : rhs_location.AsRegister<Register>();
1596 int64_t rhs_imm = use_imm ? CodeGenerator::GetInt64ValueOf(rhs_location.GetConstant()) : 0;
Roland Levillain5b5b9312016-03-22 14:57:31 +00001597 const uint32_t shift_mask =
1598 (type == Primitive::kPrimInt) ? kMaxIntShiftDistance : kMaxLongShiftDistance;
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001599 const uint32_t shift_value = rhs_imm & shift_mask;
Alexey Frunze92d90602015-12-18 18:16:36 -08001600 // Are the INS (Insert Bit Field) and ROTR instructions supported?
1601 bool has_ins_rotr = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001602
1603 switch (type) {
1604 case Primitive::kPrimInt: {
1605 Register dst = locations->Out().AsRegister<Register>();
1606 Register lhs = locations->InAt(0).AsRegister<Register>();
1607 if (use_imm) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001608 if (shift_value == 0) {
1609 if (dst != lhs) {
1610 __ Move(dst, lhs);
1611 }
1612 } else if (instr->IsShl()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001613 __ Sll(dst, lhs, shift_value);
1614 } else if (instr->IsShr()) {
1615 __ Sra(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001616 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001617 __ Srl(dst, lhs, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001618 } else {
1619 if (has_ins_rotr) {
1620 __ Rotr(dst, lhs, shift_value);
1621 } else {
1622 __ Sll(TMP, lhs, (kMipsBitsPerWord - shift_value) & shift_mask);
1623 __ Srl(dst, lhs, shift_value);
1624 __ Or(dst, dst, TMP);
1625 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001626 }
1627 } else {
1628 if (instr->IsShl()) {
1629 __ Sllv(dst, lhs, rhs_reg);
1630 } else if (instr->IsShr()) {
1631 __ Srav(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001632 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001633 __ Srlv(dst, lhs, rhs_reg);
Alexey Frunze92d90602015-12-18 18:16:36 -08001634 } else {
1635 if (has_ins_rotr) {
1636 __ Rotrv(dst, lhs, rhs_reg);
1637 } else {
1638 __ Subu(TMP, ZERO, rhs_reg);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001639 // 32-bit shift instructions use the 5 least significant bits of the shift count, so
1640 // shifting by `-rhs_reg` is equivalent to shifting by `(32 - rhs_reg) & 31`. The case
1641 // when `rhs_reg & 31 == 0` is OK even though we don't shift `lhs` left all the way out
1642 // by 32, because the result in this case is computed as `(lhs >> 0) | (lhs << 0)`,
1643 // IOW, the OR'd values are equal.
Alexey Frunze92d90602015-12-18 18:16:36 -08001644 __ Sllv(TMP, lhs, TMP);
1645 __ Srlv(dst, lhs, rhs_reg);
1646 __ Or(dst, dst, TMP);
1647 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001648 }
1649 }
1650 break;
1651 }
1652
1653 case Primitive::kPrimLong: {
1654 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
1655 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
1656 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
1657 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
1658 if (use_imm) {
1659 if (shift_value == 0) {
1660 codegen_->Move64(locations->Out(), locations->InAt(0));
1661 } else if (shift_value < kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001662 if (has_ins_rotr) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001663 if (instr->IsShl()) {
1664 __ Srl(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1665 __ Ins(dst_high, lhs_high, shift_value, kMipsBitsPerWord - shift_value);
1666 __ Sll(dst_low, lhs_low, shift_value);
1667 } else if (instr->IsShr()) {
1668 __ Srl(dst_low, lhs_low, shift_value);
1669 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1670 __ Sra(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001671 } else if (instr->IsUShr()) {
1672 __ Srl(dst_low, lhs_low, shift_value);
1673 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1674 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001675 } else {
1676 __ Srl(dst_low, lhs_low, shift_value);
1677 __ Ins(dst_low, lhs_high, kMipsBitsPerWord - shift_value, shift_value);
1678 __ Srl(dst_high, lhs_high, shift_value);
Alexey Frunze92d90602015-12-18 18:16:36 -08001679 __ Ins(dst_high, lhs_low, kMipsBitsPerWord - shift_value, shift_value);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001680 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001681 } else {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001682 if (instr->IsShl()) {
1683 __ Sll(dst_low, lhs_low, shift_value);
1684 __ Srl(TMP, lhs_low, kMipsBitsPerWord - shift_value);
1685 __ Sll(dst_high, lhs_high, shift_value);
1686 __ Or(dst_high, dst_high, TMP);
1687 } else if (instr->IsShr()) {
1688 __ Sra(dst_high, lhs_high, shift_value);
1689 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1690 __ Srl(dst_low, lhs_low, shift_value);
1691 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001692 } else if (instr->IsUShr()) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001693 __ Srl(dst_high, lhs_high, shift_value);
1694 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value);
1695 __ Srl(dst_low, lhs_low, shift_value);
1696 __ Or(dst_low, dst_low, TMP);
Alexey Frunze92d90602015-12-18 18:16:36 -08001697 } else {
1698 __ Srl(TMP, lhs_low, shift_value);
1699 __ Sll(dst_low, lhs_high, kMipsBitsPerWord - shift_value);
1700 __ Or(dst_low, dst_low, TMP);
1701 __ Srl(TMP, lhs_high, shift_value);
1702 __ Sll(dst_high, lhs_low, kMipsBitsPerWord - shift_value);
1703 __ Or(dst_high, dst_high, TMP);
Alexey Frunze5c7aed32015-11-25 19:41:54 -08001704 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001705 }
1706 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001707 const uint32_t shift_value_high = shift_value - kMipsBitsPerWord;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001708 if (instr->IsShl()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001709 __ Sll(dst_high, lhs_low, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001710 __ Move(dst_low, ZERO);
1711 } else if (instr->IsShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001712 __ Sra(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001713 __ Sra(dst_high, dst_low, kMipsBitsPerWord - 1);
Alexey Frunze92d90602015-12-18 18:16:36 -08001714 } else if (instr->IsUShr()) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001715 __ Srl(dst_low, lhs_high, shift_value_high);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001716 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001717 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001718 if (shift_value == kMipsBitsPerWord) {
Alexey Frunze92d90602015-12-18 18:16:36 -08001719 // 64-bit rotation by 32 is just a swap.
1720 __ Move(dst_low, lhs_high);
1721 __ Move(dst_high, lhs_low);
1722 } else {
1723 if (has_ins_rotr) {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001724 __ Srl(dst_low, lhs_high, shift_value_high);
1725 __ Ins(dst_low, lhs_low, kMipsBitsPerWord - shift_value_high, shift_value_high);
1726 __ Srl(dst_high, lhs_low, shift_value_high);
1727 __ Ins(dst_high, lhs_high, kMipsBitsPerWord - shift_value_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001728 } else {
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001729 __ Sll(TMP, lhs_low, kMipsBitsPerWord - shift_value_high);
1730 __ Srl(dst_low, lhs_high, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001731 __ Or(dst_low, dst_low, TMP);
Alexey Frunze0d9150b2016-01-13 16:24:25 -08001732 __ Sll(TMP, lhs_high, kMipsBitsPerWord - shift_value_high);
1733 __ Srl(dst_high, lhs_low, shift_value_high);
Alexey Frunze92d90602015-12-18 18:16:36 -08001734 __ Or(dst_high, dst_high, TMP);
1735 }
1736 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001737 }
1738 }
1739 } else {
1740 MipsLabel done;
1741 if (instr->IsShl()) {
1742 __ Sllv(dst_low, lhs_low, rhs_reg);
1743 __ Nor(AT, ZERO, rhs_reg);
1744 __ Srl(TMP, lhs_low, 1);
1745 __ Srlv(TMP, TMP, AT);
1746 __ Sllv(dst_high, lhs_high, rhs_reg);
1747 __ Or(dst_high, dst_high, TMP);
1748 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1749 __ Beqz(TMP, &done);
1750 __ Move(dst_high, dst_low);
1751 __ Move(dst_low, ZERO);
1752 } else if (instr->IsShr()) {
1753 __ Srav(dst_high, lhs_high, rhs_reg);
1754 __ Nor(AT, ZERO, rhs_reg);
1755 __ Sll(TMP, lhs_high, 1);
1756 __ Sllv(TMP, TMP, AT);
1757 __ Srlv(dst_low, lhs_low, rhs_reg);
1758 __ Or(dst_low, dst_low, TMP);
1759 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1760 __ Beqz(TMP, &done);
1761 __ Move(dst_low, dst_high);
1762 __ Sra(dst_high, dst_high, 31);
Alexey Frunze92d90602015-12-18 18:16:36 -08001763 } else if (instr->IsUShr()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001764 __ Srlv(dst_high, lhs_high, rhs_reg);
1765 __ Nor(AT, ZERO, rhs_reg);
1766 __ Sll(TMP, lhs_high, 1);
1767 __ Sllv(TMP, TMP, AT);
1768 __ Srlv(dst_low, lhs_low, rhs_reg);
1769 __ Or(dst_low, dst_low, TMP);
1770 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1771 __ Beqz(TMP, &done);
1772 __ Move(dst_low, dst_high);
1773 __ Move(dst_high, ZERO);
Alexey Frunze92d90602015-12-18 18:16:36 -08001774 } else {
1775 __ Nor(AT, ZERO, rhs_reg);
1776 __ Srlv(TMP, lhs_low, rhs_reg);
1777 __ Sll(dst_low, lhs_high, 1);
1778 __ Sllv(dst_low, dst_low, AT);
1779 __ Or(dst_low, dst_low, TMP);
1780 __ Srlv(TMP, lhs_high, rhs_reg);
1781 __ Sll(dst_high, lhs_low, 1);
1782 __ Sllv(dst_high, dst_high, AT);
1783 __ Or(dst_high, dst_high, TMP);
1784 __ Andi(TMP, rhs_reg, kMipsBitsPerWord);
1785 __ Beqz(TMP, &done);
1786 __ Move(TMP, dst_high);
1787 __ Move(dst_high, dst_low);
1788 __ Move(dst_low, TMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001789 }
1790 __ Bind(&done);
1791 }
1792 break;
1793 }
1794
1795 default:
1796 LOG(FATAL) << "Unexpected shift operation type " << type;
1797 }
1798}
1799
1800void LocationsBuilderMIPS::VisitAdd(HAdd* instruction) {
1801 HandleBinaryOp(instruction);
1802}
1803
1804void InstructionCodeGeneratorMIPS::VisitAdd(HAdd* instruction) {
1805 HandleBinaryOp(instruction);
1806}
1807
1808void LocationsBuilderMIPS::VisitAnd(HAnd* instruction) {
1809 HandleBinaryOp(instruction);
1810}
1811
1812void InstructionCodeGeneratorMIPS::VisitAnd(HAnd* instruction) {
1813 HandleBinaryOp(instruction);
1814}
1815
1816void LocationsBuilderMIPS::VisitArrayGet(HArrayGet* instruction) {
1817 LocationSummary* locations =
1818 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
1819 locations->SetInAt(0, Location::RequiresRegister());
1820 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1821 if (Primitive::IsFloatingPointType(instruction->GetType())) {
1822 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
1823 } else {
1824 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1825 }
1826}
1827
Alexey Frunze2923db72016-08-20 01:55:47 -07001828auto InstructionCodeGeneratorMIPS::GetImplicitNullChecker(HInstruction* instruction) {
1829 auto null_checker = [this, instruction]() {
1830 this->codegen_->MaybeRecordImplicitNullCheck(instruction);
1831 };
1832 return null_checker;
1833}
1834
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001835void InstructionCodeGeneratorMIPS::VisitArrayGet(HArrayGet* instruction) {
1836 LocationSummary* locations = instruction->GetLocations();
1837 Register obj = locations->InAt(0).AsRegister<Register>();
1838 Location index = locations->InAt(1);
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001839 uint32_t data_offset = CodeGenerator::GetArrayDataOffset(instruction);
Alexey Frunze2923db72016-08-20 01:55:47 -07001840 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001841
Vladimir Marko87f3fcb2016-04-28 15:52:11 +01001842 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001843 switch (type) {
1844 case Primitive::kPrimBoolean: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001845 Register out = locations->Out().AsRegister<Register>();
1846 if (index.IsConstant()) {
1847 size_t offset =
1848 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001849 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001850 } else {
1851 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001852 __ LoadFromOffset(kLoadUnsignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001853 }
1854 break;
1855 }
1856
1857 case Primitive::kPrimByte: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001858 Register out = locations->Out().AsRegister<Register>();
1859 if (index.IsConstant()) {
1860 size_t offset =
1861 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001862 __ LoadFromOffset(kLoadSignedByte, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001863 } else {
1864 __ Addu(TMP, obj, index.AsRegister<Register>());
Alexey Frunze2923db72016-08-20 01:55:47 -07001865 __ LoadFromOffset(kLoadSignedByte, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001866 }
1867 break;
1868 }
1869
1870 case Primitive::kPrimShort: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001871 Register out = locations->Out().AsRegister<Register>();
1872 if (index.IsConstant()) {
1873 size_t offset =
1874 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001875 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001876 } else {
1877 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1878 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001879 __ LoadFromOffset(kLoadSignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001880 }
1881 break;
1882 }
1883
1884 case Primitive::kPrimChar: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001885 Register out = locations->Out().AsRegister<Register>();
1886 if (index.IsConstant()) {
1887 size_t offset =
1888 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001889 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001890 } else {
1891 __ Sll(TMP, index.AsRegister<Register>(), TIMES_2);
1892 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001893 __ LoadFromOffset(kLoadUnsignedHalfword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001894 }
1895 break;
1896 }
1897
1898 case Primitive::kPrimInt:
1899 case Primitive::kPrimNot: {
1900 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001901 Register out = locations->Out().AsRegister<Register>();
1902 if (index.IsConstant()) {
1903 size_t offset =
1904 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001905 __ LoadFromOffset(kLoadWord, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001906 } else {
1907 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1908 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001909 __ LoadFromOffset(kLoadWord, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001910 }
1911 break;
1912 }
1913
1914 case Primitive::kPrimLong: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001915 Register out = locations->Out().AsRegisterPairLow<Register>();
1916 if (index.IsConstant()) {
1917 size_t offset =
1918 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001919 __ LoadFromOffset(kLoadDoubleword, out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001920 } else {
1921 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1922 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001923 __ LoadFromOffset(kLoadDoubleword, out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001924 }
1925 break;
1926 }
1927
1928 case Primitive::kPrimFloat: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001929 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1930 if (index.IsConstant()) {
1931 size_t offset =
1932 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001933 __ LoadSFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001934 } else {
1935 __ Sll(TMP, index.AsRegister<Register>(), TIMES_4);
1936 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001937 __ LoadSFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001938 }
1939 break;
1940 }
1941
1942 case Primitive::kPrimDouble: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001943 FRegister out = locations->Out().AsFpuRegister<FRegister>();
1944 if (index.IsConstant()) {
1945 size_t offset =
1946 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Alexey Frunze2923db72016-08-20 01:55:47 -07001947 __ LoadDFromOffset(out, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001948 } else {
1949 __ Sll(TMP, index.AsRegister<Register>(), TIMES_8);
1950 __ Addu(TMP, obj, TMP);
Alexey Frunze2923db72016-08-20 01:55:47 -07001951 __ LoadDFromOffset(out, TMP, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001952 }
1953 break;
1954 }
1955
1956 case Primitive::kPrimVoid:
1957 LOG(FATAL) << "Unreachable type " << instruction->GetType();
1958 UNREACHABLE();
1959 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001960}
1961
1962void LocationsBuilderMIPS::VisitArrayLength(HArrayLength* instruction) {
1963 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
1964 locations->SetInAt(0, Location::RequiresRegister());
1965 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1966}
1967
1968void InstructionCodeGeneratorMIPS::VisitArrayLength(HArrayLength* instruction) {
1969 LocationSummary* locations = instruction->GetLocations();
Vladimir Markodce016e2016-04-28 13:10:02 +01001970 uint32_t offset = CodeGenerator::GetArrayLengthOffset(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001971 Register obj = locations->InAt(0).AsRegister<Register>();
1972 Register out = locations->Out().AsRegister<Register>();
1973 __ LoadFromOffset(kLoadWord, out, obj, offset);
1974 codegen_->MaybeRecordImplicitNullCheck(instruction);
1975}
1976
Alexey Frunzef58b2482016-09-02 22:14:06 -07001977Location LocationsBuilderMIPS::RegisterOrZeroConstant(HInstruction* instruction) {
1978 return (instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern())
1979 ? Location::ConstantLocation(instruction->AsConstant())
1980 : Location::RequiresRegister();
1981}
1982
1983Location LocationsBuilderMIPS::FpuRegisterOrConstantForStore(HInstruction* instruction) {
1984 // We can store 0.0 directly (from the ZERO register) without loading it into an FPU register.
1985 // We can store a non-zero float or double constant without first loading it into the FPU,
1986 // but we should only prefer this if the constant has a single use.
1987 if (instruction->IsConstant() &&
1988 (instruction->AsConstant()->IsZeroBitPattern() ||
1989 instruction->GetUses().HasExactlyOneElement())) {
1990 return Location::ConstantLocation(instruction->AsConstant());
1991 // Otherwise fall through and require an FPU register for the constant.
1992 }
1993 return Location::RequiresFpuRegister();
1994}
1995
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001996void LocationsBuilderMIPS::VisitArraySet(HArraySet* instruction) {
Pavle Batuta934808f2015-11-03 13:23:54 +01001997 bool needs_runtime_call = instruction->NeedsTypeCheck();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02001998 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1999 instruction,
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002000 needs_runtime_call ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Pavle Batuta934808f2015-11-03 13:23:54 +01002001 if (needs_runtime_call) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002002 InvokeRuntimeCallingConvention calling_convention;
2003 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2004 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2005 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2006 } else {
2007 locations->SetInAt(0, Location::RequiresRegister());
2008 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2009 if (Primitive::IsFloatingPointType(instruction->InputAt(2)->GetType())) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002010 locations->SetInAt(2, FpuRegisterOrConstantForStore(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002011 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002012 locations->SetInAt(2, RegisterOrZeroConstant(instruction->InputAt(2)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002013 }
2014 }
2015}
2016
2017void InstructionCodeGeneratorMIPS::VisitArraySet(HArraySet* instruction) {
2018 LocationSummary* locations = instruction->GetLocations();
2019 Register obj = locations->InAt(0).AsRegister<Register>();
2020 Location index = locations->InAt(1);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002021 Location value_location = locations->InAt(2);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002022 Primitive::Type value_type = instruction->GetComponentType();
2023 bool needs_runtime_call = locations->WillCall();
2024 bool needs_write_barrier =
2025 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Alexey Frunze2923db72016-08-20 01:55:47 -07002026 auto null_checker = GetImplicitNullChecker(instruction);
Alexey Frunzef58b2482016-09-02 22:14:06 -07002027 Register base_reg = index.IsConstant() ? obj : TMP;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002028
2029 switch (value_type) {
2030 case Primitive::kPrimBoolean:
2031 case Primitive::kPrimByte: {
2032 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002033 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002034 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002035 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002036 __ Addu(base_reg, obj, index.AsRegister<Register>());
2037 }
2038 if (value_location.IsConstant()) {
2039 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2040 __ StoreConstToOffset(kStoreByte, value, base_reg, data_offset, TMP, null_checker);
2041 } else {
2042 Register value = value_location.AsRegister<Register>();
2043 __ StoreToOffset(kStoreByte, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002044 }
2045 break;
2046 }
2047
2048 case Primitive::kPrimShort:
2049 case Primitive::kPrimChar: {
2050 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002051 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002052 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002053 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002054 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_2);
2055 __ Addu(base_reg, obj, base_reg);
2056 }
2057 if (value_location.IsConstant()) {
2058 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2059 __ StoreConstToOffset(kStoreHalfword, value, base_reg, data_offset, TMP, null_checker);
2060 } else {
2061 Register value = value_location.AsRegister<Register>();
2062 __ StoreToOffset(kStoreHalfword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002063 }
2064 break;
2065 }
2066
2067 case Primitive::kPrimInt:
2068 case Primitive::kPrimNot: {
2069 if (!needs_runtime_call) {
2070 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002071 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002072 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002073 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002074 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4);
2075 __ Addu(base_reg, obj, base_reg);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002076 }
Alexey Frunzef58b2482016-09-02 22:14:06 -07002077 if (value_location.IsConstant()) {
2078 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2079 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2080 DCHECK(!needs_write_barrier);
2081 } else {
2082 Register value = value_location.AsRegister<Register>();
2083 __ StoreToOffset(kStoreWord, value, base_reg, data_offset, null_checker);
2084 if (needs_write_barrier) {
2085 DCHECK_EQ(value_type, Primitive::kPrimNot);
2086 codegen_->MarkGCCard(obj, value);
2087 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002088 }
2089 } else {
2090 DCHECK_EQ(value_type, Primitive::kPrimNot);
Serban Constantinescufca16662016-07-14 09:21:59 +01002091 codegen_->InvokeRuntime(kQuickAputObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002092 CheckEntrypointTypes<kQuickAputObject, void, mirror::Array*, int32_t, mirror::Object*>();
2093 }
2094 break;
2095 }
2096
2097 case Primitive::kPrimLong: {
2098 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002099 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002100 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002101 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002102 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8);
2103 __ Addu(base_reg, obj, base_reg);
2104 }
2105 if (value_location.IsConstant()) {
2106 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2107 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2108 } else {
2109 Register value = value_location.AsRegisterPairLow<Register>();
2110 __ StoreToOffset(kStoreDoubleword, value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002111 }
2112 break;
2113 }
2114
2115 case Primitive::kPrimFloat: {
2116 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002117 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002118 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002119 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002120 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_4);
2121 __ Addu(base_reg, obj, base_reg);
2122 }
2123 if (value_location.IsConstant()) {
2124 int32_t value = CodeGenerator::GetInt32ValueOf(value_location.GetConstant());
2125 __ StoreConstToOffset(kStoreWord, value, base_reg, data_offset, TMP, null_checker);
2126 } else {
2127 FRegister value = value_location.AsFpuRegister<FRegister>();
2128 __ StoreSToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002129 }
2130 break;
2131 }
2132
2133 case Primitive::kPrimDouble: {
2134 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002135 if (index.IsConstant()) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002136 data_offset += index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002137 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07002138 __ Sll(base_reg, index.AsRegister<Register>(), TIMES_8);
2139 __ Addu(base_reg, obj, base_reg);
2140 }
2141 if (value_location.IsConstant()) {
2142 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
2143 __ StoreConstToOffset(kStoreDoubleword, value, base_reg, data_offset, TMP, null_checker);
2144 } else {
2145 FRegister value = value_location.AsFpuRegister<FRegister>();
2146 __ StoreDToOffset(value, base_reg, data_offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002147 }
2148 break;
2149 }
2150
2151 case Primitive::kPrimVoid:
2152 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2153 UNREACHABLE();
2154 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002155}
2156
2157void LocationsBuilderMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002158 RegisterSet caller_saves = RegisterSet::Empty();
2159 InvokeRuntimeCallingConvention calling_convention;
2160 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2161 caller_saves.Add(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2162 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction, caller_saves);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002163 locations->SetInAt(0, Location::RequiresRegister());
2164 locations->SetInAt(1, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002165}
2166
2167void InstructionCodeGeneratorMIPS::VisitBoundsCheck(HBoundsCheck* instruction) {
2168 LocationSummary* locations = instruction->GetLocations();
2169 BoundsCheckSlowPathMIPS* slow_path =
2170 new (GetGraph()->GetArena()) BoundsCheckSlowPathMIPS(instruction);
2171 codegen_->AddSlowPath(slow_path);
2172
2173 Register index = locations->InAt(0).AsRegister<Register>();
2174 Register length = locations->InAt(1).AsRegister<Register>();
2175
2176 // length is limited by the maximum positive signed 32-bit integer.
2177 // Unsigned comparison of length and index checks for index < 0
2178 // and for length <= index simultaneously.
2179 __ Bgeu(index, length, slow_path->GetEntryLabel());
2180}
2181
2182void LocationsBuilderMIPS::VisitCheckCast(HCheckCast* instruction) {
2183 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2184 instruction,
2185 LocationSummary::kCallOnSlowPath);
2186 locations->SetInAt(0, Location::RequiresRegister());
2187 locations->SetInAt(1, Location::RequiresRegister());
2188 // Note that TypeCheckSlowPathMIPS uses this register too.
2189 locations->AddTemp(Location::RequiresRegister());
2190}
2191
2192void InstructionCodeGeneratorMIPS::VisitCheckCast(HCheckCast* instruction) {
2193 LocationSummary* locations = instruction->GetLocations();
2194 Register obj = locations->InAt(0).AsRegister<Register>();
2195 Register cls = locations->InAt(1).AsRegister<Register>();
2196 Register obj_cls = locations->GetTemp(0).AsRegister<Register>();
2197
2198 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
2199 codegen_->AddSlowPath(slow_path);
2200
2201 // TODO: avoid this check if we know obj is not null.
2202 __ Beqz(obj, slow_path->GetExitLabel());
2203 // Compare the class of `obj` with `cls`.
2204 __ LoadFromOffset(kLoadWord, obj_cls, obj, mirror::Object::ClassOffset().Int32Value());
2205 __ Bne(obj_cls, cls, slow_path->GetEntryLabel());
2206 __ Bind(slow_path->GetExitLabel());
2207}
2208
2209void LocationsBuilderMIPS::VisitClinitCheck(HClinitCheck* check) {
2210 LocationSummary* locations =
2211 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2212 locations->SetInAt(0, Location::RequiresRegister());
2213 if (check->HasUses()) {
2214 locations->SetOut(Location::SameAsFirstInput());
2215 }
2216}
2217
2218void InstructionCodeGeneratorMIPS::VisitClinitCheck(HClinitCheck* check) {
2219 // We assume the class is not null.
2220 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
2221 check->GetLoadClass(),
2222 check,
2223 check->GetDexPc(),
2224 true);
2225 codegen_->AddSlowPath(slow_path);
2226 GenerateClassInitializationCheck(slow_path,
2227 check->GetLocations()->InAt(0).AsRegister<Register>());
2228}
2229
2230void LocationsBuilderMIPS::VisitCompare(HCompare* compare) {
2231 Primitive::Type in_type = compare->InputAt(0)->GetType();
2232
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002233 LocationSummary* locations =
2234 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002235
2236 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002237 case Primitive::kPrimBoolean:
2238 case Primitive::kPrimByte:
2239 case Primitive::kPrimShort:
2240 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002241 case Primitive::kPrimInt:
Alexey Frunzee7697712016-09-15 21:37:49 -07002242 locations->SetInAt(0, Location::RequiresRegister());
2243 locations->SetInAt(1, Location::RequiresRegister());
2244 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2245 break;
2246
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002247 case Primitive::kPrimLong:
2248 locations->SetInAt(0, Location::RequiresRegister());
2249 locations->SetInAt(1, Location::RequiresRegister());
2250 // Output overlaps because it is written before doing the low comparison.
2251 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
2252 break;
2253
2254 case Primitive::kPrimFloat:
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002255 case Primitive::kPrimDouble:
2256 locations->SetInAt(0, Location::RequiresFpuRegister());
2257 locations->SetInAt(1, Location::RequiresFpuRegister());
2258 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002259 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002260
2261 default:
2262 LOG(FATAL) << "Unexpected type for compare operation " << in_type;
2263 }
2264}
2265
2266void InstructionCodeGeneratorMIPS::VisitCompare(HCompare* instruction) {
2267 LocationSummary* locations = instruction->GetLocations();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002268 Register res = locations->Out().AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002269 Primitive::Type in_type = instruction->InputAt(0)->GetType();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002270 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002271
2272 // 0 if: left == right
2273 // 1 if: left > right
2274 // -1 if: left < right
2275 switch (in_type) {
Roland Levillaina5c4a402016-03-15 15:02:50 +00002276 case Primitive::kPrimBoolean:
2277 case Primitive::kPrimByte:
2278 case Primitive::kPrimShort:
2279 case Primitive::kPrimChar:
Aart Bika19616e2016-02-01 18:57:58 -08002280 case Primitive::kPrimInt: {
2281 Register lhs = locations->InAt(0).AsRegister<Register>();
2282 Register rhs = locations->InAt(1).AsRegister<Register>();
2283 __ Slt(TMP, lhs, rhs);
2284 __ Slt(res, rhs, lhs);
2285 __ Subu(res, res, TMP);
2286 break;
2287 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002288 case Primitive::kPrimLong: {
2289 MipsLabel done;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002290 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
2291 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
2292 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
2293 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
2294 // TODO: more efficient (direct) comparison with a constant.
2295 __ Slt(TMP, lhs_high, rhs_high);
2296 __ Slt(AT, rhs_high, lhs_high); // Inverted: is actually gt.
2297 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2298 __ Bnez(res, &done); // If we compared ==, check if lower bits are also equal.
2299 __ Sltu(TMP, lhs_low, rhs_low);
2300 __ Sltu(AT, rhs_low, lhs_low); // Inverted: is actually gt.
2301 __ Subu(res, AT, TMP); // Result -1:1:0 for [ <, >, == ].
2302 __ Bind(&done);
2303 break;
2304 }
2305
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002306 case Primitive::kPrimFloat: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002307 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002308 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2309 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2310 MipsLabel done;
2311 if (isR6) {
2312 __ CmpEqS(FTMP, lhs, rhs);
2313 __ LoadConst32(res, 0);
2314 __ Bc1nez(FTMP, &done);
2315 if (gt_bias) {
2316 __ CmpLtS(FTMP, lhs, rhs);
2317 __ LoadConst32(res, -1);
2318 __ Bc1nez(FTMP, &done);
2319 __ LoadConst32(res, 1);
2320 } else {
2321 __ CmpLtS(FTMP, rhs, lhs);
2322 __ LoadConst32(res, 1);
2323 __ Bc1nez(FTMP, &done);
2324 __ LoadConst32(res, -1);
2325 }
2326 } else {
2327 if (gt_bias) {
2328 __ ColtS(0, lhs, rhs);
2329 __ LoadConst32(res, -1);
2330 __ Bc1t(0, &done);
2331 __ CeqS(0, lhs, rhs);
2332 __ LoadConst32(res, 1);
2333 __ Movt(res, ZERO, 0);
2334 } else {
2335 __ ColtS(0, rhs, lhs);
2336 __ LoadConst32(res, 1);
2337 __ Bc1t(0, &done);
2338 __ CeqS(0, lhs, rhs);
2339 __ LoadConst32(res, -1);
2340 __ Movt(res, ZERO, 0);
2341 }
2342 }
2343 __ Bind(&done);
2344 break;
2345 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002346 case Primitive::kPrimDouble: {
Roland Levillain32ca3752016-02-17 16:49:37 +00002347 bool gt_bias = instruction->IsGtBias();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002348 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2349 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2350 MipsLabel done;
2351 if (isR6) {
2352 __ CmpEqD(FTMP, lhs, rhs);
2353 __ LoadConst32(res, 0);
2354 __ Bc1nez(FTMP, &done);
2355 if (gt_bias) {
2356 __ CmpLtD(FTMP, lhs, rhs);
2357 __ LoadConst32(res, -1);
2358 __ Bc1nez(FTMP, &done);
2359 __ LoadConst32(res, 1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002360 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002361 __ CmpLtD(FTMP, rhs, lhs);
2362 __ LoadConst32(res, 1);
2363 __ Bc1nez(FTMP, &done);
2364 __ LoadConst32(res, -1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002365 }
2366 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002367 if (gt_bias) {
2368 __ ColtD(0, lhs, rhs);
2369 __ LoadConst32(res, -1);
2370 __ Bc1t(0, &done);
2371 __ CeqD(0, lhs, rhs);
2372 __ LoadConst32(res, 1);
2373 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002374 } else {
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002375 __ ColtD(0, rhs, lhs);
2376 __ LoadConst32(res, 1);
2377 __ Bc1t(0, &done);
2378 __ CeqD(0, lhs, rhs);
2379 __ LoadConst32(res, -1);
2380 __ Movt(res, ZERO, 0);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002381 }
2382 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002383 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002384 break;
2385 }
2386
2387 default:
2388 LOG(FATAL) << "Unimplemented compare type " << in_type;
2389 }
2390}
2391
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002392void LocationsBuilderMIPS::HandleCondition(HCondition* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002393 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002394 switch (instruction->InputAt(0)->GetType()) {
2395 default:
2396 case Primitive::kPrimLong:
2397 locations->SetInAt(0, Location::RequiresRegister());
2398 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2399 break;
2400
2401 case Primitive::kPrimFloat:
2402 case Primitive::kPrimDouble:
2403 locations->SetInAt(0, Location::RequiresFpuRegister());
2404 locations->SetInAt(1, Location::RequiresFpuRegister());
2405 break;
2406 }
David Brazdilb3e773e2016-01-26 11:28:37 +00002407 if (!instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002408 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2409 }
2410}
2411
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00002412void InstructionCodeGeneratorMIPS::HandleCondition(HCondition* instruction) {
David Brazdilb3e773e2016-01-26 11:28:37 +00002413 if (instruction->IsEmittedAtUseSite()) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002414 return;
2415 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002416
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002417 Primitive::Type type = instruction->InputAt(0)->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002418 LocationSummary* locations = instruction->GetLocations();
2419 Register dst = locations->Out().AsRegister<Register>();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002420 MipsLabel true_label;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002421
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002422 switch (type) {
2423 default:
2424 // Integer case.
2425 GenerateIntCompare(instruction->GetCondition(), locations);
2426 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002427
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002428 case Primitive::kPrimLong:
2429 // TODO: don't use branches.
2430 GenerateLongCompareAndBranch(instruction->GetCondition(), locations, &true_label);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002431 break;
2432
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002433 case Primitive::kPrimFloat:
2434 case Primitive::kPrimDouble:
Alexey Frunze2ddb7172016-09-06 17:04:55 -07002435 GenerateFpCompare(instruction->GetCondition(), instruction->IsGtBias(), type, locations);
2436 return;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002437 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002438
2439 // Convert the branches into the result.
2440 MipsLabel done;
2441
2442 // False case: result = 0.
2443 __ LoadConst32(dst, 0);
2444 __ B(&done);
2445
2446 // True case: result = 1.
2447 __ Bind(&true_label);
2448 __ LoadConst32(dst, 1);
2449 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002450}
2451
Alexey Frunze7e99e052015-11-24 19:28:01 -08002452void InstructionCodeGeneratorMIPS::DivRemOneOrMinusOne(HBinaryOperation* instruction) {
2453 DCHECK(instruction->IsDiv() || instruction->IsRem());
2454 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2455
2456 LocationSummary* locations = instruction->GetLocations();
2457 Location second = locations->InAt(1);
2458 DCHECK(second.IsConstant());
2459
2460 Register out = locations->Out().AsRegister<Register>();
2461 Register dividend = locations->InAt(0).AsRegister<Register>();
2462 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2463 DCHECK(imm == 1 || imm == -1);
2464
2465 if (instruction->IsRem()) {
2466 __ Move(out, ZERO);
2467 } else {
2468 if (imm == -1) {
2469 __ Subu(out, ZERO, dividend);
2470 } else if (out != dividend) {
2471 __ Move(out, dividend);
2472 }
2473 }
2474}
2475
2476void InstructionCodeGeneratorMIPS::DivRemByPowerOfTwo(HBinaryOperation* instruction) {
2477 DCHECK(instruction->IsDiv() || instruction->IsRem());
2478 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2479
2480 LocationSummary* locations = instruction->GetLocations();
2481 Location second = locations->InAt(1);
2482 DCHECK(second.IsConstant());
2483
2484 Register out = locations->Out().AsRegister<Register>();
2485 Register dividend = locations->InAt(0).AsRegister<Register>();
2486 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002487 uint32_t abs_imm = static_cast<uint32_t>(AbsOrMin(imm));
Alexey Frunze7e99e052015-11-24 19:28:01 -08002488 int ctz_imm = CTZ(abs_imm);
2489
2490 if (instruction->IsDiv()) {
2491 if (ctz_imm == 1) {
2492 // Fast path for division by +/-2, which is very common.
2493 __ Srl(TMP, dividend, 31);
2494 } else {
2495 __ Sra(TMP, dividend, 31);
2496 __ Srl(TMP, TMP, 32 - ctz_imm);
2497 }
2498 __ Addu(out, dividend, TMP);
2499 __ Sra(out, out, ctz_imm);
2500 if (imm < 0) {
2501 __ Subu(out, ZERO, out);
2502 }
2503 } else {
2504 if (ctz_imm == 1) {
2505 // Fast path for modulo +/-2, which is very common.
2506 __ Sra(TMP, dividend, 31);
2507 __ Subu(out, dividend, TMP);
2508 __ Andi(out, out, 1);
2509 __ Addu(out, out, TMP);
2510 } else {
2511 __ Sra(TMP, dividend, 31);
2512 __ Srl(TMP, TMP, 32 - ctz_imm);
2513 __ Addu(out, dividend, TMP);
2514 if (IsUint<16>(abs_imm - 1)) {
2515 __ Andi(out, out, abs_imm - 1);
2516 } else {
2517 __ Sll(out, out, 32 - ctz_imm);
2518 __ Srl(out, out, 32 - ctz_imm);
2519 }
2520 __ Subu(out, out, TMP);
2521 }
2522 }
2523}
2524
2525void InstructionCodeGeneratorMIPS::GenerateDivRemWithAnyConstant(HBinaryOperation* instruction) {
2526 DCHECK(instruction->IsDiv() || instruction->IsRem());
2527 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2528
2529 LocationSummary* locations = instruction->GetLocations();
2530 Location second = locations->InAt(1);
2531 DCHECK(second.IsConstant());
2532
2533 Register out = locations->Out().AsRegister<Register>();
2534 Register dividend = locations->InAt(0).AsRegister<Register>();
2535 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2536
2537 int64_t magic;
2538 int shift;
2539 CalculateMagicAndShiftForDivRem(imm, false /* is_long */, &magic, &shift);
2540
2541 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2542
2543 __ LoadConst32(TMP, magic);
2544 if (isR6) {
2545 __ MuhR6(TMP, dividend, TMP);
2546 } else {
2547 __ MultR2(dividend, TMP);
2548 __ Mfhi(TMP);
2549 }
2550 if (imm > 0 && magic < 0) {
2551 __ Addu(TMP, TMP, dividend);
2552 } else if (imm < 0 && magic > 0) {
2553 __ Subu(TMP, TMP, dividend);
2554 }
2555
2556 if (shift != 0) {
2557 __ Sra(TMP, TMP, shift);
2558 }
2559
2560 if (instruction->IsDiv()) {
2561 __ Sra(out, TMP, 31);
2562 __ Subu(out, TMP, out);
2563 } else {
2564 __ Sra(AT, TMP, 31);
2565 __ Subu(AT, TMP, AT);
2566 __ LoadConst32(TMP, imm);
2567 if (isR6) {
2568 __ MulR6(TMP, AT, TMP);
2569 } else {
2570 __ MulR2(TMP, AT, TMP);
2571 }
2572 __ Subu(out, dividend, TMP);
2573 }
2574}
2575
2576void InstructionCodeGeneratorMIPS::GenerateDivRemIntegral(HBinaryOperation* instruction) {
2577 DCHECK(instruction->IsDiv() || instruction->IsRem());
2578 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimInt);
2579
2580 LocationSummary* locations = instruction->GetLocations();
2581 Register out = locations->Out().AsRegister<Register>();
2582 Location second = locations->InAt(1);
2583
2584 if (second.IsConstant()) {
2585 int32_t imm = second.GetConstant()->AsIntConstant()->GetValue();
2586 if (imm == 0) {
2587 // Do not generate anything. DivZeroCheck would prevent any code to be executed.
2588 } else if (imm == 1 || imm == -1) {
2589 DivRemOneOrMinusOne(instruction);
Nicolas Geoffray68f62892016-01-04 08:39:49 +00002590 } else if (IsPowerOfTwo(AbsOrMin(imm))) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002591 DivRemByPowerOfTwo(instruction);
2592 } else {
2593 DCHECK(imm <= -2 || imm >= 2);
2594 GenerateDivRemWithAnyConstant(instruction);
2595 }
2596 } else {
2597 Register dividend = locations->InAt(0).AsRegister<Register>();
2598 Register divisor = second.AsRegister<Register>();
2599 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2600 if (instruction->IsDiv()) {
2601 if (isR6) {
2602 __ DivR6(out, dividend, divisor);
2603 } else {
2604 __ DivR2(out, dividend, divisor);
2605 }
2606 } else {
2607 if (isR6) {
2608 __ ModR6(out, dividend, divisor);
2609 } else {
2610 __ ModR2(out, dividend, divisor);
2611 }
2612 }
2613 }
2614}
2615
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002616void LocationsBuilderMIPS::VisitDiv(HDiv* div) {
2617 Primitive::Type type = div->GetResultType();
2618 LocationSummary::CallKind call_kind = (type == Primitive::kPrimLong)
Serban Constantinescu54ff4822016-07-07 18:03:19 +01002619 ? LocationSummary::kCallOnMainOnly
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002620 : LocationSummary::kNoCall;
2621
2622 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2623
2624 switch (type) {
2625 case Primitive::kPrimInt:
2626 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08002627 locations->SetInAt(1, Location::RegisterOrConstant(div->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002628 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2629 break;
2630
2631 case Primitive::kPrimLong: {
2632 InvokeRuntimeCallingConvention calling_convention;
2633 locations->SetInAt(0, Location::RegisterPairLocation(
2634 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2635 locations->SetInAt(1, Location::RegisterPairLocation(
2636 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2637 locations->SetOut(calling_convention.GetReturnLocation(type));
2638 break;
2639 }
2640
2641 case Primitive::kPrimFloat:
2642 case Primitive::kPrimDouble:
2643 locations->SetInAt(0, Location::RequiresFpuRegister());
2644 locations->SetInAt(1, Location::RequiresFpuRegister());
2645 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2646 break;
2647
2648 default:
2649 LOG(FATAL) << "Unexpected div type " << type;
2650 }
2651}
2652
2653void InstructionCodeGeneratorMIPS::VisitDiv(HDiv* instruction) {
2654 Primitive::Type type = instruction->GetType();
2655 LocationSummary* locations = instruction->GetLocations();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002656
2657 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08002658 case Primitive::kPrimInt:
2659 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002660 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002661 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01002662 codegen_->InvokeRuntime(kQuickLdiv, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002663 CheckEntrypointTypes<kQuickLdiv, int64_t, int64_t, int64_t>();
2664 break;
2665 }
2666 case Primitive::kPrimFloat:
2667 case Primitive::kPrimDouble: {
2668 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
2669 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
2670 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
2671 if (type == Primitive::kPrimFloat) {
2672 __ DivS(dst, lhs, rhs);
2673 } else {
2674 __ DivD(dst, lhs, rhs);
2675 }
2676 break;
2677 }
2678 default:
2679 LOG(FATAL) << "Unexpected div type " << type;
2680 }
2681}
2682
2683void LocationsBuilderMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01002684 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002685 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002686}
2687
2688void InstructionCodeGeneratorMIPS::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2689 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathMIPS(instruction);
2690 codegen_->AddSlowPath(slow_path);
2691 Location value = instruction->GetLocations()->InAt(0);
2692 Primitive::Type type = instruction->GetType();
2693
2694 switch (type) {
Nicolas Geoffraye5671612016-03-16 11:03:54 +00002695 case Primitive::kPrimBoolean:
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02002696 case Primitive::kPrimByte:
2697 case Primitive::kPrimChar:
2698 case Primitive::kPrimShort:
2699 case Primitive::kPrimInt: {
2700 if (value.IsConstant()) {
2701 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2702 __ B(slow_path->GetEntryLabel());
2703 } else {
2704 // A division by a non-null constant is valid. We don't need to perform
2705 // any check, so simply fall through.
2706 }
2707 } else {
2708 DCHECK(value.IsRegister()) << value;
2709 __ Beqz(value.AsRegister<Register>(), slow_path->GetEntryLabel());
2710 }
2711 break;
2712 }
2713 case Primitive::kPrimLong: {
2714 if (value.IsConstant()) {
2715 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2716 __ B(slow_path->GetEntryLabel());
2717 } else {
2718 // A division by a non-null constant is valid. We don't need to perform
2719 // any check, so simply fall through.
2720 }
2721 } else {
2722 DCHECK(value.IsRegisterPair()) << value;
2723 __ Or(TMP, value.AsRegisterPairHigh<Register>(), value.AsRegisterPairLow<Register>());
2724 __ Beqz(TMP, slow_path->GetEntryLabel());
2725 }
2726 break;
2727 }
2728 default:
2729 LOG(FATAL) << "Unexpected type " << type << " for DivZeroCheck.";
2730 }
2731}
2732
2733void LocationsBuilderMIPS::VisitDoubleConstant(HDoubleConstant* constant) {
2734 LocationSummary* locations =
2735 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2736 locations->SetOut(Location::ConstantLocation(constant));
2737}
2738
2739void InstructionCodeGeneratorMIPS::VisitDoubleConstant(HDoubleConstant* cst ATTRIBUTE_UNUSED) {
2740 // Will be generated at use site.
2741}
2742
2743void LocationsBuilderMIPS::VisitExit(HExit* exit) {
2744 exit->SetLocations(nullptr);
2745}
2746
2747void InstructionCodeGeneratorMIPS::VisitExit(HExit* exit ATTRIBUTE_UNUSED) {
2748}
2749
2750void LocationsBuilderMIPS::VisitFloatConstant(HFloatConstant* constant) {
2751 LocationSummary* locations =
2752 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
2753 locations->SetOut(Location::ConstantLocation(constant));
2754}
2755
2756void InstructionCodeGeneratorMIPS::VisitFloatConstant(HFloatConstant* constant ATTRIBUTE_UNUSED) {
2757 // Will be generated at use site.
2758}
2759
2760void LocationsBuilderMIPS::VisitGoto(HGoto* got) {
2761 got->SetLocations(nullptr);
2762}
2763
2764void InstructionCodeGeneratorMIPS::HandleGoto(HInstruction* got, HBasicBlock* successor) {
2765 DCHECK(!successor->IsExitBlock());
2766 HBasicBlock* block = got->GetBlock();
2767 HInstruction* previous = got->GetPrevious();
2768 HLoopInformation* info = block->GetLoopInformation();
2769
2770 if (info != nullptr && info->IsBackEdge(*block) && info->HasSuspendCheck()) {
2771 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
2772 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
2773 return;
2774 }
2775 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
2776 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
2777 }
2778 if (!codegen_->GoesToNextBlock(block, successor)) {
2779 __ B(codegen_->GetLabelOf(successor));
2780 }
2781}
2782
2783void InstructionCodeGeneratorMIPS::VisitGoto(HGoto* got) {
2784 HandleGoto(got, got->GetSuccessor());
2785}
2786
2787void LocationsBuilderMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2788 try_boundary->SetLocations(nullptr);
2789}
2790
2791void InstructionCodeGeneratorMIPS::VisitTryBoundary(HTryBoundary* try_boundary) {
2792 HBasicBlock* successor = try_boundary->GetNormalFlowSuccessor();
2793 if (!successor->IsExitBlock()) {
2794 HandleGoto(try_boundary, successor);
2795 }
2796}
2797
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002798void InstructionCodeGeneratorMIPS::GenerateIntCompare(IfCondition cond,
2799 LocationSummary* locations) {
2800 Register dst = locations->Out().AsRegister<Register>();
2801 Register lhs = locations->InAt(0).AsRegister<Register>();
2802 Location rhs_location = locations->InAt(1);
2803 Register rhs_reg = ZERO;
2804 int64_t rhs_imm = 0;
2805 bool use_imm = rhs_location.IsConstant();
2806 if (use_imm) {
2807 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2808 } else {
2809 rhs_reg = rhs_location.AsRegister<Register>();
2810 }
2811
2812 switch (cond) {
2813 case kCondEQ:
2814 case kCondNE:
Alexey Frunzee7697712016-09-15 21:37:49 -07002815 if (use_imm && IsInt<16>(-rhs_imm)) {
2816 if (rhs_imm == 0) {
2817 if (cond == kCondEQ) {
2818 __ Sltiu(dst, lhs, 1);
2819 } else {
2820 __ Sltu(dst, ZERO, lhs);
2821 }
2822 } else {
2823 __ Addiu(dst, lhs, -rhs_imm);
2824 if (cond == kCondEQ) {
2825 __ Sltiu(dst, dst, 1);
2826 } else {
2827 __ Sltu(dst, ZERO, dst);
2828 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002829 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002830 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07002831 if (use_imm && IsUint<16>(rhs_imm)) {
2832 __ Xori(dst, lhs, rhs_imm);
2833 } else {
2834 if (use_imm) {
2835 rhs_reg = TMP;
2836 __ LoadConst32(rhs_reg, rhs_imm);
2837 }
2838 __ Xor(dst, lhs, rhs_reg);
2839 }
2840 if (cond == kCondEQ) {
2841 __ Sltiu(dst, dst, 1);
2842 } else {
2843 __ Sltu(dst, ZERO, dst);
2844 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002845 }
2846 break;
2847
2848 case kCondLT:
2849 case kCondGE:
2850 if (use_imm && IsInt<16>(rhs_imm)) {
2851 __ Slti(dst, lhs, rhs_imm);
2852 } else {
2853 if (use_imm) {
2854 rhs_reg = TMP;
2855 __ LoadConst32(rhs_reg, rhs_imm);
2856 }
2857 __ Slt(dst, lhs, rhs_reg);
2858 }
2859 if (cond == kCondGE) {
2860 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2861 // only the slt instruction but no sge.
2862 __ Xori(dst, dst, 1);
2863 }
2864 break;
2865
2866 case kCondLE:
2867 case kCondGT:
2868 if (use_imm && IsInt<16>(rhs_imm + 1)) {
2869 // Simulate lhs <= rhs via lhs < rhs + 1.
2870 __ Slti(dst, lhs, rhs_imm + 1);
2871 if (cond == kCondGT) {
2872 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2873 // only the slti instruction but no sgti.
2874 __ Xori(dst, dst, 1);
2875 }
2876 } else {
2877 if (use_imm) {
2878 rhs_reg = TMP;
2879 __ LoadConst32(rhs_reg, rhs_imm);
2880 }
2881 __ Slt(dst, rhs_reg, lhs);
2882 if (cond == kCondLE) {
2883 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2884 // only the slt instruction but no sle.
2885 __ Xori(dst, dst, 1);
2886 }
2887 }
2888 break;
2889
2890 case kCondB:
2891 case kCondAE:
2892 if (use_imm && IsInt<16>(rhs_imm)) {
2893 // Sltiu sign-extends its 16-bit immediate operand before
2894 // the comparison and thus lets us compare directly with
2895 // unsigned values in the ranges [0, 0x7fff] and
2896 // [0xffff8000, 0xffffffff].
2897 __ Sltiu(dst, lhs, rhs_imm);
2898 } else {
2899 if (use_imm) {
2900 rhs_reg = TMP;
2901 __ LoadConst32(rhs_reg, rhs_imm);
2902 }
2903 __ Sltu(dst, lhs, rhs_reg);
2904 }
2905 if (cond == kCondAE) {
2906 // Simulate lhs >= rhs via !(lhs < rhs) since there's
2907 // only the sltu instruction but no sgeu.
2908 __ Xori(dst, dst, 1);
2909 }
2910 break;
2911
2912 case kCondBE:
2913 case kCondA:
2914 if (use_imm && (rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
2915 // Simulate lhs <= rhs via lhs < rhs + 1.
2916 // Note that this only works if rhs + 1 does not overflow
2917 // to 0, hence the check above.
2918 // Sltiu sign-extends its 16-bit immediate operand before
2919 // the comparison and thus lets us compare directly with
2920 // unsigned values in the ranges [0, 0x7fff] and
2921 // [0xffff8000, 0xffffffff].
2922 __ Sltiu(dst, lhs, rhs_imm + 1);
2923 if (cond == kCondA) {
2924 // Simulate lhs > rhs via !(lhs <= rhs) since there's
2925 // only the sltiu instruction but no sgtiu.
2926 __ Xori(dst, dst, 1);
2927 }
2928 } else {
2929 if (use_imm) {
2930 rhs_reg = TMP;
2931 __ LoadConst32(rhs_reg, rhs_imm);
2932 }
2933 __ Sltu(dst, rhs_reg, lhs);
2934 if (cond == kCondBE) {
2935 // Simulate lhs <= rhs via !(rhs < lhs) since there's
2936 // only the sltu instruction but no sleu.
2937 __ Xori(dst, dst, 1);
2938 }
2939 }
2940 break;
2941 }
2942}
2943
2944void InstructionCodeGeneratorMIPS::GenerateIntCompareAndBranch(IfCondition cond,
2945 LocationSummary* locations,
2946 MipsLabel* label) {
2947 Register lhs = locations->InAt(0).AsRegister<Register>();
2948 Location rhs_location = locations->InAt(1);
2949 Register rhs_reg = ZERO;
Alexey Frunzee7697712016-09-15 21:37:49 -07002950 int64_t rhs_imm = 0;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08002951 bool use_imm = rhs_location.IsConstant();
2952 if (use_imm) {
2953 rhs_imm = CodeGenerator::GetInt32ValueOf(rhs_location.GetConstant());
2954 } else {
2955 rhs_reg = rhs_location.AsRegister<Register>();
2956 }
2957
2958 if (use_imm && rhs_imm == 0) {
2959 switch (cond) {
2960 case kCondEQ:
2961 case kCondBE: // <= 0 if zero
2962 __ Beqz(lhs, label);
2963 break;
2964 case kCondNE:
2965 case kCondA: // > 0 if non-zero
2966 __ Bnez(lhs, label);
2967 break;
2968 case kCondLT:
2969 __ Bltz(lhs, label);
2970 break;
2971 case kCondGE:
2972 __ Bgez(lhs, label);
2973 break;
2974 case kCondLE:
2975 __ Blez(lhs, label);
2976 break;
2977 case kCondGT:
2978 __ Bgtz(lhs, label);
2979 break;
2980 case kCondB: // always false
2981 break;
2982 case kCondAE: // always true
2983 __ B(label);
2984 break;
2985 }
2986 } else {
Alexey Frunzee7697712016-09-15 21:37:49 -07002987 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
2988 if (isR6 || !use_imm) {
2989 if (use_imm) {
2990 rhs_reg = TMP;
2991 __ LoadConst32(rhs_reg, rhs_imm);
2992 }
2993 switch (cond) {
2994 case kCondEQ:
2995 __ Beq(lhs, rhs_reg, label);
2996 break;
2997 case kCondNE:
2998 __ Bne(lhs, rhs_reg, label);
2999 break;
3000 case kCondLT:
3001 __ Blt(lhs, rhs_reg, label);
3002 break;
3003 case kCondGE:
3004 __ Bge(lhs, rhs_reg, label);
3005 break;
3006 case kCondLE:
3007 __ Bge(rhs_reg, lhs, label);
3008 break;
3009 case kCondGT:
3010 __ Blt(rhs_reg, lhs, label);
3011 break;
3012 case kCondB:
3013 __ Bltu(lhs, rhs_reg, label);
3014 break;
3015 case kCondAE:
3016 __ Bgeu(lhs, rhs_reg, label);
3017 break;
3018 case kCondBE:
3019 __ Bgeu(rhs_reg, lhs, label);
3020 break;
3021 case kCondA:
3022 __ Bltu(rhs_reg, lhs, label);
3023 break;
3024 }
3025 } else {
3026 // Special cases for more efficient comparison with constants on R2.
3027 switch (cond) {
3028 case kCondEQ:
3029 __ LoadConst32(TMP, rhs_imm);
3030 __ Beq(lhs, TMP, label);
3031 break;
3032 case kCondNE:
3033 __ LoadConst32(TMP, rhs_imm);
3034 __ Bne(lhs, TMP, label);
3035 break;
3036 case kCondLT:
3037 if (IsInt<16>(rhs_imm)) {
3038 __ Slti(TMP, lhs, rhs_imm);
3039 __ Bnez(TMP, label);
3040 } else {
3041 __ LoadConst32(TMP, rhs_imm);
3042 __ Blt(lhs, TMP, label);
3043 }
3044 break;
3045 case kCondGE:
3046 if (IsInt<16>(rhs_imm)) {
3047 __ Slti(TMP, lhs, rhs_imm);
3048 __ Beqz(TMP, label);
3049 } else {
3050 __ LoadConst32(TMP, rhs_imm);
3051 __ Bge(lhs, TMP, label);
3052 }
3053 break;
3054 case kCondLE:
3055 if (IsInt<16>(rhs_imm + 1)) {
3056 // Simulate lhs <= rhs via lhs < rhs + 1.
3057 __ Slti(TMP, lhs, rhs_imm + 1);
3058 __ Bnez(TMP, label);
3059 } else {
3060 __ LoadConst32(TMP, rhs_imm);
3061 __ Bge(TMP, lhs, label);
3062 }
3063 break;
3064 case kCondGT:
3065 if (IsInt<16>(rhs_imm + 1)) {
3066 // Simulate lhs > rhs via !(lhs < rhs + 1).
3067 __ Slti(TMP, lhs, rhs_imm + 1);
3068 __ Beqz(TMP, label);
3069 } else {
3070 __ LoadConst32(TMP, rhs_imm);
3071 __ Blt(TMP, lhs, label);
3072 }
3073 break;
3074 case kCondB:
3075 if (IsInt<16>(rhs_imm)) {
3076 __ Sltiu(TMP, lhs, rhs_imm);
3077 __ Bnez(TMP, label);
3078 } else {
3079 __ LoadConst32(TMP, rhs_imm);
3080 __ Bltu(lhs, TMP, label);
3081 }
3082 break;
3083 case kCondAE:
3084 if (IsInt<16>(rhs_imm)) {
3085 __ Sltiu(TMP, lhs, rhs_imm);
3086 __ Beqz(TMP, label);
3087 } else {
3088 __ LoadConst32(TMP, rhs_imm);
3089 __ Bgeu(lhs, TMP, label);
3090 }
3091 break;
3092 case kCondBE:
3093 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
3094 // Simulate lhs <= rhs via lhs < rhs + 1.
3095 // Note that this only works if rhs + 1 does not overflow
3096 // to 0, hence the check above.
3097 __ Sltiu(TMP, lhs, rhs_imm + 1);
3098 __ Bnez(TMP, label);
3099 } else {
3100 __ LoadConst32(TMP, rhs_imm);
3101 __ Bgeu(TMP, lhs, label);
3102 }
3103 break;
3104 case kCondA:
3105 if ((rhs_imm != -1) && IsInt<16>(rhs_imm + 1)) {
3106 // Simulate lhs > rhs via !(lhs < rhs + 1).
3107 // Note that this only works if rhs + 1 does not overflow
3108 // to 0, hence the check above.
3109 __ Sltiu(TMP, lhs, rhs_imm + 1);
3110 __ Beqz(TMP, label);
3111 } else {
3112 __ LoadConst32(TMP, rhs_imm);
3113 __ Bltu(TMP, lhs, label);
3114 }
3115 break;
3116 }
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003117 }
3118 }
3119}
3120
3121void InstructionCodeGeneratorMIPS::GenerateLongCompareAndBranch(IfCondition cond,
3122 LocationSummary* locations,
3123 MipsLabel* label) {
3124 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
3125 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
3126 Location rhs_location = locations->InAt(1);
3127 Register rhs_high = ZERO;
3128 Register rhs_low = ZERO;
3129 int64_t imm = 0;
3130 uint32_t imm_high = 0;
3131 uint32_t imm_low = 0;
3132 bool use_imm = rhs_location.IsConstant();
3133 if (use_imm) {
3134 imm = rhs_location.GetConstant()->AsLongConstant()->GetValue();
3135 imm_high = High32Bits(imm);
3136 imm_low = Low32Bits(imm);
3137 } else {
3138 rhs_high = rhs_location.AsRegisterPairHigh<Register>();
3139 rhs_low = rhs_location.AsRegisterPairLow<Register>();
3140 }
3141
3142 if (use_imm && imm == 0) {
3143 switch (cond) {
3144 case kCondEQ:
3145 case kCondBE: // <= 0 if zero
3146 __ Or(TMP, lhs_high, lhs_low);
3147 __ Beqz(TMP, label);
3148 break;
3149 case kCondNE:
3150 case kCondA: // > 0 if non-zero
3151 __ Or(TMP, lhs_high, lhs_low);
3152 __ Bnez(TMP, label);
3153 break;
3154 case kCondLT:
3155 __ Bltz(lhs_high, label);
3156 break;
3157 case kCondGE:
3158 __ Bgez(lhs_high, label);
3159 break;
3160 case kCondLE:
3161 __ Or(TMP, lhs_high, lhs_low);
3162 __ Sra(AT, lhs_high, 31);
3163 __ Bgeu(AT, TMP, label);
3164 break;
3165 case kCondGT:
3166 __ Or(TMP, lhs_high, lhs_low);
3167 __ Sra(AT, lhs_high, 31);
3168 __ Bltu(AT, TMP, label);
3169 break;
3170 case kCondB: // always false
3171 break;
3172 case kCondAE: // always true
3173 __ B(label);
3174 break;
3175 }
3176 } else if (use_imm) {
3177 // TODO: more efficient comparison with constants without loading them into TMP/AT.
3178 switch (cond) {
3179 case kCondEQ:
3180 __ LoadConst32(TMP, imm_high);
3181 __ Xor(TMP, TMP, lhs_high);
3182 __ LoadConst32(AT, imm_low);
3183 __ Xor(AT, AT, lhs_low);
3184 __ Or(TMP, TMP, AT);
3185 __ Beqz(TMP, label);
3186 break;
3187 case kCondNE:
3188 __ LoadConst32(TMP, imm_high);
3189 __ Xor(TMP, TMP, lhs_high);
3190 __ LoadConst32(AT, imm_low);
3191 __ Xor(AT, AT, lhs_low);
3192 __ Or(TMP, TMP, AT);
3193 __ Bnez(TMP, label);
3194 break;
3195 case kCondLT:
3196 __ LoadConst32(TMP, imm_high);
3197 __ Blt(lhs_high, TMP, label);
3198 __ Slt(TMP, TMP, lhs_high);
3199 __ LoadConst32(AT, imm_low);
3200 __ Sltu(AT, lhs_low, AT);
3201 __ Blt(TMP, AT, label);
3202 break;
3203 case kCondGE:
3204 __ LoadConst32(TMP, imm_high);
3205 __ Blt(TMP, lhs_high, label);
3206 __ Slt(TMP, lhs_high, TMP);
3207 __ LoadConst32(AT, imm_low);
3208 __ Sltu(AT, lhs_low, AT);
3209 __ Or(TMP, TMP, AT);
3210 __ Beqz(TMP, label);
3211 break;
3212 case kCondLE:
3213 __ LoadConst32(TMP, imm_high);
3214 __ Blt(lhs_high, TMP, label);
3215 __ Slt(TMP, TMP, lhs_high);
3216 __ LoadConst32(AT, imm_low);
3217 __ Sltu(AT, AT, lhs_low);
3218 __ Or(TMP, TMP, AT);
3219 __ Beqz(TMP, label);
3220 break;
3221 case kCondGT:
3222 __ LoadConst32(TMP, imm_high);
3223 __ Blt(TMP, lhs_high, label);
3224 __ Slt(TMP, lhs_high, TMP);
3225 __ LoadConst32(AT, imm_low);
3226 __ Sltu(AT, AT, lhs_low);
3227 __ Blt(TMP, AT, label);
3228 break;
3229 case kCondB:
3230 __ LoadConst32(TMP, imm_high);
3231 __ Bltu(lhs_high, TMP, label);
3232 __ Sltu(TMP, TMP, lhs_high);
3233 __ LoadConst32(AT, imm_low);
3234 __ Sltu(AT, lhs_low, AT);
3235 __ Blt(TMP, AT, label);
3236 break;
3237 case kCondAE:
3238 __ LoadConst32(TMP, imm_high);
3239 __ Bltu(TMP, lhs_high, label);
3240 __ Sltu(TMP, lhs_high, TMP);
3241 __ LoadConst32(AT, imm_low);
3242 __ Sltu(AT, lhs_low, AT);
3243 __ Or(TMP, TMP, AT);
3244 __ Beqz(TMP, label);
3245 break;
3246 case kCondBE:
3247 __ LoadConst32(TMP, imm_high);
3248 __ Bltu(lhs_high, TMP, label);
3249 __ Sltu(TMP, TMP, lhs_high);
3250 __ LoadConst32(AT, imm_low);
3251 __ Sltu(AT, AT, lhs_low);
3252 __ Or(TMP, TMP, AT);
3253 __ Beqz(TMP, label);
3254 break;
3255 case kCondA:
3256 __ LoadConst32(TMP, imm_high);
3257 __ Bltu(TMP, lhs_high, label);
3258 __ Sltu(TMP, lhs_high, TMP);
3259 __ LoadConst32(AT, imm_low);
3260 __ Sltu(AT, AT, lhs_low);
3261 __ Blt(TMP, AT, label);
3262 break;
3263 }
3264 } else {
3265 switch (cond) {
3266 case kCondEQ:
3267 __ Xor(TMP, lhs_high, rhs_high);
3268 __ Xor(AT, lhs_low, rhs_low);
3269 __ Or(TMP, TMP, AT);
3270 __ Beqz(TMP, label);
3271 break;
3272 case kCondNE:
3273 __ Xor(TMP, lhs_high, rhs_high);
3274 __ Xor(AT, lhs_low, rhs_low);
3275 __ Or(TMP, TMP, AT);
3276 __ Bnez(TMP, label);
3277 break;
3278 case kCondLT:
3279 __ Blt(lhs_high, rhs_high, label);
3280 __ Slt(TMP, rhs_high, lhs_high);
3281 __ Sltu(AT, lhs_low, rhs_low);
3282 __ Blt(TMP, AT, label);
3283 break;
3284 case kCondGE:
3285 __ Blt(rhs_high, lhs_high, label);
3286 __ Slt(TMP, lhs_high, rhs_high);
3287 __ Sltu(AT, lhs_low, rhs_low);
3288 __ Or(TMP, TMP, AT);
3289 __ Beqz(TMP, label);
3290 break;
3291 case kCondLE:
3292 __ Blt(lhs_high, rhs_high, label);
3293 __ Slt(TMP, rhs_high, lhs_high);
3294 __ Sltu(AT, rhs_low, lhs_low);
3295 __ Or(TMP, TMP, AT);
3296 __ Beqz(TMP, label);
3297 break;
3298 case kCondGT:
3299 __ Blt(rhs_high, lhs_high, label);
3300 __ Slt(TMP, lhs_high, rhs_high);
3301 __ Sltu(AT, rhs_low, lhs_low);
3302 __ Blt(TMP, AT, label);
3303 break;
3304 case kCondB:
3305 __ Bltu(lhs_high, rhs_high, label);
3306 __ Sltu(TMP, rhs_high, lhs_high);
3307 __ Sltu(AT, lhs_low, rhs_low);
3308 __ Blt(TMP, AT, label);
3309 break;
3310 case kCondAE:
3311 __ Bltu(rhs_high, lhs_high, label);
3312 __ Sltu(TMP, lhs_high, rhs_high);
3313 __ Sltu(AT, lhs_low, rhs_low);
3314 __ Or(TMP, TMP, AT);
3315 __ Beqz(TMP, label);
3316 break;
3317 case kCondBE:
3318 __ Bltu(lhs_high, rhs_high, label);
3319 __ Sltu(TMP, rhs_high, lhs_high);
3320 __ Sltu(AT, rhs_low, lhs_low);
3321 __ Or(TMP, TMP, AT);
3322 __ Beqz(TMP, label);
3323 break;
3324 case kCondA:
3325 __ Bltu(rhs_high, lhs_high, label);
3326 __ Sltu(TMP, lhs_high, rhs_high);
3327 __ Sltu(AT, rhs_low, lhs_low);
3328 __ Blt(TMP, AT, label);
3329 break;
3330 }
3331 }
3332}
3333
Alexey Frunze2ddb7172016-09-06 17:04:55 -07003334void InstructionCodeGeneratorMIPS::GenerateFpCompare(IfCondition cond,
3335 bool gt_bias,
3336 Primitive::Type type,
3337 LocationSummary* locations) {
3338 Register dst = locations->Out().AsRegister<Register>();
3339 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3340 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3341 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3342 if (type == Primitive::kPrimFloat) {
3343 if (isR6) {
3344 switch (cond) {
3345 case kCondEQ:
3346 __ CmpEqS(FTMP, lhs, rhs);
3347 __ Mfc1(dst, FTMP);
3348 __ Andi(dst, dst, 1);
3349 break;
3350 case kCondNE:
3351 __ CmpEqS(FTMP, lhs, rhs);
3352 __ Mfc1(dst, FTMP);
3353 __ Addiu(dst, dst, 1);
3354 break;
3355 case kCondLT:
3356 if (gt_bias) {
3357 __ CmpLtS(FTMP, lhs, rhs);
3358 } else {
3359 __ CmpUltS(FTMP, lhs, rhs);
3360 }
3361 __ Mfc1(dst, FTMP);
3362 __ Andi(dst, dst, 1);
3363 break;
3364 case kCondLE:
3365 if (gt_bias) {
3366 __ CmpLeS(FTMP, lhs, rhs);
3367 } else {
3368 __ CmpUleS(FTMP, lhs, rhs);
3369 }
3370 __ Mfc1(dst, FTMP);
3371 __ Andi(dst, dst, 1);
3372 break;
3373 case kCondGT:
3374 if (gt_bias) {
3375 __ CmpUltS(FTMP, rhs, lhs);
3376 } else {
3377 __ CmpLtS(FTMP, rhs, lhs);
3378 }
3379 __ Mfc1(dst, FTMP);
3380 __ Andi(dst, dst, 1);
3381 break;
3382 case kCondGE:
3383 if (gt_bias) {
3384 __ CmpUleS(FTMP, rhs, lhs);
3385 } else {
3386 __ CmpLeS(FTMP, rhs, lhs);
3387 }
3388 __ Mfc1(dst, FTMP);
3389 __ Andi(dst, dst, 1);
3390 break;
3391 default:
3392 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3393 UNREACHABLE();
3394 }
3395 } else {
3396 switch (cond) {
3397 case kCondEQ:
3398 __ CeqS(0, lhs, rhs);
3399 __ LoadConst32(dst, 1);
3400 __ Movf(dst, ZERO, 0);
3401 break;
3402 case kCondNE:
3403 __ CeqS(0, lhs, rhs);
3404 __ LoadConst32(dst, 1);
3405 __ Movt(dst, ZERO, 0);
3406 break;
3407 case kCondLT:
3408 if (gt_bias) {
3409 __ ColtS(0, lhs, rhs);
3410 } else {
3411 __ CultS(0, lhs, rhs);
3412 }
3413 __ LoadConst32(dst, 1);
3414 __ Movf(dst, ZERO, 0);
3415 break;
3416 case kCondLE:
3417 if (gt_bias) {
3418 __ ColeS(0, lhs, rhs);
3419 } else {
3420 __ CuleS(0, lhs, rhs);
3421 }
3422 __ LoadConst32(dst, 1);
3423 __ Movf(dst, ZERO, 0);
3424 break;
3425 case kCondGT:
3426 if (gt_bias) {
3427 __ CultS(0, rhs, lhs);
3428 } else {
3429 __ ColtS(0, rhs, lhs);
3430 }
3431 __ LoadConst32(dst, 1);
3432 __ Movf(dst, ZERO, 0);
3433 break;
3434 case kCondGE:
3435 if (gt_bias) {
3436 __ CuleS(0, rhs, lhs);
3437 } else {
3438 __ ColeS(0, rhs, lhs);
3439 }
3440 __ LoadConst32(dst, 1);
3441 __ Movf(dst, ZERO, 0);
3442 break;
3443 default:
3444 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3445 UNREACHABLE();
3446 }
3447 }
3448 } else {
3449 DCHECK_EQ(type, Primitive::kPrimDouble);
3450 if (isR6) {
3451 switch (cond) {
3452 case kCondEQ:
3453 __ CmpEqD(FTMP, lhs, rhs);
3454 __ Mfc1(dst, FTMP);
3455 __ Andi(dst, dst, 1);
3456 break;
3457 case kCondNE:
3458 __ CmpEqD(FTMP, lhs, rhs);
3459 __ Mfc1(dst, FTMP);
3460 __ Addiu(dst, dst, 1);
3461 break;
3462 case kCondLT:
3463 if (gt_bias) {
3464 __ CmpLtD(FTMP, lhs, rhs);
3465 } else {
3466 __ CmpUltD(FTMP, lhs, rhs);
3467 }
3468 __ Mfc1(dst, FTMP);
3469 __ Andi(dst, dst, 1);
3470 break;
3471 case kCondLE:
3472 if (gt_bias) {
3473 __ CmpLeD(FTMP, lhs, rhs);
3474 } else {
3475 __ CmpUleD(FTMP, lhs, rhs);
3476 }
3477 __ Mfc1(dst, FTMP);
3478 __ Andi(dst, dst, 1);
3479 break;
3480 case kCondGT:
3481 if (gt_bias) {
3482 __ CmpUltD(FTMP, rhs, lhs);
3483 } else {
3484 __ CmpLtD(FTMP, rhs, lhs);
3485 }
3486 __ Mfc1(dst, FTMP);
3487 __ Andi(dst, dst, 1);
3488 break;
3489 case kCondGE:
3490 if (gt_bias) {
3491 __ CmpUleD(FTMP, rhs, lhs);
3492 } else {
3493 __ CmpLeD(FTMP, rhs, lhs);
3494 }
3495 __ Mfc1(dst, FTMP);
3496 __ Andi(dst, dst, 1);
3497 break;
3498 default:
3499 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3500 UNREACHABLE();
3501 }
3502 } else {
3503 switch (cond) {
3504 case kCondEQ:
3505 __ CeqD(0, lhs, rhs);
3506 __ LoadConst32(dst, 1);
3507 __ Movf(dst, ZERO, 0);
3508 break;
3509 case kCondNE:
3510 __ CeqD(0, lhs, rhs);
3511 __ LoadConst32(dst, 1);
3512 __ Movt(dst, ZERO, 0);
3513 break;
3514 case kCondLT:
3515 if (gt_bias) {
3516 __ ColtD(0, lhs, rhs);
3517 } else {
3518 __ CultD(0, lhs, rhs);
3519 }
3520 __ LoadConst32(dst, 1);
3521 __ Movf(dst, ZERO, 0);
3522 break;
3523 case kCondLE:
3524 if (gt_bias) {
3525 __ ColeD(0, lhs, rhs);
3526 } else {
3527 __ CuleD(0, lhs, rhs);
3528 }
3529 __ LoadConst32(dst, 1);
3530 __ Movf(dst, ZERO, 0);
3531 break;
3532 case kCondGT:
3533 if (gt_bias) {
3534 __ CultD(0, rhs, lhs);
3535 } else {
3536 __ ColtD(0, rhs, lhs);
3537 }
3538 __ LoadConst32(dst, 1);
3539 __ Movf(dst, ZERO, 0);
3540 break;
3541 case kCondGE:
3542 if (gt_bias) {
3543 __ CuleD(0, rhs, lhs);
3544 } else {
3545 __ ColeD(0, rhs, lhs);
3546 }
3547 __ LoadConst32(dst, 1);
3548 __ Movf(dst, ZERO, 0);
3549 break;
3550 default:
3551 LOG(FATAL) << "Unexpected non-floating-point condition " << cond;
3552 UNREACHABLE();
3553 }
3554 }
3555 }
3556}
3557
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003558void InstructionCodeGeneratorMIPS::GenerateFpCompareAndBranch(IfCondition cond,
3559 bool gt_bias,
3560 Primitive::Type type,
3561 LocationSummary* locations,
3562 MipsLabel* label) {
3563 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
3564 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
3565 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
3566 if (type == Primitive::kPrimFloat) {
3567 if (isR6) {
3568 switch (cond) {
3569 case kCondEQ:
3570 __ CmpEqS(FTMP, lhs, rhs);
3571 __ Bc1nez(FTMP, label);
3572 break;
3573 case kCondNE:
3574 __ CmpEqS(FTMP, lhs, rhs);
3575 __ Bc1eqz(FTMP, label);
3576 break;
3577 case kCondLT:
3578 if (gt_bias) {
3579 __ CmpLtS(FTMP, lhs, rhs);
3580 } else {
3581 __ CmpUltS(FTMP, lhs, rhs);
3582 }
3583 __ Bc1nez(FTMP, label);
3584 break;
3585 case kCondLE:
3586 if (gt_bias) {
3587 __ CmpLeS(FTMP, lhs, rhs);
3588 } else {
3589 __ CmpUleS(FTMP, lhs, rhs);
3590 }
3591 __ Bc1nez(FTMP, label);
3592 break;
3593 case kCondGT:
3594 if (gt_bias) {
3595 __ CmpUltS(FTMP, rhs, lhs);
3596 } else {
3597 __ CmpLtS(FTMP, rhs, lhs);
3598 }
3599 __ Bc1nez(FTMP, label);
3600 break;
3601 case kCondGE:
3602 if (gt_bias) {
3603 __ CmpUleS(FTMP, rhs, lhs);
3604 } else {
3605 __ CmpLeS(FTMP, rhs, lhs);
3606 }
3607 __ Bc1nez(FTMP, label);
3608 break;
3609 default:
3610 LOG(FATAL) << "Unexpected non-floating-point condition";
3611 }
3612 } else {
3613 switch (cond) {
3614 case kCondEQ:
3615 __ CeqS(0, lhs, rhs);
3616 __ Bc1t(0, label);
3617 break;
3618 case kCondNE:
3619 __ CeqS(0, lhs, rhs);
3620 __ Bc1f(0, label);
3621 break;
3622 case kCondLT:
3623 if (gt_bias) {
3624 __ ColtS(0, lhs, rhs);
3625 } else {
3626 __ CultS(0, lhs, rhs);
3627 }
3628 __ Bc1t(0, label);
3629 break;
3630 case kCondLE:
3631 if (gt_bias) {
3632 __ ColeS(0, lhs, rhs);
3633 } else {
3634 __ CuleS(0, lhs, rhs);
3635 }
3636 __ Bc1t(0, label);
3637 break;
3638 case kCondGT:
3639 if (gt_bias) {
3640 __ CultS(0, rhs, lhs);
3641 } else {
3642 __ ColtS(0, rhs, lhs);
3643 }
3644 __ Bc1t(0, label);
3645 break;
3646 case kCondGE:
3647 if (gt_bias) {
3648 __ CuleS(0, rhs, lhs);
3649 } else {
3650 __ ColeS(0, rhs, lhs);
3651 }
3652 __ Bc1t(0, label);
3653 break;
3654 default:
3655 LOG(FATAL) << "Unexpected non-floating-point condition";
3656 }
3657 }
3658 } else {
3659 DCHECK_EQ(type, Primitive::kPrimDouble);
3660 if (isR6) {
3661 switch (cond) {
3662 case kCondEQ:
3663 __ CmpEqD(FTMP, lhs, rhs);
3664 __ Bc1nez(FTMP, label);
3665 break;
3666 case kCondNE:
3667 __ CmpEqD(FTMP, lhs, rhs);
3668 __ Bc1eqz(FTMP, label);
3669 break;
3670 case kCondLT:
3671 if (gt_bias) {
3672 __ CmpLtD(FTMP, lhs, rhs);
3673 } else {
3674 __ CmpUltD(FTMP, lhs, rhs);
3675 }
3676 __ Bc1nez(FTMP, label);
3677 break;
3678 case kCondLE:
3679 if (gt_bias) {
3680 __ CmpLeD(FTMP, lhs, rhs);
3681 } else {
3682 __ CmpUleD(FTMP, lhs, rhs);
3683 }
3684 __ Bc1nez(FTMP, label);
3685 break;
3686 case kCondGT:
3687 if (gt_bias) {
3688 __ CmpUltD(FTMP, rhs, lhs);
3689 } else {
3690 __ CmpLtD(FTMP, rhs, lhs);
3691 }
3692 __ Bc1nez(FTMP, label);
3693 break;
3694 case kCondGE:
3695 if (gt_bias) {
3696 __ CmpUleD(FTMP, rhs, lhs);
3697 } else {
3698 __ CmpLeD(FTMP, rhs, lhs);
3699 }
3700 __ Bc1nez(FTMP, label);
3701 break;
3702 default:
3703 LOG(FATAL) << "Unexpected non-floating-point condition";
3704 }
3705 } else {
3706 switch (cond) {
3707 case kCondEQ:
3708 __ CeqD(0, lhs, rhs);
3709 __ Bc1t(0, label);
3710 break;
3711 case kCondNE:
3712 __ CeqD(0, lhs, rhs);
3713 __ Bc1f(0, label);
3714 break;
3715 case kCondLT:
3716 if (gt_bias) {
3717 __ ColtD(0, lhs, rhs);
3718 } else {
3719 __ CultD(0, lhs, rhs);
3720 }
3721 __ Bc1t(0, label);
3722 break;
3723 case kCondLE:
3724 if (gt_bias) {
3725 __ ColeD(0, lhs, rhs);
3726 } else {
3727 __ CuleD(0, lhs, rhs);
3728 }
3729 __ Bc1t(0, label);
3730 break;
3731 case kCondGT:
3732 if (gt_bias) {
3733 __ CultD(0, rhs, lhs);
3734 } else {
3735 __ ColtD(0, rhs, lhs);
3736 }
3737 __ Bc1t(0, label);
3738 break;
3739 case kCondGE:
3740 if (gt_bias) {
3741 __ CuleD(0, rhs, lhs);
3742 } else {
3743 __ ColeD(0, rhs, lhs);
3744 }
3745 __ Bc1t(0, label);
3746 break;
3747 default:
3748 LOG(FATAL) << "Unexpected non-floating-point condition";
3749 }
3750 }
3751 }
3752}
3753
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003754void InstructionCodeGeneratorMIPS::GenerateTestAndBranch(HInstruction* instruction,
David Brazdil0debae72015-11-12 18:37:00 +00003755 size_t condition_input_index,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003756 MipsLabel* true_target,
David Brazdil0debae72015-11-12 18:37:00 +00003757 MipsLabel* false_target) {
3758 HInstruction* cond = instruction->InputAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003759
David Brazdil0debae72015-11-12 18:37:00 +00003760 if (true_target == nullptr && false_target == nullptr) {
3761 // Nothing to do. The code always falls through.
3762 return;
3763 } else if (cond->IsIntConstant()) {
Roland Levillain1a653882016-03-18 18:05:57 +00003764 // Constant condition, statically compared against "true" (integer value 1).
3765 if (cond->AsIntConstant()->IsTrue()) {
David Brazdil0debae72015-11-12 18:37:00 +00003766 if (true_target != nullptr) {
3767 __ B(true_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003768 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003769 } else {
Roland Levillain1a653882016-03-18 18:05:57 +00003770 DCHECK(cond->AsIntConstant()->IsFalse()) << cond->AsIntConstant()->GetValue();
David Brazdil0debae72015-11-12 18:37:00 +00003771 if (false_target != nullptr) {
3772 __ B(false_target);
3773 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003774 }
David Brazdil0debae72015-11-12 18:37:00 +00003775 return;
3776 }
3777
3778 // The following code generates these patterns:
3779 // (1) true_target == nullptr && false_target != nullptr
3780 // - opposite condition true => branch to false_target
3781 // (2) true_target != nullptr && false_target == nullptr
3782 // - condition true => branch to true_target
3783 // (3) true_target != nullptr && false_target != nullptr
3784 // - condition true => branch to true_target
3785 // - branch to false_target
3786 if (IsBooleanValueOrMaterializedCondition(cond)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003787 // The condition instruction has been materialized, compare the output to 0.
David Brazdil0debae72015-11-12 18:37:00 +00003788 Location cond_val = instruction->GetLocations()->InAt(condition_input_index);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003789 DCHECK(cond_val.IsRegister());
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003790 if (true_target == nullptr) {
David Brazdil0debae72015-11-12 18:37:00 +00003791 __ Beqz(cond_val.AsRegister<Register>(), false_target);
3792 } else {
3793 __ Bnez(cond_val.AsRegister<Register>(), true_target);
3794 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003795 } else {
3796 // The condition instruction has not been materialized, use its inputs as
3797 // the comparison and its condition as the branch condition.
David Brazdil0debae72015-11-12 18:37:00 +00003798 HCondition* condition = cond->AsCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003799 Primitive::Type type = condition->InputAt(0)->GetType();
3800 LocationSummary* locations = cond->GetLocations();
3801 IfCondition if_cond = condition->GetCondition();
3802 MipsLabel* branch_target = true_target;
David Brazdil0debae72015-11-12 18:37:00 +00003803
David Brazdil0debae72015-11-12 18:37:00 +00003804 if (true_target == nullptr) {
3805 if_cond = condition->GetOppositeCondition();
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003806 branch_target = false_target;
David Brazdil0debae72015-11-12 18:37:00 +00003807 }
3808
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -08003809 switch (type) {
3810 default:
3811 GenerateIntCompareAndBranch(if_cond, locations, branch_target);
3812 break;
3813 case Primitive::kPrimLong:
3814 GenerateLongCompareAndBranch(if_cond, locations, branch_target);
3815 break;
3816 case Primitive::kPrimFloat:
3817 case Primitive::kPrimDouble:
3818 GenerateFpCompareAndBranch(if_cond, condition->IsGtBias(), type, locations, branch_target);
3819 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003820 }
3821 }
David Brazdil0debae72015-11-12 18:37:00 +00003822
3823 // If neither branch falls through (case 3), the conditional branch to `true_target`
3824 // was already emitted (case 2) and we need to emit a jump to `false_target`.
3825 if (true_target != nullptr && false_target != nullptr) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003826 __ B(false_target);
3827 }
3828}
3829
3830void LocationsBuilderMIPS::VisitIf(HIf* if_instr) {
3831 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(if_instr);
David Brazdil0debae72015-11-12 18:37:00 +00003832 if (IsBooleanValueOrMaterializedCondition(if_instr->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003833 locations->SetInAt(0, Location::RequiresRegister());
3834 }
3835}
3836
3837void InstructionCodeGeneratorMIPS::VisitIf(HIf* if_instr) {
David Brazdil0debae72015-11-12 18:37:00 +00003838 HBasicBlock* true_successor = if_instr->IfTrueSuccessor();
3839 HBasicBlock* false_successor = if_instr->IfFalseSuccessor();
3840 MipsLabel* true_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), true_successor) ?
3841 nullptr : codegen_->GetLabelOf(true_successor);
3842 MipsLabel* false_target = codegen_->GoesToNextBlock(if_instr->GetBlock(), false_successor) ?
3843 nullptr : codegen_->GetLabelOf(false_successor);
3844 GenerateTestAndBranch(if_instr, /* condition_input_index */ 0, true_target, false_target);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003845}
3846
3847void LocationsBuilderMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
3848 LocationSummary* locations = new (GetGraph()->GetArena())
3849 LocationSummary(deoptimize, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01003850 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
David Brazdil0debae72015-11-12 18:37:00 +00003851 if (IsBooleanValueOrMaterializedCondition(deoptimize->InputAt(0))) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003852 locations->SetInAt(0, Location::RequiresRegister());
3853 }
3854}
3855
3856void InstructionCodeGeneratorMIPS::VisitDeoptimize(HDeoptimize* deoptimize) {
Aart Bik42249c32016-01-07 15:33:50 -08003857 SlowPathCodeMIPS* slow_path =
3858 deopt_slow_paths_.NewSlowPath<DeoptimizationSlowPathMIPS>(deoptimize);
David Brazdil0debae72015-11-12 18:37:00 +00003859 GenerateTestAndBranch(deoptimize,
3860 /* condition_input_index */ 0,
3861 slow_path->GetEntryLabel(),
3862 /* false_target */ nullptr);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003863}
3864
David Brazdil74eb1b22015-12-14 11:44:01 +00003865void LocationsBuilderMIPS::VisitSelect(HSelect* select) {
3866 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(select);
3867 if (Primitive::IsFloatingPointType(select->GetType())) {
3868 locations->SetInAt(0, Location::RequiresFpuRegister());
3869 locations->SetInAt(1, Location::RequiresFpuRegister());
3870 } else {
3871 locations->SetInAt(0, Location::RequiresRegister());
3872 locations->SetInAt(1, Location::RequiresRegister());
3873 }
3874 if (IsBooleanValueOrMaterializedCondition(select->GetCondition())) {
3875 locations->SetInAt(2, Location::RequiresRegister());
3876 }
3877 locations->SetOut(Location::SameAsFirstInput());
3878}
3879
3880void InstructionCodeGeneratorMIPS::VisitSelect(HSelect* select) {
3881 LocationSummary* locations = select->GetLocations();
3882 MipsLabel false_target;
3883 GenerateTestAndBranch(select,
3884 /* condition_input_index */ 2,
3885 /* true_target */ nullptr,
3886 &false_target);
3887 codegen_->MoveLocation(locations->Out(), locations->InAt(1), select->GetType());
3888 __ Bind(&false_target);
3889}
3890
David Srbecky0cf44932015-12-09 14:09:59 +00003891void LocationsBuilderMIPS::VisitNativeDebugInfo(HNativeDebugInfo* info) {
3892 new (GetGraph()->GetArena()) LocationSummary(info);
3893}
3894
David Srbeckyd28f4a02016-03-14 17:14:24 +00003895void InstructionCodeGeneratorMIPS::VisitNativeDebugInfo(HNativeDebugInfo*) {
3896 // MaybeRecordNativeDebugInfo is already called implicitly in CodeGenerator::Compile.
David Srbeckyc7098ff2016-02-09 14:30:11 +00003897}
3898
3899void CodeGeneratorMIPS::GenerateNop() {
3900 __ Nop();
David Srbecky0cf44932015-12-09 14:09:59 +00003901}
3902
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003903void LocationsBuilderMIPS::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
3904 Primitive::Type field_type = field_info.GetFieldType();
3905 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
3906 bool generate_volatile = field_info.IsVolatile() && is_wide;
3907 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01003908 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003909
3910 locations->SetInAt(0, Location::RequiresRegister());
3911 if (generate_volatile) {
3912 InvokeRuntimeCallingConvention calling_convention;
3913 // need A0 to hold base + offset
3914 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3915 if (field_type == Primitive::kPrimLong) {
3916 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimLong));
3917 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003918 // Use Location::Any() to prevent situations when running out of available fp registers.
3919 locations->SetOut(Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003920 // Need some temp core regs since FP results are returned in core registers
3921 Location reg = calling_convention.GetReturnLocation(Primitive::kPrimLong);
3922 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairLow<Register>()));
3923 locations->AddTemp(Location::RegisterLocation(reg.AsRegisterPairHigh<Register>()));
3924 }
3925 } else {
3926 if (Primitive::IsFloatingPointType(instruction->GetType())) {
3927 locations->SetOut(Location::RequiresFpuRegister());
3928 } else {
3929 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3930 }
3931 }
3932}
3933
3934void InstructionCodeGeneratorMIPS::HandleFieldGet(HInstruction* instruction,
3935 const FieldInfo& field_info,
3936 uint32_t dex_pc) {
3937 Primitive::Type type = field_info.GetFieldType();
3938 LocationSummary* locations = instruction->GetLocations();
3939 Register obj = locations->InAt(0).AsRegister<Register>();
3940 LoadOperandType load_type = kLoadUnsignedByte;
3941 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003942 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07003943 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003944
3945 switch (type) {
3946 case Primitive::kPrimBoolean:
3947 load_type = kLoadUnsignedByte;
3948 break;
3949 case Primitive::kPrimByte:
3950 load_type = kLoadSignedByte;
3951 break;
3952 case Primitive::kPrimShort:
3953 load_type = kLoadSignedHalfword;
3954 break;
3955 case Primitive::kPrimChar:
3956 load_type = kLoadUnsignedHalfword;
3957 break;
3958 case Primitive::kPrimInt:
3959 case Primitive::kPrimFloat:
3960 case Primitive::kPrimNot:
3961 load_type = kLoadWord;
3962 break;
3963 case Primitive::kPrimLong:
3964 case Primitive::kPrimDouble:
3965 load_type = kLoadDoubleword;
3966 break;
3967 case Primitive::kPrimVoid:
3968 LOG(FATAL) << "Unreachable type " << type;
3969 UNREACHABLE();
3970 }
3971
3972 if (is_volatile && load_type == kLoadDoubleword) {
3973 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01003974 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003975 // Do implicit Null check
3976 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
3977 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Serban Constantinescufca16662016-07-14 09:21:59 +01003978 codegen_->InvokeRuntime(kQuickA64Load, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003979 CheckEntrypointTypes<kQuickA64Load, int64_t, volatile const int64_t*>();
3980 if (type == Primitive::kPrimDouble) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02003981 // FP results are returned in core registers. Need to move them.
3982 Location out = locations->Out();
3983 if (out.IsFpuRegister()) {
3984 __ Mtc1(locations->GetTemp(1).AsRegister<Register>(), out.AsFpuRegister<FRegister>());
3985 __ MoveToFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
3986 out.AsFpuRegister<FRegister>());
3987 } else {
3988 DCHECK(out.IsDoubleStackSlot());
3989 __ StoreToOffset(kStoreWord,
3990 locations->GetTemp(1).AsRegister<Register>(),
3991 SP,
3992 out.GetStackIndex());
3993 __ StoreToOffset(kStoreWord,
3994 locations->GetTemp(2).AsRegister<Register>(),
3995 SP,
3996 out.GetStackIndex() + 4);
3997 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02003998 }
3999 } else {
4000 if (!Primitive::IsFloatingPointType(type)) {
4001 Register dst;
4002 if (type == Primitive::kPrimLong) {
4003 DCHECK(locations->Out().IsRegisterPair());
4004 dst = locations->Out().AsRegisterPairLow<Register>();
4005 } else {
4006 DCHECK(locations->Out().IsRegister());
4007 dst = locations->Out().AsRegister<Register>();
4008 }
Alexey Frunze2923db72016-08-20 01:55:47 -07004009 __ LoadFromOffset(load_type, dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004010 } else {
4011 DCHECK(locations->Out().IsFpuRegister());
4012 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
4013 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004014 __ LoadSFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004015 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07004016 __ LoadDFromOffset(dst, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004017 }
4018 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004019 }
4020
4021 if (is_volatile) {
4022 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
4023 }
4024}
4025
4026void LocationsBuilderMIPS::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
4027 Primitive::Type field_type = field_info.GetFieldType();
4028 bool is_wide = (field_type == Primitive::kPrimLong) || (field_type == Primitive::kPrimDouble);
4029 bool generate_volatile = field_info.IsVolatile() && is_wide;
4030 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004031 instruction, generate_volatile ? LocationSummary::kCallOnMainOnly : LocationSummary::kNoCall);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004032
4033 locations->SetInAt(0, Location::RequiresRegister());
4034 if (generate_volatile) {
4035 InvokeRuntimeCallingConvention calling_convention;
4036 // need A0 to hold base + offset
4037 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4038 if (field_type == Primitive::kPrimLong) {
4039 locations->SetInAt(1, Location::RegisterPairLocation(
4040 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
4041 } else {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004042 // Use Location::Any() to prevent situations when running out of available fp registers.
4043 locations->SetInAt(1, Location::Any());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004044 // Pass FP parameters in core registers.
4045 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
4046 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(3)));
4047 }
4048 } else {
4049 if (Primitive::IsFloatingPointType(field_type)) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004050 locations->SetInAt(1, FpuRegisterOrConstantForStore(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004051 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004052 locations->SetInAt(1, RegisterOrZeroConstant(instruction->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004053 }
4054 }
4055}
4056
4057void InstructionCodeGeneratorMIPS::HandleFieldSet(HInstruction* instruction,
4058 const FieldInfo& field_info,
4059 uint32_t dex_pc) {
4060 Primitive::Type type = field_info.GetFieldType();
4061 LocationSummary* locations = instruction->GetLocations();
4062 Register obj = locations->InAt(0).AsRegister<Register>();
Alexey Frunzef58b2482016-09-02 22:14:06 -07004063 Location value_location = locations->InAt(1);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004064 StoreOperandType store_type = kStoreByte;
4065 bool is_volatile = field_info.IsVolatile();
Goran Jakovljevic73a42652015-11-20 17:22:57 +01004066 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
Alexey Frunze2923db72016-08-20 01:55:47 -07004067 auto null_checker = GetImplicitNullChecker(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004068
4069 switch (type) {
4070 case Primitive::kPrimBoolean:
4071 case Primitive::kPrimByte:
4072 store_type = kStoreByte;
4073 break;
4074 case Primitive::kPrimShort:
4075 case Primitive::kPrimChar:
4076 store_type = kStoreHalfword;
4077 break;
4078 case Primitive::kPrimInt:
4079 case Primitive::kPrimFloat:
4080 case Primitive::kPrimNot:
4081 store_type = kStoreWord;
4082 break;
4083 case Primitive::kPrimLong:
4084 case Primitive::kPrimDouble:
4085 store_type = kStoreDoubleword;
4086 break;
4087 case Primitive::kPrimVoid:
4088 LOG(FATAL) << "Unreachable type " << type;
4089 UNREACHABLE();
4090 }
4091
4092 if (is_volatile) {
4093 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
4094 }
4095
4096 if (is_volatile && store_type == kStoreDoubleword) {
4097 InvokeRuntimeCallingConvention calling_convention;
Goran Jakovljevic73a42652015-11-20 17:22:57 +01004098 __ Addiu32(locations->GetTemp(0).AsRegister<Register>(), obj, offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004099 // Do implicit Null check.
4100 __ Lw(ZERO, locations->GetTemp(0).AsRegister<Register>(), 0);
4101 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
4102 if (type == Primitive::kPrimDouble) {
4103 // Pass FP parameters in core registers.
Alexey Frunzef58b2482016-09-02 22:14:06 -07004104 if (value_location.IsFpuRegister()) {
4105 __ Mfc1(locations->GetTemp(1).AsRegister<Register>(),
4106 value_location.AsFpuRegister<FRegister>());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004107 __ MoveFromFpuHigh(locations->GetTemp(2).AsRegister<Register>(),
Alexey Frunzef58b2482016-09-02 22:14:06 -07004108 value_location.AsFpuRegister<FRegister>());
4109 } else if (value_location.IsDoubleStackSlot()) {
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004110 __ LoadFromOffset(kLoadWord,
4111 locations->GetTemp(1).AsRegister<Register>(),
4112 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07004113 value_location.GetStackIndex());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004114 __ LoadFromOffset(kLoadWord,
4115 locations->GetTemp(2).AsRegister<Register>(),
4116 SP,
Alexey Frunzef58b2482016-09-02 22:14:06 -07004117 value_location.GetStackIndex() + 4);
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004118 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004119 DCHECK(value_location.IsConstant());
4120 DCHECK(value_location.GetConstant()->IsDoubleConstant());
4121 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
Goran Jakovljeviccdd822f2016-07-22 09:46:43 +02004122 __ LoadConst64(locations->GetTemp(2).AsRegister<Register>(),
4123 locations->GetTemp(1).AsRegister<Register>(),
4124 value);
4125 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004126 }
Serban Constantinescufca16662016-07-14 09:21:59 +01004127 codegen_->InvokeRuntime(kQuickA64Store, instruction, dex_pc);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004128 CheckEntrypointTypes<kQuickA64Store, void, volatile int64_t *, int64_t>();
4129 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004130 if (value_location.IsConstant()) {
4131 int64_t value = CodeGenerator::GetInt64ValueOf(value_location.GetConstant());
4132 __ StoreConstToOffset(store_type, value, obj, offset, TMP, null_checker);
4133 } else if (!Primitive::IsFloatingPointType(type)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004134 Register src;
4135 if (type == Primitive::kPrimLong) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004136 src = value_location.AsRegisterPairLow<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004137 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004138 src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004139 }
Alexey Frunze2923db72016-08-20 01:55:47 -07004140 __ StoreToOffset(store_type, src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004141 } else {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004142 FRegister src = value_location.AsFpuRegister<FRegister>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004143 if (type == Primitive::kPrimFloat) {
Alexey Frunze2923db72016-08-20 01:55:47 -07004144 __ StoreSToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004145 } else {
Alexey Frunze2923db72016-08-20 01:55:47 -07004146 __ StoreDToOffset(src, obj, offset, null_checker);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004147 }
4148 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004149 }
4150
4151 // TODO: memory barriers?
4152 if (CodeGenerator::StoreNeedsWriteBarrier(type, instruction->InputAt(1))) {
Alexey Frunzef58b2482016-09-02 22:14:06 -07004153 Register src = value_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004154 codegen_->MarkGCCard(obj, src);
4155 }
4156
4157 if (is_volatile) {
4158 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
4159 }
4160}
4161
4162void LocationsBuilderMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4163 HandleFieldGet(instruction, instruction->GetFieldInfo());
4164}
4165
4166void InstructionCodeGeneratorMIPS::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
4167 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4168}
4169
4170void LocationsBuilderMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4171 HandleFieldSet(instruction, instruction->GetFieldInfo());
4172}
4173
4174void InstructionCodeGeneratorMIPS::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
4175 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
4176}
4177
Alexey Frunze06a46c42016-07-19 15:00:40 -07004178void InstructionCodeGeneratorMIPS::GenerateGcRootFieldLoad(
4179 HInstruction* instruction ATTRIBUTE_UNUSED,
4180 Location root,
4181 Register obj,
4182 uint32_t offset) {
4183 Register root_reg = root.AsRegister<Register>();
4184 if (kEmitCompilerReadBarrier) {
4185 UNIMPLEMENTED(FATAL) << "for read barrier";
4186 } else {
4187 // Plain GC root load with no read barrier.
4188 // /* GcRoot<mirror::Object> */ root = *(obj + offset)
4189 __ LoadFromOffset(kLoadWord, root_reg, obj, offset);
4190 // Note that GC roots are not affected by heap poisoning, thus we
4191 // do not have to unpoison `root_reg` here.
4192 }
4193}
4194
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004195void LocationsBuilderMIPS::VisitInstanceOf(HInstanceOf* instruction) {
4196 LocationSummary::CallKind call_kind =
4197 instruction->IsExactCheck() ? LocationSummary::kNoCall : LocationSummary::kCallOnSlowPath;
4198 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
4199 locations->SetInAt(0, Location::RequiresRegister());
4200 locations->SetInAt(1, Location::RequiresRegister());
4201 // The output does overlap inputs.
4202 // Note that TypeCheckSlowPathMIPS uses this register too.
4203 locations->SetOut(Location::RequiresRegister(), Location::kOutputOverlap);
4204}
4205
4206void InstructionCodeGeneratorMIPS::VisitInstanceOf(HInstanceOf* instruction) {
4207 LocationSummary* locations = instruction->GetLocations();
4208 Register obj = locations->InAt(0).AsRegister<Register>();
4209 Register cls = locations->InAt(1).AsRegister<Register>();
4210 Register out = locations->Out().AsRegister<Register>();
4211
4212 MipsLabel done;
4213
4214 // Return 0 if `obj` is null.
4215 // TODO: Avoid this check if we know `obj` is not null.
4216 __ Move(out, ZERO);
4217 __ Beqz(obj, &done);
4218
4219 // Compare the class of `obj` with `cls`.
4220 __ LoadFromOffset(kLoadWord, out, obj, mirror::Object::ClassOffset().Int32Value());
4221 if (instruction->IsExactCheck()) {
4222 // Classes must be equal for the instanceof to succeed.
4223 __ Xor(out, out, cls);
4224 __ Sltiu(out, out, 1);
4225 } else {
4226 // If the classes are not equal, we go into a slow path.
4227 DCHECK(locations->OnlyCallsOnSlowPath());
4228 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathMIPS(instruction);
4229 codegen_->AddSlowPath(slow_path);
4230 __ Bne(out, cls, slow_path->GetEntryLabel());
4231 __ LoadConst32(out, 1);
4232 __ Bind(slow_path->GetExitLabel());
4233 }
4234
4235 __ Bind(&done);
4236}
4237
4238void LocationsBuilderMIPS::VisitIntConstant(HIntConstant* constant) {
4239 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4240 locations->SetOut(Location::ConstantLocation(constant));
4241}
4242
4243void InstructionCodeGeneratorMIPS::VisitIntConstant(HIntConstant* constant ATTRIBUTE_UNUSED) {
4244 // Will be generated at use site.
4245}
4246
4247void LocationsBuilderMIPS::VisitNullConstant(HNullConstant* constant) {
4248 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4249 locations->SetOut(Location::ConstantLocation(constant));
4250}
4251
4252void InstructionCodeGeneratorMIPS::VisitNullConstant(HNullConstant* constant ATTRIBUTE_UNUSED) {
4253 // Will be generated at use site.
4254}
4255
4256void LocationsBuilderMIPS::HandleInvoke(HInvoke* invoke) {
4257 InvokeDexCallingConventionVisitorMIPS calling_convention_visitor;
4258 CodeGenerator::CreateCommonInvokeLocationSummary(invoke, &calling_convention_visitor);
4259}
4260
4261void LocationsBuilderMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
4262 HandleInvoke(invoke);
4263 // The register T0 is required to be used for the hidden argument in
4264 // art_quick_imt_conflict_trampoline, so add the hidden argument.
4265 invoke->GetLocations()->AddTemp(Location::RegisterLocation(T0));
4266}
4267
4268void InstructionCodeGeneratorMIPS::VisitInvokeInterface(HInvokeInterface* invoke) {
4269 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
4270 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004271 Location receiver = invoke->GetLocations()->InAt(0);
4272 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07004273 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004274
4275 // Set the hidden argument.
4276 __ LoadConst32(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
4277 invoke->GetDexMethodIndex());
4278
4279 // temp = object->GetClass();
4280 if (receiver.IsStackSlot()) {
4281 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
4282 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
4283 } else {
4284 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
4285 }
4286 codegen_->MaybeRecordImplicitNullCheck(invoke);
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00004287 __ LoadFromOffset(kLoadWord, temp, temp,
4288 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
4289 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00004290 invoke->GetImtIndex(), kMipsPointerSize));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004291 // temp = temp->GetImtEntryAt(method_offset);
4292 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4293 // T9 = temp->GetEntryPoint();
4294 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
4295 // T9();
4296 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004297 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004298 DCHECK(!codegen_->IsLeafMethod());
4299 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4300}
4301
4302void LocationsBuilderMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Chris Larsen701566a2015-10-27 15:29:13 -07004303 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
4304 if (intrinsic.TryDispatch(invoke)) {
4305 return;
4306 }
4307
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004308 HandleInvoke(invoke);
4309}
4310
4311void LocationsBuilderMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004312 // Explicit clinit checks triggered by static invokes must have been pruned by
4313 // art::PrepareForRegisterAllocation.
4314 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004315
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004316 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
4317 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
4318 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4319
4320 // kDirectAddressWithFixup and kCallDirectWithFixup need no extra input on R6 because
4321 // R6 has PC-relative addressing.
4322 bool has_extra_input = !isR6 &&
4323 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
4324 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup));
4325
4326 if (invoke->HasPcRelativeDexCache()) {
4327 // kDexCachePcRelative is mutually exclusive with
4328 // kDirectAddressWithFixup/kCallDirectWithFixup.
4329 CHECK(!has_extra_input);
4330 has_extra_input = true;
4331 }
4332
Chris Larsen701566a2015-10-27 15:29:13 -07004333 IntrinsicLocationsBuilderMIPS intrinsic(codegen_);
4334 if (intrinsic.TryDispatch(invoke)) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004335 if (invoke->GetLocations()->CanCall() && has_extra_input) {
4336 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::Any());
4337 }
Chris Larsen701566a2015-10-27 15:29:13 -07004338 return;
4339 }
4340
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004341 HandleInvoke(invoke);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004342
4343 // Add the extra input register if either the dex cache array base register
4344 // or the PC-relative base register for accessing literals is needed.
4345 if (has_extra_input) {
4346 invoke->GetLocations()->SetInAt(invoke->GetSpecialInputIndex(), Location::RequiresRegister());
4347 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004348}
4349
Chris Larsen701566a2015-10-27 15:29:13 -07004350static bool TryGenerateIntrinsicCode(HInvoke* invoke, CodeGeneratorMIPS* codegen) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004351 if (invoke->GetLocations()->Intrinsified()) {
Chris Larsen701566a2015-10-27 15:29:13 -07004352 IntrinsicCodeGeneratorMIPS intrinsic(codegen);
4353 intrinsic.Dispatch(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004354 return true;
4355 }
4356 return false;
4357}
4358
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004359HLoadString::LoadKind CodeGeneratorMIPS::GetSupportedLoadStringKind(
Alexey Frunze06a46c42016-07-19 15:00:40 -07004360 HLoadString::LoadKind desired_string_load_kind) {
4361 if (kEmitCompilerReadBarrier) {
4362 UNIMPLEMENTED(FATAL) << "for read barrier";
4363 }
4364 // We disable PC-relative load when there is an irreducible loop, as the optimization
4365 // is incompatible with it.
Vladimir Markoaad75c62016-10-03 08:46:48 +00004366 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4367 // with irreducible loops.
Alexey Frunze06a46c42016-07-19 15:00:40 -07004368 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4369 bool fallback_load = has_irreducible_loops;
4370 switch (desired_string_load_kind) {
4371 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4372 DCHECK(!GetCompilerOptions().GetCompilePic());
4373 break;
4374 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
4375 DCHECK(GetCompilerOptions().GetCompilePic());
4376 break;
4377 case HLoadString::LoadKind::kBootImageAddress:
4378 break;
4379 case HLoadString::LoadKind::kDexCacheAddress:
4380 DCHECK(Runtime::Current()->UseJitCompilation());
4381 fallback_load = false;
4382 break;
Vladimir Markoaad75c62016-10-03 08:46:48 +00004383 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07004384 DCHECK(!Runtime::Current()->UseJitCompilation());
Alexey Frunze06a46c42016-07-19 15:00:40 -07004385 break;
4386 case HLoadString::LoadKind::kDexCacheViaMethod:
4387 fallback_load = false;
4388 break;
4389 }
4390 if (fallback_load) {
4391 desired_string_load_kind = HLoadString::LoadKind::kDexCacheViaMethod;
4392 }
4393 return desired_string_load_kind;
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004394}
4395
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004396HLoadClass::LoadKind CodeGeneratorMIPS::GetSupportedLoadClassKind(
4397 HLoadClass::LoadKind desired_class_load_kind) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004398 if (kEmitCompilerReadBarrier) {
4399 UNIMPLEMENTED(FATAL) << "for read barrier";
4400 }
4401 // We disable pc-relative load when there is an irreducible loop, as the optimization
4402 // is incompatible with it.
4403 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4404 bool fallback_load = has_irreducible_loops;
4405 switch (desired_class_load_kind) {
4406 case HLoadClass::LoadKind::kReferrersClass:
4407 fallback_load = false;
4408 break;
4409 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4410 DCHECK(!GetCompilerOptions().GetCompilePic());
4411 break;
4412 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4413 DCHECK(GetCompilerOptions().GetCompilePic());
4414 break;
4415 case HLoadClass::LoadKind::kBootImageAddress:
4416 break;
4417 case HLoadClass::LoadKind::kDexCacheAddress:
4418 DCHECK(Runtime::Current()->UseJitCompilation());
4419 fallback_load = false;
4420 break;
4421 case HLoadClass::LoadKind::kDexCachePcRelative:
4422 DCHECK(!Runtime::Current()->UseJitCompilation());
4423 // TODO: Create as many MipsDexCacheArraysBase instructions as needed for methods
4424 // with irreducible loops.
4425 break;
4426 case HLoadClass::LoadKind::kDexCacheViaMethod:
4427 fallback_load = false;
4428 break;
4429 }
4430 if (fallback_load) {
4431 desired_class_load_kind = HLoadClass::LoadKind::kDexCacheViaMethod;
4432 }
4433 return desired_class_load_kind;
Vladimir Markodbb7f5b2016-03-30 13:23:58 +01004434}
4435
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004436Register CodeGeneratorMIPS::GetInvokeStaticOrDirectExtraParameter(HInvokeStaticOrDirect* invoke,
4437 Register temp) {
4438 CHECK_EQ(invoke->InputCount(), invoke->GetNumberOfArguments() + 1u);
4439 Location location = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
4440 if (!invoke->GetLocations()->Intrinsified()) {
4441 return location.AsRegister<Register>();
4442 }
4443 // For intrinsics we allow any location, so it may be on the stack.
4444 if (!location.IsRegister()) {
4445 __ LoadFromOffset(kLoadWord, temp, SP, location.GetStackIndex());
4446 return temp;
4447 }
4448 // For register locations, check if the register was saved. If so, get it from the stack.
4449 // Note: There is a chance that the register was saved but not overwritten, so we could
4450 // save one load. However, since this is just an intrinsic slow path we prefer this
4451 // simple and more robust approach rather that trying to determine if that's the case.
4452 SlowPathCode* slow_path = GetCurrentSlowPath();
4453 DCHECK(slow_path != nullptr); // For intrinsified invokes the call is emitted on the slow path.
4454 if (slow_path->IsCoreRegisterSaved(location.AsRegister<Register>())) {
4455 int stack_offset = slow_path->GetStackOffsetOfCoreRegister(location.AsRegister<Register>());
4456 __ LoadFromOffset(kLoadWord, temp, SP, stack_offset);
4457 return temp;
4458 }
4459 return location.AsRegister<Register>();
4460}
4461
Vladimir Markodc151b22015-10-15 18:02:30 +01004462HInvokeStaticOrDirect::DispatchInfo CodeGeneratorMIPS::GetSupportedInvokeStaticOrDirectDispatch(
4463 const HInvokeStaticOrDirect::DispatchInfo& desired_dispatch_info,
Nicolas Geoffray5e4e11e2016-09-22 13:17:41 +01004464 HInvokeStaticOrDirect* invoke ATTRIBUTE_UNUSED) {
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004465 HInvokeStaticOrDirect::DispatchInfo dispatch_info = desired_dispatch_info;
4466 // We disable PC-relative load when there is an irreducible loop, as the optimization
4467 // is incompatible with it.
4468 bool has_irreducible_loops = GetGraph()->HasIrreducibleLoops();
4469 bool fallback_load = true;
4470 bool fallback_call = true;
4471 switch (dispatch_info.method_load_kind) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004472 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
4473 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004474 fallback_load = has_irreducible_loops;
4475 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004476 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004477 fallback_load = false;
Vladimir Markodc151b22015-10-15 18:02:30 +01004478 break;
4479 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004480 switch (dispatch_info.code_ptr_location) {
Vladimir Markodc151b22015-10-15 18:02:30 +01004481 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004482 fallback_call = has_irreducible_loops;
4483 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004484 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004485 // TODO: Implement this type.
4486 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004487 default:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004488 fallback_call = false;
4489 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004490 }
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004491 if (fallback_load) {
4492 dispatch_info.method_load_kind = HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod;
4493 dispatch_info.method_load_data = 0;
4494 }
4495 if (fallback_call) {
4496 dispatch_info.code_ptr_location = HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod;
4497 dispatch_info.direct_code_ptr = 0;
4498 }
4499 return dispatch_info;
Vladimir Markodc151b22015-10-15 18:02:30 +01004500}
4501
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004502void CodeGeneratorMIPS::GenerateStaticOrDirectCall(HInvokeStaticOrDirect* invoke, Location temp) {
4503 // All registers are assumed to be correctly set up per the calling convention.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004504 Location callee_method = temp; // For all kinds except kRecursive, callee will be in temp.
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004505 HInvokeStaticOrDirect::MethodLoadKind method_load_kind = invoke->GetMethodLoadKind();
4506 HInvokeStaticOrDirect::CodePtrLocation code_ptr_location = invoke->GetCodePtrLocation();
4507 bool isR6 = isa_features_.IsR6();
4508 // kDirectAddressWithFixup and kCallDirectWithFixup have no extra input on R6 because
4509 // R6 has PC-relative addressing.
4510 bool has_extra_input = invoke->HasPcRelativeDexCache() ||
4511 (!isR6 &&
4512 ((method_load_kind == HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup) ||
4513 (code_ptr_location == HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup)));
4514 Register base_reg = has_extra_input
4515 ? GetInvokeStaticOrDirectExtraParameter(invoke, temp.AsRegister<Register>())
4516 : ZERO;
4517
4518 // For better instruction scheduling we load the direct code pointer before the method pointer.
4519 switch (code_ptr_location) {
4520 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
4521 // T9 = invoke->GetDirectCodePtr();
4522 __ LoadConst32(T9, invoke->GetDirectCodePtr());
4523 break;
4524 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4525 // T9 = code address from literal pool with link-time patch.
4526 __ LoadLiteral(T9, base_reg, DeduplicateMethodCodeLiteral(invoke->GetTargetMethod()));
4527 break;
4528 default:
4529 break;
4530 }
4531
4532 switch (method_load_kind) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01004533 case HInvokeStaticOrDirect::MethodLoadKind::kStringInit: {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004534 // temp = thread->string_init_entrypoint
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01004535 uint32_t offset =
4536 GetThreadOffset<kMipsPointerSize>(invoke->GetStringInitEntryPoint()).Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004537 __ LoadFromOffset(kLoadWord,
4538 temp.AsRegister<Register>(),
4539 TR,
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01004540 offset);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004541 break;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01004542 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004543 case HInvokeStaticOrDirect::MethodLoadKind::kRecursive:
Vladimir Markoc53c0792015-11-19 15:48:33 +00004544 callee_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004545 break;
4546 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddress:
4547 __ LoadConst32(temp.AsRegister<Register>(), invoke->GetMethodAddress());
4548 break;
4549 case HInvokeStaticOrDirect::MethodLoadKind::kDirectAddressWithFixup:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004550 __ LoadLiteral(temp.AsRegister<Register>(),
4551 base_reg,
4552 DeduplicateMethodAddressLiteral(invoke->GetTargetMethod()));
4553 break;
4554 case HInvokeStaticOrDirect::MethodLoadKind::kDexCachePcRelative: {
4555 HMipsDexCacheArraysBase* base =
4556 invoke->InputAt(invoke->GetSpecialInputIndex())->AsMipsDexCacheArraysBase();
4557 int32_t offset =
4558 invoke->GetDexCacheArrayOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4559 __ LoadFromOffset(kLoadWord, temp.AsRegister<Register>(), base_reg, offset);
4560 break;
4561 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004562 case HInvokeStaticOrDirect::MethodLoadKind::kDexCacheViaMethod: {
Vladimir Markoc53c0792015-11-19 15:48:33 +00004563 Location current_method = invoke->GetLocations()->InAt(invoke->GetSpecialInputIndex());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004564 Register reg = temp.AsRegister<Register>();
4565 Register method_reg;
4566 if (current_method.IsRegister()) {
4567 method_reg = current_method.AsRegister<Register>();
4568 } else {
4569 // TODO: use the appropriate DCHECK() here if possible.
4570 // DCHECK(invoke->GetLocations()->Intrinsified());
4571 DCHECK(!current_method.IsValid());
4572 method_reg = reg;
4573 __ Lw(reg, SP, kCurrentMethodStackOffset);
4574 }
4575
4576 // temp = temp->dex_cache_resolved_methods_;
4577 __ LoadFromOffset(kLoadWord,
4578 reg,
4579 method_reg,
4580 ArtMethod::DexCacheResolvedMethodsOffset(kMipsPointerSize).Int32Value());
Vladimir Marko40ecb122016-04-06 17:33:41 +01004581 // temp = temp[index_in_cache];
4582 // Note: Don't use invoke->GetTargetMethod() as it may point to a different dex file.
4583 uint32_t index_in_cache = invoke->GetDexMethodIndex();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004584 __ LoadFromOffset(kLoadWord,
4585 reg,
4586 reg,
4587 CodeGenerator::GetCachePointerOffset(index_in_cache));
4588 break;
4589 }
4590 }
4591
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004592 switch (code_ptr_location) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004593 case HInvokeStaticOrDirect::CodePtrLocation::kCallSelf:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004594 __ Bal(&frame_entry_label_);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004595 break;
4596 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirect:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004597 case HInvokeStaticOrDirect::CodePtrLocation::kCallDirectWithFixup:
4598 // T9 prepared above for better instruction scheduling.
4599 // T9()
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004600 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004601 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004602 break;
Vladimir Markodc151b22015-10-15 18:02:30 +01004603 case HInvokeStaticOrDirect::CodePtrLocation::kCallPCRelative:
Alexey Frunzee3fb2452016-05-10 16:08:05 -07004604 // TODO: Implement this type.
Vladimir Markodc151b22015-10-15 18:02:30 +01004605 // Currently filtered out by GetSupportedInvokeStaticOrDirectDispatch().
4606 LOG(FATAL) << "Unsupported";
4607 UNREACHABLE();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004608 case HInvokeStaticOrDirect::CodePtrLocation::kCallArtMethod:
4609 // T9 = callee_method->entry_point_from_quick_compiled_code_;
Goran Jakovljevic1a878372015-10-26 14:28:52 +01004610 __ LoadFromOffset(kLoadWord,
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004611 T9,
4612 callee_method.AsRegister<Register>(),
4613 ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Andreas Gampe542451c2016-07-26 09:02:02 -07004614 kMipsPointerSize).Int32Value());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004615 // T9()
4616 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004617 __ NopIfNoReordering();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004618 break;
4619 }
4620 DCHECK(!IsLeafMethod());
4621}
4622
4623void InstructionCodeGeneratorMIPS::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
David Brazdil58282f42016-01-14 12:45:10 +00004624 // Explicit clinit checks triggered by static invokes must have been pruned by
4625 // art::PrepareForRegisterAllocation.
4626 DCHECK(!invoke->IsStaticWithExplicitClinitCheck());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004627
4628 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4629 return;
4630 }
4631
4632 LocationSummary* locations = invoke->GetLocations();
4633 codegen_->GenerateStaticOrDirectCall(invoke,
4634 locations->HasTemps()
4635 ? locations->GetTemp(0)
4636 : Location::NoLocation());
4637 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4638}
4639
Chris Larsen3acee732015-11-18 13:31:08 -08004640void CodeGeneratorMIPS::GenerateVirtualCall(HInvokeVirtual* invoke, Location temp_location) {
Goran Jakovljevice919b072016-10-04 10:17:34 +02004641 // Use the calling convention instead of the location of the receiver, as
4642 // intrinsics may have put the receiver in a different register. In the intrinsics
4643 // slow path, the arguments have been moved to the right place, so here we are
4644 // guaranteed that the receiver is the first register of the calling convention.
4645 InvokeDexCallingConvention calling_convention;
4646 Register receiver = calling_convention.GetRegisterAt(0);
4647
Chris Larsen3acee732015-11-18 13:31:08 -08004648 Register temp = temp_location.AsRegister<Register>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004649 size_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
4650 invoke->GetVTableIndex(), kMipsPointerSize).SizeValue();
4651 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
Andreas Gampe542451c2016-07-26 09:02:02 -07004652 Offset entry_point = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004653
4654 // temp = object->GetClass();
Goran Jakovljevice919b072016-10-04 10:17:34 +02004655 __ LoadFromOffset(kLoadWord, temp, receiver, class_offset);
Chris Larsen3acee732015-11-18 13:31:08 -08004656 MaybeRecordImplicitNullCheck(invoke);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004657 // temp = temp->GetMethodAt(method_offset);
4658 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
4659 // T9 = temp->GetEntryPoint();
4660 __ LoadFromOffset(kLoadWord, T9, temp, entry_point.Int32Value());
4661 // T9();
4662 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07004663 __ NopIfNoReordering();
Chris Larsen3acee732015-11-18 13:31:08 -08004664}
4665
4666void InstructionCodeGeneratorMIPS::VisitInvokeVirtual(HInvokeVirtual* invoke) {
4667 if (TryGenerateIntrinsicCode(invoke, codegen_)) {
4668 return;
4669 }
4670
4671 codegen_->GenerateVirtualCall(invoke, invoke->GetLocations()->GetTemp(0));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004672 DCHECK(!codegen_->IsLeafMethod());
4673 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
4674}
4675
4676void LocationsBuilderMIPS::VisitLoadClass(HLoadClass* cls) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004677 if (cls->NeedsAccessCheck()) {
4678 InvokeRuntimeCallingConvention calling_convention;
4679 CodeGenerator::CreateLoadClassLocationSummary(
4680 cls,
4681 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
4682 Location::RegisterLocation(V0),
4683 /* code_generator_supports_read_barrier */ false); // TODO: revisit this bool.
4684 return;
4685 }
4686
4687 LocationSummary::CallKind call_kind = (cls->NeedsEnvironment() || kEmitCompilerReadBarrier)
4688 ? LocationSummary::kCallOnSlowPath
4689 : LocationSummary::kNoCall;
4690 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
4691 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4692 switch (load_kind) {
4693 // We need an extra register for PC-relative literals on R2.
4694 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4695 case HLoadClass::LoadKind::kBootImageAddress:
4696 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4697 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4698 break;
4699 }
4700 FALLTHROUGH_INTENDED;
4701 // We need an extra register for PC-relative dex cache accesses.
4702 case HLoadClass::LoadKind::kDexCachePcRelative:
4703 case HLoadClass::LoadKind::kReferrersClass:
4704 case HLoadClass::LoadKind::kDexCacheViaMethod:
4705 locations->SetInAt(0, Location::RequiresRegister());
4706 break;
4707 default:
4708 break;
4709 }
4710 locations->SetOut(Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004711}
4712
4713void InstructionCodeGeneratorMIPS::VisitLoadClass(HLoadClass* cls) {
4714 LocationSummary* locations = cls->GetLocations();
Pavle Batutae87a7182015-10-28 13:10:42 +01004715 if (cls->NeedsAccessCheck()) {
4716 codegen_->MoveConstant(locations->GetTemp(0), cls->GetTypeIndex());
Serban Constantinescufca16662016-07-14 09:21:59 +01004717 codegen_->InvokeRuntime(kQuickInitializeTypeAndVerifyAccess, cls, cls->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00004718 CheckEntrypointTypes<kQuickInitializeTypeAndVerifyAccess, void*, uint32_t>();
Pavle Batutae87a7182015-10-28 13:10:42 +01004719 return;
4720 }
4721
Alexey Frunze06a46c42016-07-19 15:00:40 -07004722 HLoadClass::LoadKind load_kind = cls->GetLoadKind();
4723 Location out_loc = locations->Out();
4724 Register out = out_loc.AsRegister<Register>();
4725 Register base_or_current_method_reg;
4726 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4727 switch (load_kind) {
4728 // We need an extra register for PC-relative literals on R2.
4729 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4730 case HLoadClass::LoadKind::kBootImageAddress:
4731 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative:
4732 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4733 break;
4734 // We need an extra register for PC-relative dex cache accesses.
4735 case HLoadClass::LoadKind::kDexCachePcRelative:
4736 case HLoadClass::LoadKind::kReferrersClass:
4737 case HLoadClass::LoadKind::kDexCacheViaMethod:
4738 base_or_current_method_reg = locations->InAt(0).AsRegister<Register>();
4739 break;
4740 default:
4741 base_or_current_method_reg = ZERO;
4742 break;
4743 }
Nicolas Geoffray42e372e2015-11-24 15:48:56 +00004744
Alexey Frunze06a46c42016-07-19 15:00:40 -07004745 bool generate_null_check = false;
4746 switch (load_kind) {
4747 case HLoadClass::LoadKind::kReferrersClass: {
4748 DCHECK(!cls->CanCallRuntime());
4749 DCHECK(!cls->MustGenerateClinitCheck());
4750 // /* GcRoot<mirror::Class> */ out = current_method->declaring_class_
4751 GenerateGcRootFieldLoad(cls,
4752 out_loc,
4753 base_or_current_method_reg,
4754 ArtMethod::DeclaringClassOffset().Int32Value());
4755 break;
4756 }
4757 case HLoadClass::LoadKind::kBootImageLinkTimeAddress:
4758 DCHECK(!kEmitCompilerReadBarrier);
4759 __ LoadLiteral(out,
4760 base_or_current_method_reg,
4761 codegen_->DeduplicateBootImageTypeLiteral(cls->GetDexFile(),
4762 cls->GetTypeIndex()));
4763 break;
4764 case HLoadClass::LoadKind::kBootImageLinkTimePcRelative: {
4765 DCHECK(!kEmitCompilerReadBarrier);
4766 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4767 codegen_->NewPcRelativeTypePatch(cls->GetDexFile(), cls->GetTypeIndex());
Vladimir Markoaad75c62016-10-03 08:46:48 +00004768 codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004769 break;
4770 }
4771 case HLoadClass::LoadKind::kBootImageAddress: {
4772 DCHECK(!kEmitCompilerReadBarrier);
4773 DCHECK_NE(cls->GetAddress(), 0u);
4774 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4775 __ LoadLiteral(out,
4776 base_or_current_method_reg,
4777 codegen_->DeduplicateBootImageAddressLiteral(address));
4778 break;
4779 }
4780 case HLoadClass::LoadKind::kDexCacheAddress: {
4781 DCHECK_NE(cls->GetAddress(), 0u);
4782 uint32_t address = dchecked_integral_cast<uint32_t>(cls->GetAddress());
4783 static_assert(sizeof(GcRoot<mirror::Class>) == 4u, "Expected GC root to be 4 bytes.");
4784 DCHECK_ALIGNED(cls->GetAddress(), 4u);
4785 int16_t offset = Low16Bits(address);
4786 uint32_t base_address = address - offset; // This accounts for offset sign extension.
4787 __ Lui(out, High16Bits(base_address));
4788 // /* GcRoot<mirror::Class> */ out = *(base_address + offset)
4789 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4790 generate_null_check = !cls->IsInDexCache();
4791 break;
4792 }
4793 case HLoadClass::LoadKind::kDexCachePcRelative: {
4794 HMipsDexCacheArraysBase* base = cls->InputAt(0)->AsMipsDexCacheArraysBase();
4795 int32_t offset =
4796 cls->GetDexCacheElementOffset() - base->GetElementOffset() - kDexCacheArrayLwOffset;
4797 // /* GcRoot<mirror::Class> */ out = *(dex_cache_arrays_base + offset)
4798 GenerateGcRootFieldLoad(cls, out_loc, base_or_current_method_reg, offset);
4799 generate_null_check = !cls->IsInDexCache();
4800 break;
4801 }
4802 case HLoadClass::LoadKind::kDexCacheViaMethod: {
4803 // /* GcRoot<mirror::Class>[] */ out =
4804 // current_method.ptr_sized_fields_->dex_cache_resolved_types_
4805 __ LoadFromOffset(kLoadWord,
4806 out,
4807 base_or_current_method_reg,
4808 ArtMethod::DexCacheResolvedTypesOffset(kArmPointerSize).Int32Value());
4809 // /* GcRoot<mirror::Class> */ out = out[type_index]
4810 size_t offset = CodeGenerator::GetCacheOffset(cls->GetTypeIndex());
4811 GenerateGcRootFieldLoad(cls, out_loc, out, offset);
4812 generate_null_check = !cls->IsInDexCache();
4813 }
4814 }
4815
4816 if (generate_null_check || cls->MustGenerateClinitCheck()) {
4817 DCHECK(cls->CanCallRuntime());
4818 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathMIPS(
4819 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
4820 codegen_->AddSlowPath(slow_path);
4821 if (generate_null_check) {
4822 __ Beqz(out, slow_path->GetEntryLabel());
4823 }
4824 if (cls->MustGenerateClinitCheck()) {
4825 GenerateClassInitializationCheck(slow_path, out);
4826 } else {
4827 __ Bind(slow_path->GetExitLabel());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004828 }
4829 }
4830}
4831
4832static int32_t GetExceptionTlsOffset() {
Andreas Gampe542451c2016-07-26 09:02:02 -07004833 return Thread::ExceptionOffset<kMipsPointerSize>().Int32Value();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004834}
4835
4836void LocationsBuilderMIPS::VisitLoadException(HLoadException* load) {
4837 LocationSummary* locations =
4838 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
4839 locations->SetOut(Location::RequiresRegister());
4840}
4841
4842void InstructionCodeGeneratorMIPS::VisitLoadException(HLoadException* load) {
4843 Register out = load->GetLocations()->Out().AsRegister<Register>();
4844 __ LoadFromOffset(kLoadWord, out, TR, GetExceptionTlsOffset());
4845}
4846
4847void LocationsBuilderMIPS::VisitClearException(HClearException* clear) {
4848 new (GetGraph()->GetArena()) LocationSummary(clear, LocationSummary::kNoCall);
4849}
4850
4851void InstructionCodeGeneratorMIPS::VisitClearException(HClearException* clear ATTRIBUTE_UNUSED) {
4852 __ StoreToOffset(kStoreWord, ZERO, TR, GetExceptionTlsOffset());
4853}
4854
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004855void LocationsBuilderMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004856 LocationSummary::CallKind call_kind = (load->NeedsEnvironment() || kEmitCompilerReadBarrier)
Vladimir Markoaad75c62016-10-03 08:46:48 +00004857 ? ((load->GetLoadKind() == HLoadString::LoadKind::kDexCacheViaMethod)
4858 ? LocationSummary::kCallOnMainOnly
4859 : LocationSummary::kCallOnSlowPath)
Vladimir Markocac5a7e2016-02-22 10:39:50 +00004860 : LocationSummary::kNoCall;
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004861 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(load, call_kind);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004862 HLoadString::LoadKind load_kind = load->GetLoadKind();
4863 switch (load_kind) {
4864 // We need an extra register for PC-relative literals on R2.
4865 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4866 case HLoadString::LoadKind::kBootImageAddress:
4867 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +00004868 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07004869 if (codegen_->GetInstructionSetFeatures().IsR6()) {
4870 break;
4871 }
4872 FALLTHROUGH_INTENDED;
4873 // We need an extra register for PC-relative dex cache accesses.
Alexey Frunze06a46c42016-07-19 15:00:40 -07004874 case HLoadString::LoadKind::kDexCacheViaMethod:
4875 locations->SetInAt(0, Location::RequiresRegister());
4876 break;
4877 default:
4878 break;
4879 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004880 locations->SetOut(Location::RequiresRegister());
4881}
4882
4883void InstructionCodeGeneratorMIPS::VisitLoadString(HLoadString* load) {
Alexey Frunze06a46c42016-07-19 15:00:40 -07004884 HLoadString::LoadKind load_kind = load->GetLoadKind();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004885 LocationSummary* locations = load->GetLocations();
Alexey Frunze06a46c42016-07-19 15:00:40 -07004886 Location out_loc = locations->Out();
4887 Register out = out_loc.AsRegister<Register>();
4888 Register base_or_current_method_reg;
4889 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
4890 switch (load_kind) {
4891 // We need an extra register for PC-relative literals on R2.
4892 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4893 case HLoadString::LoadKind::kBootImageAddress:
4894 case HLoadString::LoadKind::kBootImageLinkTimePcRelative:
Vladimir Markoaad75c62016-10-03 08:46:48 +00004895 case HLoadString::LoadKind::kBssEntry:
Alexey Frunze06a46c42016-07-19 15:00:40 -07004896 base_or_current_method_reg = isR6 ? ZERO : locations->InAt(0).AsRegister<Register>();
4897 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004898 default:
4899 base_or_current_method_reg = ZERO;
4900 break;
4901 }
4902
4903 switch (load_kind) {
4904 case HLoadString::LoadKind::kBootImageLinkTimeAddress:
4905 DCHECK(!kEmitCompilerReadBarrier);
4906 __ LoadLiteral(out,
4907 base_or_current_method_reg,
4908 codegen_->DeduplicateBootImageStringLiteral(load->GetDexFile(),
4909 load->GetStringIndex()));
4910 return; // No dex cache slow path.
4911 case HLoadString::LoadKind::kBootImageLinkTimePcRelative: {
4912 DCHECK(!kEmitCompilerReadBarrier);
Vladimir Markoaad75c62016-10-03 08:46:48 +00004913 DCHECK(codegen_->GetCompilerOptions().IsBootImage());
Alexey Frunze06a46c42016-07-19 15:00:40 -07004914 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4915 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
Vladimir Markoaad75c62016-10-03 08:46:48 +00004916 codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg);
Alexey Frunze06a46c42016-07-19 15:00:40 -07004917 return; // No dex cache slow path.
4918 }
4919 case HLoadString::LoadKind::kBootImageAddress: {
4920 DCHECK(!kEmitCompilerReadBarrier);
4921 DCHECK_NE(load->GetAddress(), 0u);
4922 uint32_t address = dchecked_integral_cast<uint32_t>(load->GetAddress());
4923 __ LoadLiteral(out,
4924 base_or_current_method_reg,
4925 codegen_->DeduplicateBootImageAddressLiteral(address));
4926 return; // No dex cache slow path.
4927 }
Vladimir Markoaad75c62016-10-03 08:46:48 +00004928 case HLoadString::LoadKind::kBssEntry: {
4929 DCHECK(!codegen_->GetCompilerOptions().IsBootImage());
4930 CodeGeneratorMIPS::PcRelativePatchInfo* info =
4931 codegen_->NewPcRelativeStringPatch(load->GetDexFile(), load->GetStringIndex());
4932 codegen_->EmitPcRelativeAddressPlaceholder(info, out, base_or_current_method_reg);
4933 __ LoadFromOffset(kLoadWord, out, out, 0);
4934 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathMIPS(load);
4935 codegen_->AddSlowPath(slow_path);
4936 __ Beqz(out, slow_path->GetEntryLabel());
4937 __ Bind(slow_path->GetExitLabel());
4938 return;
4939 }
Alexey Frunze06a46c42016-07-19 15:00:40 -07004940 default:
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004941 break;
Alexey Frunze06a46c42016-07-19 15:00:40 -07004942 }
Nicolas Geoffray917d0162015-11-24 18:25:35 +00004943
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -07004944 // TODO: Re-add the compiler code to do string dex cache lookup again.
Vladimir Markoaad75c62016-10-03 08:46:48 +00004945 DCHECK(load_kind == HLoadString::LoadKind::kDexCacheViaMethod);
4946 InvokeRuntimeCallingConvention calling_convention;
4947 __ LoadConst32(calling_convention.GetRegisterAt(0), load->GetStringIndex());
4948 codegen_->InvokeRuntime(kQuickResolveString, load, load->GetDexPc());
4949 CheckEntrypointTypes<kQuickResolveString, void*, uint32_t>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004950}
4951
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004952void LocationsBuilderMIPS::VisitLongConstant(HLongConstant* constant) {
4953 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(constant);
4954 locations->SetOut(Location::ConstantLocation(constant));
4955}
4956
4957void InstructionCodeGeneratorMIPS::VisitLongConstant(HLongConstant* constant ATTRIBUTE_UNUSED) {
4958 // Will be generated at use site.
4959}
4960
4961void LocationsBuilderMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4962 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01004963 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004964 InvokeRuntimeCallingConvention calling_convention;
4965 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
4966}
4967
4968void InstructionCodeGeneratorMIPS::VisitMonitorOperation(HMonitorOperation* instruction) {
4969 if (instruction->IsEnter()) {
Serban Constantinescufca16662016-07-14 09:21:59 +01004970 codegen_->InvokeRuntime(kQuickLockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004971 CheckEntrypointTypes<kQuickLockObject, void, mirror::Object*>();
4972 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01004973 codegen_->InvokeRuntime(kQuickUnlockObject, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02004974 }
4975 CheckEntrypointTypes<kQuickUnlockObject, void, mirror::Object*>();
4976}
4977
4978void LocationsBuilderMIPS::VisitMul(HMul* mul) {
4979 LocationSummary* locations =
4980 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
4981 switch (mul->GetResultType()) {
4982 case Primitive::kPrimInt:
4983 case Primitive::kPrimLong:
4984 locations->SetInAt(0, Location::RequiresRegister());
4985 locations->SetInAt(1, Location::RequiresRegister());
4986 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
4987 break;
4988
4989 case Primitive::kPrimFloat:
4990 case Primitive::kPrimDouble:
4991 locations->SetInAt(0, Location::RequiresFpuRegister());
4992 locations->SetInAt(1, Location::RequiresFpuRegister());
4993 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
4994 break;
4995
4996 default:
4997 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
4998 }
4999}
5000
5001void InstructionCodeGeneratorMIPS::VisitMul(HMul* instruction) {
5002 Primitive::Type type = instruction->GetType();
5003 LocationSummary* locations = instruction->GetLocations();
5004 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
5005
5006 switch (type) {
5007 case Primitive::kPrimInt: {
5008 Register dst = locations->Out().AsRegister<Register>();
5009 Register lhs = locations->InAt(0).AsRegister<Register>();
5010 Register rhs = locations->InAt(1).AsRegister<Register>();
5011
5012 if (isR6) {
5013 __ MulR6(dst, lhs, rhs);
5014 } else {
5015 __ MulR2(dst, lhs, rhs);
5016 }
5017 break;
5018 }
5019 case Primitive::kPrimLong: {
5020 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5021 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5022 Register lhs_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5023 Register lhs_low = locations->InAt(0).AsRegisterPairLow<Register>();
5024 Register rhs_high = locations->InAt(1).AsRegisterPairHigh<Register>();
5025 Register rhs_low = locations->InAt(1).AsRegisterPairLow<Register>();
5026
5027 // Extra checks to protect caused by the existance of A1_A2.
5028 // The algorithm is wrong if dst_high is either lhs_lo or rhs_lo:
5029 // (e.g. lhs=a0_a1, rhs=a2_a3 and dst=a1_a2).
5030 DCHECK_NE(dst_high, lhs_low);
5031 DCHECK_NE(dst_high, rhs_low);
5032
5033 // A_B * C_D
5034 // dst_hi: [ low(A*D) + low(B*C) + hi(B*D) ]
5035 // dst_lo: [ low(B*D) ]
5036 // Note: R2 and R6 MUL produce the low 32 bit of the multiplication result.
5037
5038 if (isR6) {
5039 __ MulR6(TMP, lhs_high, rhs_low);
5040 __ MulR6(dst_high, lhs_low, rhs_high);
5041 __ Addu(dst_high, dst_high, TMP);
5042 __ MuhuR6(TMP, lhs_low, rhs_low);
5043 __ Addu(dst_high, dst_high, TMP);
5044 __ MulR6(dst_low, lhs_low, rhs_low);
5045 } else {
5046 __ MulR2(TMP, lhs_high, rhs_low);
5047 __ MulR2(dst_high, lhs_low, rhs_high);
5048 __ Addu(dst_high, dst_high, TMP);
5049 __ MultuR2(lhs_low, rhs_low);
5050 __ Mfhi(TMP);
5051 __ Addu(dst_high, dst_high, TMP);
5052 __ Mflo(dst_low);
5053 }
5054 break;
5055 }
5056 case Primitive::kPrimFloat:
5057 case Primitive::kPrimDouble: {
5058 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5059 FRegister lhs = locations->InAt(0).AsFpuRegister<FRegister>();
5060 FRegister rhs = locations->InAt(1).AsFpuRegister<FRegister>();
5061 if (type == Primitive::kPrimFloat) {
5062 __ MulS(dst, lhs, rhs);
5063 } else {
5064 __ MulD(dst, lhs, rhs);
5065 }
5066 break;
5067 }
5068 default:
5069 LOG(FATAL) << "Unexpected mul type " << type;
5070 }
5071}
5072
5073void LocationsBuilderMIPS::VisitNeg(HNeg* neg) {
5074 LocationSummary* locations =
5075 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
5076 switch (neg->GetResultType()) {
5077 case Primitive::kPrimInt:
5078 case Primitive::kPrimLong:
5079 locations->SetInAt(0, Location::RequiresRegister());
5080 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5081 break;
5082
5083 case Primitive::kPrimFloat:
5084 case Primitive::kPrimDouble:
5085 locations->SetInAt(0, Location::RequiresFpuRegister());
5086 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5087 break;
5088
5089 default:
5090 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
5091 }
5092}
5093
5094void InstructionCodeGeneratorMIPS::VisitNeg(HNeg* instruction) {
5095 Primitive::Type type = instruction->GetType();
5096 LocationSummary* locations = instruction->GetLocations();
5097
5098 switch (type) {
5099 case Primitive::kPrimInt: {
5100 Register dst = locations->Out().AsRegister<Register>();
5101 Register src = locations->InAt(0).AsRegister<Register>();
5102 __ Subu(dst, ZERO, src);
5103 break;
5104 }
5105 case Primitive::kPrimLong: {
5106 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5107 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5108 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5109 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5110 __ Subu(dst_low, ZERO, src_low);
5111 __ Sltu(TMP, ZERO, dst_low);
5112 __ Subu(dst_high, ZERO, src_high);
5113 __ Subu(dst_high, dst_high, TMP);
5114 break;
5115 }
5116 case Primitive::kPrimFloat:
5117 case Primitive::kPrimDouble: {
5118 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5119 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5120 if (type == Primitive::kPrimFloat) {
5121 __ NegS(dst, src);
5122 } else {
5123 __ NegD(dst, src);
5124 }
5125 break;
5126 }
5127 default:
5128 LOG(FATAL) << "Unexpected neg type " << type;
5129 }
5130}
5131
5132void LocationsBuilderMIPS::VisitNewArray(HNewArray* instruction) {
5133 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005134 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005135 InvokeRuntimeCallingConvention calling_convention;
5136 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5137 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
5138 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
5139 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
5140}
5141
5142void InstructionCodeGeneratorMIPS::VisitNewArray(HNewArray* instruction) {
5143 InvokeRuntimeCallingConvention calling_convention;
5144 Register current_method_register = calling_convention.GetRegisterAt(2);
5145 __ Lw(current_method_register, SP, kCurrentMethodStackOffset);
5146 // Move an uint16_t value to a register.
5147 __ LoadConst32(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Serban Constantinescufca16662016-07-14 09:21:59 +01005148 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005149 CheckEntrypointTypes<kQuickAllocArrayWithAccessCheck,
5150 void*, uint32_t, int32_t, ArtMethod*>();
5151}
5152
5153void LocationsBuilderMIPS::VisitNewInstance(HNewInstance* instruction) {
5154 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005155 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005156 InvokeRuntimeCallingConvention calling_convention;
David Brazdil6de19382016-01-08 17:37:10 +00005157 if (instruction->IsStringAlloc()) {
5158 locations->AddTemp(Location::RegisterLocation(kMethodRegisterArgument));
5159 } else {
5160 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5161 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
5162 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005163 locations->SetOut(calling_convention.GetReturnLocation(Primitive::kPrimNot));
5164}
5165
5166void InstructionCodeGeneratorMIPS::VisitNewInstance(HNewInstance* instruction) {
David Brazdil6de19382016-01-08 17:37:10 +00005167 if (instruction->IsStringAlloc()) {
5168 // String is allocated through StringFactory. Call NewEmptyString entry point.
5169 Register temp = instruction->GetLocations()->GetTemp(0).AsRegister<Register>();
Andreas Gampe542451c2016-07-26 09:02:02 -07005170 MemberOffset code_offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(kMipsPointerSize);
David Brazdil6de19382016-01-08 17:37:10 +00005171 __ LoadFromOffset(kLoadWord, temp, TR, QUICK_ENTRY_POINT(pNewEmptyString));
5172 __ LoadFromOffset(kLoadWord, T9, temp, code_offset.Int32Value());
5173 __ Jalr(T9);
Alexey Frunze57eb0f52016-07-29 22:04:46 -07005174 __ NopIfNoReordering();
David Brazdil6de19382016-01-08 17:37:10 +00005175 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
5176 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005177 codegen_->InvokeRuntime(instruction->GetEntrypoint(), instruction, instruction->GetDexPc());
David Brazdil6de19382016-01-08 17:37:10 +00005178 CheckEntrypointTypes<kQuickAllocObjectWithAccessCheck, void*, uint32_t, ArtMethod*>();
5179 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005180}
5181
5182void LocationsBuilderMIPS::VisitNot(HNot* instruction) {
5183 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
5184 locations->SetInAt(0, Location::RequiresRegister());
5185 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5186}
5187
5188void InstructionCodeGeneratorMIPS::VisitNot(HNot* instruction) {
5189 Primitive::Type type = instruction->GetType();
5190 LocationSummary* locations = instruction->GetLocations();
5191
5192 switch (type) {
5193 case Primitive::kPrimInt: {
5194 Register dst = locations->Out().AsRegister<Register>();
5195 Register src = locations->InAt(0).AsRegister<Register>();
5196 __ Nor(dst, src, ZERO);
5197 break;
5198 }
5199
5200 case Primitive::kPrimLong: {
5201 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5202 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5203 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5204 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5205 __ Nor(dst_high, src_high, ZERO);
5206 __ Nor(dst_low, src_low, ZERO);
5207 break;
5208 }
5209
5210 default:
5211 LOG(FATAL) << "Unexpected type for not operation " << instruction->GetResultType();
5212 }
5213}
5214
5215void LocationsBuilderMIPS::VisitBooleanNot(HBooleanNot* instruction) {
5216 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
5217 locations->SetInAt(0, Location::RequiresRegister());
5218 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5219}
5220
5221void InstructionCodeGeneratorMIPS::VisitBooleanNot(HBooleanNot* instruction) {
5222 LocationSummary* locations = instruction->GetLocations();
5223 __ Xori(locations->Out().AsRegister<Register>(),
5224 locations->InAt(0).AsRegister<Register>(),
5225 1);
5226}
5227
5228void LocationsBuilderMIPS::VisitNullCheck(HNullCheck* instruction) {
Vladimir Marko804b03f2016-09-14 16:26:36 +01005229 LocationSummary* locations = codegen_->CreateThrowingSlowPathLocations(instruction);
5230 locations->SetInAt(0, Location::RequiresRegister());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005231}
5232
Calin Juravle2ae48182016-03-16 14:05:09 +00005233void CodeGeneratorMIPS::GenerateImplicitNullCheck(HNullCheck* instruction) {
5234 if (CanMoveNullCheckToUser(instruction)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005235 return;
5236 }
5237 Location obj = instruction->GetLocations()->InAt(0);
5238
5239 __ Lw(ZERO, obj.AsRegister<Register>(), 0);
Calin Juravle2ae48182016-03-16 14:05:09 +00005240 RecordPcInfo(instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005241}
5242
Calin Juravle2ae48182016-03-16 14:05:09 +00005243void CodeGeneratorMIPS::GenerateExplicitNullCheck(HNullCheck* instruction) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005244 SlowPathCodeMIPS* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathMIPS(instruction);
Calin Juravle2ae48182016-03-16 14:05:09 +00005245 AddSlowPath(slow_path);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005246
5247 Location obj = instruction->GetLocations()->InAt(0);
5248
5249 __ Beqz(obj.AsRegister<Register>(), slow_path->GetEntryLabel());
5250}
5251
5252void InstructionCodeGeneratorMIPS::VisitNullCheck(HNullCheck* instruction) {
Calin Juravle2ae48182016-03-16 14:05:09 +00005253 codegen_->GenerateNullCheck(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005254}
5255
5256void LocationsBuilderMIPS::VisitOr(HOr* instruction) {
5257 HandleBinaryOp(instruction);
5258}
5259
5260void InstructionCodeGeneratorMIPS::VisitOr(HOr* instruction) {
5261 HandleBinaryOp(instruction);
5262}
5263
5264void LocationsBuilderMIPS::VisitParallelMove(HParallelMove* instruction ATTRIBUTE_UNUSED) {
5265 LOG(FATAL) << "Unreachable";
5266}
5267
5268void InstructionCodeGeneratorMIPS::VisitParallelMove(HParallelMove* instruction) {
5269 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
5270}
5271
5272void LocationsBuilderMIPS::VisitParameterValue(HParameterValue* instruction) {
5273 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
5274 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
5275 if (location.IsStackSlot()) {
5276 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
5277 } else if (location.IsDoubleStackSlot()) {
5278 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
5279 }
5280 locations->SetOut(location);
5281}
5282
5283void InstructionCodeGeneratorMIPS::VisitParameterValue(HParameterValue* instruction
5284 ATTRIBUTE_UNUSED) {
5285 // Nothing to do, the parameter is already at its location.
5286}
5287
5288void LocationsBuilderMIPS::VisitCurrentMethod(HCurrentMethod* instruction) {
5289 LocationSummary* locations =
5290 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
5291 locations->SetOut(Location::RegisterLocation(kMethodRegisterArgument));
5292}
5293
5294void InstructionCodeGeneratorMIPS::VisitCurrentMethod(HCurrentMethod* instruction
5295 ATTRIBUTE_UNUSED) {
5296 // Nothing to do, the method is already at its location.
5297}
5298
5299void LocationsBuilderMIPS::VisitPhi(HPhi* instruction) {
5300 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Vladimir Marko372f10e2016-05-17 16:30:10 +01005301 for (size_t i = 0, e = locations->GetInputCount(); i < e; ++i) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005302 locations->SetInAt(i, Location::Any());
5303 }
5304 locations->SetOut(Location::Any());
5305}
5306
5307void InstructionCodeGeneratorMIPS::VisitPhi(HPhi* instruction ATTRIBUTE_UNUSED) {
5308 LOG(FATAL) << "Unreachable";
5309}
5310
5311void LocationsBuilderMIPS::VisitRem(HRem* rem) {
5312 Primitive::Type type = rem->GetResultType();
5313 LocationSummary::CallKind call_kind =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005314 (type == Primitive::kPrimInt) ? LocationSummary::kNoCall : LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005315 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
5316
5317 switch (type) {
5318 case Primitive::kPrimInt:
5319 locations->SetInAt(0, Location::RequiresRegister());
Alexey Frunze7e99e052015-11-24 19:28:01 -08005320 locations->SetInAt(1, Location::RegisterOrConstant(rem->InputAt(1)));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005321 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5322 break;
5323
5324 case Primitive::kPrimLong: {
5325 InvokeRuntimeCallingConvention calling_convention;
5326 locations->SetInAt(0, Location::RegisterPairLocation(
5327 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5328 locations->SetInAt(1, Location::RegisterPairLocation(
5329 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
5330 locations->SetOut(calling_convention.GetReturnLocation(type));
5331 break;
5332 }
5333
5334 case Primitive::kPrimFloat:
5335 case Primitive::kPrimDouble: {
5336 InvokeRuntimeCallingConvention calling_convention;
5337 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5338 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
5339 locations->SetOut(calling_convention.GetReturnLocation(type));
5340 break;
5341 }
5342
5343 default:
5344 LOG(FATAL) << "Unexpected rem type " << type;
5345 }
5346}
5347
5348void InstructionCodeGeneratorMIPS::VisitRem(HRem* instruction) {
5349 Primitive::Type type = instruction->GetType();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005350
5351 switch (type) {
Alexey Frunze7e99e052015-11-24 19:28:01 -08005352 case Primitive::kPrimInt:
5353 GenerateDivRemIntegral(instruction);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005354 break;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005355 case Primitive::kPrimLong: {
Serban Constantinescufca16662016-07-14 09:21:59 +01005356 codegen_->InvokeRuntime(kQuickLmod, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005357 CheckEntrypointTypes<kQuickLmod, int64_t, int64_t, int64_t>();
5358 break;
5359 }
5360 case Primitive::kPrimFloat: {
Serban Constantinescufca16662016-07-14 09:21:59 +01005361 codegen_->InvokeRuntime(kQuickFmodf, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005362 CheckEntrypointTypes<kQuickFmodf, float, float, float>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005363 break;
5364 }
5365 case Primitive::kPrimDouble: {
Serban Constantinescufca16662016-07-14 09:21:59 +01005366 codegen_->InvokeRuntime(kQuickFmod, instruction, instruction->GetDexPc());
Roland Levillain888d0672015-11-23 18:53:50 +00005367 CheckEntrypointTypes<kQuickFmod, double, double, double>();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005368 break;
5369 }
5370 default:
5371 LOG(FATAL) << "Unexpected rem type " << type;
5372 }
5373}
5374
5375void LocationsBuilderMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5376 memory_barrier->SetLocations(nullptr);
5377}
5378
5379void InstructionCodeGeneratorMIPS::VisitMemoryBarrier(HMemoryBarrier* memory_barrier) {
5380 GenerateMemoryBarrier(memory_barrier->GetBarrierKind());
5381}
5382
5383void LocationsBuilderMIPS::VisitReturn(HReturn* ret) {
5384 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(ret);
5385 Primitive::Type return_type = ret->InputAt(0)->GetType();
5386 locations->SetInAt(0, MipsReturnLocation(return_type));
5387}
5388
5389void InstructionCodeGeneratorMIPS::VisitReturn(HReturn* ret ATTRIBUTE_UNUSED) {
5390 codegen_->GenerateFrameExit();
5391}
5392
5393void LocationsBuilderMIPS::VisitReturnVoid(HReturnVoid* ret) {
5394 ret->SetLocations(nullptr);
5395}
5396
5397void InstructionCodeGeneratorMIPS::VisitReturnVoid(HReturnVoid* ret ATTRIBUTE_UNUSED) {
5398 codegen_->GenerateFrameExit();
5399}
5400
Alexey Frunze92d90602015-12-18 18:16:36 -08005401void LocationsBuilderMIPS::VisitRor(HRor* ror) {
5402 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005403}
5404
Alexey Frunze92d90602015-12-18 18:16:36 -08005405void InstructionCodeGeneratorMIPS::VisitRor(HRor* ror) {
5406 HandleShift(ror);
Scott Wakeling40a04bf2015-12-11 09:50:36 +00005407}
5408
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005409void LocationsBuilderMIPS::VisitShl(HShl* shl) {
5410 HandleShift(shl);
5411}
5412
5413void InstructionCodeGeneratorMIPS::VisitShl(HShl* shl) {
5414 HandleShift(shl);
5415}
5416
5417void LocationsBuilderMIPS::VisitShr(HShr* shr) {
5418 HandleShift(shr);
5419}
5420
5421void InstructionCodeGeneratorMIPS::VisitShr(HShr* shr) {
5422 HandleShift(shr);
5423}
5424
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005425void LocationsBuilderMIPS::VisitSub(HSub* instruction) {
5426 HandleBinaryOp(instruction);
5427}
5428
5429void InstructionCodeGeneratorMIPS::VisitSub(HSub* instruction) {
5430 HandleBinaryOp(instruction);
5431}
5432
5433void LocationsBuilderMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5434 HandleFieldGet(instruction, instruction->GetFieldInfo());
5435}
5436
5437void InstructionCodeGeneratorMIPS::VisitStaticFieldGet(HStaticFieldGet* instruction) {
5438 HandleFieldGet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5439}
5440
5441void LocationsBuilderMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5442 HandleFieldSet(instruction, instruction->GetFieldInfo());
5443}
5444
5445void InstructionCodeGeneratorMIPS::VisitStaticFieldSet(HStaticFieldSet* instruction) {
5446 HandleFieldSet(instruction, instruction->GetFieldInfo(), instruction->GetDexPc());
5447}
5448
5449void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldGet(
5450 HUnresolvedInstanceFieldGet* instruction) {
5451 FieldAccessCallingConventionMIPS calling_convention;
5452 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5453 instruction->GetFieldType(),
5454 calling_convention);
5455}
5456
5457void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldGet(
5458 HUnresolvedInstanceFieldGet* instruction) {
5459 FieldAccessCallingConventionMIPS calling_convention;
5460 codegen_->GenerateUnresolvedFieldAccess(instruction,
5461 instruction->GetFieldType(),
5462 instruction->GetFieldIndex(),
5463 instruction->GetDexPc(),
5464 calling_convention);
5465}
5466
5467void LocationsBuilderMIPS::VisitUnresolvedInstanceFieldSet(
5468 HUnresolvedInstanceFieldSet* instruction) {
5469 FieldAccessCallingConventionMIPS calling_convention;
5470 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5471 instruction->GetFieldType(),
5472 calling_convention);
5473}
5474
5475void InstructionCodeGeneratorMIPS::VisitUnresolvedInstanceFieldSet(
5476 HUnresolvedInstanceFieldSet* instruction) {
5477 FieldAccessCallingConventionMIPS calling_convention;
5478 codegen_->GenerateUnresolvedFieldAccess(instruction,
5479 instruction->GetFieldType(),
5480 instruction->GetFieldIndex(),
5481 instruction->GetDexPc(),
5482 calling_convention);
5483}
5484
5485void LocationsBuilderMIPS::VisitUnresolvedStaticFieldGet(
5486 HUnresolvedStaticFieldGet* instruction) {
5487 FieldAccessCallingConventionMIPS calling_convention;
5488 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5489 instruction->GetFieldType(),
5490 calling_convention);
5491}
5492
5493void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldGet(
5494 HUnresolvedStaticFieldGet* instruction) {
5495 FieldAccessCallingConventionMIPS calling_convention;
5496 codegen_->GenerateUnresolvedFieldAccess(instruction,
5497 instruction->GetFieldType(),
5498 instruction->GetFieldIndex(),
5499 instruction->GetDexPc(),
5500 calling_convention);
5501}
5502
5503void LocationsBuilderMIPS::VisitUnresolvedStaticFieldSet(
5504 HUnresolvedStaticFieldSet* instruction) {
5505 FieldAccessCallingConventionMIPS calling_convention;
5506 codegen_->CreateUnresolvedFieldLocationSummary(instruction,
5507 instruction->GetFieldType(),
5508 calling_convention);
5509}
5510
5511void InstructionCodeGeneratorMIPS::VisitUnresolvedStaticFieldSet(
5512 HUnresolvedStaticFieldSet* instruction) {
5513 FieldAccessCallingConventionMIPS calling_convention;
5514 codegen_->GenerateUnresolvedFieldAccess(instruction,
5515 instruction->GetFieldType(),
5516 instruction->GetFieldIndex(),
5517 instruction->GetDexPc(),
5518 calling_convention);
5519}
5520
5521void LocationsBuilderMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
Vladimir Marko70e97462016-08-09 11:04:26 +01005522 LocationSummary* locations =
5523 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
Vladimir Marko804b03f2016-09-14 16:26:36 +01005524 locations->SetCustomSlowPathCallerSaves(RegisterSet::Empty()); // No caller-save registers.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005525}
5526
5527void InstructionCodeGeneratorMIPS::VisitSuspendCheck(HSuspendCheck* instruction) {
5528 HBasicBlock* block = instruction->GetBlock();
5529 if (block->GetLoopInformation() != nullptr) {
5530 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
5531 // The back edge will generate the suspend check.
5532 return;
5533 }
5534 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
5535 // The goto will generate the suspend check.
5536 return;
5537 }
5538 GenerateSuspendCheck(instruction, nullptr);
5539}
5540
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005541void LocationsBuilderMIPS::VisitThrow(HThrow* instruction) {
5542 LocationSummary* locations =
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005543 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnMainOnly);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005544 InvokeRuntimeCallingConvention calling_convention;
5545 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
5546}
5547
5548void InstructionCodeGeneratorMIPS::VisitThrow(HThrow* instruction) {
Serban Constantinescufca16662016-07-14 09:21:59 +01005549 codegen_->InvokeRuntime(kQuickDeliverException, instruction, instruction->GetDexPc());
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005550 CheckEntrypointTypes<kQuickDeliverException, void, mirror::Object*>();
5551}
5552
5553void LocationsBuilderMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5554 Primitive::Type input_type = conversion->GetInputType();
5555 Primitive::Type result_type = conversion->GetResultType();
5556 DCHECK_NE(input_type, result_type);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005557 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005558
5559 if ((input_type == Primitive::kPrimNot) || (input_type == Primitive::kPrimVoid) ||
5560 (result_type == Primitive::kPrimNot) || (result_type == Primitive::kPrimVoid)) {
5561 LOG(FATAL) << "Unexpected type conversion from " << input_type << " to " << result_type;
5562 }
5563
5564 LocationSummary::CallKind call_kind = LocationSummary::kNoCall;
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005565 if (!isR6 &&
5566 ((Primitive::IsFloatingPointType(result_type) && input_type == Primitive::kPrimLong) ||
5567 (result_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(input_type)))) {
Serban Constantinescu54ff4822016-07-07 18:03:19 +01005568 call_kind = LocationSummary::kCallOnMainOnly;
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005569 }
5570
5571 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
5572
5573 if (call_kind == LocationSummary::kNoCall) {
5574 if (Primitive::IsFloatingPointType(input_type)) {
5575 locations->SetInAt(0, Location::RequiresFpuRegister());
5576 } else {
5577 locations->SetInAt(0, Location::RequiresRegister());
5578 }
5579
5580 if (Primitive::IsFloatingPointType(result_type)) {
5581 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
5582 } else {
5583 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
5584 }
5585 } else {
5586 InvokeRuntimeCallingConvention calling_convention;
5587
5588 if (Primitive::IsFloatingPointType(input_type)) {
5589 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
5590 } else {
5591 DCHECK_EQ(input_type, Primitive::kPrimLong);
5592 locations->SetInAt(0, Location::RegisterPairLocation(
5593 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
5594 }
5595
5596 locations->SetOut(calling_convention.GetReturnLocation(result_type));
5597 }
5598}
5599
5600void InstructionCodeGeneratorMIPS::VisitTypeConversion(HTypeConversion* conversion) {
5601 LocationSummary* locations = conversion->GetLocations();
5602 Primitive::Type result_type = conversion->GetResultType();
5603 Primitive::Type input_type = conversion->GetInputType();
5604 bool has_sign_extension = codegen_->GetInstructionSetFeatures().IsMipsIsaRevGreaterThanEqual2();
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005605 bool isR6 = codegen_->GetInstructionSetFeatures().IsR6();
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005606
5607 DCHECK_NE(input_type, result_type);
5608
5609 if (result_type == Primitive::kPrimLong && Primitive::IsIntegralType(input_type)) {
5610 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5611 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5612 Register src = locations->InAt(0).AsRegister<Register>();
5613
Alexey Frunzea871ef12016-06-27 15:20:11 -07005614 if (dst_low != src) {
5615 __ Move(dst_low, src);
5616 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005617 __ Sra(dst_high, src, 31);
5618 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type)) {
5619 Register dst = locations->Out().AsRegister<Register>();
5620 Register src = (input_type == Primitive::kPrimLong)
5621 ? locations->InAt(0).AsRegisterPairLow<Register>()
5622 : locations->InAt(0).AsRegister<Register>();
5623
5624 switch (result_type) {
5625 case Primitive::kPrimChar:
5626 __ Andi(dst, src, 0xFFFF);
5627 break;
5628 case Primitive::kPrimByte:
5629 if (has_sign_extension) {
5630 __ Seb(dst, src);
5631 } else {
5632 __ Sll(dst, src, 24);
5633 __ Sra(dst, dst, 24);
5634 }
5635 break;
5636 case Primitive::kPrimShort:
5637 if (has_sign_extension) {
5638 __ Seh(dst, src);
5639 } else {
5640 __ Sll(dst, src, 16);
5641 __ Sra(dst, dst, 16);
5642 }
5643 break;
5644 case Primitive::kPrimInt:
Alexey Frunzea871ef12016-06-27 15:20:11 -07005645 if (dst != src) {
5646 __ Move(dst, src);
5647 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005648 break;
5649
5650 default:
5651 LOG(FATAL) << "Unexpected type conversion from " << input_type
5652 << " to " << result_type;
5653 }
5654 } else if (Primitive::IsFloatingPointType(result_type) && Primitive::IsIntegralType(input_type)) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005655 if (input_type == Primitive::kPrimLong) {
5656 if (isR6) {
5657 // cvt.s.l/cvt.d.l requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5658 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5659 Register src_high = locations->InAt(0).AsRegisterPairHigh<Register>();
5660 Register src_low = locations->InAt(0).AsRegisterPairLow<Register>();
5661 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5662 __ Mtc1(src_low, FTMP);
5663 __ Mthc1(src_high, FTMP);
5664 if (result_type == Primitive::kPrimFloat) {
5665 __ Cvtsl(dst, FTMP);
5666 } else {
5667 __ Cvtdl(dst, FTMP);
5668 }
5669 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005670 QuickEntrypointEnum entrypoint = (result_type == Primitive::kPrimFloat) ? kQuickL2f
5671 : kQuickL2d;
5672 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005673 if (result_type == Primitive::kPrimFloat) {
5674 CheckEntrypointTypes<kQuickL2f, float, int64_t>();
5675 } else {
5676 CheckEntrypointTypes<kQuickL2d, double, int64_t>();
5677 }
5678 }
5679 } else {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005680 Register src = locations->InAt(0).AsRegister<Register>();
5681 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5682 __ Mtc1(src, FTMP);
5683 if (result_type == Primitive::kPrimFloat) {
5684 __ Cvtsw(dst, FTMP);
5685 } else {
5686 __ Cvtdw(dst, FTMP);
5687 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005688 }
5689 } else if (Primitive::IsIntegralType(result_type) && Primitive::IsFloatingPointType(input_type)) {
5690 CHECK(result_type == Primitive::kPrimInt || result_type == Primitive::kPrimLong);
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005691 if (result_type == Primitive::kPrimLong) {
5692 if (isR6) {
5693 // trunc.l.s/trunc.l.d requires MIPSR2+ with FR=1. MIPS32R6 is implemented as a secondary
5694 // architecture on top of MIPS64R6, which has FR=1, and therefore can use the instruction.
5695 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5696 Register dst_high = locations->Out().AsRegisterPairHigh<Register>();
5697 Register dst_low = locations->Out().AsRegisterPairLow<Register>();
5698 MipsLabel truncate;
5699 MipsLabel done;
5700
5701 // When NAN2008=0 (R2 and before), the truncate instruction produces the maximum positive
5702 // value when the input is either a NaN or is outside of the range of the output type
5703 // after the truncation. IOW, the three special cases (NaN, too small, too big) produce
5704 // the same result.
5705 //
5706 // When NAN2008=1 (R6), the truncate instruction caps the output at the minimum/maximum
5707 // value of the output type if the input is outside of the range after the truncation or
5708 // produces 0 when the input is a NaN. IOW, the three special cases produce three distinct
5709 // results. This matches the desired float/double-to-int/long conversion exactly.
5710 //
5711 // So, NAN2008 affects handling of negative values and NaNs by the truncate instruction.
5712 //
5713 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5714 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5715 // even though it must be NAN2008=1 on R6.
5716 //
5717 // The code takes care of the different behaviors by first comparing the input to the
5718 // minimum output value (-2**-63 for truncating to long, -2**-31 for truncating to int).
5719 // If the input is greater than or equal to the minimum, it procedes to the truncate
5720 // instruction, which will handle such an input the same way irrespective of NAN2008.
5721 // Otherwise the input is compared to itself to determine whether it is a NaN or not
5722 // in order to return either zero or the minimum value.
5723 //
5724 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5725 // truncate instruction for MIPS64R6.
5726 if (input_type == Primitive::kPrimFloat) {
5727 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int64_t>::min());
5728 __ LoadConst32(TMP, min_val);
5729 __ Mtc1(TMP, FTMP);
5730 __ CmpLeS(FTMP, FTMP, src);
5731 } else {
5732 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int64_t>::min());
5733 __ LoadConst32(TMP, High32Bits(min_val));
5734 __ Mtc1(ZERO, FTMP);
5735 __ Mthc1(TMP, FTMP);
5736 __ CmpLeD(FTMP, FTMP, src);
5737 }
5738
5739 __ Bc1nez(FTMP, &truncate);
5740
5741 if (input_type == Primitive::kPrimFloat) {
5742 __ CmpEqS(FTMP, src, src);
5743 } else {
5744 __ CmpEqD(FTMP, src, src);
5745 }
5746 __ Move(dst_low, ZERO);
5747 __ LoadConst32(dst_high, std::numeric_limits<int32_t>::min());
5748 __ Mfc1(TMP, FTMP);
5749 __ And(dst_high, dst_high, TMP);
5750
5751 __ B(&done);
5752
5753 __ Bind(&truncate);
5754
5755 if (input_type == Primitive::kPrimFloat) {
5756 __ TruncLS(FTMP, src);
5757 } else {
5758 __ TruncLD(FTMP, src);
5759 }
5760 __ Mfc1(dst_low, FTMP);
5761 __ Mfhc1(dst_high, FTMP);
5762
5763 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005764 } else {
Serban Constantinescufca16662016-07-14 09:21:59 +01005765 QuickEntrypointEnum entrypoint = (input_type == Primitive::kPrimFloat) ? kQuickF2l
5766 : kQuickD2l;
5767 codegen_->InvokeRuntime(entrypoint, conversion, conversion->GetDexPc());
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005768 if (input_type == Primitive::kPrimFloat) {
5769 CheckEntrypointTypes<kQuickF2l, int64_t, float>();
5770 } else {
5771 CheckEntrypointTypes<kQuickD2l, int64_t, double>();
5772 }
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005773 }
5774 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005775 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5776 Register dst = locations->Out().AsRegister<Register>();
5777 MipsLabel truncate;
5778 MipsLabel done;
5779
5780 // The following code supports both NAN2008=0 and NAN2008=1 behaviors of the truncate
5781 // instruction, the reason being that the emulator implements NAN2008=0 on MIPS64R6,
5782 // even though it must be NAN2008=1 on R6.
5783 //
5784 // For details see the large comment above for the truncation of float/double to long on R6.
5785 //
5786 // TODO: simplify this when the emulator correctly implements NAN2008=1 behavior of the
5787 // truncate instruction for MIPS64R6.
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005788 if (input_type == Primitive::kPrimFloat) {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005789 uint32_t min_val = bit_cast<uint32_t, float>(std::numeric_limits<int32_t>::min());
5790 __ LoadConst32(TMP, min_val);
5791 __ Mtc1(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005792 } else {
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005793 uint64_t min_val = bit_cast<uint64_t, double>(std::numeric_limits<int32_t>::min());
5794 __ LoadConst32(TMP, High32Bits(min_val));
5795 __ Mtc1(ZERO, FTMP);
Alexey Frunzea871ef12016-06-27 15:20:11 -07005796 __ MoveToFpuHigh(TMP, FTMP);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005797 }
Alexey Frunzebaf60b72015-12-22 15:15:03 -08005798
5799 if (isR6) {
5800 if (input_type == Primitive::kPrimFloat) {
5801 __ CmpLeS(FTMP, FTMP, src);
5802 } else {
5803 __ CmpLeD(FTMP, FTMP, src);
5804 }
5805 __ Bc1nez(FTMP, &truncate);
5806
5807 if (input_type == Primitive::kPrimFloat) {
5808 __ CmpEqS(FTMP, src, src);
5809 } else {
5810 __ CmpEqD(FTMP, src, src);
5811 }
5812 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5813 __ Mfc1(TMP, FTMP);
5814 __ And(dst, dst, TMP);
5815 } else {
5816 if (input_type == Primitive::kPrimFloat) {
5817 __ ColeS(0, FTMP, src);
5818 } else {
5819 __ ColeD(0, FTMP, src);
5820 }
5821 __ Bc1t(0, &truncate);
5822
5823 if (input_type == Primitive::kPrimFloat) {
5824 __ CeqS(0, src, src);
5825 } else {
5826 __ CeqD(0, src, src);
5827 }
5828 __ LoadConst32(dst, std::numeric_limits<int32_t>::min());
5829 __ Movf(dst, ZERO, 0);
5830 }
5831
5832 __ B(&done);
5833
5834 __ Bind(&truncate);
5835
5836 if (input_type == Primitive::kPrimFloat) {
5837 __ TruncWS(FTMP, src);
5838 } else {
5839 __ TruncWD(FTMP, src);
5840 }
5841 __ Mfc1(dst, FTMP);
5842
5843 __ Bind(&done);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005844 }
5845 } else if (Primitive::IsFloatingPointType(result_type) &&
5846 Primitive::IsFloatingPointType(input_type)) {
5847 FRegister dst = locations->Out().AsFpuRegister<FRegister>();
5848 FRegister src = locations->InAt(0).AsFpuRegister<FRegister>();
5849 if (result_type == Primitive::kPrimFloat) {
5850 __ Cvtsd(dst, src);
5851 } else {
5852 __ Cvtds(dst, src);
5853 }
5854 } else {
5855 LOG(FATAL) << "Unexpected or unimplemented type conversion from " << input_type
5856 << " to " << result_type;
5857 }
5858}
5859
5860void LocationsBuilderMIPS::VisitUShr(HUShr* ushr) {
5861 HandleShift(ushr);
5862}
5863
5864void InstructionCodeGeneratorMIPS::VisitUShr(HUShr* ushr) {
5865 HandleShift(ushr);
5866}
5867
5868void LocationsBuilderMIPS::VisitXor(HXor* instruction) {
5869 HandleBinaryOp(instruction);
5870}
5871
5872void InstructionCodeGeneratorMIPS::VisitXor(HXor* instruction) {
5873 HandleBinaryOp(instruction);
5874}
5875
5876void LocationsBuilderMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5877 // Nothing to do, this should be removed during prepare for register allocator.
5878 LOG(FATAL) << "Unreachable";
5879}
5880
5881void InstructionCodeGeneratorMIPS::VisitBoundType(HBoundType* instruction ATTRIBUTE_UNUSED) {
5882 // Nothing to do, this should be removed during prepare for register allocator.
5883 LOG(FATAL) << "Unreachable";
5884}
5885
5886void LocationsBuilderMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005887 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005888}
5889
5890void InstructionCodeGeneratorMIPS::VisitEqual(HEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005891 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005892}
5893
5894void LocationsBuilderMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005895 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005896}
5897
5898void InstructionCodeGeneratorMIPS::VisitNotEqual(HNotEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005899 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005900}
5901
5902void LocationsBuilderMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005903 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005904}
5905
5906void InstructionCodeGeneratorMIPS::VisitLessThan(HLessThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005907 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005908}
5909
5910void LocationsBuilderMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005911 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005912}
5913
5914void InstructionCodeGeneratorMIPS::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005915 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005916}
5917
5918void LocationsBuilderMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005919 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005920}
5921
5922void InstructionCodeGeneratorMIPS::VisitGreaterThan(HGreaterThan* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005923 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005924}
5925
5926void LocationsBuilderMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005927 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005928}
5929
5930void InstructionCodeGeneratorMIPS::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005931 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005932}
5933
5934void LocationsBuilderMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005935 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005936}
5937
5938void InstructionCodeGeneratorMIPS::VisitBelow(HBelow* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005939 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005940}
5941
5942void LocationsBuilderMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005943 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005944}
5945
5946void InstructionCodeGeneratorMIPS::VisitBelowOrEqual(HBelowOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005947 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005948}
5949
5950void LocationsBuilderMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005951 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005952}
5953
5954void InstructionCodeGeneratorMIPS::VisitAbove(HAbove* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005955 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005956}
5957
5958void LocationsBuilderMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005959 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005960}
5961
5962void InstructionCodeGeneratorMIPS::VisitAboveOrEqual(HAboveOrEqual* comp) {
Vladimir Marko5f7b58e2015-11-23 19:49:34 +00005963 HandleCondition(comp);
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005964}
5965
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005966void LocationsBuilderMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
5967 LocationSummary* locations =
5968 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
5969 locations->SetInAt(0, Location::RequiresRegister());
5970}
5971
Alexey Frunze96b66822016-09-10 02:32:44 -07005972void InstructionCodeGeneratorMIPS::GenPackedSwitchWithCompares(Register value_reg,
5973 int32_t lower_bound,
5974 uint32_t num_entries,
5975 HBasicBlock* switch_block,
5976 HBasicBlock* default_block) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02005977 // Create a set of compare/jumps.
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005978 Register temp_reg = TMP;
5979 __ Addiu32(temp_reg, value_reg, -lower_bound);
5980 // Jump to default if index is negative
5981 // Note: We don't check the case that index is positive while value < lower_bound, because in
5982 // this case, index >= num_entries must be true. So that we can save one branch instruction.
5983 __ Bltz(temp_reg, codegen_->GetLabelOf(default_block));
5984
Alexey Frunze96b66822016-09-10 02:32:44 -07005985 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
Vladimir Markof3e0ee22015-12-17 15:23:13 +00005986 // Jump to successors[0] if value == lower_bound.
5987 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[0]));
5988 int32_t last_index = 0;
5989 for (; num_entries - last_index > 2; last_index += 2) {
5990 __ Addiu(temp_reg, temp_reg, -2);
5991 // Jump to successors[last_index + 1] if value < case_value[last_index + 2].
5992 __ Bltz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
5993 // Jump to successors[last_index + 2] if value == case_value[last_index + 2].
5994 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 2]));
5995 }
5996 if (num_entries - last_index == 2) {
5997 // The last missing case_value.
5998 __ Addiu(temp_reg, temp_reg, -1);
5999 __ Beqz(temp_reg, codegen_->GetLabelOf(successors[last_index + 1]));
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006000 }
6001
Vladimir Markof3e0ee22015-12-17 15:23:13 +00006002 // And the default for any other value.
Alexey Frunze96b66822016-09-10 02:32:44 -07006003 if (!codegen_->GoesToNextBlock(switch_block, default_block)) {
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006004 __ B(codegen_->GetLabelOf(default_block));
6005 }
6006}
6007
Alexey Frunze96b66822016-09-10 02:32:44 -07006008void InstructionCodeGeneratorMIPS::GenTableBasedPackedSwitch(Register value_reg,
6009 Register constant_area,
6010 int32_t lower_bound,
6011 uint32_t num_entries,
6012 HBasicBlock* switch_block,
6013 HBasicBlock* default_block) {
6014 // Create a jump table.
6015 std::vector<MipsLabel*> labels(num_entries);
6016 const ArenaVector<HBasicBlock*>& successors = switch_block->GetSuccessors();
6017 for (uint32_t i = 0; i < num_entries; i++) {
6018 labels[i] = codegen_->GetLabelOf(successors[i]);
6019 }
6020 JumpTable* table = __ CreateJumpTable(std::move(labels));
6021
6022 // Is the value in range?
6023 __ Addiu32(TMP, value_reg, -lower_bound);
6024 if (IsInt<16>(static_cast<int32_t>(num_entries))) {
6025 __ Sltiu(AT, TMP, num_entries);
6026 __ Beqz(AT, codegen_->GetLabelOf(default_block));
6027 } else {
6028 __ LoadConst32(AT, num_entries);
6029 __ Bgeu(TMP, AT, codegen_->GetLabelOf(default_block));
6030 }
6031
6032 // We are in the range of the table.
6033 // Load the target address from the jump table, indexing by the value.
6034 __ LoadLabelAddress(AT, constant_area, table->GetLabel());
6035 __ Sll(TMP, TMP, 2);
6036 __ Addu(TMP, TMP, AT);
6037 __ Lw(TMP, TMP, 0);
6038 // Compute the absolute target address by adding the table start address
6039 // (the table contains offsets to targets relative to its start).
6040 __ Addu(TMP, TMP, AT);
6041 // And jump.
6042 __ Jr(TMP);
6043 __ NopIfNoReordering();
6044}
6045
6046void InstructionCodeGeneratorMIPS::VisitPackedSwitch(HPackedSwitch* switch_instr) {
6047 int32_t lower_bound = switch_instr->GetStartValue();
6048 uint32_t num_entries = switch_instr->GetNumEntries();
6049 LocationSummary* locations = switch_instr->GetLocations();
6050 Register value_reg = locations->InAt(0).AsRegister<Register>();
6051 HBasicBlock* switch_block = switch_instr->GetBlock();
6052 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
6053
6054 if (codegen_->GetInstructionSetFeatures().IsR6() &&
6055 num_entries > kPackedSwitchJumpTableThreshold) {
6056 // R6 uses PC-relative addressing to access the jump table.
6057 // R2, OTOH, requires an HMipsComputeBaseMethodAddress input to access
6058 // the jump table and it is implemented by changing HPackedSwitch to
6059 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress.
6060 // See VisitMipsPackedSwitch() for the table-based implementation on R2.
6061 GenTableBasedPackedSwitch(value_reg,
6062 ZERO,
6063 lower_bound,
6064 num_entries,
6065 switch_block,
6066 default_block);
6067 } else {
6068 GenPackedSwitchWithCompares(value_reg,
6069 lower_bound,
6070 num_entries,
6071 switch_block,
6072 default_block);
6073 }
6074}
6075
6076void LocationsBuilderMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
6077 LocationSummary* locations =
6078 new (GetGraph()->GetArena()) LocationSummary(switch_instr, LocationSummary::kNoCall);
6079 locations->SetInAt(0, Location::RequiresRegister());
6080 // Constant area pointer (HMipsComputeBaseMethodAddress).
6081 locations->SetInAt(1, Location::RequiresRegister());
6082}
6083
6084void InstructionCodeGeneratorMIPS::VisitMipsPackedSwitch(HMipsPackedSwitch* switch_instr) {
6085 int32_t lower_bound = switch_instr->GetStartValue();
6086 uint32_t num_entries = switch_instr->GetNumEntries();
6087 LocationSummary* locations = switch_instr->GetLocations();
6088 Register value_reg = locations->InAt(0).AsRegister<Register>();
6089 Register constant_area = locations->InAt(1).AsRegister<Register>();
6090 HBasicBlock* switch_block = switch_instr->GetBlock();
6091 HBasicBlock* default_block = switch_instr->GetDefaultBlock();
6092
6093 // This is an R2-only path. HPackedSwitch has been changed to
6094 // HMipsPackedSwitch, which bears HMipsComputeBaseMethodAddress
6095 // required to address the jump table relative to PC.
6096 GenTableBasedPackedSwitch(value_reg,
6097 constant_area,
6098 lower_bound,
6099 num_entries,
6100 switch_block,
6101 default_block);
6102}
6103
Alexey Frunzee3fb2452016-05-10 16:08:05 -07006104void LocationsBuilderMIPS::VisitMipsComputeBaseMethodAddress(
6105 HMipsComputeBaseMethodAddress* insn) {
6106 LocationSummary* locations =
6107 new (GetGraph()->GetArena()) LocationSummary(insn, LocationSummary::kNoCall);
6108 locations->SetOut(Location::RequiresRegister());
6109}
6110
6111void InstructionCodeGeneratorMIPS::VisitMipsComputeBaseMethodAddress(
6112 HMipsComputeBaseMethodAddress* insn) {
6113 LocationSummary* locations = insn->GetLocations();
6114 Register reg = locations->Out().AsRegister<Register>();
6115
6116 CHECK(!codegen_->GetInstructionSetFeatures().IsR6());
6117
6118 // Generate a dummy PC-relative call to obtain PC.
6119 __ Nal();
6120 // Grab the return address off RA.
6121 __ Move(reg, RA);
Alexey Frunze06a46c42016-07-19 15:00:40 -07006122 // TODO: Can we share this code with that of VisitMipsDexCacheArraysBase()?
Alexey Frunzee3fb2452016-05-10 16:08:05 -07006123
6124 // Remember this offset (the obtained PC value) for later use with constant area.
6125 __ BindPcRelBaseLabel();
6126}
6127
6128void LocationsBuilderMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
6129 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(base);
6130 locations->SetOut(Location::RequiresRegister());
6131}
6132
6133void InstructionCodeGeneratorMIPS::VisitMipsDexCacheArraysBase(HMipsDexCacheArraysBase* base) {
6134 Register reg = base->GetLocations()->Out().AsRegister<Register>();
6135 CodeGeneratorMIPS::PcRelativePatchInfo* info =
6136 codegen_->NewPcRelativeDexCacheArrayPatch(base->GetDexFile(), base->GetElementOffset());
Vladimir Markoaad75c62016-10-03 08:46:48 +00006137 // TODO: Reuse MipsComputeBaseMethodAddress on R2 instead of passing ZERO to force emitting NAL.
6138 codegen_->EmitPcRelativeAddressPlaceholder(info, reg, ZERO);
Alexey Frunzee3fb2452016-05-10 16:08:05 -07006139}
6140
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006141void LocationsBuilderMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
6142 // The trampoline uses the same calling convention as dex calling conventions,
6143 // except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
6144 // the method_idx.
6145 HandleInvoke(invoke);
6146}
6147
6148void InstructionCodeGeneratorMIPS::VisitInvokeUnresolved(HInvokeUnresolved* invoke) {
6149 codegen_->GenerateInvokeUnresolvedRuntimeCall(invoke);
6150}
6151
Roland Levillain2aba7cd2016-02-03 12:27:20 +00006152void LocationsBuilderMIPS::VisitClassTableGet(HClassTableGet* instruction) {
6153 LocationSummary* locations =
6154 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
6155 locations->SetInAt(0, Location::RequiresRegister());
6156 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00006157}
6158
Roland Levillain2aba7cd2016-02-03 12:27:20 +00006159void InstructionCodeGeneratorMIPS::VisitClassTableGet(HClassTableGet* instruction) {
6160 LocationSummary* locations = instruction->GetLocations();
Vladimir Markoa1de9182016-02-25 11:37:38 +00006161 if (instruction->GetTableKind() == HClassTableGet::TableKind::kVTable) {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01006162 uint32_t method_offset = mirror::Class::EmbeddedVTableEntryOffset(
Roland Levillain2aba7cd2016-02-03 12:27:20 +00006163 instruction->GetIndex(), kMipsPointerSize).SizeValue();
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01006164 __ LoadFromOffset(kLoadWord,
6165 locations->Out().AsRegister<Register>(),
6166 locations->InAt(0).AsRegister<Register>(),
6167 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00006168 } else {
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01006169 uint32_t method_offset = static_cast<uint32_t>(ImTable::OffsetOfElement(
Matthew Gharrity465ecc82016-07-19 21:32:52 +00006170 instruction->GetIndex(), kMipsPointerSize));
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +00006171 __ LoadFromOffset(kLoadWord,
6172 locations->Out().AsRegister<Register>(),
6173 locations->InAt(0).AsRegister<Register>(),
6174 mirror::Class::ImtPtrOffset(kMipsPointerSize).Uint32Value());
Nicolas Geoffrayff484b92016-07-13 14:13:48 +01006175 __ LoadFromOffset(kLoadWord,
6176 locations->Out().AsRegister<Register>(),
6177 locations->Out().AsRegister<Register>(),
6178 method_offset);
Roland Levillain2aba7cd2016-02-03 12:27:20 +00006179 }
Nicolas Geoffraya42363f2015-12-17 14:57:09 +00006180}
6181
Goran Jakovljevicf652cec2015-08-25 16:11:42 +02006182#undef __
6183#undef QUICK_ENTRY_POINT
6184
6185} // namespace mips
6186} // namespace art