blob: 655af9c184ff7a9123db0f8ed58e2688093695f5 [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 Marko80afd022015-05-19 18:08:00 +010021#include "base/bit_utils.h"
Elliott Hughes76160052012-12-12 16:31:20 -080022#include "base/macros.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070023#include "constants_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070024#include "globals.h"
Ian Rogers2c8f6532011-09-02 17:16:34 -070025#include "managed_register_x86.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "offsets.h"
Ian Rogers166db042013-07-26 12:05:57 -070027#include "utils/assembler.h"
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070028
Carl Shapiro6b6b5f02011-06-21 15:05:09 -070029namespace art {
Ian Rogers2c8f6532011-09-02 17:16:34 -070030namespace x86 {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070031
Ian Rogerscf7f1912014-10-22 22:06:39 -070032class Immediate : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070033 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080034 explicit Immediate(int32_t value_in) : value_(value_in) {}
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070035
36 int32_t value() const { return value_; }
37
Andreas Gampeab1eb0d2015-02-13 19:23:55 -080038 bool is_int8() const { return IsInt<8>(value_); }
39 bool is_uint8() const { return IsUint<8>(value_); }
40 bool is_int16() const { return IsInt<16>(value_); }
41 bool is_uint16() const { return IsUint<16>(value_); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070042
43 private:
44 const int32_t value_;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070045};
46
47
Ian Rogerscf7f1912014-10-22 22:06:39 -070048class Operand : public ValueObject {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070049 public:
50 uint8_t mod() const {
51 return (encoding_at(0) >> 6) & 3;
52 }
53
54 Register rm() const {
55 return static_cast<Register>(encoding_at(0) & 7);
56 }
57
58 ScaleFactor scale() const {
59 return static_cast<ScaleFactor>((encoding_at(1) >> 6) & 3);
60 }
61
62 Register index() const {
63 return static_cast<Register>((encoding_at(1) >> 3) & 7);
64 }
65
66 Register base() const {
67 return static_cast<Register>(encoding_at(1) & 7);
68 }
69
70 int8_t disp8() const {
71 CHECK_GE(length_, 2);
72 return static_cast<int8_t>(encoding_[length_ - 1]);
73 }
74
75 int32_t disp32() const {
76 CHECK_GE(length_, 5);
77 int32_t value;
78 memcpy(&value, &encoding_[length_ - 4], sizeof(value));
79 return value;
80 }
81
82 bool IsRegister(Register reg) const {
83 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only.
84 && ((encoding_[0] & 0x07) == reg); // Register codes match.
85 }
86
87 protected:
88 // Operand can be sub classed (e.g: Address).
Mark Mendell0616ae02015-04-17 12:49:27 -040089 Operand() : length_(0), fixup_(nullptr) { }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070090
Andreas Gampe277ccbd2014-11-03 21:36:10 -080091 void SetModRM(int mod_in, Register rm_in) {
92 CHECK_EQ(mod_in & ~3, 0);
93 encoding_[0] = (mod_in << 6) | rm_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070094 length_ = 1;
95 }
96
Andreas Gampe277ccbd2014-11-03 21:36:10 -080097 void SetSIB(ScaleFactor scale_in, Register index_in, Register base_in) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -070098 CHECK_EQ(length_, 1);
Andreas Gampe277ccbd2014-11-03 21:36:10 -080099 CHECK_EQ(scale_in & ~3, 0);
100 encoding_[1] = (scale_in << 6) | (index_in << 3) | base_in;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700101 length_ = 2;
102 }
103
104 void SetDisp8(int8_t disp) {
105 CHECK(length_ == 1 || length_ == 2);
106 encoding_[length_++] = static_cast<uint8_t>(disp);
107 }
108
109 void SetDisp32(int32_t disp) {
110 CHECK(length_ == 1 || length_ == 2);
111 int disp_size = sizeof(disp);
112 memmove(&encoding_[length_], &disp, disp_size);
113 length_ += disp_size;
114 }
115
Mark Mendell0616ae02015-04-17 12:49:27 -0400116 AssemblerFixup* GetFixup() const {
117 return fixup_;
118 }
119
120 void SetFixup(AssemblerFixup* fixup) {
121 fixup_ = fixup;
122 }
123
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700124 private:
Ian Rogers13735952014-10-08 12:43:28 -0700125 uint8_t length_;
126 uint8_t encoding_[6];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700127
Mark Mendell0616ae02015-04-17 12:49:27 -0400128 // A fixup can be associated with the operand, in order to be applied after the
129 // code has been generated. This is used for constant area fixups.
130 AssemblerFixup* fixup_;
131
132 explicit Operand(Register reg) : fixup_(nullptr) { SetModRM(3, reg); }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700133
134 // Get the operand encoding byte at the given index.
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800135 uint8_t encoding_at(int index_in) const {
136 CHECK_GE(index_in, 0);
137 CHECK_LT(index_in, length_);
138 return encoding_[index_in];
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700139 }
140
Ian Rogers2c8f6532011-09-02 17:16:34 -0700141 friend class X86Assembler;
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700142};
143
144
145class Address : public Operand {
146 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800147 Address(Register base_in, int32_t disp) {
148 Init(base_in, disp);
Ian Rogersb033c752011-07-20 12:22:35 -0700149 }
150
Mark Mendell0616ae02015-04-17 12:49:27 -0400151 Address(Register base_in, int32_t disp, AssemblerFixup *fixup) {
152 Init(base_in, disp);
153 SetFixup(fixup);
154 }
155
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800156 Address(Register base_in, Offset disp) {
157 Init(base_in, disp.Int32Value());
Ian Rogersa04d3972011-08-17 11:33:44 -0700158 }
159
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800160 Address(Register base_in, FrameOffset disp) {
161 CHECK_EQ(base_in, ESP);
Ian Rogersb033c752011-07-20 12:22:35 -0700162 Init(ESP, disp.Int32Value());
163 }
164
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800165 Address(Register base_in, MemberOffset disp) {
166 Init(base_in, disp.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700167 }
168
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800169 Address(Register index_in, ScaleFactor scale_in, int32_t disp) {
170 CHECK_NE(index_in, ESP); // Illegal addressing mode.
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700171 SetModRM(0, ESP);
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800172 SetSIB(scale_in, index_in, EBP);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700173 SetDisp32(disp);
174 }
175
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800176 Address(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
Mark Mendell805b3b52015-09-18 14:10:29 -0400177 Init(base_in, index_in, scale_in, disp);
178 }
179
180 Address(Register base_in,
181 Register index_in,
182 ScaleFactor scale_in,
183 int32_t disp, AssemblerFixup *fixup) {
184 Init(base_in, index_in, scale_in, disp);
185 SetFixup(fixup);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700186 }
187
Ian Rogers13735952014-10-08 12:43:28 -0700188 static Address Absolute(uintptr_t addr) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700189 Address result;
Ian Rogersdd7624d2014-03-14 17:43:00 -0700190 result.SetModRM(0, EBP);
191 result.SetDisp32(addr);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700192 return result;
193 }
194
Ian Rogersdd7624d2014-03-14 17:43:00 -0700195 static Address Absolute(ThreadOffset<4> addr) {
196 return Absolute(addr.Int32Value());
Ian Rogersb033c752011-07-20 12:22:35 -0700197 }
198
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700199 private:
200 Address() {}
Mark Mendell805b3b52015-09-18 14:10:29 -0400201
202 void Init(Register base_in, int32_t disp) {
203 if (disp == 0 && base_in != EBP) {
204 SetModRM(0, base_in);
205 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
206 } else if (disp >= -128 && disp <= 127) {
207 SetModRM(1, base_in);
208 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
209 SetDisp8(disp);
210 } else {
211 SetModRM(2, base_in);
212 if (base_in == ESP) SetSIB(TIMES_1, ESP, base_in);
213 SetDisp32(disp);
214 }
215 }
216
217 void Init(Register base_in, Register index_in, ScaleFactor scale_in, int32_t disp) {
218 CHECK_NE(index_in, ESP); // Illegal addressing mode.
219 if (disp == 0 && base_in != EBP) {
220 SetModRM(0, ESP);
221 SetSIB(scale_in, index_in, base_in);
222 } else if (disp >= -128 && disp <= 127) {
223 SetModRM(1, ESP);
224 SetSIB(scale_in, index_in, base_in);
225 SetDisp8(disp);
226 } else {
227 SetModRM(2, ESP);
228 SetSIB(scale_in, index_in, base_in);
229 SetDisp32(disp);
230 }
231 }
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700232};
233
234
Mark Mendell73f455e2015-08-21 09:30:05 -0400235// This is equivalent to the Label class, used in a slightly different context. We
236// inherit the functionality of the Label class, but prevent unintended
237// derived-to-base conversions by making the base class private.
238class NearLabel : private Label {
239 public:
240 NearLabel() : Label() {}
241
242 // Expose the Label routines that we need.
243 using Label::Position;
244 using Label::LinkPosition;
245 using Label::IsBound;
246 using Label::IsUnused;
247 using Label::IsLinked;
248
249 private:
250 using Label::BindTo;
251 using Label::LinkTo;
252
253 friend class x86::X86Assembler;
254
255 DISALLOW_COPY_AND_ASSIGN(NearLabel);
256};
257
Mark Mendell0616ae02015-04-17 12:49:27 -0400258/**
259 * Class to handle constant area values.
260 */
261class ConstantArea {
262 public:
263 ConstantArea() {}
264
265 // Add a double to the constant area, returning the offset into
266 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400267 size_t AddDouble(double v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400268
269 // Add a float to the constant area, returning the offset into
270 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400271 size_t AddFloat(float v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400272
273 // Add an int32_t to the constant area, returning the offset into
274 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400275 size_t AddInt32(int32_t v);
276
277 // Add an int32_t to the end of the constant area, returning the offset into
278 // the constant area where the literal resides.
279 size_t AppendInt32(int32_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400280
281 // Add an int64_t to the constant area, returning the offset into
282 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400283 size_t AddInt64(int64_t v);
Mark Mendell0616ae02015-04-17 12:49:27 -0400284
285 bool IsEmpty() const {
286 return buffer_.size() == 0;
287 }
288
Mark Mendell805b3b52015-09-18 14:10:29 -0400289 size_t GetSize() const {
290 return buffer_.size() * elem_size_;
291 }
292
Mark Mendell0616ae02015-04-17 12:49:27 -0400293 const std::vector<int32_t>& GetBuffer() const {
294 return buffer_;
295 }
296
Mark Mendell0616ae02015-04-17 12:49:27 -0400297 private:
Mark Mendell805b3b52015-09-18 14:10:29 -0400298 static constexpr size_t elem_size_ = sizeof(int32_t);
Mark Mendell0616ae02015-04-17 12:49:27 -0400299 std::vector<int32_t> buffer_;
Mark Mendell0616ae02015-04-17 12:49:27 -0400300};
Mark Mendell73f455e2015-08-21 09:30:05 -0400301
Ian Rogersbefbd572014-03-06 01:13:39 -0800302class X86Assembler FINAL : public Assembler {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700303 public:
Roland Levillain3887c462015-08-12 18:15:42 +0100304 X86Assembler() {}
Ian Rogers2c8f6532011-09-02 17:16:34 -0700305 virtual ~X86Assembler() {}
buzbeec143c552011-08-20 17:38:58 -0700306
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700307 /*
308 * Emit Machine Instructions.
309 */
310 void call(Register reg);
311 void call(const Address& address);
312 void call(Label* label);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +0000313 void call(const ExternalLabel& label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700314
315 void pushl(Register reg);
316 void pushl(const Address& address);
317 void pushl(const Immediate& imm);
318
319 void popl(Register reg);
320 void popl(const Address& address);
321
322 void movl(Register dst, const Immediate& src);
323 void movl(Register dst, Register src);
324
325 void movl(Register dst, const Address& src);
326 void movl(const Address& dst, Register src);
327 void movl(const Address& dst, const Immediate& imm);
Ian Rogersbdb03912011-09-14 00:55:44 -0700328 void movl(const Address& dst, Label* lbl);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700329
Mark Mendell7a08fb52015-07-15 14:09:35 -0400330 void movntl(const Address& dst, Register src);
331
Mark Mendell09ed1a32015-03-25 08:30:06 -0400332 void bswapl(Register dst);
Mark Mendellbcee0922015-09-15 21:45:01 -0400333 void bsfl(Register dst, Register src);
334 void bsfl(Register dst, const Address& src);
Mark Mendell8ae3ffb2015-08-12 21:16:41 -0400335 void bsrl(Register dst, Register src);
336 void bsrl(Register dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400337
Mark Mendellbcee0922015-09-15 21:45:01 -0400338 void rorl(Register reg, const Immediate& imm);
339 void rorl(Register operand, Register shifter);
340 void roll(Register reg, const Immediate& imm);
341 void roll(Register operand, Register shifter);
342
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700343 void movzxb(Register dst, ByteRegister src);
344 void movzxb(Register dst, const Address& src);
345 void movsxb(Register dst, ByteRegister src);
346 void movsxb(Register dst, const Address& src);
347 void movb(Register dst, const Address& src);
348 void movb(const Address& dst, ByteRegister src);
349 void movb(const Address& dst, const Immediate& imm);
350
351 void movzxw(Register dst, Register src);
352 void movzxw(Register dst, const Address& src);
353 void movsxw(Register dst, Register src);
354 void movsxw(Register dst, const Address& src);
355 void movw(Register dst, const Address& src);
356 void movw(const Address& dst, Register src);
Nicolas Geoffray26a25ef2014-09-30 13:54:09 +0100357 void movw(const Address& dst, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700358
359 void leal(Register dst, const Address& src);
360
Ian Rogersb033c752011-07-20 12:22:35 -0700361 void cmovl(Condition condition, Register dst, Register src);
362
Nicolas Geoffray5b4b8982014-12-18 17:45:56 +0000363 void setb(Condition condition, Register dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700364
Nicolas Geoffray7fb49da2014-10-06 09:12:41 +0100365 void movaps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700366 void movss(XmmRegister dst, const Address& src);
367 void movss(const Address& dst, XmmRegister src);
368 void movss(XmmRegister dst, XmmRegister src);
369
370 void movd(XmmRegister dst, Register src);
371 void movd(Register dst, XmmRegister src);
372
373 void addss(XmmRegister dst, XmmRegister src);
374 void addss(XmmRegister dst, const Address& src);
375 void subss(XmmRegister dst, XmmRegister src);
376 void subss(XmmRegister dst, const Address& src);
377 void mulss(XmmRegister dst, XmmRegister src);
378 void mulss(XmmRegister dst, const Address& src);
379 void divss(XmmRegister dst, XmmRegister src);
380 void divss(XmmRegister dst, const Address& src);
381
382 void movsd(XmmRegister dst, const Address& src);
383 void movsd(const Address& dst, XmmRegister src);
384 void movsd(XmmRegister dst, XmmRegister src);
385
Calin Juravle52c48962014-12-16 17:02:57 +0000386 void psrlq(XmmRegister reg, const Immediate& shift_count);
387 void punpckldq(XmmRegister dst, XmmRegister src);
388
Nicolas Geoffray234d69d2015-03-09 10:28:50 +0000389 void movhpd(XmmRegister dst, const Address& src);
390 void movhpd(const Address& dst, XmmRegister src);
391
392 void psrldq(XmmRegister reg, const Immediate& shift_count);
393
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700394 void addsd(XmmRegister dst, XmmRegister src);
395 void addsd(XmmRegister dst, const Address& src);
396 void subsd(XmmRegister dst, XmmRegister src);
397 void subsd(XmmRegister dst, const Address& src);
398 void mulsd(XmmRegister dst, XmmRegister src);
399 void mulsd(XmmRegister dst, const Address& src);
400 void divsd(XmmRegister dst, XmmRegister src);
401 void divsd(XmmRegister dst, const Address& src);
402
403 void cvtsi2ss(XmmRegister dst, Register src);
404 void cvtsi2sd(XmmRegister dst, Register src);
405
406 void cvtss2si(Register dst, XmmRegister src);
407 void cvtss2sd(XmmRegister dst, XmmRegister src);
408
409 void cvtsd2si(Register dst, XmmRegister src);
410 void cvtsd2ss(XmmRegister dst, XmmRegister src);
411
412 void cvttss2si(Register dst, XmmRegister src);
413 void cvttsd2si(Register dst, XmmRegister src);
414
415 void cvtdq2pd(XmmRegister dst, XmmRegister src);
416
417 void comiss(XmmRegister a, XmmRegister b);
418 void comisd(XmmRegister a, XmmRegister b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000419 void ucomiss(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400420 void ucomiss(XmmRegister a, const Address& b);
Calin Juravleddb7df22014-11-25 20:56:51 +0000421 void ucomisd(XmmRegister a, XmmRegister b);
Mark Mendell9f51f262015-10-30 09:21:37 -0400422 void ucomisd(XmmRegister a, const Address& b);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700423
Mark Mendellfb8d2792015-03-31 22:16:59 -0400424 void roundsd(XmmRegister dst, XmmRegister src, const Immediate& imm);
425 void roundss(XmmRegister dst, XmmRegister src, const Immediate& imm);
426
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700427 void sqrtsd(XmmRegister dst, XmmRegister src);
428 void sqrtss(XmmRegister dst, XmmRegister src);
429
430 void xorpd(XmmRegister dst, const Address& src);
431 void xorpd(XmmRegister dst, XmmRegister src);
432 void xorps(XmmRegister dst, const Address& src);
433 void xorps(XmmRegister dst, XmmRegister src);
434
Mark Mendell09ed1a32015-03-25 08:30:06 -0400435 void andpd(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700436 void andpd(XmmRegister dst, const Address& src);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400437 void andps(XmmRegister dst, XmmRegister src);
438 void andps(XmmRegister dst, const Address& src);
439
440 void orpd(XmmRegister dst, XmmRegister src);
441 void orps(XmmRegister dst, XmmRegister src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700442
443 void flds(const Address& src);
444 void fstps(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500445 void fsts(const Address& dst);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700446
447 void fldl(const Address& src);
448 void fstpl(const Address& dst);
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500449 void fstl(const Address& dst);
450
451 void fstsw();
452
453 void fucompp();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700454
455 void fnstcw(const Address& dst);
456 void fldcw(const Address& src);
457
458 void fistpl(const Address& dst);
459 void fistps(const Address& dst);
460 void fildl(const Address& src);
Roland Levillain0a186012015-04-13 17:00:20 +0100461 void filds(const Address& src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700462
463 void fincstp();
464 void ffree(const Immediate& index);
465
466 void fsin();
467 void fcos();
468 void fptan();
Mark Mendell24f2dfa2015-01-14 19:51:45 -0500469 void fprem();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700470
471 void xchgl(Register dst, Register src);
Ian Rogers7caad772012-03-30 01:07:54 -0700472 void xchgl(Register reg, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700473
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100474 void cmpw(const Address& address, const Immediate& imm);
475
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700476 void cmpl(Register reg, const Immediate& imm);
477 void cmpl(Register reg0, Register reg1);
478 void cmpl(Register reg, const Address& address);
479
480 void cmpl(const Address& address, Register reg);
481 void cmpl(const Address& address, const Immediate& imm);
482
483 void testl(Register reg1, Register reg2);
484 void testl(Register reg, const Immediate& imm);
Nicolas Geoffrayf12feb82014-07-17 18:32:41 +0100485 void testl(Register reg1, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700486
487 void andl(Register dst, const Immediate& imm);
488 void andl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000489 void andl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700490
491 void orl(Register dst, const Immediate& imm);
492 void orl(Register dst, Register src);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000493 void orl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700494
495 void xorl(Register dst, Register src);
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +0100496 void xorl(Register dst, const Immediate& imm);
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000497 void xorl(Register dst, const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700498
499 void addl(Register dst, Register src);
500 void addl(Register reg, const Immediate& imm);
501 void addl(Register reg, const Address& address);
502
503 void addl(const Address& address, Register reg);
504 void addl(const Address& address, const Immediate& imm);
505
506 void adcl(Register dst, Register src);
507 void adcl(Register reg, const Immediate& imm);
508 void adcl(Register dst, const Address& address);
509
510 void subl(Register dst, Register src);
511 void subl(Register reg, const Immediate& imm);
512 void subl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400513 void subl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700514
515 void cdq();
516
517 void idivl(Register reg);
518
519 void imull(Register dst, Register src);
520 void imull(Register reg, const Immediate& imm);
Mark Mendell4a2aa4a2015-07-27 16:13:10 -0400521 void imull(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700522 void imull(Register reg, const Address& address);
523
524 void imull(Register reg);
525 void imull(const Address& address);
526
527 void mull(Register reg);
528 void mull(const Address& address);
529
530 void sbbl(Register dst, Register src);
531 void sbbl(Register reg, const Immediate& imm);
532 void sbbl(Register reg, const Address& address);
Mark Mendell09ed1a32015-03-25 08:30:06 -0400533 void sbbl(const Address& address, Register src);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700534
535 void incl(Register reg);
536 void incl(const Address& address);
537
538 void decl(Register reg);
539 void decl(const Address& address);
540
541 void shll(Register reg, const Immediate& imm);
542 void shll(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000543 void shll(const Address& address, const Immediate& imm);
544 void shll(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700545 void shrl(Register reg, const Immediate& imm);
546 void shrl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000547 void shrl(const Address& address, const Immediate& imm);
548 void shrl(const Address& address, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700549 void sarl(Register reg, const Immediate& imm);
550 void sarl(Register operand, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000551 void sarl(const Address& address, const Immediate& imm);
552 void sarl(const Address& address, Register shifter);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000553 void shld(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000554 void shld(Register dst, Register src, const Immediate& imm);
Calin Juravle9aec02f2014-11-18 23:06:35 +0000555 void shrd(Register dst, Register src, Register shifter);
Mark P Mendell73945692015-04-29 14:56:17 +0000556 void shrd(Register dst, Register src, const Immediate& imm);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700557
558 void negl(Register reg);
559 void notl(Register reg);
560
561 void enter(const Immediate& imm);
562 void leave();
563
564 void ret();
565 void ret(const Immediate& imm);
566
567 void nop();
568 void int3();
569 void hlt();
570
571 void j(Condition condition, Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400572 void j(Condition condition, NearLabel* label);
573 void jecxz(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700574
575 void jmp(Register reg);
Ian Rogers7caad772012-03-30 01:07:54 -0700576 void jmp(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700577 void jmp(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400578 void jmp(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700579
Andreas Gampe21030dd2015-05-07 14:46:15 -0700580 void repne_scasw();
agicsaki71311f82015-07-27 11:34:13 -0700581 void repe_cmpsw();
agicsaki970abfb2015-07-31 10:31:14 -0700582 void repe_cmpsl();
Mark Mendellb9c4bbe2015-07-01 14:26:52 -0400583 void rep_movsw();
Andreas Gampe21030dd2015-05-07 14:46:15 -0700584
Ian Rogers2c8f6532011-09-02 17:16:34 -0700585 X86Assembler* lock();
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700586 void cmpxchgl(const Address& address, Register reg);
Mark Mendell58d25fd2015-04-03 14:52:31 -0400587 void cmpxchg8b(const Address& address);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700588
Elliott Hughes79ab9e32012-03-12 15:41:35 -0700589 void mfence();
590
Ian Rogers2c8f6532011-09-02 17:16:34 -0700591 X86Assembler* fs();
Ian Rogersbefbd572014-03-06 01:13:39 -0800592 X86Assembler* gs();
Ian Rogersb033c752011-07-20 12:22:35 -0700593
594 //
595 // Macros for High-level operations.
596 //
597
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700598 void AddImmediate(Register reg, const Immediate& imm);
599
Roland Levillain647b9ed2014-11-27 12:06:00 +0000600 void LoadLongConstant(XmmRegister dst, int64_t value);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700601 void LoadDoubleConstant(XmmRegister dst, double value);
602
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700603 void LockCmpxchgl(const Address& address, Register reg) {
Ian Rogers0d666d82011-08-14 16:03:46 -0700604 lock()->cmpxchgl(address, reg);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700605 }
606
Mark Mendell58d25fd2015-04-03 14:52:31 -0400607 void LockCmpxchg8b(const Address& address) {
608 lock()->cmpxchg8b(address);
609 }
610
Ian Rogersb033c752011-07-20 12:22:35 -0700611 //
612 // Misc. functionality
613 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700614 int PreferredLoopAlignment() { return 16; }
615 void Align(int alignment, int offset);
Andreas Gampe85b62f22015-09-09 13:15:38 -0700616 void Bind(Label* label) OVERRIDE;
617 void Jump(Label* label) OVERRIDE {
618 jmp(label);
619 }
Mark Mendell73f455e2015-08-21 09:30:05 -0400620 void Bind(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700621
Ian Rogers2c8f6532011-09-02 17:16:34 -0700622 //
623 // Overridden common assembler high-level functionality
624 //
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700625
Ian Rogers2c8f6532011-09-02 17:16:34 -0700626 // Emit code that will create an activation on the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700627 void BuildFrame(size_t frame_size, ManagedRegister method_reg,
628 const std::vector<ManagedRegister>& callee_save_regs,
629 const ManagedRegisterEntrySpills& entry_spills) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700630
631 // Emit code that will remove an activation from the stack
Ian Rogersdd7624d2014-03-14 17:43:00 -0700632 void RemoveFrame(size_t frame_size, const std::vector<ManagedRegister>& callee_save_regs)
633 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700634
Ian Rogersdd7624d2014-03-14 17:43:00 -0700635 void IncreaseFrameSize(size_t adjust) OVERRIDE;
636 void DecreaseFrameSize(size_t adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700637
638 // Store routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700639 void Store(FrameOffset offs, ManagedRegister src, size_t size) OVERRIDE;
640 void StoreRef(FrameOffset dest, ManagedRegister src) OVERRIDE;
641 void StoreRawPtr(FrameOffset dest, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700642
Ian Rogersdd7624d2014-03-14 17:43:00 -0700643 void StoreImmediateToFrame(FrameOffset dest, uint32_t imm, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700644
Ian Rogersdd7624d2014-03-14 17:43:00 -0700645 void StoreImmediateToThread32(ThreadOffset<4> dest, uint32_t imm, ManagedRegister scratch)
646 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700647
Ian Rogersdd7624d2014-03-14 17:43:00 -0700648 void StoreStackOffsetToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs,
649 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700650
Ian Rogersdd7624d2014-03-14 17:43:00 -0700651 void StoreStackPointerToThread32(ThreadOffset<4> thr_offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700652
Ian Rogersdd7624d2014-03-14 17:43:00 -0700653 void StoreSpanning(FrameOffset dest, ManagedRegister src, FrameOffset in_off,
654 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700655
656 // Load routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700657 void Load(ManagedRegister dest, FrameOffset src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700658
Ian Rogersdd7624d2014-03-14 17:43:00 -0700659 void LoadFromThread32(ManagedRegister dest, ThreadOffset<4> src, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700660
Mathieu Chartiere401d142015-04-22 13:56:20 -0700661 void LoadRef(ManagedRegister dest, FrameOffset src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700662
Mathieu Chartiere401d142015-04-22 13:56:20 -0700663 void LoadRef(ManagedRegister dest, ManagedRegister base, MemberOffset offs,
Roland Levillain4d027112015-07-01 15:41:14 +0100664 bool unpoison_reference) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700665
Ian Rogersdd7624d2014-03-14 17:43:00 -0700666 void LoadRawPtr(ManagedRegister dest, ManagedRegister base, Offset offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700667
Ian Rogersdd7624d2014-03-14 17:43:00 -0700668 void LoadRawPtrFromThread32(ManagedRegister dest, ThreadOffset<4> offs) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700669
670 // Copying routines
Ian Rogersdd7624d2014-03-14 17:43:00 -0700671 void Move(ManagedRegister dest, ManagedRegister src, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700672
Ian Rogersdd7624d2014-03-14 17:43:00 -0700673 void CopyRawPtrFromThread32(FrameOffset fr_offs, ThreadOffset<4> thr_offs,
674 ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700675
Ian Rogersdd7624d2014-03-14 17:43:00 -0700676 void CopyRawPtrToThread32(ThreadOffset<4> thr_offs, FrameOffset fr_offs, ManagedRegister scratch)
677 OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700678
Ian Rogersdd7624d2014-03-14 17:43:00 -0700679 void CopyRef(FrameOffset dest, FrameOffset src, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700680
Ian Rogersdd7624d2014-03-14 17:43:00 -0700681 void Copy(FrameOffset dest, FrameOffset src, ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700682
Ian Rogersdd7624d2014-03-14 17:43:00 -0700683 void Copy(FrameOffset dest, ManagedRegister src_base, Offset src_offset, ManagedRegister scratch,
684 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700685
Ian Rogersdd7624d2014-03-14 17:43:00 -0700686 void Copy(ManagedRegister dest_base, Offset dest_offset, FrameOffset src, ManagedRegister scratch,
687 size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700688
Ian Rogersdd7624d2014-03-14 17:43:00 -0700689 void Copy(FrameOffset dest, FrameOffset src_base, Offset src_offset, ManagedRegister scratch,
690 size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700691
Ian Rogersdd7624d2014-03-14 17:43:00 -0700692 void Copy(ManagedRegister dest, Offset dest_offset, ManagedRegister src, Offset src_offset,
693 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700694
Ian Rogersdd7624d2014-03-14 17:43:00 -0700695 void Copy(FrameOffset dest, Offset dest_offset, FrameOffset src, Offset src_offset,
696 ManagedRegister scratch, size_t size) OVERRIDE;
Ian Rogersdc51b792011-09-22 20:41:37 -0700697
Ian Rogersdd7624d2014-03-14 17:43:00 -0700698 void MemoryBarrier(ManagedRegister) OVERRIDE;
Ian Rogerse5de95b2011-09-18 20:31:38 -0700699
jeffhao58136ca2012-05-24 13:40:11 -0700700 // Sign extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700701 void SignExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhao58136ca2012-05-24 13:40:11 -0700702
jeffhaocee4d0c2012-06-15 14:42:01 -0700703 // Zero extension
Ian Rogersdd7624d2014-03-14 17:43:00 -0700704 void ZeroExtend(ManagedRegister mreg, size_t size) OVERRIDE;
jeffhaocee4d0c2012-06-15 14:42:01 -0700705
Ian Rogers2c8f6532011-09-02 17:16:34 -0700706 // Exploit fast access in managed code to Thread::Current()
Ian Rogersdd7624d2014-03-14 17:43:00 -0700707 void GetCurrentThread(ManagedRegister tr) OVERRIDE;
708 void GetCurrentThread(FrameOffset dest_offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700709
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700710 // 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 -0700711 // value is null and null_allowed. in_reg holds a possibly stale reference
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700712 // that can be used to avoid loading the handle scope entry to see if the value is
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700713 // null.
714 void CreateHandleScopeEntry(ManagedRegister out_reg, FrameOffset handlescope_offset,
715 ManagedRegister in_reg, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700716
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700717 // 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 -0700718 // value is null and null_allowed.
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700719 void CreateHandleScopeEntry(FrameOffset out_off, FrameOffset handlescope_offset,
720 ManagedRegister scratch, bool null_allowed) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700721
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700722 // src holds a handle scope entry (Object**) load this into dst
723 void LoadReferenceFromHandleScope(ManagedRegister dst, ManagedRegister src) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700724
725 // Heap::VerifyObject on src. In some cases (such as a reference to this) we
726 // know that src may not be null.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700727 void VerifyObject(ManagedRegister src, bool could_be_null) OVERRIDE;
728 void VerifyObject(FrameOffset src, bool could_be_null) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700729
730 // Call to address held at [base+offset]
Ian Rogersdd7624d2014-03-14 17:43:00 -0700731 void Call(ManagedRegister base, Offset offset, ManagedRegister scratch) OVERRIDE;
732 void Call(FrameOffset base, Offset offset, ManagedRegister scratch) OVERRIDE;
733 void CallFromThread32(ThreadOffset<4> offset, ManagedRegister scratch) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700734
Ian Rogers2c8f6532011-09-02 17:16:34 -0700735 // Generate code to check if Thread::Current()->exception_ is non-null
736 // and branch to a ExceptionSlowPath if it is.
Ian Rogersdd7624d2014-03-14 17:43:00 -0700737 void ExceptionPoll(ManagedRegister scratch, size_t stack_adjust) OVERRIDE;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700738
Roland Levillain4d027112015-07-01 15:41:14 +0100739 //
740 // Heap poisoning.
741 //
742
743 // Poison a heap reference contained in `reg`.
744 void PoisonHeapReference(Register reg) { negl(reg); }
745 // Unpoison a heap reference contained in `reg`.
746 void UnpoisonHeapReference(Register reg) { negl(reg); }
747 // Unpoison a heap reference contained in `reg` if heap poisoning is enabled.
748 void MaybeUnpoisonHeapReference(Register reg) {
749 if (kPoisonHeapReferences) {
750 UnpoisonHeapReference(reg);
751 }
752 }
753
Mark Mendell0616ae02015-04-17 12:49:27 -0400754 // Add a double to the constant area, returning the offset into
755 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400756 size_t AddDouble(double v) { return constant_area_.AddDouble(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400757
758 // Add a float to the constant area, returning the offset into
759 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400760 size_t AddFloat(float v) { return constant_area_.AddFloat(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400761
762 // Add an int32_t to the constant area, returning the offset into
763 // the constant area where the literal resides.
Mark Mendell805b3b52015-09-18 14:10:29 -0400764 size_t AddInt32(int32_t v) {
765 return constant_area_.AddInt32(v);
766 }
767
768 // Add an int32_t to the end of the constant area, returning the offset into
769 // the constant area where the literal resides.
770 size_t AppendInt32(int32_t v) {
771 return constant_area_.AppendInt32(v);
772 }
Mark Mendell0616ae02015-04-17 12:49:27 -0400773
774 // Add an int64_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 AddInt64(int64_t v) { return constant_area_.AddInt64(v); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400777
778 // Add the contents of the constant area to the assembler buffer.
779 void AddConstantArea();
780
781 // Is the constant area empty? Return true if there are no literals in the constant area.
782 bool IsConstantAreaEmpty() const { return constant_area_.IsEmpty(); }
Mark Mendell805b3b52015-09-18 14:10:29 -0400783
784 // Return the current size of the constant area.
785 size_t ConstantAreaSize() const { return constant_area_.GetSize(); }
Mark Mendell0616ae02015-04-17 12:49:27 -0400786
Ian Rogers2c8f6532011-09-02 17:16:34 -0700787 private:
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700788 inline void EmitUint8(uint8_t value);
789 inline void EmitInt32(int32_t value);
790 inline void EmitRegisterOperand(int rm, int reg);
791 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg);
792 inline void EmitFixup(AssemblerFixup* fixup);
793 inline void EmitOperandSizeOverride();
794
795 void EmitOperand(int rm, const Operand& operand);
796 void EmitImmediate(const Immediate& imm);
797 void EmitComplex(int rm, const Operand& operand, const Immediate& immediate);
798 void EmitLabel(Label* label, int instruction_size);
799 void EmitLabelLink(Label* label);
Mark Mendell73f455e2015-08-21 09:30:05 -0400800 void EmitLabelLink(NearLabel* label);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700801
Mark P Mendell73945692015-04-29 14:56:17 +0000802 void EmitGenericShift(int rm, const Operand& operand, const Immediate& imm);
803 void EmitGenericShift(int rm, const Operand& operand, Register shifter);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700804
Mark Mendell0616ae02015-04-17 12:49:27 -0400805 ConstantArea constant_area_;
806
Ian Rogers2c8f6532011-09-02 17:16:34 -0700807 DISALLOW_COPY_AND_ASSIGN(X86Assembler);
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700808};
809
Ian Rogers2c8f6532011-09-02 17:16:34 -0700810inline void X86Assembler::EmitUint8(uint8_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700811 buffer_.Emit<uint8_t>(value);
812}
813
Ian Rogers2c8f6532011-09-02 17:16:34 -0700814inline void X86Assembler::EmitInt32(int32_t value) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700815 buffer_.Emit<int32_t>(value);
816}
817
Ian Rogers2c8f6532011-09-02 17:16:34 -0700818inline void X86Assembler::EmitRegisterOperand(int rm, int reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700819 CHECK_GE(rm, 0);
820 CHECK_LT(rm, 8);
821 buffer_.Emit<uint8_t>(0xC0 + (rm << 3) + reg);
822}
823
Ian Rogers2c8f6532011-09-02 17:16:34 -0700824inline void X86Assembler::EmitXmmRegisterOperand(int rm, XmmRegister reg) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700825 EmitRegisterOperand(rm, static_cast<Register>(reg));
826}
827
Ian Rogers2c8f6532011-09-02 17:16:34 -0700828inline void X86Assembler::EmitFixup(AssemblerFixup* fixup) {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700829 buffer_.EmitFixup(fixup);
830}
831
Ian Rogers2c8f6532011-09-02 17:16:34 -0700832inline void X86Assembler::EmitOperandSizeOverride() {
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700833 EmitUint8(0x66);
834}
835
Ian Rogers2c8f6532011-09-02 17:16:34 -0700836// Slowpath entered when Thread::Current()->_exception is non-null
Ian Rogersdd7624d2014-03-14 17:43:00 -0700837class X86ExceptionSlowPath FINAL : public SlowPath {
Ian Rogers2c8f6532011-09-02 17:16:34 -0700838 public:
Brian Carlstrom93ba8932013-07-17 21:31:49 -0700839 explicit X86ExceptionSlowPath(size_t stack_adjust) : stack_adjust_(stack_adjust) {}
Ian Rogersdd7624d2014-03-14 17:43:00 -0700840 virtual void Emit(Assembler *sp_asm) OVERRIDE;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700841 private:
842 const size_t stack_adjust_;
Ian Rogers2c8f6532011-09-02 17:16:34 -0700843};
844
Ian Rogers2c8f6532011-09-02 17:16:34 -0700845} // namespace x86
Carl Shapiro6b6b5f02011-06-21 15:05:09 -0700846} // namespace art
Carl Shapiroa5d5cfd2011-06-21 12:46:59 -0700847
Ian Rogers166db042013-07-26 12:05:57 -0700848#endif // ART_COMPILER_UTILS_X86_ASSEMBLER_X86_H_