blob: 20b8b6a62d4dbfdd82035b7a0880f8a7db6b69f6 [file] [log] [blame]
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001/*
2 * Copyright (C) 2014 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_arm.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000018
Calin Juravle34166012014-12-19 17:22:29 +000019#include "arch/arm/instruction_set_features_arm.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070020#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010021#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070022#include "mirror/array-inl.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000023#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010024#include "mirror/class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070025#include "thread.h"
Nicolas Geoffray9cf35522014-06-09 18:40:10 +010026#include "utils/arm/assembler_arm.h"
27#include "utils/arm/managed_register_arm.h"
Roland Levillain946e1432014-11-11 17:35:19 +000028#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010029#include "utils/stack_checks.h"
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +000030
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000031namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010032
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000033namespace arm {
34
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000035static DRegister FromLowSToD(SRegister reg) {
36 DCHECK_EQ(reg % 2, 0);
37 return static_cast<DRegister>(reg / 2);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +010038}
39
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010040static constexpr bool kExplicitStackOverflowCheck = false;
41
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +000042static constexpr int kNumberOfPushedRegistersAtEntry = 1 + 2; // LR, R6, R7
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010043static constexpr int kCurrentMethodStackOffset = 0;
44
Calin Juravled6fb6cf2014-11-11 19:07:44 +000045static constexpr Register kRuntimeParameterCoreRegisters[] = { R0, R1, R2, R3 };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010046static constexpr size_t kRuntimeParameterCoreRegistersLength =
47 arraysize(kRuntimeParameterCoreRegisters);
Calin Juravled2ec87d2014-12-08 14:24:46 +000048static constexpr SRegister kRuntimeParameterFpuRegisters[] = { S0, S1, S2, S3 };
Roland Levillain624279f2014-12-04 11:54:28 +000049static constexpr size_t kRuntimeParameterFpuRegistersLength =
50 arraysize(kRuntimeParameterFpuRegisters);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010051
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +000052class InvokeRuntimeCallingConvention : public CallingConvention<Register, SRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010053 public:
54 InvokeRuntimeCallingConvention()
55 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010056 kRuntimeParameterCoreRegistersLength,
57 kRuntimeParameterFpuRegisters,
58 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010059
60 private:
61 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
62};
63
Nicolas Geoffraye5038322014-07-04 09:41:32 +010064#define __ reinterpret_cast<ArmAssembler*>(codegen->GetAssembler())->
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010065#define QUICK_ENTRY_POINT(x) QUICK_ENTRYPOINT_OFFSET(kArmWordSize, x).Int32Value()
Nicolas Geoffraye5038322014-07-04 09:41:32 +010066
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010067class SlowPathCodeARM : public SlowPathCode {
68 public:
69 SlowPathCodeARM() : entry_label_(), exit_label_() {}
70
71 Label* GetEntryLabel() { return &entry_label_; }
72 Label* GetExitLabel() { return &exit_label_; }
73
74 private:
75 Label entry_label_;
76 Label exit_label_;
77
78 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeARM);
79};
80
81class NullCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010082 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010083 explicit NullCheckSlowPathARM(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010084
Alexandre Rames67555f72014-11-18 10:55:16 +000085 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010086 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffraye5038322014-07-04 09:41:32 +010087 __ Bind(GetEntryLabel());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +010088 arm_codegen->InvokeRuntime(
89 QUICK_ENTRY_POINT(pThrowNullPointer), instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010090 }
91
92 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010093 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010094 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathARM);
95};
96
Calin Juravled0d48522014-11-04 16:40:20 +000097class DivZeroCheckSlowPathARM : public SlowPathCodeARM {
98 public:
99 explicit DivZeroCheckSlowPathARM(HDivZeroCheck* instruction) : instruction_(instruction) {}
100
Alexandre Rames67555f72014-11-18 10:55:16 +0000101 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Calin Juravled0d48522014-11-04 16:40:20 +0000102 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
103 __ Bind(GetEntryLabel());
104 arm_codegen->InvokeRuntime(
105 QUICK_ENTRY_POINT(pThrowDivZero), instruction_, instruction_->GetDexPc());
106 }
107
108 private:
109 HDivZeroCheck* const instruction_;
110 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathARM);
111};
112
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100113class StackOverflowCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100114 public:
115 StackOverflowCheckSlowPathARM() {}
116
Alexandre Rames67555f72014-11-18 10:55:16 +0000117 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100118 __ Bind(GetEntryLabel());
119 __ LoadFromOffset(kLoadWord, PC, TR,
120 QUICK_ENTRYPOINT_OFFSET(kArmWordSize, pThrowStackOverflow).Int32Value());
121 }
122
123 private:
124 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathARM);
125};
126
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100127class SuspendCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000128 public:
Alexandre Rames67555f72014-11-18 10:55:16 +0000129 SuspendCheckSlowPathARM(HSuspendCheck* instruction, HBasicBlock* successor)
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100130 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000131
Alexandre Rames67555f72014-11-18 10:55:16 +0000132 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100133 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000134 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100135 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100136 arm_codegen->InvokeRuntime(
137 QUICK_ENTRY_POINT(pTestSuspend), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100138 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100139 if (successor_ == nullptr) {
140 __ b(GetReturnLabel());
141 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100142 __ b(arm_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100143 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000144 }
145
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100146 Label* GetReturnLabel() {
147 DCHECK(successor_ == nullptr);
148 return &return_label_;
149 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000150
151 private:
152 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100153 // If not null, the block to branch to after the suspend check.
154 HBasicBlock* const successor_;
155
156 // If `successor_` is null, the label to branch to after the suspend check.
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000157 Label return_label_;
158
159 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathARM);
160};
161
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100162class BoundsCheckSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100164 BoundsCheckSlowPathARM(HBoundsCheck* instruction,
165 Location index_location,
166 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100167 : instruction_(instruction),
168 index_location_(index_location),
169 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100170
Alexandre Rames67555f72014-11-18 10:55:16 +0000171 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100172 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100173 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000174 // We're moving two locations to locations that could overlap, so we need a parallel
175 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100176 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000177 codegen->EmitParallelMoves(
178 index_location_,
179 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
180 length_location_,
181 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100182 arm_codegen->InvokeRuntime(
183 QUICK_ENTRY_POINT(pThrowArrayBounds), instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100184 }
185
186 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100187 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100188 const Location index_location_;
189 const Location length_location_;
190
191 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathARM);
192};
193
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000194class LoadClassSlowPathARM : public SlowPathCodeARM {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100195 public:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000196 LoadClassSlowPathARM(HLoadClass* cls,
197 HInstruction* at,
198 uint32_t dex_pc,
199 bool do_clinit)
200 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
201 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
202 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100203
Alexandre Rames67555f72014-11-18 10:55:16 +0000204 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000205 LocationSummary* locations = at_->GetLocations();
206
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100207 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
208 __ Bind(GetEntryLabel());
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000209 codegen->SaveLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100210
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100211 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000212 __ LoadImmediate(calling_convention.GetRegisterAt(0), cls_->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100213 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000214 int32_t entry_point_offset = do_clinit_
215 ? QUICK_ENTRY_POINT(pInitializeStaticStorage)
216 : QUICK_ENTRY_POINT(pInitializeType);
217 arm_codegen->InvokeRuntime(entry_point_offset, at_, dex_pc_);
218
219 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000220 Location out = locations->Out();
221 if (out.IsValid()) {
222 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000223 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
224 }
225 codegen->RestoreLiveRegisters(locations);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100226 __ b(GetExitLabel());
227 }
228
229 private:
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000230 // The class this slow path will load.
231 HLoadClass* const cls_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100232
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000233 // The instruction where this slow path is happening.
234 // (Might be the load class or an initialization check).
235 HInstruction* const at_;
236
237 // The dex PC of `at_`.
238 const uint32_t dex_pc_;
239
240 // Whether to initialize the class.
241 const bool do_clinit_;
242
243 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathARM);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100244};
245
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000246class LoadStringSlowPathARM : public SlowPathCodeARM {
247 public:
248 explicit LoadStringSlowPathARM(HLoadString* instruction) : instruction_(instruction) {}
249
Alexandre Rames67555f72014-11-18 10:55:16 +0000250 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000251 LocationSummary* locations = instruction_->GetLocations();
252 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
253
254 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
255 __ Bind(GetEntryLabel());
256 codegen->SaveLiveRegisters(locations);
257
258 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800259 arm_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
260 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction_->GetStringIndex());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000261 arm_codegen->InvokeRuntime(
262 QUICK_ENTRY_POINT(pResolveString), instruction_, instruction_->GetDexPc());
263 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
264
265 codegen->RestoreLiveRegisters(locations);
266 __ b(GetExitLabel());
267 }
268
269 private:
270 HLoadString* const instruction_;
271
272 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathARM);
273};
274
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000275class TypeCheckSlowPathARM : public SlowPathCodeARM {
276 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000277 TypeCheckSlowPathARM(HInstruction* instruction,
278 Location class_to_check,
279 Location object_class,
280 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000281 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000282 class_to_check_(class_to_check),
283 object_class_(object_class),
284 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000285
Alexandre Rames67555f72014-11-18 10:55:16 +0000286 void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000287 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 DCHECK(instruction_->IsCheckCast()
289 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000290
291 CodeGeneratorARM* arm_codegen = down_cast<CodeGeneratorARM*>(codegen);
292 __ Bind(GetEntryLabel());
293 codegen->SaveLiveRegisters(locations);
294
295 // We're moving two locations to locations that could overlap, so we need a parallel
296 // move resolver.
297 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000298 codegen->EmitParallelMoves(
299 class_to_check_,
300 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
301 object_class_,
302 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000303
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000304 if (instruction_->IsInstanceOf()) {
305 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pInstanceofNonTrivial), instruction_, dex_pc_);
306 arm_codegen->Move32(locations->Out(), Location::RegisterLocation(R0));
307 } else {
308 DCHECK(instruction_->IsCheckCast());
309 arm_codegen->InvokeRuntime(QUICK_ENTRY_POINT(pCheckCast), instruction_, dex_pc_);
310 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000311
312 codegen->RestoreLiveRegisters(locations);
313 __ b(GetExitLabel());
314 }
315
316 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000317 HInstruction* const instruction_;
318 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000319 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000320 uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000321
322 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathARM);
323};
324
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000325#undef __
326
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100327#undef __
328#define __ reinterpret_cast<ArmAssembler*>(GetAssembler())->
Dave Allison20dfc792014-06-16 20:44:29 -0700329
330inline Condition ARMCondition(IfCondition cond) {
331 switch (cond) {
332 case kCondEQ: return EQ;
333 case kCondNE: return NE;
334 case kCondLT: return LT;
335 case kCondLE: return LE;
336 case kCondGT: return GT;
337 case kCondGE: return GE;
338 default:
339 LOG(FATAL) << "Unknown if condition";
340 }
341 return EQ; // Unreachable.
342}
343
344inline Condition ARMOppositeCondition(IfCondition cond) {
345 switch (cond) {
346 case kCondEQ: return NE;
347 case kCondNE: return EQ;
348 case kCondLT: return GE;
349 case kCondLE: return GT;
350 case kCondGT: return LE;
351 case kCondGE: return LT;
352 default:
353 LOG(FATAL) << "Unknown if condition";
354 }
355 return EQ; // Unreachable.
356}
357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100358void CodeGeneratorARM::DumpCoreRegister(std::ostream& stream, int reg) const {
359 stream << ArmManagedRegister::FromCoreRegister(Register(reg));
360}
361
362void CodeGeneratorARM::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000363 stream << ArmManagedRegister::FromSRegister(SRegister(reg));
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorARM::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ StoreToOffset(kStoreWord, static_cast<Register>(reg_id), SP, stack_index);
368 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorARM::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ LoadFromOffset(kLoadWord, static_cast<Register>(reg_id), SP, stack_index);
373 return kArmWordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000376size_t CodeGeneratorARM::SaveFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
377 __ StoreSToOffset(static_cast<SRegister>(reg_id), SP, stack_index);
378 return kArmWordSize;
379}
380
381size_t CodeGeneratorARM::RestoreFloatingPointRegister(size_t stack_index, uint32_t reg_id) {
382 __ LoadSFromOffset(static_cast<SRegister>(reg_id), SP, stack_index);
383 return kArmWordSize;
384}
385
Calin Juravle34166012014-12-19 17:22:29 +0000386CodeGeneratorARM::CodeGeneratorARM(HGraph* graph,
387 const ArmInstructionSetFeatures* isa_features)
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000388 : CodeGenerator(graph, kNumberOfCoreRegisters, kNumberOfSRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100389 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100390 location_builder_(graph, this),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100391 instruction_visitor_(graph, this),
Nicolas Geoffray8d486732014-07-16 16:23:40 +0100392 move_resolver_(graph->GetArena(), this),
Calin Juravle34166012014-12-19 17:22:29 +0000393 assembler_(true),
394 isa_features_(isa_features) {}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100395
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100396size_t CodeGeneratorARM::FrameEntrySpillSize() const {
397 return kNumberOfPushedRegistersAtEntry * kArmWordSize;
398}
399
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100400Location CodeGeneratorARM::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100401 switch (type) {
402 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100403 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100404 ArmManagedRegister pair =
405 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100406 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
407 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
408
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100409 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
410 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100411 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100412 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100413 }
414
415 case Primitive::kPrimByte:
416 case Primitive::kPrimBoolean:
417 case Primitive::kPrimChar:
418 case Primitive::kPrimShort:
419 case Primitive::kPrimInt:
420 case Primitive::kPrimNot: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100421 int reg = FindFreeEntry(blocked_core_registers_, kNumberOfCoreRegisters);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100422 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100423 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
424 ArmManagedRegister current =
425 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
426 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100427 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100428 }
429 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100430 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100431 }
432
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000433 case Primitive::kPrimFloat: {
434 int reg = FindFreeEntry(blocked_fpu_registers_, kNumberOfSRegisters);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100435 return Location::FpuRegisterLocation(reg);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100436 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100437
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000438 case Primitive::kPrimDouble: {
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000439 int reg = FindTwoFreeConsecutiveAlignedEntries(blocked_fpu_registers_, kNumberOfSRegisters);
440 DCHECK_EQ(reg % 2, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000441 return Location::FpuRegisterPairLocation(reg, reg + 1);
442 }
443
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100444 case Primitive::kPrimVoid:
445 LOG(FATAL) << "Unreachable type " << type;
446 }
447
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100448 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100449}
450
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100451void CodeGeneratorARM::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100452 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100453 blocked_register_pairs_[R1_R2] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100454
455 // Stack register, LR and PC are always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100456 blocked_core_registers_[SP] = true;
457 blocked_core_registers_[LR] = true;
458 blocked_core_registers_[PC] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100459
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100460 // Reserve thread register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100461 blocked_core_registers_[TR] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100462
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100463 // Reserve temp register.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100464 blocked_core_registers_[IP] = true;
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +0100465
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000466 // TODO: We currently don't use Quick's callee saved registers.
467 // We always save and restore R6 and R7 to make sure we can use three
468 // register pairs for long operations.
469 blocked_core_registers_[R4] = true;
470 blocked_core_registers_[R5] = true;
471 blocked_core_registers_[R8] = true;
472 blocked_core_registers_[R10] = true;
473 blocked_core_registers_[R11] = true;
474
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000475 blocked_fpu_registers_[S16] = true;
476 blocked_fpu_registers_[S17] = true;
477 blocked_fpu_registers_[S18] = true;
478 blocked_fpu_registers_[S19] = true;
479 blocked_fpu_registers_[S20] = true;
480 blocked_fpu_registers_[S21] = true;
481 blocked_fpu_registers_[S22] = true;
482 blocked_fpu_registers_[S23] = true;
Nicolas Geoffray3c035032014-10-28 10:46:40 +0000483 blocked_fpu_registers_[S24] = true;
484 blocked_fpu_registers_[S25] = true;
485 blocked_fpu_registers_[S26] = true;
486 blocked_fpu_registers_[S27] = true;
487 blocked_fpu_registers_[S28] = true;
488 blocked_fpu_registers_[S29] = true;
489 blocked_fpu_registers_[S30] = true;
490 blocked_fpu_registers_[S31] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100491
492 UpdateBlockedPairRegisters();
493}
494
495void CodeGeneratorARM::UpdateBlockedPairRegisters() const {
496 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
497 ArmManagedRegister current =
498 ArmManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
499 if (blocked_core_registers_[current.AsRegisterPairLow()]
500 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
501 blocked_register_pairs_[i] = true;
502 }
503 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100504}
505
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100506InstructionCodeGeneratorARM::InstructionCodeGeneratorARM(HGraph* graph, CodeGeneratorARM* codegen)
507 : HGraphVisitor(graph),
508 assembler_(codegen->GetAssembler()),
509 codegen_(codegen) {}
510
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000511void CodeGeneratorARM::GenerateFrameEntry() {
Roland Levillain199f3362014-11-27 17:15:16 +0000512 bool skip_overflow_check =
513 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kArm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100514 if (!skip_overflow_check) {
515 if (kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100516 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathARM();
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100517 AddSlowPath(slow_path);
518
519 __ LoadFromOffset(kLoadWord, IP, TR, Thread::StackEndOffset<kArmWordSize>().Int32Value());
520 __ cmp(SP, ShifterOperand(IP));
521 __ b(slow_path->GetEntryLabel(), CC);
522 } else {
523 __ AddConstant(IP, SP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kArm)));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100524 __ LoadFromOffset(kLoadWord, IP, IP, 0);
Nicolas Geoffray39468442014-09-02 15:17:15 +0100525 RecordPcInfo(nullptr, 0);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100526 }
527 }
528
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000529 core_spill_mask_ |= (1 << LR | 1 << R6 | 1 << R7);
530 __ PushList(1 << LR | 1 << R6 | 1 << R7);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000531
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100532 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100533 __ AddConstant(SP, -(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize));
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100534 __ StoreToOffset(kStoreWord, R0, SP, 0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000535}
536
537void CodeGeneratorARM::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100538 __ AddConstant(SP, GetFrameSize() - kNumberOfPushedRegistersAtEntry * kArmWordSize);
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000539 __ PopList(1 << PC | 1 << R6 | 1 << R7);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000540}
541
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100542void CodeGeneratorARM::Bind(HBasicBlock* block) {
543 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000544}
545
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100546Location CodeGeneratorARM::GetStackLocation(HLoadLocal* load) const {
547 switch (load->GetType()) {
548 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100549 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100550 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
551 break;
552
553 case Primitive::kPrimInt:
554 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100555 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100556 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100557
558 case Primitive::kPrimBoolean:
559 case Primitive::kPrimByte:
560 case Primitive::kPrimChar:
561 case Primitive::kPrimShort:
562 case Primitive::kPrimVoid:
563 LOG(FATAL) << "Unexpected type " << load->GetType();
564 }
565
566 LOG(FATAL) << "Unreachable";
567 return Location();
568}
569
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100570Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
571 switch (type) {
572 case Primitive::kPrimBoolean:
573 case Primitive::kPrimByte:
574 case Primitive::kPrimChar:
575 case Primitive::kPrimShort:
576 case Primitive::kPrimInt:
577 case Primitive::kPrimNot: {
578 uint32_t index = gp_index_++;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000579 uint32_t stack_index = stack_index_++;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100580 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100581 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100582 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000583 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100584 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100585 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100586
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000587 case Primitive::kPrimLong: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100588 uint32_t index = gp_index_;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000589 uint32_t stack_index = stack_index_;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100590 gp_index_ += 2;
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000591 stack_index_ += 2;
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100592 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000593 if (calling_convention.GetRegisterAt(index) == R1) {
594 // Skip R1, and use R2_R3 instead.
595 gp_index_++;
596 index++;
597 }
598 }
599 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
600 DCHECK_EQ(calling_convention.GetRegisterAt(index) + 1,
601 calling_convention.GetRegisterAt(index + 1));
602 return Location::RegisterPairLocation(calling_convention.GetRegisterAt(index),
603 calling_convention.GetRegisterAt(index + 1));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100604 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000605 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
606 }
607 }
608
609 case Primitive::kPrimFloat: {
610 uint32_t stack_index = stack_index_++;
611 if (float_index_ % 2 == 0) {
612 float_index_ = std::max(double_index_, float_index_);
613 }
614 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
615 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
616 } else {
617 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
618 }
619 }
620
621 case Primitive::kPrimDouble: {
622 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
623 uint32_t stack_index = stack_index_;
624 stack_index_ += 2;
625 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
626 uint32_t index = double_index_;
627 double_index_ += 2;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000628 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) + 1,
629 calling_convention.GetFpuRegisterAt(index + 1));
630 DCHECK_EQ(calling_convention.GetFpuRegisterAt(index) & 1, 0);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000631 return Location::FpuRegisterPairLocation(
632 calling_convention.GetFpuRegisterAt(index),
633 calling_convention.GetFpuRegisterAt(index + 1));
634 } else {
635 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100636 }
637 }
638
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100639 case Primitive::kPrimVoid:
640 LOG(FATAL) << "Unexpected parameter type " << type;
641 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100642 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100643 return Location();
644}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100645
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000646Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
647 switch (type) {
648 case Primitive::kPrimBoolean:
649 case Primitive::kPrimByte:
650 case Primitive::kPrimChar:
651 case Primitive::kPrimShort:
652 case Primitive::kPrimInt:
653 case Primitive::kPrimNot: {
654 return Location::RegisterLocation(R0);
655 }
656
657 case Primitive::kPrimFloat: {
658 return Location::FpuRegisterLocation(S0);
659 }
660
661 case Primitive::kPrimLong: {
662 return Location::RegisterPairLocation(R0, R1);
663 }
664
665 case Primitive::kPrimDouble: {
666 return Location::FpuRegisterPairLocation(S0, S1);
667 }
668
669 case Primitive::kPrimVoid:
670 return Location();
671 }
672 UNREACHABLE();
673 return Location();
674}
675
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100676void CodeGeneratorARM::Move32(Location destination, Location source) {
677 if (source.Equals(destination)) {
678 return;
679 }
680 if (destination.IsRegister()) {
681 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000682 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100683 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000684 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100685 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000686 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100688 } else if (destination.IsFpuRegister()) {
689 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000690 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100691 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000692 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100693 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000694 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100695 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100696 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000697 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100698 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000699 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100700 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000701 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100702 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000703 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100704 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
705 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100706 }
707 }
708}
709
710void CodeGeneratorARM::Move64(Location destination, Location source) {
711 if (source.Equals(destination)) {
712 return;
713 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100714 if (destination.IsRegisterPair()) {
715 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000716 EmitParallelMoves(
717 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
718 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
719 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
720 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100721 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000722 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100723 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000724 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100725 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100726 if (destination.AsRegisterPairLow<Register>() == R1) {
727 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100728 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
729 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100731 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 SP, source.GetStackIndex());
733 }
734 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000735 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100736 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000737 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
738 SP,
739 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100740 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000741 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100742 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100743 } else {
744 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100745 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000746 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100747 if (source.AsRegisterPairLow<Register>() == R1) {
748 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100749 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
750 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100751 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100752 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100753 SP, destination.GetStackIndex());
754 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000755 } else if (source.IsFpuRegisterPair()) {
756 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
757 SP,
758 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100759 } else {
760 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000761 EmitParallelMoves(
762 Location::StackSlot(source.GetStackIndex()),
763 Location::StackSlot(destination.GetStackIndex()),
764 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
765 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100766 }
767 }
768}
769
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100770void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100771 LocationSummary* locations = instruction->GetLocations();
772 if (locations != nullptr && locations->Out().Equals(location)) {
773 return;
774 }
775
Calin Juravlea21f5982014-11-13 15:53:04 +0000776 if (locations != nullptr && locations->Out().IsConstant()) {
777 HConstant* const_to_move = locations->Out().GetConstant();
778 if (const_to_move->IsIntConstant()) {
779 int32_t value = const_to_move->AsIntConstant()->GetValue();
780 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000781 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000782 } else {
783 DCHECK(location.IsStackSlot());
784 __ LoadImmediate(IP, value);
785 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
786 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000787 } else {
788 DCHECK(const_to_move->IsLongConstant()) << const_to_move;
Calin Juravlea21f5982014-11-13 15:53:04 +0000789 int64_t value = const_to_move->AsLongConstant()->GetValue();
790 if (location.IsRegisterPair()) {
791 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
792 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
793 } else {
794 DCHECK(location.IsDoubleStackSlot());
795 __ LoadImmediate(IP, Low32Bits(value));
796 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
797 __ LoadImmediate(IP, High32Bits(value));
798 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
799 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 }
Roland Levillain476df552014-10-09 17:51:36 +0100801 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100802 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
803 switch (instruction->GetType()) {
804 case Primitive::kPrimBoolean:
805 case Primitive::kPrimByte:
806 case Primitive::kPrimChar:
807 case Primitive::kPrimShort:
808 case Primitive::kPrimInt:
809 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100810 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100811 Move32(location, Location::StackSlot(stack_slot));
812 break;
813
814 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100815 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100816 Move64(location, Location::DoubleStackSlot(stack_slot));
817 break;
818
819 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100820 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000822 } else if (instruction->IsTemporary()) {
823 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000824 if (temp_location.IsStackSlot()) {
825 Move32(location, temp_location);
826 } else {
827 DCHECK(temp_location.IsDoubleStackSlot());
828 Move64(location, temp_location);
829 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000830 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100831 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100832 switch (instruction->GetType()) {
833 case Primitive::kPrimBoolean:
834 case Primitive::kPrimByte:
835 case Primitive::kPrimChar:
836 case Primitive::kPrimShort:
837 case Primitive::kPrimNot:
838 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100839 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100840 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100841 break;
842
843 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100844 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100845 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100846 break;
847
848 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100849 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100850 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000851 }
852}
853
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100854void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
855 HInstruction* instruction,
856 uint32_t dex_pc) {
857 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
858 __ blx(LR);
859 RecordPcInfo(instruction, dex_pc);
860 DCHECK(instruction->IsSuspendCheck()
861 || instruction->IsBoundsCheck()
862 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000863 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000864 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100865 || !IsLeafMethod());
866}
867
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000868void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000869 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000870}
871
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000872void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000873 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100874 DCHECK(!successor->IsExitBlock());
875
876 HBasicBlock* block = got->GetBlock();
877 HInstruction* previous = got->GetPrevious();
878
879 HLoopInformation* info = block->GetLoopInformation();
880 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
881 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
882 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
883 return;
884 }
885
886 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
887 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
888 }
889 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000890 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000891 }
892}
893
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000894void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000895 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000896}
897
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000898void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700899 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000900 if (kIsDebugBuild) {
901 __ Comment("Unreachable");
902 __ bkpt(0);
903 }
904}
905
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000906void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100907 LocationSummary* locations =
908 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100909 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100910 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100911 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100912 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000913}
914
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000915void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700916 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100917 if (cond->IsIntConstant()) {
918 // Constant condition, statically compared against 1.
919 int32_t cond_value = cond->AsIntConstant()->GetValue();
920 if (cond_value == 1) {
921 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
922 if_instr->IfTrueSuccessor())) {
923 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100924 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100925 return;
926 } else {
927 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100928 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100929 } else {
930 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
931 // Condition has been materialized, compare the output to 0
932 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000933 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100934 ShifterOperand(0));
935 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
936 } else {
937 // Condition has not been materialized, use its inputs as the
938 // comparison and its condition as the branch condition.
939 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000940 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100941 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000942 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 } else {
944 DCHECK(locations->InAt(1).IsConstant());
945 int32_t value =
946 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
947 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000948 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
949 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100950 } else {
951 Register temp = IP;
952 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000953 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100954 }
955 }
956 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
957 ARMCondition(cond->AsCondition()->GetCondition()));
958 }
Dave Allison20dfc792014-06-16 20:44:29 -0700959 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100960 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
961 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700962 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000963 }
964}
965
Dave Allison20dfc792014-06-16 20:44:29 -0700966
967void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100968 LocationSummary* locations =
969 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100970 locations->SetInAt(0, Location::RequiresRegister());
971 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100972 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100973 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100974 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000975}
976
Dave Allison20dfc792014-06-16 20:44:29 -0700977void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100978 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000980 Register left = locations->InAt(0).AsRegister<Register>();
981
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100982 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000983 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100984 } else {
985 DCHECK(locations->InAt(1).IsConstant());
986 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
987 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000988 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
989 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100990 } else {
991 Register temp = IP;
992 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000993 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100994 }
Dave Allison20dfc792014-06-16 20:44:29 -0700995 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100996 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000997 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100998 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000999 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001000 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -07001001}
1002
1003void LocationsBuilderARM::VisitEqual(HEqual* comp) {
1004 VisitCondition(comp);
1005}
1006
1007void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
1008 VisitCondition(comp);
1009}
1010
1011void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1012 VisitCondition(comp);
1013}
1014
1015void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1016 VisitCondition(comp);
1017}
1018
1019void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1020 VisitCondition(comp);
1021}
1022
1023void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1024 VisitCondition(comp);
1025}
1026
1027void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1028 VisitCondition(comp);
1029}
1030
1031void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1032 VisitCondition(comp);
1033}
1034
1035void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1036 VisitCondition(comp);
1037}
1038
1039void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1040 VisitCondition(comp);
1041}
1042
1043void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1044 VisitCondition(comp);
1045}
1046
1047void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1048 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001049}
1050
1051void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001052 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001053}
1054
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001055void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1056 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001057}
1058
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001059void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001060 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001061}
1062
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001063void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001064 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001065 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001066}
1067
1068void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001069 LocationSummary* locations =
1070 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001071 switch (store->InputAt(1)->GetType()) {
1072 case Primitive::kPrimBoolean:
1073 case Primitive::kPrimByte:
1074 case Primitive::kPrimChar:
1075 case Primitive::kPrimShort:
1076 case Primitive::kPrimInt:
1077 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001078 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001079 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1080 break;
1081
1082 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001083 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001084 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1085 break;
1086
1087 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001088 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001090}
1091
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001092void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001093 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001094}
1095
1096void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001097 LocationSummary* locations =
1098 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001099 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001100}
1101
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001102void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001103 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001104 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001105}
1106
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001107void LocationsBuilderARM::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001108 LocationSummary* locations =
1109 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001110 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001111}
1112
1113void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1114 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001115 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001116}
1117
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001118void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1119 LocationSummary* locations =
1120 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1121 locations->SetOut(Location::ConstantLocation(constant));
1122}
1123
1124void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1125 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001126 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001127}
1128
1129void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1130 LocationSummary* locations =
1131 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1132 locations->SetOut(Location::ConstantLocation(constant));
1133}
1134
1135void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* constant) {
1136 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001137 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001138}
1139
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001140void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001141 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001142}
1143
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001144void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001145 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001146 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001147}
1148
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001149void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001150 LocationSummary* locations =
1151 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001152 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001153}
1154
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001155void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001156 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001157 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001158}
1159
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001160void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001161 HandleInvoke(invoke);
1162}
1163
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001164void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001165 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001166}
1167
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001168void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001169 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001170
1171 // TODO: Implement all kinds of calls:
1172 // 1) boot -> boot
1173 // 2) app -> boot
1174 // 3) app -> app
1175 //
1176 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1177
1178 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001179 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001180 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001181 __ LoadFromOffset(
1182 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001183 // temp = temp[index_in_cache]
1184 __ LoadFromOffset(
1185 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
1186 // LR = temp[offset_of_quick_compiled_code]
1187 __ LoadFromOffset(kLoadWord, LR, temp,
1188 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1189 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001190 // LR()
1191 __ blx(LR);
1192
1193 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1194 DCHECK(!codegen_->IsLeafMethod());
1195}
1196
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001197void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001198 LocationSummary* locations =
1199 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001200 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001201
1202 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001203 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001204 HInstruction* input = invoke->InputAt(i);
1205 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1206 }
1207
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001208 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001209}
1210
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001211void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1212 HandleInvoke(invoke);
1213}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001214
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001215void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001216 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001217 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1218 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1219 LocationSummary* locations = invoke->GetLocations();
1220 Location receiver = locations->InAt(0);
1221 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1222 // temp = object->GetClass();
1223 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001224 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1225 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001226 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001227 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001228 }
1229 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001230 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001231 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001232 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001233 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001234 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001235 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001236 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001237 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001238 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001239}
1240
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001241void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1242 HandleInvoke(invoke);
1243 // Add the hidden argument.
1244 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1245}
1246
1247void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1248 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001249 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001250 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1251 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1252 LocationSummary* locations = invoke->GetLocations();
1253 Location receiver = locations->InAt(0);
1254 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1255
1256 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001257 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1258 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001259
1260 // temp = object->GetClass();
1261 if (receiver.IsStackSlot()) {
1262 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1263 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1264 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001265 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001266 }
1267 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001268 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001269 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001270 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1271 // LR = temp->GetEntryPoint();
1272 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1273 // LR();
1274 __ blx(LR);
1275 DCHECK(!codegen_->IsLeafMethod());
1276 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1277}
1278
Roland Levillain88cb1752014-10-20 16:36:47 +01001279void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1280 LocationSummary* locations =
1281 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1282 switch (neg->GetResultType()) {
1283 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001284 case Primitive::kPrimLong: {
1285 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001286 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001287 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001288 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001289 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001290
Roland Levillain88cb1752014-10-20 16:36:47 +01001291 case Primitive::kPrimFloat:
1292 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001293 locations->SetInAt(0, Location::RequiresFpuRegister());
1294 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001295 break;
1296
1297 default:
1298 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1299 }
1300}
1301
1302void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1303 LocationSummary* locations = neg->GetLocations();
1304 Location out = locations->Out();
1305 Location in = locations->InAt(0);
1306 switch (neg->GetResultType()) {
1307 case Primitive::kPrimInt:
1308 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001309 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001310 break;
1311
1312 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001313 DCHECK(in.IsRegisterPair());
1314 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1315 __ rsbs(out.AsRegisterPairLow<Register>(),
1316 in.AsRegisterPairLow<Register>(),
1317 ShifterOperand(0));
1318 // We cannot emit an RSC (Reverse Subtract with Carry)
1319 // instruction here, as it does not exist in the Thumb-2
1320 // instruction set. We use the following approach
1321 // using SBC and SUB instead.
1322 //
1323 // out.hi = -C
1324 __ sbc(out.AsRegisterPairHigh<Register>(),
1325 out.AsRegisterPairHigh<Register>(),
1326 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1327 // out.hi = out.hi - in.hi
1328 __ sub(out.AsRegisterPairHigh<Register>(),
1329 out.AsRegisterPairHigh<Register>(),
1330 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1331 break;
1332
Roland Levillain88cb1752014-10-20 16:36:47 +01001333 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001334 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001335 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001336 break;
1337
Roland Levillain88cb1752014-10-20 16:36:47 +01001338 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001339 DCHECK(in.IsFpuRegisterPair());
1340 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1341 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001342 break;
1343
1344 default:
1345 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1346 }
1347}
1348
Roland Levillaindff1f282014-11-05 14:15:05 +00001349void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001350 Primitive::Type result_type = conversion->GetResultType();
1351 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001352 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001353
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001354 // The float-to-long and double-to-long type conversions rely on a
1355 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001356 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001357 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1358 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001359 ? LocationSummary::kCall
1360 : LocationSummary::kNoCall;
1361 LocationSummary* locations =
1362 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1363
Roland Levillaindff1f282014-11-05 14:15:05 +00001364 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001365 case Primitive::kPrimByte:
1366 switch (input_type) {
1367 case Primitive::kPrimShort:
1368 case Primitive::kPrimInt:
1369 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001370 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001371 locations->SetInAt(0, Location::RequiresRegister());
1372 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1373 break;
1374
1375 default:
1376 LOG(FATAL) << "Unexpected type conversion from " << input_type
1377 << " to " << result_type;
1378 }
1379 break;
1380
Roland Levillain01a8d712014-11-14 16:27:39 +00001381 case Primitive::kPrimShort:
1382 switch (input_type) {
1383 case Primitive::kPrimByte:
1384 case Primitive::kPrimInt:
1385 case Primitive::kPrimChar:
1386 // Processing a Dex `int-to-short' instruction.
1387 locations->SetInAt(0, Location::RequiresRegister());
1388 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1389 break;
1390
1391 default:
1392 LOG(FATAL) << "Unexpected type conversion from " << input_type
1393 << " to " << result_type;
1394 }
1395 break;
1396
Roland Levillain946e1432014-11-11 17:35:19 +00001397 case Primitive::kPrimInt:
1398 switch (input_type) {
1399 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001400 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001401 locations->SetInAt(0, Location::Any());
1402 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1403 break;
1404
1405 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001406 // Processing a Dex `float-to-int' instruction.
1407 locations->SetInAt(0, Location::RequiresFpuRegister());
1408 locations->SetOut(Location::RequiresRegister());
1409 locations->AddTemp(Location::RequiresFpuRegister());
1410 break;
1411
Roland Levillain946e1432014-11-11 17:35:19 +00001412 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001413 // Processing a Dex `double-to-int' instruction.
1414 locations->SetInAt(0, Location::RequiresFpuRegister());
1415 locations->SetOut(Location::RequiresRegister());
1416 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001417 break;
1418
1419 default:
1420 LOG(FATAL) << "Unexpected type conversion from " << input_type
1421 << " to " << result_type;
1422 }
1423 break;
1424
Roland Levillaindff1f282014-11-05 14:15:05 +00001425 case Primitive::kPrimLong:
1426 switch (input_type) {
1427 case Primitive::kPrimByte:
1428 case Primitive::kPrimShort:
1429 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001430 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001431 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001432 locations->SetInAt(0, Location::RequiresRegister());
1433 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1434 break;
1435
Roland Levillain624279f2014-12-04 11:54:28 +00001436 case Primitive::kPrimFloat: {
1437 // Processing a Dex `float-to-long' instruction.
1438 InvokeRuntimeCallingConvention calling_convention;
1439 locations->SetInAt(0, Location::FpuRegisterLocation(
1440 calling_convention.GetFpuRegisterAt(0)));
1441 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1442 break;
1443 }
1444
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001445 case Primitive::kPrimDouble: {
1446 // Processing a Dex `double-to-long' instruction.
1447 InvokeRuntimeCallingConvention calling_convention;
1448 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1449 calling_convention.GetFpuRegisterAt(0),
1450 calling_convention.GetFpuRegisterAt(1)));
1451 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001452 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001453 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001454
1455 default:
1456 LOG(FATAL) << "Unexpected type conversion from " << input_type
1457 << " to " << result_type;
1458 }
1459 break;
1460
Roland Levillain981e4542014-11-14 11:47:14 +00001461 case Primitive::kPrimChar:
1462 switch (input_type) {
1463 case Primitive::kPrimByte:
1464 case Primitive::kPrimShort:
1465 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001466 // Processing a Dex `int-to-char' instruction.
1467 locations->SetInAt(0, Location::RequiresRegister());
1468 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1469 break;
1470
1471 default:
1472 LOG(FATAL) << "Unexpected type conversion from " << input_type
1473 << " to " << result_type;
1474 }
1475 break;
1476
Roland Levillaindff1f282014-11-05 14:15:05 +00001477 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001478 switch (input_type) {
1479 case Primitive::kPrimByte:
1480 case Primitive::kPrimShort:
1481 case Primitive::kPrimInt:
1482 case Primitive::kPrimChar:
1483 // Processing a Dex `int-to-float' instruction.
1484 locations->SetInAt(0, Location::RequiresRegister());
1485 locations->SetOut(Location::RequiresFpuRegister());
1486 break;
1487
1488 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001489 // Processing a Dex `long-to-float' instruction.
1490 locations->SetInAt(0, Location::RequiresRegister());
1491 locations->SetOut(Location::RequiresFpuRegister());
1492 locations->AddTemp(Location::RequiresRegister());
1493 locations->AddTemp(Location::RequiresRegister());
1494 locations->AddTemp(Location::RequiresFpuRegister());
1495 locations->AddTemp(Location::RequiresFpuRegister());
1496 break;
1497
Roland Levillaincff13742014-11-17 14:32:17 +00001498 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001499 // Processing a Dex `double-to-float' instruction.
1500 locations->SetInAt(0, Location::RequiresFpuRegister());
1501 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001502 break;
1503
1504 default:
1505 LOG(FATAL) << "Unexpected type conversion from " << input_type
1506 << " to " << result_type;
1507 };
1508 break;
1509
Roland Levillaindff1f282014-11-05 14:15:05 +00001510 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001511 switch (input_type) {
1512 case Primitive::kPrimByte:
1513 case Primitive::kPrimShort:
1514 case Primitive::kPrimInt:
1515 case Primitive::kPrimChar:
1516 // Processing a Dex `int-to-double' instruction.
1517 locations->SetInAt(0, Location::RequiresRegister());
1518 locations->SetOut(Location::RequiresFpuRegister());
1519 break;
1520
1521 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001522 // Processing a Dex `long-to-double' instruction.
1523 locations->SetInAt(0, Location::RequiresRegister());
1524 locations->SetOut(Location::RequiresFpuRegister());
1525 locations->AddTemp(Location::RequiresRegister());
1526 locations->AddTemp(Location::RequiresRegister());
1527 locations->AddTemp(Location::RequiresFpuRegister());
1528 break;
1529
Roland Levillaincff13742014-11-17 14:32:17 +00001530 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001531 // Processing a Dex `float-to-double' instruction.
1532 locations->SetInAt(0, Location::RequiresFpuRegister());
1533 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001534 break;
1535
1536 default:
1537 LOG(FATAL) << "Unexpected type conversion from " << input_type
1538 << " to " << result_type;
1539 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001540 break;
1541
1542 default:
1543 LOG(FATAL) << "Unexpected type conversion from " << input_type
1544 << " to " << result_type;
1545 }
1546}
1547
1548void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1549 LocationSummary* locations = conversion->GetLocations();
1550 Location out = locations->Out();
1551 Location in = locations->InAt(0);
1552 Primitive::Type result_type = conversion->GetResultType();
1553 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001554 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001555 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001556 case Primitive::kPrimByte:
1557 switch (input_type) {
1558 case Primitive::kPrimShort:
1559 case Primitive::kPrimInt:
1560 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001561 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001562 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001563 break;
1564
1565 default:
1566 LOG(FATAL) << "Unexpected type conversion from " << input_type
1567 << " to " << result_type;
1568 }
1569 break;
1570
Roland Levillain01a8d712014-11-14 16:27:39 +00001571 case Primitive::kPrimShort:
1572 switch (input_type) {
1573 case Primitive::kPrimByte:
1574 case Primitive::kPrimInt:
1575 case Primitive::kPrimChar:
1576 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001577 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001578 break;
1579
1580 default:
1581 LOG(FATAL) << "Unexpected type conversion from " << input_type
1582 << " to " << result_type;
1583 }
1584 break;
1585
Roland Levillain946e1432014-11-11 17:35:19 +00001586 case Primitive::kPrimInt:
1587 switch (input_type) {
1588 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001589 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001590 DCHECK(out.IsRegister());
1591 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001592 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001593 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001594 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001595 } else {
1596 DCHECK(in.IsConstant());
1597 DCHECK(in.GetConstant()->IsLongConstant());
1598 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001599 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001600 }
1601 break;
1602
Roland Levillain3f8f9362014-12-02 17:45:01 +00001603 case Primitive::kPrimFloat: {
1604 // Processing a Dex `float-to-int' instruction.
1605 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1606 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1607 __ vcvtis(temp, temp);
1608 __ vmovrs(out.AsRegister<Register>(), temp);
1609 break;
1610 }
1611
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001612 case Primitive::kPrimDouble: {
1613 // Processing a Dex `double-to-int' instruction.
1614 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1615 DRegister temp_d = FromLowSToD(temp_s);
1616 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1617 __ vcvtid(temp_s, temp_d);
1618 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001619 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001620 }
Roland Levillain946e1432014-11-11 17:35:19 +00001621
1622 default:
1623 LOG(FATAL) << "Unexpected type conversion from " << input_type
1624 << " to " << result_type;
1625 }
1626 break;
1627
Roland Levillaindff1f282014-11-05 14:15:05 +00001628 case Primitive::kPrimLong:
1629 switch (input_type) {
1630 case Primitive::kPrimByte:
1631 case Primitive::kPrimShort:
1632 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001633 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001634 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001635 DCHECK(out.IsRegisterPair());
1636 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001637 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001638 // Sign extension.
1639 __ Asr(out.AsRegisterPairHigh<Register>(),
1640 out.AsRegisterPairLow<Register>(),
1641 31);
1642 break;
1643
1644 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001645 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001646 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1647 conversion,
1648 conversion->GetDexPc());
1649 break;
1650
Roland Levillaindff1f282014-11-05 14:15:05 +00001651 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001652 // Processing a Dex `double-to-long' instruction.
1653 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1654 conversion,
1655 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001656 break;
1657
1658 default:
1659 LOG(FATAL) << "Unexpected type conversion from " << input_type
1660 << " to " << result_type;
1661 }
1662 break;
1663
Roland Levillain981e4542014-11-14 11:47:14 +00001664 case Primitive::kPrimChar:
1665 switch (input_type) {
1666 case Primitive::kPrimByte:
1667 case Primitive::kPrimShort:
1668 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001669 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001670 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001671 break;
1672
1673 default:
1674 LOG(FATAL) << "Unexpected type conversion from " << input_type
1675 << " to " << result_type;
1676 }
1677 break;
1678
Roland Levillaindff1f282014-11-05 14:15:05 +00001679 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001680 switch (input_type) {
1681 case Primitive::kPrimByte:
1682 case Primitive::kPrimShort:
1683 case Primitive::kPrimInt:
1684 case Primitive::kPrimChar: {
1685 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001686 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1687 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001688 break;
1689 }
1690
Roland Levillain6d0e4832014-11-27 18:31:21 +00001691 case Primitive::kPrimLong: {
1692 // Processing a Dex `long-to-float' instruction.
1693 Register low = in.AsRegisterPairLow<Register>();
1694 Register high = in.AsRegisterPairHigh<Register>();
1695 SRegister output = out.AsFpuRegister<SRegister>();
1696 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1697 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1698 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1699 DRegister temp1_d = FromLowSToD(temp1_s);
1700 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1701 DRegister temp2_d = FromLowSToD(temp2_s);
1702
1703 // Operations use doubles for precision reasons (each 32-bit
1704 // half of a long fits in the 53-bit mantissa of a double,
1705 // but not in the 24-bit mantissa of a float). This is
1706 // especially important for the low bits. The result is
1707 // eventually converted to float.
1708
1709 // temp1_d = int-to-double(high)
1710 __ vmovsr(temp1_s, high);
1711 __ vcvtdi(temp1_d, temp1_s);
1712 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1713 // as an immediate value into `temp2_d` does not work, as
1714 // this instruction only transfers 8 significant bits of its
1715 // immediate operand. Instead, use two 32-bit core
1716 // registers to load `k2Pow32EncodingForDouble` into
1717 // `temp2_d`.
1718 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1719 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1720 __ vmovdrr(temp2_d, constant_low, constant_high);
1721 // temp1_d = temp1_d * 2^32
1722 __ vmuld(temp1_d, temp1_d, temp2_d);
1723 // temp2_d = unsigned-to-double(low)
1724 __ vmovsr(temp2_s, low);
1725 __ vcvtdu(temp2_d, temp2_s);
1726 // temp1_d = temp1_d + temp2_d
1727 __ vaddd(temp1_d, temp1_d, temp2_d);
1728 // output = double-to-float(temp1_d);
1729 __ vcvtsd(output, temp1_d);
1730 break;
1731 }
1732
Roland Levillaincff13742014-11-17 14:32:17 +00001733 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001734 // Processing a Dex `double-to-float' instruction.
1735 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1736 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001737 break;
1738
1739 default:
1740 LOG(FATAL) << "Unexpected type conversion from " << input_type
1741 << " to " << result_type;
1742 };
1743 break;
1744
Roland Levillaindff1f282014-11-05 14:15:05 +00001745 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001746 switch (input_type) {
1747 case Primitive::kPrimByte:
1748 case Primitive::kPrimShort:
1749 case Primitive::kPrimInt:
1750 case Primitive::kPrimChar: {
1751 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001752 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001753 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1754 out.AsFpuRegisterPairLow<SRegister>());
1755 break;
1756 }
1757
Roland Levillain647b9ed2014-11-27 12:06:00 +00001758 case Primitive::kPrimLong: {
1759 // Processing a Dex `long-to-double' instruction.
1760 Register low = in.AsRegisterPairLow<Register>();
1761 Register high = in.AsRegisterPairHigh<Register>();
1762 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1763 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001764 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1765 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001766 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1767 DRegister temp_d = FromLowSToD(temp_s);
1768
Roland Levillain647b9ed2014-11-27 12:06:00 +00001769 // out_d = int-to-double(high)
1770 __ vmovsr(out_s, high);
1771 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001772 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1773 // as an immediate value into `temp_d` does not work, as
1774 // this instruction only transfers 8 significant bits of its
1775 // immediate operand. Instead, use two 32-bit core
1776 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1777 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1778 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001779 __ vmovdrr(temp_d, constant_low, constant_high);
1780 // out_d = out_d * 2^32
1781 __ vmuld(out_d, out_d, temp_d);
1782 // temp_d = unsigned-to-double(low)
1783 __ vmovsr(temp_s, low);
1784 __ vcvtdu(temp_d, temp_s);
1785 // out_d = out_d + temp_d
1786 __ vaddd(out_d, out_d, temp_d);
1787 break;
1788 }
1789
Roland Levillaincff13742014-11-17 14:32:17 +00001790 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001791 // Processing a Dex `float-to-double' instruction.
1792 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1793 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001794 break;
1795
1796 default:
1797 LOG(FATAL) << "Unexpected type conversion from " << input_type
1798 << " to " << result_type;
1799 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001800 break;
1801
1802 default:
1803 LOG(FATAL) << "Unexpected type conversion from " << input_type
1804 << " to " << result_type;
1805 }
1806}
1807
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001808void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001809 LocationSummary* locations =
1810 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001811 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001812 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001813 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001814 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1815 locations->SetInAt(0, Location::RequiresRegister());
1816 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1817 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001818 break;
1819 }
1820
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001821 case Primitive::kPrimFloat:
1822 case Primitive::kPrimDouble: {
1823 locations->SetInAt(0, Location::RequiresFpuRegister());
1824 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001825 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001826 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001827 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001828
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001829 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001830 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001831 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001832}
1833
1834void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1835 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001836 Location out = locations->Out();
1837 Location first = locations->InAt(0);
1838 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001839 switch (add->GetResultType()) {
1840 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001841 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001842 __ add(out.AsRegister<Register>(),
1843 first.AsRegister<Register>(),
1844 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001845 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001846 __ AddConstant(out.AsRegister<Register>(),
1847 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001848 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001849 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001850 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001851
1852 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001853 __ adds(out.AsRegisterPairLow<Register>(),
1854 first.AsRegisterPairLow<Register>(),
1855 ShifterOperand(second.AsRegisterPairLow<Register>()));
1856 __ adc(out.AsRegisterPairHigh<Register>(),
1857 first.AsRegisterPairHigh<Register>(),
1858 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001859 break;
1860
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001861 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001862 __ vadds(out.AsFpuRegister<SRegister>(),
1863 first.AsFpuRegister<SRegister>(),
1864 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001865 break;
1866
1867 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001868 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1869 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1870 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001871 break;
1872
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001873 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001874 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001875 }
1876}
1877
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001878void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001879 LocationSummary* locations =
1880 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001881 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001882 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001883 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001884 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1885 locations->SetInAt(0, Location::RequiresRegister());
1886 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1887 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001888 break;
1889 }
Calin Juravle11351682014-10-23 15:38:15 +01001890 case Primitive::kPrimFloat:
1891 case Primitive::kPrimDouble: {
1892 locations->SetInAt(0, Location::RequiresFpuRegister());
1893 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001894 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001895 break;
Calin Juravle11351682014-10-23 15:38:15 +01001896 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001897 default:
Calin Juravle11351682014-10-23 15:38:15 +01001898 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001899 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001900}
1901
1902void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1903 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001904 Location out = locations->Out();
1905 Location first = locations->InAt(0);
1906 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001907 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001908 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001909 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001910 __ sub(out.AsRegister<Register>(),
1911 first.AsRegister<Register>(),
1912 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001913 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001914 __ AddConstant(out.AsRegister<Register>(),
1915 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001916 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001917 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001918 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001919 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001920
Calin Juravle11351682014-10-23 15:38:15 +01001921 case Primitive::kPrimLong: {
1922 __ subs(out.AsRegisterPairLow<Register>(),
1923 first.AsRegisterPairLow<Register>(),
1924 ShifterOperand(second.AsRegisterPairLow<Register>()));
1925 __ sbc(out.AsRegisterPairHigh<Register>(),
1926 first.AsRegisterPairHigh<Register>(),
1927 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001928 break;
Calin Juravle11351682014-10-23 15:38:15 +01001929 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001930
Calin Juravle11351682014-10-23 15:38:15 +01001931 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001932 __ vsubs(out.AsFpuRegister<SRegister>(),
1933 first.AsFpuRegister<SRegister>(),
1934 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001935 break;
Calin Juravle11351682014-10-23 15:38:15 +01001936 }
1937
1938 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001939 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1940 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1941 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001942 break;
1943 }
1944
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001945
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001946 default:
Calin Juravle11351682014-10-23 15:38:15 +01001947 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001948 }
1949}
1950
Calin Juravle34bacdf2014-10-07 20:23:36 +01001951void LocationsBuilderARM::VisitMul(HMul* mul) {
1952 LocationSummary* locations =
1953 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1954 switch (mul->GetResultType()) {
1955 case Primitive::kPrimInt:
1956 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001957 locations->SetInAt(0, Location::RequiresRegister());
1958 locations->SetInAt(1, Location::RequiresRegister());
1959 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001960 break;
1961 }
1962
Calin Juravleb5bfa962014-10-21 18:02:24 +01001963 case Primitive::kPrimFloat:
1964 case Primitive::kPrimDouble: {
1965 locations->SetInAt(0, Location::RequiresFpuRegister());
1966 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001967 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001968 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001969 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001970
1971 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001972 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001973 }
1974}
1975
1976void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1977 LocationSummary* locations = mul->GetLocations();
1978 Location out = locations->Out();
1979 Location first = locations->InAt(0);
1980 Location second = locations->InAt(1);
1981 switch (mul->GetResultType()) {
1982 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001983 __ mul(out.AsRegister<Register>(),
1984 first.AsRegister<Register>(),
1985 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001986 break;
1987 }
1988 case Primitive::kPrimLong: {
1989 Register out_hi = out.AsRegisterPairHigh<Register>();
1990 Register out_lo = out.AsRegisterPairLow<Register>();
1991 Register in1_hi = first.AsRegisterPairHigh<Register>();
1992 Register in1_lo = first.AsRegisterPairLow<Register>();
1993 Register in2_hi = second.AsRegisterPairHigh<Register>();
1994 Register in2_lo = second.AsRegisterPairLow<Register>();
1995
1996 // Extra checks to protect caused by the existence of R1_R2.
1997 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1998 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1999 DCHECK_NE(out_hi, in1_lo);
2000 DCHECK_NE(out_hi, in2_lo);
2001
2002 // input: in1 - 64 bits, in2 - 64 bits
2003 // output: out
2004 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
2005 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
2006 // parts: out.lo = (in1.lo * in2.lo)[31:0]
2007
2008 // IP <- in1.lo * in2.hi
2009 __ mul(IP, in1_lo, in2_hi);
2010 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2011 __ mla(out_hi, in1_hi, in2_lo, IP);
2012 // out.lo <- (in1.lo * in2.lo)[31:0];
2013 __ umull(out_lo, IP, in1_lo, in2_lo);
2014 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2015 __ add(out_hi, out_hi, ShifterOperand(IP));
2016 break;
2017 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002018
2019 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002020 __ vmuls(out.AsFpuRegister<SRegister>(),
2021 first.AsFpuRegister<SRegister>(),
2022 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002023 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002024 }
2025
2026 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002027 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2028 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2029 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002030 break;
2031 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002032
2033 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002034 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002035 }
2036}
2037
Calin Juravle7c4954d2014-10-28 16:57:40 +00002038void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002039 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2040 ? LocationSummary::kCall
2041 : LocationSummary::kNoCall;
2042 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2043
Calin Juravle7c4954d2014-10-28 16:57:40 +00002044 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002045 case Primitive::kPrimInt: {
2046 locations->SetInAt(0, Location::RequiresRegister());
2047 locations->SetInAt(1, Location::RequiresRegister());
2048 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2049 break;
2050 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002051 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002052 InvokeRuntimeCallingConvention calling_convention;
2053 locations->SetInAt(0, Location::RegisterPairLocation(
2054 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2055 locations->SetInAt(1, Location::RegisterPairLocation(
2056 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2057 // The runtime helper puts the output in R0,R2.
2058 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002059 break;
2060 }
2061 case Primitive::kPrimFloat:
2062 case Primitive::kPrimDouble: {
2063 locations->SetInAt(0, Location::RequiresFpuRegister());
2064 locations->SetInAt(1, Location::RequiresFpuRegister());
2065 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2066 break;
2067 }
2068
2069 default:
2070 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2071 }
2072}
2073
2074void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2075 LocationSummary* locations = div->GetLocations();
2076 Location out = locations->Out();
2077 Location first = locations->InAt(0);
2078 Location second = locations->InAt(1);
2079
2080 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002081 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002082 __ sdiv(out.AsRegister<Register>(),
2083 first.AsRegister<Register>(),
2084 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002085 break;
2086 }
2087
Calin Juravle7c4954d2014-10-28 16:57:40 +00002088 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002089 InvokeRuntimeCallingConvention calling_convention;
2090 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2091 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2092 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2093 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2094 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2095 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2096
2097 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002098 break;
2099 }
2100
2101 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002102 __ vdivs(out.AsFpuRegister<SRegister>(),
2103 first.AsFpuRegister<SRegister>(),
2104 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002105 break;
2106 }
2107
2108 case Primitive::kPrimDouble: {
2109 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2110 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2111 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2112 break;
2113 }
2114
2115 default:
2116 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2117 }
2118}
2119
Calin Juravlebacfec32014-11-14 15:54:36 +00002120void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002121 Primitive::Type type = rem->GetResultType();
2122 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2123 ? LocationSummary::kNoCall
2124 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002125 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2126
Calin Juravled2ec87d2014-12-08 14:24:46 +00002127 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002128 case Primitive::kPrimInt: {
2129 locations->SetInAt(0, Location::RequiresRegister());
2130 locations->SetInAt(1, Location::RequiresRegister());
2131 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2132 locations->AddTemp(Location::RequiresRegister());
2133 break;
2134 }
2135 case Primitive::kPrimLong: {
2136 InvokeRuntimeCallingConvention calling_convention;
2137 locations->SetInAt(0, Location::RegisterPairLocation(
2138 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2139 locations->SetInAt(1, Location::RegisterPairLocation(
2140 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2141 // The runtime helper puts the output in R2,R3.
2142 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2143 break;
2144 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002145 case Primitive::kPrimFloat: {
2146 InvokeRuntimeCallingConvention calling_convention;
2147 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2148 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2149 locations->SetOut(Location::FpuRegisterLocation(S0));
2150 break;
2151 }
2152
Calin Juravlebacfec32014-11-14 15:54:36 +00002153 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002154 InvokeRuntimeCallingConvention calling_convention;
2155 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2156 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2157 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2158 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2159 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002160 break;
2161 }
2162
2163 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002164 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002165 }
2166}
2167
2168void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2169 LocationSummary* locations = rem->GetLocations();
2170 Location out = locations->Out();
2171 Location first = locations->InAt(0);
2172 Location second = locations->InAt(1);
2173
Calin Juravled2ec87d2014-12-08 14:24:46 +00002174 Primitive::Type type = rem->GetResultType();
2175 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002176 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002177 Register reg1 = first.AsRegister<Register>();
2178 Register reg2 = second.AsRegister<Register>();
2179 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002180
2181 // temp = reg1 / reg2 (integer division)
2182 // temp = temp * reg2
2183 // dest = reg1 - temp
2184 __ sdiv(temp, reg1, reg2);
2185 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002186 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002187 break;
2188 }
2189
2190 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002191 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2192 break;
2193 }
2194
Calin Juravled2ec87d2014-12-08 14:24:46 +00002195 case Primitive::kPrimFloat: {
2196 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2197 break;
2198 }
2199
Calin Juravlebacfec32014-11-14 15:54:36 +00002200 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002201 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002202 break;
2203 }
2204
2205 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002206 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002207 }
2208}
2209
Calin Juravled0d48522014-11-04 16:40:20 +00002210void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2211 LocationSummary* locations =
2212 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002213 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002214 if (instruction->HasUses()) {
2215 locations->SetOut(Location::SameAsFirstInput());
2216 }
2217}
2218
2219void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2220 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2221 codegen_->AddSlowPath(slow_path);
2222
2223 LocationSummary* locations = instruction->GetLocations();
2224 Location value = locations->InAt(0);
2225
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002226 switch (instruction->GetType()) {
2227 case Primitive::kPrimInt: {
2228 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002229 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002230 __ b(slow_path->GetEntryLabel(), EQ);
2231 } else {
2232 DCHECK(value.IsConstant()) << value;
2233 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2234 __ b(slow_path->GetEntryLabel());
2235 }
2236 }
2237 break;
2238 }
2239 case Primitive::kPrimLong: {
2240 if (value.IsRegisterPair()) {
2241 __ orrs(IP,
2242 value.AsRegisterPairLow<Register>(),
2243 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2244 __ b(slow_path->GetEntryLabel(), EQ);
2245 } else {
2246 DCHECK(value.IsConstant()) << value;
2247 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2248 __ b(slow_path->GetEntryLabel());
2249 }
2250 }
2251 break;
2252 default:
2253 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2254 }
2255 }
Calin Juravled0d48522014-11-04 16:40:20 +00002256}
2257
Calin Juravle9aec02f2014-11-18 23:06:35 +00002258void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2259 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2260
2261 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2262 ? LocationSummary::kCall
2263 : LocationSummary::kNoCall;
2264 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2265
2266 switch (op->GetResultType()) {
2267 case Primitive::kPrimInt: {
2268 locations->SetInAt(0, Location::RequiresRegister());
2269 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2270 locations->SetOut(Location::RequiresRegister());
2271 break;
2272 }
2273 case Primitive::kPrimLong: {
2274 InvokeRuntimeCallingConvention calling_convention;
2275 locations->SetInAt(0, Location::RegisterPairLocation(
2276 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2277 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2278 // The runtime helper puts the output in R0,R2.
2279 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2280 break;
2281 }
2282 default:
2283 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2284 }
2285}
2286
2287void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2288 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2289
2290 LocationSummary* locations = op->GetLocations();
2291 Location out = locations->Out();
2292 Location first = locations->InAt(0);
2293 Location second = locations->InAt(1);
2294
2295 Primitive::Type type = op->GetResultType();
2296 switch (type) {
2297 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002298 Register out_reg = out.AsRegister<Register>();
2299 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002300 // Arm doesn't mask the shift count so we need to do it ourselves.
2301 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002302 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002303 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2304 if (op->IsShl()) {
2305 __ Lsl(out_reg, first_reg, second_reg);
2306 } else if (op->IsShr()) {
2307 __ Asr(out_reg, first_reg, second_reg);
2308 } else {
2309 __ Lsr(out_reg, first_reg, second_reg);
2310 }
2311 } else {
2312 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2313 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2314 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2315 __ Mov(out_reg, first_reg);
2316 } else if (op->IsShl()) {
2317 __ Lsl(out_reg, first_reg, shift_value);
2318 } else if (op->IsShr()) {
2319 __ Asr(out_reg, first_reg, shift_value);
2320 } else {
2321 __ Lsr(out_reg, first_reg, shift_value);
2322 }
2323 }
2324 break;
2325 }
2326 case Primitive::kPrimLong: {
2327 // TODO: Inline the assembly instead of calling the runtime.
2328 InvokeRuntimeCallingConvention calling_convention;
2329 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2330 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002331 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002332 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2333 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2334
2335 int32_t entry_point_offset;
2336 if (op->IsShl()) {
2337 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2338 } else if (op->IsShr()) {
2339 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2340 } else {
2341 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2342 }
2343 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2344 __ blx(LR);
2345 break;
2346 }
2347 default:
2348 LOG(FATAL) << "Unexpected operation type " << type;
2349 }
2350}
2351
2352void LocationsBuilderARM::VisitShl(HShl* shl) {
2353 HandleShift(shl);
2354}
2355
2356void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2357 HandleShift(shl);
2358}
2359
2360void LocationsBuilderARM::VisitShr(HShr* shr) {
2361 HandleShift(shr);
2362}
2363
2364void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2365 HandleShift(shr);
2366}
2367
2368void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2369 HandleShift(ushr);
2370}
2371
2372void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2373 HandleShift(ushr);
2374}
2375
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002376void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002377 LocationSummary* locations =
2378 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002379 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002380 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2381 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2382 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002383}
2384
2385void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2386 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002387 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002388 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002389 codegen_->InvokeRuntime(
2390 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002391}
2392
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002393void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2394 LocationSummary* locations =
2395 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2396 InvokeRuntimeCallingConvention calling_convention;
2397 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002398 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002399 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002400 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002401}
2402
2403void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2404 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002405 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002406 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002407 codegen_->InvokeRuntime(
2408 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002409}
2410
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002411void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002412 LocationSummary* locations =
2413 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002414 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2415 if (location.IsStackSlot()) {
2416 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2417 } else if (location.IsDoubleStackSlot()) {
2418 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002419 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002420 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002421}
2422
2423void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002424 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002425 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002426}
2427
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002428void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002429 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002430 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002431 locations->SetInAt(0, Location::RequiresRegister());
2432 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002433}
2434
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002435void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2436 LocationSummary* locations = not_->GetLocations();
2437 Location out = locations->Out();
2438 Location in = locations->InAt(0);
2439 switch (not_->InputAt(0)->GetType()) {
2440 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002441 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002442 break;
2443
2444 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002445 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002446 break;
2447
2448 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002449 __ mvn(out.AsRegisterPairLow<Register>(),
2450 ShifterOperand(in.AsRegisterPairLow<Register>()));
2451 __ mvn(out.AsRegisterPairHigh<Register>(),
2452 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002453 break;
2454
2455 default:
2456 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2457 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002458}
2459
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002460void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002461 LocationSummary* locations =
2462 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002463 switch (compare->InputAt(0)->GetType()) {
2464 case Primitive::kPrimLong: {
2465 locations->SetInAt(0, Location::RequiresRegister());
2466 locations->SetInAt(1, Location::RequiresRegister());
2467 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2468 break;
2469 }
2470 case Primitive::kPrimFloat:
2471 case Primitive::kPrimDouble: {
2472 locations->SetInAt(0, Location::RequiresFpuRegister());
2473 locations->SetInAt(1, Location::RequiresFpuRegister());
2474 locations->SetOut(Location::RequiresRegister());
2475 break;
2476 }
2477 default:
2478 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2479 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002480}
2481
2482void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002483 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002484 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002485 Location left = locations->InAt(0);
2486 Location right = locations->InAt(1);
2487
2488 Label less, greater, done;
2489 Primitive::Type type = compare->InputAt(0)->GetType();
2490 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002491 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002492 __ cmp(left.AsRegisterPairHigh<Register>(),
2493 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002494 __ b(&less, LT);
2495 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002496 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2497 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002498 __ cmp(left.AsRegisterPairLow<Register>(),
2499 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002500 break;
2501 }
2502 case Primitive::kPrimFloat:
2503 case Primitive::kPrimDouble: {
2504 __ LoadImmediate(out, 0);
2505 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002506 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002507 } else {
2508 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2509 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2510 }
2511 __ vmstat(); // transfer FP status register to ARM APSR.
2512 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002513 break;
2514 }
2515 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002516 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002517 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002518 __ b(&done, EQ);
2519 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2520
2521 __ Bind(&greater);
2522 __ LoadImmediate(out, 1);
2523 __ b(&done);
2524
2525 __ Bind(&less);
2526 __ LoadImmediate(out, -1);
2527
2528 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002529}
2530
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002531void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002532 LocationSummary* locations =
2533 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002534 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2535 locations->SetInAt(i, Location::Any());
2536 }
2537 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002538}
2539
2540void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002541 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002542 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002543}
2544
Calin Juravle52c48962014-12-16 17:02:57 +00002545void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2546 // TODO (ported from quick): revisit Arm barrier kinds
2547 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2548 switch (kind) {
2549 case MemBarrierKind::kAnyStore:
2550 case MemBarrierKind::kLoadAny:
2551 case MemBarrierKind::kAnyAny: {
2552 flavour = DmbOptions::ISH;
2553 break;
2554 }
2555 case MemBarrierKind::kStoreStore: {
2556 flavour = DmbOptions::ISHST;
2557 break;
2558 }
2559 default:
2560 LOG(FATAL) << "Unexpected memory barrier " << kind;
2561 }
2562 __ dmb(flavour);
2563}
2564
2565void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2566 uint32_t offset,
2567 Register out_lo,
2568 Register out_hi) {
2569 if (offset != 0) {
2570 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002571 __ add(IP, addr, ShifterOperand(out_lo));
2572 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002573 }
2574 __ ldrexd(out_lo, out_hi, addr);
2575}
2576
2577void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2578 uint32_t offset,
2579 Register value_lo,
2580 Register value_hi,
2581 Register temp1,
2582 Register temp2) {
2583 Label fail;
2584 if (offset != 0) {
2585 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002586 __ add(IP, addr, ShifterOperand(temp1));
2587 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002588 }
2589 __ Bind(&fail);
2590 // We need a load followed by store. (The address used in a STREX instruction must
2591 // be the same as the address in the most recently executed LDREX instruction.)
2592 __ ldrexd(temp1, temp2, addr);
2593 __ strexd(temp1, value_lo, value_hi, addr);
2594 __ cmp(temp1, ShifterOperand(0));
2595 __ b(&fail, NE);
2596}
2597
2598void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2599 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2600
Nicolas Geoffray39468442014-09-02 15:17:15 +01002601 LocationSummary* locations =
2602 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002603 locations->SetInAt(0, Location::RequiresRegister());
2604 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002605
Calin Juravle34166012014-12-19 17:22:29 +00002606
Calin Juravle52c48962014-12-16 17:02:57 +00002607 Primitive::Type field_type = field_info.GetFieldType();
2608 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002609 bool generate_volatile = field_info.IsVolatile()
2610 && is_wide
2611 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002612 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002613 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2614 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002615 locations->AddTemp(Location::RequiresRegister());
2616 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002617 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002618 // Arm encoding have some additional constraints for ldrexd/strexd:
2619 // - registers need to be consecutive
2620 // - the first register should be even but not R14.
2621 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2622 // enable Arm encoding.
2623 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2624
2625 locations->AddTemp(Location::RequiresRegister());
2626 locations->AddTemp(Location::RequiresRegister());
2627 if (field_type == Primitive::kPrimDouble) {
2628 // For doubles we need two more registers to copy the value.
2629 locations->AddTemp(Location::RegisterLocation(R2));
2630 locations->AddTemp(Location::RegisterLocation(R3));
2631 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002632 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002633}
2634
Calin Juravle52c48962014-12-16 17:02:57 +00002635void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2636 const FieldInfo& field_info) {
2637 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2638
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002639 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002640 Register base = locations->InAt(0).AsRegister<Register>();
2641 Location value = locations->InAt(1);
2642
2643 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002644 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002645 Primitive::Type field_type = field_info.GetFieldType();
2646 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2647
2648 if (is_volatile) {
2649 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2650 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002651
2652 switch (field_type) {
2653 case Primitive::kPrimBoolean:
2654 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002655 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002656 break;
2657 }
2658
2659 case Primitive::kPrimShort:
2660 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002661 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002662 break;
2663 }
2664
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002665 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002666 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002667 Register value_reg = value.AsRegister<Register>();
2668 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2669 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002670 Register temp = locations->GetTemp(0).AsRegister<Register>();
2671 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002672 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002673 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002674 break;
2675 }
2676
2677 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002678 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002679 GenerateWideAtomicStore(base, offset,
2680 value.AsRegisterPairLow<Register>(),
2681 value.AsRegisterPairHigh<Register>(),
2682 locations->GetTemp(0).AsRegister<Register>(),
2683 locations->GetTemp(1).AsRegister<Register>());
2684 } else {
2685 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2686 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002687 break;
2688 }
2689
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002690 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002691 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002692 break;
2693 }
2694
2695 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002696 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002697 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002698 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2699 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2700
2701 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2702
2703 GenerateWideAtomicStore(base, offset,
2704 value_reg_lo,
2705 value_reg_hi,
2706 locations->GetTemp(2).AsRegister<Register>(),
2707 locations->GetTemp(3).AsRegister<Register>());
2708 } else {
2709 __ StoreDToOffset(value_reg, base, offset);
2710 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002711 break;
2712 }
2713
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002714 case Primitive::kPrimVoid:
2715 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002716 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002717 }
Calin Juravle52c48962014-12-16 17:02:57 +00002718
2719 if (is_volatile) {
2720 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2721 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002722}
2723
Calin Juravle52c48962014-12-16 17:02:57 +00002724void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2725 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002726 LocationSummary* locations =
2727 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002728 locations->SetInAt(0, Location::RequiresRegister());
2729 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002730
Calin Juravle34166012014-12-19 17:22:29 +00002731 bool generate_volatile = field_info.IsVolatile()
2732 && (field_info.GetFieldType() == Primitive::kPrimDouble)
2733 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
2734 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002735 // Arm encoding have some additional constraints for ldrexd/strexd:
2736 // - registers need to be consecutive
2737 // - the first register should be even but not R14.
2738 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2739 // enable Arm encoding.
2740 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2741 locations->AddTemp(Location::RequiresRegister());
2742 locations->AddTemp(Location::RequiresRegister());
2743 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002744}
2745
Calin Juravle52c48962014-12-16 17:02:57 +00002746void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2747 const FieldInfo& field_info) {
2748 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002749
Calin Juravle52c48962014-12-16 17:02:57 +00002750 LocationSummary* locations = instruction->GetLocations();
2751 Register base = locations->InAt(0).AsRegister<Register>();
2752 Location out = locations->Out();
2753 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002754 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002755 Primitive::Type field_type = field_info.GetFieldType();
2756 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2757
2758 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002759 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002760 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002761 break;
2762 }
2763
2764 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002765 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002766 break;
2767 }
2768
2769 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002770 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002771 break;
2772 }
2773
2774 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002775 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002776 break;
2777 }
2778
2779 case Primitive::kPrimInt:
2780 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002781 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002782 break;
2783 }
2784
2785 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002786 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002787 GenerateWideAtomicLoad(base, offset,
2788 out.AsRegisterPairLow<Register>(),
2789 out.AsRegisterPairHigh<Register>());
2790 } else {
2791 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2792 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002793 break;
2794 }
2795
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002796 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002797 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002798 break;
2799 }
2800
2801 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002802 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002803 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002804 Register lo = locations->GetTemp(0).AsRegister<Register>();
2805 Register hi = locations->GetTemp(1).AsRegister<Register>();
2806 GenerateWideAtomicLoad(base, offset, lo, hi);
2807 __ vmovdrr(out_reg, lo, hi);
2808 } else {
2809 __ LoadDFromOffset(out_reg, base, offset);
2810 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002811 break;
2812 }
2813
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002814 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002815 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002816 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002817 }
Calin Juravle52c48962014-12-16 17:02:57 +00002818
2819 if (is_volatile) {
2820 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2821 }
2822}
2823
2824void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2825 HandleFieldSet(instruction, instruction->GetFieldInfo());
2826}
2827
2828void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2829 HandleFieldSet(instruction, instruction->GetFieldInfo());
2830}
2831
2832void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2833 HandleFieldGet(instruction, instruction->GetFieldInfo());
2834}
2835
2836void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2837 HandleFieldGet(instruction, instruction->GetFieldInfo());
2838}
2839
2840void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2841 HandleFieldGet(instruction, instruction->GetFieldInfo());
2842}
2843
2844void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2845 HandleFieldGet(instruction, instruction->GetFieldInfo());
2846}
2847
2848void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2849 HandleFieldSet(instruction, instruction->GetFieldInfo());
2850}
2851
2852void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2853 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002854}
2855
2856void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002857 LocationSummary* locations =
2858 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002859 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002860 if (instruction->HasUses()) {
2861 locations->SetOut(Location::SameAsFirstInput());
2862 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002863}
2864
2865void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002866 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002867 codegen_->AddSlowPath(slow_path);
2868
2869 LocationSummary* locations = instruction->GetLocations();
2870 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002871
2872 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002873 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002874 __ b(slow_path->GetEntryLabel(), EQ);
2875 } else {
2876 DCHECK(obj.IsConstant()) << obj;
2877 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2878 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002879 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002880}
2881
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002882void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002883 LocationSummary* locations =
2884 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002885 locations->SetInAt(0, Location::RequiresRegister());
2886 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2887 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002888}
2889
2890void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2891 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002892 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002893 Location index = locations->InAt(1);
2894
2895 switch (instruction->GetType()) {
2896 case Primitive::kPrimBoolean: {
2897 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002898 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002899 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002900 size_t offset =
2901 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002902 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2903 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002904 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002905 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2906 }
2907 break;
2908 }
2909
2910 case Primitive::kPrimByte: {
2911 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002912 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002913 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002914 size_t offset =
2915 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002916 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2917 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002918 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002919 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2920 }
2921 break;
2922 }
2923
2924 case Primitive::kPrimShort: {
2925 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002926 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002927 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002928 size_t offset =
2929 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002930 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2931 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002932 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002933 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2934 }
2935 break;
2936 }
2937
2938 case Primitive::kPrimChar: {
2939 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002940 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002941 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002942 size_t offset =
2943 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002944 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2945 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002946 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002947 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2948 }
2949 break;
2950 }
2951
2952 case Primitive::kPrimInt:
2953 case Primitive::kPrimNot: {
2954 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2955 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002956 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002957 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002958 size_t offset =
2959 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 __ LoadFromOffset(kLoadWord, out, obj, offset);
2961 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002962 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002963 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2964 }
2965 break;
2966 }
2967
2968 case Primitive::kPrimLong: {
2969 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002970 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002971 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002972 size_t offset =
2973 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002974 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002975 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002976 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002977 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002978 }
2979 break;
2980 }
2981
Nicolas Geoffray840e5462015-01-07 16:01:24 +00002982 case Primitive::kPrimFloat: {
2983 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2984 Location out = locations->Out();
2985 DCHECK(out.IsFpuRegister());
2986 if (index.IsConstant()) {
2987 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2988 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
2989 } else {
2990 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
2991 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
2992 }
2993 break;
2994 }
2995
2996 case Primitive::kPrimDouble: {
2997 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2998 Location out = locations->Out();
2999 DCHECK(out.IsFpuRegisterPair());
3000 if (index.IsConstant()) {
3001 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3002 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3003 } else {
3004 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3005 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3006 }
3007 break;
3008 }
3009
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003010 case Primitive::kPrimVoid:
3011 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003012 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003013 }
3014}
3015
3016void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003017 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003018
3019 bool needs_write_barrier =
3020 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3021 bool needs_runtime_call = instruction->NeedsTypeCheck();
3022
Nicolas Geoffray39468442014-09-02 15:17:15 +01003023 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003024 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3025 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003026 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003027 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3028 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3029 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003030 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003031 locations->SetInAt(0, Location::RequiresRegister());
3032 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3033 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003034
3035 if (needs_write_barrier) {
3036 // Temporary registers for the write barrier.
3037 locations->AddTemp(Location::RequiresRegister());
3038 locations->AddTemp(Location::RequiresRegister());
3039 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003040 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003041}
3042
3043void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3044 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003045 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003046 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003047 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003048 bool needs_runtime_call = locations->WillCall();
3049 bool needs_write_barrier =
3050 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003051
3052 switch (value_type) {
3053 case Primitive::kPrimBoolean:
3054 case Primitive::kPrimByte: {
3055 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003056 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003057 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003058 size_t offset =
3059 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003060 __ StoreToOffset(kStoreByte, value, obj, offset);
3061 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003062 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003063 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3064 }
3065 break;
3066 }
3067
3068 case Primitive::kPrimShort:
3069 case Primitive::kPrimChar: {
3070 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003071 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003072 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003073 size_t offset =
3074 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003075 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3076 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003077 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003078 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3079 }
3080 break;
3081 }
3082
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003083 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003084 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003085 if (!needs_runtime_call) {
3086 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003087 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003088 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003089 size_t offset =
3090 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003091 __ StoreToOffset(kStoreWord, value, obj, offset);
3092 } else {
3093 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003094 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003095 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3096 }
3097 if (needs_write_barrier) {
3098 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003099 Register temp = locations->GetTemp(0).AsRegister<Register>();
3100 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003101 codegen_->MarkGCCard(temp, card, obj, value);
3102 }
3103 } else {
3104 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003105 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3106 instruction,
3107 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003108 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003109 break;
3110 }
3111
3112 case Primitive::kPrimLong: {
3113 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003114 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003115 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003116 size_t offset =
3117 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003118 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003119 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003120 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003121 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003122 }
3123 break;
3124 }
3125
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003126 case Primitive::kPrimFloat: {
3127 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3128 Location value = locations->InAt(2);
3129 DCHECK(value.IsFpuRegister());
3130 if (index.IsConstant()) {
3131 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3132 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3133 } else {
3134 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3135 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3136 }
3137 break;
3138 }
3139
3140 case Primitive::kPrimDouble: {
3141 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3142 Location value = locations->InAt(2);
3143 DCHECK(value.IsFpuRegisterPair());
3144 if (index.IsConstant()) {
3145 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3146 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3147 } else {
3148 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3149 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3150 }
3151 break;
3152 }
3153
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003154 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003155 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003156 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003157 }
3158}
3159
3160void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003161 LocationSummary* locations =
3162 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003163 locations->SetInAt(0, Location::RequiresRegister());
3164 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003165}
3166
3167void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3168 LocationSummary* locations = instruction->GetLocations();
3169 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003170 Register obj = locations->InAt(0).AsRegister<Register>();
3171 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003172 __ LoadFromOffset(kLoadWord, out, obj, offset);
3173}
3174
3175void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003176 LocationSummary* locations =
3177 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003178 locations->SetInAt(0, Location::RequiresRegister());
3179 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003180 if (instruction->HasUses()) {
3181 locations->SetOut(Location::SameAsFirstInput());
3182 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003183}
3184
3185void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3186 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003187 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003188 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003189 codegen_->AddSlowPath(slow_path);
3190
Roland Levillain271ab9c2014-11-27 15:23:57 +00003191 Register index = locations->InAt(0).AsRegister<Register>();
3192 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003193
3194 __ cmp(index, ShifterOperand(length));
3195 __ b(slow_path->GetEntryLabel(), CS);
3196}
3197
3198void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3199 Label is_null;
3200 __ CompareAndBranchIfZero(value, &is_null);
3201 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3202 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3203 __ strb(card, Address(card, temp));
3204 __ Bind(&is_null);
3205}
3206
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003207void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3208 temp->SetLocations(nullptr);
3209}
3210
3211void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3212 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003213 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003214}
3215
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003216void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003217 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003218 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003219}
3220
3221void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003222 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3223}
3224
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003225void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3226 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3227}
3228
3229void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003230 HBasicBlock* block = instruction->GetBlock();
3231 if (block->GetLoopInformation() != nullptr) {
3232 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3233 // The back edge will generate the suspend check.
3234 return;
3235 }
3236 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3237 // The goto will generate the suspend check.
3238 return;
3239 }
3240 GenerateSuspendCheck(instruction, nullptr);
3241}
3242
3243void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3244 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003245 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003246 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003247 codegen_->AddSlowPath(slow_path);
3248
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003249 __ LoadFromOffset(
3250 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3251 __ cmp(IP, ShifterOperand(0));
3252 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003253 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003254 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003255 __ Bind(slow_path->GetReturnLabel());
3256 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003257 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003258 __ b(slow_path->GetEntryLabel());
3259 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003260}
3261
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003262ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3263 return codegen_->GetAssembler();
3264}
3265
3266void ParallelMoveResolverARM::EmitMove(size_t index) {
3267 MoveOperands* move = moves_.Get(index);
3268 Location source = move->GetSource();
3269 Location destination = move->GetDestination();
3270
3271 if (source.IsRegister()) {
3272 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003273 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003274 } else {
3275 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003276 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003277 SP, destination.GetStackIndex());
3278 }
3279 } else if (source.IsStackSlot()) {
3280 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003281 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003282 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003283 } else if (destination.IsFpuRegister()) {
3284 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003285 } else {
3286 DCHECK(destination.IsStackSlot());
3287 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3288 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3289 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003290 } else if (source.IsFpuRegister()) {
3291 if (destination.IsFpuRegister()) {
3292 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003293 } else {
3294 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003295 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3296 }
3297 } else if (source.IsFpuRegisterPair()) {
3298 if (destination.IsFpuRegisterPair()) {
3299 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3300 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3301 } else {
3302 DCHECK(destination.IsDoubleStackSlot()) << destination;
3303 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3304 SP, destination.GetStackIndex());
3305 }
3306 } else if (source.IsDoubleStackSlot()) {
3307 if (destination.IsFpuRegisterPair()) {
3308 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3309 SP, source.GetStackIndex());
3310 } else {
3311 DCHECK(destination.IsDoubleStackSlot()) << destination;
3312 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003313 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003314 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3315 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3316 }
3317 } else {
3318 DCHECK(source.IsConstant()) << source;
3319 HInstruction* constant = source.GetConstant();
3320 if (constant->IsIntConstant()) {
3321 int32_t value = constant->AsIntConstant()->GetValue();
3322 if (destination.IsRegister()) {
3323 __ LoadImmediate(destination.AsRegister<Register>(), value);
3324 } else {
3325 DCHECK(destination.IsStackSlot());
3326 __ LoadImmediate(IP, value);
3327 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3328 }
3329 } else {
3330 DCHECK(constant->IsFloatConstant());
3331 float value = constant->AsFloatConstant()->GetValue();
3332 if (destination.IsFpuRegister()) {
3333 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3334 } else {
3335 DCHECK(destination.IsStackSlot());
3336 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3337 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3338 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003339 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003340 }
3341}
3342
3343void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3344 __ Mov(IP, reg);
3345 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3346 __ StoreToOffset(kStoreWord, IP, SP, mem);
3347}
3348
3349void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3350 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3351 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3352 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3353 SP, mem1 + stack_offset);
3354 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3355 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3356 SP, mem2 + stack_offset);
3357 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3358}
3359
3360void ParallelMoveResolverARM::EmitSwap(size_t index) {
3361 MoveOperands* move = moves_.Get(index);
3362 Location source = move->GetSource();
3363 Location destination = move->GetDestination();
3364
3365 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003366 DCHECK_NE(source.AsRegister<Register>(), IP);
3367 DCHECK_NE(destination.AsRegister<Register>(), IP);
3368 __ Mov(IP, source.AsRegister<Register>());
3369 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3370 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003371 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003372 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003373 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003374 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003375 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3376 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003377 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
3378 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
3379 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
3380 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
3381 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3382 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3383 : destination.AsFpuRegister<SRegister>();
3384 int mem = source.IsFpuRegister()
3385 ? destination.GetStackIndex()
3386 : source.GetStackIndex();
3387
3388 __ vmovrs(IP, reg);
3389 __ LoadSFromOffset(reg, SP, mem);
3390 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003391 } else {
3392 LOG(FATAL) << "Unimplemented";
3393 }
3394}
3395
3396void ParallelMoveResolverARM::SpillScratch(int reg) {
3397 __ Push(static_cast<Register>(reg));
3398}
3399
3400void ParallelMoveResolverARM::RestoreScratch(int reg) {
3401 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003402}
3403
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003404void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003405 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3406 ? LocationSummary::kCallOnSlowPath
3407 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003408 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003409 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003410 locations->SetOut(Location::RequiresRegister());
3411}
3412
3413void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003414 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003415 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003416 DCHECK(!cls->CanCallRuntime());
3417 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003418 codegen_->LoadCurrentMethod(out);
3419 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3420 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003421 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003422 codegen_->LoadCurrentMethod(out);
3423 __ LoadFromOffset(
3424 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3425 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003426
3427 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3428 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3429 codegen_->AddSlowPath(slow_path);
3430 __ cmp(out, ShifterOperand(0));
3431 __ b(slow_path->GetEntryLabel(), EQ);
3432 if (cls->MustGenerateClinitCheck()) {
3433 GenerateClassInitializationCheck(slow_path, out);
3434 } else {
3435 __ Bind(slow_path->GetExitLabel());
3436 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003437 }
3438}
3439
3440void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3441 LocationSummary* locations =
3442 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3443 locations->SetInAt(0, Location::RequiresRegister());
3444 if (check->HasUses()) {
3445 locations->SetOut(Location::SameAsFirstInput());
3446 }
3447}
3448
3449void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003450 // We assume the class is not null.
3451 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3452 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003453 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003454 GenerateClassInitializationCheck(slow_path,
3455 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003456}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003457
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003458void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3459 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003460 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3461 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3462 __ b(slow_path->GetEntryLabel(), LT);
3463 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3464 // properly. Therefore, we do a memory fence.
3465 __ dmb(ISH);
3466 __ Bind(slow_path->GetExitLabel());
3467}
3468
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003469void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3470 LocationSummary* locations =
3471 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3472 locations->SetOut(Location::RequiresRegister());
3473}
3474
3475void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3476 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3477 codegen_->AddSlowPath(slow_path);
3478
Roland Levillain271ab9c2014-11-27 15:23:57 +00003479 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003480 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003481 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3482 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003483 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3484 __ cmp(out, ShifterOperand(0));
3485 __ b(slow_path->GetEntryLabel(), EQ);
3486 __ Bind(slow_path->GetExitLabel());
3487}
3488
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003489void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3490 LocationSummary* locations =
3491 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3492 locations->SetOut(Location::RequiresRegister());
3493}
3494
3495void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003496 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003497 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3498 __ LoadFromOffset(kLoadWord, out, TR, offset);
3499 __ LoadImmediate(IP, 0);
3500 __ StoreToOffset(kStoreWord, IP, TR, offset);
3501}
3502
3503void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3504 LocationSummary* locations =
3505 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3506 InvokeRuntimeCallingConvention calling_convention;
3507 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3508}
3509
3510void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3511 codegen_->InvokeRuntime(
3512 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3513}
3514
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003515void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003516 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3517 ? LocationSummary::kNoCall
3518 : LocationSummary::kCallOnSlowPath;
3519 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3520 locations->SetInAt(0, Location::RequiresRegister());
3521 locations->SetInAt(1, Location::RequiresRegister());
3522 locations->SetOut(Location::RequiresRegister());
3523}
3524
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003525void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003526 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003527 Register obj = locations->InAt(0).AsRegister<Register>();
3528 Register cls = locations->InAt(1).AsRegister<Register>();
3529 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003530 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3531 Label done, zero;
3532 SlowPathCodeARM* slow_path = nullptr;
3533
3534 // Return 0 if `obj` is null.
3535 // TODO: avoid this check if we know obj is not null.
3536 __ cmp(obj, ShifterOperand(0));
3537 __ b(&zero, EQ);
3538 // Compare the class of `obj` with `cls`.
3539 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3540 __ cmp(out, ShifterOperand(cls));
3541 if (instruction->IsClassFinal()) {
3542 // Classes must be equal for the instanceof to succeed.
3543 __ b(&zero, NE);
3544 __ LoadImmediate(out, 1);
3545 __ b(&done);
3546 } else {
3547 // If the classes are not equal, we go into a slow path.
3548 DCHECK(locations->OnlyCallsOnSlowPath());
3549 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003550 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003551 codegen_->AddSlowPath(slow_path);
3552 __ b(slow_path->GetEntryLabel(), NE);
3553 __ LoadImmediate(out, 1);
3554 __ b(&done);
3555 }
3556 __ Bind(&zero);
3557 __ LoadImmediate(out, 0);
3558 if (slow_path != nullptr) {
3559 __ Bind(slow_path->GetExitLabel());
3560 }
3561 __ Bind(&done);
3562}
3563
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003564void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3565 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3566 instruction, LocationSummary::kCallOnSlowPath);
3567 locations->SetInAt(0, Location::RequiresRegister());
3568 locations->SetInAt(1, Location::RequiresRegister());
3569 locations->AddTemp(Location::RequiresRegister());
3570}
3571
3572void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3573 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003574 Register obj = locations->InAt(0).AsRegister<Register>();
3575 Register cls = locations->InAt(1).AsRegister<Register>();
3576 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003577 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3578
3579 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3580 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3581 codegen_->AddSlowPath(slow_path);
3582
3583 // TODO: avoid this check if we know obj is not null.
3584 __ cmp(obj, ShifterOperand(0));
3585 __ b(slow_path->GetExitLabel(), EQ);
3586 // Compare the class of `obj` with `cls`.
3587 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3588 __ cmp(temp, ShifterOperand(cls));
3589 __ b(slow_path->GetEntryLabel(), NE);
3590 __ Bind(slow_path->GetExitLabel());
3591}
3592
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003593void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3594 LocationSummary* locations =
3595 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3596 InvokeRuntimeCallingConvention calling_convention;
3597 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3598}
3599
3600void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3601 codegen_->InvokeRuntime(instruction->IsEnter()
3602 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3603 instruction,
3604 instruction->GetDexPc());
3605}
3606
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003607void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3608void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3609void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3610
3611void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3612 LocationSummary* locations =
3613 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3614 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3615 || instruction->GetResultType() == Primitive::kPrimLong);
3616 locations->SetInAt(0, Location::RequiresRegister());
3617 locations->SetInAt(1, Location::RequiresRegister());
3618 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3619 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3620}
3621
3622void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3623 HandleBitwiseOperation(instruction);
3624}
3625
3626void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3627 HandleBitwiseOperation(instruction);
3628}
3629
3630void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3631 HandleBitwiseOperation(instruction);
3632}
3633
3634void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3635 LocationSummary* locations = instruction->GetLocations();
3636
3637 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003638 Register first = locations->InAt(0).AsRegister<Register>();
3639 Register second = locations->InAt(1).AsRegister<Register>();
3640 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003641 if (instruction->IsAnd()) {
3642 __ and_(out, first, ShifterOperand(second));
3643 } else if (instruction->IsOr()) {
3644 __ orr(out, first, ShifterOperand(second));
3645 } else {
3646 DCHECK(instruction->IsXor());
3647 __ eor(out, first, ShifterOperand(second));
3648 }
3649 } else {
3650 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3651 Location first = locations->InAt(0);
3652 Location second = locations->InAt(1);
3653 Location out = locations->Out();
3654 if (instruction->IsAnd()) {
3655 __ and_(out.AsRegisterPairLow<Register>(),
3656 first.AsRegisterPairLow<Register>(),
3657 ShifterOperand(second.AsRegisterPairLow<Register>()));
3658 __ and_(out.AsRegisterPairHigh<Register>(),
3659 first.AsRegisterPairHigh<Register>(),
3660 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3661 } else if (instruction->IsOr()) {
3662 __ orr(out.AsRegisterPairLow<Register>(),
3663 first.AsRegisterPairLow<Register>(),
3664 ShifterOperand(second.AsRegisterPairLow<Register>()));
3665 __ orr(out.AsRegisterPairHigh<Register>(),
3666 first.AsRegisterPairHigh<Register>(),
3667 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3668 } else {
3669 DCHECK(instruction->IsXor());
3670 __ eor(out.AsRegisterPairLow<Register>(),
3671 first.AsRegisterPairLow<Register>(),
3672 ShifterOperand(second.AsRegisterPairLow<Register>()));
3673 __ eor(out.AsRegisterPairHigh<Register>(),
3674 first.AsRegisterPairHigh<Register>(),
3675 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3676 }
3677 }
3678}
3679
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003680} // namespace arm
3681} // namespace art