blob: 1cc2dcc9b8e552270506fa11215959fac2ec70e3 [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 Geoffray56b9ee62014-10-09 11:47:51 +0100593 ArmManagedRegister pair = ArmManagedRegister::FromRegisterPair(
594 calling_convention.GetRegisterPairAt(index));
595 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100596 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000597 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
598 }
599 }
600
601 case Primitive::kPrimFloat: {
602 uint32_t stack_index = stack_index_++;
603 if (float_index_ % 2 == 0) {
604 float_index_ = std::max(double_index_, float_index_);
605 }
606 if (float_index_ < calling_convention.GetNumberOfFpuRegisters()) {
607 return Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(float_index_++));
608 } else {
609 return Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index));
610 }
611 }
612
613 case Primitive::kPrimDouble: {
614 double_index_ = std::max(double_index_, RoundUp(float_index_, 2));
615 uint32_t stack_index = stack_index_;
616 stack_index_ += 2;
617 if (double_index_ + 1 < calling_convention.GetNumberOfFpuRegisters()) {
618 uint32_t index = double_index_;
619 double_index_ += 2;
620 return Location::FpuRegisterPairLocation(
621 calling_convention.GetFpuRegisterAt(index),
622 calling_convention.GetFpuRegisterAt(index + 1));
623 } else {
624 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(stack_index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100625 }
626 }
627
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100628 case Primitive::kPrimVoid:
629 LOG(FATAL) << "Unexpected parameter type " << type;
630 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100631 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100632 return Location();
633}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100634
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000635Location InvokeDexCallingConventionVisitor::GetReturnLocation(Primitive::Type type) {
636 switch (type) {
637 case Primitive::kPrimBoolean:
638 case Primitive::kPrimByte:
639 case Primitive::kPrimChar:
640 case Primitive::kPrimShort:
641 case Primitive::kPrimInt:
642 case Primitive::kPrimNot: {
643 return Location::RegisterLocation(R0);
644 }
645
646 case Primitive::kPrimFloat: {
647 return Location::FpuRegisterLocation(S0);
648 }
649
650 case Primitive::kPrimLong: {
651 return Location::RegisterPairLocation(R0, R1);
652 }
653
654 case Primitive::kPrimDouble: {
655 return Location::FpuRegisterPairLocation(S0, S1);
656 }
657
658 case Primitive::kPrimVoid:
659 return Location();
660 }
661 UNREACHABLE();
662 return Location();
663}
664
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665void CodeGeneratorARM::Move32(Location destination, Location source) {
666 if (source.Equals(destination)) {
667 return;
668 }
669 if (destination.IsRegister()) {
670 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000671 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100672 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000673 __ vmovrs(destination.AsRegister<Register>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100674 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000675 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(), SP, source.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100676 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100677 } else if (destination.IsFpuRegister()) {
678 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000679 __ vmovsr(destination.AsFpuRegister<SRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100680 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000681 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100682 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000683 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100684 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100685 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000686 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100687 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000688 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(), SP, destination.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100689 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000690 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100691 } else {
Calin Juravlea21f5982014-11-13 15:53:04 +0000692 DCHECK(source.IsStackSlot()) << source;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100693 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
694 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100695 }
696 }
697}
698
699void CodeGeneratorARM::Move64(Location destination, Location source) {
700 if (source.Equals(destination)) {
701 return;
702 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100703 if (destination.IsRegisterPair()) {
704 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000705 EmitParallelMoves(
706 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
707 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
708 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
709 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100710 } else if (source.IsFpuRegister()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000711 UNIMPLEMENTED(FATAL);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100712 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000713 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100714 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100715 if (destination.AsRegisterPairLow<Register>() == R1) {
716 DCHECK_EQ(destination.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100717 __ LoadFromOffset(kLoadWord, R1, SP, source.GetStackIndex());
718 __ LoadFromOffset(kLoadWord, R2, SP, source.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100720 __ LoadFromOffset(kLoadWordPair, destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100721 SP, source.GetStackIndex());
722 }
723 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000724 } else if (destination.IsFpuRegisterPair()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100725 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000726 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
727 SP,
728 source.GetStackIndex());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 } else {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000730 UNIMPLEMENTED(FATAL);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100731 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100732 } else {
733 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100734 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000735 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100736 if (source.AsRegisterPairLow<Register>() == R1) {
737 DCHECK_EQ(source.AsRegisterPairHigh<Register>(), R2);
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100738 __ StoreToOffset(kStoreWord, R1, SP, destination.GetStackIndex());
739 __ StoreToOffset(kStoreWord, R2, SP, destination.GetHighStackIndex(kArmWordSize));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100740 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100741 __ StoreToOffset(kStoreWordPair, source.AsRegisterPairLow<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100742 SP, destination.GetStackIndex());
743 }
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +0000744 } else if (source.IsFpuRegisterPair()) {
745 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
746 SP,
747 destination.GetStackIndex());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100748 } else {
749 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000750 EmitParallelMoves(
751 Location::StackSlot(source.GetStackIndex()),
752 Location::StackSlot(destination.GetStackIndex()),
753 Location::StackSlot(source.GetHighStackIndex(kArmWordSize)),
754 Location::StackSlot(destination.GetHighStackIndex(kArmWordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100755 }
756 }
757}
758
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100759void CodeGeneratorARM::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100760 LocationSummary* locations = instruction->GetLocations();
761 if (locations != nullptr && locations->Out().Equals(location)) {
762 return;
763 }
764
Calin Juravlea21f5982014-11-13 15:53:04 +0000765 if (locations != nullptr && locations->Out().IsConstant()) {
766 HConstant* const_to_move = locations->Out().GetConstant();
767 if (const_to_move->IsIntConstant()) {
768 int32_t value = const_to_move->AsIntConstant()->GetValue();
769 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000770 __ LoadImmediate(location.AsRegister<Register>(), value);
Calin Juravlea21f5982014-11-13 15:53:04 +0000771 } else {
772 DCHECK(location.IsStackSlot());
773 __ LoadImmediate(IP, value);
774 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
775 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +0000776 } else {
777 DCHECK(const_to_move->IsLongConstant()) << const_to_move;
Calin Juravlea21f5982014-11-13 15:53:04 +0000778 int64_t value = const_to_move->AsLongConstant()->GetValue();
779 if (location.IsRegisterPair()) {
780 __ LoadImmediate(location.AsRegisterPairLow<Register>(), Low32Bits(value));
781 __ LoadImmediate(location.AsRegisterPairHigh<Register>(), High32Bits(value));
782 } else {
783 DCHECK(location.IsDoubleStackSlot());
784 __ LoadImmediate(IP, Low32Bits(value));
785 __ StoreToOffset(kStoreWord, IP, SP, location.GetStackIndex());
786 __ LoadImmediate(IP, High32Bits(value));
787 __ StoreToOffset(kStoreWord, IP, SP, location.GetHighStackIndex(kArmWordSize));
788 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100789 }
Roland Levillain476df552014-10-09 17:51:36 +0100790 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100791 uint32_t stack_slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
792 switch (instruction->GetType()) {
793 case Primitive::kPrimBoolean:
794 case Primitive::kPrimByte:
795 case Primitive::kPrimChar:
796 case Primitive::kPrimShort:
797 case Primitive::kPrimInt:
798 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100799 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100800 Move32(location, Location::StackSlot(stack_slot));
801 break;
802
803 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100804 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100805 Move64(location, Location::DoubleStackSlot(stack_slot));
806 break;
807
808 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100809 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100810 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000811 } else if (instruction->IsTemporary()) {
812 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000813 if (temp_location.IsStackSlot()) {
814 Move32(location, temp_location);
815 } else {
816 DCHECK(temp_location.IsDoubleStackSlot());
817 Move64(location, temp_location);
818 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000819 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100820 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100821 switch (instruction->GetType()) {
822 case Primitive::kPrimBoolean:
823 case Primitive::kPrimByte:
824 case Primitive::kPrimChar:
825 case Primitive::kPrimShort:
826 case Primitive::kPrimNot:
827 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100828 case Primitive::kPrimFloat:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100829 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100830 break;
831
832 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100833 case Primitive::kPrimDouble:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100834 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100835 break;
836
837 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100838 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100839 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000840 }
841}
842
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100843void CodeGeneratorARM::InvokeRuntime(int32_t entry_point_offset,
844 HInstruction* instruction,
845 uint32_t dex_pc) {
846 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
847 __ blx(LR);
848 RecordPcInfo(instruction, dex_pc);
849 DCHECK(instruction->IsSuspendCheck()
850 || instruction->IsBoundsCheck()
851 || instruction->IsNullCheck()
Calin Juravled0d48522014-11-04 16:40:20 +0000852 || instruction->IsDivZeroCheck()
Roland Levillain624279f2014-12-04 11:54:28 +0000853 || instruction->GetLocations()->CanCall()
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100854 || !IsLeafMethod());
855}
856
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000857void LocationsBuilderARM::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000858 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000859}
860
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000861void InstructionCodeGeneratorARM::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000862 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100863 DCHECK(!successor->IsExitBlock());
864
865 HBasicBlock* block = got->GetBlock();
866 HInstruction* previous = got->GetPrevious();
867
868 HLoopInformation* info = block->GetLoopInformation();
869 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
870 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
871 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
872 return;
873 }
874
875 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
876 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
877 }
878 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000879 __ b(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000880 }
881}
882
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000883void LocationsBuilderARM::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000884 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000885}
886
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000887void InstructionCodeGeneratorARM::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700888 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000889 if (kIsDebugBuild) {
890 __ Comment("Unreachable");
891 __ bkpt(0);
892 }
893}
894
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000895void LocationsBuilderARM::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100896 LocationSummary* locations =
897 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100898 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100899 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100900 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100901 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000902}
903
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000904void InstructionCodeGeneratorARM::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700905 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100906 if (cond->IsIntConstant()) {
907 // Constant condition, statically compared against 1.
908 int32_t cond_value = cond->AsIntConstant()->GetValue();
909 if (cond_value == 1) {
910 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
911 if_instr->IfTrueSuccessor())) {
912 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100913 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100914 return;
915 } else {
916 DCHECK_EQ(cond_value, 0);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100917 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100918 } else {
919 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
920 // Condition has been materialized, compare the output to 0
921 DCHECK(if_instr->GetLocations()->InAt(0).IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000922 __ cmp(if_instr->GetLocations()->InAt(0).AsRegister<Register>(),
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100923 ShifterOperand(0));
924 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()), NE);
925 } else {
926 // Condition has not been materialized, use its inputs as the
927 // comparison and its condition as the branch condition.
928 LocationSummary* locations = cond->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000929 Register left = locations->InAt(0).AsRegister<Register>();
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100930 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000931 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100932 } else {
933 DCHECK(locations->InAt(1).IsConstant());
934 int32_t value =
935 locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
936 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000937 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
938 __ cmp(left, operand);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100939 } else {
940 Register temp = IP;
941 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000942 __ cmp(left, ShifterOperand(temp));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100943 }
944 }
945 __ b(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()),
946 ARMCondition(cond->AsCondition()->GetCondition()));
947 }
Dave Allison20dfc792014-06-16 20:44:29 -0700948 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100949 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
950 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700951 __ b(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000952 }
953}
954
Dave Allison20dfc792014-06-16 20:44:29 -0700955
956void LocationsBuilderARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100957 LocationSummary* locations =
958 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100959 locations->SetInAt(0, Location::RequiresRegister());
960 locations->SetInAt(1, Location::RegisterOrConstant(comp->InputAt(1)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100961 if (comp->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100962 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100963 }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000964}
965
Dave Allison20dfc792014-06-16 20:44:29 -0700966void InstructionCodeGeneratorARM::VisitCondition(HCondition* comp) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100967 if (!comp->NeedsMaterialization()) return;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100968 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000969 Register left = locations->InAt(0).AsRegister<Register>();
970
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100971 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000972 __ cmp(left, ShifterOperand(locations->InAt(1).AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100973 } else {
974 DCHECK(locations->InAt(1).IsConstant());
975 int32_t value = locations->InAt(1).GetConstant()->AsIntConstant()->GetValue();
976 ShifterOperand operand;
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000977 if (GetAssembler()->ShifterOperandCanHold(R0, left, CMP, value, &operand)) {
978 __ cmp(left, operand);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100979 } else {
980 Register temp = IP;
981 __ LoadImmediate(temp, value);
Nicolas Geoffray3bcc8ea2014-11-28 15:00:02 +0000982 __ cmp(left, ShifterOperand(temp));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100983 }
Dave Allison20dfc792014-06-16 20:44:29 -0700984 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100985 __ it(ARMCondition(comp->GetCondition()), kItElse);
Roland Levillain271ab9c2014-11-27 15:23:57 +0000986 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(1),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100987 ARMCondition(comp->GetCondition()));
Roland Levillain271ab9c2014-11-27 15:23:57 +0000988 __ mov(locations->Out().AsRegister<Register>(), ShifterOperand(0),
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100989 ARMOppositeCondition(comp->GetCondition()));
Dave Allison20dfc792014-06-16 20:44:29 -0700990}
991
992void LocationsBuilderARM::VisitEqual(HEqual* comp) {
993 VisitCondition(comp);
994}
995
996void InstructionCodeGeneratorARM::VisitEqual(HEqual* comp) {
997 VisitCondition(comp);
998}
999
1000void LocationsBuilderARM::VisitNotEqual(HNotEqual* comp) {
1001 VisitCondition(comp);
1002}
1003
1004void InstructionCodeGeneratorARM::VisitNotEqual(HNotEqual* comp) {
1005 VisitCondition(comp);
1006}
1007
1008void LocationsBuilderARM::VisitLessThan(HLessThan* comp) {
1009 VisitCondition(comp);
1010}
1011
1012void InstructionCodeGeneratorARM::VisitLessThan(HLessThan* comp) {
1013 VisitCondition(comp);
1014}
1015
1016void LocationsBuilderARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1017 VisitCondition(comp);
1018}
1019
1020void InstructionCodeGeneratorARM::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
1021 VisitCondition(comp);
1022}
1023
1024void LocationsBuilderARM::VisitGreaterThan(HGreaterThan* comp) {
1025 VisitCondition(comp);
1026}
1027
1028void InstructionCodeGeneratorARM::VisitGreaterThan(HGreaterThan* comp) {
1029 VisitCondition(comp);
1030}
1031
1032void LocationsBuilderARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1033 VisitCondition(comp);
1034}
1035
1036void InstructionCodeGeneratorARM::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1037 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001038}
1039
1040void LocationsBuilderARM::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001041 local->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001042}
1043
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001044void InstructionCodeGeneratorARM::VisitLocal(HLocal* local) {
1045 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001046}
1047
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001048void LocationsBuilderARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001049 load->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001050}
1051
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001052void InstructionCodeGeneratorARM::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001053 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001054 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001055}
1056
1057void LocationsBuilderARM::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001058 LocationSummary* locations =
1059 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001060 switch (store->InputAt(1)->GetType()) {
1061 case Primitive::kPrimBoolean:
1062 case Primitive::kPrimByte:
1063 case Primitive::kPrimChar:
1064 case Primitive::kPrimShort:
1065 case Primitive::kPrimInt:
1066 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001067 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001068 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
1069 break;
1070
1071 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001072 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001073 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
1074 break;
1075
1076 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001077 LOG(FATAL) << "Unexpected local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001078 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001079}
1080
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001081void InstructionCodeGeneratorARM::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001082 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001083}
1084
1085void LocationsBuilderARM::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001086 LocationSummary* locations =
1087 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001088 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001089}
1090
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001091void InstructionCodeGeneratorARM::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001092 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001093 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001094}
1095
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001096void LocationsBuilderARM::VisitLongConstant(HLongConstant* 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 Geoffray01bc96d2014-04-11 17:43:50 +01001100}
1101
1102void InstructionCodeGeneratorARM::VisitLongConstant(HLongConstant* constant) {
1103 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001104 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001105}
1106
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001107void LocationsBuilderARM::VisitFloatConstant(HFloatConstant* constant) {
1108 LocationSummary* locations =
1109 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1110 locations->SetOut(Location::ConstantLocation(constant));
1111}
1112
1113void InstructionCodeGeneratorARM::VisitFloatConstant(HFloatConstant* constant) {
1114 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001115 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001116}
1117
1118void LocationsBuilderARM::VisitDoubleConstant(HDoubleConstant* constant) {
1119 LocationSummary* locations =
1120 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1121 locations->SetOut(Location::ConstantLocation(constant));
1122}
1123
1124void InstructionCodeGeneratorARM::VisitDoubleConstant(HDoubleConstant* 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
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001129void LocationsBuilderARM::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001130 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001131}
1132
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001133void InstructionCodeGeneratorARM::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001134 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001135 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001136}
1137
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001138void LocationsBuilderARM::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001139 LocationSummary* locations =
1140 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001141 locations->SetInAt(0, parameter_visitor_.GetReturnLocation(ret->InputAt(0)->GetType()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001142}
1143
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001144void InstructionCodeGeneratorARM::VisitReturn(HReturn* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001145 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001146 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001147}
1148
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001149void LocationsBuilderARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001150 HandleInvoke(invoke);
1151}
1152
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001153void CodeGeneratorARM::LoadCurrentMethod(Register reg) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001154 __ LoadFromOffset(kLoadWord, reg, SP, kCurrentMethodStackOffset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001155}
1156
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001157void InstructionCodeGeneratorARM::VisitInvokeStaticOrDirect(HInvokeStaticOrDirect* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001158 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001159
1160 // TODO: Implement all kinds of calls:
1161 // 1) boot -> boot
1162 // 2) app -> boot
1163 // 3) app -> app
1164 //
1165 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1166
1167 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001168 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001169 // temp = temp->dex_cache_resolved_methods_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001170 __ LoadFromOffset(
1171 kLoadWord, temp, temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value());
Nicolas Geoffray4e44c822014-12-17 12:25:12 +00001172 // temp = temp[index_in_cache]
1173 __ LoadFromOffset(
1174 kLoadWord, temp, temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache()));
1175 // LR = temp[offset_of_quick_compiled_code]
1176 __ LoadFromOffset(kLoadWord, LR, temp,
1177 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
1178 kArmWordSize).Int32Value());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001179 // LR()
1180 __ blx(LR);
1181
1182 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1183 DCHECK(!codegen_->IsLeafMethod());
1184}
1185
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001186void LocationsBuilderARM::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001187 LocationSummary* locations =
1188 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001189 locations->AddTemp(Location::RegisterLocation(R0));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001190
1191 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001192 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001193 HInstruction* input = invoke->InputAt(i);
1194 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1195 }
1196
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001197 locations->SetOut(calling_convention_visitor.GetReturnLocation(invoke->GetType()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001198}
1199
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001200void LocationsBuilderARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1201 HandleInvoke(invoke);
1202}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001203
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001204void InstructionCodeGeneratorARM::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001205 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001206 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1207 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1208 LocationSummary* locations = invoke->GetLocations();
1209 Location receiver = locations->InAt(0);
1210 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1211 // temp = object->GetClass();
1212 if (receiver.IsStackSlot()) {
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001213 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1214 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001215 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001216 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001217 }
1218 // temp = temp->GetMethodAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001219 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001220 kArmWordSize).Int32Value();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001221 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001222 // LR = temp->GetEntryPoint();
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001223 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001224 // LR();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001225 __ blx(LR);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001226 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001227 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001228}
1229
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001230void LocationsBuilderARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1231 HandleInvoke(invoke);
1232 // Add the hidden argument.
1233 invoke->GetLocations()->AddTemp(Location::RegisterLocation(R12));
1234}
1235
1236void InstructionCodeGeneratorARM::VisitInvokeInterface(HInvokeInterface* invoke) {
1237 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001238 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001239 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1240 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1241 LocationSummary* locations = invoke->GetLocations();
1242 Location receiver = locations->InAt(0);
1243 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1244
1245 // Set the hidden argument.
Roland Levillain199f3362014-11-27 17:15:16 +00001246 __ LoadImmediate(invoke->GetLocations()->GetTemp(1).AsRegister<Register>(),
1247 invoke->GetDexMethodIndex());
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001248
1249 // temp = object->GetClass();
1250 if (receiver.IsStackSlot()) {
1251 __ LoadFromOffset(kLoadWord, temp, SP, receiver.GetStackIndex());
1252 __ LoadFromOffset(kLoadWord, temp, temp, class_offset);
1253 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001254 __ LoadFromOffset(kLoadWord, temp, receiver.AsRegister<Register>(), class_offset);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001255 }
1256 // temp = temp->GetImtEntryAt(method_offset);
Mathieu Chartier2d721012014-11-10 11:08:06 -08001257 uint32_t entry_point = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001258 kArmWordSize).Int32Value();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001259 __ LoadFromOffset(kLoadWord, temp, temp, method_offset);
1260 // LR = temp->GetEntryPoint();
1261 __ LoadFromOffset(kLoadWord, LR, temp, entry_point);
1262 // LR();
1263 __ blx(LR);
1264 DCHECK(!codegen_->IsLeafMethod());
1265 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1266}
1267
Roland Levillain88cb1752014-10-20 16:36:47 +01001268void LocationsBuilderARM::VisitNeg(HNeg* neg) {
1269 LocationSummary* locations =
1270 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1271 switch (neg->GetResultType()) {
1272 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001273 case Primitive::kPrimLong: {
1274 bool output_overlaps = (neg->GetResultType() == Primitive::kPrimLong);
Roland Levillain88cb1752014-10-20 16:36:47 +01001275 locations->SetInAt(0, Location::RequiresRegister());
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001276 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Roland Levillain88cb1752014-10-20 16:36:47 +01001277 break;
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001278 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001279
Roland Levillain88cb1752014-10-20 16:36:47 +01001280 case Primitive::kPrimFloat:
1281 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001282 locations->SetInAt(0, Location::RequiresFpuRegister());
1283 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillain88cb1752014-10-20 16:36:47 +01001284 break;
1285
1286 default:
1287 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1288 }
1289}
1290
1291void InstructionCodeGeneratorARM::VisitNeg(HNeg* neg) {
1292 LocationSummary* locations = neg->GetLocations();
1293 Location out = locations->Out();
1294 Location in = locations->InAt(0);
1295 switch (neg->GetResultType()) {
1296 case Primitive::kPrimInt:
1297 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001298 __ rsb(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(0));
Roland Levillain88cb1752014-10-20 16:36:47 +01001299 break;
1300
1301 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001302 DCHECK(in.IsRegisterPair());
1303 // out.lo = 0 - in.lo (and update the carry/borrow (C) flag)
1304 __ rsbs(out.AsRegisterPairLow<Register>(),
1305 in.AsRegisterPairLow<Register>(),
1306 ShifterOperand(0));
1307 // We cannot emit an RSC (Reverse Subtract with Carry)
1308 // instruction here, as it does not exist in the Thumb-2
1309 // instruction set. We use the following approach
1310 // using SBC and SUB instead.
1311 //
1312 // out.hi = -C
1313 __ sbc(out.AsRegisterPairHigh<Register>(),
1314 out.AsRegisterPairHigh<Register>(),
1315 ShifterOperand(out.AsRegisterPairHigh<Register>()));
1316 // out.hi = out.hi - in.hi
1317 __ sub(out.AsRegisterPairHigh<Register>(),
1318 out.AsRegisterPairHigh<Register>(),
1319 ShifterOperand(in.AsRegisterPairHigh<Register>()));
1320 break;
1321
Roland Levillain88cb1752014-10-20 16:36:47 +01001322 case Primitive::kPrimFloat:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001323 DCHECK(in.IsFpuRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001324 __ vnegs(out.AsFpuRegister<SRegister>(), in.AsFpuRegister<SRegister>());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001325 break;
1326
Roland Levillain88cb1752014-10-20 16:36:47 +01001327 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001328 DCHECK(in.IsFpuRegisterPair());
1329 __ vnegd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1330 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillain88cb1752014-10-20 16:36:47 +01001331 break;
1332
1333 default:
1334 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1335 }
1336}
1337
Roland Levillaindff1f282014-11-05 14:15:05 +00001338void LocationsBuilderARM::VisitTypeConversion(HTypeConversion* conversion) {
Roland Levillaindff1f282014-11-05 14:15:05 +00001339 Primitive::Type result_type = conversion->GetResultType();
1340 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001341 DCHECK_NE(result_type, input_type);
Roland Levillain624279f2014-12-04 11:54:28 +00001342
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001343 // The float-to-long and double-to-long type conversions rely on a
1344 // call to the runtime.
Roland Levillain624279f2014-12-04 11:54:28 +00001345 LocationSummary::CallKind call_kind =
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001346 ((input_type == Primitive::kPrimFloat || input_type == Primitive::kPrimDouble)
1347 && result_type == Primitive::kPrimLong)
Roland Levillain624279f2014-12-04 11:54:28 +00001348 ? LocationSummary::kCall
1349 : LocationSummary::kNoCall;
1350 LocationSummary* locations =
1351 new (GetGraph()->GetArena()) LocationSummary(conversion, call_kind);
1352
Roland Levillaindff1f282014-11-05 14:15:05 +00001353 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001354 case Primitive::kPrimByte:
1355 switch (input_type) {
1356 case Primitive::kPrimShort:
1357 case Primitive::kPrimInt:
1358 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001359 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001360 locations->SetInAt(0, Location::RequiresRegister());
1361 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1362 break;
1363
1364 default:
1365 LOG(FATAL) << "Unexpected type conversion from " << input_type
1366 << " to " << result_type;
1367 }
1368 break;
1369
Roland Levillain01a8d712014-11-14 16:27:39 +00001370 case Primitive::kPrimShort:
1371 switch (input_type) {
1372 case Primitive::kPrimByte:
1373 case Primitive::kPrimInt:
1374 case Primitive::kPrimChar:
1375 // Processing a Dex `int-to-short' instruction.
1376 locations->SetInAt(0, Location::RequiresRegister());
1377 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1378 break;
1379
1380 default:
1381 LOG(FATAL) << "Unexpected type conversion from " << input_type
1382 << " to " << result_type;
1383 }
1384 break;
1385
Roland Levillain946e1432014-11-11 17:35:19 +00001386 case Primitive::kPrimInt:
1387 switch (input_type) {
1388 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001389 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001390 locations->SetInAt(0, Location::Any());
1391 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1392 break;
1393
1394 case Primitive::kPrimFloat:
Roland Levillain3f8f9362014-12-02 17:45:01 +00001395 // Processing a Dex `float-to-int' instruction.
1396 locations->SetInAt(0, Location::RequiresFpuRegister());
1397 locations->SetOut(Location::RequiresRegister());
1398 locations->AddTemp(Location::RequiresFpuRegister());
1399 break;
1400
Roland Levillain946e1432014-11-11 17:35:19 +00001401 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001402 // Processing a Dex `double-to-int' instruction.
1403 locations->SetInAt(0, Location::RequiresFpuRegister());
1404 locations->SetOut(Location::RequiresRegister());
1405 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain946e1432014-11-11 17:35:19 +00001406 break;
1407
1408 default:
1409 LOG(FATAL) << "Unexpected type conversion from " << input_type
1410 << " to " << result_type;
1411 }
1412 break;
1413
Roland Levillaindff1f282014-11-05 14:15:05 +00001414 case Primitive::kPrimLong:
1415 switch (input_type) {
1416 case Primitive::kPrimByte:
1417 case Primitive::kPrimShort:
1418 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001419 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001420 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001421 locations->SetInAt(0, Location::RequiresRegister());
1422 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1423 break;
1424
Roland Levillain624279f2014-12-04 11:54:28 +00001425 case Primitive::kPrimFloat: {
1426 // Processing a Dex `float-to-long' instruction.
1427 InvokeRuntimeCallingConvention calling_convention;
1428 locations->SetInAt(0, Location::FpuRegisterLocation(
1429 calling_convention.GetFpuRegisterAt(0)));
1430 locations->SetOut(Location::RegisterPairLocation(R0, R1));
1431 break;
1432 }
1433
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001434 case Primitive::kPrimDouble: {
1435 // Processing a Dex `double-to-long' instruction.
1436 InvokeRuntimeCallingConvention calling_convention;
1437 locations->SetInAt(0, Location::FpuRegisterPairLocation(
1438 calling_convention.GetFpuRegisterAt(0),
1439 calling_convention.GetFpuRegisterAt(1)));
1440 locations->SetOut(Location::RegisterPairLocation(R0, R1));
Roland Levillaindff1f282014-11-05 14:15:05 +00001441 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001442 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001443
1444 default:
1445 LOG(FATAL) << "Unexpected type conversion from " << input_type
1446 << " to " << result_type;
1447 }
1448 break;
1449
Roland Levillain981e4542014-11-14 11:47:14 +00001450 case Primitive::kPrimChar:
1451 switch (input_type) {
1452 case Primitive::kPrimByte:
1453 case Primitive::kPrimShort:
1454 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001455 // Processing a Dex `int-to-char' instruction.
1456 locations->SetInAt(0, Location::RequiresRegister());
1457 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1458 break;
1459
1460 default:
1461 LOG(FATAL) << "Unexpected type conversion from " << input_type
1462 << " to " << result_type;
1463 }
1464 break;
1465
Roland Levillaindff1f282014-11-05 14:15:05 +00001466 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001467 switch (input_type) {
1468 case Primitive::kPrimByte:
1469 case Primitive::kPrimShort:
1470 case Primitive::kPrimInt:
1471 case Primitive::kPrimChar:
1472 // Processing a Dex `int-to-float' instruction.
1473 locations->SetInAt(0, Location::RequiresRegister());
1474 locations->SetOut(Location::RequiresFpuRegister());
1475 break;
1476
1477 case Primitive::kPrimLong:
Roland Levillain6d0e4832014-11-27 18:31:21 +00001478 // Processing a Dex `long-to-float' instruction.
1479 locations->SetInAt(0, Location::RequiresRegister());
1480 locations->SetOut(Location::RequiresFpuRegister());
1481 locations->AddTemp(Location::RequiresRegister());
1482 locations->AddTemp(Location::RequiresRegister());
1483 locations->AddTemp(Location::RequiresFpuRegister());
1484 locations->AddTemp(Location::RequiresFpuRegister());
1485 break;
1486
Roland Levillaincff13742014-11-17 14:32:17 +00001487 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001488 // Processing a Dex `double-to-float' instruction.
1489 locations->SetInAt(0, Location::RequiresFpuRegister());
1490 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001491 break;
1492
1493 default:
1494 LOG(FATAL) << "Unexpected type conversion from " << input_type
1495 << " to " << result_type;
1496 };
1497 break;
1498
Roland Levillaindff1f282014-11-05 14:15:05 +00001499 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001500 switch (input_type) {
1501 case Primitive::kPrimByte:
1502 case Primitive::kPrimShort:
1503 case Primitive::kPrimInt:
1504 case Primitive::kPrimChar:
1505 // Processing a Dex `int-to-double' instruction.
1506 locations->SetInAt(0, Location::RequiresRegister());
1507 locations->SetOut(Location::RequiresFpuRegister());
1508 break;
1509
1510 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001511 // Processing a Dex `long-to-double' instruction.
1512 locations->SetInAt(0, Location::RequiresRegister());
1513 locations->SetOut(Location::RequiresFpuRegister());
1514 locations->AddTemp(Location::RequiresRegister());
1515 locations->AddTemp(Location::RequiresRegister());
1516 locations->AddTemp(Location::RequiresFpuRegister());
1517 break;
1518
Roland Levillaincff13742014-11-17 14:32:17 +00001519 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001520 // Processing a Dex `float-to-double' instruction.
1521 locations->SetInAt(0, Location::RequiresFpuRegister());
1522 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Roland Levillaincff13742014-11-17 14:32:17 +00001523 break;
1524
1525 default:
1526 LOG(FATAL) << "Unexpected type conversion from " << input_type
1527 << " to " << result_type;
1528 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001529 break;
1530
1531 default:
1532 LOG(FATAL) << "Unexpected type conversion from " << input_type
1533 << " to " << result_type;
1534 }
1535}
1536
1537void InstructionCodeGeneratorARM::VisitTypeConversion(HTypeConversion* conversion) {
1538 LocationSummary* locations = conversion->GetLocations();
1539 Location out = locations->Out();
1540 Location in = locations->InAt(0);
1541 Primitive::Type result_type = conversion->GetResultType();
1542 Primitive::Type input_type = conversion->GetInputType();
Nicolas Geoffray01fcc9e2014-12-01 14:16:20 +00001543 DCHECK_NE(result_type, input_type);
Roland Levillaindff1f282014-11-05 14:15:05 +00001544 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001545 case Primitive::kPrimByte:
1546 switch (input_type) {
1547 case Primitive::kPrimShort:
1548 case Primitive::kPrimInt:
1549 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001550 // Processing a Dex `int-to-byte' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001551 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 8);
Roland Levillain51d3fc42014-11-13 14:11:42 +00001552 break;
1553
1554 default:
1555 LOG(FATAL) << "Unexpected type conversion from " << input_type
1556 << " to " << result_type;
1557 }
1558 break;
1559
Roland Levillain01a8d712014-11-14 16:27:39 +00001560 case Primitive::kPrimShort:
1561 switch (input_type) {
1562 case Primitive::kPrimByte:
1563 case Primitive::kPrimInt:
1564 case Primitive::kPrimChar:
1565 // Processing a Dex `int-to-short' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001566 __ sbfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain01a8d712014-11-14 16:27:39 +00001567 break;
1568
1569 default:
1570 LOG(FATAL) << "Unexpected type conversion from " << input_type
1571 << " to " << result_type;
1572 }
1573 break;
1574
Roland Levillain946e1432014-11-11 17:35:19 +00001575 case Primitive::kPrimInt:
1576 switch (input_type) {
1577 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001578 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001579 DCHECK(out.IsRegister());
1580 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001581 __ Mov(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001582 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001583 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), SP, in.GetStackIndex());
Roland Levillain946e1432014-11-11 17:35:19 +00001584 } else {
1585 DCHECK(in.IsConstant());
1586 DCHECK(in.GetConstant()->IsLongConstant());
1587 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001588 __ LoadImmediate(out.AsRegister<Register>(), static_cast<int32_t>(value));
Roland Levillain946e1432014-11-11 17:35:19 +00001589 }
1590 break;
1591
Roland Levillain3f8f9362014-12-02 17:45:01 +00001592 case Primitive::kPrimFloat: {
1593 // Processing a Dex `float-to-int' instruction.
1594 SRegister temp = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1595 __ vmovs(temp, in.AsFpuRegister<SRegister>());
1596 __ vcvtis(temp, temp);
1597 __ vmovrs(out.AsRegister<Register>(), temp);
1598 break;
1599 }
1600
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001601 case Primitive::kPrimDouble: {
1602 // Processing a Dex `double-to-int' instruction.
1603 SRegister temp_s = locations->GetTemp(0).AsFpuRegisterPairLow<SRegister>();
1604 DRegister temp_d = FromLowSToD(temp_s);
1605 __ vmovd(temp_d, FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
1606 __ vcvtid(temp_s, temp_d);
1607 __ vmovrs(out.AsRegister<Register>(), temp_s);
Roland Levillain946e1432014-11-11 17:35:19 +00001608 break;
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001609 }
Roland Levillain946e1432014-11-11 17:35:19 +00001610
1611 default:
1612 LOG(FATAL) << "Unexpected type conversion from " << input_type
1613 << " to " << result_type;
1614 }
1615 break;
1616
Roland Levillaindff1f282014-11-05 14:15:05 +00001617 case Primitive::kPrimLong:
1618 switch (input_type) {
1619 case Primitive::kPrimByte:
1620 case Primitive::kPrimShort:
1621 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001622 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001623 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001624 DCHECK(out.IsRegisterPair());
1625 DCHECK(in.IsRegister());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001626 __ Mov(out.AsRegisterPairLow<Register>(), in.AsRegister<Register>());
Roland Levillaindff1f282014-11-05 14:15:05 +00001627 // Sign extension.
1628 __ Asr(out.AsRegisterPairHigh<Register>(),
1629 out.AsRegisterPairLow<Register>(),
1630 31);
1631 break;
1632
1633 case Primitive::kPrimFloat:
Roland Levillain624279f2014-12-04 11:54:28 +00001634 // Processing a Dex `float-to-long' instruction.
Roland Levillain624279f2014-12-04 11:54:28 +00001635 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pF2l),
1636 conversion,
1637 conversion->GetDexPc());
1638 break;
1639
Roland Levillaindff1f282014-11-05 14:15:05 +00001640 case Primitive::kPrimDouble:
Roland Levillain4c0b61f2014-12-05 12:06:01 +00001641 // Processing a Dex `double-to-long' instruction.
1642 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pD2l),
1643 conversion,
1644 conversion->GetDexPc());
Roland Levillaindff1f282014-11-05 14:15:05 +00001645 break;
1646
1647 default:
1648 LOG(FATAL) << "Unexpected type conversion from " << input_type
1649 << " to " << result_type;
1650 }
1651 break;
1652
Roland Levillain981e4542014-11-14 11:47:14 +00001653 case Primitive::kPrimChar:
1654 switch (input_type) {
1655 case Primitive::kPrimByte:
1656 case Primitive::kPrimShort:
1657 case Primitive::kPrimInt:
Roland Levillain981e4542014-11-14 11:47:14 +00001658 // Processing a Dex `int-to-char' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001659 __ ubfx(out.AsRegister<Register>(), in.AsRegister<Register>(), 0, 16);
Roland Levillain981e4542014-11-14 11:47:14 +00001660 break;
1661
1662 default:
1663 LOG(FATAL) << "Unexpected type conversion from " << input_type
1664 << " to " << result_type;
1665 }
1666 break;
1667
Roland Levillaindff1f282014-11-05 14:15:05 +00001668 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001669 switch (input_type) {
1670 case Primitive::kPrimByte:
1671 case Primitive::kPrimShort:
1672 case Primitive::kPrimInt:
1673 case Primitive::kPrimChar: {
1674 // Processing a Dex `int-to-float' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001675 __ vmovsr(out.AsFpuRegister<SRegister>(), in.AsRegister<Register>());
1676 __ vcvtsi(out.AsFpuRegister<SRegister>(), out.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001677 break;
1678 }
1679
Roland Levillain6d0e4832014-11-27 18:31:21 +00001680 case Primitive::kPrimLong: {
1681 // Processing a Dex `long-to-float' instruction.
1682 Register low = in.AsRegisterPairLow<Register>();
1683 Register high = in.AsRegisterPairHigh<Register>();
1684 SRegister output = out.AsFpuRegister<SRegister>();
1685 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1686 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
1687 SRegister temp1_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1688 DRegister temp1_d = FromLowSToD(temp1_s);
1689 SRegister temp2_s = locations->GetTemp(3).AsFpuRegisterPairLow<SRegister>();
1690 DRegister temp2_d = FromLowSToD(temp2_s);
1691
1692 // Operations use doubles for precision reasons (each 32-bit
1693 // half of a long fits in the 53-bit mantissa of a double,
1694 // but not in the 24-bit mantissa of a float). This is
1695 // especially important for the low bits. The result is
1696 // eventually converted to float.
1697
1698 // temp1_d = int-to-double(high)
1699 __ vmovsr(temp1_s, high);
1700 __ vcvtdi(temp1_d, temp1_s);
1701 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1702 // as an immediate value into `temp2_d` does not work, as
1703 // this instruction only transfers 8 significant bits of its
1704 // immediate operand. Instead, use two 32-bit core
1705 // registers to load `k2Pow32EncodingForDouble` into
1706 // `temp2_d`.
1707 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1708 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
1709 __ vmovdrr(temp2_d, constant_low, constant_high);
1710 // temp1_d = temp1_d * 2^32
1711 __ vmuld(temp1_d, temp1_d, temp2_d);
1712 // temp2_d = unsigned-to-double(low)
1713 __ vmovsr(temp2_s, low);
1714 __ vcvtdu(temp2_d, temp2_s);
1715 // temp1_d = temp1_d + temp2_d
1716 __ vaddd(temp1_d, temp1_d, temp2_d);
1717 // output = double-to-float(temp1_d);
1718 __ vcvtsd(output, temp1_d);
1719 break;
1720 }
1721
Roland Levillaincff13742014-11-17 14:32:17 +00001722 case Primitive::kPrimDouble:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001723 // Processing a Dex `double-to-float' instruction.
1724 __ vcvtsd(out.AsFpuRegister<SRegister>(),
1725 FromLowSToD(in.AsFpuRegisterPairLow<SRegister>()));
Roland Levillaincff13742014-11-17 14:32:17 +00001726 break;
1727
1728 default:
1729 LOG(FATAL) << "Unexpected type conversion from " << input_type
1730 << " to " << result_type;
1731 };
1732 break;
1733
Roland Levillaindff1f282014-11-05 14:15:05 +00001734 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001735 switch (input_type) {
1736 case Primitive::kPrimByte:
1737 case Primitive::kPrimShort:
1738 case Primitive::kPrimInt:
1739 case Primitive::kPrimChar: {
1740 // Processing a Dex `int-to-double' instruction.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001741 __ vmovsr(out.AsFpuRegisterPairLow<SRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001742 __ vcvtdi(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1743 out.AsFpuRegisterPairLow<SRegister>());
1744 break;
1745 }
1746
Roland Levillain647b9ed2014-11-27 12:06:00 +00001747 case Primitive::kPrimLong: {
1748 // Processing a Dex `long-to-double' instruction.
1749 Register low = in.AsRegisterPairLow<Register>();
1750 Register high = in.AsRegisterPairHigh<Register>();
1751 SRegister out_s = out.AsFpuRegisterPairLow<SRegister>();
1752 DRegister out_d = FromLowSToD(out_s);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001753 Register constant_low = locations->GetTemp(0).AsRegister<Register>();
1754 Register constant_high = locations->GetTemp(1).AsRegister<Register>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001755 SRegister temp_s = locations->GetTemp(2).AsFpuRegisterPairLow<SRegister>();
1756 DRegister temp_d = FromLowSToD(temp_s);
1757
Roland Levillain647b9ed2014-11-27 12:06:00 +00001758 // out_d = int-to-double(high)
1759 __ vmovsr(out_s, high);
1760 __ vcvtdi(out_d, out_s);
Roland Levillain6d0e4832014-11-27 18:31:21 +00001761 // Using vmovd to load the `k2Pow32EncodingForDouble` constant
1762 // as an immediate value into `temp_d` does not work, as
1763 // this instruction only transfers 8 significant bits of its
1764 // immediate operand. Instead, use two 32-bit core
1765 // registers to load `k2Pow32EncodingForDouble` into `temp_d`.
1766 __ LoadImmediate(constant_low, Low32Bits(k2Pow32EncodingForDouble));
1767 __ LoadImmediate(constant_high, High32Bits(k2Pow32EncodingForDouble));
Roland Levillain647b9ed2014-11-27 12:06:00 +00001768 __ vmovdrr(temp_d, constant_low, constant_high);
1769 // out_d = out_d * 2^32
1770 __ vmuld(out_d, out_d, temp_d);
1771 // temp_d = unsigned-to-double(low)
1772 __ vmovsr(temp_s, low);
1773 __ vcvtdu(temp_d, temp_s);
1774 // out_d = out_d + temp_d
1775 __ vaddd(out_d, out_d, temp_d);
1776 break;
1777 }
1778
Roland Levillaincff13742014-11-17 14:32:17 +00001779 case Primitive::kPrimFloat:
Roland Levillain8964e2b2014-12-04 12:10:50 +00001780 // Processing a Dex `float-to-double' instruction.
1781 __ vcvtds(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1782 in.AsFpuRegister<SRegister>());
Roland Levillaincff13742014-11-17 14:32:17 +00001783 break;
1784
1785 default:
1786 LOG(FATAL) << "Unexpected type conversion from " << input_type
1787 << " to " << result_type;
1788 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001789 break;
1790
1791 default:
1792 LOG(FATAL) << "Unexpected type conversion from " << input_type
1793 << " to " << result_type;
1794 }
1795}
1796
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001797void LocationsBuilderARM::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001798 LocationSummary* locations =
1799 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001800 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001801 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001802 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001803 bool output_overlaps = (add->GetResultType() == Primitive::kPrimLong);
1804 locations->SetInAt(0, Location::RequiresRegister());
1805 locations->SetInAt(1, Location::RegisterOrConstant(add->InputAt(1)));
1806 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001807 break;
1808 }
1809
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001810 case Primitive::kPrimFloat:
1811 case Primitive::kPrimDouble: {
1812 locations->SetInAt(0, Location::RequiresFpuRegister());
1813 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001814 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001815 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001816 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001817
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001818 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001819 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001820 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001821}
1822
1823void InstructionCodeGeneratorARM::VisitAdd(HAdd* add) {
1824 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001825 Location out = locations->Out();
1826 Location first = locations->InAt(0);
1827 Location second = locations->InAt(1);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001828 switch (add->GetResultType()) {
1829 case Primitive::kPrimInt:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001830 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001831 __ add(out.AsRegister<Register>(),
1832 first.AsRegister<Register>(),
1833 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001834 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001835 __ AddConstant(out.AsRegister<Register>(),
1836 first.AsRegister<Register>(),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001837 second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001838 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001839 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001840
1841 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001842 __ adds(out.AsRegisterPairLow<Register>(),
1843 first.AsRegisterPairLow<Register>(),
1844 ShifterOperand(second.AsRegisterPairLow<Register>()));
1845 __ adc(out.AsRegisterPairHigh<Register>(),
1846 first.AsRegisterPairHigh<Register>(),
1847 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001848 break;
1849
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001850 case Primitive::kPrimFloat:
Roland Levillain199f3362014-11-27 17:15:16 +00001851 __ vadds(out.AsFpuRegister<SRegister>(),
1852 first.AsFpuRegister<SRegister>(),
1853 second.AsFpuRegister<SRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001854 break;
1855
1856 case Primitive::kPrimDouble:
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001857 __ vaddd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1858 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1859 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001860 break;
1861
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001862 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001863 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001864 }
1865}
1866
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001867void LocationsBuilderARM::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001868 LocationSummary* locations =
1869 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001870 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001871 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001872 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001873 bool output_overlaps = (sub->GetResultType() == Primitive::kPrimLong);
1874 locations->SetInAt(0, Location::RequiresRegister());
1875 locations->SetInAt(1, Location::RegisterOrConstant(sub->InputAt(1)));
1876 locations->SetOut(Location::RequiresRegister(), output_overlaps);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001877 break;
1878 }
Calin Juravle11351682014-10-23 15:38:15 +01001879 case Primitive::kPrimFloat:
1880 case Primitive::kPrimDouble: {
1881 locations->SetInAt(0, Location::RequiresFpuRegister());
1882 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001883 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001884 break;
Calin Juravle11351682014-10-23 15:38:15 +01001885 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001886 default:
Calin Juravle11351682014-10-23 15:38:15 +01001887 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001888 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001889}
1890
1891void InstructionCodeGeneratorARM::VisitSub(HSub* sub) {
1892 LocationSummary* locations = sub->GetLocations();
Calin Juravle11351682014-10-23 15:38:15 +01001893 Location out = locations->Out();
1894 Location first = locations->InAt(0);
1895 Location second = locations->InAt(1);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001896 switch (sub->GetResultType()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001897 case Primitive::kPrimInt: {
Calin Juravle11351682014-10-23 15:38:15 +01001898 if (second.IsRegister()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001899 __ sub(out.AsRegister<Register>(),
1900 first.AsRegister<Register>(),
1901 ShifterOperand(second.AsRegister<Register>()));
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001902 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001903 __ AddConstant(out.AsRegister<Register>(),
1904 first.AsRegister<Register>(),
Calin Juravle11351682014-10-23 15:38:15 +01001905 -second.GetConstant()->AsIntConstant()->GetValue());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001906 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001907 break;
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001908 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001909
Calin Juravle11351682014-10-23 15:38:15 +01001910 case Primitive::kPrimLong: {
1911 __ subs(out.AsRegisterPairLow<Register>(),
1912 first.AsRegisterPairLow<Register>(),
1913 ShifterOperand(second.AsRegisterPairLow<Register>()));
1914 __ sbc(out.AsRegisterPairHigh<Register>(),
1915 first.AsRegisterPairHigh<Register>(),
1916 ShifterOperand(second.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001917 break;
Calin Juravle11351682014-10-23 15:38:15 +01001918 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001919
Calin Juravle11351682014-10-23 15:38:15 +01001920 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00001921 __ vsubs(out.AsFpuRegister<SRegister>(),
1922 first.AsFpuRegister<SRegister>(),
1923 second.AsFpuRegister<SRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001924 break;
Calin Juravle11351682014-10-23 15:38:15 +01001925 }
1926
1927 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00001928 __ vsubd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
1929 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
1930 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravle11351682014-10-23 15:38:15 +01001931 break;
1932 }
1933
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001934
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001935 default:
Calin Juravle11351682014-10-23 15:38:15 +01001936 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001937 }
1938}
1939
Calin Juravle34bacdf2014-10-07 20:23:36 +01001940void LocationsBuilderARM::VisitMul(HMul* mul) {
1941 LocationSummary* locations =
1942 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1943 switch (mul->GetResultType()) {
1944 case Primitive::kPrimInt:
1945 case Primitive::kPrimLong: {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001946 locations->SetInAt(0, Location::RequiresRegister());
1947 locations->SetInAt(1, Location::RequiresRegister());
1948 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001949 break;
1950 }
1951
Calin Juravleb5bfa962014-10-21 18:02:24 +01001952 case Primitive::kPrimFloat:
1953 case Primitive::kPrimDouble: {
1954 locations->SetInAt(0, Location::RequiresFpuRegister());
1955 locations->SetInAt(1, Location::RequiresFpuRegister());
Calin Juravle7c4954d2014-10-28 16:57:40 +00001956 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001957 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001958 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001959
1960 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001961 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001962 }
1963}
1964
1965void InstructionCodeGeneratorARM::VisitMul(HMul* mul) {
1966 LocationSummary* locations = mul->GetLocations();
1967 Location out = locations->Out();
1968 Location first = locations->InAt(0);
1969 Location second = locations->InAt(1);
1970 switch (mul->GetResultType()) {
1971 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00001972 __ mul(out.AsRegister<Register>(),
1973 first.AsRegister<Register>(),
1974 second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001975 break;
1976 }
1977 case Primitive::kPrimLong: {
1978 Register out_hi = out.AsRegisterPairHigh<Register>();
1979 Register out_lo = out.AsRegisterPairLow<Register>();
1980 Register in1_hi = first.AsRegisterPairHigh<Register>();
1981 Register in1_lo = first.AsRegisterPairLow<Register>();
1982 Register in2_hi = second.AsRegisterPairHigh<Register>();
1983 Register in2_lo = second.AsRegisterPairLow<Register>();
1984
1985 // Extra checks to protect caused by the existence of R1_R2.
1986 // The algorithm is wrong if out.hi is either in1.lo or in2.lo:
1987 // (e.g. in1=r0_r1, in2=r2_r3 and out=r1_r2);
1988 DCHECK_NE(out_hi, in1_lo);
1989 DCHECK_NE(out_hi, in2_lo);
1990
1991 // input: in1 - 64 bits, in2 - 64 bits
1992 // output: out
1993 // formula: out.hi : out.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1994 // parts: out.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1995 // parts: out.lo = (in1.lo * in2.lo)[31:0]
1996
1997 // IP <- in1.lo * in2.hi
1998 __ mul(IP, in1_lo, in2_hi);
1999 // out.hi <- in1.lo * in2.hi + in1.hi * in2.lo
2000 __ mla(out_hi, in1_hi, in2_lo, IP);
2001 // out.lo <- (in1.lo * in2.lo)[31:0];
2002 __ umull(out_lo, IP, in1_lo, in2_lo);
2003 // out.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
2004 __ add(out_hi, out_hi, ShifterOperand(IP));
2005 break;
2006 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01002007
2008 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002009 __ vmuls(out.AsFpuRegister<SRegister>(),
2010 first.AsFpuRegister<SRegister>(),
2011 second.AsFpuRegister<SRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01002012 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01002013 }
2014
2015 case Primitive::kPrimDouble: {
Nicolas Geoffray1ba0f592014-10-27 15:14:55 +00002016 __ vmuld(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2017 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2018 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
Calin Juravleb5bfa962014-10-21 18:02:24 +01002019 break;
2020 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01002021
2022 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01002023 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01002024 }
2025}
2026
Calin Juravle7c4954d2014-10-28 16:57:40 +00002027void LocationsBuilderARM::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002028 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2029 ? LocationSummary::kCall
2030 : LocationSummary::kNoCall;
2031 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2032
Calin Juravle7c4954d2014-10-28 16:57:40 +00002033 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002034 case Primitive::kPrimInt: {
2035 locations->SetInAt(0, Location::RequiresRegister());
2036 locations->SetInAt(1, Location::RequiresRegister());
2037 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2038 break;
2039 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002040 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002041 InvokeRuntimeCallingConvention calling_convention;
2042 locations->SetInAt(0, Location::RegisterPairLocation(
2043 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2044 locations->SetInAt(1, Location::RegisterPairLocation(
2045 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2046 // The runtime helper puts the output in R0,R2.
2047 locations->SetOut(Location::RegisterPairLocation(R0, R2));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002048 break;
2049 }
2050 case Primitive::kPrimFloat:
2051 case Primitive::kPrimDouble: {
2052 locations->SetInAt(0, Location::RequiresFpuRegister());
2053 locations->SetInAt(1, Location::RequiresFpuRegister());
2054 locations->SetOut(Location::RequiresFpuRegister(), Location::kNoOutputOverlap);
2055 break;
2056 }
2057
2058 default:
2059 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2060 }
2061}
2062
2063void InstructionCodeGeneratorARM::VisitDiv(HDiv* div) {
2064 LocationSummary* locations = div->GetLocations();
2065 Location out = locations->Out();
2066 Location first = locations->InAt(0);
2067 Location second = locations->InAt(1);
2068
2069 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002070 case Primitive::kPrimInt: {
Roland Levillain199f3362014-11-27 17:15:16 +00002071 __ sdiv(out.AsRegister<Register>(),
2072 first.AsRegister<Register>(),
2073 second.AsRegister<Register>());
Calin Juravled0d48522014-11-04 16:40:20 +00002074 break;
2075 }
2076
Calin Juravle7c4954d2014-10-28 16:57:40 +00002077 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002078 InvokeRuntimeCallingConvention calling_convention;
2079 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2080 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
2081 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
2082 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
2083 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2084 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2085
2086 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLdiv), div, div->GetDexPc());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002087 break;
2088 }
2089
2090 case Primitive::kPrimFloat: {
Roland Levillain199f3362014-11-27 17:15:16 +00002091 __ vdivs(out.AsFpuRegister<SRegister>(),
2092 first.AsFpuRegister<SRegister>(),
2093 second.AsFpuRegister<SRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002094 break;
2095 }
2096
2097 case Primitive::kPrimDouble: {
2098 __ vdivd(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()),
2099 FromLowSToD(first.AsFpuRegisterPairLow<SRegister>()),
2100 FromLowSToD(second.AsFpuRegisterPairLow<SRegister>()));
2101 break;
2102 }
2103
2104 default:
2105 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2106 }
2107}
2108
Calin Juravlebacfec32014-11-14 15:54:36 +00002109void LocationsBuilderARM::VisitRem(HRem* rem) {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002110 Primitive::Type type = rem->GetResultType();
2111 LocationSummary::CallKind call_kind = type == Primitive::kPrimInt
2112 ? LocationSummary::kNoCall
2113 : LocationSummary::kCall;
Calin Juravlebacfec32014-11-14 15:54:36 +00002114 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2115
Calin Juravled2ec87d2014-12-08 14:24:46 +00002116 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002117 case Primitive::kPrimInt: {
2118 locations->SetInAt(0, Location::RequiresRegister());
2119 locations->SetInAt(1, Location::RequiresRegister());
2120 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2121 locations->AddTemp(Location::RequiresRegister());
2122 break;
2123 }
2124 case Primitive::kPrimLong: {
2125 InvokeRuntimeCallingConvention calling_convention;
2126 locations->SetInAt(0, Location::RegisterPairLocation(
2127 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2128 locations->SetInAt(1, Location::RegisterPairLocation(
2129 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2130 // The runtime helper puts the output in R2,R3.
2131 locations->SetOut(Location::RegisterPairLocation(R2, R3));
2132 break;
2133 }
Calin Juravled2ec87d2014-12-08 14:24:46 +00002134 case Primitive::kPrimFloat: {
2135 InvokeRuntimeCallingConvention calling_convention;
2136 locations->SetInAt(0, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(0)));
2137 locations->SetInAt(1, Location::FpuRegisterLocation(calling_convention.GetFpuRegisterAt(1)));
2138 locations->SetOut(Location::FpuRegisterLocation(S0));
2139 break;
2140 }
2141
Calin Juravlebacfec32014-11-14 15:54:36 +00002142 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002143 InvokeRuntimeCallingConvention calling_convention;
2144 locations->SetInAt(0, Location::FpuRegisterPairLocation(
2145 calling_convention.GetFpuRegisterAt(0), calling_convention.GetFpuRegisterAt(1)));
2146 locations->SetInAt(1, Location::FpuRegisterPairLocation(
2147 calling_convention.GetFpuRegisterAt(2), calling_convention.GetFpuRegisterAt(3)));
2148 locations->SetOut(Location::Location::FpuRegisterPairLocation(S0, S1));
Calin Juravlebacfec32014-11-14 15:54:36 +00002149 break;
2150 }
2151
2152 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002153 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002154 }
2155}
2156
2157void InstructionCodeGeneratorARM::VisitRem(HRem* rem) {
2158 LocationSummary* locations = rem->GetLocations();
2159 Location out = locations->Out();
2160 Location first = locations->InAt(0);
2161 Location second = locations->InAt(1);
2162
Calin Juravled2ec87d2014-12-08 14:24:46 +00002163 Primitive::Type type = rem->GetResultType();
2164 switch (type) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002165 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002166 Register reg1 = first.AsRegister<Register>();
2167 Register reg2 = second.AsRegister<Register>();
2168 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravlebacfec32014-11-14 15:54:36 +00002169
2170 // temp = reg1 / reg2 (integer division)
2171 // temp = temp * reg2
2172 // dest = reg1 - temp
2173 __ sdiv(temp, reg1, reg2);
2174 __ mul(temp, temp, reg2);
Roland Levillain271ab9c2014-11-27 15:23:57 +00002175 __ sub(out.AsRegister<Register>(), reg1, ShifterOperand(temp));
Calin Juravlebacfec32014-11-14 15:54:36 +00002176 break;
2177 }
2178
2179 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002180 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pLmod), rem, rem->GetDexPc());
2181 break;
2182 }
2183
Calin Juravled2ec87d2014-12-08 14:24:46 +00002184 case Primitive::kPrimFloat: {
2185 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmodf), rem, rem->GetDexPc());
2186 break;
2187 }
2188
Calin Juravlebacfec32014-11-14 15:54:36 +00002189 case Primitive::kPrimDouble: {
Calin Juravled2ec87d2014-12-08 14:24:46 +00002190 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pFmod), rem, rem->GetDexPc());
Calin Juravlebacfec32014-11-14 15:54:36 +00002191 break;
2192 }
2193
2194 default:
Calin Juravled2ec87d2014-12-08 14:24:46 +00002195 LOG(FATAL) << "Unexpected rem type " << type;
Calin Juravlebacfec32014-11-14 15:54:36 +00002196 }
2197}
2198
Calin Juravled0d48522014-11-04 16:40:20 +00002199void LocationsBuilderARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2200 LocationSummary* locations =
2201 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002202 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
Calin Juravled0d48522014-11-04 16:40:20 +00002203 if (instruction->HasUses()) {
2204 locations->SetOut(Location::SameAsFirstInput());
2205 }
2206}
2207
2208void InstructionCodeGeneratorARM::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2209 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathARM(instruction);
2210 codegen_->AddSlowPath(slow_path);
2211
2212 LocationSummary* locations = instruction->GetLocations();
2213 Location value = locations->InAt(0);
2214
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002215 switch (instruction->GetType()) {
2216 case Primitive::kPrimInt: {
2217 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002218 __ cmp(value.AsRegister<Register>(), ShifterOperand(0));
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002219 __ b(slow_path->GetEntryLabel(), EQ);
2220 } else {
2221 DCHECK(value.IsConstant()) << value;
2222 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2223 __ b(slow_path->GetEntryLabel());
2224 }
2225 }
2226 break;
2227 }
2228 case Primitive::kPrimLong: {
2229 if (value.IsRegisterPair()) {
2230 __ orrs(IP,
2231 value.AsRegisterPairLow<Register>(),
2232 ShifterOperand(value.AsRegisterPairHigh<Register>()));
2233 __ b(slow_path->GetEntryLabel(), EQ);
2234 } else {
2235 DCHECK(value.IsConstant()) << value;
2236 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2237 __ b(slow_path->GetEntryLabel());
2238 }
2239 }
2240 break;
2241 default:
2242 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2243 }
2244 }
Calin Juravled0d48522014-11-04 16:40:20 +00002245}
2246
Calin Juravle9aec02f2014-11-18 23:06:35 +00002247void LocationsBuilderARM::HandleShift(HBinaryOperation* op) {
2248 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2249
2250 LocationSummary::CallKind call_kind = op->GetResultType() == Primitive::kPrimLong
2251 ? LocationSummary::kCall
2252 : LocationSummary::kNoCall;
2253 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(op, call_kind);
2254
2255 switch (op->GetResultType()) {
2256 case Primitive::kPrimInt: {
2257 locations->SetInAt(0, Location::RequiresRegister());
2258 locations->SetInAt(1, Location::RegisterOrConstant(op->InputAt(1)));
2259 locations->SetOut(Location::RequiresRegister());
2260 break;
2261 }
2262 case Primitive::kPrimLong: {
2263 InvokeRuntimeCallingConvention calling_convention;
2264 locations->SetInAt(0, Location::RegisterPairLocation(
2265 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2266 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2267 // The runtime helper puts the output in R0,R2.
2268 locations->SetOut(Location::RegisterPairLocation(R0, R2));
2269 break;
2270 }
2271 default:
2272 LOG(FATAL) << "Unexpected operation type " << op->GetResultType();
2273 }
2274}
2275
2276void InstructionCodeGeneratorARM::HandleShift(HBinaryOperation* op) {
2277 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2278
2279 LocationSummary* locations = op->GetLocations();
2280 Location out = locations->Out();
2281 Location first = locations->InAt(0);
2282 Location second = locations->InAt(1);
2283
2284 Primitive::Type type = op->GetResultType();
2285 switch (type) {
2286 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002287 Register out_reg = out.AsRegister<Register>();
2288 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002289 // Arm doesn't mask the shift count so we need to do it ourselves.
2290 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002291 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002292 __ and_(second_reg, second_reg, ShifterOperand(kMaxIntShiftValue));
2293 if (op->IsShl()) {
2294 __ Lsl(out_reg, first_reg, second_reg);
2295 } else if (op->IsShr()) {
2296 __ Asr(out_reg, first_reg, second_reg);
2297 } else {
2298 __ Lsr(out_reg, first_reg, second_reg);
2299 }
2300 } else {
2301 int32_t cst = second.GetConstant()->AsIntConstant()->GetValue();
2302 uint32_t shift_value = static_cast<uint32_t>(cst & kMaxIntShiftValue);
2303 if (shift_value == 0) { // arm does not support shifting with 0 immediate.
2304 __ Mov(out_reg, first_reg);
2305 } else if (op->IsShl()) {
2306 __ Lsl(out_reg, first_reg, shift_value);
2307 } else if (op->IsShr()) {
2308 __ Asr(out_reg, first_reg, shift_value);
2309 } else {
2310 __ Lsr(out_reg, first_reg, shift_value);
2311 }
2312 }
2313 break;
2314 }
2315 case Primitive::kPrimLong: {
2316 // TODO: Inline the assembly instead of calling the runtime.
2317 InvokeRuntimeCallingConvention calling_convention;
2318 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
2319 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002320 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegister<Register>());
Calin Juravle9aec02f2014-11-18 23:06:35 +00002321 DCHECK_EQ(R0, out.AsRegisterPairLow<Register>());
2322 DCHECK_EQ(R2, out.AsRegisterPairHigh<Register>());
2323
2324 int32_t entry_point_offset;
2325 if (op->IsShl()) {
2326 entry_point_offset = QUICK_ENTRY_POINT(pShlLong);
2327 } else if (op->IsShr()) {
2328 entry_point_offset = QUICK_ENTRY_POINT(pShrLong);
2329 } else {
2330 entry_point_offset = QUICK_ENTRY_POINT(pUshrLong);
2331 }
2332 __ LoadFromOffset(kLoadWord, LR, TR, entry_point_offset);
2333 __ blx(LR);
2334 break;
2335 }
2336 default:
2337 LOG(FATAL) << "Unexpected operation type " << type;
2338 }
2339}
2340
2341void LocationsBuilderARM::VisitShl(HShl* shl) {
2342 HandleShift(shl);
2343}
2344
2345void InstructionCodeGeneratorARM::VisitShl(HShl* shl) {
2346 HandleShift(shl);
2347}
2348
2349void LocationsBuilderARM::VisitShr(HShr* shr) {
2350 HandleShift(shr);
2351}
2352
2353void InstructionCodeGeneratorARM::VisitShr(HShr* shr) {
2354 HandleShift(shr);
2355}
2356
2357void LocationsBuilderARM::VisitUShr(HUShr* ushr) {
2358 HandleShift(ushr);
2359}
2360
2361void InstructionCodeGeneratorARM::VisitUShr(HUShr* ushr) {
2362 HandleShift(ushr);
2363}
2364
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002365void LocationsBuilderARM::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002366 LocationSummary* locations =
2367 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002368 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002369 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2370 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2371 locations->SetOut(Location::RegisterLocation(R0));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002372}
2373
2374void InstructionCodeGeneratorARM::VisitNewInstance(HNewInstance* instruction) {
2375 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002376 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002377 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002378 codegen_->InvokeRuntime(
2379 QUICK_ENTRY_POINT(pAllocObjectWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002380}
2381
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002382void LocationsBuilderARM::VisitNewArray(HNewArray* instruction) {
2383 LocationSummary* locations =
2384 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2385 InvokeRuntimeCallingConvention calling_convention;
2386 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002387 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002388 locations->SetOut(Location::RegisterLocation(R0));
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002389 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002390}
2391
2392void InstructionCodeGeneratorARM::VisitNewArray(HNewArray* instruction) {
2393 InvokeRuntimeCallingConvention calling_convention;
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08002394 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(2));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002395 __ LoadImmediate(calling_convention.GetRegisterAt(0), instruction->GetTypeIndex());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002396 codegen_->InvokeRuntime(
2397 QUICK_ENTRY_POINT(pAllocArrayWithAccessCheck), instruction, instruction->GetDexPc());
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002398}
2399
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002400void LocationsBuilderARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002401 LocationSummary* locations =
2402 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002403 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2404 if (location.IsStackSlot()) {
2405 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2406 } else if (location.IsDoubleStackSlot()) {
2407 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002408 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002409 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002410}
2411
2412void InstructionCodeGeneratorARM::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01002413 // Nothing to do, the parameter is already at its location.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002414 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002415}
2416
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002417void LocationsBuilderARM::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002418 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002419 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002420 locations->SetInAt(0, Location::RequiresRegister());
2421 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002422}
2423
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002424void InstructionCodeGeneratorARM::VisitNot(HNot* not_) {
2425 LocationSummary* locations = not_->GetLocations();
2426 Location out = locations->Out();
2427 Location in = locations->InAt(0);
2428 switch (not_->InputAt(0)->GetType()) {
2429 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002430 __ eor(out.AsRegister<Register>(), in.AsRegister<Register>(), ShifterOperand(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002431 break;
2432
2433 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002434 __ mvn(out.AsRegister<Register>(), ShifterOperand(in.AsRegister<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002435 break;
2436
2437 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002438 __ mvn(out.AsRegisterPairLow<Register>(),
2439 ShifterOperand(in.AsRegisterPairLow<Register>()));
2440 __ mvn(out.AsRegisterPairHigh<Register>(),
2441 ShifterOperand(in.AsRegisterPairHigh<Register>()));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002442 break;
2443
2444 default:
2445 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2446 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002447}
2448
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002449void LocationsBuilderARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002450 LocationSummary* locations =
2451 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002452 switch (compare->InputAt(0)->GetType()) {
2453 case Primitive::kPrimLong: {
2454 locations->SetInAt(0, Location::RequiresRegister());
2455 locations->SetInAt(1, Location::RequiresRegister());
2456 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2457 break;
2458 }
2459 case Primitive::kPrimFloat:
2460 case Primitive::kPrimDouble: {
2461 locations->SetInAt(0, Location::RequiresFpuRegister());
2462 locations->SetInAt(1, Location::RequiresFpuRegister());
2463 locations->SetOut(Location::RequiresRegister());
2464 break;
2465 }
2466 default:
2467 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2468 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002469}
2470
2471void InstructionCodeGeneratorARM::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002472 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002473 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002474 Location left = locations->InAt(0);
2475 Location right = locations->InAt(1);
2476
2477 Label less, greater, done;
2478 Primitive::Type type = compare->InputAt(0)->GetType();
2479 switch (type) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002480 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002481 __ cmp(left.AsRegisterPairHigh<Register>(),
2482 ShifterOperand(right.AsRegisterPairHigh<Register>())); // Signed compare.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002483 __ b(&less, LT);
2484 __ b(&greater, GT);
Calin Juravleddb7df22014-11-25 20:56:51 +00002485 // Do LoadImmediate before any `cmp`, as LoadImmediate might affect the status flags.
2486 __ LoadImmediate(out, 0);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002487 __ cmp(left.AsRegisterPairLow<Register>(),
2488 ShifterOperand(right.AsRegisterPairLow<Register>())); // Unsigned compare.
Calin Juravleddb7df22014-11-25 20:56:51 +00002489 break;
2490 }
2491 case Primitive::kPrimFloat:
2492 case Primitive::kPrimDouble: {
2493 __ LoadImmediate(out, 0);
2494 if (type == Primitive::kPrimFloat) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002495 __ vcmps(left.AsFpuRegister<SRegister>(), right.AsFpuRegister<SRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002496 } else {
2497 __ vcmpd(FromLowSToD(left.AsFpuRegisterPairLow<SRegister>()),
2498 FromLowSToD(right.AsFpuRegisterPairLow<SRegister>()));
2499 }
2500 __ vmstat(); // transfer FP status register to ARM APSR.
2501 __ b(compare->IsGtBias() ? &greater : &less, VS); // VS for unordered.
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002502 break;
2503 }
2504 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002505 LOG(FATAL) << "Unexpected compare type " << type;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002506 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002507 __ b(&done, EQ);
2508 __ b(&less, CC); // CC is for both: unsigned compare for longs and 'less than' for floats.
2509
2510 __ Bind(&greater);
2511 __ LoadImmediate(out, 1);
2512 __ b(&done);
2513
2514 __ Bind(&less);
2515 __ LoadImmediate(out, -1);
2516
2517 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002518}
2519
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002520void LocationsBuilderARM::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002521 LocationSummary* locations =
2522 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002523 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2524 locations->SetInAt(i, Location::Any());
2525 }
2526 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002527}
2528
2529void InstructionCodeGeneratorARM::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002530 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002531 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002532}
2533
Calin Juravle52c48962014-12-16 17:02:57 +00002534void InstructionCodeGeneratorARM::GenerateMemoryBarrier(MemBarrierKind kind) {
2535 // TODO (ported from quick): revisit Arm barrier kinds
2536 DmbOptions flavour = DmbOptions::ISH; // quiet c++ warnings
2537 switch (kind) {
2538 case MemBarrierKind::kAnyStore:
2539 case MemBarrierKind::kLoadAny:
2540 case MemBarrierKind::kAnyAny: {
2541 flavour = DmbOptions::ISH;
2542 break;
2543 }
2544 case MemBarrierKind::kStoreStore: {
2545 flavour = DmbOptions::ISHST;
2546 break;
2547 }
2548 default:
2549 LOG(FATAL) << "Unexpected memory barrier " << kind;
2550 }
2551 __ dmb(flavour);
2552}
2553
2554void InstructionCodeGeneratorARM::GenerateWideAtomicLoad(Register addr,
2555 uint32_t offset,
2556 Register out_lo,
2557 Register out_hi) {
2558 if (offset != 0) {
2559 __ LoadImmediate(out_lo, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002560 __ add(IP, addr, ShifterOperand(out_lo));
2561 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002562 }
2563 __ ldrexd(out_lo, out_hi, addr);
2564}
2565
2566void InstructionCodeGeneratorARM::GenerateWideAtomicStore(Register addr,
2567 uint32_t offset,
2568 Register value_lo,
2569 Register value_hi,
2570 Register temp1,
2571 Register temp2) {
2572 Label fail;
2573 if (offset != 0) {
2574 __ LoadImmediate(temp1, offset);
Nicolas Geoffraybdcedd32015-01-09 08:48:29 +00002575 __ add(IP, addr, ShifterOperand(temp1));
2576 addr = IP;
Calin Juravle52c48962014-12-16 17:02:57 +00002577 }
2578 __ Bind(&fail);
2579 // We need a load followed by store. (The address used in a STREX instruction must
2580 // be the same as the address in the most recently executed LDREX instruction.)
2581 __ ldrexd(temp1, temp2, addr);
2582 __ strexd(temp1, value_lo, value_hi, addr);
2583 __ cmp(temp1, ShifterOperand(0));
2584 __ b(&fail, NE);
2585}
2586
2587void LocationsBuilderARM::HandleFieldSet(HInstruction* instruction, const FieldInfo& field_info) {
2588 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2589
Nicolas Geoffray39468442014-09-02 15:17:15 +01002590 LocationSummary* locations =
2591 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002592 locations->SetInAt(0, Location::RequiresRegister());
2593 locations->SetInAt(1, Location::RequiresRegister());
Calin Juravle52c48962014-12-16 17:02:57 +00002594
Calin Juravle34166012014-12-19 17:22:29 +00002595
Calin Juravle52c48962014-12-16 17:02:57 +00002596 Primitive::Type field_type = field_info.GetFieldType();
2597 bool is_wide = field_type == Primitive::kPrimLong || field_type == Primitive::kPrimDouble;
Calin Juravle34166012014-12-19 17:22:29 +00002598 bool generate_volatile = field_info.IsVolatile()
2599 && is_wide
2600 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002601 // Temporary registers for the write barrier.
Calin Juravle52c48962014-12-16 17:02:57 +00002602 // TODO: consider renaming StoreNeedsWriteBarrier to StoreNeedsGCMark.
2603 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002604 locations->AddTemp(Location::RequiresRegister());
2605 locations->AddTemp(Location::RequiresRegister());
Calin Juravle34166012014-12-19 17:22:29 +00002606 } else if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002607 // Arm encoding have some additional constraints for ldrexd/strexd:
2608 // - registers need to be consecutive
2609 // - the first register should be even but not R14.
2610 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2611 // enable Arm encoding.
2612 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2613
2614 locations->AddTemp(Location::RequiresRegister());
2615 locations->AddTemp(Location::RequiresRegister());
2616 if (field_type == Primitive::kPrimDouble) {
2617 // For doubles we need two more registers to copy the value.
2618 locations->AddTemp(Location::RegisterLocation(R2));
2619 locations->AddTemp(Location::RegisterLocation(R3));
2620 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002621 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002622}
2623
Calin Juravle52c48962014-12-16 17:02:57 +00002624void InstructionCodeGeneratorARM::HandleFieldSet(HInstruction* instruction,
2625 const FieldInfo& field_info) {
2626 DCHECK(instruction->IsInstanceFieldSet() || instruction->IsStaticFieldSet());
2627
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002628 LocationSummary* locations = instruction->GetLocations();
Calin Juravle52c48962014-12-16 17:02:57 +00002629 Register base = locations->InAt(0).AsRegister<Register>();
2630 Location value = locations->InAt(1);
2631
2632 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002633 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002634 Primitive::Type field_type = field_info.GetFieldType();
2635 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2636
2637 if (is_volatile) {
2638 GenerateMemoryBarrier(MemBarrierKind::kAnyStore);
2639 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002640
2641 switch (field_type) {
2642 case Primitive::kPrimBoolean:
2643 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002644 __ StoreToOffset(kStoreByte, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002645 break;
2646 }
2647
2648 case Primitive::kPrimShort:
2649 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002650 __ StoreToOffset(kStoreHalfword, value.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002651 break;
2652 }
2653
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002654 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002655 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002656 Register value_reg = value.AsRegister<Register>();
2657 __ StoreToOffset(kStoreWord, value_reg, base, offset);
2658 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002659 Register temp = locations->GetTemp(0).AsRegister<Register>();
2660 Register card = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle52c48962014-12-16 17:02:57 +00002661 codegen_->MarkGCCard(temp, card, base, value_reg);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002662 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002663 break;
2664 }
2665
2666 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002667 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002668 GenerateWideAtomicStore(base, offset,
2669 value.AsRegisterPairLow<Register>(),
2670 value.AsRegisterPairHigh<Register>(),
2671 locations->GetTemp(0).AsRegister<Register>(),
2672 locations->GetTemp(1).AsRegister<Register>());
2673 } else {
2674 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), base, offset);
2675 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002676 break;
2677 }
2678
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002679 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002680 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002681 break;
2682 }
2683
2684 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002685 DRegister value_reg = FromLowSToD(value.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002686 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002687 Register value_reg_lo = locations->GetTemp(0).AsRegister<Register>();
2688 Register value_reg_hi = locations->GetTemp(1).AsRegister<Register>();
2689
2690 __ vmovrrd(value_reg_lo, value_reg_hi, value_reg);
2691
2692 GenerateWideAtomicStore(base, offset,
2693 value_reg_lo,
2694 value_reg_hi,
2695 locations->GetTemp(2).AsRegister<Register>(),
2696 locations->GetTemp(3).AsRegister<Register>());
2697 } else {
2698 __ StoreDToOffset(value_reg, base, offset);
2699 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002700 break;
2701 }
2702
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002703 case Primitive::kPrimVoid:
2704 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002705 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002706 }
Calin Juravle52c48962014-12-16 17:02:57 +00002707
2708 if (is_volatile) {
2709 GenerateMemoryBarrier(MemBarrierKind::kAnyAny);
2710 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002711}
2712
Calin Juravle52c48962014-12-16 17:02:57 +00002713void LocationsBuilderARM::HandleFieldGet(HInstruction* instruction, const FieldInfo& field_info) {
2714 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002715 LocationSummary* locations =
2716 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002717 locations->SetInAt(0, Location::RequiresRegister());
2718 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Calin Juravle52c48962014-12-16 17:02:57 +00002719
Calin Juravle34166012014-12-19 17:22:29 +00002720 bool generate_volatile = field_info.IsVolatile()
2721 && (field_info.GetFieldType() == Primitive::kPrimDouble)
2722 && !codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
2723 if (generate_volatile) {
Calin Juravle52c48962014-12-16 17:02:57 +00002724 // Arm encoding have some additional constraints for ldrexd/strexd:
2725 // - registers need to be consecutive
2726 // - the first register should be even but not R14.
2727 // We don't test for Arm yet, and the assertion makes sure that we revisit this if we ever
2728 // enable Arm encoding.
2729 DCHECK_EQ(InstructionSet::kThumb2, codegen_->GetInstructionSet());
2730 locations->AddTemp(Location::RequiresRegister());
2731 locations->AddTemp(Location::RequiresRegister());
2732 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002733}
2734
Calin Juravle52c48962014-12-16 17:02:57 +00002735void InstructionCodeGeneratorARM::HandleFieldGet(HInstruction* instruction,
2736 const FieldInfo& field_info) {
2737 DCHECK(instruction->IsInstanceFieldGet() || instruction->IsStaticFieldGet());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002738
Calin Juravle52c48962014-12-16 17:02:57 +00002739 LocationSummary* locations = instruction->GetLocations();
2740 Register base = locations->InAt(0).AsRegister<Register>();
2741 Location out = locations->Out();
2742 bool is_volatile = field_info.IsVolatile();
Calin Juravle34166012014-12-19 17:22:29 +00002743 bool atomic_ldrd_strd = codegen_->GetInstructionSetFeatures()->HasAtomicLdrdAndStrd();
Calin Juravle52c48962014-12-16 17:02:57 +00002744 Primitive::Type field_type = field_info.GetFieldType();
2745 uint32_t offset = field_info.GetFieldOffset().Uint32Value();
2746
2747 switch (field_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002748 case Primitive::kPrimBoolean: {
Calin Juravle52c48962014-12-16 17:02:57 +00002749 __ LoadFromOffset(kLoadUnsignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002750 break;
2751 }
2752
2753 case Primitive::kPrimByte: {
Calin Juravle52c48962014-12-16 17:02:57 +00002754 __ LoadFromOffset(kLoadSignedByte, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002755 break;
2756 }
2757
2758 case Primitive::kPrimShort: {
Calin Juravle52c48962014-12-16 17:02:57 +00002759 __ LoadFromOffset(kLoadSignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002760 break;
2761 }
2762
2763 case Primitive::kPrimChar: {
Calin Juravle52c48962014-12-16 17:02:57 +00002764 __ LoadFromOffset(kLoadUnsignedHalfword, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002765 break;
2766 }
2767
2768 case Primitive::kPrimInt:
2769 case Primitive::kPrimNot: {
Calin Juravle52c48962014-12-16 17:02:57 +00002770 __ LoadFromOffset(kLoadWord, out.AsRegister<Register>(), base, offset);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002771 break;
2772 }
2773
2774 case Primitive::kPrimLong: {
Calin Juravle34166012014-12-19 17:22:29 +00002775 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002776 GenerateWideAtomicLoad(base, offset,
2777 out.AsRegisterPairLow<Register>(),
2778 out.AsRegisterPairHigh<Register>());
2779 } else {
2780 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), base, offset);
2781 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002782 break;
2783 }
2784
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002785 case Primitive::kPrimFloat: {
Calin Juravle52c48962014-12-16 17:02:57 +00002786 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), base, offset);
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002787 break;
2788 }
2789
2790 case Primitive::kPrimDouble: {
Calin Juravle52c48962014-12-16 17:02:57 +00002791 DRegister out_reg = FromLowSToD(out.AsFpuRegisterPairLow<SRegister>());
Calin Juravle34166012014-12-19 17:22:29 +00002792 if (is_volatile && !atomic_ldrd_strd) {
Calin Juravle52c48962014-12-16 17:02:57 +00002793 Register lo = locations->GetTemp(0).AsRegister<Register>();
2794 Register hi = locations->GetTemp(1).AsRegister<Register>();
2795 GenerateWideAtomicLoad(base, offset, lo, hi);
2796 __ vmovdrr(out_reg, lo, hi);
2797 } else {
2798 __ LoadDFromOffset(out_reg, base, offset);
2799 }
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002800 break;
2801 }
2802
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002803 case Primitive::kPrimVoid:
Calin Juravle52c48962014-12-16 17:02:57 +00002804 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002805 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002806 }
Calin Juravle52c48962014-12-16 17:02:57 +00002807
2808 if (is_volatile) {
2809 GenerateMemoryBarrier(MemBarrierKind::kLoadAny);
2810 }
2811}
2812
2813void LocationsBuilderARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2814 HandleFieldSet(instruction, instruction->GetFieldInfo());
2815}
2816
2817void InstructionCodeGeneratorARM::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2818 HandleFieldSet(instruction, instruction->GetFieldInfo());
2819}
2820
2821void LocationsBuilderARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2822 HandleFieldGet(instruction, instruction->GetFieldInfo());
2823}
2824
2825void InstructionCodeGeneratorARM::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2826 HandleFieldGet(instruction, instruction->GetFieldInfo());
2827}
2828
2829void LocationsBuilderARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2830 HandleFieldGet(instruction, instruction->GetFieldInfo());
2831}
2832
2833void InstructionCodeGeneratorARM::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2834 HandleFieldGet(instruction, instruction->GetFieldInfo());
2835}
2836
2837void LocationsBuilderARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2838 HandleFieldSet(instruction, instruction->GetFieldInfo());
2839}
2840
2841void InstructionCodeGeneratorARM::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2842 HandleFieldSet(instruction, instruction->GetFieldInfo());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002843}
2844
2845void LocationsBuilderARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002846 LocationSummary* locations =
2847 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002848 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002849 if (instruction->HasUses()) {
2850 locations->SetOut(Location::SameAsFirstInput());
2851 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002852}
2853
2854void InstructionCodeGeneratorARM::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002855 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathARM(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002856 codegen_->AddSlowPath(slow_path);
2857
2858 LocationSummary* locations = instruction->GetLocations();
2859 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002860
2861 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002862 __ cmp(obj.AsRegister<Register>(), ShifterOperand(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002863 __ b(slow_path->GetEntryLabel(), EQ);
2864 } else {
2865 DCHECK(obj.IsConstant()) << obj;
2866 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2867 __ b(slow_path->GetEntryLabel());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002868 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002869}
2870
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002871void LocationsBuilderARM::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002872 LocationSummary* locations =
2873 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002874 locations->SetInAt(0, Location::RequiresRegister());
2875 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2876 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002877}
2878
2879void InstructionCodeGeneratorARM::VisitArrayGet(HArrayGet* instruction) {
2880 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002881 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002882 Location index = locations->InAt(1);
2883
2884 switch (instruction->GetType()) {
2885 case Primitive::kPrimBoolean: {
2886 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002887 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002888 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002889 size_t offset =
2890 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002891 __ LoadFromOffset(kLoadUnsignedByte, out, obj, offset);
2892 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002893 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002894 __ LoadFromOffset(kLoadUnsignedByte, out, IP, data_offset);
2895 }
2896 break;
2897 }
2898
2899 case Primitive::kPrimByte: {
2900 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002901 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002902 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002903 size_t offset =
2904 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002905 __ LoadFromOffset(kLoadSignedByte, out, obj, offset);
2906 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002907 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002908 __ LoadFromOffset(kLoadSignedByte, out, IP, data_offset);
2909 }
2910 break;
2911 }
2912
2913 case Primitive::kPrimShort: {
2914 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002915 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002916 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002917 size_t offset =
2918 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002919 __ LoadFromOffset(kLoadSignedHalfword, out, obj, offset);
2920 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002921 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002922 __ LoadFromOffset(kLoadSignedHalfword, out, IP, data_offset);
2923 }
2924 break;
2925 }
2926
2927 case Primitive::kPrimChar: {
2928 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002929 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002930 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002931 size_t offset =
2932 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002933 __ LoadFromOffset(kLoadUnsignedHalfword, out, obj, offset);
2934 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002935 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002936 __ LoadFromOffset(kLoadUnsignedHalfword, out, IP, data_offset);
2937 }
2938 break;
2939 }
2940
2941 case Primitive::kPrimInt:
2942 case Primitive::kPrimNot: {
2943 DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
2944 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002945 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002946 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002947 size_t offset =
2948 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002949 __ LoadFromOffset(kLoadWord, out, obj, offset);
2950 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002951 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002952 __ LoadFromOffset(kLoadWord, out, IP, data_offset);
2953 }
2954 break;
2955 }
2956
2957 case Primitive::kPrimLong: {
2958 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002959 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002960 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002961 size_t offset =
2962 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002963 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002964 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002965 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002966 __ LoadFromOffset(kLoadWordPair, out.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002967 }
2968 break;
2969 }
2970
Nicolas Geoffray840e5462015-01-07 16:01:24 +00002971 case Primitive::kPrimFloat: {
2972 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
2973 Location out = locations->Out();
2974 DCHECK(out.IsFpuRegister());
2975 if (index.IsConstant()) {
2976 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
2977 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), obj, offset);
2978 } else {
2979 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
2980 __ LoadSFromOffset(out.AsFpuRegister<SRegister>(), IP, data_offset);
2981 }
2982 break;
2983 }
2984
2985 case Primitive::kPrimDouble: {
2986 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
2987 Location out = locations->Out();
2988 DCHECK(out.IsFpuRegisterPair());
2989 if (index.IsConstant()) {
2990 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
2991 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), obj, offset);
2992 } else {
2993 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
2994 __ LoadDFromOffset(FromLowSToD(out.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
2995 }
2996 break;
2997 }
2998
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002999 case Primitive::kPrimVoid:
3000 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07003001 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003002 }
3003}
3004
3005void LocationsBuilderARM::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003006 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003007
3008 bool needs_write_barrier =
3009 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
3010 bool needs_runtime_call = instruction->NeedsTypeCheck();
3011
Nicolas Geoffray39468442014-09-02 15:17:15 +01003012 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003013 instruction, needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
3014 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003015 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003016 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3017 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
3018 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003019 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003020 locations->SetInAt(0, Location::RequiresRegister());
3021 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
3022 locations->SetInAt(2, Location::RequiresRegister());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003023
3024 if (needs_write_barrier) {
3025 // Temporary registers for the write barrier.
3026 locations->AddTemp(Location::RequiresRegister());
3027 locations->AddTemp(Location::RequiresRegister());
3028 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003029 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003030}
3031
3032void InstructionCodeGeneratorARM::VisitArraySet(HArraySet* instruction) {
3033 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003034 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003035 Location index = locations->InAt(1);
Nicolas Geoffray39468442014-09-02 15:17:15 +01003036 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003037 bool needs_runtime_call = locations->WillCall();
3038 bool needs_write_barrier =
3039 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003040
3041 switch (value_type) {
3042 case Primitive::kPrimBoolean:
3043 case Primitive::kPrimByte: {
3044 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003045 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003046 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003047 size_t offset =
3048 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003049 __ StoreToOffset(kStoreByte, value, obj, offset);
3050 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003051 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>()));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003052 __ StoreToOffset(kStoreByte, value, IP, data_offset);
3053 }
3054 break;
3055 }
3056
3057 case Primitive::kPrimShort:
3058 case Primitive::kPrimChar: {
3059 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003060 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003061 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003062 size_t offset =
3063 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003064 __ StoreToOffset(kStoreHalfword, value, obj, offset);
3065 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003066 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_2));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003067 __ StoreToOffset(kStoreHalfword, value, IP, data_offset);
3068 }
3069 break;
3070 }
3071
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003072 case Primitive::kPrimInt:
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003073 case Primitive::kPrimNot: {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003074 if (!needs_runtime_call) {
3075 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003076 Register value = locations->InAt(2).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003077 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003078 size_t offset =
3079 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003080 __ StoreToOffset(kStoreWord, value, obj, offset);
3081 } else {
3082 DCHECK(index.IsRegister()) << index;
Roland Levillain271ab9c2014-11-27 15:23:57 +00003083 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003084 __ StoreToOffset(kStoreWord, value, IP, data_offset);
3085 }
3086 if (needs_write_barrier) {
3087 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003088 Register temp = locations->GetTemp(0).AsRegister<Register>();
3089 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003090 codegen_->MarkGCCard(temp, card, obj, value);
3091 }
3092 } else {
3093 DCHECK_EQ(value_type, Primitive::kPrimNot);
Roland Levillain199f3362014-11-27 17:15:16 +00003094 codegen_->InvokeRuntime(QUICK_ENTRY_POINT(pAputObject),
3095 instruction,
3096 instruction->GetDexPc());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003097 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003098 break;
3099 }
3100
3101 case Primitive::kPrimLong: {
3102 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003103 Location value = locations->InAt(2);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003104 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003105 size_t offset =
3106 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003107 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), obj, offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003108 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003109 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01003110 __ StoreToOffset(kStoreWordPair, value.AsRegisterPairLow<Register>(), IP, data_offset);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003111 }
3112 break;
3113 }
3114
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003115 case Primitive::kPrimFloat: {
3116 uint32_t data_offset = mirror::Array::DataOffset(sizeof(float)).Uint32Value();
3117 Location value = locations->InAt(2);
3118 DCHECK(value.IsFpuRegister());
3119 if (index.IsConstant()) {
3120 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
3121 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), obj, offset);
3122 } else {
3123 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_4));
3124 __ StoreSToOffset(value.AsFpuRegister<SRegister>(), IP, data_offset);
3125 }
3126 break;
3127 }
3128
3129 case Primitive::kPrimDouble: {
3130 uint32_t data_offset = mirror::Array::DataOffset(sizeof(double)).Uint32Value();
3131 Location value = locations->InAt(2);
3132 DCHECK(value.IsFpuRegisterPair());
3133 if (index.IsConstant()) {
3134 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
3135 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), obj, offset);
3136 } else {
3137 __ add(IP, obj, ShifterOperand(index.AsRegister<Register>(), LSL, TIMES_8));
3138 __ StoreDToOffset(FromLowSToD(value.AsFpuRegisterPairLow<SRegister>()), IP, data_offset);
3139 }
3140 break;
3141 }
3142
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003143 case Primitive::kPrimVoid:
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003144 LOG(FATAL) << "Unreachable type " << value_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07003145 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003146 }
3147}
3148
3149void LocationsBuilderARM::VisitArrayLength(HArrayLength* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003150 LocationSummary* locations =
3151 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01003152 locations->SetInAt(0, Location::RequiresRegister());
3153 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003154}
3155
3156void InstructionCodeGeneratorARM::VisitArrayLength(HArrayLength* instruction) {
3157 LocationSummary* locations = instruction->GetLocations();
3158 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003159 Register obj = locations->InAt(0).AsRegister<Register>();
3160 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003161 __ LoadFromOffset(kLoadWord, out, obj, offset);
3162}
3163
3164void LocationsBuilderARM::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003165 LocationSummary* locations =
3166 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003167 locations->SetInAt(0, Location::RequiresRegister());
3168 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003169 if (instruction->HasUses()) {
3170 locations->SetOut(Location::SameAsFirstInput());
3171 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003172}
3173
3174void InstructionCodeGeneratorARM::VisitBoundsCheck(HBoundsCheck* instruction) {
3175 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003176 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathARM(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003177 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003178 codegen_->AddSlowPath(slow_path);
3179
Roland Levillain271ab9c2014-11-27 15:23:57 +00003180 Register index = locations->InAt(0).AsRegister<Register>();
3181 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003182
3183 __ cmp(index, ShifterOperand(length));
3184 __ b(slow_path->GetEntryLabel(), CS);
3185}
3186
3187void CodeGeneratorARM::MarkGCCard(Register temp, Register card, Register object, Register value) {
3188 Label is_null;
3189 __ CompareAndBranchIfZero(value, &is_null);
3190 __ LoadFromOffset(kLoadWord, card, TR, Thread::CardTableOffset<kArmWordSize>().Int32Value());
3191 __ Lsr(temp, object, gc::accounting::CardTable::kCardShift);
3192 __ strb(card, Address(card, temp));
3193 __ Bind(&is_null);
3194}
3195
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003196void LocationsBuilderARM::VisitTemporary(HTemporary* temp) {
3197 temp->SetLocations(nullptr);
3198}
3199
3200void InstructionCodeGeneratorARM::VisitTemporary(HTemporary* temp) {
3201 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003202 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003203}
3204
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003205void LocationsBuilderARM::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003206 UNUSED(instruction);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003207 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003208}
3209
3210void InstructionCodeGeneratorARM::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003211 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3212}
3213
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003214void LocationsBuilderARM::VisitSuspendCheck(HSuspendCheck* instruction) {
3215 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3216}
3217
3218void InstructionCodeGeneratorARM::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003219 HBasicBlock* block = instruction->GetBlock();
3220 if (block->GetLoopInformation() != nullptr) {
3221 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3222 // The back edge will generate the suspend check.
3223 return;
3224 }
3225 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3226 // The goto will generate the suspend check.
3227 return;
3228 }
3229 GenerateSuspendCheck(instruction, nullptr);
3230}
3231
3232void InstructionCodeGeneratorARM::GenerateSuspendCheck(HSuspendCheck* instruction,
3233 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003234 SuspendCheckSlowPathARM* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003235 new (GetGraph()->GetArena()) SuspendCheckSlowPathARM(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003236 codegen_->AddSlowPath(slow_path);
3237
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003238 __ LoadFromOffset(
3239 kLoadUnsignedHalfword, IP, TR, Thread::ThreadFlagsOffset<kArmWordSize>().Int32Value());
3240 __ cmp(IP, ShifterOperand(0));
3241 // TODO: Figure out the branch offsets and use cbz/cbnz.
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003242 if (successor == nullptr) {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003243 __ b(slow_path->GetEntryLabel(), NE);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003244 __ Bind(slow_path->GetReturnLabel());
3245 } else {
Nicolas Geoffray44b819e2014-11-06 12:00:54 +00003246 __ b(codegen_->GetLabelOf(successor), EQ);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003247 __ b(slow_path->GetEntryLabel());
3248 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003249}
3250
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003251ArmAssembler* ParallelMoveResolverARM::GetAssembler() const {
3252 return codegen_->GetAssembler();
3253}
3254
3255void ParallelMoveResolverARM::EmitMove(size_t index) {
3256 MoveOperands* move = moves_.Get(index);
3257 Location source = move->GetSource();
3258 Location destination = move->GetDestination();
3259
3260 if (source.IsRegister()) {
3261 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003262 __ Mov(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003263 } else {
3264 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003265 __ StoreToOffset(kStoreWord, source.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003266 SP, destination.GetStackIndex());
3267 }
3268 } else if (source.IsStackSlot()) {
3269 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003270 __ LoadFromOffset(kLoadWord, destination.AsRegister<Register>(),
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003271 SP, source.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003272 } else if (destination.IsFpuRegister()) {
3273 __ LoadSFromOffset(destination.AsFpuRegister<SRegister>(), SP, source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003274 } else {
3275 DCHECK(destination.IsStackSlot());
3276 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
3277 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3278 }
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003279 } else if (source.IsFpuRegister()) {
3280 if (destination.IsFpuRegister()) {
3281 __ vmovs(destination.AsFpuRegister<SRegister>(), source.AsFpuRegister<SRegister>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003282 } else {
3283 DCHECK(destination.IsStackSlot());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003284 __ StoreSToOffset(source.AsFpuRegister<SRegister>(), SP, destination.GetStackIndex());
3285 }
3286 } else if (source.IsFpuRegisterPair()) {
3287 if (destination.IsFpuRegisterPair()) {
3288 __ vmovd(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3289 FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()));
3290 } else {
3291 DCHECK(destination.IsDoubleStackSlot()) << destination;
3292 __ StoreDToOffset(FromLowSToD(source.AsFpuRegisterPairLow<SRegister>()),
3293 SP, destination.GetStackIndex());
3294 }
3295 } else if (source.IsDoubleStackSlot()) {
3296 if (destination.IsFpuRegisterPair()) {
3297 __ LoadDFromOffset(FromLowSToD(destination.AsFpuRegisterPairLow<SRegister>()),
3298 SP, source.GetStackIndex());
3299 } else {
3300 DCHECK(destination.IsDoubleStackSlot()) << destination;
3301 __ LoadFromOffset(kLoadWord, IP, SP, source.GetStackIndex());
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003302 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003303 __ LoadFromOffset(kLoadWord, IP, SP, source.GetHighStackIndex(kArmWordSize));
3304 __ StoreToOffset(kStoreWord, IP, SP, destination.GetHighStackIndex(kArmWordSize));
3305 }
3306 } else {
3307 DCHECK(source.IsConstant()) << source;
3308 HInstruction* constant = source.GetConstant();
3309 if (constant->IsIntConstant()) {
3310 int32_t value = constant->AsIntConstant()->GetValue();
3311 if (destination.IsRegister()) {
3312 __ LoadImmediate(destination.AsRegister<Register>(), value);
3313 } else {
3314 DCHECK(destination.IsStackSlot());
3315 __ LoadImmediate(IP, value);
3316 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3317 }
3318 } else {
3319 DCHECK(constant->IsFloatConstant());
3320 float value = constant->AsFloatConstant()->GetValue();
3321 if (destination.IsFpuRegister()) {
3322 __ LoadSImmediate(destination.AsFpuRegister<SRegister>(), value);
3323 } else {
3324 DCHECK(destination.IsStackSlot());
3325 __ LoadImmediate(IP, bit_cast<int32_t, float>(value));
3326 __ StoreToOffset(kStoreWord, IP, SP, destination.GetStackIndex());
3327 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003328 }
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003329 }
3330}
3331
3332void ParallelMoveResolverARM::Exchange(Register reg, int mem) {
3333 __ Mov(IP, reg);
3334 __ LoadFromOffset(kLoadWord, reg, SP, mem);
3335 __ StoreToOffset(kStoreWord, IP, SP, mem);
3336}
3337
3338void ParallelMoveResolverARM::Exchange(int mem1, int mem2) {
3339 ScratchRegisterScope ensure_scratch(this, IP, R0, codegen_->GetNumberOfCoreRegisters());
3340 int stack_offset = ensure_scratch.IsSpilled() ? kArmWordSize : 0;
3341 __ LoadFromOffset(kLoadWord, static_cast<Register>(ensure_scratch.GetRegister()),
3342 SP, mem1 + stack_offset);
3343 __ LoadFromOffset(kLoadWord, IP, SP, mem2 + stack_offset);
3344 __ StoreToOffset(kStoreWord, static_cast<Register>(ensure_scratch.GetRegister()),
3345 SP, mem2 + stack_offset);
3346 __ StoreToOffset(kStoreWord, IP, SP, mem1 + stack_offset);
3347}
3348
3349void ParallelMoveResolverARM::EmitSwap(size_t index) {
3350 MoveOperands* move = moves_.Get(index);
3351 Location source = move->GetSource();
3352 Location destination = move->GetDestination();
3353
3354 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003355 DCHECK_NE(source.AsRegister<Register>(), IP);
3356 DCHECK_NE(destination.AsRegister<Register>(), IP);
3357 __ Mov(IP, source.AsRegister<Register>());
3358 __ Mov(source.AsRegister<Register>(), destination.AsRegister<Register>());
3359 __ Mov(destination.AsRegister<Register>(), IP);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003360 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003361 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003362 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003363 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003364 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3365 Exchange(source.GetStackIndex(), destination.GetStackIndex());
Nicolas Geoffray840e5462015-01-07 16:01:24 +00003366 } else if (source.IsFpuRegister() && destination.IsFpuRegister()) {
3367 __ vmovrs(IP, source.AsFpuRegister<SRegister>());
3368 __ vmovs(source.AsFpuRegister<SRegister>(), destination.AsFpuRegister<SRegister>());
3369 __ vmovsr(destination.AsFpuRegister<SRegister>(), IP);
3370 } else if (source.IsFpuRegister() || destination.IsFpuRegister()) {
3371 SRegister reg = source.IsFpuRegister() ? source.AsFpuRegister<SRegister>()
3372 : destination.AsFpuRegister<SRegister>();
3373 int mem = source.IsFpuRegister()
3374 ? destination.GetStackIndex()
3375 : source.GetStackIndex();
3376
3377 __ vmovrs(IP, reg);
3378 __ LoadSFromOffset(reg, SP, mem);
3379 __ StoreToOffset(kStoreWord, IP, SP, mem);
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003380 } else {
3381 LOG(FATAL) << "Unimplemented";
3382 }
3383}
3384
3385void ParallelMoveResolverARM::SpillScratch(int reg) {
3386 __ Push(static_cast<Register>(reg));
3387}
3388
3389void ParallelMoveResolverARM::RestoreScratch(int reg) {
3390 __ Pop(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003391}
3392
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003393void LocationsBuilderARM::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003394 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3395 ? LocationSummary::kCallOnSlowPath
3396 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003397 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003398 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003399 locations->SetOut(Location::RequiresRegister());
3400}
3401
3402void InstructionCodeGeneratorARM::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003403 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003404 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003405 DCHECK(!cls->CanCallRuntime());
3406 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003407 codegen_->LoadCurrentMethod(out);
3408 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3409 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003410 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003411 codegen_->LoadCurrentMethod(out);
3412 __ LoadFromOffset(
3413 kLoadWord, out, out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value());
3414 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex()));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003415
3416 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3417 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3418 codegen_->AddSlowPath(slow_path);
3419 __ cmp(out, ShifterOperand(0));
3420 __ b(slow_path->GetEntryLabel(), EQ);
3421 if (cls->MustGenerateClinitCheck()) {
3422 GenerateClassInitializationCheck(slow_path, out);
3423 } else {
3424 __ Bind(slow_path->GetExitLabel());
3425 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003426 }
3427}
3428
3429void LocationsBuilderARM::VisitClinitCheck(HClinitCheck* check) {
3430 LocationSummary* locations =
3431 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3432 locations->SetInAt(0, Location::RequiresRegister());
3433 if (check->HasUses()) {
3434 locations->SetOut(Location::SameAsFirstInput());
3435 }
3436}
3437
3438void InstructionCodeGeneratorARM::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003439 // We assume the class is not null.
3440 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathARM(
3441 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003442 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003443 GenerateClassInitializationCheck(slow_path,
3444 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003445}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003446
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003447void InstructionCodeGeneratorARM::GenerateClassInitializationCheck(
3448 SlowPathCodeARM* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003449 __ LoadFromOffset(kLoadWord, IP, class_reg, mirror::Class::StatusOffset().Int32Value());
3450 __ cmp(IP, ShifterOperand(mirror::Class::kStatusInitialized));
3451 __ b(slow_path->GetEntryLabel(), LT);
3452 // Even if the initialized flag is set, we may be in a situation where caches are not synced
3453 // properly. Therefore, we do a memory fence.
3454 __ dmb(ISH);
3455 __ Bind(slow_path->GetExitLabel());
3456}
3457
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003458void LocationsBuilderARM::VisitLoadString(HLoadString* load) {
3459 LocationSummary* locations =
3460 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3461 locations->SetOut(Location::RequiresRegister());
3462}
3463
3464void InstructionCodeGeneratorARM::VisitLoadString(HLoadString* load) {
3465 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathARM(load);
3466 codegen_->AddSlowPath(slow_path);
3467
Roland Levillain271ab9c2014-11-27 15:23:57 +00003468 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003469 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003470 __ LoadFromOffset(kLoadWord, out, out, mirror::ArtMethod::DeclaringClassOffset().Int32Value());
3471 __ LoadFromOffset(kLoadWord, out, out, mirror::Class::DexCacheStringsOffset().Int32Value());
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003472 __ LoadFromOffset(kLoadWord, out, out, CodeGenerator::GetCacheOffset(load->GetStringIndex()));
3473 __ cmp(out, ShifterOperand(0));
3474 __ b(slow_path->GetEntryLabel(), EQ);
3475 __ Bind(slow_path->GetExitLabel());
3476}
3477
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003478void LocationsBuilderARM::VisitLoadException(HLoadException* load) {
3479 LocationSummary* locations =
3480 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3481 locations->SetOut(Location::RequiresRegister());
3482}
3483
3484void InstructionCodeGeneratorARM::VisitLoadException(HLoadException* load) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003485 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003486 int32_t offset = Thread::ExceptionOffset<kArmWordSize>().Int32Value();
3487 __ LoadFromOffset(kLoadWord, out, TR, offset);
3488 __ LoadImmediate(IP, 0);
3489 __ StoreToOffset(kStoreWord, IP, TR, offset);
3490}
3491
3492void LocationsBuilderARM::VisitThrow(HThrow* instruction) {
3493 LocationSummary* locations =
3494 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3495 InvokeRuntimeCallingConvention calling_convention;
3496 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3497}
3498
3499void InstructionCodeGeneratorARM::VisitThrow(HThrow* instruction) {
3500 codegen_->InvokeRuntime(
3501 QUICK_ENTRY_POINT(pDeliverException), instruction, instruction->GetDexPc());
3502}
3503
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003504void LocationsBuilderARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003505 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3506 ? LocationSummary::kNoCall
3507 : LocationSummary::kCallOnSlowPath;
3508 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3509 locations->SetInAt(0, Location::RequiresRegister());
3510 locations->SetInAt(1, Location::RequiresRegister());
3511 locations->SetOut(Location::RequiresRegister());
3512}
3513
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003514void InstructionCodeGeneratorARM::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003515 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003516 Register obj = locations->InAt(0).AsRegister<Register>();
3517 Register cls = locations->InAt(1).AsRegister<Register>();
3518 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003519 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3520 Label done, zero;
3521 SlowPathCodeARM* slow_path = nullptr;
3522
3523 // Return 0 if `obj` is null.
3524 // TODO: avoid this check if we know obj is not null.
3525 __ cmp(obj, ShifterOperand(0));
3526 __ b(&zero, EQ);
3527 // Compare the class of `obj` with `cls`.
3528 __ LoadFromOffset(kLoadWord, out, obj, class_offset);
3529 __ cmp(out, ShifterOperand(cls));
3530 if (instruction->IsClassFinal()) {
3531 // Classes must be equal for the instanceof to succeed.
3532 __ b(&zero, NE);
3533 __ LoadImmediate(out, 1);
3534 __ b(&done);
3535 } else {
3536 // If the classes are not equal, we go into a slow path.
3537 DCHECK(locations->OnlyCallsOnSlowPath());
3538 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003539 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003540 codegen_->AddSlowPath(slow_path);
3541 __ b(slow_path->GetEntryLabel(), NE);
3542 __ LoadImmediate(out, 1);
3543 __ b(&done);
3544 }
3545 __ Bind(&zero);
3546 __ LoadImmediate(out, 0);
3547 if (slow_path != nullptr) {
3548 __ Bind(slow_path->GetExitLabel());
3549 }
3550 __ Bind(&done);
3551}
3552
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003553void LocationsBuilderARM::VisitCheckCast(HCheckCast* instruction) {
3554 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3555 instruction, LocationSummary::kCallOnSlowPath);
3556 locations->SetInAt(0, Location::RequiresRegister());
3557 locations->SetInAt(1, Location::RequiresRegister());
3558 locations->AddTemp(Location::RequiresRegister());
3559}
3560
3561void InstructionCodeGeneratorARM::VisitCheckCast(HCheckCast* instruction) {
3562 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003563 Register obj = locations->InAt(0).AsRegister<Register>();
3564 Register cls = locations->InAt(1).AsRegister<Register>();
3565 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003566 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3567
3568 SlowPathCodeARM* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathARM(
3569 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3570 codegen_->AddSlowPath(slow_path);
3571
3572 // TODO: avoid this check if we know obj is not null.
3573 __ cmp(obj, ShifterOperand(0));
3574 __ b(slow_path->GetExitLabel(), EQ);
3575 // Compare the class of `obj` with `cls`.
3576 __ LoadFromOffset(kLoadWord, temp, obj, class_offset);
3577 __ cmp(temp, ShifterOperand(cls));
3578 __ b(slow_path->GetEntryLabel(), NE);
3579 __ Bind(slow_path->GetExitLabel());
3580}
3581
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003582void LocationsBuilderARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3583 LocationSummary* locations =
3584 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3585 InvokeRuntimeCallingConvention calling_convention;
3586 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3587}
3588
3589void InstructionCodeGeneratorARM::VisitMonitorOperation(HMonitorOperation* instruction) {
3590 codegen_->InvokeRuntime(instruction->IsEnter()
3591 ? QUICK_ENTRY_POINT(pLockObject) : QUICK_ENTRY_POINT(pUnlockObject),
3592 instruction,
3593 instruction->GetDexPc());
3594}
3595
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003596void LocationsBuilderARM::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3597void LocationsBuilderARM::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3598void LocationsBuilderARM::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3599
3600void LocationsBuilderARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3601 LocationSummary* locations =
3602 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3603 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3604 || instruction->GetResultType() == Primitive::kPrimLong);
3605 locations->SetInAt(0, Location::RequiresRegister());
3606 locations->SetInAt(1, Location::RequiresRegister());
3607 bool output_overlaps = (instruction->GetResultType() == Primitive::kPrimLong);
3608 locations->SetOut(Location::RequiresRegister(), output_overlaps);
3609}
3610
3611void InstructionCodeGeneratorARM::VisitAnd(HAnd* instruction) {
3612 HandleBitwiseOperation(instruction);
3613}
3614
3615void InstructionCodeGeneratorARM::VisitOr(HOr* instruction) {
3616 HandleBitwiseOperation(instruction);
3617}
3618
3619void InstructionCodeGeneratorARM::VisitXor(HXor* instruction) {
3620 HandleBitwiseOperation(instruction);
3621}
3622
3623void InstructionCodeGeneratorARM::HandleBitwiseOperation(HBinaryOperation* instruction) {
3624 LocationSummary* locations = instruction->GetLocations();
3625
3626 if (instruction->GetResultType() == Primitive::kPrimInt) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003627 Register first = locations->InAt(0).AsRegister<Register>();
3628 Register second = locations->InAt(1).AsRegister<Register>();
3629 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003630 if (instruction->IsAnd()) {
3631 __ and_(out, first, ShifterOperand(second));
3632 } else if (instruction->IsOr()) {
3633 __ orr(out, first, ShifterOperand(second));
3634 } else {
3635 DCHECK(instruction->IsXor());
3636 __ eor(out, first, ShifterOperand(second));
3637 }
3638 } else {
3639 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3640 Location first = locations->InAt(0);
3641 Location second = locations->InAt(1);
3642 Location out = locations->Out();
3643 if (instruction->IsAnd()) {
3644 __ and_(out.AsRegisterPairLow<Register>(),
3645 first.AsRegisterPairLow<Register>(),
3646 ShifterOperand(second.AsRegisterPairLow<Register>()));
3647 __ and_(out.AsRegisterPairHigh<Register>(),
3648 first.AsRegisterPairHigh<Register>(),
3649 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3650 } else if (instruction->IsOr()) {
3651 __ orr(out.AsRegisterPairLow<Register>(),
3652 first.AsRegisterPairLow<Register>(),
3653 ShifterOperand(second.AsRegisterPairLow<Register>()));
3654 __ orr(out.AsRegisterPairHigh<Register>(),
3655 first.AsRegisterPairHigh<Register>(),
3656 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3657 } else {
3658 DCHECK(instruction->IsXor());
3659 __ eor(out.AsRegisterPairLow<Register>(),
3660 first.AsRegisterPairLow<Register>(),
3661 ShifterOperand(second.AsRegisterPairLow<Register>()));
3662 __ eor(out.AsRegisterPairHigh<Register>(),
3663 first.AsRegisterPairHigh<Register>(),
3664 ShifterOperand(second.AsRegisterPairHigh<Register>()));
3665 }
3666 }
3667}
3668
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003669} // namespace arm
3670} // namespace art