blob: 6d519e425fdb2ad777432688aeaa008c63f08377 [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"
Elliott Hughes76160052012-12-12 16:31:20 -080024#include "base/macros.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070025#include "constants_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "globals.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -070027#include "managed_register_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070028#include "offsets.h"
Vladimir Marko93205e32016-04-13 11:59:46 +010029#include "utils/array_ref.h"
Ian Rogers166db042013-07-26 12:05:57 -070030#include "utils/assembler.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070031
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070032namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070033namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070034
Ian Rogerscf7f1912014-10-22 22:06:39 -070035class Immediate : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070036 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080037 explicit Immediate(int32_t value_in) : value_(value_in) {}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070038
39 int32_t value() const { return value_; }
40
Andreas Gampeab1eb0d2015-02-13 19:23:55 -080041 bool is_int8() const { return IsInt<8>(value_); }
42 bool is_uint8() const { return IsUint<8>(value_); }
43 bool is_int16() const { return IsInt<16>(value_); }
44 bool is_uint16() const { return IsUint<16>(value_); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070045
46 private:
47 const int32_t value_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070048};
49
50
Ian Rogerscf7f1912014-10-22 22:06:39 -070051class Operand : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070052 public:
53 uint8_t mod() const {
54 return (encoding_at(0) >> 6) & 3;
55 }
56
57 Register rm() const {
58 return static_cast<Register>(encoding_at(0) & 7);
59 }
60
61 ScaleFactor scale() const {
62 return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
63 }
64
65 Register index() const {
66 return static_cast<Register>((encoding_at(1) >> 3) & 7);
67 }
68
69 Register base() const {
70 return static_cast<Register>(encoding_at(1) & 7);
71 }
72
73 int8_t disp8() const {
74 CHECK_GE(length_, 2);
75 return static_cast<int8_t>(encoding_[length_ - 1]);
76 }
77
78 int32_t disp32() const {
79 CHECK_GE(length_, 5);
80 int32_t value;
81 memcpy(&value, &encoding_[length_ - 4], sizeof(value));
82 return value;
83 }
84
85 bool IsRegister(Register reg) const {
86 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only.
87 && ((encoding_[0] & 0x07) == reg); // Register codes match.
88 }
89
90 protected:
91 // Operand can be sub classed (e.g: Address).
Mark Mendell0616ae02015-04-17 12:49:27 -040092 Operand() : length_(0), fixup_(nullptr) { }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070093
Andreas Gampe277ccbd2014-11-03 21:36:10 -080094 void SetModRM(int mod_in, Register rm_in) {
95 CHECK_EQ(mod_in & ~3, 0);
96 encoding_[0] = (mod_in << 6) | rm_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070097 length_ = 1;
98 }
99
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800100 void SetSIB(ScaleFactor scale_in, Register index_in, Register base_in) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700101 CHECK_EQ(length_, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800102 CHECK_EQ(scale_in & ~3, 0);
103 encoding_[1] = (scale_in << 6) | (index_in << 3) | base_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700104 length_ = 2;
105 }
106
107 void SetDisp8(int8_t disp) {
108 CHECK(length_ == 1 || length_ == 2);
109 encoding_[length_++] = static_cast<uint8_t>(disp);
110 }
111
112 void SetDisp32(int32_t disp) {
113 CHECK(length_ == 1 || length_ == 2);
114 int disp_size = sizeof(disp);
115 memmove(&encoding_[length_], &disp, disp_size);
116 length_ += disp_size;
117 }
118
Mark Mendell0616ae02015-04-17 12:49:27 -0400119 AssemblerFixup* GetFixup() const {
120 return fixup_;
121 }
122
123 void SetFixup(AssemblerFixup* fixup) {
124 fixup_ = fixup;
125 }
126
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700127 private:
Ian Rogers13735952014-10-08 12:43:28 -0700128 uint8_t length_;
129 uint8_t encoding_[6];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700130
Mark Mendell0616ae02015-04-17 12:49:27 -0400131 // A fixup can be associated with the operand, in order to be applied after the
132 // code has been generated. This is used for constant area fixups.
133 AssemblerFixup* fixup_;
134
135 explicit Operand(Register reg) : fixup_(nullptr) { SetModRM(3, reg); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700136
137 // Get the operand encoding byte at the given index.
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800138 uint8_t encoding_at(int index_in) const {
139 CHECK_GE(index_in, 0);
140 CHECK_LT(index_in, length_);
141 return encoding_[index_in];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700142 }
143
Ian Rogers2c8f6532011-09-02 17:16:34 -0700144 friend class X86Assembler;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700145};
146
147
148class Address : public Operand {
149 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800150 Address(Register base_in, int32_t disp) {
151 Init(base_in, disp);
Ian Rogersb033c752011-07-20 12:22:35 -0700152 }
153
Mark Mendell0616ae02015-04-17 12:49:27 -0400154 Address(Register base_in, int32_t disp, AssemblerFixup *fixup) {
155 Init(base_in, disp);
156 SetFixup(fixup);
157 }
158
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800159 Address(Register base_in, Offset disp) {
160 Init(base_in, disp.Int32Value());
Ian Rogersa04d3972011-08-17 11:33:44 -0700161 }
162
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800163 Address(Register base_in, FrameOffset disp) {
164 CHECK_EQ(base_in, ESP);
Ian Rogersb033c752011-07-20 12:22:35 -0700165 Init(ESP, disp.Int32Value());
166 }
167
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800168 Address(Register base_in, MemberOffset disp) {
169 Init(base_in, disp.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700170 }
171
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800172 Address(Register index_in, ScaleFactor scale_in, int32_t disp) {
173 CHECK_NE(index_in, ESP); // Illegal addressing mode.
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700174 SetModRM(0, ESP);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800175 SetSIB(scale_in, index_in, EBP);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700176 SetDisp32(disp);
177 }
178
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800179 Address(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
Mark Mendell805b3b52015-09-18 14:10:29 -0400180 Init(base_in, index_in, scale_in, disp);
181 }
182
183 Address(Register base_in,
184 Register index_in,
185 ScaleFactor scale_in,
186 int32_t disp, AssemblerFixup *fixup) {
187 Init(base_in, index_in, scale_in, disp);
188 SetFixup(fixup);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700189 }
190
Ian Rogers13735952014-10-08 12:43:28 -0700191 static Address Absolute(uintptr_t addr) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700192 Address result;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700193 result.SetModRM(0, EBP);
194 result.SetDisp32(addr);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700195 return result;
196 }
197
Andreas Gampe542451c2016-07-26 09:02:02 -0700198 static Address Absolute(ThreadOffset32 addr) {
Ian Rogersdd7624d2014-03-14 17:43:00 -0700199 return Absolute(addr.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700200 }
201
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700202 private:
203 Address() {}
Mark Mendell805b3b52015-09-18 14:10:29 -0400204
205 void Init(Register base_in, int32_t disp) {
206 if (disp == 0 && base_in != EBP) {
207 SetModRM(0, base_in);
208 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
209 } else if (disp >= -128 && disp <= 127) {
210 SetModRM(1, base_in);
211 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
212 SetDisp8(disp);
213 } else {
214 SetModRM(2, base_in);
215 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
216 SetDisp32(disp);
217 }
218 }
219
220 void Init(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
221 CHECK_NE(index_in, ESP); // Illegal addressing mode.
222 if (disp == 0 && base_in != EBP) {
223 SetModRM(0, ESP);
224 SetSIB(scale_in, index_in, base_in);
225 } else if (disp >= -128 && disp <= 127) {
226 SetModRM(1, ESP);
227 SetSIB(scale_in, index_in, base_in);
228 SetDisp8(disp);
229 } else {
230 SetModRM(2, ESP);
231 SetSIB(scale_in, index_in, base_in);
232 SetDisp32(disp);
233 }
234 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700235};
236
237
Mark Mendell73f455e2015-08-21 09:30:05 -0400238// This is equivalent to the Label class, used in a slightly different context. We
239// inherit the functionality of the Label class, but prevent unintended
240// derived-to-base conversions by making the base class private.
241class NearLabel : private Label {
242 public:
243 NearLabel() : Label() {}
244
245 // Expose the Label routines that we need.
246 using Label::Position;
247 using Label::LinkPosition;
248 using Label::IsBound;
249 using Label::IsUnused;
250 using Label::IsLinked;
251
252 private:
253 using Label::BindTo;
254 using Label::LinkTo;
255
256 friend class x86::X86Assembler;
257
258 DISALLOW_COPY_AND_ASSIGN(NearLabel);
259};
260
Mark Mendell0616ae02015-04-17 12:49:27 -0400261/**
262 * Class to handle constant area values.
263 */
264class ConstantArea {
265 public:
Vladimir Marko93205e32016-04-13 11:59:46 +0100266 explicit ConstantArea(ArenaAllocator* arena) : buffer_(arena->Adapter(kArenaAllocAssembler)) {}
Mark Mendell0616ae02015-04-17 12:49:27 -0400267
268 // Add a double to the constant area, returning the offset into
269 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400270 size_t AddDouble(double v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400271
272 // Add a float to the constant area, returning the offset into
273 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400274 size_t AddFloat(float v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400275
276 // Add an int32_t to the constant area, returning the offset into
277 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400278 size_t AddInt32(int32_t v);
279
280 // Add an int32_t to the end of the constant area, returning the offset into
281 // the constant area where the literal resides.
282 size_t AppendInt32(int32_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400283
284 // Add an int64_t to the constant area, returning the offset into
285 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400286 size_t AddInt64(int64_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400287
288 bool IsEmpty() const {
289 return buffer_.size() == 0;
290 }
291
Mark Mendell805b3b52015-09-18 14:10:29 -0400292 size_t GetSize() const {
293 return buffer_.size() * elem_size_;
294 }
295
Vladimir Marko93205e32016-04-13 11:59:46 +0100296 ArrayRef<const int32_t> GetBuffer() const {
297 return ArrayRef<const int32_t>(buffer_);
Mark Mendell0616ae02015-04-17 12:49:27 -0400298 }
299
Mark Mendell0616ae02015-04-17 12:49:27 -0400300 private:
Mark Mendell805b3b52015-09-18 14:10:29 -0400301 static constexpr size_t elem_size_ = sizeof(int32_t);
Vladimir Marko93205e32016-04-13 11:59:46 +0100302 ArenaVector<int32_t> buffer_;
Mark Mendell0616ae02015-04-17 12:49:27 -0400303};
Mark Mendell73f455e2015-08-21 09:30:05 -0400304
Ian Rogersbefbd572014-03-06 01:13:39 -0800305class X86Assembler FINAL : public Assembler {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700306 public:
Vladimir Marko93205e32016-04-13 11:59:46 +0100307 explicit X86Assembler(ArenaAllocator* arena) : Assembler(arena), constant_area_(arena) {}
Ian Rogers2c8f6532011-09-02 17:16:34 -0700308 virtual ~X86Assembler() {}
buzbeec143c552011-08-20 17:38:58 -0700309
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700310 /*
311 * Emit Machine Instructions.
312 */
313 void call(Register reg);
314 void call(const Address& address);
315 void call(Label* label);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000316 void call(const ExternalLabel& label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700317
318 void pushl(Register reg);
319 void pushl(const Address& address);
320 void pushl(const Immediate& imm);
321
322 void popl(Register reg);
323 void popl(const Address& address);
324
325 void movl(Register dst, const Immediate& src);
326 void movl(Register dst, Register src);
327
328 void movl(Register dst, const Address& src);
329 void movl(const Address& dst, Register src);
330 void movl(const Address& dst, const Immediate& imm);
Ian Rogersbdb03912011-09-14 00:55:44 -0700331 void movl(const Address& dst, Label* lbl);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700332
Mark Mendell7a08fb52015-07-15 14:09:35 -0400333 void movntl(const Address& dst, Register src);
334
Mark Mendell09ed1a32015-03-25 08:30:06 -0400335 void bswapl(Register dst);
Aart Bikc39dac12016-01-21 08:59:48 -0800336
Mark Mendellbcee0922015-09-15 21:45:01 -0400337 void bsfl(Register dst, Register src);
338 void bsfl(Register dst, const Address& src);
Mark Mendell8ae3ffb2015-08-12 21:16:41 -0400339 void bsrl(Register dst, Register src);
340 void bsrl(Register dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400341
Aart Bikc39dac12016-01-21 08:59:48 -0800342 void popcntl(Register dst, Register src);
343 void popcntl(Register dst, const Address& src);
344
Mark Mendellbcee0922015-09-15 21:45:01 -0400345 void rorl(Register reg, const Immediate& imm);
346 void rorl(Register operand, Register shifter);
347 void roll(Register reg, const Immediate& imm);
348 void roll(Register operand, Register shifter);
349
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700350 void movzxb(Register dst, ByteRegister src);
351 void movzxb(Register dst, const Address& src);
352 void movsxb(Register dst, ByteRegister src);
353 void movsxb(Register dst, const Address& src);
354 void movb(Register dst, const Address& src);
355 void movb(const Address& dst, ByteRegister src);
356 void movb(const Address& dst, const Immediate& imm);
357
358 void movzxw(Register dst, Register src);
359 void movzxw(Register dst, const Address& src);
360 void movsxw(Register dst, Register src);
361 void movsxw(Register dst, const Address& src);
362 void movw(Register dst, const Address& src);
363 void movw(const Address& dst, Register src);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100364 void movw(const Address& dst, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700365
366 void leal(Register dst, const Address& src);
367
Ian Rogersb033c752011-07-20 12:22:35 -0700368 void cmovl(Condition condition, Register dst, Register src);
Mark Mendellabdac472016-02-12 13:49:03 -0500369 void cmovl(Condition condition, Register dst, const Address& src);
Ian Rogersb033c752011-07-20 12:22:35 -0700370
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000371 void setb(Condition condition, Register dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700372
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100373 void movaps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700374 void movss(XmmRegister dst, const Address& src);
375 void movss(const Address& dst, XmmRegister src);
376 void movss(XmmRegister dst, XmmRegister src);
377
378 void movd(XmmRegister dst, Register src);
379 void movd(Register dst, XmmRegister src);
380
381 void addss(XmmRegister dst, XmmRegister src);
382 void addss(XmmRegister dst, const Address& src);
383 void subss(XmmRegister dst, XmmRegister src);
384 void subss(XmmRegister dst, const Address& src);
385 void mulss(XmmRegister dst, XmmRegister src);
386 void mulss(XmmRegister dst, const Address& src);
387 void divss(XmmRegister dst, XmmRegister src);
388 void divss(XmmRegister dst, const Address& src);
389
390 void movsd(XmmRegister dst, const Address& src);
391 void movsd(const Address& dst, XmmRegister src);
392 void movsd(XmmRegister dst, XmmRegister src);
393
Calin Juravle52c48962014-12-16 17:02:57 +0000394 void psrlq(XmmRegister reg, const Immediate& shift_count);
395 void punpckldq(XmmRegister dst, XmmRegister src);
396
Nicolas Geoffray234d69d2015-03-09 10:28:50 +0000397 void movhpd(XmmRegister dst, const Address& src);
398 void movhpd(const Address& dst, XmmRegister src);
399
400 void psrldq(XmmRegister reg, const Immediate& shift_count);
401
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700402 void addsd(XmmRegister dst, XmmRegister src);
403 void addsd(XmmRegister dst, const Address& src);
404 void subsd(XmmRegister dst, XmmRegister src);
405 void subsd(XmmRegister dst, const Address& src);
406 void mulsd(XmmRegister dst, XmmRegister src);
407 void mulsd(XmmRegister dst, const Address& src);
408 void divsd(XmmRegister dst, XmmRegister src);
409 void divsd(XmmRegister dst, const Address& src);
410
411 void cvtsi2ss(XmmRegister dst, Register src);
412 void cvtsi2sd(XmmRegister dst, Register src);
413
414 void cvtss2si(Register dst, XmmRegister src);
415 void cvtss2sd(XmmRegister dst, XmmRegister src);
416
417 void cvtsd2si(Register dst, XmmRegister src);
418 void cvtsd2ss(XmmRegister dst, XmmRegister src);
419
420 void cvttss2si(Register dst, XmmRegister src);
421 void cvttsd2si(Register dst, XmmRegister src);
422
423 void cvtdq2pd(XmmRegister dst, XmmRegister src);
424
425 void comiss(XmmRegister a, XmmRegister b);
Aart Bik18ba1212016-08-01 14:11:20 -0700426 void comiss(XmmRegister a, const Address& b);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700427 void comisd(XmmRegister a, XmmRegister b);
Aart Bik18ba1212016-08-01 14:11:20 -0700428 void comisd(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000429 void ucomiss(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400430 void ucomiss(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000431 void ucomisd(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400432 void ucomisd(XmmRegister a, const Address& b);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700433
Mark Mendellfb8d2792015-03-31 22:16:59 -0400434 void roundsd(XmmRegister dst, XmmRegister src, const Immediate& imm);
435 void roundss(XmmRegister dst, XmmRegister src, const Immediate& imm);
436
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700437 void sqrtsd(XmmRegister dst, XmmRegister src);
438 void sqrtss(XmmRegister dst, XmmRegister src);
439
440 void xorpd(XmmRegister dst, const Address& src);
441 void xorpd(XmmRegister dst, XmmRegister src);
442 void xorps(XmmRegister dst, const Address& src);
443 void xorps(XmmRegister dst, XmmRegister src);
444
Mark Mendell09ed1a32015-03-25 08:30:06 -0400445 void andpd(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700446 void andpd(XmmRegister dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400447 void andps(XmmRegister dst, XmmRegister src);
448 void andps(XmmRegister dst, const Address& src);
449
450 void orpd(XmmRegister dst, XmmRegister src);
451 void orps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700452
453 void flds(const Address& src);
454 void fstps(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500455 void fsts(const Address& dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700456
457 void fldl(const Address& src);
458 void fstpl(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500459 void fstl(const Address& dst);
460
461 void fstsw();
462
463 void fucompp();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700464
465 void fnstcw(const Address& dst);
466 void fldcw(const Address& src);
467
468 void fistpl(const Address& dst);
469 void fistps(const Address& dst);
470 void fildl(const Address& src);
Roland Levillain0a186012015-04-13 17:00:20 +0100471 void filds(const Address& src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700472
473 void fincstp();
474 void ffree(const Immediate& index);
475
476 void fsin();
477 void fcos();
478 void fptan();
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500479 void fprem();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700480
481 void xchgl(Register dst, Register src);
Ian Rogers7caad772012-03-30 01:07:54 -0700482 void xchgl(Register reg, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700483
Serguei Katkov3b625932016-05-06 10:24:17 +0600484 void cmpb(const Address& address, const Immediate& imm);
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100485 void cmpw(const Address& address, const Immediate& imm);
486
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700487 void cmpl(Register reg, const Immediate& imm);
488 void cmpl(Register reg0, Register reg1);
489 void cmpl(Register reg, const Address& address);
490
491 void cmpl(const Address& address, Register reg);
492 void cmpl(const Address& address, const Immediate& imm);
493
494 void testl(Register reg1, Register reg2);
495 void testl(Register reg, const Immediate& imm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100496 void testl(Register reg1, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700497
498 void andl(Register dst, const Immediate& imm);
499 void andl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000500 void andl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700501
502 void orl(Register dst, const Immediate& imm);
503 void orl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000504 void orl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700505
506 void xorl(Register dst, Register src);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100507 void xorl(Register dst, const Immediate& imm);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000508 void xorl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700509
510 void addl(Register dst, Register src);
511 void addl(Register reg, const Immediate& imm);
512 void addl(Register reg, const Address& address);
513
514 void addl(const Address& address, Register reg);
515 void addl(const Address& address, const Immediate& imm);
516
517 void adcl(Register dst, Register src);
518 void adcl(Register reg, const Immediate& imm);
519 void adcl(Register dst, const Address& address);
520
521 void subl(Register dst, Register src);
522 void subl(Register reg, const Immediate& imm);
523 void subl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400524 void subl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700525
526 void cdq();
527
528 void idivl(Register reg);
529
530 void imull(Register dst, Register src);
531 void imull(Register reg, const Immediate& imm);
Mark Mendell4a2aa4a2015-07-27 16:13:10 -0400532 void imull(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700533 void imull(Register reg, const Address& address);
534
535 void imull(Register reg);
536 void imull(const Address& address);
537
538 void mull(Register reg);
539 void mull(const Address& address);
540
541 void sbbl(Register dst, Register src);
542 void sbbl(Register reg, const Immediate& imm);
543 void sbbl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400544 void sbbl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700545
546 void incl(Register reg);
547 void incl(const Address& address);
548
549 void decl(Register reg);
550 void decl(const Address& address);
551
552 void shll(Register reg, const Immediate& imm);
553 void shll(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000554 void shll(const Address& address, const Immediate& imm);
555 void shll(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700556 void shrl(Register reg, const Immediate& imm);
557 void shrl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000558 void shrl(const Address& address, const Immediate& imm);
559 void shrl(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700560 void sarl(Register reg, const Immediate& imm);
561 void sarl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000562 void sarl(const Address& address, const Immediate& imm);
563 void sarl(const Address& address, Register shifter);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000564 void shld(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000565 void shld(Register dst, Register src, const Immediate& imm);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000566 void shrd(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000567 void shrd(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700568
569 void negl(Register reg);
570 void notl(Register reg);
571
572 void enter(const Immediate& imm);
573 void leave();
574
575 void ret();
576 void ret(const Immediate& imm);
577
578 void nop();
579 void int3();
580 void hlt();
581
582 void j(Condition condition, Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400583 void j(Condition condition, NearLabel* label);
584 void jecxz(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700585
586 void jmp(Register reg);
Ian Rogers7caad772012-03-30 01:07:54 -0700587 void jmp(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700588 void jmp(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400589 void jmp(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700590
Andreas Gampe21030dd2015-05-07 14:46:15 -0700591 void repne_scasw();
agicsaki71311f82015-07-27 11:34:13 -0700592 void repe_cmpsw();
agicsaki970abfb2015-07-31 10:31:14 -0700593 void repe_cmpsl();
Mark Mendellb9c4bbe2015-07-01 14:26:52 -0400594 void rep_movsw();
Andreas Gampe21030dd2015-05-07 14:46:15 -0700595
Ian Rogers2c8f6532011-09-02 17:16:34 -0700596 X86Assembler* lock();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700597 void cmpxchgl(const Address& address, Register reg);
Mark Mendell58d25fd2015-04-03 14:52:31 -0400598 void cmpxchg8b(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700599
Elliott Hughes79ab9e32012-03-12 15:41:35 -0700600 void mfence();
601
Ian Rogers2c8f6532011-09-02 17:16:34 -0700602 X86Assembler* fs();
Ian Rogersbefbd572014-03-06 01:13:39 -0800603 X86Assembler* gs();
Ian Rogersb033c752011-07-20 12:22:35 -0700604
605 //
606 // Macros for High-level operations.
607 //
608
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700609 void AddImmediate(Register reg, const Immediate& imm);
610
Roland Levillain647b9ed2014-11-27 12:06:00 +0000611 void LoadLongConstant(XmmRegister dst, int64_t value);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700612 void LoadDoubleConstant(XmmRegister dst, double value);
613
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700614 void LockCmpxchgl(const Address& address, Register reg) {
Ian Rogers0d666d82011-08-14 16:03:46 -0700615 lock()->cmpxchgl(address, reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700616 }
617
Mark Mendell58d25fd2015-04-03 14:52:31 -0400618 void LockCmpxchg8b(const Address& address) {
619 lock()->cmpxchg8b(address);
620 }
621
Ian Rogersb033c752011-07-20 12:22:35 -0700622 //
623 // Misc. functionality
624 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700625 int PreferredLoopAlignment() { return 16; }
626 void Align(int alignment, int offset);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700627 void Bind(Label* label) OVERRIDE;
628 void Jump(Label* label) OVERRIDE {
629 jmp(label);
630 }
Mark Mendell73f455e2015-08-21 09:30:05 -0400631 void Bind(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700632
Ian Rogers2c8f6532011-09-02 17:16:34 -0700633 //
634 // Overridden common assembler high-level functionality
635 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700636
Ian Rogers2c8f6532011-09-02 17:16:34 -0700637 // Emit code that will create an activation on the stack
Vladimir Marko32248382016-05-19 10:37:24 +0100638 void BuildFrame(size_t frame_size,
639 ManagedRegister method_reg,
640 ArrayRef<const ManagedRegister> callee_save_regs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700641 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700642
643 // Emit code that will remove an activation from the stack
Vladimir Marko32248382016-05-19 10:37:24 +0100644 void RemoveFrame(size_t frame_size, ArrayRef<const ManagedRegister> callee_save_regs)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700645 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700646
Ian Rogersdd7624d2014-03-14 17:43:00 -0700647 void IncreaseFrameSize(size_t adjust) OVERRIDE;
648 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700649
650 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700651 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
652 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
653 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700654
Ian Rogersdd7624d2014-03-14 17:43:00 -0700655 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700656
Andreas Gampe542451c2016-07-26 09:02:02 -0700657 void StoreImmediateToThread32(ThreadOffset32 dest, uint32_t imm, ManagedRegister scratch)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700658 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700659
Andreas Gampe542451c2016-07-26 09:02:02 -0700660 void StoreStackOffsetToThread32(ThreadOffset32 thr_offs, FrameOffset fr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700661 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700662
Andreas Gampe542451c2016-07-26 09:02:02 -0700663 void StoreStackPointerToThread32(ThreadOffset32 thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700664
Ian Rogersdd7624d2014-03-14 17:43:00 -0700665 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
666 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700667
668 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700669 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700670
Andreas Gampe542451c2016-07-26 09:02:02 -0700671 void LoadFromThread32(ManagedRegister dest, ThreadOffset32 src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700672
Mathieu Chartiere401d142015-04-22 13:56:20 -0700673 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700674
Mathieu Chartiere401d142015-04-22 13:56:20 -0700675 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +0100676 bool unpoison_reference) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700677
Ian Rogersdd7624d2014-03-14 17:43:00 -0700678 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700679
Andreas Gampe542451c2016-07-26 09:02:02 -0700680 void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset32 offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700681
682 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700683 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700684
Andreas Gampe542451c2016-07-26 09:02:02 -0700685 void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset32 thr_offs,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700686 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700687
Andreas Gampe542451c2016-07-26 09:02:02 -0700688 void CopyRawPtrToThread32(ThreadOffset32 thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
Ian Rogersdd7624d2014-03-14 17:43:00 -0700689 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700690
Ian Rogersdd7624d2014-03-14 17:43:00 -0700691 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700692
Ian Rogersdd7624d2014-03-14 17:43:00 -0700693 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700694
Ian Rogersdd7624d2014-03-14 17:43:00 -0700695 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
696 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700697
Ian Rogersdd7624d2014-03-14 17:43:00 -0700698 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
699 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700700
Ian Rogersdd7624d2014-03-14 17:43:00 -0700701 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
702 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700703
Ian Rogersdd7624d2014-03-14 17:43:00 -0700704 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
705 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700706
Ian Rogersdd7624d2014-03-14 17:43:00 -0700707 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
708 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700709
Ian Rogersdd7624d2014-03-14 17:43:00 -0700710 void MemoryBarrier(ManagedRegister) OVERRIDE;
Ian Rogerse5de95b2011-09-18 20:31:38 -0700711
jeffhao58136ca2012-05-24 13:40:11 -0700712 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700713 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700714
jeffhaocee4d0c2012-06-15 14:42:01 -0700715 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700716 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700717
Ian Rogers2c8f6532011-09-02 17:16:34 -0700718 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700719 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
720 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700721
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700722 // 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 -0700723 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700724 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700725 // null.
726 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
727 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700728
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700729 // 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 -0700730 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700731 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
732 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700733
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700734 // src holds a handle scope entry (Object**) load this into dst
735 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700736
737 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
738 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700739 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
740 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700741
742 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700743 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
744 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
Andreas Gampe542451c2016-07-26 09:02:02 -0700745 void CallFromThread32(ThreadOffset32 offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700746
Ian Rogers2c8f6532011-09-02 17:16:34 -0700747 // Generate code to check if Thread::Current()->exception_ is non-null
748 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700749 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700750
Roland Levillain4d027112015-07-01 15:41:14 +0100751 //
752 // Heap poisoning.
753 //
754
755 // Poison a heap reference contained in `reg`.
756 void PoisonHeapReference(Register reg) { negl(reg); }
757 // Unpoison a heap reference contained in `reg`.
758 void UnpoisonHeapReference(Register reg) { negl(reg); }
759 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
760 void MaybeUnpoisonHeapReference(Register reg) {
761 if (kPoisonHeapReferences) {
762 UnpoisonHeapReference(reg);
763 }
764 }
765
Mark Mendell0616ae02015-04-17 12:49:27 -0400766 // Add a double to the constant area, returning the offset into
767 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400768 size_t AddDouble(double v) { return constant_area_.AddDouble(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400769
770 // Add a float to the constant area, returning the offset into
771 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400772 size_t AddFloat(float v) { return constant_area_.AddFloat(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400773
774 // Add an int32_t 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 AddInt32(int32_t v) {
777 return constant_area_.AddInt32(v);
778 }
779
780 // Add an int32_t to the end of the constant area, returning the offset into
781 // the constant area where the literal resides.
782 size_t AppendInt32(int32_t v) {
783 return constant_area_.AppendInt32(v);
784 }
Mark Mendell0616ae02015-04-17 12:49:27 -0400785
786 // Add an int64_t to the constant area, returning the offset into
787 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400788 size_t AddInt64(int64_t v) { return constant_area_.AddInt64(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400789
790 // Add the contents of the constant area to the assembler buffer.
791 void AddConstantArea();
792
793 // Is the constant area empty? Return true if there are no literals in the constant area.
794 bool IsConstantAreaEmpty() const { return constant_area_.IsEmpty(); }
Mark Mendell805b3b52015-09-18 14:10:29 -0400795
796 // Return the current size of the constant area.
797 size_t ConstantAreaSize() const { return constant_area_.GetSize(); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400798
Ian Rogers2c8f6532011-09-02 17:16:34 -0700799 private:
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700800 inline void EmitUint8(uint8_t value);
801 inline void EmitInt32(int32_t value);
802 inline void EmitRegisterOperand(int rm, int reg);
803 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg);
804 inline void EmitFixup(AssemblerFixup* fixup);
805 inline void EmitOperandSizeOverride();
806
807 void EmitOperand(int rm, const Operand& operand);
808 void EmitImmediate(const Immediate& imm);
809 void EmitComplex(int rm, const Operand& operand, const Immediate& immediate);
810 void EmitLabel(Label* label, int instruction_size);
811 void EmitLabelLink(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400812 void EmitLabelLink(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700813
Mark P Mendell73945692015-04-29 14:56:17 +0000814 void EmitGenericShift(int rm, const Operand& operand, const Immediate& imm);
815 void EmitGenericShift(int rm, const Operand& operand, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700816
Mark Mendell0616ae02015-04-17 12:49:27 -0400817 ConstantArea constant_area_;
818
Ian Rogers2c8f6532011-09-02 17:16:34 -0700819 DISALLOW_COPY_AND_ASSIGN(X86Assembler);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700820};
821
Ian Rogers2c8f6532011-09-02 17:16:34 -0700822inline void X86Assembler::EmitUint8(uint8_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700823 buffer_.Emit<uint8_t>(value);
824}
825
Ian Rogers2c8f6532011-09-02 17:16:34 -0700826inline void X86Assembler::EmitInt32(int32_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700827 buffer_.Emit<int32_t>(value);
828}
829
Ian Rogers2c8f6532011-09-02 17:16:34 -0700830inline void X86Assembler::EmitRegisterOperand(int rm, int reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700831 CHECK_GE(rm, 0);
832 CHECK_LT(rm, 8);
833 buffer_.Emit<uint8_t>(0xC0 + (rm << 3) + reg);
834}
835
Ian Rogers2c8f6532011-09-02 17:16:34 -0700836inline void X86Assembler::EmitXmmRegisterOperand(int rm, XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700837 EmitRegisterOperand(rm, static_cast<Register>(reg));
838}
839
Ian Rogers2c8f6532011-09-02 17:16:34 -0700840inline void X86Assembler::EmitFixup(AssemblerFixup* fixup) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700841 buffer_.EmitFixup(fixup);
842}
843
Ian Rogers2c8f6532011-09-02 17:16:34 -0700844inline void X86Assembler::EmitOperandSizeOverride() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700845 EmitUint8(0x66);
846}
847
Ian Rogers2c8f6532011-09-02 17:16:34 -0700848// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700849class X86ExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700850 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -0700851 explicit X86ExceptionSlowPath(size_t stack_adjust) : stack_adjust_(stack_adjust) {}
Ian Rogersdd7624d2014-03-14 17:43:00 -0700852 virtual void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700853 private:
854 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700855};
856
Ian Rogers2c8f6532011-09-02 17:16:34 -0700857} // namespace x86
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700858} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700859
Ian Rogers166db042013-07-26 12:05:57 -0700860#endif // ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_