blob: 4e542d72c9b04a60a5cefc90266c852d2073ecc0 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
Steve Block1e0659c2011-05-24 12:43:12 +010033// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35// A light-weight IA32 Assembler.
36
37#ifndef V8_IA32_ASSEMBLER_IA32_H_
38#define V8_IA32_ASSEMBLER_IA32_H_
39
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040#include <deque>
41
42#include "src/assembler.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044#include "src/utils.h"
Steve Blockd0582a62009-12-15 09:54:21 +000045
Steve Blocka7e24c12009-10-30 11:49:00 +000046namespace v8 {
47namespace internal {
48
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049#define GENERAL_REGISTERS(V) \
50 V(eax) \
51 V(ecx) \
52 V(edx) \
53 V(ebx) \
54 V(esp) \
55 V(ebp) \
56 V(esi) \
57 V(edi)
58
59#define ALLOCATABLE_GENERAL_REGISTERS(V) \
60 V(eax) \
61 V(ecx) \
62 V(edx) \
63 V(ebx) \
64 V(esi) \
65 V(edi)
66
67#define DOUBLE_REGISTERS(V) \
68 V(xmm0) \
69 V(xmm1) \
70 V(xmm2) \
71 V(xmm3) \
72 V(xmm4) \
73 V(xmm5) \
74 V(xmm6) \
75 V(xmm7)
76
Ben Murdochc5610432016-08-08 18:44:38 +010077#define FLOAT_REGISTERS DOUBLE_REGISTERS
78#define SIMD_REGISTERS DOUBLE_REGISTERS
79
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000080#define ALLOCATABLE_DOUBLE_REGISTERS(V) \
81 V(xmm1) \
82 V(xmm2) \
83 V(xmm3) \
84 V(xmm4) \
85 V(xmm5) \
86 V(xmm6) \
87 V(xmm7)
88
Steve Blocka7e24c12009-10-30 11:49:00 +000089// CPU Registers.
90//
91// 1) We would prefer to use an enum, but enum values are assignment-
92// compatible with int, which has caused code-generation bugs.
93//
94// 2) We would prefer to use a class instead of a struct but we don't like
95// the register initialization to depend on the particular initialization
96// order (which appears to be different on OS X, Linux, and Windows for the
97// installed versions of C++ we tried). Using a struct permits C-style
98// "initialization". Also, the Register objects cannot be const as this
99// forces initialization stubs in MSVC, making us dependent on initialization
100// order.
101//
102// 3) By not using an enum, we are possibly preventing the compiler from
103// doing certain constant folds, which may significantly reduce the
104// code generated for some assembly instructions (because they boil down
105// to a few constants). If this is a problem, we could change the code
106// such that we use an enum in optimized mode, and the struct in debug
107// mode. This way we get the compile-time error checking in debug mode
108// and best performance in optimized code.
109//
110struct Register {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 enum Code {
112#define REGISTER_CODE(R) kCode_##R,
113 GENERAL_REGISTERS(REGISTER_CODE)
114#undef REGISTER_CODE
115 kAfterLast,
116 kCode_no_reg = -1
117 };
Ben Murdochb0fe1622011-05-05 13:52:32 +0100118
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119 static const int kNumRegisters = Code::kAfterLast;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100120
121 static Register from_code(int code) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000122 DCHECK(code >= 0);
123 DCHECK(code < kNumRegisters);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124 Register r = {code};
Ben Murdochb0fe1622011-05-05 13:52:32 +0100125 return r;
126 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 bool is_valid() const { return 0 <= reg_code && reg_code < kNumRegisters; }
128 bool is(Register reg) const { return reg_code == reg.reg_code; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100129 int code() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131 return reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000132 }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100133 int bit() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000135 return 1 << reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000136 }
137
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000138 bool is_byte_register() const { return reg_code <= 3; }
139
Andrei Popescu31002712010-02-23 13:46:05 +0000140 // Unfortunately we can't make this private in a struct.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000142};
143
Steve Block1e0659c2011-05-24 12:43:12 +0100144
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145#define DECLARE_REGISTER(R) const Register R = {Register::kCode_##R};
146GENERAL_REGISTERS(DECLARE_REGISTER)
147#undef DECLARE_REGISTER
148const Register no_reg = {Register::kCode_no_reg};
Steve Blocka7e24c12009-10-30 11:49:00 +0000149
Ben Murdoch61f157c2016-09-16 13:49:30 +0100150static const bool kSimpleFPAliasing = true;
151
Ben Murdochc5610432016-08-08 18:44:38 +0100152struct XMMRegister {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000153 enum Code {
154#define REGISTER_CODE(R) kCode_##R,
155 DOUBLE_REGISTERS(REGISTER_CODE)
156#undef REGISTER_CODE
157 kAfterLast,
158 kCode_no_reg = -1
159 };
Steve Block1e0659c2011-05-24 12:43:12 +0100160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161 static const int kMaxNumRegisters = Code::kAfterLast;
Steve Block1e0659c2011-05-24 12:43:12 +0100162
Ben Murdochc5610432016-08-08 18:44:38 +0100163 static XMMRegister from_code(int code) {
164 XMMRegister result = {code};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165 return result;
166 }
167
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 bool is_valid() const { return 0 <= reg_code && reg_code < kMaxNumRegisters; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169
170 int code() const {
171 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172 return reg_code;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173 }
174
Ben Murdochc5610432016-08-08 18:44:38 +0100175 bool is(XMMRegister reg) const { return reg_code == reg.reg_code; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000176
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000177 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000178};
179
Ben Murdochc5610432016-08-08 18:44:38 +0100180typedef XMMRegister FloatRegister;
181
182typedef XMMRegister DoubleRegister;
183
184typedef XMMRegister Simd128Register;
185
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000186#define DECLARE_REGISTER(R) \
187 const DoubleRegister R = {DoubleRegister::kCode_##R};
188DOUBLE_REGISTERS(DECLARE_REGISTER)
189#undef DECLARE_REGISTER
190const DoubleRegister no_double_reg = {DoubleRegister::kCode_no_reg};
Ben Murdochb0fe1622011-05-05 13:52:32 +0100191
Steve Blocka7e24c12009-10-30 11:49:00 +0000192enum Condition {
193 // any value < 0 is considered no_condition
194 no_condition = -1,
195
196 overflow = 0,
197 no_overflow = 1,
198 below = 2,
199 above_equal = 3,
200 equal = 4,
201 not_equal = 5,
202 below_equal = 6,
203 above = 7,
204 negative = 8,
205 positive = 9,
206 parity_even = 10,
207 parity_odd = 11,
208 less = 12,
209 greater_equal = 13,
210 less_equal = 14,
211 greater = 15,
212
213 // aliases
214 carry = below,
215 not_carry = above_equal,
216 zero = equal,
217 not_zero = not_equal,
218 sign = negative,
219 not_sign = positive
220};
221
222
223// Returns the equivalent of !cc.
224// Negation of the default no_condition (-1) results in a non-default
225// no_condition value (-2). As long as tests for no_condition check
226// for condition < 0, this will work as expected.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100227inline Condition NegateCondition(Condition cc) {
228 return static_cast<Condition>(cc ^ 1);
229}
230
Steve Blocka7e24c12009-10-30 11:49:00 +0000231
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232// Commute a condition such that {a cond b == b cond' a}.
233inline Condition CommuteCondition(Condition cc) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 switch (cc) {
235 case below:
236 return above;
237 case above:
238 return below;
239 case above_equal:
240 return below_equal;
241 case below_equal:
242 return above_equal;
243 case less:
244 return greater;
245 case greater:
246 return less;
247 case greater_equal:
248 return less_equal;
249 case less_equal:
250 return greater_equal;
251 default:
252 return cc;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000254}
255
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100256
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000257enum RoundingMode {
258 kRoundToNearest = 0x0,
259 kRoundDown = 0x1,
260 kRoundUp = 0x2,
261 kRoundToZero = 0x3
262};
263
264
Steve Blocka7e24c12009-10-30 11:49:00 +0000265// -----------------------------------------------------------------------------
266// Machine instruction Immediates
267
268class Immediate BASE_EMBEDDED {
269 public:
270 inline explicit Immediate(int x);
Steve Blocka7e24c12009-10-30 11:49:00 +0000271 inline explicit Immediate(const ExternalReference& ext);
272 inline explicit Immediate(Handle<Object> handle);
273 inline explicit Immediate(Smi* value);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100274 inline explicit Immediate(Address addr);
Ben Murdochda12d292016-06-02 14:46:10 +0100275 inline explicit Immediate(Address x, RelocInfo::Mode rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000276
277 static Immediate CodeRelativeOffset(Label* label) {
278 return Immediate(label);
279 }
280
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000281 bool is_zero() const { return x_ == 0 && RelocInfo::IsNone(rmode_); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000282 bool is_int8() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000283 return -128 <= x_ && x_ < 128 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000284 }
Ben Murdochda12d292016-06-02 14:46:10 +0100285 bool is_uint8() const {
286 return v8::internal::is_uint8(x_) && RelocInfo::IsNone(rmode_);
287 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 bool is_int16() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000289 return -32768 <= x_ && x_ < 32768 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000290 }
Ben Murdochda12d292016-06-02 14:46:10 +0100291 bool is_uint16() const {
292 return v8::internal::is_uint16(x_) && RelocInfo::IsNone(rmode_);
293 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000294
295 private:
296 inline explicit Immediate(Label* value);
297
298 int x_;
299 RelocInfo::Mode rmode_;
300
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 friend class Operand;
Steve Blocka7e24c12009-10-30 11:49:00 +0000302 friend class Assembler;
Steve Block053d10c2011-06-13 19:13:29 +0100303 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000304};
305
306
307// -----------------------------------------------------------------------------
308// Machine instruction Operands
309
310enum ScaleFactor {
311 times_1 = 0,
312 times_2 = 1,
313 times_4 = 2,
314 times_8 = 3,
Leon Clarke4515c472010-02-03 11:58:03 +0000315 times_int_size = times_4,
316 times_half_pointer_size = times_2,
Andrei Popescu402d9372010-02-26 13:31:12 +0000317 times_pointer_size = times_4,
318 times_twice_pointer_size = times_8
Steve Blocka7e24c12009-10-30 11:49:00 +0000319};
320
321
322class Operand BASE_EMBEDDED {
323 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000324 // reg
325 INLINE(explicit Operand(Register reg));
326
Steve Block6ded16b2010-05-10 14:33:55 +0100327 // XMM reg
328 INLINE(explicit Operand(XMMRegister xmm_reg));
329
Steve Blocka7e24c12009-10-30 11:49:00 +0000330 // [disp/r]
331 INLINE(explicit Operand(int32_t disp, RelocInfo::Mode rmode));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000332
333 // [disp/r]
334 INLINE(explicit Operand(Immediate imm));
Steve Blocka7e24c12009-10-30 11:49:00 +0000335
336 // [base + disp/r]
337 explicit Operand(Register base, int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000339
340 // [base + index*scale + disp/r]
341 explicit Operand(Register base,
342 Register index,
343 ScaleFactor scale,
344 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000345 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000346
347 // [index*scale + disp/r]
348 explicit Operand(Register index,
349 ScaleFactor scale,
350 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000353 static Operand JumpTable(Register index, ScaleFactor scale, Label* table) {
354 return Operand(index, scale, reinterpret_cast<int32_t>(table),
355 RelocInfo::INTERNAL_REFERENCE);
356 }
357
Steve Blocka7e24c12009-10-30 11:49:00 +0000358 static Operand StaticVariable(const ExternalReference& ext) {
359 return Operand(reinterpret_cast<int32_t>(ext.address()),
360 RelocInfo::EXTERNAL_REFERENCE);
361 }
362
363 static Operand StaticArray(Register index,
364 ScaleFactor scale,
365 const ExternalReference& arr) {
366 return Operand(index, scale, reinterpret_cast<int32_t>(arr.address()),
367 RelocInfo::EXTERNAL_REFERENCE);
368 }
369
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 static Operand ForCell(Handle<Cell> cell) {
371 AllowDeferredHandleDereference embedding_raw_address;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100372 return Operand(reinterpret_cast<int32_t>(cell.location()),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000373 RelocInfo::CELL);
374 }
375
376 static Operand ForRegisterPlusImmediate(Register base, Immediate imm) {
377 return Operand(base, imm.x_, imm.rmode_);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100378 }
379
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 // Returns true if this Operand is a wrapper for the specified register.
381 bool is_reg(Register reg) const;
382
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100383 // Returns true if this Operand is a wrapper for one register.
384 bool is_reg_only() const;
385
386 // Asserts that this Operand is a wrapper for one register and returns the
387 // register.
388 Register reg() const;
389
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 // Set the ModRM byte without an encoded 'reg' register. The
392 // register is encoded later as part of the emit_operand operation.
393 inline void set_modrm(int mod, Register rm);
394
395 inline void set_sib(ScaleFactor scale, Register index, Register base);
396 inline void set_disp8(int8_t disp);
397 inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
398
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100399 byte buf_[6];
400 // The number of bytes in buf_.
401 unsigned int len_;
402 // Only valid if len_ > 4.
403 RelocInfo::Mode rmode_;
404
Steve Blocka7e24c12009-10-30 11:49:00 +0000405 friend class Assembler;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100406 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000407};
408
409
410// -----------------------------------------------------------------------------
411// A Displacement describes the 32bit immediate field of an instruction which
412// may be used together with a Label in order to refer to a yet unknown code
413// position. Displacements stored in the instruction stream are used to describe
414// the instruction and to chain a list of instructions using the same Label.
415// A Displacement contains 2 different fields:
416//
417// next field: position of next displacement in the chain (0 = end of list)
418// type field: instruction type
419//
420// A next value of null (0) indicates the end of a chain (note that there can
421// be no displacement at position zero, because there is always at least one
422// instruction byte before the displacement).
423//
424// Displacement _data field layout
425//
426// |31.....2|1......0|
427// [ next | type |
428
429class Displacement BASE_EMBEDDED {
430 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000431 enum Type { UNCONDITIONAL_JUMP, CODE_RELATIVE, OTHER, CODE_ABSOLUTE };
Steve Blocka7e24c12009-10-30 11:49:00 +0000432
433 int data() const { return data_; }
434 Type type() const { return TypeField::decode(data_); }
435 void next(Label* L) const {
436 int n = NextField::decode(data_);
437 n > 0 ? L->link_to(n) : L->Unuse();
438 }
439 void link_to(Label* L) { init(L, type()); }
440
441 explicit Displacement(int data) { data_ = data; }
442
443 Displacement(Label* L, Type type) { init(L, type); }
444
445 void print() {
446 PrintF("%s (%x) ", (type() == UNCONDITIONAL_JUMP ? "jmp" : "[other]"),
447 NextField::decode(data_));
448 }
449
450 private:
451 int data_;
452
453 class TypeField: public BitField<Type, 0, 2> {};
454 class NextField: public BitField<int, 2, 32-2> {};
455
456 void init(Label* L, Type type);
457};
458
459
Steve Block44f0eee2011-05-26 01:26:41 +0100460class Assembler : public AssemblerBase {
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 private:
462 // We check before assembling an instruction that there is sufficient
463 // space to write an instruction and its relocation information.
464 // The relocation writer's position must be kGap bytes above the end of
465 // the generated instructions. This leaves enough space for the
466 // longest possible ia32 instruction, 15 bytes, and the longest possible
467 // relocation information encoding, RelocInfoWriter::kMaxLength == 16.
468 // (There is a 15 byte limit on ia32 instruction length that rules out some
469 // otherwise valid instructions.)
470 // This allows for a single, fast space check per instruction.
471 static const int kGap = 32;
472
473 public:
474 // Create an assembler. Instructions and relocation information are emitted
475 // into a buffer, with the instructions starting from the beginning and the
476 // relocation information starting from the end of the buffer. See CodeDesc
477 // for a detailed comment on the layout (globals.h).
478 //
479 // If the provided buffer is NULL, the assembler allocates and grows its own
480 // buffer, and buffer_size determines the initial buffer size. The buffer is
481 // owned by the assembler and deallocated upon destruction of the assembler.
482 //
483 // If the provided buffer is not NULL, the assembler uses the provided buffer
484 // for code generation and assumes its size to be buffer_size. If the buffer
485 // is too small, a fatal error occurs. No deallocation of the buffer is done
486 // upon destruction of the assembler.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100487 // TODO(vitalyr): the assembler does not need an isolate.
488 Assembler(Isolate* isolate, void* buffer, int buffer_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000489 virtual ~Assembler() { }
Steve Block44f0eee2011-05-26 01:26:41 +0100490
Steve Blocka7e24c12009-10-30 11:49:00 +0000491 // GetCode emits any pending (non-emitted) code and fills the descriptor
492 // desc. GetCode() is idempotent; it returns the same result if no other
493 // Assembler functions are invoked in between GetCode() calls.
494 void GetCode(CodeDesc* desc);
495
496 // Read/Modify the code target in the branch/call instruction at pc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000497 inline static Address target_address_at(Address pc, Address constant_pool);
498 inline static void set_target_address_at(
499 Isolate* isolate, Address pc, Address constant_pool, Address target,
500 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000501 static inline Address target_address_at(Address pc, Code* code) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000502 Address constant_pool = code ? code->constant_pool() : NULL;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000503 return target_address_at(pc, constant_pool);
504 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000505 static inline void set_target_address_at(
506 Isolate* isolate, Address pc, Code* code, Address target,
507 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED) {
508 Address constant_pool = code ? code->constant_pool() : NULL;
509 set_target_address_at(isolate, pc, constant_pool, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000510 }
511
512 // Return the code target address at a call site from the return address
513 // of that call in the instruction stream.
514 inline static Address target_address_from_return_address(Address pc);
515
Steve Blockd0582a62009-12-15 09:54:21 +0000516 // This sets the branch destination (which is in the instruction on x86).
517 // This is for calls and branches within generated code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100518 inline static void deserialization_set_special_target_at(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000519 Isolate* isolate, Address instruction_payload, Code* code,
520 Address target) {
521 set_target_address_at(isolate, instruction_payload, code, target);
Steve Blockd0582a62009-12-15 09:54:21 +0000522 }
523
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 // This sets the internal reference at the pc.
525 inline static void deserialization_set_target_internal_reference_at(
526 Isolate* isolate, Address pc, Address target,
527 RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
528
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100529 static const int kSpecialTargetSize = kPointerSize;
Steve Blockd0582a62009-12-15 09:54:21 +0000530
Steve Blocka7e24c12009-10-30 11:49:00 +0000531 // Distance between the address of the code target in the call instruction
532 // and the return address
533 static const int kCallTargetAddressOffset = kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000534
535 static const int kCallInstructionLength = 5;
536
537 // The debug break slot must be able to contain a call instruction.
538 static const int kDebugBreakSlotLength = kCallInstructionLength;
Steve Blocka7e24c12009-10-30 11:49:00 +0000539
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100540 // Distance between start of patched debug break slot and the emitted address
541 // to jump to.
542 static const int kPatchDebugBreakSlotAddressOffset = 1; // JMP imm32.
543
Ben Murdochb0fe1622011-05-05 13:52:32 +0100544 // One byte opcode for test al, 0xXX.
545 static const byte kTestAlByte = 0xA8;
546 // One byte opcode for nop.
547 static const byte kNopByte = 0x90;
548
549 // One byte opcode for a short unconditional jump.
550 static const byte kJmpShortOpcode = 0xEB;
551 // One byte prefix for a short conditional jump.
552 static const byte kJccShortPrefix = 0x70;
553 static const byte kJncShortOpcode = kJccShortPrefix | not_carry;
554 static const byte kJcShortOpcode = kJccShortPrefix | carry;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000555 static const byte kJnzShortOpcode = kJccShortPrefix | not_zero;
556 static const byte kJzShortOpcode = kJccShortPrefix | zero;
557
Ben Murdochb0fe1622011-05-05 13:52:32 +0100558
Steve Blocka7e24c12009-10-30 11:49:00 +0000559 // ---------------------------------------------------------------------------
560 // Code generation
561 //
562 // - function names correspond one-to-one to ia32 instruction mnemonics
563 // - unless specified otherwise, instructions operate on 32bit operands
564 // - instructions on 8bit (byte) operands/registers have a trailing '_b'
565 // - instructions on 16bit (word) operands/registers have a trailing '_w'
566 // - naming conflicts with C++ keywords are resolved via a trailing '_'
567
568 // NOTE ON INTERFACE: Currently, the interface is not very consistent
569 // in the sense that some operations (e.g. mov()) can be called in more
570 // the one way to generate the same instruction: The Register argument
571 // can in some cases be replaced with an Operand(Register) argument.
572 // This should be cleaned up and made more orthogonal. The questions
573 // is: should we always use Operands instead of Registers where an
574 // Operand is possible, or should we have a Register (overloaded) form
575 // instead? We must be careful to make sure that the selected instruction
576 // is obvious from the parameters to avoid hard-to-find code generation
577 // bugs.
578
579 // Insert the smallest number of nop instructions
580 // possible to align the pc offset to a multiple
581 // of m. m must be a power of 2.
582 void Align(int m);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000583 // Insert the smallest number of zero bytes possible to align the pc offset
584 // to a mulitple of m. m must be a power of 2 (>= 2).
585 void DataAlign(int m);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100586 void Nop(int bytes = 1);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100587 // Aligns code to something that's optimal for a jump target for the platform.
588 void CodeTargetAlign();
Steve Blocka7e24c12009-10-30 11:49:00 +0000589
590 // Stack
591 void pushad();
592 void popad();
593
594 void pushfd();
595 void popfd();
596
597 void push(const Immediate& x);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100598 void push_imm32(int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000599 void push(Register src);
600 void push(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000601
602 void pop(Register dst);
603 void pop(const Operand& dst);
604
605 void enter(const Immediate& size);
606 void leave();
607
608 // Moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100609 void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000610 void mov_b(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100611 void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400612 void mov_b(const Operand& dst, int8_t src) { mov_b(dst, Immediate(src)); }
613 void mov_b(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000614 void mov_b(const Operand& dst, Register src);
615
616 void mov_w(Register dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400617 void mov_w(const Operand& dst, int16_t src) { mov_w(dst, Immediate(src)); }
618 void mov_w(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000619 void mov_w(const Operand& dst, Register src);
620
621 void mov(Register dst, int32_t imm32);
622 void mov(Register dst, const Immediate& x);
623 void mov(Register dst, Handle<Object> handle);
624 void mov(Register dst, const Operand& src);
625 void mov(Register dst, Register src);
626 void mov(const Operand& dst, const Immediate& x);
627 void mov(const Operand& dst, Handle<Object> handle);
628 void mov(const Operand& dst, Register src);
629
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100630 void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000631 void movsx_b(Register dst, const Operand& src);
632
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100633 void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000634 void movsx_w(Register dst, const Operand& src);
635
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100636 void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000637 void movzx_b(Register dst, const Operand& src);
638
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639 void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000640 void movzx_w(Register dst, const Operand& src);
641
642 // Conditional moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100643 void cmov(Condition cc, Register dst, Register src) {
644 cmov(cc, dst, Operand(src));
645 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000646 void cmov(Condition cc, Register dst, const Operand& src);
647
Steve Block6ded16b2010-05-10 14:33:55 +0100648 // Flag management.
649 void cld();
650
Leon Clarkee46be812010-01-19 14:06:41 +0000651 // Repetitive string instructions.
652 void rep_movs();
Steve Block6ded16b2010-05-10 14:33:55 +0100653 void rep_stos();
Leon Clarkef7060e22010-06-03 12:02:55 +0100654 void stos();
Leon Clarkee46be812010-01-19 14:06:41 +0000655
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 // Exchange
Steve Blocka7e24c12009-10-30 11:49:00 +0000657 void xchg(Register dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000658 void xchg(Register dst, const Operand& src);
Ben Murdochc5610432016-08-08 18:44:38 +0100659 void xchg_b(Register reg, const Operand& op);
660 void xchg_w(Register reg, const Operand& op);
Steve Blocka7e24c12009-10-30 11:49:00 +0000661
Ben Murdoch61f157c2016-09-16 13:49:30 +0100662 // Lock prefix
663 void lock();
664
665 // CompareExchange
666 void cmpxchg(const Operand& dst, Register src);
667 void cmpxchg_b(const Operand& dst, Register src);
668 void cmpxchg_w(const Operand& dst, Register src);
669
Steve Blocka7e24c12009-10-30 11:49:00 +0000670 // Arithmetics
671 void adc(Register dst, int32_t imm32);
672 void adc(Register dst, const Operand& src);
673
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100674 void add(Register dst, Register src) { add(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000675 void add(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100676 void add(const Operand& dst, Register src);
677 void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 void add(const Operand& dst, const Immediate& x);
679
680 void and_(Register dst, int32_t imm32);
Steve Block59151502010-09-22 15:07:15 +0100681 void and_(Register dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100682 void and_(Register dst, Register src) { and_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000683 void and_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100684 void and_(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000685 void and_(const Operand& dst, const Immediate& x);
686
Ben Murdochda12d292016-06-02 14:46:10 +0100687 void cmpb(Register reg, Immediate imm8) { cmpb(Operand(reg), imm8); }
688 void cmpb(const Operand& op, Immediate imm8);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100689 void cmpb(Register reg, const Operand& op);
690 void cmpb(const Operand& op, Register reg);
Ben Murdochda12d292016-06-02 14:46:10 +0100691 void cmpb(Register dst, Register src) { cmpb(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000692 void cmpb_al(const Operand& op);
693 void cmpw_ax(const Operand& op);
Ben Murdochda12d292016-06-02 14:46:10 +0100694 void cmpw(const Operand& dst, Immediate src);
695 void cmpw(Register dst, Immediate src) { cmpw(Operand(dst), src); }
696 void cmpw(Register dst, const Operand& src);
697 void cmpw(Register dst, Register src) { cmpw(Operand(dst), src); }
698 void cmpw(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000699 void cmp(Register reg, int32_t imm32);
700 void cmp(Register reg, Handle<Object> handle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100701 void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000702 void cmp(Register reg, const Operand& op);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100703 void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100704 void cmp(const Operand& op, Register reg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000705 void cmp(const Operand& op, const Immediate& imm);
706 void cmp(const Operand& op, Handle<Object> handle);
707
708 void dec_b(Register dst);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100709 void dec_b(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000710
711 void dec(Register dst);
712 void dec(const Operand& dst);
713
714 void cdq();
715
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000716 void idiv(Register src) { idiv(Operand(src)); }
717 void idiv(const Operand& src);
718 void div(Register src) { div(Operand(src)); }
719 void div(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000720
721 // Signed multiply instructions.
722 void imul(Register src); // edx:eax = eax * src.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100723 void imul(Register dst, Register src) { imul(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000724 void imul(Register dst, const Operand& src); // dst = dst * src.
725 void imul(Register dst, Register src, int32_t imm32); // dst = src * imm32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000726 void imul(Register dst, const Operand& src, int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000727
728 void inc(Register dst);
729 void inc(const Operand& dst);
730
731 void lea(Register dst, const Operand& src);
732
733 // Unsigned multiply instruction.
734 void mul(Register src); // edx:eax = eax * reg.
735
736 void neg(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000737 void neg(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000738
739 void not_(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000740 void not_(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000741
742 void or_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100743 void or_(Register dst, Register src) { or_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000744 void or_(Register dst, const Operand& src);
745 void or_(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100746 void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000747 void or_(const Operand& dst, const Immediate& x);
748
749 void rcl(Register dst, uint8_t imm8);
Iain Merrick75681382010-08-19 15:07:18 +0100750 void rcr(Register dst, uint8_t imm8);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400751
752 void ror(Register dst, uint8_t imm8) { ror(Operand(dst), imm8); }
753 void ror(const Operand& dst, uint8_t imm8);
754 void ror_cl(Register dst) { ror_cl(Operand(dst)); }
755 void ror_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000756
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000757 void sar(Register dst, uint8_t imm8) { sar(Operand(dst), imm8); }
758 void sar(const Operand& dst, uint8_t imm8);
759 void sar_cl(Register dst) { sar_cl(Operand(dst)); }
760 void sar_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000761
762 void sbb(Register dst, const Operand& src);
763
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000764 void shl(Register dst, uint8_t imm8) { shl(Operand(dst), imm8); }
765 void shl(const Operand& dst, uint8_t imm8);
766 void shl_cl(Register dst) { shl_cl(Operand(dst)); }
767 void shl_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100768 void shld(Register dst, Register src, uint8_t shift);
769 void shld_cl(Register dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000770
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000771 void shr(Register dst, uint8_t imm8) { shr(Operand(dst), imm8); }
772 void shr(const Operand& dst, uint8_t imm8);
773 void shr_cl(Register dst) { shr_cl(Operand(dst)); }
774 void shr_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100775 void shrd(Register dst, Register src, uint8_t shift);
776 void shrd_cl(Register dst, Register src) { shrd_cl(Operand(dst), src); }
777 void shrd_cl(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000778
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100779 void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000780 void sub(const Operand& dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100781 void sub(Register dst, Register src) { sub(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000782 void sub(Register dst, const Operand& src);
783 void sub(const Operand& dst, Register src);
784
785 void test(Register reg, const Immediate& imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100786 void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000787 void test(Register reg, const Operand& op);
788 void test(const Operand& op, const Immediate& imm);
Ben Murdochda12d292016-06-02 14:46:10 +0100789 void test(const Operand& op, Register reg) { test(reg, op); }
790 void test_b(Register reg, const Operand& op);
791 void test_b(Register reg, Immediate imm8);
792 void test_b(const Operand& op, Immediate imm8);
793 void test_b(const Operand& op, Register reg) { test_b(reg, op); }
794 void test_b(Register dst, Register src) { test_b(dst, Operand(src)); }
795 void test_w(Register reg, const Operand& op);
796 void test_w(Register reg, Immediate imm16);
797 void test_w(const Operand& op, Immediate imm16);
798 void test_w(const Operand& op, Register reg) { test_w(reg, op); }
799 void test_w(Register dst, Register src) { test_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000800
801 void xor_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100802 void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000803 void xor_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100804 void xor_(const Operand& dst, Register src);
805 void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000806 void xor_(const Operand& dst, const Immediate& x);
807
808 // Bit operations.
809 void bt(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100810 void bts(Register dst, Register src) { bts(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000811 void bts(const Operand& dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000812 void bsr(Register dst, Register src) { bsr(dst, Operand(src)); }
813 void bsr(Register dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000814 void bsf(Register dst, Register src) { bsf(dst, Operand(src)); }
815 void bsf(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000816
817 // Miscellaneous
818 void hlt();
819 void int3();
820 void nop();
Steve Blocka7e24c12009-10-30 11:49:00 +0000821 void ret(int imm16);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000822 void ud2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000823
824 // Label operations & relative jumps (PPUM Appendix D)
825 //
826 // Takes a branch opcode (cc) and a label (L) and generates
827 // either a backward branch or a forward branch and links it
828 // to the label fixup chain. Usage:
829 //
830 // Label L; // unbound label
831 // j(cc, &L); // forward branch to unbound label
832 // bind(&L); // bind label to the current pc
833 // j(cc, &L); // backward branch to bound label
834 // bind(&L); // illegal: a label may be bound only once
835 //
836 // Note: The same Label can be used for forward and backward branches
837 // but it may be bound only once.
838
839 void bind(Label* L); // binds an unbound label L to the current code position
840
841 // Calls
842 void call(Label* L);
843 void call(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch257744e2011-11-30 15:57:28 +0000844 int CallSize(const Operand& adr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100845 void call(Register reg) { call(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000846 void call(const Operand& adr);
Ben Murdoch257744e2011-11-30 15:57:28 +0000847 int CallSize(Handle<Code> code, RelocInfo::Mode mode);
848 void call(Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000849 RelocInfo::Mode rmode,
850 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000851
852 // Jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000853 // unconditional jump to L
854 void jmp(Label* L, Label::Distance distance = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000855 void jmp(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100856 void jmp(Register reg) { jmp(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000857 void jmp(const Operand& adr);
858 void jmp(Handle<Code> code, RelocInfo::Mode rmode);
859
860 // Conditional jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000861 void j(Condition cc,
862 Label* L,
863 Label::Distance distance = Label::kFar);
864 void j(Condition cc, byte* entry, RelocInfo::Mode rmode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000865 void j(Condition cc, Handle<Code> code,
866 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100867
Steve Blocka7e24c12009-10-30 11:49:00 +0000868 // Floating-point operations
869 void fld(int i);
Andrei Popescu402d9372010-02-26 13:31:12 +0000870 void fstp(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000871
872 void fld1();
873 void fldz();
Andrei Popescu402d9372010-02-26 13:31:12 +0000874 void fldpi();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100875 void fldln2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000876
877 void fld_s(const Operand& adr);
878 void fld_d(const Operand& adr);
879
880 void fstp_s(const Operand& adr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000881 void fst_s(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000882 void fstp_d(const Operand& adr);
Andrei Popescu402d9372010-02-26 13:31:12 +0000883 void fst_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000884
885 void fild_s(const Operand& adr);
886 void fild_d(const Operand& adr);
887
888 void fist_s(const Operand& adr);
889
890 void fistp_s(const Operand& adr);
891 void fistp_d(const Operand& adr);
892
Steve Block6ded16b2010-05-10 14:33:55 +0100893 // The fisttp instructions require SSE3.
Steve Blocka7e24c12009-10-30 11:49:00 +0000894 void fisttp_s(const Operand& adr);
Leon Clarkee46be812010-01-19 14:06:41 +0000895 void fisttp_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000896
897 void fabs();
898 void fchs();
899 void fcos();
900 void fsin();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100901 void fptan();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100902 void fyl2x();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100903 void f2xm1();
904 void fscale();
905 void fninit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000906
907 void fadd(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000908 void fadd_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000909 void fsub(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000910 void fsub_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000911 void fmul(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000912 void fmul_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000913 void fdiv(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000914 void fdiv_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000915
916 void fisub_s(const Operand& adr);
917
918 void faddp(int i = 1);
919 void fsubp(int i = 1);
920 void fsubrp(int i = 1);
921 void fmulp(int i = 1);
922 void fdivp(int i = 1);
923 void fprem();
924 void fprem1();
925
926 void fxch(int i = 1);
927 void fincstp();
928 void ffree(int i = 0);
929
930 void ftst();
931 void fucomp(int i);
932 void fucompp();
Steve Block3ce2e202009-11-05 08:53:23 +0000933 void fucomi(int i);
934 void fucomip();
Steve Blocka7e24c12009-10-30 11:49:00 +0000935 void fcompp();
936 void fnstsw_ax();
937 void fwait();
938 void fnclex();
939
940 void frndint();
941
942 void sahf();
943 void setcc(Condition cc, Register reg);
944
945 void cpuid();
946
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000947 // SSE instructions
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400948 void addss(XMMRegister dst, XMMRegister src) { addss(dst, Operand(src)); }
949 void addss(XMMRegister dst, const Operand& src);
950 void subss(XMMRegister dst, XMMRegister src) { subss(dst, Operand(src)); }
951 void subss(XMMRegister dst, const Operand& src);
952 void mulss(XMMRegister dst, XMMRegister src) { mulss(dst, Operand(src)); }
953 void mulss(XMMRegister dst, const Operand& src);
954 void divss(XMMRegister dst, XMMRegister src) { divss(dst, Operand(src)); }
955 void divss(XMMRegister dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000956 void sqrtss(XMMRegister dst, XMMRegister src) { sqrtss(dst, Operand(src)); }
957 void sqrtss(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400958
959 void ucomiss(XMMRegister dst, XMMRegister src) { ucomiss(dst, Operand(src)); }
960 void ucomiss(XMMRegister dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000961 void movaps(XMMRegister dst, XMMRegister src);
962 void shufps(XMMRegister dst, XMMRegister src, byte imm8);
963
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000964 void maxss(XMMRegister dst, XMMRegister src) { maxss(dst, Operand(src)); }
965 void maxss(XMMRegister dst, const Operand& src);
966 void minss(XMMRegister dst, XMMRegister src) { minss(dst, Operand(src)); }
967 void minss(XMMRegister dst, const Operand& src);
968
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000969 void andps(XMMRegister dst, const Operand& src);
970 void andps(XMMRegister dst, XMMRegister src) { andps(dst, Operand(src)); }
971 void xorps(XMMRegister dst, const Operand& src);
972 void xorps(XMMRegister dst, XMMRegister src) { xorps(dst, Operand(src)); }
973 void orps(XMMRegister dst, const Operand& src);
974 void orps(XMMRegister dst, XMMRegister src) { orps(dst, Operand(src)); }
975
976 void addps(XMMRegister dst, const Operand& src);
977 void addps(XMMRegister dst, XMMRegister src) { addps(dst, Operand(src)); }
978 void subps(XMMRegister dst, const Operand& src);
979 void subps(XMMRegister dst, XMMRegister src) { subps(dst, Operand(src)); }
980 void mulps(XMMRegister dst, const Operand& src);
981 void mulps(XMMRegister dst, XMMRegister src) { mulps(dst, Operand(src)); }
982 void divps(XMMRegister dst, const Operand& src);
983 void divps(XMMRegister dst, XMMRegister src) { divps(dst, Operand(src)); }
984
Steve Blocka7e24c12009-10-30 11:49:00 +0000985 // SSE2 instructions
986 void cvttss2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000987 void cvttss2si(Register dst, XMMRegister src) {
988 cvttss2si(dst, Operand(src));
989 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000990 void cvttsd2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000991 void cvttsd2si(Register dst, XMMRegister src) {
992 cvttsd2si(dst, Operand(src));
993 }
994 void cvtsd2si(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000995
Ben Murdoch097c5b22016-05-18 11:27:45 +0100996 void cvtsi2ss(XMMRegister dst, Register src) { cvtsi2ss(dst, Operand(src)); }
997 void cvtsi2ss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100998 void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000999 void cvtsi2sd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001000 void cvtss2sd(XMMRegister dst, const Operand& src);
1001 void cvtss2sd(XMMRegister dst, XMMRegister src) {
1002 cvtss2sd(dst, Operand(src));
1003 }
1004 void cvtsd2ss(XMMRegister dst, const Operand& src);
1005 void cvtsd2ss(XMMRegister dst, XMMRegister src) {
1006 cvtsd2ss(dst, Operand(src));
1007 }
1008 void addsd(XMMRegister dst, XMMRegister src) { addsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001009 void addsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001010 void subsd(XMMRegister dst, XMMRegister src) { subsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001011 void subsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001012 void mulsd(XMMRegister dst, XMMRegister src) { mulsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001013 void mulsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001014 void divsd(XMMRegister dst, XMMRegister src) { divsd(dst, Operand(src)); }
1015 void divsd(XMMRegister dst, const Operand& src);
Leon Clarkee46be812010-01-19 14:06:41 +00001016 void xorpd(XMMRegister dst, XMMRegister src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001017 void sqrtsd(XMMRegister dst, XMMRegister src) { sqrtsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001018 void sqrtsd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001019
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001020 void andpd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001021 void orpd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001022
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001023 void ucomisd(XMMRegister dst, XMMRegister src) { ucomisd(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001024 void ucomisd(XMMRegister dst, const Operand& src);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001025
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001026 void roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001027 void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
1028
Steve Block6ded16b2010-05-10 14:33:55 +01001029 void movmskpd(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001030 void movmskps(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001031
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001032 void cmpltsd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001033 void pcmpeqd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001034
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001035 void punpckldq(XMMRegister dst, XMMRegister src);
1036 void punpckhdq(XMMRegister dst, XMMRegister src);
1037
1038 void maxsd(XMMRegister dst, XMMRegister src) { maxsd(dst, Operand(src)); }
1039 void maxsd(XMMRegister dst, const Operand& src);
1040 void minsd(XMMRegister dst, XMMRegister src) { minsd(dst, Operand(src)); }
1041 void minsd(XMMRegister dst, const Operand& src);
1042
Leon Clarkee46be812010-01-19 14:06:41 +00001043 void movdqa(XMMRegister dst, const Operand& src);
1044 void movdqa(const Operand& dst, XMMRegister src);
1045 void movdqu(XMMRegister dst, const Operand& src);
1046 void movdqu(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047 void movdq(bool aligned, XMMRegister dst, const Operand& src) {
1048 if (aligned) {
1049 movdqa(dst, src);
1050 } else {
1051 movdqu(dst, src);
1052 }
1053 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001054
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001055 void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
Steve Block6ded16b2010-05-10 14:33:55 +01001056 void movd(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001057 void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1058 void movd(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001059 void movsd(XMMRegister dst, XMMRegister src) { movsd(dst, Operand(src)); }
1060 void movsd(XMMRegister dst, const Operand& src);
1061 void movsd(const Operand& dst, XMMRegister src);
1062
Steve Block6ded16b2010-05-10 14:33:55 +01001063
Steve Block44f0eee2011-05-26 01:26:41 +01001064 void movss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001065 void movss(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001066 void movss(XMMRegister dst, XMMRegister src) { movss(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001067 void extractps(Register dst, XMMRegister src, byte imm8);
Steve Block44f0eee2011-05-26 01:26:41 +01001068
Ben Murdochb0fe1622011-05-05 13:52:32 +01001069 void pand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001070 void pxor(XMMRegister dst, XMMRegister src);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001071 void por(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001072 void ptest(XMMRegister dst, XMMRegister src);
1073
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001074 void pslld(XMMRegister reg, int8_t shift);
1075 void psrld(XMMRegister reg, int8_t shift);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001076 void psllq(XMMRegister reg, int8_t shift);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001077 void psllq(XMMRegister dst, XMMRegister src);
1078 void psrlq(XMMRegister reg, int8_t shift);
1079 void psrlq(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001080 void pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001081 void pextrd(Register dst, XMMRegister src, int8_t offset) {
1082 pextrd(Operand(dst), src, offset);
1083 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001084 void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001085 void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1086 pinsrd(dst, Operand(src), offset);
1087 }
Steve Block1e0659c2011-05-24 12:43:12 +01001088 void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001089
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001090 // AVX instructions
1091 void vfmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1092 vfmadd132sd(dst, src1, Operand(src2));
1093 }
1094 void vfmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1095 vfmadd213sd(dst, src1, Operand(src2));
1096 }
1097 void vfmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1098 vfmadd231sd(dst, src1, Operand(src2));
1099 }
1100 void vfmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1101 vfmasd(0x99, dst, src1, src2);
1102 }
1103 void vfmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1104 vfmasd(0xa9, dst, src1, src2);
1105 }
1106 void vfmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1107 vfmasd(0xb9, dst, src1, src2);
1108 }
1109 void vfmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1110 vfmsub132sd(dst, src1, Operand(src2));
1111 }
1112 void vfmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1113 vfmsub213sd(dst, src1, Operand(src2));
1114 }
1115 void vfmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1116 vfmsub231sd(dst, src1, Operand(src2));
1117 }
1118 void vfmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1119 vfmasd(0x9b, dst, src1, src2);
1120 }
1121 void vfmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1122 vfmasd(0xab, dst, src1, src2);
1123 }
1124 void vfmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1125 vfmasd(0xbb, dst, src1, src2);
1126 }
1127 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1128 vfnmadd132sd(dst, src1, Operand(src2));
1129 }
1130 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1131 vfnmadd213sd(dst, src1, Operand(src2));
1132 }
1133 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1134 vfnmadd231sd(dst, src1, Operand(src2));
1135 }
1136 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1137 vfmasd(0x9d, dst, src1, src2);
1138 }
1139 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1140 vfmasd(0xad, dst, src1, src2);
1141 }
1142 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1143 vfmasd(0xbd, dst, src1, src2);
1144 }
1145 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1146 vfnmsub132sd(dst, src1, Operand(src2));
1147 }
1148 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1149 vfnmsub213sd(dst, src1, Operand(src2));
1150 }
1151 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1152 vfnmsub231sd(dst, src1, Operand(src2));
1153 }
1154 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1155 vfmasd(0x9f, dst, src1, src2);
1156 }
1157 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1158 vfmasd(0xaf, dst, src1, src2);
1159 }
1160 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1161 vfmasd(0xbf, dst, src1, src2);
1162 }
1163 void vfmasd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1164
1165 void vfmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1166 vfmadd132ss(dst, src1, Operand(src2));
1167 }
1168 void vfmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1169 vfmadd213ss(dst, src1, Operand(src2));
1170 }
1171 void vfmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1172 vfmadd231ss(dst, src1, Operand(src2));
1173 }
1174 void vfmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1175 vfmass(0x99, dst, src1, src2);
1176 }
1177 void vfmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1178 vfmass(0xa9, dst, src1, src2);
1179 }
1180 void vfmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1181 vfmass(0xb9, dst, src1, src2);
1182 }
1183 void vfmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1184 vfmsub132ss(dst, src1, Operand(src2));
1185 }
1186 void vfmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1187 vfmsub213ss(dst, src1, Operand(src2));
1188 }
1189 void vfmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1190 vfmsub231ss(dst, src1, Operand(src2));
1191 }
1192 void vfmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1193 vfmass(0x9b, dst, src1, src2);
1194 }
1195 void vfmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1196 vfmass(0xab, dst, src1, src2);
1197 }
1198 void vfmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1199 vfmass(0xbb, dst, src1, src2);
1200 }
1201 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1202 vfnmadd132ss(dst, src1, Operand(src2));
1203 }
1204 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1205 vfnmadd213ss(dst, src1, Operand(src2));
1206 }
1207 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1208 vfnmadd231ss(dst, src1, Operand(src2));
1209 }
1210 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1211 vfmass(0x9d, dst, src1, src2);
1212 }
1213 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1214 vfmass(0xad, dst, src1, src2);
1215 }
1216 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1217 vfmass(0xbd, dst, src1, src2);
1218 }
1219 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1220 vfnmsub132ss(dst, src1, Operand(src2));
1221 }
1222 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1223 vfnmsub213ss(dst, src1, Operand(src2));
1224 }
1225 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1226 vfnmsub231ss(dst, src1, Operand(src2));
1227 }
1228 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1229 vfmass(0x9f, dst, src1, src2);
1230 }
1231 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1232 vfmass(0xaf, dst, src1, src2);
1233 }
1234 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1235 vfmass(0xbf, dst, src1, src2);
1236 }
1237 void vfmass(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1238
1239 void vaddsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1240 vaddsd(dst, src1, Operand(src2));
1241 }
1242 void vaddsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1243 vsd(0x58, dst, src1, src2);
1244 }
1245 void vsubsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1246 vsubsd(dst, src1, Operand(src2));
1247 }
1248 void vsubsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1249 vsd(0x5c, dst, src1, src2);
1250 }
1251 void vmulsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1252 vmulsd(dst, src1, Operand(src2));
1253 }
1254 void vmulsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1255 vsd(0x59, dst, src1, src2);
1256 }
1257 void vdivsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1258 vdivsd(dst, src1, Operand(src2));
1259 }
1260 void vdivsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1261 vsd(0x5e, dst, src1, src2);
1262 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001263 void vmaxsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1264 vmaxsd(dst, src1, Operand(src2));
1265 }
1266 void vmaxsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1267 vsd(0x5f, dst, src1, src2);
1268 }
1269 void vminsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1270 vminsd(dst, src1, Operand(src2));
1271 }
1272 void vminsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1273 vsd(0x5d, dst, src1, src2);
1274 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001275 void vsd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1276
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001277 void vaddss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1278 vaddss(dst, src1, Operand(src2));
1279 }
1280 void vaddss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1281 vss(0x58, dst, src1, src2);
1282 }
1283 void vsubss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1284 vsubss(dst, src1, Operand(src2));
1285 }
1286 void vsubss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1287 vss(0x5c, dst, src1, src2);
1288 }
1289 void vmulss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1290 vmulss(dst, src1, Operand(src2));
1291 }
1292 void vmulss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1293 vss(0x59, dst, src1, src2);
1294 }
1295 void vdivss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1296 vdivss(dst, src1, Operand(src2));
1297 }
1298 void vdivss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1299 vss(0x5e, dst, src1, src2);
1300 }
1301 void vmaxss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1302 vmaxss(dst, src1, Operand(src2));
1303 }
1304 void vmaxss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1305 vss(0x5f, dst, src1, src2);
1306 }
1307 void vminss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1308 vminss(dst, src1, Operand(src2));
1309 }
1310 void vminss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1311 vss(0x5d, dst, src1, src2);
1312 }
1313 void vss(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1314
1315 // BMI instruction
1316 void andn(Register dst, Register src1, Register src2) {
1317 andn(dst, src1, Operand(src2));
1318 }
1319 void andn(Register dst, Register src1, const Operand& src2) {
1320 bmi1(0xf2, dst, src1, src2);
1321 }
1322 void bextr(Register dst, Register src1, Register src2) {
1323 bextr(dst, Operand(src1), src2);
1324 }
1325 void bextr(Register dst, const Operand& src1, Register src2) {
1326 bmi1(0xf7, dst, src2, src1);
1327 }
1328 void blsi(Register dst, Register src) { blsi(dst, Operand(src)); }
1329 void blsi(Register dst, const Operand& src) {
1330 Register ireg = {3};
1331 bmi1(0xf3, ireg, dst, src);
1332 }
1333 void blsmsk(Register dst, Register src) { blsmsk(dst, Operand(src)); }
1334 void blsmsk(Register dst, const Operand& src) {
1335 Register ireg = {2};
1336 bmi1(0xf3, ireg, dst, src);
1337 }
1338 void blsr(Register dst, Register src) { blsr(dst, Operand(src)); }
1339 void blsr(Register dst, const Operand& src) {
1340 Register ireg = {1};
1341 bmi1(0xf3, ireg, dst, src);
1342 }
1343 void tzcnt(Register dst, Register src) { tzcnt(dst, Operand(src)); }
1344 void tzcnt(Register dst, const Operand& src);
1345
1346 void lzcnt(Register dst, Register src) { lzcnt(dst, Operand(src)); }
1347 void lzcnt(Register dst, const Operand& src);
1348
1349 void popcnt(Register dst, Register src) { popcnt(dst, Operand(src)); }
1350 void popcnt(Register dst, const Operand& src);
1351
1352 void bzhi(Register dst, Register src1, Register src2) {
1353 bzhi(dst, Operand(src1), src2);
1354 }
1355 void bzhi(Register dst, const Operand& src1, Register src2) {
1356 bmi2(kNone, 0xf5, dst, src2, src1);
1357 }
1358 void mulx(Register dst1, Register dst2, Register src) {
1359 mulx(dst1, dst2, Operand(src));
1360 }
1361 void mulx(Register dst1, Register dst2, const Operand& src) {
1362 bmi2(kF2, 0xf6, dst1, dst2, src);
1363 }
1364 void pdep(Register dst, Register src1, Register src2) {
1365 pdep(dst, src1, Operand(src2));
1366 }
1367 void pdep(Register dst, Register src1, const Operand& src2) {
1368 bmi2(kF2, 0xf5, dst, src1, src2);
1369 }
1370 void pext(Register dst, Register src1, Register src2) {
1371 pext(dst, src1, Operand(src2));
1372 }
1373 void pext(Register dst, Register src1, const Operand& src2) {
1374 bmi2(kF3, 0xf5, dst, src1, src2);
1375 }
1376 void sarx(Register dst, Register src1, Register src2) {
1377 sarx(dst, Operand(src1), src2);
1378 }
1379 void sarx(Register dst, const Operand& src1, Register src2) {
1380 bmi2(kF3, 0xf7, dst, src2, src1);
1381 }
1382 void shlx(Register dst, Register src1, Register src2) {
1383 shlx(dst, Operand(src1), src2);
1384 }
1385 void shlx(Register dst, const Operand& src1, Register src2) {
1386 bmi2(k66, 0xf7, dst, src2, src1);
1387 }
1388 void shrx(Register dst, Register src1, Register src2) {
1389 shrx(dst, Operand(src1), src2);
1390 }
1391 void shrx(Register dst, const Operand& src1, Register src2) {
1392 bmi2(kF2, 0xf7, dst, src2, src1);
1393 }
1394 void rorx(Register dst, Register src, byte imm8) {
1395 rorx(dst, Operand(src), imm8);
1396 }
1397 void rorx(Register dst, const Operand& src, byte imm8);
1398
1399#define PACKED_OP_LIST(V) \
1400 V(and, 0x54) \
1401 V(xor, 0x57)
1402
1403#define AVX_PACKED_OP_DECLARE(name, opcode) \
1404 void v##name##ps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1405 vps(opcode, dst, src1, Operand(src2)); \
1406 } \
1407 void v##name##ps(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1408 vps(opcode, dst, src1, src2); \
1409 } \
1410 void v##name##pd(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1411 vpd(opcode, dst, src1, Operand(src2)); \
1412 } \
1413 void v##name##pd(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1414 vpd(opcode, dst, src1, src2); \
1415 }
1416
1417 PACKED_OP_LIST(AVX_PACKED_OP_DECLARE);
1418 void vps(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1419 void vps(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1420 void vpd(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1421 void vpd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1422
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001423 // Prefetch src position into cache level.
1424 // Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a
1425 // non-temporal
1426 void prefetch(const Operand& src, int level);
1427 // TODO(lrn): Need SFENCE for movnt?
1428
Steve Blocka7e24c12009-10-30 11:49:00 +00001429 // Check the code size generated from label to here.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001430 int SizeOfCodeGeneratedSince(Label* label) {
1431 return pc_offset() - label->pos();
1432 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434 // Mark generator continuation.
1435 void RecordGeneratorContinuation();
Steve Blocka7e24c12009-10-30 11:49:00 +00001436
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001437 // Mark address of a debug break slot.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001438 void RecordDebugBreakSlot(RelocInfo::Mode mode);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001439
Steve Blocka7e24c12009-10-30 11:49:00 +00001440 // Record a comment relocation entry that can be used by a disassembler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001441 // Use --code-comments to enable.
1442 void RecordComment(const char* msg);
1443
1444 // Record a deoptimization reason that can be used by a log or cpu profiler.
1445 // Use --trace-deopt to enable.
Ben Murdochc5610432016-08-08 18:44:38 +01001446 void RecordDeoptReason(const int reason, int raw_position, int id);
Steve Blocka7e24c12009-10-30 11:49:00 +00001447
Ben Murdochb0fe1622011-05-05 13:52:32 +01001448 // Writes a single byte or word of data in the code stream. Used for
1449 // inline tables, e.g., jump-tables.
1450 void db(uint8_t data);
1451 void dd(uint32_t data);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001452 void dq(uint64_t data);
1453 void dp(uintptr_t data) { dd(data); }
1454 void dd(Label* label);
Steve Blocka7e24c12009-10-30 11:49:00 +00001455
Steve Blocka7e24c12009-10-30 11:49:00 +00001456 // Check if there is less than kGap bytes available in the buffer.
1457 // If this is the case, we need to grow the buffer before emitting
1458 // an instruction or relocation information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001459 inline bool buffer_overflow() const {
1460 return pc_ >= reloc_info_writer.pos() - kGap;
1461 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001462
1463 // Get the number of bytes available in the buffer.
1464 inline int available_space() const { return reloc_info_writer.pos() - pc_; }
1465
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001466 static bool IsNop(Address addr);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001467
Ben Murdochda12d292016-06-02 14:46:10 +01001468 AssemblerPositionsRecorder* positions_recorder() {
1469 return &positions_recorder_;
1470 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001471
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001472 int relocation_writer_size() {
1473 return (buffer_ + buffer_size_) - reloc_info_writer.pos();
1474 }
1475
Steve Blocka7e24c12009-10-30 11:49:00 +00001476 // Avoid overflows for displacements etc.
1477 static const int kMaximalBufferSize = 512*MB;
Steve Blocka7e24c12009-10-30 11:49:00 +00001478
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001479 byte byte_at(int pos) { return buffer_[pos]; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001480 void set_byte_at(int pos, byte value) { buffer_[pos] = value; }
1481
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001482 void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1483 ConstantPoolEntry::Access access,
1484 ConstantPoolEntry::Type type) {
1485 // No embedded constant pool support.
1486 UNREACHABLE();
1487 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001488
Steve Blocka7e24c12009-10-30 11:49:00 +00001489 protected:
Steve Blocka7e24c12009-10-30 11:49:00 +00001490 void emit_sse_operand(XMMRegister reg, const Operand& adr);
1491 void emit_sse_operand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001492 void emit_sse_operand(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001493 void emit_sse_operand(XMMRegister dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001494
Steve Block44f0eee2011-05-26 01:26:41 +01001495 byte* addr_at(int pos) { return buffer_ + pos; }
1496
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001497
Ben Murdochb0fe1622011-05-05 13:52:32 +01001498 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00001499 uint32_t long_at(int pos) {
1500 return *reinterpret_cast<uint32_t*>(addr_at(pos));
1501 }
1502 void long_at_put(int pos, uint32_t x) {
1503 *reinterpret_cast<uint32_t*>(addr_at(pos)) = x;
1504 }
1505
1506 // code emission
1507 void GrowBuffer();
1508 inline void emit(uint32_t x);
1509 inline void emit(Handle<Object> handle);
Ben Murdoch257744e2011-11-30 15:57:28 +00001510 inline void emit(uint32_t x,
1511 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001512 TypeFeedbackId id = TypeFeedbackId::None());
1513 inline void emit(Handle<Code> code,
1514 RelocInfo::Mode rmode,
1515 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001516 inline void emit(const Immediate& x);
Ben Murdochda12d292016-06-02 14:46:10 +01001517 inline void emit_b(Immediate x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001518 inline void emit_w(const Immediate& x);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001519 inline void emit_q(uint64_t x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001520
1521 // Emit the code-object-relative offset of the label's position
1522 inline void emit_code_relative_offset(Label* label);
1523
1524 // instruction generation
1525 void emit_arith_b(int op1, int op2, Register dst, int imm8);
1526
1527 // Emit a basic arithmetic instruction (i.e. first byte of the family is 0x81)
1528 // with a given destination expression and an immediate operand. It attempts
1529 // to use the shortest encoding possible.
1530 // sel specifies the /n in the modrm byte (see the Intel PRM).
1531 void emit_arith(int sel, Operand dst, const Immediate& x);
1532
1533 void emit_operand(Register reg, const Operand& adr);
1534
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001535 void emit_label(Label* label);
1536
Steve Blocka7e24c12009-10-30 11:49:00 +00001537 void emit_farith(int b1, int b2, int i);
1538
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001539 // Emit vex prefix
1540 enum SIMDPrefix { kNone = 0x0, k66 = 0x1, kF3 = 0x2, kF2 = 0x3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001541 enum VectorLength { kL128 = 0x0, kL256 = 0x4, kLIG = kL128, kLZ = kL128 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001542 enum VexW { kW0 = 0x0, kW1 = 0x80, kWIG = kW0 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001543 enum LeadingOpcode { k0F = 0x1, k0F38 = 0x2, k0F3A = 0x3 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001544 inline void emit_vex_prefix(XMMRegister v, VectorLength l, SIMDPrefix pp,
1545 LeadingOpcode m, VexW w);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001546 inline void emit_vex_prefix(Register v, VectorLength l, SIMDPrefix pp,
1547 LeadingOpcode m, VexW w);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001548
Steve Blocka7e24c12009-10-30 11:49:00 +00001549 // labels
1550 void print(Label* L);
1551 void bind_to(Label* L, int pos);
Steve Blocka7e24c12009-10-30 11:49:00 +00001552
1553 // displacements
1554 inline Displacement disp_at(Label* L);
1555 inline void disp_at_put(Label* L, Displacement disp);
1556 inline void emit_disp(Label* L, Displacement::Type type);
Ben Murdoch257744e2011-11-30 15:57:28 +00001557 inline void emit_near_disp(Label* L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001559 // Most BMI instructions are similiar.
1560 void bmi1(byte op, Register reg, Register vreg, const Operand& rm);
1561 void bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
1562 const Operand& rm);
1563
Steve Blocka7e24c12009-10-30 11:49:00 +00001564 // record reloc info for current pc_
1565 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1566
1567 friend class CodePatcher;
1568 friend class EnsureSpace;
1569
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001570 // Internal reference positions, required for (potential) patching in
1571 // GrowBuffer(); contains only those internal references whose labels
1572 // are already bound.
1573 std::deque<int> internal_reference_positions_;
1574
Steve Blocka7e24c12009-10-30 11:49:00 +00001575 // code generation
Steve Blocka7e24c12009-10-30 11:49:00 +00001576 RelocInfoWriter reloc_info_writer;
1577
Ben Murdochda12d292016-06-02 14:46:10 +01001578 AssemblerPositionsRecorder positions_recorder_;
1579 friend class AssemblerPositionsRecorder;
Steve Blocka7e24c12009-10-30 11:49:00 +00001580};
1581
1582
1583// Helper class that ensures that there is enough space for generating
1584// instructions and relocation information. The constructor makes
1585// sure that there is enough space and (in debug mode) the destructor
1586// checks that we did not generate too much.
1587class EnsureSpace BASE_EMBEDDED {
1588 public:
1589 explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001590 if (assembler_->buffer_overflow()) assembler_->GrowBuffer();
Steve Blocka7e24c12009-10-30 11:49:00 +00001591#ifdef DEBUG
1592 space_before_ = assembler_->available_space();
1593#endif
1594 }
1595
1596#ifdef DEBUG
1597 ~EnsureSpace() {
1598 int bytes_generated = space_before_ - assembler_->available_space();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001599 DCHECK(bytes_generated < assembler_->kGap);
Steve Blocka7e24c12009-10-30 11:49:00 +00001600 }
1601#endif
1602
1603 private:
1604 Assembler* assembler_;
1605#ifdef DEBUG
1606 int space_before_;
1607#endif
1608};
1609
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001610} // namespace internal
1611} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001612
1613#endif // V8_IA32_ASSEMBLER_IA32_H_