blob: b6442feb69e4491affb45dba41b0548a957116bb [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 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 */
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_
18#define ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070019
Ian Rogers0d666d82011-08-14 16:03:46 -070020#include <vector>
Vladimir Marko93205e32016-04-13 11:59:46 +010021
22#include "base/arena_containers.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010023#include "base/bit_utils.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070024#include "base/enums.h"
Elliott Hughes76160052012-12-12 16:31:20 -080025#include "base/macros.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070026#include "constants_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "globals.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -070028#include "managed_register_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070029#include "offsets.h"
Vladimir Marko93205e32016-04-13 11:59:46 +010030#include "utils/array_ref.h"
Ian Rogers166db042013-07-26 12:05:57 -070031#include "utils/assembler.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070032#include "utils/jni_macro_assembler.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070034namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070035namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070036
Ian Rogerscf7f1912014-10-22 22:06:39 -070037class Immediate : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070038 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080039 explicit Immediate(int32_t value_in) : value_(value_in) {}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070040
41 int32_t value() const { return value_; }
42
Andreas Gampeab1eb0d2015-02-13 19:23:55 -080043 bool is_int8() const { return IsInt<8>(value_); }
44 bool is_uint8() const { return IsUint<8>(value_); }
45 bool is_int16() const { return IsInt<16>(value_); }
46 bool is_uint16() const { return IsUint<16>(value_); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070047
48 private:
49 const int32_t value_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070050};
51
52
Ian Rogerscf7f1912014-10-22 22:06:39 -070053class Operand : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070054 public:
55 uint8_t mod() const {
56 return (encoding_at(0) >> 6) & 3;
57 }
58
59 Register rm() const {
60 return static_cast<Register>(encoding_at(0) & 7);
61 }
62
63 ScaleFactor scale() const {
64 return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
65 }
66
67 Register index() const {
68 return static_cast<Register>((encoding_at(1) >> 3) & 7);
69 }
70
71 Register base() const {
72 return static_cast<Register>(encoding_at(1) & 7);
73 }
74
75 int8_t disp8() const {
76 CHECK_GE(length_, 2);
77 return static_cast<int8_t>(encoding_[length_ - 1]);
78 }
79
80 int32_t disp32() const {
81 CHECK_GE(length_, 5);
82 int32_t value;
83 memcpy(&value, &encoding_[length_ - 4], sizeof(value));
84 return value;
85 }
86
87 bool IsRegister(Register reg) const {
88 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only.
89 && ((encoding_[0] & 0x07) == reg); // Register codes match.
90 }
91
92 protected:
93 // Operand can be sub classed (e.g: Address).
Mark Mendell0616ae02015-04-17 12:49:27 -040094 Operand() : length_(0), fixup_(nullptr) { }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070095
Andreas Gampe277ccbd2014-11-03 21:36:10 -080096 void SetModRM(int mod_in, Register rm_in) {
97 CHECK_EQ(mod_in & ~3, 0);
98 encoding_[0] = (mod_in << 6) | rm_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070099 length_ = 1;
100 }
101
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800102 void SetSIB(ScaleFactor scale_in, Register index_in, Register base_in) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700103 CHECK_EQ(length_, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800104 CHECK_EQ(scale_in & ~3, 0);
105 encoding_[1] = (scale_in << 6) | (index_in << 3) | base_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700106 length_ = 2;
107 }
108
109 void SetDisp8(int8_t disp) {
110 CHECK(length_ == 1 || length_ == 2);
111 encoding_[length_++] = static_cast<uint8_t>(disp);
112 }
113
114 void SetDisp32(int32_t disp) {
115 CHECK(length_ == 1 || length_ == 2);
116 int disp_size = sizeof(disp);
117 memmove(&encoding_[length_], &disp, disp_size);
118 length_ += disp_size;
119 }
120
Mark Mendell0616ae02015-04-17 12:49:27 -0400121 AssemblerFixup* GetFixup() const {
122 return fixup_;
123 }
124
125 void SetFixup(AssemblerFixup* fixup) {
126 fixup_ = fixup;
127 }
128
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700129 private:
Ian Rogers13735952014-10-08 12:43:28 -0700130 uint8_t length_;
131 uint8_t encoding_[6];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700132
Mark Mendell0616ae02015-04-17 12:49:27 -0400133 // A fixup can be associated with the operand, in order to be applied after the
134 // code has been generated. This is used for constant area fixups.
135 AssemblerFixup* fixup_;
136
137 explicit Operand(Register reg) : fixup_(nullptr) { SetModRM(3, reg); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700138
139 // Get the operand encoding byte at the given index.
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800140 uint8_t encoding_at(int index_in) const {
141 CHECK_GE(index_in, 0);
142 CHECK_LT(index_in, length_);
143 return encoding_[index_in];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700144 }
145
Ian Rogers2c8f6532011-09-02 17:16:34 -0700146 friend class X86Assembler;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700147};
148
149
150class Address : public Operand {
151 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800152 Address(Register base_in, int32_t disp) {
153 Init(base_in, disp);
Ian Rogersb033c752011-07-20 12:22:35 -0700154 }
155
Mark Mendell0616ae02015-04-17 12:49:27 -0400156 Address(Register base_in, int32_t disp, AssemblerFixup *fixup) {
157 Init(base_in, disp);
158 SetFixup(fixup);
159 }
160
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800161 Address(Register base_in, Offset disp) {
162 Init(base_in, disp.Int32Value());
Ian Rogersa04d3972011-08-17 11:33:44 -0700163 }
164
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800165 Address(Register base_in, FrameOffset disp) {
166 CHECK_EQ(base_in, ESP);
Ian Rogersb033c752011-07-20 12:22:35 -0700167 Init(ESP, disp.Int32Value());
168 }
169
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800170 Address(Register base_in, MemberOffset disp) {
171 Init(base_in, disp.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700172 }
173
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800174 Address(Register index_in, ScaleFactor scale_in, int32_t disp) {
175 CHECK_NE(index_in, ESP); // Illegal addressing mode.
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700176 SetModRM(0, ESP);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800177 SetSIB(scale_in, index_in, EBP);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700178 SetDisp32(disp);
179 }
180
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800181 Address(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
Mark Mendell805b3b52015-09-18 14:10:29 -0400182 Init(base_in, index_in, scale_in, disp);
183 }
184
185 Address(Register base_in,
186 Register index_in,
187 ScaleFactor scale_in,
188 int32_t disp, AssemblerFixup *fixup) {
189 Init(base_in, index_in, scale_in, disp);
190 SetFixup(fixup);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700191 }
192
Ian Rogers13735952014-10-08 12:43:28 -0700193 static Address Absolute(uintptr_t addr) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700194 Address result;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700195 result.SetModRM(0, EBP);
196 result.SetDisp32(addr);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700197 return result;
198 }
199
Andreas Gampe542451c2016-07-26 09:02:02 -0700200 static Address Absolute(ThreadOffset32 addr) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700201 return Absolute(addr.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700202 }
203
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700204 private:
205 Address() {}
Mark Mendell805b3b52015-09-18 14:10:29 -0400206
207 void Init(Register base_in, int32_t disp) {
208 if (disp == 0 && base_in != EBP) {
209 SetModRM(0, base_in);
210 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
211 } else if (disp >= -128 && disp <= 127) {
212 SetModRM(1, base_in);
213 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
214 SetDisp8(disp);
215 } else {
216 SetModRM(2, base_in);
217 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
218 SetDisp32(disp);
219 }
220 }
221
222 void Init(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
223 CHECK_NE(index_in, ESP); // Illegal addressing mode.
224 if (disp == 0 && base_in != EBP) {
225 SetModRM(0, ESP);
226 SetSIB(scale_in, index_in, base_in);
227 } else if (disp >= -128 && disp <= 127) {
228 SetModRM(1, ESP);
229 SetSIB(scale_in, index_in, base_in);
230 SetDisp8(disp);
231 } else {
232 SetModRM(2, ESP);
233 SetSIB(scale_in, index_in, base_in);
234 SetDisp32(disp);
235 }
236 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700237};
238
239
Mark Mendell73f455e2015-08-21 09:30:05 -0400240// This is equivalent to the Label class, used in a slightly different context. We
241// inherit the functionality of the Label class, but prevent unintended
242// derived-to-base conversions by making the base class private.
243class NearLabel : private Label {
244 public:
245 NearLabel() : Label() {}
246
247 // Expose the Label routines that we need.
248 using Label::Position;
249 using Label::LinkPosition;
250 using Label::IsBound;
251 using Label::IsUnused;
252 using Label::IsLinked;
253
254 private:
255 using Label::BindTo;
256 using Label::LinkTo;
257
258 friend class x86::X86Assembler;
259
260 DISALLOW_COPY_AND_ASSIGN(NearLabel);
261};
262
Mark Mendell0616ae02015-04-17 12:49:27 -0400263/**
264 * Class to handle constant area values.
265 */
266class ConstantArea {
267 public:
Vladimir Marko93205e32016-04-13 11:59:46 +0100268 explicit ConstantArea(ArenaAllocator* arena) : buffer_(arena->Adapter(kArenaAllocAssembler)) {}
Mark Mendell0616ae02015-04-17 12:49:27 -0400269
270 // Add a double to the constant area, returning the offset into
271 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400272 size_t AddDouble(double v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400273
274 // Add a float to the constant area, returning the offset into
275 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400276 size_t AddFloat(float v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400277
278 // Add an int32_t to the constant area, returning the offset into
279 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400280 size_t AddInt32(int32_t v);
281
282 // Add an int32_t to the end of the constant area, returning the offset into
283 // the constant area where the literal resides.
284 size_t AppendInt32(int32_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400285
286 // Add an int64_t to the constant area, returning the offset into
287 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400288 size_t AddInt64(int64_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400289
290 bool IsEmpty() const {
291 return buffer_.size() == 0;
292 }
293
Mark Mendell805b3b52015-09-18 14:10:29 -0400294 size_t GetSize() const {
295 return buffer_.size() * elem_size_;
296 }
297
Vladimir Marko93205e32016-04-13 11:59:46 +0100298 ArrayRef<const int32_t> GetBuffer() const {
299 return ArrayRef<const int32_t>(buffer_);
Mark Mendell0616ae02015-04-17 12:49:27 -0400300 }
301
Mark Mendell0616ae02015-04-17 12:49:27 -0400302 private:
Mark Mendell805b3b52015-09-18 14:10:29 -0400303 static constexpr size_t elem_size_ = sizeof(int32_t);
Vladimir Marko93205e32016-04-13 11:59:46 +0100304 ArenaVector<int32_t> buffer_;
Mark Mendell0616ae02015-04-17 12:49:27 -0400305};
Mark Mendell73f455e2015-08-21 09:30:05 -0400306
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700307class X86Assembler FINAL : public Assembler, public JNIMacroAssembler<PointerSize::k32> {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700308 public:
Vladimir Marko93205e32016-04-13 11:59:46 +0100309 explicit X86Assembler(ArenaAllocator* arena) : Assembler(arena), constant_area_(arena) {}
Ian Rogers2c8f6532011-09-02 17:16:34 -0700310 virtual ~X86Assembler() {}
buzbeec143c552011-08-20 17:38:58 -0700311
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700312 size_t CodeSize() const OVERRIDE { return Assembler::CodeSize(); }
313 DebugFrameOpCodeWriterForAssembler& cfi() { return Assembler::cfi(); }
314 void FinalizeCode() { Assembler::FinalizeCode(); }
315 void FinalizeInstructions(const MemoryRegion& region) {
316 Assembler::FinalizeInstructions(region);
317 }
318
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700319 /*
320 * Emit Machine Instructions.
321 */
322 void call(Register reg);
323 void call(const Address& address);
324 void call(Label* label);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000325 void call(const ExternalLabel& label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700326
327 void pushl(Register reg);
328 void pushl(const Address& address);
329 void pushl(const Immediate& imm);
330
331 void popl(Register reg);
332 void popl(const Address& address);
333
334 void movl(Register dst, const Immediate& src);
335 void movl(Register dst, Register src);
336
337 void movl(Register dst, const Address& src);
338 void movl(const Address& dst, Register src);
339 void movl(const Address& dst, const Immediate& imm);
Ian Rogersbdb03912011-09-14 00:55:44 -0700340 void movl(const Address& dst, Label* lbl);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700341
Mark Mendell7a08fb52015-07-15 14:09:35 -0400342 void movntl(const Address& dst, Register src);
343
Mark Mendell09ed1a32015-03-25 08:30:06 -0400344 void bswapl(Register dst);
Aart Bikc39dac12016-01-21 08:59:48 -0800345
Mark Mendellbcee0922015-09-15 21:45:01 -0400346 void bsfl(Register dst, Register src);
347 void bsfl(Register dst, const Address& src);
Mark Mendell8ae3ffb2015-08-12 21:16:41 -0400348 void bsrl(Register dst, Register src);
349 void bsrl(Register dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400350
Aart Bikc39dac12016-01-21 08:59:48 -0800351 void popcntl(Register dst, Register src);
352 void popcntl(Register dst, const Address& src);
353
Mark Mendellbcee0922015-09-15 21:45:01 -0400354 void rorl(Register reg, const Immediate& imm);
355 void rorl(Register operand, Register shifter);
356 void roll(Register reg, const Immediate& imm);
357 void roll(Register operand, Register shifter);
358
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700359 void movzxb(Register dst, ByteRegister src);
360 void movzxb(Register dst, const Address& src);
361 void movsxb(Register dst, ByteRegister src);
362 void movsxb(Register dst, const Address& src);
363 void movb(Register dst, const Address& src);
364 void movb(const Address& dst, ByteRegister src);
365 void movb(const Address& dst, const Immediate& imm);
366
367 void movzxw(Register dst, Register src);
368 void movzxw(Register dst, const Address& src);
369 void movsxw(Register dst, Register src);
370 void movsxw(Register dst, const Address& src);
371 void movw(Register dst, const Address& src);
372 void movw(const Address& dst, Register src);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100373 void movw(const Address& dst, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700374
375 void leal(Register dst, const Address& src);
376
Ian Rogersb033c752011-07-20 12:22:35 -0700377 void cmovl(Condition condition, Register dst, Register src);
Mark Mendellabdac472016-02-12 13:49:03 -0500378 void cmovl(Condition condition, Register dst, const Address& src);
Ian Rogersb033c752011-07-20 12:22:35 -0700379
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000380 void setb(Condition condition, Register dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700381
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100382 void movaps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700383 void movss(XmmRegister dst, const Address& src);
384 void movss(const Address& dst, XmmRegister src);
385 void movss(XmmRegister dst, XmmRegister src);
386
387 void movd(XmmRegister dst, Register src);
388 void movd(Register dst, XmmRegister src);
389
390 void addss(XmmRegister dst, XmmRegister src);
391 void addss(XmmRegister dst, const Address& src);
392 void subss(XmmRegister dst, XmmRegister src);
393 void subss(XmmRegister dst, const Address& src);
394 void mulss(XmmRegister dst, XmmRegister src);
395 void mulss(XmmRegister dst, const Address& src);
396 void divss(XmmRegister dst, XmmRegister src);
397 void divss(XmmRegister dst, const Address& src);
398
399 void movsd(XmmRegister dst, const Address& src);
400 void movsd(const Address& dst, XmmRegister src);
401 void movsd(XmmRegister dst, XmmRegister src);
402
Calin Juravle52c48962014-12-16 17:02:57 +0000403 void psrlq(XmmRegister reg, const Immediate& shift_count);
404 void punpckldq(XmmRegister dst, XmmRegister src);
405
Nicolas Geoffray234d69d2015-03-09 10:28:50 +0000406 void movhpd(XmmRegister dst, const Address& src);
407 void movhpd(const Address& dst, XmmRegister src);
408
409 void psrldq(XmmRegister reg, const Immediate& shift_count);
410
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700411 void addsd(XmmRegister dst, XmmRegister src);
412 void addsd(XmmRegister dst, const Address& src);
413 void subsd(XmmRegister dst, XmmRegister src);
414 void subsd(XmmRegister dst, const Address& src);
415 void mulsd(XmmRegister dst, XmmRegister src);
416 void mulsd(XmmRegister dst, const Address& src);
417 void divsd(XmmRegister dst, XmmRegister src);
418 void divsd(XmmRegister dst, const Address& src);
419
420 void cvtsi2ss(XmmRegister dst, Register src);
421 void cvtsi2sd(XmmRegister dst, Register src);
422
423 void cvtss2si(Register dst, XmmRegister src);
424 void cvtss2sd(XmmRegister dst, XmmRegister src);
425
426 void cvtsd2si(Register dst, XmmRegister src);
427 void cvtsd2ss(XmmRegister dst, XmmRegister src);
428
429 void cvttss2si(Register dst, XmmRegister src);
430 void cvttsd2si(Register dst, XmmRegister src);
431
432 void cvtdq2pd(XmmRegister dst, XmmRegister src);
433
434 void comiss(XmmRegister a, XmmRegister b);
Aart Bik18ba1212016-08-01 14:11:20 -0700435 void comiss(XmmRegister a, const Address& b);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700436 void comisd(XmmRegister a, XmmRegister b);
Aart Bik18ba1212016-08-01 14:11:20 -0700437 void comisd(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000438 void ucomiss(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400439 void ucomiss(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000440 void ucomisd(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400441 void ucomisd(XmmRegister a, const Address& b);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700442
Mark Mendellfb8d2792015-03-31 22:16:59 -0400443 void roundsd(XmmRegister dst, XmmRegister src, const Immediate& imm);
444 void roundss(XmmRegister dst, XmmRegister src, const Immediate& imm);
445
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700446 void sqrtsd(XmmRegister dst, XmmRegister src);
447 void sqrtss(XmmRegister dst, XmmRegister src);
448
449 void xorpd(XmmRegister dst, const Address& src);
450 void xorpd(XmmRegister dst, XmmRegister src);
451 void xorps(XmmRegister dst, const Address& src);
452 void xorps(XmmRegister dst, XmmRegister src);
453
Mark Mendell09ed1a32015-03-25 08:30:06 -0400454 void andpd(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700455 void andpd(XmmRegister dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400456 void andps(XmmRegister dst, XmmRegister src);
457 void andps(XmmRegister dst, const Address& src);
458
459 void orpd(XmmRegister dst, XmmRegister src);
460 void orps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700461
462 void flds(const Address& src);
463 void fstps(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500464 void fsts(const Address& dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700465
466 void fldl(const Address& src);
467 void fstpl(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500468 void fstl(const Address& dst);
469
470 void fstsw();
471
472 void fucompp();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700473
474 void fnstcw(const Address& dst);
475 void fldcw(const Address& src);
476
477 void fistpl(const Address& dst);
478 void fistps(const Address& dst);
479 void fildl(const Address& src);
Roland Levillain0a186012015-04-13 17:00:20 +0100480 void filds(const Address& src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700481
482 void fincstp();
483 void ffree(const Immediate& index);
484
485 void fsin();
486 void fcos();
487 void fptan();
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500488 void fprem();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700489
490 void xchgl(Register dst, Register src);
Ian Rogers7caad772012-03-30 01:07:54 -0700491 void xchgl(Register reg, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700492
Serguei Katkov3b625932016-05-06 10:24:17 +0600493 void cmpb(const Address& address, const Immediate& imm);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100494 void cmpw(const Address& address, const Immediate& imm);
495
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700496 void cmpl(Register reg, const Immediate& imm);
497 void cmpl(Register reg0, Register reg1);
498 void cmpl(Register reg, const Address& address);
499
500 void cmpl(const Address& address, Register reg);
501 void cmpl(const Address& address, const Immediate& imm);
502
503 void testl(Register reg1, Register reg2);
504 void testl(Register reg, const Immediate& imm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100505 void testl(Register reg1, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700506
507 void andl(Register dst, const Immediate& imm);
508 void andl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000509 void andl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700510
511 void orl(Register dst, const Immediate& imm);
512 void orl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000513 void orl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700514
515 void xorl(Register dst, Register src);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100516 void xorl(Register dst, const Immediate& imm);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000517 void xorl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700518
519 void addl(Register dst, Register src);
520 void addl(Register reg, const Immediate& imm);
521 void addl(Register reg, const Address& address);
522
523 void addl(const Address& address, Register reg);
524 void addl(const Address& address, const Immediate& imm);
525
526 void adcl(Register dst, Register src);
527 void adcl(Register reg, const Immediate& imm);
528 void adcl(Register dst, const Address& address);
529
530 void subl(Register dst, Register src);
531 void subl(Register reg, const Immediate& imm);
532 void subl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400533 void subl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700534
535 void cdq();
536
537 void idivl(Register reg);
538
539 void imull(Register dst, Register src);
540 void imull(Register reg, const Immediate& imm);
Mark Mendell4a2aa4a2015-07-27 16:13:10 -0400541 void imull(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700542 void imull(Register reg, const Address& address);
543
544 void imull(Register reg);
545 void imull(const Address& address);
546
547 void mull(Register reg);
548 void mull(const Address& address);
549
550 void sbbl(Register dst, Register src);
551 void sbbl(Register reg, const Immediate& imm);
552 void sbbl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400553 void sbbl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700554
555 void incl(Register reg);
556 void incl(const Address& address);
557
558 void decl(Register reg);
559 void decl(const Address& address);
560
561 void shll(Register reg, const Immediate& imm);
562 void shll(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000563 void shll(const Address& address, const Immediate& imm);
564 void shll(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700565 void shrl(Register reg, const Immediate& imm);
566 void shrl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000567 void shrl(const Address& address, const Immediate& imm);
568 void shrl(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700569 void sarl(Register reg, const Immediate& imm);
570 void sarl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000571 void sarl(const Address& address, const Immediate& imm);
572 void sarl(const Address& address, Register shifter);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000573 void shld(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000574 void shld(Register dst, Register src, const Immediate& imm);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000575 void shrd(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000576 void shrd(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700577
578 void negl(Register reg);
579 void notl(Register reg);
580
581 void enter(const Immediate& imm);
582 void leave();
583
584 void ret();
585 void ret(const Immediate& imm);
586
587 void nop();
588 void int3();
589 void hlt();
590
591 void j(Condition condition, Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400592 void j(Condition condition, NearLabel* label);
593 void jecxz(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700594
595 void jmp(Register reg);
Ian Rogers7caad772012-03-30 01:07:54 -0700596 void jmp(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700597 void jmp(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400598 void jmp(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700599
Andreas Gampe21030dd2015-05-07 14:46:15 -0700600 void repne_scasw();
agicsaki71311f82015-07-27 11:34:13 -0700601 void repe_cmpsw();
agicsaki970abfb2015-07-31 10:31:14 -0700602 void repe_cmpsl();
Mark Mendellb9c4bbe2015-07-01 14:26:52 -0400603 void rep_movsw();
Andreas Gampe21030dd2015-05-07 14:46:15 -0700604
Ian Rogers2c8f6532011-09-02 17:16:34 -0700605 X86Assembler* lock();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700606 void cmpxchgl(const Address& address, Register reg);
Mark Mendell58d25fd2015-04-03 14:52:31 -0400607 void cmpxchg8b(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700608
Elliott Hughes79ab9e32012-03-12 15:41:35 -0700609 void mfence();
610
Ian Rogers2c8f6532011-09-02 17:16:34 -0700611 X86Assembler* fs();
Ian Rogersbefbd572014-03-06 01:13:39 -0800612 X86Assembler* gs();
Ian Rogersb033c752011-07-20 12:22:35 -0700613
614 //
615 // Macros for High-level operations.
616 //
617
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700618 void AddImmediate(Register reg, const Immediate& imm);
619
Roland Levillain647b9ed2014-11-27 12:06:00 +0000620 void LoadLongConstant(XmmRegister dst, int64_t value);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700621 void LoadDoubleConstant(XmmRegister dst, double value);
622
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700623 void LockCmpxchgl(const Address& address, Register reg) {
Ian Rogers0d666d82011-08-14 16:03:46 -0700624 lock()->cmpxchgl(address, reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700625 }
626
Mark Mendell58d25fd2015-04-03 14:52:31 -0400627 void LockCmpxchg8b(const Address& address) {
628 lock()->cmpxchg8b(address);
629 }
630
Ian Rogersb033c752011-07-20 12:22:35 -0700631 //
632 // Misc. functionality
633 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700634 int PreferredLoopAlignment() { return 16; }
635 void Align(int alignment, int offset);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700636 void Bind(Label* label) OVERRIDE;
637 void Jump(Label* label) OVERRIDE {
638 jmp(label);
639 }
Mark Mendell73f455e2015-08-21 09:30:05 -0400640 void Bind(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700641
Ian Rogers2c8f6532011-09-02 17:16:34 -0700642 //
643 // Overridden common assembler high-level functionality
644 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700645
Ian Rogers2c8f6532011-09-02 17:16:34 -0700646 // Emit code that will create an activation on the stack
Vladimir Marko32248382016-05-19 10:37:24 +0100647 void BuildFrame(size_t frame_size,
648 ManagedRegister method_reg,
649 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700650 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700651
652 // Emit code that will remove an activation from the stack
Vladimir Marko32248382016-05-19 10:37:24 +0100653 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700654 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700655
Ian Rogersdd7624d2014-03-14 17:43:00 -0700656 void IncreaseFrameSize(size_t adjust) OVERRIDE;
657 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700658
659 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700660 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
661 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
662 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700663
Ian Rogersdd7624d2014-03-14 17:43:00 -0700664 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700665
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700666 void StoreStackOffsetToThread(ThreadOffset32 thr_offs,
667 FrameOffset fr_offs,
668 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700669
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700670 void StoreStackPointerToThread(ThreadOffset32 thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700671
Ian Rogersdd7624d2014-03-14 17:43:00 -0700672 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
673 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700674
675 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700676 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700677
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700678 void LoadFromThread(ManagedRegister dest, ThreadOffset32 src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700679
Mathieu Chartiere401d142015-04-22 13:56:20 -0700680 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700681
Mathieu Chartiere401d142015-04-22 13:56:20 -0700682 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +0100683 bool unpoison_reference) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700684
Ian Rogersdd7624d2014-03-14 17:43:00 -0700685 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700686
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700687 void LoadRawPtrFromThread(ManagedRegister dest, ThreadOffset32 offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700688
689 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700690 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700691
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700692 void CopyRawPtrFromThread(FrameOffset fr_offs,
693 ThreadOffset32 thr_offs,
694 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700695
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700696 void CopyRawPtrToThread(ThreadOffset32 thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700697 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700698
Ian Rogersdd7624d2014-03-14 17:43:00 -0700699 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700700
Ian Rogersdd7624d2014-03-14 17:43:00 -0700701 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700702
Ian Rogersdd7624d2014-03-14 17:43:00 -0700703 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
704 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700705
Ian Rogersdd7624d2014-03-14 17:43:00 -0700706 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
707 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700708
Ian Rogersdd7624d2014-03-14 17:43:00 -0700709 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
710 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700711
Ian Rogersdd7624d2014-03-14 17:43:00 -0700712 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
713 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700714
Ian Rogersdd7624d2014-03-14 17:43:00 -0700715 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
716 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700717
Ian Rogersdd7624d2014-03-14 17:43:00 -0700718 void MemoryBarrier(ManagedRegister) OVERRIDE;
Ian Rogerse5de95b2011-09-18 20:31:38 -0700719
jeffhao58136ca2012-05-24 13:40:11 -0700720 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700721 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700722
jeffhaocee4d0c2012-06-15 14:42:01 -0700723 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700724 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700725
Ian Rogers2c8f6532011-09-02 17:16:34 -0700726 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700727 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
728 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700729
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700730 // Set up out_reg to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700731 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700732 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700733 // null.
734 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
735 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700736
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700737 // Set up out_off to hold a Object** into the handle scope, or to be null if the
Ian Rogers2c8f6532011-09-02 17:16:34 -0700738 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700739 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
740 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700741
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700742 // src holds a handle scope entry (Object**) load this into dst
743 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700744
745 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
746 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700747 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
748 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700749
750 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700751 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
752 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700753 void CallFromThread(ThreadOffset32 offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700754
Ian Rogers2c8f6532011-09-02 17:16:34 -0700755 // Generate code to check if Thread::Current()->exception_ is non-null
756 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700757 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700758
Roland Levillain4d027112015-07-01 15:41:14 +0100759 //
760 // Heap poisoning.
761 //
762
763 // Poison a heap reference contained in `reg`.
764 void PoisonHeapReference(Register reg) { negl(reg); }
765 // Unpoison a heap reference contained in `reg`.
766 void UnpoisonHeapReference(Register reg) { negl(reg); }
767 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
768 void MaybeUnpoisonHeapReference(Register reg) {
769 if (kPoisonHeapReferences) {
770 UnpoisonHeapReference(reg);
771 }
772 }
773
Mark Mendell0616ae02015-04-17 12:49:27 -0400774 // Add a double to the constant area, returning the offset into
775 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400776 size_t AddDouble(double v) { return constant_area_.AddDouble(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400777
778 // Add a float to the constant area, returning the offset into
779 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400780 size_t AddFloat(float v) { return constant_area_.AddFloat(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400781
782 // Add an int32_t to the constant area, returning the offset into
783 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400784 size_t AddInt32(int32_t v) {
785 return constant_area_.AddInt32(v);
786 }
787
788 // Add an int32_t to the end of the constant area, returning the offset into
789 // the constant area where the literal resides.
790 size_t AppendInt32(int32_t v) {
791 return constant_area_.AppendInt32(v);
792 }
Mark Mendell0616ae02015-04-17 12:49:27 -0400793
794 // Add an int64_t to the constant area, returning the offset into
795 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400796 size_t AddInt64(int64_t v) { return constant_area_.AddInt64(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400797
798 // Add the contents of the constant area to the assembler buffer.
799 void AddConstantArea();
800
801 // Is the constant area empty? Return true if there are no literals in the constant area.
802 bool IsConstantAreaEmpty() const { return constant_area_.IsEmpty(); }
Mark Mendell805b3b52015-09-18 14:10:29 -0400803
804 // Return the current size of the constant area.
805 size_t ConstantAreaSize() const { return constant_area_.GetSize(); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400806
Ian Rogers2c8f6532011-09-02 17:16:34 -0700807 private:
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700808 inline void EmitUint8(uint8_t value);
809 inline void EmitInt32(int32_t value);
810 inline void EmitRegisterOperand(int rm, int reg);
811 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg);
812 inline void EmitFixup(AssemblerFixup* fixup);
813 inline void EmitOperandSizeOverride();
814
815 void EmitOperand(int rm, const Operand& operand);
816 void EmitImmediate(const Immediate& imm);
817 void EmitComplex(int rm, const Operand& operand, const Immediate& immediate);
818 void EmitLabel(Label* label, int instruction_size);
819 void EmitLabelLink(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400820 void EmitLabelLink(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700821
Mark P Mendell73945692015-04-29 14:56:17 +0000822 void EmitGenericShift(int rm, const Operand& operand, const Immediate& imm);
823 void EmitGenericShift(int rm, const Operand& operand, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700824
Mark Mendell0616ae02015-04-17 12:49:27 -0400825 ConstantArea constant_area_;
826
Ian Rogers2c8f6532011-09-02 17:16:34 -0700827 DISALLOW_COPY_AND_ASSIGN(X86Assembler);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700828};
829
Ian Rogers2c8f6532011-09-02 17:16:34 -0700830inline void X86Assembler::EmitUint8(uint8_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700831 buffer_.Emit<uint8_t>(value);
832}
833
Ian Rogers2c8f6532011-09-02 17:16:34 -0700834inline void X86Assembler::EmitInt32(int32_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700835 buffer_.Emit<int32_t>(value);
836}
837
Ian Rogers2c8f6532011-09-02 17:16:34 -0700838inline void X86Assembler::EmitRegisterOperand(int rm, int reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700839 CHECK_GE(rm, 0);
840 CHECK_LT(rm, 8);
841 buffer_.Emit<uint8_t>(0xC0 + (rm << 3) + reg);
842}
843
Ian Rogers2c8f6532011-09-02 17:16:34 -0700844inline void X86Assembler::EmitXmmRegisterOperand(int rm, XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700845 EmitRegisterOperand(rm, static_cast<Register>(reg));
846}
847
Ian Rogers2c8f6532011-09-02 17:16:34 -0700848inline void X86Assembler::EmitFixup(AssemblerFixup* fixup) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700849 buffer_.EmitFixup(fixup);
850}
851
Ian Rogers2c8f6532011-09-02 17:16:34 -0700852inline void X86Assembler::EmitOperandSizeOverride() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700853 EmitUint8(0x66);
854}
855
Ian Rogers2c8f6532011-09-02 17:16:34 -0700856// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700857class X86ExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700858 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -0700859 explicit X86ExceptionSlowPath(size_t stack_adjust) : stack_adjust_(stack_adjust) {}
Ian Rogersdd7624d2014-03-14 17:43:00 -0700860 virtual void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700861 private:
862 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700863};
864
Ian Rogers2c8f6532011-09-02 17:16:34 -0700865} // namespace x86
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700866} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700867
Ian Rogers166db042013-07-26 12:05:57 -0700868#endif // ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_