blob: 8132e81798d4a1da27b7f8e0c1084d80aad354f5 [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_x86.h"
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +010018
19#include "entrypoints/quick/quick_entrypoints.h"
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +010020#include "gc/accounting/card_table.h"
Ian Rogers7e70b002014-10-08 11:47:24 -070021#include "mirror/array-inl.h"
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +010022#include "mirror/art_method.h"
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +010023#include "mirror/class.h"
Nicolas Geoffrayf6e206c2014-08-07 20:25:41 +010024#include "thread.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000025#include "utils/assembler.h"
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010026#include "utils/stack_checks.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000027#include "utils/x86/assembler_x86.h"
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010028#include "utils/x86/managed_register_x86.h"
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000029
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000030namespace art {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010031
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +000032namespace x86 {
33
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010034static constexpr bool kExplicitStackOverflowCheck = false;
35
36static constexpr int kNumberOfPushedRegistersAtEntry = 1;
37static constexpr int kCurrentMethodStackOffset = 0;
38
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010039static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX };
40static constexpr size_t kRuntimeParameterCoreRegistersLength =
41 arraysize(kRuntimeParameterCoreRegisters);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010042static constexpr XmmRegister kRuntimeParameterFpuRegisters[] = { };
43static constexpr size_t kRuntimeParameterFpuRegistersLength = 0;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010044
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010045class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010046 public:
47 InvokeRuntimeCallingConvention()
48 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010049 kRuntimeParameterCoreRegistersLength,
50 kRuntimeParameterFpuRegisters,
51 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010052
53 private:
54 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
55};
56
Nicolas Geoffraye5038322014-07-04 09:41:32 +010057#define __ reinterpret_cast<X86Assembler*>(codegen->GetAssembler())->
58
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010059class SlowPathCodeX86 : public SlowPathCode {
60 public:
61 SlowPathCodeX86() : entry_label_(), exit_label_() {}
62
63 Label* GetEntryLabel() { return &entry_label_; }
64 Label* GetExitLabel() { return &exit_label_; }
65
66 private:
67 Label entry_label_;
68 Label exit_label_;
69
70 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86);
71};
72
73class NullCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010074 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010075 explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010076
77 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
78 __ Bind(GetEntryLabel());
79 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowNullPointer)));
Nicolas Geoffray39468442014-09-02 15:17:15 +010080 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010081 }
82
83 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010084 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010085 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86);
86};
87
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010088class StackOverflowCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +010089 public:
90 StackOverflowCheckSlowPathX86() {}
91
92 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
93 __ Bind(GetEntryLabel());
94 __ addl(ESP,
95 Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
96 __ fs()->jmp(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowStackOverflow)));
97 }
98
99 private:
100 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86);
101};
102
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100103class BoundsCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100104 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100105 BoundsCheckSlowPathX86(HBoundsCheck* instruction,
106 Location index_location,
107 Location length_location)
Nicolas Geoffray39468442014-09-02 15:17:15 +0100108 : instruction_(instruction), index_location_(index_location), length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100109
110 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100111 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100112 __ Bind(GetEntryLabel());
113 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100114 x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(0)), index_location_);
115 x86_codegen->Move32(Location::RegisterLocation(calling_convention.GetRegisterAt(1)), length_location_);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100116 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds)));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100117 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100118 }
119
120 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100121 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100122 const Location index_location_;
123 const Location length_location_;
124
125 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86);
126};
127
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100128class SuspendCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000129 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100130 explicit SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor)
131 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000132
133 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100134 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000135 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100136 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000137 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend)));
138 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100139 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100140 if (successor_ == nullptr) {
141 __ jmp(GetReturnLabel());
142 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100143 __ jmp(x86_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100144 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000145 }
146
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100147 Label* GetReturnLabel() {
148 DCHECK(successor_ == nullptr);
149 return &return_label_;
150 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000151
152 private:
153 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100154 HBasicBlock* const successor_;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000155 Label return_label_;
156
157 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86);
158};
159
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000160class LoadStringSlowPathX86 : public SlowPathCodeX86 {
161 public:
162 explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {}
163
164 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
165 LocationSummary* locations = instruction_->GetLocations();
166 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
167
168 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
169 __ Bind(GetEntryLabel());
170 codegen->SaveLiveRegisters(locations);
171
172 InvokeRuntimeCallingConvention calling_convention;
173 x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
174 __ movl(calling_convention.GetRegisterAt(1), Immediate(instruction_->GetStringIndex()));
175 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pResolveString)));
176 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
177 x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX));
178 codegen->RestoreLiveRegisters(locations);
179
180 __ jmp(GetExitLabel());
181 }
182
183 private:
184 HLoadString* const instruction_;
185
186 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86);
187};
188
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000189class LoadClassSlowPathX86 : public SlowPathCodeX86 {
190 public:
191 LoadClassSlowPathX86(HLoadClass* cls,
192 HInstruction* at,
193 uint32_t dex_pc,
194 bool do_clinit)
195 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
196 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
197 }
198
199 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
200 LocationSummary* locations = at_->GetLocations();
201 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
202 __ Bind(GetEntryLabel());
203 codegen->SaveLiveRegisters(locations);
204
205 InvokeRuntimeCallingConvention calling_convention;
206 __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex()));
207 x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
208 __ fs()->call(Address::Absolute(do_clinit_
209 ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeStaticStorage)
210 : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeType)));
211 codegen->RecordPcInfo(at_, dex_pc_);
212
213 // Move the class to the desired location.
214 if (locations->Out().IsValid()) {
215 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
216 x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX));
217 }
218 codegen->RestoreLiveRegisters(locations);
219 __ jmp(GetExitLabel());
220 }
221
222 private:
223 // The class this slow path will load.
224 HLoadClass* const cls_;
225
226 // The instruction where this slow path is happening.
227 // (Might be the load class or an initialization check).
228 HInstruction* const at_;
229
230 // The dex PC of `at_`.
231 const uint32_t dex_pc_;
232
233 // Whether to initialize the class.
234 const bool do_clinit_;
235
236 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86);
237};
238
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100239#undef __
240#define __ reinterpret_cast<X86Assembler*>(GetAssembler())->
241
Dave Allison20dfc792014-06-16 20:44:29 -0700242inline Condition X86Condition(IfCondition cond) {
243 switch (cond) {
244 case kCondEQ: return kEqual;
245 case kCondNE: return kNotEqual;
246 case kCondLT: return kLess;
247 case kCondLE: return kLessEqual;
248 case kCondGT: return kGreater;
249 case kCondGE: return kGreaterEqual;
250 default:
251 LOG(FATAL) << "Unknown if condition";
252 }
253 return kEqual;
254}
255
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100256void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const {
257 stream << X86ManagedRegister::FromCpuRegister(Register(reg));
258}
259
260void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
261 stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg));
262}
263
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100264size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
265 __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id));
266 return kX86WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100267}
268
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100269size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
270 __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index));
271 return kX86WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100272}
273
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100274CodeGeneratorX86::CodeGeneratorX86(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100275 : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfXmmRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100276 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100277 location_builder_(graph, this),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100278 instruction_visitor_(graph, this),
279 move_resolver_(graph->GetArena(), this) {}
280
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100281size_t CodeGeneratorX86::FrameEntrySpillSize() const {
282 return kNumberOfPushedRegistersAtEntry * kX86WordSize;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100283}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100284
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100285Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100286 switch (type) {
287 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100288 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100289 X86ManagedRegister pair =
290 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100291 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
292 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100293 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
294 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100295 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100296 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100297 }
298
299 case Primitive::kPrimByte:
300 case Primitive::kPrimBoolean:
301 case Primitive::kPrimChar:
302 case Primitive::kPrimShort:
303 case Primitive::kPrimInt:
304 case Primitive::kPrimNot: {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100305 Register reg = static_cast<Register>(
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100306 FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100307 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100308 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
309 X86ManagedRegister current =
310 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
311 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100312 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100313 }
314 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100315 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100316 }
317
318 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100319 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100320 return Location::FpuRegisterLocation(
321 FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100322 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100323
324 case Primitive::kPrimVoid:
325 LOG(FATAL) << "Unreachable type " << type;
326 }
327
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100328 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100329}
330
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100331void CodeGeneratorX86::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100332 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100333 blocked_register_pairs_[ECX_EDX] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100334
335 // Stack register is always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100336 blocked_core_registers_[ESP] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100337
338 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100339 blocked_core_registers_[EBP] = true;
340 blocked_core_registers_[ESI] = true;
341 blocked_core_registers_[EDI] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100342
343 UpdateBlockedPairRegisters();
344}
345
346void CodeGeneratorX86::UpdateBlockedPairRegisters() const {
347 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
348 X86ManagedRegister current =
349 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
350 if (blocked_core_registers_[current.AsRegisterPairLow()]
351 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
352 blocked_register_pairs_[i] = true;
353 }
354 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100355}
356
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100357InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen)
358 : HGraphVisitor(graph),
359 assembler_(codegen->GetAssembler()),
360 codegen_(codegen) {}
361
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000362void CodeGeneratorX86::GenerateFrameEntry() {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000363 // Create a fake register to mimic Quick.
364 static const int kFakeReturnRegister = 8;
365 core_spill_mask_ |= (1 << kFakeReturnRegister);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000366
Dave Allison648d7112014-07-25 16:15:27 -0700367 bool skip_overflow_check = IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86);
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100368 if (!skip_overflow_check && !kExplicitStackOverflowCheck) {
369 __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86))));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100370 RecordPcInfo(nullptr, 0);
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100371 }
372
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100373 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100374 __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100375
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100376 if (!skip_overflow_check && kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100377 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86();
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100378 AddSlowPath(slow_path);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100379
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100380 __ fs()->cmpl(ESP, Address::Absolute(Thread::StackEndOffset<kX86WordSize>()));
381 __ j(kLess, slow_path->GetEntryLabel());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100382 }
383
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100384 __ movl(Address(ESP, kCurrentMethodStackOffset), EAX);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000385}
386
387void CodeGeneratorX86::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100388 __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000389}
390
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100391void CodeGeneratorX86::Bind(HBasicBlock* block) {
392 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000393}
394
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100395void CodeGeneratorX86::LoadCurrentMethod(Register reg) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100396 __ movl(reg, Address(ESP, kCurrentMethodStackOffset));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000397}
398
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100399Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const {
400 switch (load->GetType()) {
401 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100402 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100403 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
404 break;
405
406 case Primitive::kPrimInt:
407 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100408 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100409 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100410
411 case Primitive::kPrimBoolean:
412 case Primitive::kPrimByte:
413 case Primitive::kPrimChar:
414 case Primitive::kPrimShort:
415 case Primitive::kPrimVoid:
416 LOG(FATAL) << "Unexpected type " << load->GetType();
417 }
418
419 LOG(FATAL) << "Unreachable";
420 return Location();
421}
422
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100423Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
424 switch (type) {
425 case Primitive::kPrimBoolean:
426 case Primitive::kPrimByte:
427 case Primitive::kPrimChar:
428 case Primitive::kPrimShort:
429 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100430 case Primitive::kPrimFloat:
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100431 case Primitive::kPrimNot: {
432 uint32_t index = gp_index_++;
433 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100434 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100435 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100436 return Location::StackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100437 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100438 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100439
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100440 case Primitive::kPrimLong:
441 case Primitive::kPrimDouble: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100442 uint32_t index = gp_index_;
443 gp_index_ += 2;
444 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100445 X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair(
446 calling_convention.GetRegisterPairAt(index));
447 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100448 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000449 // On X86, the register index and stack index of a quick parameter is the same, since
450 // we are passing floating pointer values in core registers.
451 return Location::QuickParameter(index, index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100452 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100453 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100454 }
455 }
456
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100457 case Primitive::kPrimVoid:
458 LOG(FATAL) << "Unexpected parameter type " << type;
459 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100460 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100461 return Location();
462}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100463
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100464void CodeGeneratorX86::Move32(Location destination, Location source) {
465 if (source.Equals(destination)) {
466 return;
467 }
468 if (destination.IsRegister()) {
469 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100470 __ movl(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100471 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100472 __ movd(destination.As<Register>(), source.As<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100473 } else {
474 DCHECK(source.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100475 __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100476 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100477 } else if (destination.IsFpuRegister()) {
478 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100479 __ movd(destination.As<XmmRegister>(), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100480 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100481 __ movaps(destination.As<XmmRegister>(), source.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100482 } else {
483 DCHECK(source.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100484 __ movss(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100485 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100486 } else {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100487 DCHECK(destination.IsStackSlot());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100488 if (source.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100489 __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100490 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100491 __ movss(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100492 } else {
493 DCHECK(source.IsStackSlot());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100494 __ pushl(Address(ESP, source.GetStackIndex()));
495 __ popl(Address(ESP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100496 }
497 }
498}
499
500void CodeGeneratorX86::Move64(Location destination, Location source) {
501 if (source.Equals(destination)) {
502 return;
503 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100504 if (destination.IsRegisterPair()) {
505 if (source.IsRegisterPair()) {
506 __ movl(destination.AsRegisterPairLow<Register>(), source.AsRegisterPairLow<Register>());
507 __ movl(destination.AsRegisterPairHigh<Register>(), source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100508 } else if (source.IsFpuRegister()) {
509 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100510 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000511 uint16_t register_index = source.GetQuickParameterRegisterIndex();
512 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100513 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100514 __ movl(destination.AsRegisterPairLow<Register>(),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000515 calling_convention.GetRegisterAt(register_index));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100516 __ movl(destination.AsRegisterPairHigh<Register>(), Address(ESP,
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000517 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100518 } else {
519 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100520 __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex()));
521 __ movl(destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100522 Address(ESP, source.GetHighStackIndex(kX86WordSize)));
523 }
524 } else if (destination.IsQuickParameter()) {
525 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000526 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
527 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100528 if (source.IsRegister()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000529 __ movl(calling_convention.GetRegisterAt(register_index), source.AsRegisterPairLow<Register>());
530 __ movl(Address(ESP, calling_convention.GetStackOffsetOf(stack_index + 1)),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100531 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100532 } else if (source.IsFpuRegister()) {
533 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100534 } else {
535 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000536 __ movl(calling_convention.GetRegisterAt(register_index),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100537 Address(ESP, source.GetStackIndex()));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100538 __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000539 __ popl(Address(ESP, calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100540 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100541 } else if (destination.IsFpuRegister()) {
542 if (source.IsDoubleStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100543 __ movsd(destination.As<XmmRegister>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100544 } else {
545 LOG(FATAL) << "Unimplemented";
546 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100547 } else {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100548 DCHECK(destination.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100549 if (source.IsRegisterPair()) {
550 __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100551 __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100552 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100553 } else if (source.IsQuickParameter()) {
554 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000555 uint16_t register_index = source.GetQuickParameterRegisterIndex();
556 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100557 __ movl(Address(ESP, destination.GetStackIndex()),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000558 calling_convention.GetRegisterAt(register_index));
559 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100560 static_cast<size_t>(destination.GetHighStackIndex(kX86WordSize)));
561 } else if (source.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100562 __ movsd(Address(ESP, destination.GetStackIndex()), source.As<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100563 } else {
564 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100565 __ pushl(Address(ESP, source.GetStackIndex()));
566 __ popl(Address(ESP, destination.GetStackIndex()));
567 __ pushl(Address(ESP, source.GetHighStackIndex(kX86WordSize)));
568 __ popl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100569 }
570 }
571}
572
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100573void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Roland Levillain476df552014-10-09 17:51:36 +0100574 if (instruction->IsIntConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100575 Immediate imm(instruction->AsIntConstant()->GetValue());
576 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100577 __ movl(location.As<Register>(), imm);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100578 } else if (location.IsStackSlot()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100579 __ movl(Address(ESP, location.GetStackIndex()), imm);
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100580 } else {
581 DCHECK(location.IsConstant());
582 DCHECK_EQ(location.GetConstant(), instruction);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100583 }
Roland Levillain476df552014-10-09 17:51:36 +0100584 } else if (instruction->IsLongConstant()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100585 int64_t value = instruction->AsLongConstant()->GetValue();
586 if (location.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100587 __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value)));
588 __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100589 } else if (location.IsDoubleStackSlot()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100590 __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value)));
591 __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)), Immediate(High32Bits(value)));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +0100592 } else {
593 DCHECK(location.IsConstant());
594 DCHECK_EQ(location.GetConstant(), instruction);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100595 }
Roland Levillain476df552014-10-09 17:51:36 +0100596 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100597 int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100598 switch (instruction->GetType()) {
599 case Primitive::kPrimBoolean:
600 case Primitive::kPrimByte:
601 case Primitive::kPrimChar:
602 case Primitive::kPrimShort:
603 case Primitive::kPrimInt:
604 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100605 case Primitive::kPrimFloat:
606 Move32(location, Location::StackSlot(slot));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100607 break;
608
609 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100610 case Primitive::kPrimDouble:
611 Move64(location, Location::DoubleStackSlot(slot));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100612 break;
613
614 default:
615 LOG(FATAL) << "Unimplemented local type " << instruction->GetType();
616 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000617 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100618 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100619 switch (instruction->GetType()) {
620 case Primitive::kPrimBoolean:
621 case Primitive::kPrimByte:
622 case Primitive::kPrimChar:
623 case Primitive::kPrimShort:
624 case Primitive::kPrimInt:
625 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100626 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100627 Move32(location, instruction->GetLocations()->Out());
628 break;
629
630 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100631 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100632 Move64(location, instruction->GetLocations()->Out());
633 break;
634
635 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100636 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100637 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000638 }
639}
640
641void LocationsBuilderX86::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000642 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000643}
644
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000645void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000646 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100647 DCHECK(!successor->IsExitBlock());
648
649 HBasicBlock* block = got->GetBlock();
650 HInstruction* previous = got->GetPrevious();
651
652 HLoopInformation* info = block->GetLoopInformation();
653 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
654 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
655 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
656 return;
657 }
658
659 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
660 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
661 }
662 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000663 __ jmp(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000664 }
665}
666
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000667void LocationsBuilderX86::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000668 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000669}
670
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000671void InstructionCodeGeneratorX86::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700672 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000673 if (kIsDebugBuild) {
674 __ Comment("Unreachable");
675 __ int3();
676 }
677}
678
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000679void LocationsBuilderX86::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100680 LocationSummary* locations =
681 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100682 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100683 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100684 locations->SetInAt(0, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100685 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000686}
687
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000688void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700689 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100690 if (cond->IsIntConstant()) {
691 // Constant condition, statically compared against 1.
692 int32_t cond_value = cond->AsIntConstant()->GetValue();
693 if (cond_value == 1) {
694 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
695 if_instr->IfTrueSuccessor())) {
696 __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100697 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100698 return;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100699 } else {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100700 DCHECK_EQ(cond_value, 0);
701 }
702 } else {
703 bool materialized =
704 !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization();
705 // Moves do not affect the eflags register, so if the condition is
706 // evaluated just before the if, we don't need to evaluate it
707 // again.
708 bool eflags_set = cond->IsCondition()
709 && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr);
710 if (materialized) {
711 if (!eflags_set) {
712 // Materialized condition, compare against 0.
713 Location lhs = if_instr->GetLocations()->InAt(0);
714 if (lhs.IsRegister()) {
715 __ cmpl(lhs.As<Register>(), Immediate(0));
716 } else {
717 __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0));
718 }
719 __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
720 } else {
721 __ j(X86Condition(cond->AsCondition()->GetCondition()),
722 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
723 }
724 } else {
725 Location lhs = cond->GetLocations()->InAt(0);
726 Location rhs = cond->GetLocations()->InAt(1);
727 // LHS is guaranteed to be in a register (see
728 // LocationsBuilderX86::VisitCondition).
729 if (rhs.IsRegister()) {
730 __ cmpl(lhs.As<Register>(), rhs.As<Register>());
731 } else if (rhs.IsConstant()) {
732 HIntConstant* instruction = rhs.GetConstant()->AsIntConstant();
733 Immediate imm(instruction->AsIntConstant()->GetValue());
734 __ cmpl(lhs.As<Register>(), imm);
735 } else {
736 __ cmpl(lhs.As<Register>(), Address(ESP, rhs.GetStackIndex()));
737 }
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100738 __ j(X86Condition(cond->AsCondition()->GetCondition()),
739 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Dave Allison20dfc792014-06-16 20:44:29 -0700740 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100741 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100742 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
743 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700744 __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000745 }
746}
747
748void LocationsBuilderX86::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000749 local->SetLocations(nullptr);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000750}
751
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000752void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) {
753 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000754}
755
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000756void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100757 local->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000758}
759
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000760void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100761 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700762 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000763}
764
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100765void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100766 LocationSummary* locations =
767 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100768 switch (store->InputAt(1)->GetType()) {
769 case Primitive::kPrimBoolean:
770 case Primitive::kPrimByte:
771 case Primitive::kPrimChar:
772 case Primitive::kPrimShort:
773 case Primitive::kPrimInt:
774 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100775 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100776 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
777 break;
778
779 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100780 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100781 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
782 break;
783
784 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100785 LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100786 }
787 store->SetLocations(locations);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000788}
789
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000790void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700791 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000792}
793
Dave Allison20dfc792014-06-16 20:44:29 -0700794void LocationsBuilderX86::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100795 LocationSummary* locations =
796 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100797 locations->SetInAt(0, Location::RequiresRegister());
798 locations->SetInAt(1, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100799 if (comp->NeedsMaterialization()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100800 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100801 }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000802}
803
Dave Allison20dfc792014-06-16 20:44:29 -0700804void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) {
805 if (comp->NeedsMaterialization()) {
806 LocationSummary* locations = comp->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100807 Register reg = locations->Out().As<Register>();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100808 // Clear register: setcc only sets the low byte.
809 __ xorl(reg, reg);
Dave Allison20dfc792014-06-16 20:44:29 -0700810 if (locations->InAt(1).IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100811 __ cmpl(locations->InAt(0).As<Register>(),
812 locations->InAt(1).As<Register>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100813 } else if (locations->InAt(1).IsConstant()) {
814 HConstant* instruction = locations->InAt(1).GetConstant();
815 Immediate imm(instruction->AsIntConstant()->GetValue());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100816 __ cmpl(locations->InAt(0).As<Register>(), imm);
Dave Allison20dfc792014-06-16 20:44:29 -0700817 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100818 __ cmpl(locations->InAt(0).As<Register>(),
Dave Allison20dfc792014-06-16 20:44:29 -0700819 Address(ESP, locations->InAt(1).GetStackIndex()));
820 }
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100821 __ setb(X86Condition(comp->GetCondition()), reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100822 }
Dave Allison20dfc792014-06-16 20:44:29 -0700823}
824
825void LocationsBuilderX86::VisitEqual(HEqual* comp) {
826 VisitCondition(comp);
827}
828
829void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) {
830 VisitCondition(comp);
831}
832
833void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) {
834 VisitCondition(comp);
835}
836
837void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) {
838 VisitCondition(comp);
839}
840
841void LocationsBuilderX86::VisitLessThan(HLessThan* comp) {
842 VisitCondition(comp);
843}
844
845void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) {
846 VisitCondition(comp);
847}
848
849void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
850 VisitCondition(comp);
851}
852
853void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
854 VisitCondition(comp);
855}
856
857void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) {
858 VisitCondition(comp);
859}
860
861void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) {
862 VisitCondition(comp);
863}
864
865void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
866 VisitCondition(comp);
867}
868
869void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
870 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000871}
872
873void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100874 LocationSummary* locations =
875 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100876 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000877}
878
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000879void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100880 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700881 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000882}
883
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100884void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100885 LocationSummary* locations =
886 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100887 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100888}
889
890void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) {
891 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700892 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100893}
894
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100895void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) {
896 LocationSummary* locations =
897 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
898 locations->SetOut(Location::ConstantLocation(constant));
899}
900
901void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) {
902 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700903 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100904}
905
906void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) {
907 LocationSummary* locations =
908 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
909 locations->SetOut(Location::ConstantLocation(constant));
910}
911
912void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) {
913 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700914 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100915}
916
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000917void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000918 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000919}
920
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000921void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700922 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000923 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000924 __ ret();
925}
926
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000927void LocationsBuilderX86::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100928 LocationSummary* locations =
929 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100930 switch (ret->InputAt(0)->GetType()) {
931 case Primitive::kPrimBoolean:
932 case Primitive::kPrimByte:
933 case Primitive::kPrimChar:
934 case Primitive::kPrimShort:
935 case Primitive::kPrimInt:
936 case Primitive::kPrimNot:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100937 locations->SetInAt(0, Location::RegisterLocation(EAX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100938 break;
939
940 case Primitive::kPrimLong:
941 locations->SetInAt(
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100942 0, Location::RegisterPairLocation(EAX, EDX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100943 break;
944
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100945 case Primitive::kPrimFloat:
946 case Primitive::kPrimDouble:
947 locations->SetInAt(
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100948 0, Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100949 break;
950
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100951 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100952 LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100953 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000954}
955
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000956void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100957 if (kIsDebugBuild) {
958 switch (ret->InputAt(0)->GetType()) {
959 case Primitive::kPrimBoolean:
960 case Primitive::kPrimByte:
961 case Primitive::kPrimChar:
962 case Primitive::kPrimShort:
963 case Primitive::kPrimInt:
964 case Primitive::kPrimNot:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100965 DCHECK_EQ(ret->GetLocations()->InAt(0).As<Register>(), EAX);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100966 break;
967
968 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100969 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX);
970 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100971 break;
972
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100973 case Primitive::kPrimFloat:
974 case Primitive::kPrimDouble:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100975 DCHECK_EQ(ret->GetLocations()->InAt(0).As<XmmRegister>(), XMM0);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100976 break;
977
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100978 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100979 LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100980 }
981 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000982 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000983 __ ret();
984}
985
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000986void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100987 HandleInvoke(invoke);
988}
989
990void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100991 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +0100992
993 // TODO: Implement all kinds of calls:
994 // 1) boot -> boot
995 // 2) app -> boot
996 // 3) app -> app
997 //
998 // Currently we implement the app -> app logic, which looks up in the resolve cache.
999
1000 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001001 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001002 // temp = temp->dex_cache_resolved_methods_;
1003 __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()));
1004 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001005 __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001006 // (temp + offset_of_quick_compiled_code)()
1007 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()));
1008
1009 DCHECK(!codegen_->IsLeafMethod());
1010 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1011}
1012
1013void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1014 HandleInvoke(invoke);
1015}
1016
1017void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001018 LocationSummary* locations =
1019 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001020 locations->AddTemp(Location::RegisterLocation(EAX));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001021
1022 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001023 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001024 HInstruction* input = invoke->InputAt(i);
1025 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1026 }
1027
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001028 switch (invoke->GetType()) {
1029 case Primitive::kPrimBoolean:
1030 case Primitive::kPrimByte:
1031 case Primitive::kPrimChar:
1032 case Primitive::kPrimShort:
1033 case Primitive::kPrimInt:
1034 case Primitive::kPrimNot:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001035 locations->SetOut(Location::RegisterLocation(EAX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001036 break;
1037
1038 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001039 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001040 break;
1041
1042 case Primitive::kPrimVoid:
1043 break;
1044
1045 case Primitive::kPrimDouble:
1046 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001047 locations->SetOut(Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001048 break;
1049 }
1050
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001051 invoke->SetLocations(locations);
1052}
1053
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001054void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001055 Register temp = invoke->GetLocations()->GetTemp(0).As<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001056 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1057 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1058 LocationSummary* locations = invoke->GetLocations();
1059 Location receiver = locations->InAt(0);
1060 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1061 // temp = object->GetClass();
1062 if (receiver.IsStackSlot()) {
1063 __ movl(temp, Address(ESP, receiver.GetStackIndex()));
1064 __ movl(temp, Address(temp, class_offset));
1065 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001066 __ movl(temp, Address(receiver.As<Register>(), class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001067 }
1068 // temp = temp->GetMethodAt(method_offset);
1069 __ movl(temp, Address(temp, method_offset));
1070 // call temp->GetEntryPoint();
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001071 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()));
1072
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001073 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001074 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001075}
1076
Roland Levillain88cb1752014-10-20 16:36:47 +01001077void LocationsBuilderX86::VisitNeg(HNeg* neg) {
1078 LocationSummary* locations =
1079 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1080 switch (neg->GetResultType()) {
1081 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001082 case Primitive::kPrimLong:
Roland Levillain88cb1752014-10-20 16:36:47 +01001083 locations->SetInAt(0, Location::RequiresRegister());
1084 locations->SetOut(Location::SameAsFirstInput());
1085 break;
1086
Roland Levillain88cb1752014-10-20 16:36:47 +01001087 case Primitive::kPrimFloat:
1088 case Primitive::kPrimDouble:
1089 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1090 break;
1091
1092 default:
1093 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1094 }
1095}
1096
1097void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) {
1098 LocationSummary* locations = neg->GetLocations();
1099 Location out = locations->Out();
1100 Location in = locations->InAt(0);
1101 switch (neg->GetResultType()) {
1102 case Primitive::kPrimInt:
1103 DCHECK(in.IsRegister());
1104 __ negl(out.As<Register>());
1105 break;
1106
1107 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001108 DCHECK(in.IsRegisterPair());
1109 __ negl(out.AsRegisterPairLow<Register>());
1110 // Negation is similar to subtraction from zero. The least
1111 // significant byte triggers a borrow when it is different from
1112 // zero; to take it into account, add 1 to the most significant
1113 // byte if the carry flag (CF) is set to 1 after the first NEGL
1114 // operation.
1115 __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0));
1116 __ negl(out.AsRegisterPairHigh<Register>());
1117 break;
1118
Roland Levillain88cb1752014-10-20 16:36:47 +01001119 case Primitive::kPrimFloat:
1120 case Primitive::kPrimDouble:
1121 LOG(FATAL) << "Not yet implemented neg type " << neg->GetResultType();
1122 break;
1123
1124 default:
1125 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1126 }
1127}
1128
Roland Levillaindff1f282014-11-05 14:15:05 +00001129void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) {
1130 LocationSummary* locations =
1131 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1132 Primitive::Type result_type = conversion->GetResultType();
1133 Primitive::Type input_type = conversion->GetInputType();
1134 switch (result_type) {
1135 case Primitive::kPrimLong:
1136 switch (input_type) {
1137 case Primitive::kPrimByte:
1138 case Primitive::kPrimShort:
1139 case Primitive::kPrimInt:
1140 // int-to-long conversion.
1141 locations->SetInAt(0, Location::RegisterLocation(EAX));
1142 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
1143 break;
1144
1145 case Primitive::kPrimFloat:
1146 case Primitive::kPrimDouble:
1147 LOG(FATAL) << "Type conversion from " << input_type << " to "
1148 << result_type << " not yet implemented";
1149 break;
1150
1151 default:
1152 LOG(FATAL) << "Unexpected type conversion from " << input_type
1153 << " to " << result_type;
1154 }
1155 break;
1156
1157 case Primitive::kPrimInt:
1158 case Primitive::kPrimFloat:
1159 case Primitive::kPrimDouble:
1160 LOG(FATAL) << "Type conversion from " << input_type
1161 << " to " << result_type << " not yet implemented";
1162 break;
1163
1164 default:
1165 LOG(FATAL) << "Unexpected type conversion from " << input_type
1166 << " to " << result_type;
1167 }
1168}
1169
1170void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) {
1171 LocationSummary* locations = conversion->GetLocations();
1172 Location out = locations->Out();
1173 Location in = locations->InAt(0);
1174 Primitive::Type result_type = conversion->GetResultType();
1175 Primitive::Type input_type = conversion->GetInputType();
1176 switch (result_type) {
1177 case Primitive::kPrimLong:
1178 switch (input_type) {
1179 case Primitive::kPrimByte:
1180 case Primitive::kPrimShort:
1181 case Primitive::kPrimInt:
1182 // int-to-long conversion.
1183 DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX);
1184 DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX);
1185 DCHECK_EQ(in.As<Register>(), EAX);
1186 __ cdq();
1187 break;
1188
1189 case Primitive::kPrimFloat:
1190 case Primitive::kPrimDouble:
1191 LOG(FATAL) << "Type conversion from " << input_type << " to "
1192 << result_type << " not yet implemented";
1193 break;
1194
1195 default:
1196 LOG(FATAL) << "Unexpected type conversion from " << input_type
1197 << " to " << result_type;
1198 }
1199 break;
1200
1201 case Primitive::kPrimInt:
1202 case Primitive::kPrimFloat:
1203 case Primitive::kPrimDouble:
1204 LOG(FATAL) << "Type conversion from " << input_type
1205 << " to " << result_type << " not yet implemented";
1206 break;
1207
1208 default:
1209 LOG(FATAL) << "Unexpected type conversion from " << input_type
1210 << " to " << result_type;
1211 }
1212}
1213
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001214void LocationsBuilderX86::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001215 LocationSummary* locations =
1216 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001217 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001218 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001219 case Primitive::kPrimLong: {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001220 locations->SetInAt(0, Location::RequiresRegister());
1221 locations->SetInAt(1, Location::Any());
1222 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001223 break;
1224 }
1225
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001226 case Primitive::kPrimFloat:
1227 case Primitive::kPrimDouble: {
1228 locations->SetInAt(0, Location::RequiresFpuRegister());
1229 locations->SetInAt(1, Location::Any());
1230 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001231 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001232 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001233
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001234 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001235 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
1236 break;
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001237 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001238}
1239
1240void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) {
1241 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001242 Location first = locations->InAt(0);
1243 Location second = locations->InAt(1);
Calin Juravle11351682014-10-23 15:38:15 +01001244 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001245 switch (add->GetResultType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001246 case Primitive::kPrimInt: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001247 if (second.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001248 __ addl(first.As<Register>(), second.As<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001249 } else if (second.IsConstant()) {
Calin Juravle11351682014-10-23 15:38:15 +01001250 __ addl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001251 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001252 __ addl(first.As<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001253 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001254 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001255 }
1256
1257 case Primitive::kPrimLong: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001258 if (second.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001259 __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
1260 __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001261 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001262 __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
1263 __ adcl(first.AsRegisterPairHigh<Register>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001264 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001265 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001266 break;
1267 }
1268
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001269 case Primitive::kPrimFloat: {
1270 if (second.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001271 __ addss(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001272 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001273 __ addss(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001274 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001275 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001276 }
1277
1278 case Primitive::kPrimDouble: {
1279 if (second.IsFpuRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001280 __ addsd(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001281 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001282 __ addsd(first.As<XmmRegister>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001283 }
1284 break;
1285 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001286
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001287 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001288 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001289 }
1290}
1291
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001292void LocationsBuilderX86::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001293 LocationSummary* locations =
1294 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001295 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001296 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001297 case Primitive::kPrimLong: {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001298 locations->SetInAt(0, Location::RequiresRegister());
1299 locations->SetInAt(1, Location::Any());
1300 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001301 break;
1302 }
Calin Juravle11351682014-10-23 15:38:15 +01001303 case Primitive::kPrimFloat:
1304 case Primitive::kPrimDouble: {
1305 locations->SetInAt(0, Location::RequiresFpuRegister());
1306 locations->SetInAt(1, Location::RequiresFpuRegister());
1307 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001308 break;
Calin Juravle11351682014-10-23 15:38:15 +01001309 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001310
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001311 default:
Calin Juravle11351682014-10-23 15:38:15 +01001312 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001313 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001314}
1315
1316void InstructionCodeGeneratorX86::VisitSub(HSub* sub) {
1317 LocationSummary* locations = sub->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001318 Location first = locations->InAt(0);
1319 Location second = locations->InAt(1);
Calin Juravle11351682014-10-23 15:38:15 +01001320 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001321 switch (sub->GetResultType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001322 case Primitive::kPrimInt: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001323 if (second.IsRegister()) {
Calin Juravle11351682014-10-23 15:38:15 +01001324 __ subl(first.As<Register>(), second.As<Register>());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001325 } else if (second.IsConstant()) {
Calin Juravle11351682014-10-23 15:38:15 +01001326 __ subl(first.As<Register>(), Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001327 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001328 __ subl(first.As<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001329 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001330 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001331 }
1332
1333 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001334 if (second.IsRegister()) {
Calin Juravle11351682014-10-23 15:38:15 +01001335 __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
1336 __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001337 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001338 __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001339 __ sbbl(first.AsRegisterPairHigh<Register>(),
1340 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001341 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001342 break;
1343 }
1344
Calin Juravle11351682014-10-23 15:38:15 +01001345 case Primitive::kPrimFloat: {
1346 __ subss(first.As<XmmRegister>(), second.As<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001347 break;
Calin Juravle11351682014-10-23 15:38:15 +01001348 }
1349
1350 case Primitive::kPrimDouble: {
1351 __ subsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1352 break;
1353 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001354
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001355 default:
Calin Juravle11351682014-10-23 15:38:15 +01001356 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001357 }
1358}
1359
Calin Juravle34bacdf2014-10-07 20:23:36 +01001360void LocationsBuilderX86::VisitMul(HMul* mul) {
1361 LocationSummary* locations =
1362 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1363 switch (mul->GetResultType()) {
1364 case Primitive::kPrimInt:
1365 locations->SetInAt(0, Location::RequiresRegister());
1366 locations->SetInAt(1, Location::Any());
1367 locations->SetOut(Location::SameAsFirstInput());
1368 break;
1369 case Primitive::kPrimLong: {
1370 locations->SetInAt(0, Location::RequiresRegister());
1371 // TODO: Currently this handles only stack operands:
1372 // - we don't have enough registers because we currently use Quick ABI.
1373 // - by the time we have a working register allocator we will probably change the ABI
1374 // and fix the above.
1375 // - we don't have a way yet to request operands on stack but the base line compiler
1376 // will leave the operands on the stack with Any().
1377 locations->SetInAt(1, Location::Any());
1378 locations->SetOut(Location::SameAsFirstInput());
1379 // Needed for imul on 32bits with 64bits output.
1380 locations->AddTemp(Location::RegisterLocation(EAX));
1381 locations->AddTemp(Location::RegisterLocation(EDX));
1382 break;
1383 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001384 case Primitive::kPrimFloat:
1385 case Primitive::kPrimDouble: {
1386 locations->SetInAt(0, Location::RequiresFpuRegister());
1387 locations->SetInAt(1, Location::RequiresFpuRegister());
1388 locations->SetOut(Location::SameAsFirstInput());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001389 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001390 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001391
1392 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001393 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001394 }
1395}
1396
1397void InstructionCodeGeneratorX86::VisitMul(HMul* mul) {
1398 LocationSummary* locations = mul->GetLocations();
1399 Location first = locations->InAt(0);
1400 Location second = locations->InAt(1);
1401 DCHECK(first.Equals(locations->Out()));
1402
1403 switch (mul->GetResultType()) {
1404 case Primitive::kPrimInt: {
1405 if (second.IsRegister()) {
1406 __ imull(first.As<Register>(), second.As<Register>());
1407 } else if (second.IsConstant()) {
1408 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
1409 __ imull(first.As<Register>(), imm);
1410 } else {
1411 DCHECK(second.IsStackSlot());
1412 __ imull(first.As<Register>(), Address(ESP, second.GetStackIndex()));
1413 }
1414 break;
1415 }
1416
1417 case Primitive::kPrimLong: {
1418 DCHECK(second.IsDoubleStackSlot());
1419
1420 Register in1_hi = first.AsRegisterPairHigh<Register>();
1421 Register in1_lo = first.AsRegisterPairLow<Register>();
1422 Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize));
1423 Address in2_lo(ESP, second.GetStackIndex());
1424 Register eax = locations->GetTemp(0).As<Register>();
1425 Register edx = locations->GetTemp(1).As<Register>();
1426
1427 DCHECK_EQ(EAX, eax);
1428 DCHECK_EQ(EDX, edx);
1429
1430 // input: in1 - 64 bits, in2 - 64 bits
1431 // output: in1
1432 // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1433 // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1434 // parts: in1.lo = (in1.lo * in2.lo)[31:0]
1435
1436 __ movl(eax, in2_hi);
1437 // eax <- in1.lo * in2.hi
1438 __ imull(eax, in1_lo);
1439 // in1.hi <- in1.hi * in2.lo
1440 __ imull(in1_hi, in2_lo);
1441 // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1442 __ addl(in1_hi, eax);
1443 // move in1_lo to eax to prepare for double precision
1444 __ movl(eax, in1_lo);
1445 // edx:eax <- in1.lo * in2.lo
1446 __ mull(in2_lo);
1447 // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1448 __ addl(in1_hi, edx);
1449 // in1.lo <- (in1.lo * in2.lo)[31:0];
1450 __ movl(in1_lo, eax);
1451
1452 break;
1453 }
1454
Calin Juravleb5bfa962014-10-21 18:02:24 +01001455 case Primitive::kPrimFloat: {
1456 __ mulss(first.As<XmmRegister>(), second.As<XmmRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001457 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001458 }
1459
1460 case Primitive::kPrimDouble: {
1461 __ mulsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1462 break;
1463 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001464
1465 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001466 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001467 }
1468}
1469
Calin Juravle7c4954d2014-10-28 16:57:40 +00001470void LocationsBuilderX86::VisitDiv(HDiv* div) {
1471 LocationSummary* locations =
1472 new (GetGraph()->GetArena()) LocationSummary(div, LocationSummary::kNoCall);
1473 switch (div->GetResultType()) {
1474 case Primitive::kPrimInt:
1475 case Primitive::kPrimLong: {
1476 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1477 break;
1478 }
1479 case Primitive::kPrimFloat:
1480 case Primitive::kPrimDouble: {
1481 locations->SetInAt(0, Location::RequiresFpuRegister());
1482 locations->SetInAt(1, Location::RequiresFpuRegister());
1483 locations->SetOut(Location::SameAsFirstInput());
1484 break;
1485 }
1486
1487 default:
1488 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1489 }
1490}
1491
1492void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) {
1493 LocationSummary* locations = div->GetLocations();
1494 Location first = locations->InAt(0);
1495 Location second = locations->InAt(1);
1496 DCHECK(first.Equals(locations->Out()));
1497
1498 switch (div->GetResultType()) {
1499 case Primitive::kPrimInt:
1500 case Primitive::kPrimLong: {
1501 LOG(FATAL) << "Not implemented div type" << div->GetResultType();
1502 break;
1503 }
1504
1505 case Primitive::kPrimFloat: {
1506 __ divss(first.As<XmmRegister>(), second.As<XmmRegister>());
1507 break;
1508 }
1509
1510 case Primitive::kPrimDouble: {
1511 __ divsd(first.As<XmmRegister>(), second.As<XmmRegister>());
1512 break;
1513 }
1514
1515 default:
1516 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
1517 }
1518}
1519
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001520void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001521 LocationSummary* locations =
1522 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001523 locations->SetOut(Location::RegisterLocation(EAX));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001524 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001525 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1526 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001527}
1528
1529void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) {
1530 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001531 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001532 __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex()));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001533
Nicolas Geoffray707c8092014-04-04 10:50:14 +01001534 __ fs()->call(
1535 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck)));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001536
Nicolas Geoffray39468442014-09-02 15:17:15 +01001537 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001538 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001539}
1540
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001541void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) {
1542 LocationSummary* locations =
1543 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
1544 locations->SetOut(Location::RegisterLocation(EAX));
1545 InvokeRuntimeCallingConvention calling_convention;
1546 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1547 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1548 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
1549}
1550
1551void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) {
1552 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001553 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01001554 __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex()));
1555
1556 __ fs()->call(
1557 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck)));
1558
1559 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
1560 DCHECK(!codegen_->IsLeafMethod());
1561}
1562
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001563void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001564 LocationSummary* locations =
1565 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001566 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
1567 if (location.IsStackSlot()) {
1568 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
1569 } else if (location.IsDoubleStackSlot()) {
1570 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001571 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01001572 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001573}
1574
1575void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001576 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001577}
1578
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001579void LocationsBuilderX86::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001580 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001581 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001582 locations->SetInAt(0, Location::RequiresRegister());
1583 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001584}
1585
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001586void InstructionCodeGeneratorX86::VisitNot(HNot* not_) {
1587 LocationSummary* locations = not_->GetLocations();
Roland Levillain70566432014-10-24 16:20:17 +01001588 Location in = locations->InAt(0);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001589 Location out = locations->Out();
Roland Levillain70566432014-10-24 16:20:17 +01001590 DCHECK(in.Equals(out));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001591 switch (not_->InputAt(0)->GetType()) {
1592 case Primitive::kPrimBoolean:
1593 __ xorl(out.As<Register>(), Immediate(1));
1594 break;
1595
1596 case Primitive::kPrimInt:
1597 __ notl(out.As<Register>());
1598 break;
1599
1600 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01001601 __ notl(out.AsRegisterPairLow<Register>());
1602 __ notl(out.AsRegisterPairHigh<Register>());
Roland Levillain1cc5f2512014-10-22 18:06:21 +01001603 break;
1604
1605 default:
1606 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
1607 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01001608}
1609
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001610void LocationsBuilderX86::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001611 LocationSummary* locations =
1612 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001613 locations->SetInAt(0, Location::RequiresRegister());
1614 locations->SetInAt(1, Location::Any());
1615 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001616}
1617
1618void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001619 LocationSummary* locations = compare->GetLocations();
1620 switch (compare->InputAt(0)->GetType()) {
1621 case Primitive::kPrimLong: {
1622 Label less, greater, done;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001623 Register output = locations->Out().As<Register>();
1624 Location left = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001625 Location right = locations->InAt(1);
1626 if (right.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001627 __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001628 } else {
1629 DCHECK(right.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001630 __ cmpl(left.AsRegisterPairHigh<Register>(),
1631 Address(ESP, right.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001632 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001633 __ j(kLess, &less); // Signed compare.
1634 __ j(kGreater, &greater); // Signed compare.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001635 if (right.IsRegisterPair()) {
1636 __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001637 } else {
1638 DCHECK(right.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001639 __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex()));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001640 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001641 __ movl(output, Immediate(0));
1642 __ j(kEqual, &done);
1643 __ j(kBelow, &less); // Unsigned compare.
1644
1645 __ Bind(&greater);
1646 __ movl(output, Immediate(1));
1647 __ jmp(&done);
1648
1649 __ Bind(&less);
1650 __ movl(output, Immediate(-1));
1651
1652 __ Bind(&done);
1653 break;
1654 }
1655 default:
1656 LOG(FATAL) << "Unimplemented compare type " << compare->InputAt(0)->GetType();
1657 }
1658}
1659
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001660void LocationsBuilderX86::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001661 LocationSummary* locations =
1662 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01001663 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
1664 locations->SetInAt(i, Location::Any());
1665 }
1666 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001667}
1668
1669void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001670 UNUSED(instruction);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01001671 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001672}
1673
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001674void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001675 LocationSummary* locations =
1676 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001677 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001678 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001679 bool is_object_type = field_type == Primitive::kPrimNot;
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01001680 bool is_byte_type = (field_type == Primitive::kPrimBoolean)
1681 || (field_type == Primitive::kPrimByte);
1682 // The register allocator does not support multiple
1683 // inputs that die at entry with one in a specific register.
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01001684 if (is_byte_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001685 // Ensure the value is in a byte register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001686 locations->SetInAt(1, Location::RegisterLocation(EAX));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001687 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001688 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001689 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001690 // Temporary registers for the write barrier.
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001691 if (is_object_type) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001692 locations->AddTemp(Location::RequiresRegister());
1693 // Ensure the card is in a byte register.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001694 locations->AddTemp(Location::RegisterLocation(ECX));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01001695 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001696}
1697
1698void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
1699 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001700 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001701 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01001702 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001703
1704 switch (field_type) {
1705 case Primitive::kPrimBoolean:
1706 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001707 ByteRegister value = locations->InAt(1).As<ByteRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001708 __ movb(Address(obj, offset), value);
1709 break;
1710 }
1711
1712 case Primitive::kPrimShort:
1713 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001714 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001715 __ movw(Address(obj, offset), value);
1716 break;
1717 }
1718
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001719 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001720 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001721 Register value = locations->InAt(1).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001722 __ movl(Address(obj, offset), value);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001723
1724 if (field_type == Primitive::kPrimNot) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001725 Register temp = locations->GetTemp(0).As<Register>();
1726 Register card = locations->GetTemp(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001727 codegen_->MarkGCCard(temp, card, obj, value);
1728 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001729 break;
1730 }
1731
1732 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001733 Location value = locations->InAt(1);
1734 __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>());
1735 __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001736 break;
1737 }
1738
1739 case Primitive::kPrimFloat:
1740 case Primitive::kPrimDouble:
1741 LOG(FATAL) << "Unimplemented register type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001742 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001743 case Primitive::kPrimVoid:
1744 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07001745 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001746 }
1747}
1748
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001749void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) {
1750 Label is_null;
1751 __ testl(value, value);
1752 __ j(kEqual, &is_null);
1753 __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value()));
1754 __ movl(temp, object);
1755 __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift));
1756 __ movb(Address(temp, card, TIMES_1, 0),
1757 X86ManagedRegister::FromCpuRegister(card).AsByteRegister());
1758 __ Bind(&is_null);
1759}
1760
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001761void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001762 LocationSummary* locations =
1763 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001764 locations->SetInAt(0, Location::RequiresRegister());
1765 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001766}
1767
1768void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
1769 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001770 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001771 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
1772
1773 switch (instruction->GetType()) {
1774 case Primitive::kPrimBoolean: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001775 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001776 __ movzxb(out, Address(obj, offset));
1777 break;
1778 }
1779
1780 case Primitive::kPrimByte: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001781 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001782 __ movsxb(out, Address(obj, offset));
1783 break;
1784 }
1785
1786 case Primitive::kPrimShort: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001787 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001788 __ movsxw(out, Address(obj, offset));
1789 break;
1790 }
1791
1792 case Primitive::kPrimChar: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001793 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001794 __ movzxw(out, Address(obj, offset));
1795 break;
1796 }
1797
1798 case Primitive::kPrimInt:
1799 case Primitive::kPrimNot: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001800 Register out = locations->Out().As<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001801 __ movl(out, Address(obj, offset));
1802 break;
1803 }
1804
1805 case Primitive::kPrimLong: {
1806 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001807 __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset));
1808 __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001809 break;
1810 }
1811
1812 case Primitive::kPrimFloat:
1813 case Primitive::kPrimDouble:
1814 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001815 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001816 case Primitive::kPrimVoid:
1817 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001818 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001819 }
1820}
1821
1822void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001823 LocationSummary* locations =
1824 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001825 locations->SetInAt(0, Location::Any());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001826 if (instruction->HasUses()) {
1827 locations->SetOut(Location::SameAsFirstInput());
1828 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001829}
1830
1831void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01001832 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001833 codegen_->AddSlowPath(slow_path);
1834
1835 LocationSummary* locations = instruction->GetLocations();
1836 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001837
1838 if (obj.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001839 __ cmpl(obj.As<Register>(), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001840 } else if (obj.IsStackSlot()) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001841 __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001842 } else {
1843 DCHECK(obj.IsConstant()) << obj;
1844 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
1845 __ jmp(slow_path->GetEntryLabel());
1846 return;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01001847 }
1848 __ j(kEqual, slow_path->GetEntryLabel());
1849}
1850
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001851void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001852 LocationSummary* locations =
1853 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001854 locations->SetInAt(0, Location::RequiresRegister());
1855 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
1856 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001857}
1858
1859void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) {
1860 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001861 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001862 Location index = locations->InAt(1);
1863
1864 switch (instruction->GetType()) {
1865 case Primitive::kPrimBoolean: {
1866 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001867 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001868 if (index.IsConstant()) {
1869 __ movzxb(out, Address(obj,
1870 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1871 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001872 __ movzxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001873 }
1874 break;
1875 }
1876
1877 case Primitive::kPrimByte: {
1878 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001879 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001880 if (index.IsConstant()) {
1881 __ movsxb(out, Address(obj,
1882 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
1883 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001884 __ movsxb(out, Address(obj, index.As<Register>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001885 }
1886 break;
1887 }
1888
1889 case Primitive::kPrimShort: {
1890 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001891 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001892 if (index.IsConstant()) {
1893 __ movsxw(out, Address(obj,
1894 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1895 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001896 __ movsxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001897 }
1898 break;
1899 }
1900
1901 case Primitive::kPrimChar: {
1902 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001903 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001904 if (index.IsConstant()) {
1905 __ movzxw(out, Address(obj,
1906 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
1907 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001908 __ movzxw(out, Address(obj, index.As<Register>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001909 }
1910 break;
1911 }
1912
1913 case Primitive::kPrimInt:
1914 case Primitive::kPrimNot: {
1915 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001916 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001917 if (index.IsConstant()) {
1918 __ movl(out, Address(obj,
1919 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
1920 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001921 __ movl(out, Address(obj, index.As<Register>(), TIMES_4, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001922 }
1923 break;
1924 }
1925
1926 case Primitive::kPrimLong: {
1927 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001928 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001929 if (index.IsConstant()) {
1930 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001931 __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset));
1932 __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001933 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001934 __ movl(out.AsRegisterPairLow<Register>(),
1935 Address(obj, index.As<Register>(), TIMES_8, data_offset));
1936 __ movl(out.AsRegisterPairHigh<Register>(),
1937 Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001938 }
1939 break;
1940 }
1941
1942 case Primitive::kPrimFloat:
1943 case Primitive::kPrimDouble:
1944 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001945 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001946 case Primitive::kPrimVoid:
1947 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07001948 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001949 }
1950}
1951
1952void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001953 Primitive::Type value_type = instruction->GetComponentType();
1954 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
1955 instruction,
1956 value_type == Primitive::kPrimNot ? LocationSummary::kCall : LocationSummary::kNoCall);
1957
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001958 if (value_type == Primitive::kPrimNot) {
1959 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001960 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
1961 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
1962 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001963 } else {
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01001964 bool is_byte_type = (value_type == Primitive::kPrimBoolean)
1965 || (value_type == Primitive::kPrimByte);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01001966 // We need the inputs to be different than the output in case of long operation.
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01001967 // In case of a byte operation, the register allocator does not support multiple
1968 // inputs that die at entry with one in a specific register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001969 locations->SetInAt(0, Location::RequiresRegister());
1970 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01001971 if (is_byte_type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001972 // Ensure the value is in a byte register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001973 locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001974 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01001975 locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001976 }
1977 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001978}
1979
1980void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) {
1981 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001982 Register obj = locations->InAt(0).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001983 Location index = locations->InAt(1);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001984 Location value = locations->InAt(2);
Nicolas Geoffray39468442014-09-02 15:17:15 +01001985 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001986
1987 switch (value_type) {
1988 case Primitive::kPrimBoolean:
1989 case Primitive::kPrimByte: {
1990 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001991 if (index.IsConstant()) {
1992 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001993 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001994 __ movb(Address(obj, offset), value.As<ByteRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01001995 } else {
1996 __ movb(Address(obj, offset),
1997 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
1998 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01001999 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002000 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002001 __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset),
2002 value.As<ByteRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002003 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002004 __ movb(Address(obj, index.As<Register>(), TIMES_1, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002005 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2006 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002007 }
2008 break;
2009 }
2010
2011 case Primitive::kPrimShort:
2012 case Primitive::kPrimChar: {
2013 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002014 if (index.IsConstant()) {
2015 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002016 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002017 __ movw(Address(obj, offset), value.As<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002018 } else {
2019 __ movw(Address(obj, offset),
2020 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2021 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002022 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002023 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002024 __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset),
2025 value.As<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002026 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002027 __ movw(Address(obj, index.As<Register>(), TIMES_2, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002028 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2029 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002030 }
2031 break;
2032 }
2033
2034 case Primitive::kPrimInt: {
2035 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002036 if (index.IsConstant()) {
2037 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002038 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002039 __ movl(Address(obj, offset), value.As<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002040 } else {
2041 __ movl(Address(obj, offset), Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2042 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002043 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002044 if (value.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002045 __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset),
2046 value.As<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002047 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002048 __ movl(Address(obj, index.As<Register>(), TIMES_4, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002049 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2050 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002051 }
2052 break;
2053 }
2054
2055 case Primitive::kPrimNot: {
2056 DCHECK(!codegen_->IsLeafMethod());
2057 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject)));
Nicolas Geoffray39468442014-09-02 15:17:15 +01002058 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002059 break;
2060 }
2061
2062 case Primitive::kPrimLong: {
2063 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002064 if (index.IsConstant()) {
2065 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002066 if (value.IsRegisterPair()) {
2067 __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>());
2068 __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002069 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002070 DCHECK(value.IsConstant());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002071 int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
2072 __ movl(Address(obj, offset), Immediate(Low32Bits(val)));
2073 __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val)));
2074 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002075 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002076 if (value.IsRegisterPair()) {
2077 __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset),
2078 value.AsRegisterPairLow<Register>());
2079 __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize),
2080 value.AsRegisterPairHigh<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002081 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002082 DCHECK(value.IsConstant());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002083 int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002084 __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002085 Immediate(Low32Bits(val)));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002086 __ movl(Address(obj, index.As<Register>(), TIMES_8, data_offset + kX86WordSize),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002087 Immediate(High32Bits(val)));
2088 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002089 }
2090 break;
2091 }
2092
2093 case Primitive::kPrimFloat:
2094 case Primitive::kPrimDouble:
2095 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002096 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002097 case Primitive::kPrimVoid:
2098 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002099 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002100 }
2101}
2102
2103void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) {
2104 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002105 locations->SetInAt(0, Location::RequiresRegister());
2106 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002107 instruction->SetLocations(locations);
2108}
2109
2110void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) {
2111 LocationSummary* locations = instruction->GetLocations();
2112 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002113 Register obj = locations->InAt(0).As<Register>();
2114 Register out = locations->Out().As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002115 __ movl(out, Address(obj, offset));
2116}
2117
2118void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002119 LocationSummary* locations =
2120 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002121 locations->SetInAt(0, Location::RequiresRegister());
2122 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002123 if (instruction->HasUses()) {
2124 locations->SetOut(Location::SameAsFirstInput());
2125 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002126}
2127
2128void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) {
2129 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002130 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(
Nicolas Geoffray39468442014-09-02 15:17:15 +01002131 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002132 codegen_->AddSlowPath(slow_path);
2133
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002134 Register index = locations->InAt(0).As<Register>();
2135 Register length = locations->InAt(1).As<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002136
2137 __ cmpl(index, length);
2138 __ j(kAboveEqual, slow_path->GetEntryLabel());
2139}
2140
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002141void LocationsBuilderX86::VisitTemporary(HTemporary* temp) {
2142 temp->SetLocations(nullptr);
2143}
2144
2145void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) {
2146 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002147 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002148}
2149
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002150void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002151 UNUSED(instruction);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002152 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002153}
2154
2155void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002156 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
2157}
2158
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002159void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) {
2160 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
2161}
2162
2163void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002164 HBasicBlock* block = instruction->GetBlock();
2165 if (block->GetLoopInformation() != nullptr) {
2166 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
2167 // The back edge will generate the suspend check.
2168 return;
2169 }
2170 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
2171 // The goto will generate the suspend check.
2172 return;
2173 }
2174 GenerateSuspendCheck(instruction, nullptr);
2175}
2176
2177void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction,
2178 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002179 SuspendCheckSlowPathX86* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002180 new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002181 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002182 __ fs()->cmpw(Address::Absolute(
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002183 Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01002184 if (successor == nullptr) {
2185 __ j(kNotEqual, slow_path->GetEntryLabel());
2186 __ Bind(slow_path->GetReturnLabel());
2187 } else {
2188 __ j(kEqual, codegen_->GetLabelOf(successor));
2189 __ jmp(slow_path->GetEntryLabel());
2190 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002191}
2192
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002193X86Assembler* ParallelMoveResolverX86::GetAssembler() const {
2194 return codegen_->GetAssembler();
2195}
2196
2197void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) {
2198 ScratchRegisterScope ensure_scratch(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002199 this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002200 int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0;
2201 __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset));
2202 __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister()));
2203}
2204
2205void ParallelMoveResolverX86::EmitMove(size_t index) {
2206 MoveOperands* move = moves_.Get(index);
2207 Location source = move->GetSource();
2208 Location destination = move->GetDestination();
2209
2210 if (source.IsRegister()) {
2211 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002212 __ movl(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002213 } else {
2214 DCHECK(destination.IsStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002215 __ movl(Address(ESP, destination.GetStackIndex()), source.As<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002216 }
2217 } else if (source.IsStackSlot()) {
2218 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002219 __ movl(destination.As<Register>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002220 } else {
2221 DCHECK(destination.IsStackSlot());
2222 MoveMemoryToMemory(destination.GetStackIndex(),
2223 source.GetStackIndex());
2224 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002225 } else if (source.IsConstant()) {
2226 HIntConstant* instruction = source.GetConstant()->AsIntConstant();
2227 Immediate imm(instruction->AsIntConstant()->GetValue());
2228 if (destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002229 __ movl(destination.As<Register>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002230 } else {
2231 __ movl(Address(ESP, destination.GetStackIndex()), imm);
2232 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002233 } else {
2234 LOG(FATAL) << "Unimplemented";
2235 }
2236}
2237
2238void ParallelMoveResolverX86::Exchange(Register reg, int mem) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002239 Register suggested_scratch = reg == EAX ? EBX : EAX;
2240 ScratchRegisterScope ensure_scratch(
2241 this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters());
2242
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002243 int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0;
2244 __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset));
2245 __ movl(Address(ESP, mem + stack_offset), reg);
2246 __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister()));
2247}
2248
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002249void ParallelMoveResolverX86::Exchange(int mem1, int mem2) {
2250 ScratchRegisterScope ensure_scratch1(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002251 this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters());
2252
2253 Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002254 ScratchRegisterScope ensure_scratch2(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01002255 this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters());
2256
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002257 int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0;
2258 stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0;
2259 __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset));
2260 __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset));
2261 __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister()));
2262 __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister()));
2263}
2264
2265void ParallelMoveResolverX86::EmitSwap(size_t index) {
2266 MoveOperands* move = moves_.Get(index);
2267 Location source = move->GetSource();
2268 Location destination = move->GetDestination();
2269
2270 if (source.IsRegister() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002271 __ xchgl(destination.As<Register>(), source.As<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002272 } else if (source.IsRegister() && destination.IsStackSlot()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002273 Exchange(source.As<Register>(), destination.GetStackIndex());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002274 } else if (source.IsStackSlot() && destination.IsRegister()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002275 Exchange(destination.As<Register>(), source.GetStackIndex());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002276 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
2277 Exchange(destination.GetStackIndex(), source.GetStackIndex());
2278 } else {
2279 LOG(FATAL) << "Unimplemented";
2280 }
2281}
2282
2283void ParallelMoveResolverX86::SpillScratch(int reg) {
2284 __ pushl(static_cast<Register>(reg));
2285}
2286
2287void ParallelMoveResolverX86::RestoreScratch(int reg) {
2288 __ popl(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01002289}
2290
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002291void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002292 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
2293 ? LocationSummary::kCallOnSlowPath
2294 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002295 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002296 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002297 locations->SetOut(Location::RequiresRegister());
2298}
2299
2300void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) {
2301 Register out = cls->GetLocations()->Out().As<Register>();
2302 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002303 DCHECK(!cls->CanCallRuntime());
2304 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002305 codegen_->LoadCurrentMethod(out);
2306 __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()));
2307 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002308 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002309 codegen_->LoadCurrentMethod(out);
2310 __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()));
2311 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002312
2313 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86(
2314 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
2315 codegen_->AddSlowPath(slow_path);
2316 __ testl(out, out);
2317 __ j(kEqual, slow_path->GetEntryLabel());
2318 if (cls->MustGenerateClinitCheck()) {
2319 GenerateClassInitializationCheck(slow_path, out);
2320 } else {
2321 __ Bind(slow_path->GetExitLabel());
2322 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002323 }
2324}
2325
2326void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) {
2327 LocationSummary* locations =
2328 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
2329 locations->SetInAt(0, Location::RequiresRegister());
2330 if (check->HasUses()) {
2331 locations->SetOut(Location::SameAsFirstInput());
2332 }
2333}
2334
2335void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002336 // We assume the class to not be null.
2337 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86(
2338 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002339 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002340 GenerateClassInitializationCheck(slow_path, check->GetLocations()->InAt(0).As<Register>());
2341}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002342
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002343void InstructionCodeGeneratorX86::GenerateClassInitializationCheck(
2344 SlowPathCodeX86* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002345 __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()),
2346 Immediate(mirror::Class::kStatusInitialized));
2347 __ j(kLess, slow_path->GetEntryLabel());
2348 __ Bind(slow_path->GetExitLabel());
2349 // No need for memory fence, thanks to the X86 memory model.
2350}
2351
2352void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2353 LocationSummary* locations =
2354 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2355 locations->SetInAt(0, Location::RequiresRegister());
2356 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2357}
2358
2359void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) {
2360 LocationSummary* locations = instruction->GetLocations();
2361 Register cls = locations->InAt(0).As<Register>();
2362 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2363
2364 switch (instruction->GetType()) {
2365 case Primitive::kPrimBoolean: {
2366 Register out = locations->Out().As<Register>();
2367 __ movzxb(out, Address(cls, offset));
2368 break;
2369 }
2370
2371 case Primitive::kPrimByte: {
2372 Register out = locations->Out().As<Register>();
2373 __ movsxb(out, Address(cls, offset));
2374 break;
2375 }
2376
2377 case Primitive::kPrimShort: {
2378 Register out = locations->Out().As<Register>();
2379 __ movsxw(out, Address(cls, offset));
2380 break;
2381 }
2382
2383 case Primitive::kPrimChar: {
2384 Register out = locations->Out().As<Register>();
2385 __ movzxw(out, Address(cls, offset));
2386 break;
2387 }
2388
2389 case Primitive::kPrimInt:
2390 case Primitive::kPrimNot: {
2391 Register out = locations->Out().As<Register>();
2392 __ movl(out, Address(cls, offset));
2393 break;
2394 }
2395
2396 case Primitive::kPrimLong: {
2397 // TODO: support volatile.
2398 __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset));
2399 __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset));
2400 break;
2401 }
2402
2403 case Primitive::kPrimFloat:
2404 case Primitive::kPrimDouble:
2405 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
2406 UNREACHABLE();
2407 case Primitive::kPrimVoid:
2408 LOG(FATAL) << "Unreachable type " << instruction->GetType();
2409 UNREACHABLE();
2410 }
2411}
2412
2413void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2414 LocationSummary* locations =
2415 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
2416 locations->SetInAt(0, Location::RequiresRegister());
2417 Primitive::Type field_type = instruction->GetFieldType();
2418 bool is_object_type = field_type == Primitive::kPrimNot;
2419 bool is_byte_type = (field_type == Primitive::kPrimBoolean)
2420 || (field_type == Primitive::kPrimByte);
2421 // The register allocator does not support multiple
2422 // inputs that die at entry with one in a specific register.
2423 if (is_byte_type) {
2424 // Ensure the value is in a byte register.
2425 locations->SetInAt(1, Location::RegisterLocation(EAX));
2426 } else {
2427 locations->SetInAt(1, Location::RequiresRegister());
2428 }
2429 // Temporary registers for the write barrier.
2430 if (is_object_type) {
2431 locations->AddTemp(Location::RequiresRegister());
2432 // Ensure the card is in a byte register.
2433 locations->AddTemp(Location::RegisterLocation(ECX));
2434 }
2435}
2436
2437void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) {
2438 LocationSummary* locations = instruction->GetLocations();
2439 Register cls = locations->InAt(0).As<Register>();
2440 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2441 Primitive::Type field_type = instruction->GetFieldType();
2442
2443 switch (field_type) {
2444 case Primitive::kPrimBoolean:
2445 case Primitive::kPrimByte: {
2446 ByteRegister value = locations->InAt(1).As<ByteRegister>();
2447 __ movb(Address(cls, offset), value);
2448 break;
2449 }
2450
2451 case Primitive::kPrimShort:
2452 case Primitive::kPrimChar: {
2453 Register value = locations->InAt(1).As<Register>();
2454 __ movw(Address(cls, offset), value);
2455 break;
2456 }
2457
2458 case Primitive::kPrimInt:
2459 case Primitive::kPrimNot: {
2460 Register value = locations->InAt(1).As<Register>();
2461 __ movl(Address(cls, offset), value);
2462
2463 if (field_type == Primitive::kPrimNot) {
2464 Register temp = locations->GetTemp(0).As<Register>();
2465 Register card = locations->GetTemp(1).As<Register>();
2466 codegen_->MarkGCCard(temp, card, cls, value);
2467 }
2468 break;
2469 }
2470
2471 case Primitive::kPrimLong: {
2472 Location value = locations->InAt(1);
2473 __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>());
2474 __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>());
2475 break;
2476 }
2477
2478 case Primitive::kPrimFloat:
2479 case Primitive::kPrimDouble:
2480 LOG(FATAL) << "Unimplemented register type " << field_type;
2481 UNREACHABLE();
2482 case Primitive::kPrimVoid:
2483 LOG(FATAL) << "Unreachable type " << field_type;
2484 UNREACHABLE();
2485 }
2486}
2487
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002488void LocationsBuilderX86::VisitLoadString(HLoadString* load) {
2489 LocationSummary* locations =
2490 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
2491 locations->SetOut(Location::RequiresRegister());
2492}
2493
2494void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) {
2495 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load);
2496 codegen_->AddSlowPath(slow_path);
2497
2498 Register out = load->GetLocations()->Out().As<Register>();
2499 codegen_->LoadCurrentMethod(out);
2500 __ movl(out, Address(out, mirror::ArtMethod::DexCacheStringsOffset().Int32Value()));
2501 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
2502 __ testl(out, out);
2503 __ j(kEqual, slow_path->GetEntryLabel());
2504 __ Bind(slow_path->GetExitLabel());
2505}
2506
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00002507} // namespace x86
2508} // namespace art