blob: 705065d600368e107d1befaa5ebbc6c167f13e21 [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
Calin Juravled6fb6cf2014-11-11 19:07:44 +000039static constexpr Register kRuntimeParameterCoreRegisters[] = { EAX, ECX, EDX, EBX };
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010040static 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 Geoffrayaf07bc12014-11-12 18:08:09 +000045// Marker for places that can be updated once we don't follow the quick ABI.
46static constexpr bool kFollowsQuickABI = true;
47
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010048class InvokeRuntimeCallingConvention : public CallingConvention<Register, XmmRegister> {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010049 public:
50 InvokeRuntimeCallingConvention()
51 : CallingConvention(kRuntimeParameterCoreRegisters,
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +010052 kRuntimeParameterCoreRegistersLength,
53 kRuntimeParameterFpuRegisters,
54 kRuntimeParameterFpuRegistersLength) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +010055
56 private:
57 DISALLOW_COPY_AND_ASSIGN(InvokeRuntimeCallingConvention);
58};
59
Nicolas Geoffraye5038322014-07-04 09:41:32 +010060#define __ reinterpret_cast<X86Assembler*>(codegen->GetAssembler())->
61
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +010062class SlowPathCodeX86 : public SlowPathCode {
63 public:
64 SlowPathCodeX86() : entry_label_(), exit_label_() {}
65
66 Label* GetEntryLabel() { return &entry_label_; }
67 Label* GetExitLabel() { return &exit_label_; }
68
69 private:
70 Label entry_label_;
71 Label exit_label_;
72
73 DISALLOW_COPY_AND_ASSIGN(SlowPathCodeX86);
74};
75
76class NullCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffraye5038322014-07-04 09:41:32 +010077 public:
Nicolas Geoffray39468442014-09-02 15:17:15 +010078 explicit NullCheckSlowPathX86(HNullCheck* instruction) : instruction_(instruction) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +010079
80 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
81 __ Bind(GetEntryLabel());
82 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowNullPointer)));
Nicolas Geoffray39468442014-09-02 15:17:15 +010083 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffraye5038322014-07-04 09:41:32 +010084 }
85
86 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +010087 HNullCheck* const instruction_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +010088 DISALLOW_COPY_AND_ASSIGN(NullCheckSlowPathX86);
89};
90
Calin Juravled0d48522014-11-04 16:40:20 +000091class DivZeroCheckSlowPathX86 : public SlowPathCodeX86 {
92 public:
93 explicit DivZeroCheckSlowPathX86(HDivZeroCheck* instruction) : instruction_(instruction) {}
94
95 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
96 __ Bind(GetEntryLabel());
97 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowDivZero)));
98 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
99 }
100
101 private:
102 HDivZeroCheck* const instruction_;
103 DISALLOW_COPY_AND_ASSIGN(DivZeroCheckSlowPathX86);
104};
105
Calin Juravlebacfec32014-11-14 15:54:36 +0000106class DivRemMinusOneSlowPathX86 : public SlowPathCodeX86 {
Calin Juravled0d48522014-11-04 16:40:20 +0000107 public:
Calin Juravlebacfec32014-11-14 15:54:36 +0000108 explicit DivRemMinusOneSlowPathX86(Register reg, bool is_div) : reg_(reg), is_div_(is_div) {}
Calin Juravled0d48522014-11-04 16:40:20 +0000109
110 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
111 __ Bind(GetEntryLabel());
Calin Juravlebacfec32014-11-14 15:54:36 +0000112 if (is_div_) {
113 __ negl(reg_);
114 } else {
115 __ movl(reg_, Immediate(0));
116 }
Calin Juravled0d48522014-11-04 16:40:20 +0000117 __ jmp(GetExitLabel());
118 }
119
120 private:
121 Register reg_;
Calin Juravlebacfec32014-11-14 15:54:36 +0000122 bool is_div_;
123 DISALLOW_COPY_AND_ASSIGN(DivRemMinusOneSlowPathX86);
Calin Juravled0d48522014-11-04 16:40:20 +0000124};
125
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100126class StackOverflowCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100127 public:
128 StackOverflowCheckSlowPathX86() {}
129
130 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
131 __ Bind(GetEntryLabel());
132 __ addl(ESP,
133 Immediate(codegen->GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
134 __ fs()->jmp(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowStackOverflow)));
135 }
136
137 private:
138 DISALLOW_COPY_AND_ASSIGN(StackOverflowCheckSlowPathX86);
139};
140
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100141class BoundsCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100142 public:
Roland Levillain5799fc02014-09-25 12:15:20 +0100143 BoundsCheckSlowPathX86(HBoundsCheck* instruction,
144 Location index_location,
145 Location length_location)
Roland Levillain199f3362014-11-27 17:15:16 +0000146 : instruction_(instruction),
147 index_location_(index_location),
148 length_location_(length_location) {}
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100149
150 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100151 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100152 __ Bind(GetEntryLabel());
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000153 // We're moving two locations to locations that could overlap, so we need a parallel
154 // move resolver.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100155 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000156 x86_codegen->EmitParallelMoves(
157 index_location_,
158 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
159 length_location_,
160 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100161 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pThrowArrayBounds)));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100162 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100163 }
164
165 private:
Nicolas Geoffray39468442014-09-02 15:17:15 +0100166 HBoundsCheck* const instruction_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +0100167 const Location index_location_;
168 const Location length_location_;
169
170 DISALLOW_COPY_AND_ASSIGN(BoundsCheckSlowPathX86);
171};
172
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100173class SuspendCheckSlowPathX86 : public SlowPathCodeX86 {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000174 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100175 explicit SuspendCheckSlowPathX86(HSuspendCheck* instruction, HBasicBlock* successor)
176 : instruction_(instruction), successor_(successor) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000177
178 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100179 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000180 __ Bind(GetEntryLabel());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100181 codegen->SaveLiveRegisters(instruction_->GetLocations());
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000182 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pTestSuspend)));
183 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100184 codegen->RestoreLiveRegisters(instruction_->GetLocations());
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100185 if (successor_ == nullptr) {
186 __ jmp(GetReturnLabel());
187 } else {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100188 __ jmp(x86_codegen->GetLabelOf(successor_));
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100189 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000190 }
191
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100192 Label* GetReturnLabel() {
193 DCHECK(successor_ == nullptr);
194 return &return_label_;
195 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000196
197 private:
198 HSuspendCheck* const instruction_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100199 HBasicBlock* const successor_;
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +0000200 Label return_label_;
201
202 DISALLOW_COPY_AND_ASSIGN(SuspendCheckSlowPathX86);
203};
204
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000205class LoadStringSlowPathX86 : public SlowPathCodeX86 {
206 public:
207 explicit LoadStringSlowPathX86(HLoadString* instruction) : instruction_(instruction) {}
208
209 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
210 LocationSummary* locations = instruction_->GetLocations();
211 DCHECK(!locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
212
213 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
214 __ Bind(GetEntryLabel());
215 codegen->SaveLiveRegisters(locations);
216
217 InvokeRuntimeCallingConvention calling_convention;
218 x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(0));
219 __ movl(calling_convention.GetRegisterAt(1), Immediate(instruction_->GetStringIndex()));
220 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pResolveString)));
221 codegen->RecordPcInfo(instruction_, instruction_->GetDexPc());
222 x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX));
223 codegen->RestoreLiveRegisters(locations);
224
225 __ jmp(GetExitLabel());
226 }
227
228 private:
229 HLoadString* const instruction_;
230
231 DISALLOW_COPY_AND_ASSIGN(LoadStringSlowPathX86);
232};
233
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000234class LoadClassSlowPathX86 : public SlowPathCodeX86 {
235 public:
236 LoadClassSlowPathX86(HLoadClass* cls,
237 HInstruction* at,
238 uint32_t dex_pc,
239 bool do_clinit)
240 : cls_(cls), at_(at), dex_pc_(dex_pc), do_clinit_(do_clinit) {
241 DCHECK(at->IsLoadClass() || at->IsClinitCheck());
242 }
243
244 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
245 LocationSummary* locations = at_->GetLocations();
246 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
247 __ Bind(GetEntryLabel());
248 codegen->SaveLiveRegisters(locations);
249
250 InvokeRuntimeCallingConvention calling_convention;
251 __ movl(calling_convention.GetRegisterAt(0), Immediate(cls_->GetTypeIndex()));
252 x86_codegen->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
253 __ fs()->call(Address::Absolute(do_clinit_
254 ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeStaticStorage)
255 : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pInitializeType)));
256 codegen->RecordPcInfo(at_, dex_pc_);
257
258 // Move the class to the desired location.
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000259 Location out = locations->Out();
260 if (out.IsValid()) {
261 DCHECK(out.IsRegister() && !locations->GetLiveRegisters()->ContainsCoreRegister(out.reg()));
262 x86_codegen->Move32(out, Location::RegisterLocation(EAX));
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000263 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000264
Nicolas Geoffray424f6762014-11-03 14:51:25 +0000265 codegen->RestoreLiveRegisters(locations);
266 __ jmp(GetExitLabel());
267 }
268
269 private:
270 // The class this slow path will load.
271 HLoadClass* const cls_;
272
273 // The instruction where this slow path is happening.
274 // (Might be the load class or an initialization check).
275 HInstruction* const at_;
276
277 // The dex PC of `at_`.
278 const uint32_t dex_pc_;
279
280 // Whether to initialize the class.
281 const bool do_clinit_;
282
283 DISALLOW_COPY_AND_ASSIGN(LoadClassSlowPathX86);
284};
285
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000286class TypeCheckSlowPathX86 : public SlowPathCodeX86 {
287 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000288 TypeCheckSlowPathX86(HInstruction* instruction,
289 Location class_to_check,
290 Location object_class,
291 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000292 : instruction_(instruction),
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000293 class_to_check_(class_to_check),
294 object_class_(object_class),
295 dex_pc_(dex_pc) {}
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000296
297 virtual void EmitNativeCode(CodeGenerator* codegen) OVERRIDE {
298 LocationSummary* locations = instruction_->GetLocations();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000299 DCHECK(instruction_->IsCheckCast()
300 || !locations->GetLiveRegisters()->ContainsCoreRegister(locations->Out().reg()));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000301
302 CodeGeneratorX86* x86_codegen = down_cast<CodeGeneratorX86*>(codegen);
303 __ Bind(GetEntryLabel());
304 codegen->SaveLiveRegisters(locations);
305
306 // We're moving two locations to locations that could overlap, so we need a parallel
307 // move resolver.
308 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffrayf0e39372014-11-12 17:50:07 +0000309 x86_codegen->EmitParallelMoves(
310 class_to_check_,
311 Location::RegisterLocation(calling_convention.GetRegisterAt(0)),
312 object_class_,
313 Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000314
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000315 if (instruction_->IsInstanceOf()) {
Roland Levillain199f3362014-11-27 17:15:16 +0000316 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize,
317 pInstanceofNonTrivial)));
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000318 } else {
319 DCHECK(instruction_->IsCheckCast());
320 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pCheckCast)));
321 }
322
323 codegen->RecordPcInfo(instruction_, dex_pc_);
324 if (instruction_->IsInstanceOf()) {
325 x86_codegen->Move32(locations->Out(), Location::RegisterLocation(EAX));
326 }
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000327 codegen->RestoreLiveRegisters(locations);
328
329 __ jmp(GetExitLabel());
330 }
331
332 private:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000333 HInstruction* const instruction_;
334 const Location class_to_check_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000335 const Location object_class_;
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000336 const uint32_t dex_pc_;
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +0000337
338 DISALLOW_COPY_AND_ASSIGN(TypeCheckSlowPathX86);
339};
340
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100341#undef __
342#define __ reinterpret_cast<X86Assembler*>(GetAssembler())->
343
Dave Allison20dfc792014-06-16 20:44:29 -0700344inline Condition X86Condition(IfCondition cond) {
345 switch (cond) {
346 case kCondEQ: return kEqual;
347 case kCondNE: return kNotEqual;
348 case kCondLT: return kLess;
349 case kCondLE: return kLessEqual;
350 case kCondGT: return kGreater;
351 case kCondGE: return kGreaterEqual;
352 default:
353 LOG(FATAL) << "Unknown if condition";
354 }
355 return kEqual;
356}
357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100358void CodeGeneratorX86::DumpCoreRegister(std::ostream& stream, int reg) const {
359 stream << X86ManagedRegister::FromCpuRegister(Register(reg));
360}
361
362void CodeGeneratorX86::DumpFloatingPointRegister(std::ostream& stream, int reg) const {
363 stream << X86ManagedRegister::FromXmmRegister(XmmRegister(reg));
364}
365
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100366size_t CodeGeneratorX86::SaveCoreRegister(size_t stack_index, uint32_t reg_id) {
367 __ movl(Address(ESP, stack_index), static_cast<Register>(reg_id));
368 return kX86WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100369}
370
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100371size_t CodeGeneratorX86::RestoreCoreRegister(size_t stack_index, uint32_t reg_id) {
372 __ movl(static_cast<Register>(reg_id), Address(ESP, stack_index));
373 return kX86WordSize;
Nicolas Geoffray3bca0df2014-09-19 11:01:00 +0100374}
375
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100376CodeGeneratorX86::CodeGeneratorX86(HGraph* graph)
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100377 : CodeGenerator(graph, kNumberOfCpuRegisters, kNumberOfXmmRegisters, kNumberOfRegisterPairs),
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100378 block_labels_(graph->GetArena(), 0),
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100379 location_builder_(graph, this),
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100380 instruction_visitor_(graph, this),
381 move_resolver_(graph->GetArena(), this) {}
382
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100383size_t CodeGeneratorX86::FrameEntrySpillSize() const {
384 return kNumberOfPushedRegistersAtEntry * kX86WordSize;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100385}
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100386
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100387Location CodeGeneratorX86::AllocateFreeRegister(Primitive::Type type) const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100388 switch (type) {
389 case Primitive::kPrimLong: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100390 size_t reg = FindFreeEntry(blocked_register_pairs_, kNumberOfRegisterPairs);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100391 X86ManagedRegister pair =
392 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(reg));
Calin Juravle34bacdf2014-10-07 20:23:36 +0100393 DCHECK(!blocked_core_registers_[pair.AsRegisterPairLow()]);
394 DCHECK(!blocked_core_registers_[pair.AsRegisterPairHigh()]);
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100395 blocked_core_registers_[pair.AsRegisterPairLow()] = true;
396 blocked_core_registers_[pair.AsRegisterPairHigh()] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100397 UpdateBlockedPairRegisters();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100398 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100399 }
400
401 case Primitive::kPrimByte:
402 case Primitive::kPrimBoolean:
403 case Primitive::kPrimChar:
404 case Primitive::kPrimShort:
405 case Primitive::kPrimInt:
406 case Primitive::kPrimNot: {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100407 Register reg = static_cast<Register>(
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100408 FindFreeEntry(blocked_core_registers_, kNumberOfCpuRegisters));
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100409 // Block all register pairs that contain `reg`.
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100410 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
411 X86ManagedRegister current =
412 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
413 if (current.AsRegisterPairLow() == reg || current.AsRegisterPairHigh() == reg) {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100414 blocked_register_pairs_[i] = true;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100415 }
416 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100417 return Location::RegisterLocation(reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100418 }
419
420 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100421 case Primitive::kPrimDouble: {
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100422 return Location::FpuRegisterLocation(
423 FindFreeEntry(blocked_fpu_registers_, kNumberOfXmmRegisters));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100424 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100425
426 case Primitive::kPrimVoid:
427 LOG(FATAL) << "Unreachable type " << type;
428 }
429
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100430 return Location();
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100431}
432
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100433void CodeGeneratorX86::SetupBlockedRegisters() const {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100434 // Don't allocate the dalvik style register pair passing.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100435 blocked_register_pairs_[ECX_EDX] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100436
437 // Stack register is always reserved.
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100438 blocked_core_registers_[ESP] = true;
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100439
440 // TODO: We currently don't use Quick's callee saved registers.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +0000441 DCHECK(kFollowsQuickABI);
Nicolas Geoffray71175b72014-10-09 22:13:55 +0100442 blocked_core_registers_[EBP] = true;
443 blocked_core_registers_[ESI] = true;
444 blocked_core_registers_[EDI] = true;
Calin Juravle34bacdf2014-10-07 20:23:36 +0100445
446 UpdateBlockedPairRegisters();
447}
448
449void CodeGeneratorX86::UpdateBlockedPairRegisters() const {
450 for (int i = 0; i < kNumberOfRegisterPairs; i++) {
451 X86ManagedRegister current =
452 X86ManagedRegister::FromRegisterPair(static_cast<RegisterPair>(i));
453 if (blocked_core_registers_[current.AsRegisterPairLow()]
454 || blocked_core_registers_[current.AsRegisterPairHigh()]) {
455 blocked_register_pairs_[i] = true;
456 }
457 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100458}
459
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100460InstructionCodeGeneratorX86::InstructionCodeGeneratorX86(HGraph* graph, CodeGeneratorX86* codegen)
461 : HGraphVisitor(graph),
462 assembler_(codegen->GetAssembler()),
463 codegen_(codegen) {}
464
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000465void CodeGeneratorX86::GenerateFrameEntry() {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000466 // Create a fake register to mimic Quick.
467 static const int kFakeReturnRegister = 8;
468 core_spill_mask_ |= (1 << kFakeReturnRegister);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000469
Roland Levillain199f3362014-11-27 17:15:16 +0000470 bool skip_overflow_check =
471 IsLeafMethod() && !FrameNeedsStackCheck(GetFrameSize(), InstructionSet::kX86);
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100472 if (!skip_overflow_check && !kExplicitStackOverflowCheck) {
473 __ testl(EAX, Address(ESP, -static_cast<int32_t>(GetStackOverflowReservedBytes(kX86))));
Nicolas Geoffray39468442014-09-02 15:17:15 +0100474 RecordPcInfo(nullptr, 0);
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100475 }
476
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100477 // The return PC has already been pushed on the stack.
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100478 __ subl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100479
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100480 if (!skip_overflow_check && kExplicitStackOverflowCheck) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100481 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) StackOverflowCheckSlowPathX86();
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100482 AddSlowPath(slow_path);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100483
Nicolas Geoffray397f2e42014-07-23 12:57:19 +0100484 __ fs()->cmpl(ESP, Address::Absolute(Thread::StackEndOffset<kX86WordSize>()));
485 __ j(kLess, slow_path->GetEntryLabel());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100486 }
487
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100488 __ movl(Address(ESP, kCurrentMethodStackOffset), EAX);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000489}
490
491void CodeGeneratorX86::GenerateFrameExit() {
Nicolas Geoffray707c8092014-04-04 10:50:14 +0100492 __ addl(ESP, Immediate(GetFrameSize() - kNumberOfPushedRegistersAtEntry * kX86WordSize));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000493}
494
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +0100495void CodeGeneratorX86::Bind(HBasicBlock* block) {
496 __ Bind(GetLabelOf(block));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000497}
498
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100499void CodeGeneratorX86::LoadCurrentMethod(Register reg) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100500 __ movl(reg, Address(ESP, kCurrentMethodStackOffset));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000501}
502
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100503Location CodeGeneratorX86::GetStackLocation(HLoadLocal* load) const {
504 switch (load->GetType()) {
505 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100506 case Primitive::kPrimDouble:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100507 return Location::DoubleStackSlot(GetStackSlot(load->GetLocal()));
508 break;
509
510 case Primitive::kPrimInt:
511 case Primitive::kPrimNot:
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100512 case Primitive::kPrimFloat:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100513 return Location::StackSlot(GetStackSlot(load->GetLocal()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100514
515 case Primitive::kPrimBoolean:
516 case Primitive::kPrimByte:
517 case Primitive::kPrimChar:
518 case Primitive::kPrimShort:
519 case Primitive::kPrimVoid:
520 LOG(FATAL) << "Unexpected type " << load->GetType();
521 }
522
523 LOG(FATAL) << "Unreachable";
524 return Location();
525}
526
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100527Location InvokeDexCallingConventionVisitor::GetNextLocation(Primitive::Type type) {
528 switch (type) {
529 case Primitive::kPrimBoolean:
530 case Primitive::kPrimByte:
531 case Primitive::kPrimChar:
532 case Primitive::kPrimShort:
533 case Primitive::kPrimInt:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100534 case Primitive::kPrimFloat:
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100535 case Primitive::kPrimNot: {
536 uint32_t index = gp_index_++;
537 if (index < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100538 return Location::RegisterLocation(calling_convention.GetRegisterAt(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100539 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100540 return Location::StackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100541 }
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100542 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100543
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100544 case Primitive::kPrimLong:
545 case Primitive::kPrimDouble: {
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100546 uint32_t index = gp_index_;
547 gp_index_ += 2;
548 if (index + 1 < calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100549 X86ManagedRegister pair = X86ManagedRegister::FromRegisterPair(
550 calling_convention.GetRegisterPairAt(index));
551 return Location::RegisterPairLocation(pair.AsRegisterPairLow(), pair.AsRegisterPairHigh());
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100552 } else if (index + 1 == calling_convention.GetNumberOfRegisters()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000553 // On X86, the register index and stack index of a quick parameter is the same, since
554 // we are passing floating pointer values in core registers.
555 return Location::QuickParameter(index, index);
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100556 } else {
Nicolas Geoffray9cf35522014-06-09 18:40:10 +0100557 return Location::DoubleStackSlot(calling_convention.GetStackOffsetOf(index));
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100558 }
559 }
560
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100561 case Primitive::kPrimVoid:
562 LOG(FATAL) << "Unexpected parameter type " << type;
563 break;
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100564 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +0100565 return Location();
566}
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +0100567
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100568void CodeGeneratorX86::Move32(Location destination, Location source) {
569 if (source.Equals(destination)) {
570 return;
571 }
572 if (destination.IsRegister()) {
573 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000574 __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100575 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000576 __ movd(destination.AsRegister<Register>(), source.AsFpuRegister<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100577 } else {
578 DCHECK(source.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000579 __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100580 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100581 } else if (destination.IsFpuRegister()) {
582 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000583 __ movd(destination.AsFpuRegister<XmmRegister>(), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100584 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000585 __ movaps(destination.AsFpuRegister<XmmRegister>(), source.AsFpuRegister<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100586 } else {
587 DCHECK(source.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000588 __ movss(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100589 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100590 } else {
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000591 DCHECK(destination.IsStackSlot()) << destination;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100592 if (source.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000593 __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100594 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000595 __ movss(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100596 } else {
597 DCHECK(source.IsStackSlot());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +0100598 __ pushl(Address(ESP, source.GetStackIndex()));
599 __ popl(Address(ESP, destination.GetStackIndex()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100600 }
601 }
602}
603
604void CodeGeneratorX86::Move64(Location destination, Location source) {
605 if (source.Equals(destination)) {
606 return;
607 }
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100608 if (destination.IsRegisterPair()) {
609 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000610 EmitParallelMoves(
611 Location::RegisterLocation(source.AsRegisterPairHigh<Register>()),
612 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()),
613 Location::RegisterLocation(source.AsRegisterPairLow<Register>()),
614 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100615 } else if (source.IsFpuRegister()) {
616 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100617 } else if (source.IsQuickParameter()) {
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000618 uint16_t register_index = source.GetQuickParameterRegisterIndex();
619 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100620 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000621 EmitParallelMoves(
622 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
623 Location::RegisterLocation(destination.AsRegisterPairLow<Register>()),
624 Location::StackSlot(
625 calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize()),
626 Location::RegisterLocation(destination.AsRegisterPairHigh<Register>()));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100627 } else {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000628 // No conflict possible, so just do the moves.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100629 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100630 __ movl(destination.AsRegisterPairLow<Register>(), Address(ESP, source.GetStackIndex()));
631 __ movl(destination.AsRegisterPairHigh<Register>(),
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100632 Address(ESP, source.GetHighStackIndex(kX86WordSize)));
633 }
634 } else if (destination.IsQuickParameter()) {
635 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000636 uint16_t register_index = destination.GetQuickParameterRegisterIndex();
637 uint16_t stack_index = destination.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000638 if (source.IsRegisterPair()) {
639 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100640 } else if (source.IsFpuRegister()) {
641 LOG(FATAL) << "Unimplemented";
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100642 } else {
643 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000644 EmitParallelMoves(
645 Location::StackSlot(source.GetStackIndex()),
646 Location::RegisterLocation(calling_convention.GetRegisterAt(register_index)),
647 Location::StackSlot(source.GetHighStackIndex(kX86WordSize)),
648 Location::StackSlot(calling_convention.GetStackOffsetOf(stack_index + 1)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100649 }
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100650 } else if (destination.IsFpuRegister()) {
651 if (source.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000652 __ movsd(destination.AsFpuRegister<XmmRegister>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100653 } else {
654 LOG(FATAL) << "Unimplemented";
655 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100656 } else {
Calin Juravled6fb6cf2014-11-11 19:07:44 +0000657 DCHECK(destination.IsDoubleStackSlot()) << destination;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100658 if (source.IsRegisterPair()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000659 // No conflict possible, so just do the moves.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100660 __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegisterPairLow<Register>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100661 __ movl(Address(ESP, destination.GetHighStackIndex(kX86WordSize)),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +0100662 source.AsRegisterPairHigh<Register>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100663 } else if (source.IsQuickParameter()) {
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000664 // No conflict possible, so just do the move.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100665 InvokeDexCallingConvention calling_convention;
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000666 uint16_t register_index = source.GetQuickParameterRegisterIndex();
667 uint16_t stack_index = source.GetQuickParameterStackIndex();
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000668 // Just move the low part. The only time a source is a quick parameter is
669 // when moving the parameter to its stack locations. And the (Java) caller
670 // of this method has already done that.
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100671 __ movl(Address(ESP, destination.GetStackIndex()),
Nicolas Geoffray0a6c4592014-10-30 16:37:57 +0000672 calling_convention.GetRegisterAt(register_index));
673 DCHECK_EQ(calling_convention.GetStackOffsetOf(stack_index + 1) + GetFrameSize(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100674 static_cast<size_t>(destination.GetHighStackIndex(kX86WordSize)));
675 } else if (source.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000676 __ movsd(Address(ESP, destination.GetStackIndex()), source.AsFpuRegister<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100677 } else {
678 DCHECK(source.IsDoubleStackSlot());
Nicolas Geoffray32b2a522014-11-27 14:54:18 +0000679 EmitParallelMoves(
680 Location::StackSlot(source.GetStackIndex()),
681 Location::StackSlot(destination.GetStackIndex()),
682 Location::StackSlot(source.GetHighStackIndex(kX86WordSize)),
683 Location::StackSlot(destination.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100684 }
685 }
686}
687
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100688void CodeGeneratorX86::Move(HInstruction* instruction, Location location, HInstruction* move_for) {
Calin Juravlea21f5982014-11-13 15:53:04 +0000689 LocationSummary* locations = instruction->GetLocations();
690 if (locations != nullptr && locations->Out().Equals(location)) {
691 return;
692 }
693
694 if (locations != nullptr && locations->Out().IsConstant()) {
695 HConstant* const_to_move = locations->Out().GetConstant();
696 if (const_to_move->IsIntConstant()) {
697 Immediate imm(const_to_move->AsIntConstant()->GetValue());
698 if (location.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000699 __ movl(location.AsRegister<Register>(), imm);
Calin Juravlea21f5982014-11-13 15:53:04 +0000700 } else if (location.IsStackSlot()) {
701 __ movl(Address(ESP, location.GetStackIndex()), imm);
702 } else {
703 DCHECK(location.IsConstant());
704 DCHECK_EQ(location.GetConstant(), const_to_move);
705 }
706 } else if (const_to_move->IsLongConstant()) {
707 int64_t value = const_to_move->AsLongConstant()->GetValue();
708 if (location.IsRegisterPair()) {
709 __ movl(location.AsRegisterPairLow<Register>(), Immediate(Low32Bits(value)));
710 __ movl(location.AsRegisterPairHigh<Register>(), Immediate(High32Bits(value)));
711 } else if (location.IsDoubleStackSlot()) {
712 __ movl(Address(ESP, location.GetStackIndex()), Immediate(Low32Bits(value)));
Roland Levillain199f3362014-11-27 17:15:16 +0000713 __ movl(Address(ESP, location.GetHighStackIndex(kX86WordSize)),
714 Immediate(High32Bits(value)));
Calin Juravlea21f5982014-11-13 15:53:04 +0000715 } else {
716 DCHECK(location.IsConstant());
717 DCHECK_EQ(location.GetConstant(), instruction);
718 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100719 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +0000720 } else if (instruction->IsTemporary()) {
721 Location temp_location = GetTemporaryLocation(instruction->AsTemporary());
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000722 if (temp_location.IsStackSlot()) {
723 Move32(location, temp_location);
724 } else {
725 DCHECK(temp_location.IsDoubleStackSlot());
726 Move64(location, temp_location);
727 }
Roland Levillain476df552014-10-09 17:51:36 +0100728 } else if (instruction->IsLoadLocal()) {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100729 int slot = GetStackSlot(instruction->AsLoadLocal()->GetLocal());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100730 switch (instruction->GetType()) {
731 case Primitive::kPrimBoolean:
732 case Primitive::kPrimByte:
733 case Primitive::kPrimChar:
734 case Primitive::kPrimShort:
735 case Primitive::kPrimInt:
736 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100737 case Primitive::kPrimFloat:
738 Move32(location, Location::StackSlot(slot));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100739 break;
740
741 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100742 case Primitive::kPrimDouble:
743 Move64(location, Location::DoubleStackSlot(slot));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100744 break;
745
746 default:
747 LOG(FATAL) << "Unimplemented local type " << instruction->GetType();
748 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000749 } else {
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100750 DCHECK((instruction->GetNext() == move_for) || instruction->GetNext()->IsTemporary());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100751 switch (instruction->GetType()) {
752 case Primitive::kPrimBoolean:
753 case Primitive::kPrimByte:
754 case Primitive::kPrimChar:
755 case Primitive::kPrimShort:
756 case Primitive::kPrimInt:
757 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100758 case Primitive::kPrimFloat:
Calin Juravlea21f5982014-11-13 15:53:04 +0000759 Move32(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100760 break;
761
762 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100763 case Primitive::kPrimDouble:
Calin Juravlea21f5982014-11-13 15:53:04 +0000764 Move64(location, locations->Out());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100765 break;
766
767 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100768 LOG(FATAL) << "Unexpected type " << instruction->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100769 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000770 }
771}
772
773void LocationsBuilderX86::VisitGoto(HGoto* got) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000774 got->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000775}
776
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000777void InstructionCodeGeneratorX86::VisitGoto(HGoto* got) {
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000778 HBasicBlock* successor = got->GetSuccessor();
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100779 DCHECK(!successor->IsExitBlock());
780
781 HBasicBlock* block = got->GetBlock();
782 HInstruction* previous = got->GetPrevious();
783
784 HLoopInformation* info = block->GetLoopInformation();
785 if (info != nullptr && info->IsBackEdge(block) && info->HasSuspendCheck()) {
786 codegen_->ClearSpillSlotsFromLoopPhisInStackMap(info->GetSuspendCheck());
787 GenerateSuspendCheck(info->GetSuspendCheck(), successor);
788 return;
789 }
790
791 if (block->IsEntryBlock() && (previous != nullptr) && previous->IsSuspendCheck()) {
792 GenerateSuspendCheck(previous->AsSuspendCheck(), nullptr);
793 }
794 if (!codegen_->GoesToNextBlock(got->GetBlock(), successor)) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000795 __ jmp(codegen_->GetLabelOf(successor));
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000796 }
797}
798
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000799void LocationsBuilderX86::VisitExit(HExit* exit) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000800 exit->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000801}
802
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000803void InstructionCodeGeneratorX86::VisitExit(HExit* exit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700804 UNUSED(exit);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000805 if (kIsDebugBuild) {
806 __ Comment("Unreachable");
807 __ int3();
808 }
809}
810
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000811void LocationsBuilderX86::VisitIf(HIf* if_instr) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100812 LocationSummary* locations =
813 new (GetGraph()->GetArena()) LocationSummary(if_instr, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100814 HInstruction* cond = if_instr->InputAt(0);
Nicolas Geoffray01ef3452014-10-01 11:32:17 +0100815 if (!cond->IsCondition() || cond->AsCondition()->NeedsMaterialization()) {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100816 locations->SetInAt(0, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100817 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000818}
819
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000820void InstructionCodeGeneratorX86::VisitIf(HIf* if_instr) {
Dave Allison20dfc792014-06-16 20:44:29 -0700821 HInstruction* cond = if_instr->InputAt(0);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100822 if (cond->IsIntConstant()) {
823 // Constant condition, statically compared against 1.
824 int32_t cond_value = cond->AsIntConstant()->GetValue();
825 if (cond_value == 1) {
826 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
827 if_instr->IfTrueSuccessor())) {
828 __ jmp(codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100829 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100830 return;
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100831 } else {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100832 DCHECK_EQ(cond_value, 0);
833 }
834 } else {
835 bool materialized =
836 !cond->IsCondition() || cond->AsCondition()->NeedsMaterialization();
837 // Moves do not affect the eflags register, so if the condition is
838 // evaluated just before the if, we don't need to evaluate it
839 // again.
840 bool eflags_set = cond->IsCondition()
841 && cond->AsCondition()->IsBeforeWhenDisregardMoves(if_instr);
842 if (materialized) {
843 if (!eflags_set) {
844 // Materialized condition, compare against 0.
845 Location lhs = if_instr->GetLocations()->InAt(0);
846 if (lhs.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000847 __ cmpl(lhs.AsRegister<Register>(), Immediate(0));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100848 } else {
849 __ cmpl(Address(ESP, lhs.GetStackIndex()), Immediate(0));
850 }
851 __ j(kNotEqual, codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
852 } else {
853 __ j(X86Condition(cond->AsCondition()->GetCondition()),
854 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
855 }
856 } else {
857 Location lhs = cond->GetLocations()->InAt(0);
858 Location rhs = cond->GetLocations()->InAt(1);
859 // LHS is guaranteed to be in a register (see
860 // LocationsBuilderX86::VisitCondition).
861 if (rhs.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000862 __ cmpl(lhs.AsRegister<Register>(), rhs.AsRegister<Register>());
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100863 } else if (rhs.IsConstant()) {
864 HIntConstant* instruction = rhs.GetConstant()->AsIntConstant();
865 Immediate imm(instruction->AsIntConstant()->GetValue());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000866 __ cmpl(lhs.AsRegister<Register>(), imm);
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100867 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000868 __ cmpl(lhs.AsRegister<Register>(), Address(ESP, rhs.GetStackIndex()));
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100869 }
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100870 __ j(X86Condition(cond->AsCondition()->GetCondition()),
871 codegen_->GetLabelOf(if_instr->IfTrueSuccessor()));
Dave Allison20dfc792014-06-16 20:44:29 -0700872 }
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100873 }
Roland Levillain3a3fd0f2014-10-10 13:56:31 +0100874 if (!codegen_->GoesToNextBlock(if_instr->GetBlock(),
875 if_instr->IfFalseSuccessor())) {
Dave Allison20dfc792014-06-16 20:44:29 -0700876 __ jmp(codegen_->GetLabelOf(if_instr->IfFalseSuccessor()));
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000877 }
878}
879
880void LocationsBuilderX86::VisitLocal(HLocal* local) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000881 local->SetLocations(nullptr);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000882}
883
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000884void InstructionCodeGeneratorX86::VisitLocal(HLocal* local) {
885 DCHECK_EQ(local->GetBlock(), GetGraph()->GetEntryBlock());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000886}
887
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000888void LocationsBuilderX86::VisitLoadLocal(HLoadLocal* local) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100889 local->SetLocations(nullptr);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000890}
891
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000892void InstructionCodeGeneratorX86::VisitLoadLocal(HLoadLocal* load) {
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100893 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700894 UNUSED(load);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000895}
896
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100897void LocationsBuilderX86::VisitStoreLocal(HStoreLocal* store) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100898 LocationSummary* locations =
899 new (GetGraph()->GetArena()) LocationSummary(store, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100900 switch (store->InputAt(1)->GetType()) {
901 case Primitive::kPrimBoolean:
902 case Primitive::kPrimByte:
903 case Primitive::kPrimChar:
904 case Primitive::kPrimShort:
905 case Primitive::kPrimInt:
906 case Primitive::kPrimNot:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100907 case Primitive::kPrimFloat:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100908 locations->SetInAt(1, Location::StackSlot(codegen_->GetStackSlot(store->GetLocal())));
909 break;
910
911 case Primitive::kPrimLong:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100912 case Primitive::kPrimDouble:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100913 locations->SetInAt(1, Location::DoubleStackSlot(codegen_->GetStackSlot(store->GetLocal())));
914 break;
915
916 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100917 LOG(FATAL) << "Unknown local type " << store->InputAt(1)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100918 }
919 store->SetLocations(locations);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000920}
921
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000922void InstructionCodeGeneratorX86::VisitStoreLocal(HStoreLocal* store) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700923 UNUSED(store);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000924}
925
Dave Allison20dfc792014-06-16 20:44:29 -0700926void LocationsBuilderX86::VisitCondition(HCondition* comp) {
Nicolas Geoffray39468442014-09-02 15:17:15 +0100927 LocationSummary* locations =
928 new (GetGraph()->GetArena()) LocationSummary(comp, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +0100929 locations->SetInAt(0, Location::RequiresRegister());
930 locations->SetInAt(1, Location::Any());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100931 if (comp->NeedsMaterialization()) {
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100932 locations->SetOut(Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100933 }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000934}
935
Dave Allison20dfc792014-06-16 20:44:29 -0700936void InstructionCodeGeneratorX86::VisitCondition(HCondition* comp) {
937 if (comp->NeedsMaterialization()) {
938 LocationSummary* locations = comp->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +0000939 Register reg = locations->Out().AsRegister<Register>();
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100940 // Clear register: setcc only sets the low byte.
941 __ xorl(reg, reg);
Dave Allison20dfc792014-06-16 20:44:29 -0700942 if (locations->InAt(1).IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000943 __ cmpl(locations->InAt(0).AsRegister<Register>(),
944 locations->InAt(1).AsRegister<Register>());
Nicolas Geoffray96f89a22014-07-11 10:57:49 +0100945 } else if (locations->InAt(1).IsConstant()) {
946 HConstant* instruction = locations->InAt(1).GetConstant();
947 Immediate imm(instruction->AsIntConstant()->GetValue());
Roland Levillain271ab9c2014-11-27 15:23:57 +0000948 __ cmpl(locations->InAt(0).AsRegister<Register>(), imm);
Dave Allison20dfc792014-06-16 20:44:29 -0700949 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +0000950 __ cmpl(locations->InAt(0).AsRegister<Register>(),
Dave Allison20dfc792014-06-16 20:44:29 -0700951 Address(ESP, locations->InAt(1).GetStackIndex()));
952 }
Nicolas Geoffray18efde52014-09-22 15:51:11 +0100953 __ setb(X86Condition(comp->GetCondition()), reg);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +0100954 }
Dave Allison20dfc792014-06-16 20:44:29 -0700955}
956
957void LocationsBuilderX86::VisitEqual(HEqual* comp) {
958 VisitCondition(comp);
959}
960
961void InstructionCodeGeneratorX86::VisitEqual(HEqual* comp) {
962 VisitCondition(comp);
963}
964
965void LocationsBuilderX86::VisitNotEqual(HNotEqual* comp) {
966 VisitCondition(comp);
967}
968
969void InstructionCodeGeneratorX86::VisitNotEqual(HNotEqual* comp) {
970 VisitCondition(comp);
971}
972
973void LocationsBuilderX86::VisitLessThan(HLessThan* comp) {
974 VisitCondition(comp);
975}
976
977void InstructionCodeGeneratorX86::VisitLessThan(HLessThan* comp) {
978 VisitCondition(comp);
979}
980
981void LocationsBuilderX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
982 VisitCondition(comp);
983}
984
985void InstructionCodeGeneratorX86::VisitLessThanOrEqual(HLessThanOrEqual* comp) {
986 VisitCondition(comp);
987}
988
989void LocationsBuilderX86::VisitGreaterThan(HGreaterThan* comp) {
990 VisitCondition(comp);
991}
992
993void InstructionCodeGeneratorX86::VisitGreaterThan(HGreaterThan* comp) {
994 VisitCondition(comp);
995}
996
997void LocationsBuilderX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
998 VisitCondition(comp);
999}
1000
1001void InstructionCodeGeneratorX86::VisitGreaterThanOrEqual(HGreaterThanOrEqual* comp) {
1002 VisitCondition(comp);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001003}
1004
1005void LocationsBuilderX86::VisitIntConstant(HIntConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001006 LocationSummary* locations =
1007 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001008 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001009}
1010
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001011void InstructionCodeGeneratorX86::VisitIntConstant(HIntConstant* constant) {
Roland Levillain3a3fd0f2014-10-10 13:56:31 +01001012 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001013 UNUSED(constant);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001014}
1015
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001016void LocationsBuilderX86::VisitLongConstant(HLongConstant* constant) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001017 LocationSummary* locations =
1018 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001019 locations->SetOut(Location::ConstantLocation(constant));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001020}
1021
1022void InstructionCodeGeneratorX86::VisitLongConstant(HLongConstant* constant) {
1023 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001024 UNUSED(constant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001025}
1026
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001027void LocationsBuilderX86::VisitFloatConstant(HFloatConstant* constant) {
1028 LocationSummary* locations =
1029 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1030 locations->SetOut(Location::ConstantLocation(constant));
1031}
1032
1033void InstructionCodeGeneratorX86::VisitFloatConstant(HFloatConstant* constant) {
1034 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001035 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001036}
1037
1038void LocationsBuilderX86::VisitDoubleConstant(HDoubleConstant* constant) {
1039 LocationSummary* locations =
1040 new (GetGraph()->GetArena()) LocationSummary(constant, LocationSummary::kNoCall);
1041 locations->SetOut(Location::ConstantLocation(constant));
1042}
1043
1044void InstructionCodeGeneratorX86::VisitDoubleConstant(HDoubleConstant* constant) {
1045 // Will be generated at use site.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001046 UNUSED(constant);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001047}
1048
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001049void LocationsBuilderX86::VisitReturnVoid(HReturnVoid* ret) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001050 ret->SetLocations(nullptr);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001051}
1052
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001053void InstructionCodeGeneratorX86::VisitReturnVoid(HReturnVoid* ret) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001054 UNUSED(ret);
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001055 codegen_->GenerateFrameExit();
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001056 __ ret();
1057}
1058
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001059void LocationsBuilderX86::VisitReturn(HReturn* ret) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001060 LocationSummary* locations =
1061 new (GetGraph()->GetArena()) LocationSummary(ret, LocationSummary::kNoCall);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001062 switch (ret->InputAt(0)->GetType()) {
1063 case Primitive::kPrimBoolean:
1064 case Primitive::kPrimByte:
1065 case Primitive::kPrimChar:
1066 case Primitive::kPrimShort:
1067 case Primitive::kPrimInt:
1068 case Primitive::kPrimNot:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001069 locations->SetInAt(0, Location::RegisterLocation(EAX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001070 break;
1071
1072 case Primitive::kPrimLong:
1073 locations->SetInAt(
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001074 0, Location::RegisterPairLocation(EAX, EDX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001075 break;
1076
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001077 case Primitive::kPrimFloat:
1078 case Primitive::kPrimDouble:
1079 locations->SetInAt(
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001080 0, Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001081 break;
1082
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001083 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001084 LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001085 }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001086}
1087
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001088void InstructionCodeGeneratorX86::VisitReturn(HReturn* ret) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001089 if (kIsDebugBuild) {
1090 switch (ret->InputAt(0)->GetType()) {
1091 case Primitive::kPrimBoolean:
1092 case Primitive::kPrimByte:
1093 case Primitive::kPrimChar:
1094 case Primitive::kPrimShort:
1095 case Primitive::kPrimInt:
1096 case Primitive::kPrimNot:
Roland Levillain271ab9c2014-11-27 15:23:57 +00001097 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegister<Register>(), EAX);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001098 break;
1099
1100 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001101 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairLow<Register>(), EAX);
1102 DCHECK_EQ(ret->GetLocations()->InAt(0).AsRegisterPairHigh<Register>(), EDX);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001103 break;
1104
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001105 case Primitive::kPrimFloat:
1106 case Primitive::kPrimDouble:
Roland Levillain271ab9c2014-11-27 15:23:57 +00001107 DCHECK_EQ(ret->GetLocations()->InAt(0).AsFpuRegister<XmmRegister>(), XMM0);
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001108 break;
1109
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001110 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001111 LOG(FATAL) << "Unknown return type " << ret->InputAt(0)->GetType();
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001112 }
1113 }
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001114 codegen_->GenerateFrameExit();
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001115 __ ret();
1116}
1117
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001118void LocationsBuilderX86::VisitInvokeStatic(HInvokeStatic* invoke) {
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001119 HandleInvoke(invoke);
1120}
1121
1122void InstructionCodeGeneratorX86::VisitInvokeStatic(HInvokeStatic* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001123 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001124
1125 // TODO: Implement all kinds of calls:
1126 // 1) boot -> boot
1127 // 2) app -> boot
1128 // 3) app -> app
1129 //
1130 // Currently we implement the app -> app logic, which looks up in the resolve cache.
1131
1132 // temp = method;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001133 codegen_->LoadCurrentMethod(temp);
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001134 // temp = temp->dex_cache_resolved_methods_;
1135 __ movl(temp, Address(temp, mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value()));
1136 // temp = temp[index_in_cache]
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01001137 __ movl(temp, Address(temp, CodeGenerator::GetCacheOffset(invoke->GetIndexInDexCache())));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001138 // (temp + offset_of_quick_compiled_code)()
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001139 __ call(Address(
1140 temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value()));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001141
1142 DCHECK(!codegen_->IsLeafMethod());
1143 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1144}
1145
1146void LocationsBuilderX86::VisitInvokeVirtual(HInvokeVirtual* invoke) {
1147 HandleInvoke(invoke);
1148}
1149
1150void LocationsBuilderX86::HandleInvoke(HInvoke* invoke) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001151 LocationSummary* locations =
1152 new (GetGraph()->GetArena()) LocationSummary(invoke, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001153 locations->AddTemp(Location::RegisterLocation(EAX));
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001154
1155 InvokeDexCallingConventionVisitor calling_convention_visitor;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001156 for (size_t i = 0; i < invoke->InputCount(); i++) {
Nicolas Geoffraydb928fc2014-04-16 17:38:32 +01001157 HInstruction* input = invoke->InputAt(i);
1158 locations->SetInAt(i, calling_convention_visitor.GetNextLocation(input->GetType()));
1159 }
1160
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001161 switch (invoke->GetType()) {
1162 case Primitive::kPrimBoolean:
1163 case Primitive::kPrimByte:
1164 case Primitive::kPrimChar:
1165 case Primitive::kPrimShort:
1166 case Primitive::kPrimInt:
1167 case Primitive::kPrimNot:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001168 locations->SetOut(Location::RegisterLocation(EAX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001169 break;
1170
1171 case Primitive::kPrimLong:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001172 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001173 break;
1174
1175 case Primitive::kPrimVoid:
1176 break;
1177
1178 case Primitive::kPrimDouble:
1179 case Primitive::kPrimFloat:
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001180 locations->SetOut(Location::FpuRegisterLocation(XMM0));
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001181 break;
1182 }
1183
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001184 invoke->SetLocations(locations);
1185}
1186
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001187void InstructionCodeGeneratorX86::VisitInvokeVirtual(HInvokeVirtual* invoke) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001188 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001189 uint32_t method_offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
1190 invoke->GetVTableIndex() * sizeof(mirror::Class::VTableEntry);
1191 LocationSummary* locations = invoke->GetLocations();
1192 Location receiver = locations->InAt(0);
1193 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1194 // temp = object->GetClass();
1195 if (receiver.IsStackSlot()) {
1196 __ movl(temp, Address(ESP, receiver.GetStackIndex()));
1197 __ movl(temp, Address(temp, class_offset));
1198 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001199 __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset));
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001200 }
1201 // temp = temp->GetMethodAt(method_offset);
1202 __ movl(temp, Address(temp, method_offset));
1203 // call temp->GetEntryPoint();
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001204 __ call(Address(
1205 temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(kX86WordSize).Int32Value()));
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001206
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01001207 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray39468442014-09-02 15:17:15 +01001208 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001209}
1210
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001211void LocationsBuilderX86::VisitInvokeInterface(HInvokeInterface* invoke) {
1212 HandleInvoke(invoke);
1213 // Add the hidden argument.
1214 invoke->GetLocations()->AddTemp(Location::FpuRegisterLocation(XMM0));
1215}
1216
1217void InstructionCodeGeneratorX86::VisitInvokeInterface(HInvokeInterface* invoke) {
1218 // TODO: b/18116999, our IMTs can miss an IncompatibleClassChangeError.
Roland Levillain271ab9c2014-11-27 15:23:57 +00001219 Register temp = invoke->GetLocations()->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001220 uint32_t method_offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
1221 (invoke->GetImtIndex() % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
1222 LocationSummary* locations = invoke->GetLocations();
1223 Location receiver = locations->InAt(0);
1224 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
1225
1226 // Set the hidden argument.
1227 __ movl(temp, Immediate(invoke->GetDexMethodIndex()));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001228 __ movd(invoke->GetLocations()->GetTemp(1).AsFpuRegister<XmmRegister>(), temp);
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001229
1230 // temp = object->GetClass();
1231 if (receiver.IsStackSlot()) {
1232 __ movl(temp, Address(ESP, receiver.GetStackIndex()));
1233 __ movl(temp, Address(temp, class_offset));
1234 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001235 __ movl(temp, Address(receiver.AsRegister<Register>(), class_offset));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001236 }
1237 // temp = temp->GetImtEntryAt(method_offset);
1238 __ movl(temp, Address(temp, method_offset));
1239 // call temp->GetEntryPoint();
Mathieu Chartier2d721012014-11-10 11:08:06 -08001240 __ call(Address(temp, mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Nicolas Geoffray86a8d7a2014-11-19 08:47:18 +00001241 kX86WordSize).Int32Value()));
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001242
1243 DCHECK(!codegen_->IsLeafMethod());
1244 codegen_->RecordPcInfo(invoke, invoke->GetDexPc());
1245}
1246
Roland Levillain88cb1752014-10-20 16:36:47 +01001247void LocationsBuilderX86::VisitNeg(HNeg* neg) {
1248 LocationSummary* locations =
1249 new (GetGraph()->GetArena()) LocationSummary(neg, LocationSummary::kNoCall);
1250 switch (neg->GetResultType()) {
1251 case Primitive::kPrimInt:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001252 case Primitive::kPrimLong:
Roland Levillain88cb1752014-10-20 16:36:47 +01001253 locations->SetInAt(0, Location::RequiresRegister());
1254 locations->SetOut(Location::SameAsFirstInput());
1255 break;
1256
Roland Levillain88cb1752014-10-20 16:36:47 +01001257 case Primitive::kPrimFloat:
Roland Levillain5368c212014-11-27 15:03:41 +00001258 locations->SetInAt(0, Location::RequiresFpuRegister());
1259 locations->SetOut(Location::SameAsFirstInput());
1260 locations->AddTemp(Location::RequiresRegister());
1261 locations->AddTemp(Location::RequiresFpuRegister());
1262 break;
1263
Roland Levillain88cb1752014-10-20 16:36:47 +01001264 case Primitive::kPrimDouble:
Roland Levillain3dbcb382014-10-28 17:30:07 +00001265 locations->SetInAt(0, Location::RequiresFpuRegister());
Roland Levillain5368c212014-11-27 15:03:41 +00001266 locations->SetOut(Location::SameAsFirstInput());
1267 locations->AddTemp(Location::RequiresFpuRegister());
Roland Levillain88cb1752014-10-20 16:36:47 +01001268 break;
1269
1270 default:
1271 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1272 }
1273}
1274
1275void InstructionCodeGeneratorX86::VisitNeg(HNeg* neg) {
1276 LocationSummary* locations = neg->GetLocations();
1277 Location out = locations->Out();
1278 Location in = locations->InAt(0);
1279 switch (neg->GetResultType()) {
1280 case Primitive::kPrimInt:
1281 DCHECK(in.IsRegister());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001282 DCHECK(in.Equals(out));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001283 __ negl(out.AsRegister<Register>());
Roland Levillain88cb1752014-10-20 16:36:47 +01001284 break;
1285
1286 case Primitive::kPrimLong:
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001287 DCHECK(in.IsRegisterPair());
Roland Levillain3dbcb382014-10-28 17:30:07 +00001288 DCHECK(in.Equals(out));
Roland Levillain2e07b4f2014-10-23 18:12:09 +01001289 __ negl(out.AsRegisterPairLow<Register>());
1290 // Negation is similar to subtraction from zero. The least
1291 // significant byte triggers a borrow when it is different from
1292 // zero; to take it into account, add 1 to the most significant
1293 // byte if the carry flag (CF) is set to 1 after the first NEGL
1294 // operation.
1295 __ adcl(out.AsRegisterPairHigh<Register>(), Immediate(0));
1296 __ negl(out.AsRegisterPairHigh<Register>());
1297 break;
1298
Roland Levillain5368c212014-11-27 15:03:41 +00001299 case Primitive::kPrimFloat: {
1300 DCHECK(in.Equals(out));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001301 Register constant = locations->GetTemp(0).AsRegister<Register>();
1302 XmmRegister mask = locations->GetTemp(1).AsFpuRegister<XmmRegister>();
Roland Levillain5368c212014-11-27 15:03:41 +00001303 // Implement float negation with an exclusive or with value
1304 // 0x80000000 (mask for bit 31, representing the sign of a
1305 // single-precision floating-point number).
1306 __ movl(constant, Immediate(INT32_C(0x80000000)));
1307 __ movd(mask, constant);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001308 __ xorps(out.AsFpuRegister<XmmRegister>(), mask);
Roland Levillain3dbcb382014-10-28 17:30:07 +00001309 break;
Roland Levillain5368c212014-11-27 15:03:41 +00001310 }
Roland Levillain3dbcb382014-10-28 17:30:07 +00001311
Roland Levillain5368c212014-11-27 15:03:41 +00001312 case Primitive::kPrimDouble: {
1313 DCHECK(in.Equals(out));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001314 XmmRegister mask = locations->GetTemp(0).AsFpuRegister<XmmRegister>();
Roland Levillain5368c212014-11-27 15:03:41 +00001315 // Implement double negation with an exclusive or with value
1316 // 0x8000000000000000 (mask for bit 63, representing the sign of
1317 // a double-precision floating-point number).
1318 __ LoadLongConstant(mask, INT64_C(0x8000000000000000));
Roland Levillain271ab9c2014-11-27 15:23:57 +00001319 __ xorpd(out.AsFpuRegister<XmmRegister>(), mask);
Roland Levillain88cb1752014-10-20 16:36:47 +01001320 break;
Roland Levillain5368c212014-11-27 15:03:41 +00001321 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001322
1323 default:
1324 LOG(FATAL) << "Unexpected neg type " << neg->GetResultType();
1325 }
1326}
1327
Roland Levillaindff1f282014-11-05 14:15:05 +00001328void LocationsBuilderX86::VisitTypeConversion(HTypeConversion* conversion) {
1329 LocationSummary* locations =
1330 new (GetGraph()->GetArena()) LocationSummary(conversion, LocationSummary::kNoCall);
1331 Primitive::Type result_type = conversion->GetResultType();
1332 Primitive::Type input_type = conversion->GetInputType();
1333 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001334 case Primitive::kPrimByte:
1335 switch (input_type) {
1336 case Primitive::kPrimShort:
1337 case Primitive::kPrimInt:
1338 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001339 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001340 locations->SetInAt(0, Location::Any());
1341 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1342 break;
1343
1344 default:
1345 LOG(FATAL) << "Unexpected type conversion from " << input_type
1346 << " to " << result_type;
1347 }
1348 break;
1349
Roland Levillain01a8d712014-11-14 16:27:39 +00001350 case Primitive::kPrimShort:
1351 switch (input_type) {
1352 case Primitive::kPrimByte:
1353 case Primitive::kPrimInt:
1354 case Primitive::kPrimChar:
1355 // Processing a Dex `int-to-short' instruction.
1356 locations->SetInAt(0, Location::Any());
1357 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1358 break;
1359
1360 default:
1361 LOG(FATAL) << "Unexpected type conversion from " << input_type
1362 << " to " << result_type;
1363 }
1364 break;
1365
Roland Levillain946e1432014-11-11 17:35:19 +00001366 case Primitive::kPrimInt:
1367 switch (input_type) {
1368 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001369 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001370 locations->SetInAt(0, Location::Any());
1371 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1372 break;
1373
1374 case Primitive::kPrimFloat:
1375 case Primitive::kPrimDouble:
1376 LOG(FATAL) << "Type conversion from " << input_type
1377 << " to " << result_type << " not yet implemented";
1378 break;
1379
1380 default:
1381 LOG(FATAL) << "Unexpected type conversion from " << input_type
1382 << " to " << result_type;
1383 }
1384 break;
1385
Roland Levillaindff1f282014-11-05 14:15:05 +00001386 case Primitive::kPrimLong:
1387 switch (input_type) {
1388 case Primitive::kPrimByte:
1389 case Primitive::kPrimShort:
1390 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001391 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001392 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001393 locations->SetInAt(0, Location::RegisterLocation(EAX));
1394 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
1395 break;
1396
1397 case Primitive::kPrimFloat:
1398 case Primitive::kPrimDouble:
1399 LOG(FATAL) << "Type conversion from " << input_type << " to "
1400 << result_type << " not yet implemented";
1401 break;
1402
1403 default:
1404 LOG(FATAL) << "Unexpected type conversion from " << input_type
1405 << " to " << result_type;
1406 }
1407 break;
1408
Roland Levillain981e4542014-11-14 11:47:14 +00001409 case Primitive::kPrimChar:
1410 switch (input_type) {
1411 case Primitive::kPrimByte:
1412 case Primitive::kPrimShort:
1413 case Primitive::kPrimInt:
1414 case Primitive::kPrimChar:
1415 // Processing a Dex `int-to-char' instruction.
1416 locations->SetInAt(0, Location::Any());
1417 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
1418 break;
1419
1420 default:
1421 LOG(FATAL) << "Unexpected type conversion from " << input_type
1422 << " to " << result_type;
1423 }
1424 break;
1425
Roland Levillaindff1f282014-11-05 14:15:05 +00001426 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001427 switch (input_type) {
1428 case Primitive::kPrimByte:
1429 case Primitive::kPrimShort:
1430 case Primitive::kPrimInt:
1431 case Primitive::kPrimChar:
1432 // Processing a Dex `int-to-float' instruction.
1433 locations->SetInAt(0, Location::RequiresRegister());
1434 locations->SetOut(Location::RequiresFpuRegister());
1435 break;
1436
1437 case Primitive::kPrimLong:
1438 case Primitive::kPrimDouble:
1439 LOG(FATAL) << "Type conversion from " << input_type
1440 << " to " << result_type << " not yet implemented";
1441 break;
1442
1443 default:
1444 LOG(FATAL) << "Unexpected type conversion from " << input_type
1445 << " to " << result_type;
1446 };
1447 break;
1448
Roland Levillaindff1f282014-11-05 14:15:05 +00001449 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001450 switch (input_type) {
1451 case Primitive::kPrimByte:
1452 case Primitive::kPrimShort:
1453 case Primitive::kPrimInt:
1454 case Primitive::kPrimChar:
1455 // Processing a Dex `int-to-double' instruction.
1456 locations->SetInAt(0, Location::RequiresRegister());
1457 locations->SetOut(Location::RequiresFpuRegister());
1458 break;
1459
1460 case Primitive::kPrimLong:
Roland Levillain647b9ed2014-11-27 12:06:00 +00001461 // Processing a Dex `long-to-double' instruction.
1462 locations->SetInAt(0, Location::RequiresRegister());
1463 locations->SetOut(Location::RequiresFpuRegister());
1464 locations->AddTemp(Location::RequiresFpuRegister());
1465 locations->AddTemp(Location::RequiresFpuRegister());
1466 break;
1467
Roland Levillaincff13742014-11-17 14:32:17 +00001468 case Primitive::kPrimFloat:
1469 LOG(FATAL) << "Type conversion from " << input_type
1470 << " to " << result_type << " not yet implemented";
1471 break;
1472
1473 default:
1474 LOG(FATAL) << "Unexpected type conversion from " << input_type
1475 << " to " << result_type;
1476 }
Roland Levillaindff1f282014-11-05 14:15:05 +00001477 break;
1478
1479 default:
1480 LOG(FATAL) << "Unexpected type conversion from " << input_type
1481 << " to " << result_type;
1482 }
1483}
1484
1485void InstructionCodeGeneratorX86::VisitTypeConversion(HTypeConversion* conversion) {
1486 LocationSummary* locations = conversion->GetLocations();
1487 Location out = locations->Out();
1488 Location in = locations->InAt(0);
1489 Primitive::Type result_type = conversion->GetResultType();
1490 Primitive::Type input_type = conversion->GetInputType();
1491 switch (result_type) {
Roland Levillain51d3fc42014-11-13 14:11:42 +00001492 case Primitive::kPrimByte:
1493 switch (input_type) {
1494 case Primitive::kPrimShort:
1495 case Primitive::kPrimInt:
1496 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001497 // Processing a Dex `int-to-byte' instruction.
Roland Levillain51d3fc42014-11-13 14:11:42 +00001498 if (in.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001499 __ movsxb(out.AsRegister<Register>(), in.AsRegister<ByteRegister>());
Roland Levillain51d3fc42014-11-13 14:11:42 +00001500 } else if (in.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001501 __ movsxb(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex()));
Roland Levillain51d3fc42014-11-13 14:11:42 +00001502 } else {
1503 DCHECK(in.GetConstant()->IsIntConstant());
1504 int32_t value = in.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001505 __ movl(out.AsRegister<Register>(), Immediate(static_cast<int8_t>(value)));
Roland Levillain51d3fc42014-11-13 14:11:42 +00001506 }
1507 break;
1508
1509 default:
1510 LOG(FATAL) << "Unexpected type conversion from " << input_type
1511 << " to " << result_type;
1512 }
1513 break;
1514
Roland Levillain01a8d712014-11-14 16:27:39 +00001515 case Primitive::kPrimShort:
1516 switch (input_type) {
1517 case Primitive::kPrimByte:
1518 case Primitive::kPrimInt:
1519 case Primitive::kPrimChar:
1520 // Processing a Dex `int-to-short' instruction.
1521 if (in.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001522 __ movsxw(out.AsRegister<Register>(), in.AsRegister<Register>());
Roland Levillain01a8d712014-11-14 16:27:39 +00001523 } else if (in.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001524 __ movsxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex()));
Roland Levillain01a8d712014-11-14 16:27:39 +00001525 } else {
1526 DCHECK(in.GetConstant()->IsIntConstant());
1527 int32_t value = in.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001528 __ movl(out.AsRegister<Register>(), Immediate(static_cast<int16_t>(value)));
Roland Levillain01a8d712014-11-14 16:27:39 +00001529 }
1530 break;
1531
1532 default:
1533 LOG(FATAL) << "Unexpected type conversion from " << input_type
1534 << " to " << result_type;
1535 }
1536 break;
1537
Roland Levillain946e1432014-11-11 17:35:19 +00001538 case Primitive::kPrimInt:
1539 switch (input_type) {
1540 case Primitive::kPrimLong:
Roland Levillain981e4542014-11-14 11:47:14 +00001541 // Processing a Dex `long-to-int' instruction.
Roland Levillain946e1432014-11-11 17:35:19 +00001542 if (in.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001543 __ movl(out.AsRegister<Register>(), in.AsRegisterPairLow<Register>());
Roland Levillain946e1432014-11-11 17:35:19 +00001544 } else if (in.IsDoubleStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001545 __ movl(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex()));
Roland Levillain946e1432014-11-11 17:35:19 +00001546 } else {
1547 DCHECK(in.IsConstant());
1548 DCHECK(in.GetConstant()->IsLongConstant());
1549 int64_t value = in.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001550 __ movl(out.AsRegister<Register>(), Immediate(static_cast<int32_t>(value)));
Roland Levillain946e1432014-11-11 17:35:19 +00001551 }
1552 break;
1553
1554 case Primitive::kPrimFloat:
1555 case Primitive::kPrimDouble:
1556 LOG(FATAL) << "Type conversion from " << input_type
1557 << " to " << result_type << " not yet implemented";
1558 break;
1559
1560 default:
1561 LOG(FATAL) << "Unexpected type conversion from " << input_type
1562 << " to " << result_type;
1563 }
1564 break;
1565
Roland Levillaindff1f282014-11-05 14:15:05 +00001566 case Primitive::kPrimLong:
1567 switch (input_type) {
1568 case Primitive::kPrimByte:
1569 case Primitive::kPrimShort:
1570 case Primitive::kPrimInt:
Roland Levillain666c7322014-11-10 13:39:43 +00001571 case Primitive::kPrimChar:
Roland Levillain981e4542014-11-14 11:47:14 +00001572 // Processing a Dex `int-to-long' instruction.
Roland Levillaindff1f282014-11-05 14:15:05 +00001573 DCHECK_EQ(out.AsRegisterPairLow<Register>(), EAX);
1574 DCHECK_EQ(out.AsRegisterPairHigh<Register>(), EDX);
Roland Levillain271ab9c2014-11-27 15:23:57 +00001575 DCHECK_EQ(in.AsRegister<Register>(), EAX);
Roland Levillaindff1f282014-11-05 14:15:05 +00001576 __ cdq();
1577 break;
1578
1579 case Primitive::kPrimFloat:
1580 case Primitive::kPrimDouble:
1581 LOG(FATAL) << "Type conversion from " << input_type << " to "
1582 << result_type << " not yet implemented";
1583 break;
1584
1585 default:
1586 LOG(FATAL) << "Unexpected type conversion from " << input_type
1587 << " to " << result_type;
1588 }
1589 break;
1590
Roland Levillain981e4542014-11-14 11:47:14 +00001591 case Primitive::kPrimChar:
1592 switch (input_type) {
1593 case Primitive::kPrimByte:
1594 case Primitive::kPrimShort:
1595 case Primitive::kPrimInt:
1596 case Primitive::kPrimChar:
1597 // Processing a Dex `Process a Dex `int-to-char'' instruction.
1598 if (in.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001599 __ movzxw(out.AsRegister<Register>(), in.AsRegister<Register>());
Roland Levillain981e4542014-11-14 11:47:14 +00001600 } else if (in.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001601 __ movzxw(out.AsRegister<Register>(), Address(ESP, in.GetStackIndex()));
Roland Levillain981e4542014-11-14 11:47:14 +00001602 } else {
1603 DCHECK(in.GetConstant()->IsIntConstant());
1604 int32_t value = in.GetConstant()->AsIntConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001605 __ movl(out.AsRegister<Register>(), Immediate(static_cast<uint16_t>(value)));
Roland Levillain981e4542014-11-14 11:47:14 +00001606 }
1607 break;
1608
1609 default:
1610 LOG(FATAL) << "Unexpected type conversion from " << input_type
1611 << " to " << result_type;
1612 }
1613 break;
1614
Roland Levillaindff1f282014-11-05 14:15:05 +00001615 case Primitive::kPrimFloat:
Roland Levillaincff13742014-11-17 14:32:17 +00001616 switch (input_type) {
1617 // Processing a Dex `int-to-float' instruction.
1618 case Primitive::kPrimByte:
1619 case Primitive::kPrimShort:
1620 case Primitive::kPrimInt:
1621 case Primitive::kPrimChar:
Roland Levillain271ab9c2014-11-27 15:23:57 +00001622 __ cvtsi2ss(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001623 break;
1624
1625 case Primitive::kPrimLong:
1626 case Primitive::kPrimDouble:
1627 LOG(FATAL) << "Type conversion from " << input_type
1628 << " to " << result_type << " not yet implemented";
1629 break;
1630
1631 default:
1632 LOG(FATAL) << "Unexpected type conversion from " << input_type
1633 << " to " << result_type;
1634 };
1635 break;
1636
Roland Levillaindff1f282014-11-05 14:15:05 +00001637 case Primitive::kPrimDouble:
Roland Levillaincff13742014-11-17 14:32:17 +00001638 switch (input_type) {
1639 // Processing a Dex `int-to-double' instruction.
1640 case Primitive::kPrimByte:
1641 case Primitive::kPrimShort:
1642 case Primitive::kPrimInt:
1643 case Primitive::kPrimChar:
Roland Levillain271ab9c2014-11-27 15:23:57 +00001644 __ cvtsi2sd(out.AsFpuRegister<XmmRegister>(), in.AsRegister<Register>());
Roland Levillaincff13742014-11-17 14:32:17 +00001645 break;
1646
Roland Levillain647b9ed2014-11-27 12:06:00 +00001647 case Primitive::kPrimLong: {
1648 // Processing a Dex `long-to-double' instruction.
1649 Register low = in.AsRegisterPairLow<Register>();
1650 Register high = in.AsRegisterPairHigh<Register>();
Roland Levillain271ab9c2014-11-27 15:23:57 +00001651 XmmRegister result = out.AsFpuRegister<XmmRegister>();
1652 XmmRegister temp = locations->GetTemp(0).AsFpuRegister<XmmRegister>();
1653 XmmRegister constant = locations->GetTemp(1).AsFpuRegister<XmmRegister>();
Roland Levillain647b9ed2014-11-27 12:06:00 +00001654
1655 // Binary encoding of 2^32 for type double.
1656 const int64_t c1 = INT64_C(0x41F0000000000000);
1657 // Binary encoding of 2^31 for type double.
1658 const int64_t c2 = INT64_C(0x41E0000000000000);
1659
1660 // low = low - 2^31 (to prevent bit 31 of `low` to be
1661 // interpreted as a sign bit)
1662 __ subl(low, Immediate(0x80000000));
1663 // temp = int-to-double(high)
1664 __ cvtsi2sd(temp, high);
1665 // temp = temp * 2^32
1666 __ LoadLongConstant(constant, c1);
1667 __ mulsd(temp, constant);
1668 // result = int-to-double(low)
1669 __ cvtsi2sd(result, low);
1670 // result = result + 2^31 (restore the original value of `low`)
1671 __ LoadLongConstant(constant, c2);
1672 __ addsd(result, constant);
1673 // result = result + temp
1674 __ addsd(result, temp);
1675 break;
1676 }
1677
Roland Levillaincff13742014-11-17 14:32:17 +00001678 case Primitive::kPrimFloat:
1679 LOG(FATAL) << "Type conversion from " << input_type
1680 << " to " << result_type << " not yet implemented";
1681 break;
1682
1683 default:
1684 LOG(FATAL) << "Unexpected type conversion from " << input_type
1685 << " to " << result_type;
1686 };
Roland Levillaindff1f282014-11-05 14:15:05 +00001687 break;
1688
1689 default:
1690 LOG(FATAL) << "Unexpected type conversion from " << input_type
1691 << " to " << result_type;
1692 }
1693}
1694
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001695void LocationsBuilderX86::VisitAdd(HAdd* add) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001696 LocationSummary* locations =
1697 new (GetGraph()->GetArena()) LocationSummary(add, LocationSummary::kNoCall);
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001698 switch (add->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001699 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001700 case Primitive::kPrimLong: {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001701 locations->SetInAt(0, Location::RequiresRegister());
1702 locations->SetInAt(1, Location::Any());
1703 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001704 break;
1705 }
1706
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001707 case Primitive::kPrimFloat:
1708 case Primitive::kPrimDouble: {
1709 locations->SetInAt(0, Location::RequiresFpuRegister());
1710 locations->SetInAt(1, Location::Any());
1711 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001712 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001713 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001714
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001715 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001716 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
1717 break;
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001718 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001719}
1720
1721void InstructionCodeGeneratorX86::VisitAdd(HAdd* add) {
1722 LocationSummary* locations = add->GetLocations();
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001723 Location first = locations->InAt(0);
1724 Location second = locations->InAt(1);
Calin Juravle11351682014-10-23 15:38:15 +01001725 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001726 switch (add->GetResultType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001727 case Primitive::kPrimInt: {
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001728 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001729 __ addl(first.AsRegister<Register>(), second.AsRegister<Register>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001730 } else if (second.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001731 __ addl(first.AsRegister<Register>(),
1732 Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001733 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001734 __ addl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001735 }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001736 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001737 }
1738
1739 case Primitive::kPrimLong: {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001740 if (second.IsRegisterPair()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001741 __ addl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
1742 __ adcl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001743 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001744 __ addl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
1745 __ adcl(first.AsRegisterPairHigh<Register>(),
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001746 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001747 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001748 break;
1749 }
1750
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001751 case Primitive::kPrimFloat: {
1752 if (second.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001753 __ addss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001754 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001755 __ addss(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001756 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001757 break;
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001758 }
1759
1760 case Primitive::kPrimDouble: {
1761 if (second.IsFpuRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001762 __ addsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001763 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001764 __ addsd(first.AsFpuRegister<XmmRegister>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001765 }
1766 break;
1767 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001768
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001769 default:
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +01001770 LOG(FATAL) << "Unexpected add type " << add->GetResultType();
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001771 }
1772}
1773
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001774void LocationsBuilderX86::VisitSub(HSub* sub) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01001775 LocationSummary* locations =
1776 new (GetGraph()->GetArena()) LocationSummary(sub, LocationSummary::kNoCall);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001777 switch (sub->GetResultType()) {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001778 case Primitive::kPrimInt:
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001779 case Primitive::kPrimLong: {
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001780 locations->SetInAt(0, Location::RequiresRegister());
1781 locations->SetInAt(1, Location::Any());
1782 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001783 break;
1784 }
Calin Juravle11351682014-10-23 15:38:15 +01001785 case Primitive::kPrimFloat:
1786 case Primitive::kPrimDouble: {
1787 locations->SetInAt(0, Location::RequiresFpuRegister());
1788 locations->SetInAt(1, Location::RequiresFpuRegister());
1789 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001790 break;
Calin Juravle11351682014-10-23 15:38:15 +01001791 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001792
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001793 default:
Calin Juravle11351682014-10-23 15:38:15 +01001794 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001795 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001796}
1797
1798void InstructionCodeGeneratorX86::VisitSub(HSub* sub) {
1799 LocationSummary* locations = sub->GetLocations();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001800 Location first = locations->InAt(0);
1801 Location second = locations->InAt(1);
Calin Juravle11351682014-10-23 15:38:15 +01001802 DCHECK(first.Equals(locations->Out()));
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001803 switch (sub->GetResultType()) {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001804 case Primitive::kPrimInt: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001805 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001806 __ subl(first.AsRegister<Register>(), second.AsRegister<Register>());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001807 } else if (second.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00001808 __ subl(first.AsRegister<Register>(),
1809 Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001810 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001811 __ subl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001812 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001813 break;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001814 }
1815
1816 case Primitive::kPrimLong: {
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00001817 if (second.IsRegisterPair()) {
Calin Juravle11351682014-10-23 15:38:15 +01001818 __ subl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
1819 __ sbbl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001820 } else {
Calin Juravle11351682014-10-23 15:38:15 +01001821 __ subl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01001822 __ sbbl(first.AsRegisterPairHigh<Register>(),
1823 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01001824 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001825 break;
1826 }
1827
Calin Juravle11351682014-10-23 15:38:15 +01001828 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001829 __ subss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001830 break;
Calin Juravle11351682014-10-23 15:38:15 +01001831 }
1832
1833 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001834 __ subsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Calin Juravle11351682014-10-23 15:38:15 +01001835 break;
1836 }
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001837
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001838 default:
Calin Juravle11351682014-10-23 15:38:15 +01001839 LOG(FATAL) << "Unexpected sub type " << sub->GetResultType();
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01001840 }
1841}
1842
Calin Juravle34bacdf2014-10-07 20:23:36 +01001843void LocationsBuilderX86::VisitMul(HMul* mul) {
1844 LocationSummary* locations =
1845 new (GetGraph()->GetArena()) LocationSummary(mul, LocationSummary::kNoCall);
1846 switch (mul->GetResultType()) {
1847 case Primitive::kPrimInt:
1848 locations->SetInAt(0, Location::RequiresRegister());
1849 locations->SetInAt(1, Location::Any());
1850 locations->SetOut(Location::SameAsFirstInput());
1851 break;
1852 case Primitive::kPrimLong: {
1853 locations->SetInAt(0, Location::RequiresRegister());
1854 // TODO: Currently this handles only stack operands:
1855 // - we don't have enough registers because we currently use Quick ABI.
1856 // - by the time we have a working register allocator we will probably change the ABI
1857 // and fix the above.
1858 // - we don't have a way yet to request operands on stack but the base line compiler
1859 // will leave the operands on the stack with Any().
1860 locations->SetInAt(1, Location::Any());
1861 locations->SetOut(Location::SameAsFirstInput());
1862 // Needed for imul on 32bits with 64bits output.
1863 locations->AddTemp(Location::RegisterLocation(EAX));
1864 locations->AddTemp(Location::RegisterLocation(EDX));
1865 break;
1866 }
Calin Juravleb5bfa962014-10-21 18:02:24 +01001867 case Primitive::kPrimFloat:
1868 case Primitive::kPrimDouble: {
1869 locations->SetInAt(0, Location::RequiresFpuRegister());
1870 locations->SetInAt(1, Location::RequiresFpuRegister());
1871 locations->SetOut(Location::SameAsFirstInput());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001872 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001873 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001874
1875 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001876 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001877 }
1878}
1879
1880void InstructionCodeGeneratorX86::VisitMul(HMul* mul) {
1881 LocationSummary* locations = mul->GetLocations();
1882 Location first = locations->InAt(0);
1883 Location second = locations->InAt(1);
1884 DCHECK(first.Equals(locations->Out()));
1885
1886 switch (mul->GetResultType()) {
1887 case Primitive::kPrimInt: {
1888 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001889 __ imull(first.AsRegister<Register>(), second.AsRegister<Register>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001890 } else if (second.IsConstant()) {
1891 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001892 __ imull(first.AsRegister<Register>(), imm);
Calin Juravle34bacdf2014-10-07 20:23:36 +01001893 } else {
1894 DCHECK(second.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001895 __ imull(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Calin Juravle34bacdf2014-10-07 20:23:36 +01001896 }
1897 break;
1898 }
1899
1900 case Primitive::kPrimLong: {
1901 DCHECK(second.IsDoubleStackSlot());
1902
1903 Register in1_hi = first.AsRegisterPairHigh<Register>();
1904 Register in1_lo = first.AsRegisterPairLow<Register>();
1905 Address in2_hi(ESP, second.GetHighStackIndex(kX86WordSize));
1906 Address in2_lo(ESP, second.GetStackIndex());
Roland Levillain271ab9c2014-11-27 15:23:57 +00001907 Register eax = locations->GetTemp(0).AsRegister<Register>();
1908 Register edx = locations->GetTemp(1).AsRegister<Register>();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001909
1910 DCHECK_EQ(EAX, eax);
1911 DCHECK_EQ(EDX, edx);
1912
1913 // input: in1 - 64 bits, in2 - 64 bits
1914 // output: in1
1915 // formula: in1.hi : in1.lo = (in1.lo * in2.hi + in1.hi * in2.lo)* 2^32 + in1.lo * in2.lo
1916 // parts: in1.hi = in1.lo * in2.hi + in1.hi * in2.lo + (in1.lo * in2.lo)[63:32]
1917 // parts: in1.lo = (in1.lo * in2.lo)[31:0]
1918
1919 __ movl(eax, in2_hi);
1920 // eax <- in1.lo * in2.hi
1921 __ imull(eax, in1_lo);
1922 // in1.hi <- in1.hi * in2.lo
1923 __ imull(in1_hi, in2_lo);
1924 // in1.hi <- in1.lo * in2.hi + in1.hi * in2.lo
1925 __ addl(in1_hi, eax);
1926 // move in1_lo to eax to prepare for double precision
1927 __ movl(eax, in1_lo);
1928 // edx:eax <- in1.lo * in2.lo
1929 __ mull(in2_lo);
1930 // in1.hi <- in2.hi * in1.lo + in2.lo * in1.hi + (in1.lo * in2.lo)[63:32]
1931 __ addl(in1_hi, edx);
1932 // in1.lo <- (in1.lo * in2.lo)[31:0];
1933 __ movl(in1_lo, eax);
1934
1935 break;
1936 }
1937
Calin Juravleb5bfa962014-10-21 18:02:24 +01001938 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001939 __ mulss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Calin Juravle34bacdf2014-10-07 20:23:36 +01001940 break;
Calin Juravleb5bfa962014-10-21 18:02:24 +01001941 }
1942
1943 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001944 __ mulsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Calin Juravleb5bfa962014-10-21 18:02:24 +01001945 break;
1946 }
Calin Juravle34bacdf2014-10-07 20:23:36 +01001947
1948 default:
Calin Juravleb5bfa962014-10-21 18:02:24 +01001949 LOG(FATAL) << "Unexpected mul type " << mul->GetResultType();
Calin Juravle34bacdf2014-10-07 20:23:36 +01001950 }
1951}
1952
Calin Juravlebacfec32014-11-14 15:54:36 +00001953void InstructionCodeGeneratorX86::GenerateDivRemIntegral(HBinaryOperation* instruction) {
1954 DCHECK(instruction->IsDiv() || instruction->IsRem());
1955
1956 LocationSummary* locations = instruction->GetLocations();
1957 Location out = locations->Out();
1958 Location first = locations->InAt(0);
1959 Location second = locations->InAt(1);
1960 bool is_div = instruction->IsDiv();
1961
1962 switch (instruction->GetResultType()) {
1963 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00001964 Register second_reg = second.AsRegister<Register>();
1965 DCHECK_EQ(EAX, first.AsRegister<Register>());
1966 DCHECK_EQ(is_div ? EAX : EDX, out.AsRegister<Register>());
Calin Juravlebacfec32014-11-14 15:54:36 +00001967
1968 SlowPathCodeX86* slow_path =
Roland Levillain199f3362014-11-27 17:15:16 +00001969 new (GetGraph()->GetArena()) DivRemMinusOneSlowPathX86(out.AsRegister<Register>(),
1970 is_div);
Calin Juravlebacfec32014-11-14 15:54:36 +00001971 codegen_->AddSlowPath(slow_path);
1972
1973 // 0x80000000/-1 triggers an arithmetic exception!
1974 // Dividing by -1 is actually negation and -0x800000000 = 0x80000000 so
1975 // it's safe to just use negl instead of more complex comparisons.
1976
1977 __ cmpl(second_reg, Immediate(-1));
1978 __ j(kEqual, slow_path->GetEntryLabel());
1979
1980 // edx:eax <- sign-extended of eax
1981 __ cdq();
1982 // eax = quotient, edx = remainder
1983 __ idivl(second_reg);
1984
1985 __ Bind(slow_path->GetExitLabel());
1986 break;
1987 }
1988
1989 case Primitive::kPrimLong: {
1990 InvokeRuntimeCallingConvention calling_convention;
1991 DCHECK_EQ(calling_convention.GetRegisterAt(0), first.AsRegisterPairLow<Register>());
1992 DCHECK_EQ(calling_convention.GetRegisterAt(1), first.AsRegisterPairHigh<Register>());
1993 DCHECK_EQ(calling_convention.GetRegisterAt(2), second.AsRegisterPairLow<Register>());
1994 DCHECK_EQ(calling_convention.GetRegisterAt(3), second.AsRegisterPairHigh<Register>());
1995 DCHECK_EQ(EAX, out.AsRegisterPairLow<Register>());
1996 DCHECK_EQ(EDX, out.AsRegisterPairHigh<Register>());
1997
1998 if (is_div) {
1999 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLdiv)));
2000 } else {
2001 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLmod)));
2002 }
2003 uint32_t dex_pc = is_div
2004 ? instruction->AsDiv()->GetDexPc()
2005 : instruction->AsRem()->GetDexPc();
2006 codegen_->RecordPcInfo(instruction, dex_pc);
2007
2008 break;
2009 }
2010
2011 default:
2012 LOG(FATAL) << "Unexpected type for GenerateDivRemIntegral " << instruction->GetResultType();
2013 }
2014}
2015
Calin Juravle7c4954d2014-10-28 16:57:40 +00002016void LocationsBuilderX86::VisitDiv(HDiv* div) {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002017 LocationSummary::CallKind call_kind = div->GetResultType() == Primitive::kPrimLong
2018 ? LocationSummary::kCall
2019 : LocationSummary::kNoCall;
2020 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(div, call_kind);
2021
Calin Juravle7c4954d2014-10-28 16:57:40 +00002022 switch (div->GetResultType()) {
Calin Juravled0d48522014-11-04 16:40:20 +00002023 case Primitive::kPrimInt: {
2024 locations->SetInAt(0, Location::RegisterLocation(EAX));
2025 locations->SetInAt(1, Location::RequiresRegister());
2026 locations->SetOut(Location::SameAsFirstInput());
2027 // Intel uses edx:eax as the dividend.
2028 locations->AddTemp(Location::RegisterLocation(EDX));
2029 break;
2030 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002031 case Primitive::kPrimLong: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002032 InvokeRuntimeCallingConvention calling_convention;
2033 locations->SetInAt(0, Location::RegisterPairLocation(
2034 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2035 locations->SetInAt(1, Location::RegisterPairLocation(
2036 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2037 // Runtime helper puts the result in EAX, EDX.
2038 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
Calin Juravle7c4954d2014-10-28 16:57:40 +00002039 break;
2040 }
2041 case Primitive::kPrimFloat:
2042 case Primitive::kPrimDouble: {
2043 locations->SetInAt(0, Location::RequiresFpuRegister());
2044 locations->SetInAt(1, Location::RequiresFpuRegister());
2045 locations->SetOut(Location::SameAsFirstInput());
2046 break;
2047 }
2048
2049 default:
2050 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2051 }
2052}
2053
2054void InstructionCodeGeneratorX86::VisitDiv(HDiv* div) {
2055 LocationSummary* locations = div->GetLocations();
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002056 Location out = locations->Out();
Calin Juravle7c4954d2014-10-28 16:57:40 +00002057 Location first = locations->InAt(0);
2058 Location second = locations->InAt(1);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002059
2060 switch (div->GetResultType()) {
Calin Juravlebacfec32014-11-14 15:54:36 +00002061 case Primitive::kPrimInt:
Calin Juravle7c4954d2014-10-28 16:57:40 +00002062 case Primitive::kPrimLong: {
Calin Juravlebacfec32014-11-14 15:54:36 +00002063 GenerateDivRemIntegral(div);
Calin Juravle7c4954d2014-10-28 16:57:40 +00002064 break;
2065 }
2066
2067 case Primitive::kPrimFloat: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002068 DCHECK(first.Equals(out));
Roland Levillain271ab9c2014-11-27 15:23:57 +00002069 __ divss(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002070 break;
2071 }
2072
2073 case Primitive::kPrimDouble: {
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002074 DCHECK(first.Equals(out));
Roland Levillain271ab9c2014-11-27 15:23:57 +00002075 __ divsd(first.AsFpuRegister<XmmRegister>(), second.AsFpuRegister<XmmRegister>());
Calin Juravle7c4954d2014-10-28 16:57:40 +00002076 break;
2077 }
2078
2079 default:
2080 LOG(FATAL) << "Unexpected div type " << div->GetResultType();
2081 }
2082}
2083
Calin Juravlebacfec32014-11-14 15:54:36 +00002084void LocationsBuilderX86::VisitRem(HRem* rem) {
2085 LocationSummary::CallKind call_kind = rem->GetResultType() == Primitive::kPrimLong
2086 ? LocationSummary::kCall
2087 : LocationSummary::kNoCall;
2088 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(rem, call_kind);
2089
2090 switch (rem->GetResultType()) {
2091 case Primitive::kPrimInt: {
2092 locations->SetInAt(0, Location::RegisterLocation(EAX));
2093 locations->SetInAt(1, Location::RequiresRegister());
2094 locations->SetOut(Location::RegisterLocation(EDX));
2095 break;
2096 }
2097 case Primitive::kPrimLong: {
2098 InvokeRuntimeCallingConvention calling_convention;
2099 locations->SetInAt(0, Location::RegisterPairLocation(
2100 calling_convention.GetRegisterAt(0), calling_convention.GetRegisterAt(1)));
2101 locations->SetInAt(1, Location::RegisterPairLocation(
2102 calling_convention.GetRegisterAt(2), calling_convention.GetRegisterAt(3)));
2103 // Runtime helper puts the result in EAX, EDX.
2104 locations->SetOut(Location::RegisterPairLocation(EAX, EDX));
2105 break;
2106 }
2107 case Primitive::kPrimFloat:
2108 case Primitive::kPrimDouble: {
2109 LOG(FATAL) << "Unimplemented rem type " << rem->GetResultType();
2110 break;
2111 }
2112
2113 default:
2114 LOG(FATAL) << "Unexpected rem type " << rem->GetResultType();
2115 }
2116}
2117
2118void InstructionCodeGeneratorX86::VisitRem(HRem* rem) {
2119 Primitive::Type type = rem->GetResultType();
2120 switch (type) {
2121 case Primitive::kPrimInt:
2122 case Primitive::kPrimLong: {
2123 GenerateDivRemIntegral(rem);
2124 break;
2125 }
2126 case Primitive::kPrimFloat:
2127 case Primitive::kPrimDouble: {
2128 LOG(FATAL) << "Unimplemented rem type " << type;
2129 break;
2130 }
2131 default:
2132 LOG(FATAL) << "Unexpected rem type " << type;
2133 }
2134}
2135
Calin Juravled0d48522014-11-04 16:40:20 +00002136void LocationsBuilderX86::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2137 LocationSummary* locations =
2138 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002139 switch (instruction->GetType()) {
2140 case Primitive::kPrimInt: {
2141 locations->SetInAt(0, Location::Any());
2142 break;
2143 }
2144 case Primitive::kPrimLong: {
2145 locations->SetInAt(0, Location::RegisterOrConstant(instruction->InputAt(0)));
2146 if (!instruction->IsConstant()) {
2147 locations->AddTemp(Location::RequiresRegister());
2148 }
2149 break;
2150 }
2151 default:
2152 LOG(FATAL) << "Unexpected type for HDivZeroCheck " << instruction->GetType();
2153 }
Calin Juravled0d48522014-11-04 16:40:20 +00002154 if (instruction->HasUses()) {
2155 locations->SetOut(Location::SameAsFirstInput());
2156 }
2157}
2158
2159void InstructionCodeGeneratorX86::VisitDivZeroCheck(HDivZeroCheck* instruction) {
2160 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) DivZeroCheckSlowPathX86(instruction);
2161 codegen_->AddSlowPath(slow_path);
2162
2163 LocationSummary* locations = instruction->GetLocations();
2164 Location value = locations->InAt(0);
2165
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002166 switch (instruction->GetType()) {
2167 case Primitive::kPrimInt: {
2168 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002169 __ testl(value.AsRegister<Register>(), value.AsRegister<Register>());
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002170 __ j(kEqual, slow_path->GetEntryLabel());
2171 } else if (value.IsStackSlot()) {
2172 __ cmpl(Address(ESP, value.GetStackIndex()), Immediate(0));
2173 __ j(kEqual, slow_path->GetEntryLabel());
2174 } else {
2175 DCHECK(value.IsConstant()) << value;
2176 if (value.GetConstant()->AsIntConstant()->GetValue() == 0) {
2177 __ jmp(slow_path->GetEntryLabel());
2178 }
2179 }
2180 break;
Calin Juravled0d48522014-11-04 16:40:20 +00002181 }
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002182 case Primitive::kPrimLong: {
2183 if (value.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002184 Register temp = locations->GetTemp(0).AsRegister<Register>();
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002185 __ movl(temp, value.AsRegisterPairLow<Register>());
2186 __ orl(temp, value.AsRegisterPairHigh<Register>());
2187 __ j(kEqual, slow_path->GetEntryLabel());
2188 } else {
2189 DCHECK(value.IsConstant()) << value;
2190 if (value.GetConstant()->AsLongConstant()->GetValue() == 0) {
2191 __ jmp(slow_path->GetEntryLabel());
2192 }
2193 }
2194 break;
2195 }
2196 default:
2197 LOG(FATAL) << "Unexpected type for HDivZeroCheck" << instruction->GetType();
Calin Juravled0d48522014-11-04 16:40:20 +00002198 }
Calin Juravled0d48522014-11-04 16:40:20 +00002199}
2200
Calin Juravle9aec02f2014-11-18 23:06:35 +00002201void LocationsBuilderX86::HandleShift(HBinaryOperation* op) {
2202 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2203
2204 LocationSummary* locations =
2205 new (GetGraph()->GetArena()) LocationSummary(op, LocationSummary::kNoCall);
2206
2207 switch (op->GetResultType()) {
2208 case Primitive::kPrimInt: {
2209 locations->SetInAt(0, Location::RequiresRegister());
2210 // The shift count needs to be in CL.
2211 locations->SetInAt(1, Location::ByteRegisterOrConstant(ECX, op->InputAt(1)));
2212 locations->SetOut(Location::SameAsFirstInput());
2213 break;
2214 }
2215 case Primitive::kPrimLong: {
2216 locations->SetInAt(0, Location::RequiresRegister());
2217 // The shift count needs to be in CL.
2218 locations->SetInAt(1, Location::RegisterLocation(ECX));
2219 locations->SetOut(Location::SameAsFirstInput());
2220 break;
2221 }
2222 default:
2223 LOG(FATAL) << "Unexpected op type " << op->GetResultType();
2224 }
2225}
2226
2227void InstructionCodeGeneratorX86::HandleShift(HBinaryOperation* op) {
2228 DCHECK(op->IsShl() || op->IsShr() || op->IsUShr());
2229
2230 LocationSummary* locations = op->GetLocations();
2231 Location first = locations->InAt(0);
2232 Location second = locations->InAt(1);
2233 DCHECK(first.Equals(locations->Out()));
2234
2235 switch (op->GetResultType()) {
2236 case Primitive::kPrimInt: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002237 Register first_reg = first.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002238 if (second.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002239 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002240 DCHECK_EQ(ECX, second_reg);
2241 if (op->IsShl()) {
2242 __ shll(first_reg, second_reg);
2243 } else if (op->IsShr()) {
2244 __ sarl(first_reg, second_reg);
2245 } else {
2246 __ shrl(first_reg, second_reg);
2247 }
2248 } else {
2249 Immediate imm(second.GetConstant()->AsIntConstant()->GetValue());
2250 if (op->IsShl()) {
2251 __ shll(first_reg, imm);
2252 } else if (op->IsShr()) {
2253 __ sarl(first_reg, imm);
2254 } else {
2255 __ shrl(first_reg, imm);
2256 }
2257 }
2258 break;
2259 }
2260 case Primitive::kPrimLong: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002261 Register second_reg = second.AsRegister<Register>();
Calin Juravle9aec02f2014-11-18 23:06:35 +00002262 DCHECK_EQ(ECX, second_reg);
2263 if (op->IsShl()) {
2264 GenerateShlLong(first, second_reg);
2265 } else if (op->IsShr()) {
2266 GenerateShrLong(first, second_reg);
2267 } else {
2268 GenerateUShrLong(first, second_reg);
2269 }
2270 break;
2271 }
2272 default:
2273 LOG(FATAL) << "Unexpected op type " << op->GetResultType();
2274 }
2275}
2276
2277void InstructionCodeGeneratorX86::GenerateShlLong(const Location& loc, Register shifter) {
2278 Label done;
2279 __ shld(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>(), shifter);
2280 __ shll(loc.AsRegisterPairLow<Register>(), shifter);
2281 __ testl(shifter, Immediate(32));
2282 __ j(kEqual, &done);
2283 __ movl(loc.AsRegisterPairHigh<Register>(), loc.AsRegisterPairLow<Register>());
2284 __ movl(loc.AsRegisterPairLow<Register>(), Immediate(0));
2285 __ Bind(&done);
2286}
2287
2288void InstructionCodeGeneratorX86::GenerateShrLong(const Location& loc, Register shifter) {
2289 Label done;
2290 __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter);
2291 __ sarl(loc.AsRegisterPairHigh<Register>(), shifter);
2292 __ testl(shifter, Immediate(32));
2293 __ j(kEqual, &done);
2294 __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>());
2295 __ sarl(loc.AsRegisterPairHigh<Register>(), Immediate(31));
2296 __ Bind(&done);
2297}
2298
2299void InstructionCodeGeneratorX86::GenerateUShrLong(const Location& loc, Register shifter) {
2300 Label done;
2301 __ shrd(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>(), shifter);
2302 __ shrl(loc.AsRegisterPairHigh<Register>(), shifter);
2303 __ testl(shifter, Immediate(32));
2304 __ j(kEqual, &done);
2305 __ movl(loc.AsRegisterPairLow<Register>(), loc.AsRegisterPairHigh<Register>());
2306 __ movl(loc.AsRegisterPairHigh<Register>(), Immediate(0));
2307 __ Bind(&done);
2308}
2309
2310void LocationsBuilderX86::VisitShl(HShl* shl) {
2311 HandleShift(shl);
2312}
2313
2314void InstructionCodeGeneratorX86::VisitShl(HShl* shl) {
2315 HandleShift(shl);
2316}
2317
2318void LocationsBuilderX86::VisitShr(HShr* shr) {
2319 HandleShift(shr);
2320}
2321
2322void InstructionCodeGeneratorX86::VisitShr(HShr* shr) {
2323 HandleShift(shr);
2324}
2325
2326void LocationsBuilderX86::VisitUShr(HUShr* ushr) {
2327 HandleShift(ushr);
2328}
2329
2330void InstructionCodeGeneratorX86::VisitUShr(HUShr* ushr) {
2331 HandleShift(ushr);
2332}
2333
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002334void LocationsBuilderX86::VisitNewInstance(HNewInstance* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002335 LocationSummary* locations =
2336 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002337 locations->SetOut(Location::RegisterLocation(EAX));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002338 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002339 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2340 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002341}
2342
2343void InstructionCodeGeneratorX86::VisitNewInstance(HNewInstance* instruction) {
2344 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002345 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002346 __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex()));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002347
Nicolas Geoffray707c8092014-04-04 10:50:14 +01002348 __ fs()->call(
2349 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocObjectWithAccessCheck)));
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002350
Nicolas Geoffray39468442014-09-02 15:17:15 +01002351 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +01002352 DCHECK(!codegen_->IsLeafMethod());
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002353}
2354
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002355void LocationsBuilderX86::VisitNewArray(HNewArray* instruction) {
2356 LocationSummary* locations =
2357 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
2358 locations->SetOut(Location::RegisterLocation(EAX));
2359 InvokeRuntimeCallingConvention calling_convention;
2360 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2361 locations->AddTemp(Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2362 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
2363}
2364
2365void InstructionCodeGeneratorX86::VisitNewArray(HNewArray* instruction) {
2366 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002367 codegen_->LoadCurrentMethod(calling_convention.GetRegisterAt(1));
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002368 __ movl(calling_convention.GetRegisterAt(0), Immediate(instruction->GetTypeIndex()));
2369
2370 __ fs()->call(
2371 Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAllocArrayWithAccessCheck)));
2372
2373 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
2374 DCHECK(!codegen_->IsLeafMethod());
2375}
2376
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002377void LocationsBuilderX86::VisitParameterValue(HParameterValue* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002378 LocationSummary* locations =
2379 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002380 Location location = parameter_visitor_.GetNextLocation(instruction->GetType());
2381 if (location.IsStackSlot()) {
2382 location = Location::StackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
2383 } else if (location.IsDoubleStackSlot()) {
2384 location = Location::DoubleStackSlot(location.GetStackIndex() + codegen_->GetFrameSize());
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002385 }
Nicolas Geoffraya747a392014-04-17 14:56:23 +01002386 locations->SetOut(location);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002387}
2388
2389void InstructionCodeGeneratorX86::VisitParameterValue(HParameterValue* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002390 UNUSED(instruction);
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002391}
2392
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002393void LocationsBuilderX86::VisitNot(HNot* not_) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002394 LocationSummary* locations =
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002395 new (GetGraph()->GetArena()) LocationSummary(not_, LocationSummary::kNoCall);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002396 locations->SetInAt(0, Location::RequiresRegister());
2397 locations->SetOut(Location::SameAsFirstInput());
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002398}
2399
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002400void InstructionCodeGeneratorX86::VisitNot(HNot* not_) {
2401 LocationSummary* locations = not_->GetLocations();
Roland Levillain70566432014-10-24 16:20:17 +01002402 Location in = locations->InAt(0);
Nicolas Geoffraya7aca372014-04-28 17:47:12 +01002403 Location out = locations->Out();
Roland Levillain70566432014-10-24 16:20:17 +01002404 DCHECK(in.Equals(out));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002405 switch (not_->InputAt(0)->GetType()) {
2406 case Primitive::kPrimBoolean:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002407 __ xorl(out.AsRegister<Register>(), Immediate(1));
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002408 break;
2409
2410 case Primitive::kPrimInt:
Roland Levillain271ab9c2014-11-27 15:23:57 +00002411 __ notl(out.AsRegister<Register>());
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002412 break;
2413
2414 case Primitive::kPrimLong:
Roland Levillain70566432014-10-24 16:20:17 +01002415 __ notl(out.AsRegisterPairLow<Register>());
2416 __ notl(out.AsRegisterPairHigh<Register>());
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002417 break;
2418
2419 default:
2420 LOG(FATAL) << "Unimplemented type for not operation " << not_->GetResultType();
2421 }
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002422}
2423
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002424void LocationsBuilderX86::VisitCompare(HCompare* compare) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002425 LocationSummary* locations =
2426 new (GetGraph()->GetArena()) LocationSummary(compare, LocationSummary::kNoCall);
Calin Juravleddb7df22014-11-25 20:56:51 +00002427 switch (compare->InputAt(0)->GetType()) {
2428 case Primitive::kPrimLong: {
2429 locations->SetInAt(0, Location::RequiresRegister());
2430 // TODO: we set any here but we don't handle constants
2431 locations->SetInAt(1, Location::Any());
2432 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
2433 break;
2434 }
2435 case Primitive::kPrimFloat:
2436 case Primitive::kPrimDouble: {
2437 locations->SetInAt(0, Location::RequiresFpuRegister());
2438 locations->SetInAt(1, Location::RequiresFpuRegister());
2439 locations->SetOut(Location::RequiresRegister());
2440 break;
2441 }
2442 default:
2443 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
2444 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002445}
2446
2447void InstructionCodeGeneratorX86::VisitCompare(HCompare* compare) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002448 LocationSummary* locations = compare->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002449 Register out = locations->Out().AsRegister<Register>();
Calin Juravleddb7df22014-11-25 20:56:51 +00002450 Location left = locations->InAt(0);
2451 Location right = locations->InAt(1);
2452
2453 Label less, greater, done;
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002454 switch (compare->InputAt(0)->GetType()) {
2455 case Primitive::kPrimLong: {
Calin Juravleddb7df22014-11-25 20:56:51 +00002456 if (right.IsRegisterPair()) {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002457 __ cmpl(left.AsRegisterPairHigh<Register>(), right.AsRegisterPairHigh<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002458 } else {
2459 DCHECK(right.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002460 __ cmpl(left.AsRegisterPairHigh<Register>(),
2461 Address(ESP, right.GetHighStackIndex(kX86WordSize)));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002462 }
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002463 __ j(kLess, &less); // Signed compare.
2464 __ j(kGreater, &greater); // Signed compare.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002465 if (right.IsRegisterPair()) {
2466 __ cmpl(left.AsRegisterPairLow<Register>(), right.AsRegisterPairLow<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002467 } else {
2468 DCHECK(right.IsDoubleStackSlot());
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002469 __ cmpl(left.AsRegisterPairLow<Register>(), Address(ESP, right.GetStackIndex()));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002470 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002471 break;
2472 }
2473 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002474 __ ucomiss(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002475 __ j(kUnordered, compare->IsGtBias() ? &greater : &less);
2476 break;
2477 }
2478 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002479 __ ucomisd(left.AsFpuRegister<XmmRegister>(), right.AsFpuRegister<XmmRegister>());
Calin Juravleddb7df22014-11-25 20:56:51 +00002480 __ j(kUnordered, compare->IsGtBias() ? &greater : &less);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002481 break;
2482 }
2483 default:
Calin Juravleddb7df22014-11-25 20:56:51 +00002484 LOG(FATAL) << "Unexpected type for compare operation " << compare->InputAt(0)->GetType();
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002485 }
Calin Juravleddb7df22014-11-25 20:56:51 +00002486 __ movl(out, Immediate(0));
2487 __ j(kEqual, &done);
2488 __ j(kBelow, &less); // kBelow is for CF (unsigned & floats).
2489
2490 __ Bind(&greater);
2491 __ movl(out, Immediate(1));
2492 __ jmp(&done);
2493
2494 __ Bind(&less);
2495 __ movl(out, Immediate(-1));
2496
2497 __ Bind(&done);
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01002498}
2499
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002500void LocationsBuilderX86::VisitPhi(HPhi* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002501 LocationSummary* locations =
2502 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray31d76b42014-06-09 15:02:22 +01002503 for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) {
2504 locations->SetInAt(i, Location::Any());
2505 }
2506 locations->SetOut(Location::Any());
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002507}
2508
2509void InstructionCodeGeneratorX86::VisitPhi(HPhi* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002510 UNUSED(instruction);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01002511 LOG(FATAL) << "Unreachable";
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002512}
2513
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002514void LocationsBuilderX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002515 LocationSummary* locations =
2516 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002517 locations->SetInAt(0, Location::RequiresRegister());
Nicolas Geoffray39468442014-09-02 15:17:15 +01002518 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002519 bool needs_write_barrier =
2520 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
2521
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01002522 bool is_byte_type = (field_type == Primitive::kPrimBoolean)
2523 || (field_type == Primitive::kPrimByte);
2524 // The register allocator does not support multiple
2525 // inputs that die at entry with one in a specific register.
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01002526 if (is_byte_type) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002527 // Ensure the value is in a byte register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002528 locations->SetInAt(1, Location::RegisterLocation(EAX));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002529 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002530 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002531 }
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002532 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002533 if (needs_write_barrier) {
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002534 locations->AddTemp(Location::RequiresRegister());
2535 // Ensure the card is in a byte register.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002536 locations->AddTemp(Location::RegisterLocation(ECX));
Nicolas Geoffray1a43dd72014-07-17 15:15:34 +01002537 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002538}
2539
2540void InstructionCodeGeneratorX86::VisitInstanceFieldSet(HInstanceFieldSet* instruction) {
2541 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002542 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002543 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
Nicolas Geoffray39468442014-09-02 15:17:15 +01002544 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002545
2546 switch (field_type) {
2547 case Primitive::kPrimBoolean:
2548 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002549 ByteRegister value = locations->InAt(1).AsRegister<ByteRegister>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002550 __ movb(Address(obj, offset), value);
2551 break;
2552 }
2553
2554 case Primitive::kPrimShort:
2555 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002556 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002557 __ movw(Address(obj, offset), value);
2558 break;
2559 }
2560
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002561 case Primitive::kPrimInt:
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002562 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002563 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002564 __ movl(Address(obj, offset), value);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002565
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002566 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002567 Register temp = locations->GetTemp(0).AsRegister<Register>();
2568 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002569 codegen_->MarkGCCard(temp, card, obj, value);
2570 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002571 break;
2572 }
2573
2574 case Primitive::kPrimLong: {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002575 Location value = locations->InAt(1);
2576 __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>());
2577 __ movl(Address(obj, kX86WordSize + offset), value.AsRegisterPairHigh<Register>());
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002578 break;
2579 }
2580
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002581 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002582 XmmRegister value = locations->InAt(1).AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002583 __ movss(Address(obj, offset), value);
2584 break;
2585 }
2586
2587 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002588 XmmRegister value = locations->InAt(1).AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002589 __ movsd(Address(obj, offset), value);
2590 break;
2591 }
2592
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002593 case Primitive::kPrimVoid:
2594 LOG(FATAL) << "Unreachable type " << field_type;
Ian Rogersfc787ec2014-10-09 21:56:44 -07002595 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002596 }
2597}
2598
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002599void CodeGeneratorX86::MarkGCCard(Register temp, Register card, Register object, Register value) {
2600 Label is_null;
2601 __ testl(value, value);
2602 __ j(kEqual, &is_null);
2603 __ fs()->movl(card, Address::Absolute(Thread::CardTableOffset<kX86WordSize>().Int32Value()));
2604 __ movl(temp, object);
2605 __ shrl(temp, Immediate(gc::accounting::CardTable::kCardShift));
2606 __ movb(Address(temp, card, TIMES_1, 0),
2607 X86ManagedRegister::FromCpuRegister(card).AsByteRegister());
2608 __ Bind(&is_null);
2609}
2610
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002611void LocationsBuilderX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002612 LocationSummary* locations =
2613 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002614 locations->SetInAt(0, Location::RequiresRegister());
2615 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002616}
2617
2618void InstructionCodeGeneratorX86::VisitInstanceFieldGet(HInstanceFieldGet* instruction) {
2619 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002620 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002621 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
2622
2623 switch (instruction->GetType()) {
2624 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002625 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002626 __ movzxb(out, Address(obj, offset));
2627 break;
2628 }
2629
2630 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002631 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002632 __ movsxb(out, Address(obj, offset));
2633 break;
2634 }
2635
2636 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002637 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002638 __ movsxw(out, Address(obj, offset));
2639 break;
2640 }
2641
2642 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002643 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002644 __ movzxw(out, Address(obj, offset));
2645 break;
2646 }
2647
2648 case Primitive::kPrimInt:
2649 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002650 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002651 __ movl(out, Address(obj, offset));
2652 break;
2653 }
2654
2655 case Primitive::kPrimLong: {
2656 // TODO: support volatile.
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002657 __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(obj, offset));
2658 __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(obj, kX86WordSize + offset));
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002659 break;
2660 }
2661
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002662 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002663 XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002664 __ movss(out, Address(obj, offset));
2665 break;
2666 }
2667
2668 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002669 XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00002670 __ movsd(out, Address(obj, offset));
2671 break;
2672 }
2673
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002674 case Primitive::kPrimVoid:
2675 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002676 UNREACHABLE();
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002677 }
2678}
2679
2680void LocationsBuilderX86::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002681 LocationSummary* locations =
2682 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002683 locations->SetInAt(0, Location::Any());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002684 if (instruction->HasUses()) {
2685 locations->SetOut(Location::SameAsFirstInput());
2686 }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002687}
2688
2689void InstructionCodeGeneratorX86::VisitNullCheck(HNullCheck* instruction) {
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01002690 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) NullCheckSlowPathX86(instruction);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002691 codegen_->AddSlowPath(slow_path);
2692
2693 LocationSummary* locations = instruction->GetLocations();
2694 Location obj = locations->InAt(0);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002695
2696 if (obj.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002697 __ cmpl(obj.AsRegister<Register>(), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002698 } else if (obj.IsStackSlot()) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002699 __ cmpl(Address(ESP, obj.GetStackIndex()), Immediate(0));
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002700 } else {
2701 DCHECK(obj.IsConstant()) << obj;
2702 DCHECK_EQ(obj.GetConstant()->AsIntConstant()->GetValue(), 0);
2703 __ jmp(slow_path->GetEntryLabel());
2704 return;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002705 }
2706 __ j(kEqual, slow_path->GetEntryLabel());
2707}
2708
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002709void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002710 LocationSummary* locations =
2711 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002712 locations->SetInAt(0, Location::RequiresRegister());
2713 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
2714 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002715}
2716
2717void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) {
2718 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002719 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002720 Location index = locations->InAt(1);
2721
2722 switch (instruction->GetType()) {
2723 case Primitive::kPrimBoolean: {
2724 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002725 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002726 if (index.IsConstant()) {
2727 __ movzxb(out, Address(obj,
2728 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
2729 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002730 __ movzxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002731 }
2732 break;
2733 }
2734
2735 case Primitive::kPrimByte: {
2736 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int8_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002737 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002738 if (index.IsConstant()) {
2739 __ movsxb(out, Address(obj,
2740 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset));
2741 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002742 __ movsxb(out, Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002743 }
2744 break;
2745 }
2746
2747 case Primitive::kPrimShort: {
2748 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002749 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002750 if (index.IsConstant()) {
2751 __ movsxw(out, Address(obj,
2752 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
2753 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002754 __ movsxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002755 }
2756 break;
2757 }
2758
2759 case Primitive::kPrimChar: {
2760 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002761 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002762 if (index.IsConstant()) {
2763 __ movzxw(out, Address(obj,
2764 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset));
2765 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002766 __ movzxw(out, Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002767 }
2768 break;
2769 }
2770
2771 case Primitive::kPrimInt:
2772 case Primitive::kPrimNot: {
2773 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002774 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002775 if (index.IsConstant()) {
2776 __ movl(out, Address(obj,
2777 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset));
2778 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002779 __ movl(out, Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002780 }
2781 break;
2782 }
2783
2784 case Primitive::kPrimLong: {
2785 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002786 Location out = locations->Out();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002787 if (index.IsConstant()) {
2788 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002789 __ movl(out.AsRegisterPairLow<Register>(), Address(obj, offset));
2790 __ movl(out.AsRegisterPairHigh<Register>(), Address(obj, offset + kX86WordSize));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002791 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002792 __ movl(out.AsRegisterPairLow<Register>(),
Roland Levillain271ab9c2014-11-27 15:23:57 +00002793 Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset));
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002794 __ movl(out.AsRegisterPairHigh<Register>(),
Roland Levillain271ab9c2014-11-27 15:23:57 +00002795 Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002796 }
2797 break;
2798 }
2799
2800 case Primitive::kPrimFloat:
2801 case Primitive::kPrimDouble:
2802 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002803 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002804 case Primitive::kPrimVoid:
2805 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002806 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002807 }
2808}
2809
2810void LocationsBuilderX86::VisitArraySet(HArraySet* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01002811 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002812 bool needs_write_barrier =
2813 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
2814
2815 DCHECK(kFollowsQuickABI);
2816 bool not_enough_registers = needs_write_barrier
2817 && !instruction->GetValue()->IsConstant()
2818 && !instruction->GetIndex()->IsConstant();
2819 bool needs_runtime_call = instruction->NeedsTypeCheck() || not_enough_registers;
2820
Nicolas Geoffray39468442014-09-02 15:17:15 +01002821 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
2822 instruction,
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002823 needs_runtime_call ? LocationSummary::kCall : LocationSummary::kNoCall);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002824
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002825 if (needs_runtime_call) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002826 InvokeRuntimeCallingConvention calling_convention;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002827 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
2828 locations->SetInAt(1, Location::RegisterLocation(calling_convention.GetRegisterAt(1)));
2829 locations->SetInAt(2, Location::RegisterLocation(calling_convention.GetRegisterAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002830 } else {
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01002831 bool is_byte_type = (value_type == Primitive::kPrimBoolean)
2832 || (value_type == Primitive::kPrimByte);
Nicolas Geoffray9ae0daa2014-09-30 22:40:23 +01002833 // We need the inputs to be different than the output in case of long operation.
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01002834 // In case of a byte operation, the register allocator does not support multiple
2835 // inputs that die at entry with one in a specific register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002836 locations->SetInAt(0, Location::RequiresRegister());
2837 locations->SetInAt(1, Location::RegisterOrConstant(instruction->InputAt(1)));
Nicolas Geoffray7adfcc82014-10-07 12:24:52 +01002838 if (is_byte_type) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002839 // Ensure the value is in a byte register.
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002840 locations->SetInAt(2, Location::ByteRegisterOrConstant(EAX, instruction->InputAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002841 } else {
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002842 locations->SetInAt(2, Location::RegisterOrConstant(instruction->InputAt(2)));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002843 }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002844 // Temporary registers for the write barrier.
2845 if (needs_write_barrier) {
2846 locations->AddTemp(Location::RequiresRegister());
2847 // Ensure the card is in a byte register.
2848 locations->AddTemp(Location::RegisterLocation(ECX));
2849 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002850 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002851}
2852
2853void InstructionCodeGeneratorX86::VisitArraySet(HArraySet* instruction) {
2854 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002855 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002856 Location index = locations->InAt(1);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002857 Location value = locations->InAt(2);
Nicolas Geoffray39468442014-09-02 15:17:15 +01002858 Primitive::Type value_type = instruction->GetComponentType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002859 bool needs_runtime_call = locations->WillCall();
2860 bool needs_write_barrier =
2861 CodeGenerator::StoreNeedsWriteBarrier(value_type, instruction->GetValue());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002862
2863 switch (value_type) {
2864 case Primitive::kPrimBoolean:
2865 case Primitive::kPrimByte: {
2866 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint8_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002867 if (index.IsConstant()) {
2868 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_1) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002869 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002870 __ movb(Address(obj, offset), value.AsRegister<ByteRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002871 } else {
2872 __ movb(Address(obj, offset),
2873 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2874 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002875 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002876 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002877 __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset),
2878 value.AsRegister<ByteRegister>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002879 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002880 __ movb(Address(obj, index.AsRegister<Register>(), TIMES_1, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002881 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2882 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002883 }
2884 break;
2885 }
2886
2887 case Primitive::kPrimShort:
2888 case Primitive::kPrimChar: {
2889 uint32_t data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002890 if (index.IsConstant()) {
2891 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_2) + data_offset;
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002892 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002893 __ movw(Address(obj, offset), value.AsRegister<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002894 } else {
2895 __ movw(Address(obj, offset),
2896 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2897 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002898 } else {
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002899 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002900 __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset),
2901 value.AsRegister<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002902 } else {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002903 __ movw(Address(obj, index.AsRegister<Register>(), TIMES_2, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002904 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2905 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002906 }
2907 break;
2908 }
2909
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002910 case Primitive::kPrimInt:
2911 case Primitive::kPrimNot: {
2912 if (!needs_runtime_call) {
2913 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
2914 if (index.IsConstant()) {
Roland Levillain199f3362014-11-27 17:15:16 +00002915 size_t offset =
2916 (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_4) + data_offset;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002917 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002918 __ movl(Address(obj, offset), value.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002919 } else {
2920 DCHECK(value.IsConstant()) << value;
2921 __ movl(Address(obj, offset),
2922 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2923 }
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002924 } else {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002925 DCHECK(index.IsRegister()) << index;
2926 if (value.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002927 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset),
2928 value.AsRegister<Register>());
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002929 } else {
2930 DCHECK(value.IsConstant()) << value;
Roland Levillain271ab9c2014-11-27 15:23:57 +00002931 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_4, data_offset),
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002932 Immediate(value.GetConstant()->AsIntConstant()->GetValue()));
2933 }
2934 }
2935
2936 if (needs_write_barrier) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002937 Register temp = locations->GetTemp(0).AsRegister<Register>();
2938 Register card = locations->GetTemp(1).AsRegister<Register>();
2939 codegen_->MarkGCCard(temp, card, obj, value.AsRegister<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002940 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002941 } else {
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002942 DCHECK_EQ(value_type, Primitive::kPrimNot);
2943 DCHECK(!codegen_->IsLeafMethod());
2944 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pAputObject)));
2945 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002946 }
2947 break;
2948 }
2949
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002950 case Primitive::kPrimLong: {
2951 uint32_t data_offset = mirror::Array::DataOffset(sizeof(int64_t)).Uint32Value();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002952 if (index.IsConstant()) {
2953 size_t offset = (index.GetConstant()->AsIntConstant()->GetValue() << TIMES_8) + data_offset;
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002954 if (value.IsRegisterPair()) {
2955 __ movl(Address(obj, offset), value.AsRegisterPairLow<Register>());
2956 __ movl(Address(obj, offset + kX86WordSize), value.AsRegisterPairHigh<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002957 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002958 DCHECK(value.IsConstant());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002959 int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
2960 __ movl(Address(obj, offset), Immediate(Low32Bits(val)));
2961 __ movl(Address(obj, offset + kX86WordSize), Immediate(High32Bits(val)));
2962 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002963 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002964 if (value.IsRegisterPair()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00002965 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002966 value.AsRegisterPairLow<Register>());
Roland Levillain271ab9c2014-11-27 15:23:57 +00002967 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize),
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002968 value.AsRegisterPairHigh<Register>());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002969 } else {
Nicolas Geoffray56b9ee62014-10-09 11:47:51 +01002970 DCHECK(value.IsConstant());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002971 int64_t val = value.GetConstant()->AsLongConstant()->GetValue();
Roland Levillain271ab9c2014-11-27 15:23:57 +00002972 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002973 Immediate(Low32Bits(val)));
Roland Levillain271ab9c2014-11-27 15:23:57 +00002974 __ movl(Address(obj, index.AsRegister<Register>(), TIMES_8, data_offset + kX86WordSize),
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01002975 Immediate(High32Bits(val)));
2976 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002977 }
2978 break;
2979 }
2980
2981 case Primitive::kPrimFloat:
2982 case Primitive::kPrimDouble:
2983 LOG(FATAL) << "Unimplemented register type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002984 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002985 case Primitive::kPrimVoid:
2986 LOG(FATAL) << "Unreachable type " << instruction->GetType();
Ian Rogersfc787ec2014-10-09 21:56:44 -07002987 UNREACHABLE();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002988 }
2989}
2990
2991void LocationsBuilderX86::VisitArrayLength(HArrayLength* instruction) {
2992 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction);
Nicolas Geoffray8e3964b2014-10-17 11:06:38 +01002993 locations->SetInAt(0, Location::RequiresRegister());
2994 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002995 instruction->SetLocations(locations);
2996}
2997
2998void InstructionCodeGeneratorX86::VisitArrayLength(HArrayLength* instruction) {
2999 LocationSummary* locations = instruction->GetLocations();
3000 uint32_t offset = mirror::Array::LengthOffset().Uint32Value();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003001 Register obj = locations->InAt(0).AsRegister<Register>();
3002 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003003 __ movl(out, Address(obj, offset));
3004}
3005
3006void LocationsBuilderX86::VisitBoundsCheck(HBoundsCheck* instruction) {
Nicolas Geoffray39468442014-09-02 15:17:15 +01003007 LocationSummary* locations =
3008 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003009 locations->SetInAt(0, Location::RequiresRegister());
3010 locations->SetInAt(1, Location::RequiresRegister());
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +01003011 if (instruction->HasUses()) {
3012 locations->SetOut(Location::SameAsFirstInput());
3013 }
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003014}
3015
3016void InstructionCodeGeneratorX86::VisitBoundsCheck(HBoundsCheck* instruction) {
3017 LocationSummary* locations = instruction->GetLocations();
Nicolas Geoffray92a73ae2014-10-16 11:12:52 +01003018 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) BoundsCheckSlowPathX86(
Nicolas Geoffray39468442014-09-02 15:17:15 +01003019 instruction, locations->InAt(0), locations->InAt(1));
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003020 codegen_->AddSlowPath(slow_path);
3021
Roland Levillain271ab9c2014-11-27 15:23:57 +00003022 Register index = locations->InAt(0).AsRegister<Register>();
3023 Register length = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01003024
3025 __ cmpl(index, length);
3026 __ j(kAboveEqual, slow_path->GetEntryLabel());
3027}
3028
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003029void LocationsBuilderX86::VisitTemporary(HTemporary* temp) {
3030 temp->SetLocations(nullptr);
3031}
3032
3033void InstructionCodeGeneratorX86::VisitTemporary(HTemporary* temp) {
3034 // Nothing to do, this is driven by the code generator.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003035 UNUSED(temp);
Nicolas Geoffraye5038322014-07-04 09:41:32 +01003036}
3037
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003038void LocationsBuilderX86::VisitParallelMove(HParallelMove* instruction) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003039 UNUSED(instruction);
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003040 LOG(FATAL) << "Unreachable";
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003041}
3042
3043void InstructionCodeGeneratorX86::VisitParallelMove(HParallelMove* instruction) {
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003044 codegen_->GetMoveResolver()->EmitNativeCode(instruction);
3045}
3046
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003047void LocationsBuilderX86::VisitSuspendCheck(HSuspendCheck* instruction) {
3048 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCallOnSlowPath);
3049}
3050
3051void InstructionCodeGeneratorX86::VisitSuspendCheck(HSuspendCheck* instruction) {
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003052 HBasicBlock* block = instruction->GetBlock();
3053 if (block->GetLoopInformation() != nullptr) {
3054 DCHECK(block->GetLoopInformation()->GetSuspendCheck() == instruction);
3055 // The back edge will generate the suspend check.
3056 return;
3057 }
3058 if (block->IsEntryBlock() && instruction->GetNext()->IsGoto()) {
3059 // The goto will generate the suspend check.
3060 return;
3061 }
3062 GenerateSuspendCheck(instruction, nullptr);
3063}
3064
3065void InstructionCodeGeneratorX86::GenerateSuspendCheck(HSuspendCheck* instruction,
3066 HBasicBlock* successor) {
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003067 SuspendCheckSlowPathX86* slow_path =
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003068 new (GetGraph()->GetArena()) SuspendCheckSlowPathX86(instruction, successor);
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003069 codegen_->AddSlowPath(slow_path);
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003070 __ fs()->cmpw(Address::Absolute(
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003071 Thread::ThreadFlagsOffset<kX86WordSize>().Int32Value()), Immediate(0));
Nicolas Geoffray3c049742014-09-24 18:10:46 +01003072 if (successor == nullptr) {
3073 __ j(kNotEqual, slow_path->GetEntryLabel());
3074 __ Bind(slow_path->GetReturnLabel());
3075 } else {
3076 __ j(kEqual, codegen_->GetLabelOf(successor));
3077 __ jmp(slow_path->GetEntryLabel());
3078 }
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00003079}
3080
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003081X86Assembler* ParallelMoveResolverX86::GetAssembler() const {
3082 return codegen_->GetAssembler();
3083}
3084
3085void ParallelMoveResolverX86::MoveMemoryToMemory(int dst, int src) {
3086 ScratchRegisterScope ensure_scratch(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003087 this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003088 int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0;
3089 __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, src + stack_offset));
3090 __ movl(Address(ESP, dst + stack_offset), static_cast<Register>(ensure_scratch.GetRegister()));
3091}
3092
3093void ParallelMoveResolverX86::EmitMove(size_t index) {
3094 MoveOperands* move = moves_.Get(index);
3095 Location source = move->GetSource();
3096 Location destination = move->GetDestination();
3097
3098 if (source.IsRegister()) {
3099 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003100 __ movl(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003101 } else {
3102 DCHECK(destination.IsStackSlot());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003103 __ movl(Address(ESP, destination.GetStackIndex()), source.AsRegister<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003104 }
3105 } else if (source.IsStackSlot()) {
3106 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003107 __ movl(destination.AsRegister<Register>(), Address(ESP, source.GetStackIndex()));
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003108 } else {
3109 DCHECK(destination.IsStackSlot());
3110 MoveMemoryToMemory(destination.GetStackIndex(),
3111 source.GetStackIndex());
3112 }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003113 } else if (source.IsConstant()) {
3114 HIntConstant* instruction = source.GetConstant()->AsIntConstant();
3115 Immediate imm(instruction->AsIntConstant()->GetValue());
3116 if (destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003117 __ movl(destination.AsRegister<Register>(), imm);
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01003118 } else {
3119 __ movl(Address(ESP, destination.GetStackIndex()), imm);
3120 }
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003121 } else {
3122 LOG(FATAL) << "Unimplemented";
3123 }
3124}
3125
3126void ParallelMoveResolverX86::Exchange(Register reg, int mem) {
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003127 Register suggested_scratch = reg == EAX ? EBX : EAX;
3128 ScratchRegisterScope ensure_scratch(
3129 this, reg, suggested_scratch, codegen_->GetNumberOfCoreRegisters());
3130
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003131 int stack_offset = ensure_scratch.IsSpilled() ? kX86WordSize : 0;
3132 __ movl(static_cast<Register>(ensure_scratch.GetRegister()), Address(ESP, mem + stack_offset));
3133 __ movl(Address(ESP, mem + stack_offset), reg);
3134 __ movl(reg, static_cast<Register>(ensure_scratch.GetRegister()));
3135}
3136
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003137void ParallelMoveResolverX86::Exchange(int mem1, int mem2) {
3138 ScratchRegisterScope ensure_scratch1(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003139 this, kNoRegister, EAX, codegen_->GetNumberOfCoreRegisters());
3140
3141 Register suggested_scratch = ensure_scratch1.GetRegister() == EAX ? EBX : EAX;
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003142 ScratchRegisterScope ensure_scratch2(
Nicolas Geoffraye27f31a2014-06-12 17:53:14 +01003143 this, ensure_scratch1.GetRegister(), suggested_scratch, codegen_->GetNumberOfCoreRegisters());
3144
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003145 int stack_offset = ensure_scratch1.IsSpilled() ? kX86WordSize : 0;
3146 stack_offset += ensure_scratch2.IsSpilled() ? kX86WordSize : 0;
3147 __ movl(static_cast<Register>(ensure_scratch1.GetRegister()), Address(ESP, mem1 + stack_offset));
3148 __ movl(static_cast<Register>(ensure_scratch2.GetRegister()), Address(ESP, mem2 + stack_offset));
3149 __ movl(Address(ESP, mem2 + stack_offset), static_cast<Register>(ensure_scratch1.GetRegister()));
3150 __ movl(Address(ESP, mem1 + stack_offset), static_cast<Register>(ensure_scratch2.GetRegister()));
3151}
3152
3153void ParallelMoveResolverX86::EmitSwap(size_t index) {
3154 MoveOperands* move = moves_.Get(index);
3155 Location source = move->GetSource();
3156 Location destination = move->GetDestination();
3157
3158 if (source.IsRegister() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003159 __ xchgl(destination.AsRegister<Register>(), source.AsRegister<Register>());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003160 } else if (source.IsRegister() && destination.IsStackSlot()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003161 Exchange(source.AsRegister<Register>(), destination.GetStackIndex());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003162 } else if (source.IsStackSlot() && destination.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003163 Exchange(destination.AsRegister<Register>(), source.GetStackIndex());
Nicolas Geoffray86dbb9a2014-06-04 11:12:39 +01003164 } else if (source.IsStackSlot() && destination.IsStackSlot()) {
3165 Exchange(destination.GetStackIndex(), source.GetStackIndex());
3166 } else {
3167 LOG(FATAL) << "Unimplemented";
3168 }
3169}
3170
3171void ParallelMoveResolverX86::SpillScratch(int reg) {
3172 __ pushl(static_cast<Register>(reg));
3173}
3174
3175void ParallelMoveResolverX86::RestoreScratch(int reg) {
3176 __ popl(static_cast<Register>(reg));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003177}
3178
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003179void LocationsBuilderX86::VisitLoadClass(HLoadClass* cls) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003180 LocationSummary::CallKind call_kind = cls->CanCallRuntime()
3181 ? LocationSummary::kCallOnSlowPath
3182 : LocationSummary::kNoCall;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003183 LocationSummary* locations =
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003184 new (GetGraph()->GetArena()) LocationSummary(cls, call_kind);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003185 locations->SetOut(Location::RequiresRegister());
3186}
3187
3188void InstructionCodeGeneratorX86::VisitLoadClass(HLoadClass* cls) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003189 Register out = cls->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003190 if (cls->IsReferrersClass()) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003191 DCHECK(!cls->CanCallRuntime());
3192 DCHECK(!cls->MustGenerateClinitCheck());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003193 codegen_->LoadCurrentMethod(out);
3194 __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()));
3195 } else {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003196 DCHECK(cls->CanCallRuntime());
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003197 codegen_->LoadCurrentMethod(out);
3198 __ movl(out, Address(out, mirror::ArtMethod::DexCacheResolvedTypesOffset().Int32Value()));
3199 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(cls->GetTypeIndex())));
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003200
3201 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86(
3202 cls, cls, cls->GetDexPc(), cls->MustGenerateClinitCheck());
3203 codegen_->AddSlowPath(slow_path);
3204 __ testl(out, out);
3205 __ j(kEqual, slow_path->GetEntryLabel());
3206 if (cls->MustGenerateClinitCheck()) {
3207 GenerateClassInitializationCheck(slow_path, out);
3208 } else {
3209 __ Bind(slow_path->GetExitLabel());
3210 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003211 }
3212}
3213
3214void LocationsBuilderX86::VisitClinitCheck(HClinitCheck* check) {
3215 LocationSummary* locations =
3216 new (GetGraph()->GetArena()) LocationSummary(check, LocationSummary::kCallOnSlowPath);
3217 locations->SetInAt(0, Location::RequiresRegister());
3218 if (check->HasUses()) {
3219 locations->SetOut(Location::SameAsFirstInput());
3220 }
3221}
3222
3223void InstructionCodeGeneratorX86::VisitClinitCheck(HClinitCheck* check) {
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003224 // We assume the class to not be null.
3225 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadClassSlowPathX86(
3226 check->GetLoadClass(), check, check->GetDexPc(), true);
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003227 codegen_->AddSlowPath(slow_path);
Roland Levillain199f3362014-11-27 17:15:16 +00003228 GenerateClassInitializationCheck(slow_path,
3229 check->GetLocations()->InAt(0).AsRegister<Register>());
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003230}
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003231
Nicolas Geoffray424f6762014-11-03 14:51:25 +00003232void InstructionCodeGeneratorX86::GenerateClassInitializationCheck(
3233 SlowPathCodeX86* slow_path, Register class_reg) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003234 __ cmpl(Address(class_reg, mirror::Class::StatusOffset().Int32Value()),
3235 Immediate(mirror::Class::kStatusInitialized));
3236 __ j(kLess, slow_path->GetEntryLabel());
3237 __ Bind(slow_path->GetExitLabel());
3238 // No need for memory fence, thanks to the X86 memory model.
3239}
3240
3241void LocationsBuilderX86::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3242 LocationSummary* locations =
3243 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3244 locations->SetInAt(0, Location::RequiresRegister());
3245 locations->SetOut(Location::RequiresRegister(), Location::kNoOutputOverlap);
3246}
3247
3248void InstructionCodeGeneratorX86::VisitStaticFieldGet(HStaticFieldGet* instruction) {
3249 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003250 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003251 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3252
3253 switch (instruction->GetType()) {
3254 case Primitive::kPrimBoolean: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003255 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003256 __ movzxb(out, Address(cls, offset));
3257 break;
3258 }
3259
3260 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003261 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003262 __ movsxb(out, Address(cls, offset));
3263 break;
3264 }
3265
3266 case Primitive::kPrimShort: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003267 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003268 __ movsxw(out, Address(cls, offset));
3269 break;
3270 }
3271
3272 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003273 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003274 __ movzxw(out, Address(cls, offset));
3275 break;
3276 }
3277
3278 case Primitive::kPrimInt:
3279 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003280 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003281 __ movl(out, Address(cls, offset));
3282 break;
3283 }
3284
3285 case Primitive::kPrimLong: {
3286 // TODO: support volatile.
3287 __ movl(locations->Out().AsRegisterPairLow<Register>(), Address(cls, offset));
3288 __ movl(locations->Out().AsRegisterPairHigh<Register>(), Address(cls, kX86WordSize + offset));
3289 break;
3290 }
3291
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003292 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003293 XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003294 __ movss(out, Address(cls, offset));
3295 break;
3296 }
3297
3298 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003299 XmmRegister out = locations->Out().AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003300 __ movsd(out, Address(cls, offset));
3301 break;
3302 }
3303
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003304 case Primitive::kPrimVoid:
3305 LOG(FATAL) << "Unreachable type " << instruction->GetType();
3306 UNREACHABLE();
3307 }
3308}
3309
3310void LocationsBuilderX86::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3311 LocationSummary* locations =
3312 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3313 locations->SetInAt(0, Location::RequiresRegister());
3314 Primitive::Type field_type = instruction->GetFieldType();
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003315 bool needs_write_barrier =
3316 CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1));
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003317 bool is_byte_type = (field_type == Primitive::kPrimBoolean)
3318 || (field_type == Primitive::kPrimByte);
3319 // The register allocator does not support multiple
3320 // inputs that die at entry with one in a specific register.
3321 if (is_byte_type) {
3322 // Ensure the value is in a byte register.
3323 locations->SetInAt(1, Location::RegisterLocation(EAX));
3324 } else {
3325 locations->SetInAt(1, Location::RequiresRegister());
3326 }
3327 // Temporary registers for the write barrier.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003328 if (needs_write_barrier) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003329 locations->AddTemp(Location::RequiresRegister());
3330 // Ensure the card is in a byte register.
3331 locations->AddTemp(Location::RegisterLocation(ECX));
3332 }
3333}
3334
3335void InstructionCodeGeneratorX86::VisitStaticFieldSet(HStaticFieldSet* instruction) {
3336 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003337 Register cls = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003338 uint32_t offset = instruction->GetFieldOffset().Uint32Value();
3339 Primitive::Type field_type = instruction->GetFieldType();
3340
3341 switch (field_type) {
3342 case Primitive::kPrimBoolean:
3343 case Primitive::kPrimByte: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003344 ByteRegister value = locations->InAt(1).AsRegister<ByteRegister>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003345 __ movb(Address(cls, offset), value);
3346 break;
3347 }
3348
3349 case Primitive::kPrimShort:
3350 case Primitive::kPrimChar: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003351 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003352 __ movw(Address(cls, offset), value);
3353 break;
3354 }
3355
3356 case Primitive::kPrimInt:
3357 case Primitive::kPrimNot: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003358 Register value = locations->InAt(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003359 __ movl(Address(cls, offset), value);
3360
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00003361 if (CodeGenerator::StoreNeedsWriteBarrier(field_type, instruction->InputAt(1))) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003362 Register temp = locations->GetTemp(0).AsRegister<Register>();
3363 Register card = locations->GetTemp(1).AsRegister<Register>();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003364 codegen_->MarkGCCard(temp, card, cls, value);
3365 }
3366 break;
3367 }
3368
3369 case Primitive::kPrimLong: {
3370 Location value = locations->InAt(1);
3371 __ movl(Address(cls, offset), value.AsRegisterPairLow<Register>());
3372 __ movl(Address(cls, kX86WordSize + offset), value.AsRegisterPairHigh<Register>());
3373 break;
3374 }
3375
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003376 case Primitive::kPrimFloat: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003377 XmmRegister value = locations->InAt(1).AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003378 __ movss(Address(cls, offset), value);
3379 break;
3380 }
3381
3382 case Primitive::kPrimDouble: {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003383 XmmRegister value = locations->InAt(1).AsFpuRegister<XmmRegister>();
Nicolas Geoffray52e832b2014-11-06 15:15:31 +00003384 __ movsd(Address(cls, offset), value);
3385 break;
3386 }
3387
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01003388 case Primitive::kPrimVoid:
3389 LOG(FATAL) << "Unreachable type " << field_type;
3390 UNREACHABLE();
3391 }
3392}
3393
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003394void LocationsBuilderX86::VisitLoadString(HLoadString* load) {
3395 LocationSummary* locations =
3396 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kCallOnSlowPath);
3397 locations->SetOut(Location::RequiresRegister());
3398}
3399
3400void InstructionCodeGeneratorX86::VisitLoadString(HLoadString* load) {
3401 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) LoadStringSlowPathX86(load);
3402 codegen_->AddSlowPath(slow_path);
3403
Roland Levillain271ab9c2014-11-27 15:23:57 +00003404 Register out = load->GetLocations()->Out().AsRegister<Register>();
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003405 codegen_->LoadCurrentMethod(out);
Mathieu Chartiereace4582014-11-24 18:29:54 -08003406 __ movl(out, Address(out, mirror::ArtMethod::DeclaringClassOffset().Int32Value()));
3407 __ movl(out, Address(out, mirror::Class::DexCacheStringsOffset().Int32Value()));
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00003408 __ movl(out, Address(out, CodeGenerator::GetCacheOffset(load->GetStringIndex())));
3409 __ testl(out, out);
3410 __ j(kEqual, slow_path->GetEntryLabel());
3411 __ Bind(slow_path->GetExitLabel());
3412}
3413
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003414void LocationsBuilderX86::VisitLoadException(HLoadException* load) {
3415 LocationSummary* locations =
3416 new (GetGraph()->GetArena()) LocationSummary(load, LocationSummary::kNoCall);
3417 locations->SetOut(Location::RequiresRegister());
3418}
3419
3420void InstructionCodeGeneratorX86::VisitLoadException(HLoadException* load) {
3421 Address address = Address::Absolute(Thread::ExceptionOffset<kX86WordSize>().Int32Value());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003422 __ fs()->movl(load->GetLocations()->Out().AsRegister<Register>(), address);
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00003423 __ fs()->movl(address, Immediate(0));
3424}
3425
3426void LocationsBuilderX86::VisitThrow(HThrow* instruction) {
3427 LocationSummary* locations =
3428 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3429 InvokeRuntimeCallingConvention calling_convention;
3430 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3431}
3432
3433void InstructionCodeGeneratorX86::VisitThrow(HThrow* instruction) {
3434 __ fs()->call(Address::Absolute(QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pDeliverException)));
3435 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3436}
3437
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003438void LocationsBuilderX86::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003439 LocationSummary::CallKind call_kind = instruction->IsClassFinal()
3440 ? LocationSummary::kNoCall
3441 : LocationSummary::kCallOnSlowPath;
3442 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(instruction, call_kind);
3443 locations->SetInAt(0, Location::RequiresRegister());
3444 locations->SetInAt(1, Location::Any());
3445 locations->SetOut(Location::RequiresRegister());
3446}
3447
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003448void InstructionCodeGeneratorX86::VisitInstanceOf(HInstanceOf* instruction) {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003449 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003450 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003451 Location cls = locations->InAt(1);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003452 Register out = locations->Out().AsRegister<Register>();
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003453 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3454 Label done, zero;
3455 SlowPathCodeX86* slow_path = nullptr;
3456
3457 // Return 0 if `obj` is null.
3458 // TODO: avoid this check if we know obj is not null.
3459 __ testl(obj, obj);
3460 __ j(kEqual, &zero);
3461 __ movl(out, Address(obj, class_offset));
3462 // Compare the class of `obj` with `cls`.
3463 if (cls.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003464 __ cmpl(out, cls.AsRegister<Register>());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003465 } else {
3466 DCHECK(cls.IsStackSlot()) << cls;
3467 __ cmpl(out, Address(ESP, cls.GetStackIndex()));
3468 }
3469
3470 if (instruction->IsClassFinal()) {
3471 // Classes must be equal for the instanceof to succeed.
3472 __ j(kNotEqual, &zero);
3473 __ movl(out, Immediate(1));
3474 __ jmp(&done);
3475 } else {
3476 // If the classes are not equal, we go into a slow path.
3477 DCHECK(locations->OnlyCallsOnSlowPath());
3478 slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003479 instruction, locations->InAt(1), locations->Out(), instruction->GetDexPc());
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003480 codegen_->AddSlowPath(slow_path);
3481 __ j(kNotEqual, slow_path->GetEntryLabel());
3482 __ movl(out, Immediate(1));
3483 __ jmp(&done);
3484 }
3485 __ Bind(&zero);
3486 __ movl(out, Immediate(0));
3487 if (slow_path != nullptr) {
3488 __ Bind(slow_path->GetExitLabel());
3489 }
3490 __ Bind(&done);
3491}
3492
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003493void LocationsBuilderX86::VisitCheckCast(HCheckCast* instruction) {
3494 LocationSummary* locations = new (GetGraph()->GetArena()) LocationSummary(
3495 instruction, LocationSummary::kCallOnSlowPath);
3496 locations->SetInAt(0, Location::RequiresRegister());
3497 locations->SetInAt(1, Location::Any());
3498 locations->AddTemp(Location::RequiresRegister());
3499}
3500
3501void InstructionCodeGeneratorX86::VisitCheckCast(HCheckCast* instruction) {
3502 LocationSummary* locations = instruction->GetLocations();
Roland Levillain271ab9c2014-11-27 15:23:57 +00003503 Register obj = locations->InAt(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003504 Location cls = locations->InAt(1);
Roland Levillain271ab9c2014-11-27 15:23:57 +00003505 Register temp = locations->GetTemp(0).AsRegister<Register>();
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003506 uint32_t class_offset = mirror::Object::ClassOffset().Int32Value();
3507 SlowPathCodeX86* slow_path = new (GetGraph()->GetArena()) TypeCheckSlowPathX86(
3508 instruction, locations->InAt(1), locations->GetTemp(0), instruction->GetDexPc());
3509 codegen_->AddSlowPath(slow_path);
3510
3511 // TODO: avoid this check if we know obj is not null.
3512 __ testl(obj, obj);
3513 __ j(kEqual, slow_path->GetExitLabel());
3514 __ movl(temp, Address(obj, class_offset));
3515
3516 // Compare the class of `obj` with `cls`.
3517 if (cls.IsRegister()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003518 __ cmpl(temp, cls.AsRegister<Register>());
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003519 } else {
3520 DCHECK(cls.IsStackSlot()) << cls;
3521 __ cmpl(temp, Address(ESP, cls.GetStackIndex()));
3522 }
3523
3524 __ j(kNotEqual, slow_path->GetEntryLabel());
3525 __ Bind(slow_path->GetExitLabel());
3526}
3527
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003528void LocationsBuilderX86::VisitMonitorOperation(HMonitorOperation* instruction) {
3529 LocationSummary* locations =
3530 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kCall);
3531 InvokeRuntimeCallingConvention calling_convention;
3532 locations->SetInAt(0, Location::RegisterLocation(calling_convention.GetRegisterAt(0)));
3533}
3534
3535void InstructionCodeGeneratorX86::VisitMonitorOperation(HMonitorOperation* instruction) {
3536 __ fs()->call(Address::Absolute(instruction->IsEnter()
3537 ? QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pLockObject)
3538 : QUICK_ENTRYPOINT_OFFSET(kX86WordSize, pUnlockObject)));
3539 codegen_->RecordPcInfo(instruction, instruction->GetDexPc());
3540}
3541
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003542void LocationsBuilderX86::VisitAnd(HAnd* instruction) { HandleBitwiseOperation(instruction); }
3543void LocationsBuilderX86::VisitOr(HOr* instruction) { HandleBitwiseOperation(instruction); }
3544void LocationsBuilderX86::VisitXor(HXor* instruction) { HandleBitwiseOperation(instruction); }
3545
3546void LocationsBuilderX86::HandleBitwiseOperation(HBinaryOperation* instruction) {
3547 LocationSummary* locations =
3548 new (GetGraph()->GetArena()) LocationSummary(instruction, LocationSummary::kNoCall);
3549 DCHECK(instruction->GetResultType() == Primitive::kPrimInt
3550 || instruction->GetResultType() == Primitive::kPrimLong);
3551 locations->SetInAt(0, Location::RequiresRegister());
3552 locations->SetInAt(1, Location::Any());
3553 locations->SetOut(Location::SameAsFirstInput());
3554}
3555
3556void InstructionCodeGeneratorX86::VisitAnd(HAnd* instruction) {
3557 HandleBitwiseOperation(instruction);
3558}
3559
3560void InstructionCodeGeneratorX86::VisitOr(HOr* instruction) {
3561 HandleBitwiseOperation(instruction);
3562}
3563
3564void InstructionCodeGeneratorX86::VisitXor(HXor* instruction) {
3565 HandleBitwiseOperation(instruction);
3566}
3567
3568void InstructionCodeGeneratorX86::HandleBitwiseOperation(HBinaryOperation* instruction) {
3569 LocationSummary* locations = instruction->GetLocations();
3570 Location first = locations->InAt(0);
3571 Location second = locations->InAt(1);
3572 DCHECK(first.Equals(locations->Out()));
3573
3574 if (instruction->GetResultType() == Primitive::kPrimInt) {
3575 if (second.IsRegister()) {
3576 if (instruction->IsAnd()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003577 __ andl(first.AsRegister<Register>(), second.AsRegister<Register>());
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003578 } else if (instruction->IsOr()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003579 __ orl(first.AsRegister<Register>(), second.AsRegister<Register>());
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003580 } else {
3581 DCHECK(instruction->IsXor());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003582 __ xorl(first.AsRegister<Register>(), second.AsRegister<Register>());
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003583 }
3584 } else if (second.IsConstant()) {
3585 if (instruction->IsAnd()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003586 __ andl(first.AsRegister<Register>(),
3587 Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003588 } else if (instruction->IsOr()) {
Roland Levillain199f3362014-11-27 17:15:16 +00003589 __ orl(first.AsRegister<Register>(),
3590 Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003591 } else {
3592 DCHECK(instruction->IsXor());
Roland Levillain199f3362014-11-27 17:15:16 +00003593 __ xorl(first.AsRegister<Register>(),
3594 Immediate(second.GetConstant()->AsIntConstant()->GetValue()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003595 }
3596 } else {
3597 if (instruction->IsAnd()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003598 __ andl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003599 } else if (instruction->IsOr()) {
Roland Levillain271ab9c2014-11-27 15:23:57 +00003600 __ orl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003601 } else {
3602 DCHECK(instruction->IsXor());
Roland Levillain271ab9c2014-11-27 15:23:57 +00003603 __ xorl(first.AsRegister<Register>(), Address(ESP, second.GetStackIndex()));
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00003604 }
3605 }
3606 } else {
3607 DCHECK_EQ(instruction->GetResultType(), Primitive::kPrimLong);
3608 if (second.IsRegisterPair()) {
3609 if (instruction->IsAnd()) {
3610 __ andl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
3611 __ andl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
3612 } else if (instruction->IsOr()) {
3613 __ orl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
3614 __ orl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
3615 } else {
3616 DCHECK(instruction->IsXor());
3617 __ xorl(first.AsRegisterPairLow<Register>(), second.AsRegisterPairLow<Register>());
3618 __ xorl(first.AsRegisterPairHigh<Register>(), second.AsRegisterPairHigh<Register>());
3619 }
3620 } else {
3621 if (instruction->IsAnd()) {
3622 __ andl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
3623 __ andl(first.AsRegisterPairHigh<Register>(),
3624 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
3625 } else if (instruction->IsOr()) {
3626 __ orl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
3627 __ orl(first.AsRegisterPairHigh<Register>(),
3628 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
3629 } else {
3630 DCHECK(instruction->IsXor());
3631 __ xorl(first.AsRegisterPairLow<Register>(), Address(ESP, second.GetStackIndex()));
3632 __ xorl(first.AsRegisterPairHigh<Register>(),
3633 Address(ESP, second.GetHighStackIndex(kX86WordSize)));
3634 }
3635 }
3636 }
3637}
3638
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003639} // namespace x86
3640} // namespace art