blob: c3edacb0ac5b369c6c76380baed92988cd327f2c [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 const char* ToString();
128 bool IsAllocatable() const;
129 bool is_valid() const { return 0 <= reg_code && reg_code < kNumRegisters; }
130 bool is(Register reg) const { return reg_code == reg.reg_code; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100131 int code() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133 return reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100135 int bit() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 return 1 << reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000138 }
139
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 bool is_byte_register() const { return reg_code <= 3; }
141
Andrei Popescu31002712010-02-23 13:46:05 +0000142 // Unfortunately we can't make this private in a struct.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000143 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000144};
145
Steve Block1e0659c2011-05-24 12:43:12 +0100146
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147#define DECLARE_REGISTER(R) const Register R = {Register::kCode_##R};
148GENERAL_REGISTERS(DECLARE_REGISTER)
149#undef DECLARE_REGISTER
150const Register no_reg = {Register::kCode_no_reg};
Steve Blocka7e24c12009-10-30 11:49:00 +0000151
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 IsAllocatable() const;
169 bool is_valid() const { return 0 <= reg_code && reg_code < kMaxNumRegisters; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170
171 int code() const {
172 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173 return reg_code;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174 }
175
Ben Murdochc5610432016-08-08 18:44:38 +0100176 bool is(XMMRegister reg) const { return reg_code == reg.reg_code; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000177
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000178 const char* ToString();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100179
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000180 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000181};
182
Ben Murdochc5610432016-08-08 18:44:38 +0100183typedef XMMRegister FloatRegister;
184
185typedef XMMRegister DoubleRegister;
186
187typedef XMMRegister Simd128Register;
188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000189#define DECLARE_REGISTER(R) \
190 const DoubleRegister R = {DoubleRegister::kCode_##R};
191DOUBLE_REGISTERS(DECLARE_REGISTER)
192#undef DECLARE_REGISTER
193const DoubleRegister no_double_reg = {DoubleRegister::kCode_no_reg};
Ben Murdochb0fe1622011-05-05 13:52:32 +0100194
Steve Blocka7e24c12009-10-30 11:49:00 +0000195enum Condition {
196 // any value < 0 is considered no_condition
197 no_condition = -1,
198
199 overflow = 0,
200 no_overflow = 1,
201 below = 2,
202 above_equal = 3,
203 equal = 4,
204 not_equal = 5,
205 below_equal = 6,
206 above = 7,
207 negative = 8,
208 positive = 9,
209 parity_even = 10,
210 parity_odd = 11,
211 less = 12,
212 greater_equal = 13,
213 less_equal = 14,
214 greater = 15,
215
216 // aliases
217 carry = below,
218 not_carry = above_equal,
219 zero = equal,
220 not_zero = not_equal,
221 sign = negative,
222 not_sign = positive
223};
224
225
226// Returns the equivalent of !cc.
227// Negation of the default no_condition (-1) results in a non-default
228// no_condition value (-2). As long as tests for no_condition check
229// for condition < 0, this will work as expected.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100230inline Condition NegateCondition(Condition cc) {
231 return static_cast<Condition>(cc ^ 1);
232}
233
Steve Blocka7e24c12009-10-30 11:49:00 +0000234
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000235// Commute a condition such that {a cond b == b cond' a}.
236inline Condition CommuteCondition(Condition cc) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 switch (cc) {
238 case below:
239 return above;
240 case above:
241 return below;
242 case above_equal:
243 return below_equal;
244 case below_equal:
245 return above_equal;
246 case less:
247 return greater;
248 case greater:
249 return less;
250 case greater_equal:
251 return less_equal;
252 case less_equal:
253 return greater_equal;
254 default:
255 return cc;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000257}
258
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100259
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000260enum RoundingMode {
261 kRoundToNearest = 0x0,
262 kRoundDown = 0x1,
263 kRoundUp = 0x2,
264 kRoundToZero = 0x3
265};
266
267
Steve Blocka7e24c12009-10-30 11:49:00 +0000268// -----------------------------------------------------------------------------
269// Machine instruction Immediates
270
271class Immediate BASE_EMBEDDED {
272 public:
273 inline explicit Immediate(int x);
Steve Blocka7e24c12009-10-30 11:49:00 +0000274 inline explicit Immediate(const ExternalReference& ext);
275 inline explicit Immediate(Handle<Object> handle);
276 inline explicit Immediate(Smi* value);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100277 inline explicit Immediate(Address addr);
Ben Murdochda12d292016-06-02 14:46:10 +0100278 inline explicit Immediate(Address x, RelocInfo::Mode rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000279
280 static Immediate CodeRelativeOffset(Label* label) {
281 return Immediate(label);
282 }
283
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284 bool is_zero() const { return x_ == 0 && RelocInfo::IsNone(rmode_); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 bool is_int8() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 return -128 <= x_ && x_ < 128 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000287 }
Ben Murdochda12d292016-06-02 14:46:10 +0100288 bool is_uint8() const {
289 return v8::internal::is_uint8(x_) && RelocInfo::IsNone(rmode_);
290 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000291 bool is_int16() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000292 return -32768 <= x_ && x_ < 32768 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000293 }
Ben Murdochda12d292016-06-02 14:46:10 +0100294 bool is_uint16() const {
295 return v8::internal::is_uint16(x_) && RelocInfo::IsNone(rmode_);
296 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000297
298 private:
299 inline explicit Immediate(Label* value);
300
301 int x_;
302 RelocInfo::Mode rmode_;
303
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000304 friend class Operand;
Steve Blocka7e24c12009-10-30 11:49:00 +0000305 friend class Assembler;
Steve Block053d10c2011-06-13 19:13:29 +0100306 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000307};
308
309
310// -----------------------------------------------------------------------------
311// Machine instruction Operands
312
313enum ScaleFactor {
314 times_1 = 0,
315 times_2 = 1,
316 times_4 = 2,
317 times_8 = 3,
Leon Clarke4515c472010-02-03 11:58:03 +0000318 times_int_size = times_4,
319 times_half_pointer_size = times_2,
Andrei Popescu402d9372010-02-26 13:31:12 +0000320 times_pointer_size = times_4,
321 times_twice_pointer_size = times_8
Steve Blocka7e24c12009-10-30 11:49:00 +0000322};
323
324
325class Operand BASE_EMBEDDED {
326 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 // reg
328 INLINE(explicit Operand(Register reg));
329
Steve Block6ded16b2010-05-10 14:33:55 +0100330 // XMM reg
331 INLINE(explicit Operand(XMMRegister xmm_reg));
332
Steve Blocka7e24c12009-10-30 11:49:00 +0000333 // [disp/r]
334 INLINE(explicit Operand(int32_t disp, RelocInfo::Mode rmode));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000335
336 // [disp/r]
337 INLINE(explicit Operand(Immediate imm));
Steve Blocka7e24c12009-10-30 11:49:00 +0000338
339 // [base + disp/r]
340 explicit Operand(Register base, int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000342
343 // [base + index*scale + disp/r]
344 explicit Operand(Register base,
345 Register index,
346 ScaleFactor scale,
347 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000348 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000349
350 // [index*scale + disp/r]
351 explicit Operand(Register index,
352 ScaleFactor scale,
353 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000354 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000355
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000356 static Operand JumpTable(Register index, ScaleFactor scale, Label* table) {
357 return Operand(index, scale, reinterpret_cast<int32_t>(table),
358 RelocInfo::INTERNAL_REFERENCE);
359 }
360
Steve Blocka7e24c12009-10-30 11:49:00 +0000361 static Operand StaticVariable(const ExternalReference& ext) {
362 return Operand(reinterpret_cast<int32_t>(ext.address()),
363 RelocInfo::EXTERNAL_REFERENCE);
364 }
365
366 static Operand StaticArray(Register index,
367 ScaleFactor scale,
368 const ExternalReference& arr) {
369 return Operand(index, scale, reinterpret_cast<int32_t>(arr.address()),
370 RelocInfo::EXTERNAL_REFERENCE);
371 }
372
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000373 static Operand ForCell(Handle<Cell> cell) {
374 AllowDeferredHandleDereference embedding_raw_address;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100375 return Operand(reinterpret_cast<int32_t>(cell.location()),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000376 RelocInfo::CELL);
377 }
378
379 static Operand ForRegisterPlusImmediate(Register base, Immediate imm) {
380 return Operand(base, imm.x_, imm.rmode_);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100381 }
382
Steve Blocka7e24c12009-10-30 11:49:00 +0000383 // Returns true if this Operand is a wrapper for the specified register.
384 bool is_reg(Register reg) const;
385
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100386 // Returns true if this Operand is a wrapper for one register.
387 bool is_reg_only() const;
388
389 // Asserts that this Operand is a wrapper for one register and returns the
390 // register.
391 Register reg() const;
392
Steve Blocka7e24c12009-10-30 11:49:00 +0000393 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 // Set the ModRM byte without an encoded 'reg' register. The
395 // register is encoded later as part of the emit_operand operation.
396 inline void set_modrm(int mod, Register rm);
397
398 inline void set_sib(ScaleFactor scale, Register index, Register base);
399 inline void set_disp8(int8_t disp);
400 inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
401
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100402 byte buf_[6];
403 // The number of bytes in buf_.
404 unsigned int len_;
405 // Only valid if len_ > 4.
406 RelocInfo::Mode rmode_;
407
Steve Blocka7e24c12009-10-30 11:49:00 +0000408 friend class Assembler;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100409 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000410};
411
412
413// -----------------------------------------------------------------------------
414// A Displacement describes the 32bit immediate field of an instruction which
415// may be used together with a Label in order to refer to a yet unknown code
416// position. Displacements stored in the instruction stream are used to describe
417// the instruction and to chain a list of instructions using the same Label.
418// A Displacement contains 2 different fields:
419//
420// next field: position of next displacement in the chain (0 = end of list)
421// type field: instruction type
422//
423// A next value of null (0) indicates the end of a chain (note that there can
424// be no displacement at position zero, because there is always at least one
425// instruction byte before the displacement).
426//
427// Displacement _data field layout
428//
429// |31.....2|1......0|
430// [ next | type |
431
432class Displacement BASE_EMBEDDED {
433 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434 enum Type { UNCONDITIONAL_JUMP, CODE_RELATIVE, OTHER, CODE_ABSOLUTE };
Steve Blocka7e24c12009-10-30 11:49:00 +0000435
436 int data() const { return data_; }
437 Type type() const { return TypeField::decode(data_); }
438 void next(Label* L) const {
439 int n = NextField::decode(data_);
440 n > 0 ? L->link_to(n) : L->Unuse();
441 }
442 void link_to(Label* L) { init(L, type()); }
443
444 explicit Displacement(int data) { data_ = data; }
445
446 Displacement(Label* L, Type type) { init(L, type); }
447
448 void print() {
449 PrintF("%s (%x) ", (type() == UNCONDITIONAL_JUMP ? "jmp" : "[other]"),
450 NextField::decode(data_));
451 }
452
453 private:
454 int data_;
455
456 class TypeField: public BitField<Type, 0, 2> {};
457 class NextField: public BitField<int, 2, 32-2> {};
458
459 void init(Label* L, Type type);
460};
461
462
Steve Block44f0eee2011-05-26 01:26:41 +0100463class Assembler : public AssemblerBase {
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 private:
465 // We check before assembling an instruction that there is sufficient
466 // space to write an instruction and its relocation information.
467 // The relocation writer's position must be kGap bytes above the end of
468 // the generated instructions. This leaves enough space for the
469 // longest possible ia32 instruction, 15 bytes, and the longest possible
470 // relocation information encoding, RelocInfoWriter::kMaxLength == 16.
471 // (There is a 15 byte limit on ia32 instruction length that rules out some
472 // otherwise valid instructions.)
473 // This allows for a single, fast space check per instruction.
474 static const int kGap = 32;
475
476 public:
477 // Create an assembler. Instructions and relocation information are emitted
478 // into a buffer, with the instructions starting from the beginning and the
479 // relocation information starting from the end of the buffer. See CodeDesc
480 // for a detailed comment on the layout (globals.h).
481 //
482 // If the provided buffer is NULL, the assembler allocates and grows its own
483 // buffer, and buffer_size determines the initial buffer size. The buffer is
484 // owned by the assembler and deallocated upon destruction of the assembler.
485 //
486 // If the provided buffer is not NULL, the assembler uses the provided buffer
487 // for code generation and assumes its size to be buffer_size. If the buffer
488 // is too small, a fatal error occurs. No deallocation of the buffer is done
489 // upon destruction of the assembler.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100490 // TODO(vitalyr): the assembler does not need an isolate.
491 Assembler(Isolate* isolate, void* buffer, int buffer_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000492 virtual ~Assembler() { }
Steve Block44f0eee2011-05-26 01:26:41 +0100493
Steve Blocka7e24c12009-10-30 11:49:00 +0000494 // GetCode emits any pending (non-emitted) code and fills the descriptor
495 // desc. GetCode() is idempotent; it returns the same result if no other
496 // Assembler functions are invoked in between GetCode() calls.
497 void GetCode(CodeDesc* desc);
498
499 // Read/Modify the code target in the branch/call instruction at pc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000500 inline static Address target_address_at(Address pc, Address constant_pool);
501 inline static void set_target_address_at(
502 Isolate* isolate, Address pc, Address constant_pool, Address target,
503 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000504 static inline Address target_address_at(Address pc, Code* code) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000505 Address constant_pool = code ? code->constant_pool() : NULL;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000506 return target_address_at(pc, constant_pool);
507 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000508 static inline void set_target_address_at(
509 Isolate* isolate, Address pc, Code* code, Address target,
510 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED) {
511 Address constant_pool = code ? code->constant_pool() : NULL;
512 set_target_address_at(isolate, pc, constant_pool, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000513 }
514
515 // Return the code target address at a call site from the return address
516 // of that call in the instruction stream.
517 inline static Address target_address_from_return_address(Address pc);
518
Steve Blockd0582a62009-12-15 09:54:21 +0000519 // This sets the branch destination (which is in the instruction on x86).
520 // This is for calls and branches within generated code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100521 inline static void deserialization_set_special_target_at(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000522 Isolate* isolate, Address instruction_payload, Code* code,
523 Address target) {
524 set_target_address_at(isolate, instruction_payload, code, target);
Steve Blockd0582a62009-12-15 09:54:21 +0000525 }
526
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000527 // This sets the internal reference at the pc.
528 inline static void deserialization_set_target_internal_reference_at(
529 Isolate* isolate, Address pc, Address target,
530 RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
531
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100532 static const int kSpecialTargetSize = kPointerSize;
Steve Blockd0582a62009-12-15 09:54:21 +0000533
Steve Blocka7e24c12009-10-30 11:49:00 +0000534 // Distance between the address of the code target in the call instruction
535 // and the return address
536 static const int kCallTargetAddressOffset = kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000537
538 static const int kCallInstructionLength = 5;
539
540 // The debug break slot must be able to contain a call instruction.
541 static const int kDebugBreakSlotLength = kCallInstructionLength;
Steve Blocka7e24c12009-10-30 11:49:00 +0000542
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100543 // Distance between start of patched debug break slot and the emitted address
544 // to jump to.
545 static const int kPatchDebugBreakSlotAddressOffset = 1; // JMP imm32.
546
Ben Murdochb0fe1622011-05-05 13:52:32 +0100547 // One byte opcode for test al, 0xXX.
548 static const byte kTestAlByte = 0xA8;
549 // One byte opcode for nop.
550 static const byte kNopByte = 0x90;
551
552 // One byte opcode for a short unconditional jump.
553 static const byte kJmpShortOpcode = 0xEB;
554 // One byte prefix for a short conditional jump.
555 static const byte kJccShortPrefix = 0x70;
556 static const byte kJncShortOpcode = kJccShortPrefix | not_carry;
557 static const byte kJcShortOpcode = kJccShortPrefix | carry;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000558 static const byte kJnzShortOpcode = kJccShortPrefix | not_zero;
559 static const byte kJzShortOpcode = kJccShortPrefix | zero;
560
Ben Murdochb0fe1622011-05-05 13:52:32 +0100561
Steve Blocka7e24c12009-10-30 11:49:00 +0000562 // ---------------------------------------------------------------------------
563 // Code generation
564 //
565 // - function names correspond one-to-one to ia32 instruction mnemonics
566 // - unless specified otherwise, instructions operate on 32bit operands
567 // - instructions on 8bit (byte) operands/registers have a trailing '_b'
568 // - instructions on 16bit (word) operands/registers have a trailing '_w'
569 // - naming conflicts with C++ keywords are resolved via a trailing '_'
570
571 // NOTE ON INTERFACE: Currently, the interface is not very consistent
572 // in the sense that some operations (e.g. mov()) can be called in more
573 // the one way to generate the same instruction: The Register argument
574 // can in some cases be replaced with an Operand(Register) argument.
575 // This should be cleaned up and made more orthogonal. The questions
576 // is: should we always use Operands instead of Registers where an
577 // Operand is possible, or should we have a Register (overloaded) form
578 // instead? We must be careful to make sure that the selected instruction
579 // is obvious from the parameters to avoid hard-to-find code generation
580 // bugs.
581
582 // Insert the smallest number of nop instructions
583 // possible to align the pc offset to a multiple
584 // of m. m must be a power of 2.
585 void Align(int m);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000586 // Insert the smallest number of zero bytes possible to align the pc offset
587 // to a mulitple of m. m must be a power of 2 (>= 2).
588 void DataAlign(int m);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100589 void Nop(int bytes = 1);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100590 // Aligns code to something that's optimal for a jump target for the platform.
591 void CodeTargetAlign();
Steve Blocka7e24c12009-10-30 11:49:00 +0000592
593 // Stack
594 void pushad();
595 void popad();
596
597 void pushfd();
598 void popfd();
599
600 void push(const Immediate& x);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100601 void push_imm32(int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000602 void push(Register src);
603 void push(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000604
605 void pop(Register dst);
606 void pop(const Operand& dst);
607
608 void enter(const Immediate& size);
609 void leave();
610
611 // Moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100612 void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000613 void mov_b(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100614 void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400615 void mov_b(const Operand& dst, int8_t src) { mov_b(dst, Immediate(src)); }
616 void mov_b(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000617 void mov_b(const Operand& dst, Register src);
618
619 void mov_w(Register dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400620 void mov_w(const Operand& dst, int16_t src) { mov_w(dst, Immediate(src)); }
621 void mov_w(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000622 void mov_w(const Operand& dst, Register src);
623
624 void mov(Register dst, int32_t imm32);
625 void mov(Register dst, const Immediate& x);
626 void mov(Register dst, Handle<Object> handle);
627 void mov(Register dst, const Operand& src);
628 void mov(Register dst, Register src);
629 void mov(const Operand& dst, const Immediate& x);
630 void mov(const Operand& dst, Handle<Object> handle);
631 void mov(const Operand& dst, Register src);
632
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100633 void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000634 void movsx_b(Register dst, const Operand& src);
635
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100636 void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000637 void movsx_w(Register dst, const Operand& src);
638
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639 void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000640 void movzx_b(Register dst, const Operand& src);
641
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100642 void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000643 void movzx_w(Register dst, const Operand& src);
644
645 // Conditional moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100646 void cmov(Condition cc, Register dst, Register src) {
647 cmov(cc, dst, Operand(src));
648 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000649 void cmov(Condition cc, Register dst, const Operand& src);
650
Steve Block6ded16b2010-05-10 14:33:55 +0100651 // Flag management.
652 void cld();
653
Leon Clarkee46be812010-01-19 14:06:41 +0000654 // Repetitive string instructions.
655 void rep_movs();
Steve Block6ded16b2010-05-10 14:33:55 +0100656 void rep_stos();
Leon Clarkef7060e22010-06-03 12:02:55 +0100657 void stos();
Leon Clarkee46be812010-01-19 14:06:41 +0000658
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000659 // Exchange
Steve Blocka7e24c12009-10-30 11:49:00 +0000660 void xchg(Register dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000661 void xchg(Register dst, const Operand& src);
Ben Murdochc5610432016-08-08 18:44:38 +0100662 void xchg_b(Register reg, const Operand& op);
663 void xchg_w(Register reg, const Operand& op);
Steve Blocka7e24c12009-10-30 11:49:00 +0000664
665 // Arithmetics
666 void adc(Register dst, int32_t imm32);
667 void adc(Register dst, const Operand& src);
668
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100669 void add(Register dst, Register src) { add(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000670 void add(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100671 void add(const Operand& dst, Register src);
672 void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000673 void add(const Operand& dst, const Immediate& x);
674
675 void and_(Register dst, int32_t imm32);
Steve Block59151502010-09-22 15:07:15 +0100676 void and_(Register dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100677 void and_(Register dst, Register src) { and_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 void and_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100679 void and_(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000680 void and_(const Operand& dst, const Immediate& x);
681
Ben Murdochda12d292016-06-02 14:46:10 +0100682 void cmpb(Register reg, Immediate imm8) { cmpb(Operand(reg), imm8); }
683 void cmpb(const Operand& op, Immediate imm8);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100684 void cmpb(Register reg, const Operand& op);
685 void cmpb(const Operand& op, Register reg);
Ben Murdochda12d292016-06-02 14:46:10 +0100686 void cmpb(Register dst, Register src) { cmpb(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000687 void cmpb_al(const Operand& op);
688 void cmpw_ax(const Operand& op);
Ben Murdochda12d292016-06-02 14:46:10 +0100689 void cmpw(const Operand& dst, Immediate src);
690 void cmpw(Register dst, Immediate src) { cmpw(Operand(dst), src); }
691 void cmpw(Register dst, const Operand& src);
692 void cmpw(Register dst, Register src) { cmpw(Operand(dst), src); }
693 void cmpw(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000694 void cmp(Register reg, int32_t imm32);
695 void cmp(Register reg, Handle<Object> handle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100696 void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000697 void cmp(Register reg, const Operand& op);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100698 void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100699 void cmp(const Operand& op, Register reg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000700 void cmp(const Operand& op, const Immediate& imm);
701 void cmp(const Operand& op, Handle<Object> handle);
702
703 void dec_b(Register dst);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100704 void dec_b(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000705
706 void dec(Register dst);
707 void dec(const Operand& dst);
708
709 void cdq();
710
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000711 void idiv(Register src) { idiv(Operand(src)); }
712 void idiv(const Operand& src);
713 void div(Register src) { div(Operand(src)); }
714 void div(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000715
716 // Signed multiply instructions.
717 void imul(Register src); // edx:eax = eax * src.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100718 void imul(Register dst, Register src) { imul(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000719 void imul(Register dst, const Operand& src); // dst = dst * src.
720 void imul(Register dst, Register src, int32_t imm32); // dst = src * imm32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000721 void imul(Register dst, const Operand& src, int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000722
723 void inc(Register dst);
724 void inc(const Operand& dst);
725
726 void lea(Register dst, const Operand& src);
727
728 // Unsigned multiply instruction.
729 void mul(Register src); // edx:eax = eax * reg.
730
731 void neg(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000732 void neg(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000733
734 void not_(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000735 void not_(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000736
737 void or_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100738 void or_(Register dst, Register src) { or_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000739 void or_(Register dst, const Operand& src);
740 void or_(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100741 void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000742 void or_(const Operand& dst, const Immediate& x);
743
744 void rcl(Register dst, uint8_t imm8);
Iain Merrick75681382010-08-19 15:07:18 +0100745 void rcr(Register dst, uint8_t imm8);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400746
747 void ror(Register dst, uint8_t imm8) { ror(Operand(dst), imm8); }
748 void ror(const Operand& dst, uint8_t imm8);
749 void ror_cl(Register dst) { ror_cl(Operand(dst)); }
750 void ror_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000751
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000752 void sar(Register dst, uint8_t imm8) { sar(Operand(dst), imm8); }
753 void sar(const Operand& dst, uint8_t imm8);
754 void sar_cl(Register dst) { sar_cl(Operand(dst)); }
755 void sar_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000756
757 void sbb(Register dst, const Operand& src);
758
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000759 void shl(Register dst, uint8_t imm8) { shl(Operand(dst), imm8); }
760 void shl(const Operand& dst, uint8_t imm8);
761 void shl_cl(Register dst) { shl_cl(Operand(dst)); }
762 void shl_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100763 void shld(Register dst, Register src, uint8_t shift);
764 void shld_cl(Register dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000765
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000766 void shr(Register dst, uint8_t imm8) { shr(Operand(dst), imm8); }
767 void shr(const Operand& dst, uint8_t imm8);
768 void shr_cl(Register dst) { shr_cl(Operand(dst)); }
769 void shr_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100770 void shrd(Register dst, Register src, uint8_t shift);
771 void shrd_cl(Register dst, Register src) { shrd_cl(Operand(dst), src); }
772 void shrd_cl(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000773
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100774 void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000775 void sub(const Operand& dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100776 void sub(Register dst, Register src) { sub(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000777 void sub(Register dst, const Operand& src);
778 void sub(const Operand& dst, Register src);
779
780 void test(Register reg, const Immediate& imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100781 void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000782 void test(Register reg, const Operand& op);
783 void test(const Operand& op, const Immediate& imm);
Ben Murdochda12d292016-06-02 14:46:10 +0100784 void test(const Operand& op, Register reg) { test(reg, op); }
785 void test_b(Register reg, const Operand& op);
786 void test_b(Register reg, Immediate imm8);
787 void test_b(const Operand& op, Immediate imm8);
788 void test_b(const Operand& op, Register reg) { test_b(reg, op); }
789 void test_b(Register dst, Register src) { test_b(dst, Operand(src)); }
790 void test_w(Register reg, const Operand& op);
791 void test_w(Register reg, Immediate imm16);
792 void test_w(const Operand& op, Immediate imm16);
793 void test_w(const Operand& op, Register reg) { test_w(reg, op); }
794 void test_w(Register dst, Register src) { test_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000795
796 void xor_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100797 void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000798 void xor_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100799 void xor_(const Operand& dst, Register src);
800 void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000801 void xor_(const Operand& dst, const Immediate& x);
802
803 // Bit operations.
804 void bt(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100805 void bts(Register dst, Register src) { bts(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000806 void bts(const Operand& dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000807 void bsr(Register dst, Register src) { bsr(dst, Operand(src)); }
808 void bsr(Register dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000809 void bsf(Register dst, Register src) { bsf(dst, Operand(src)); }
810 void bsf(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000811
812 // Miscellaneous
813 void hlt();
814 void int3();
815 void nop();
Steve Blocka7e24c12009-10-30 11:49:00 +0000816 void ret(int imm16);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000817 void ud2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000818
819 // Label operations & relative jumps (PPUM Appendix D)
820 //
821 // Takes a branch opcode (cc) and a label (L) and generates
822 // either a backward branch or a forward branch and links it
823 // to the label fixup chain. Usage:
824 //
825 // Label L; // unbound label
826 // j(cc, &L); // forward branch to unbound label
827 // bind(&L); // bind label to the current pc
828 // j(cc, &L); // backward branch to bound label
829 // bind(&L); // illegal: a label may be bound only once
830 //
831 // Note: The same Label can be used for forward and backward branches
832 // but it may be bound only once.
833
834 void bind(Label* L); // binds an unbound label L to the current code position
835
836 // Calls
837 void call(Label* L);
838 void call(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch257744e2011-11-30 15:57:28 +0000839 int CallSize(const Operand& adr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100840 void call(Register reg) { call(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000841 void call(const Operand& adr);
Ben Murdoch257744e2011-11-30 15:57:28 +0000842 int CallSize(Handle<Code> code, RelocInfo::Mode mode);
843 void call(Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000844 RelocInfo::Mode rmode,
845 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000846
847 // Jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000848 // unconditional jump to L
849 void jmp(Label* L, Label::Distance distance = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000850 void jmp(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100851 void jmp(Register reg) { jmp(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000852 void jmp(const Operand& adr);
853 void jmp(Handle<Code> code, RelocInfo::Mode rmode);
854
855 // Conditional jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000856 void j(Condition cc,
857 Label* L,
858 Label::Distance distance = Label::kFar);
859 void j(Condition cc, byte* entry, RelocInfo::Mode rmode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000860 void j(Condition cc, Handle<Code> code,
861 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100862
Steve Blocka7e24c12009-10-30 11:49:00 +0000863 // Floating-point operations
864 void fld(int i);
Andrei Popescu402d9372010-02-26 13:31:12 +0000865 void fstp(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000866
867 void fld1();
868 void fldz();
Andrei Popescu402d9372010-02-26 13:31:12 +0000869 void fldpi();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100870 void fldln2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000871
872 void fld_s(const Operand& adr);
873 void fld_d(const Operand& adr);
874
875 void fstp_s(const Operand& adr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000876 void fst_s(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000877 void fstp_d(const Operand& adr);
Andrei Popescu402d9372010-02-26 13:31:12 +0000878 void fst_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000879
880 void fild_s(const Operand& adr);
881 void fild_d(const Operand& adr);
882
883 void fist_s(const Operand& adr);
884
885 void fistp_s(const Operand& adr);
886 void fistp_d(const Operand& adr);
887
Steve Block6ded16b2010-05-10 14:33:55 +0100888 // The fisttp instructions require SSE3.
Steve Blocka7e24c12009-10-30 11:49:00 +0000889 void fisttp_s(const Operand& adr);
Leon Clarkee46be812010-01-19 14:06:41 +0000890 void fisttp_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000891
892 void fabs();
893 void fchs();
894 void fcos();
895 void fsin();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100896 void fptan();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100897 void fyl2x();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100898 void f2xm1();
899 void fscale();
900 void fninit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000901
902 void fadd(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000903 void fadd_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000904 void fsub(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 void fsub_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000906 void fmul(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000907 void fmul_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000908 void fdiv(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000909 void fdiv_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000910
911 void fisub_s(const Operand& adr);
912
913 void faddp(int i = 1);
914 void fsubp(int i = 1);
915 void fsubrp(int i = 1);
916 void fmulp(int i = 1);
917 void fdivp(int i = 1);
918 void fprem();
919 void fprem1();
920
921 void fxch(int i = 1);
922 void fincstp();
923 void ffree(int i = 0);
924
925 void ftst();
926 void fucomp(int i);
927 void fucompp();
Steve Block3ce2e202009-11-05 08:53:23 +0000928 void fucomi(int i);
929 void fucomip();
Steve Blocka7e24c12009-10-30 11:49:00 +0000930 void fcompp();
931 void fnstsw_ax();
932 void fwait();
933 void fnclex();
934
935 void frndint();
936
937 void sahf();
938 void setcc(Condition cc, Register reg);
939
940 void cpuid();
941
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 // SSE instructions
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400943 void addss(XMMRegister dst, XMMRegister src) { addss(dst, Operand(src)); }
944 void addss(XMMRegister dst, const Operand& src);
945 void subss(XMMRegister dst, XMMRegister src) { subss(dst, Operand(src)); }
946 void subss(XMMRegister dst, const Operand& src);
947 void mulss(XMMRegister dst, XMMRegister src) { mulss(dst, Operand(src)); }
948 void mulss(XMMRegister dst, const Operand& src);
949 void divss(XMMRegister dst, XMMRegister src) { divss(dst, Operand(src)); }
950 void divss(XMMRegister dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000951 void sqrtss(XMMRegister dst, XMMRegister src) { sqrtss(dst, Operand(src)); }
952 void sqrtss(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400953
954 void ucomiss(XMMRegister dst, XMMRegister src) { ucomiss(dst, Operand(src)); }
955 void ucomiss(XMMRegister dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000956 void movaps(XMMRegister dst, XMMRegister src);
957 void shufps(XMMRegister dst, XMMRegister src, byte imm8);
958
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000959 void maxss(XMMRegister dst, XMMRegister src) { maxss(dst, Operand(src)); }
960 void maxss(XMMRegister dst, const Operand& src);
961 void minss(XMMRegister dst, XMMRegister src) { minss(dst, Operand(src)); }
962 void minss(XMMRegister dst, const Operand& src);
963
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000964 void andps(XMMRegister dst, const Operand& src);
965 void andps(XMMRegister dst, XMMRegister src) { andps(dst, Operand(src)); }
966 void xorps(XMMRegister dst, const Operand& src);
967 void xorps(XMMRegister dst, XMMRegister src) { xorps(dst, Operand(src)); }
968 void orps(XMMRegister dst, const Operand& src);
969 void orps(XMMRegister dst, XMMRegister src) { orps(dst, Operand(src)); }
970
971 void addps(XMMRegister dst, const Operand& src);
972 void addps(XMMRegister dst, XMMRegister src) { addps(dst, Operand(src)); }
973 void subps(XMMRegister dst, const Operand& src);
974 void subps(XMMRegister dst, XMMRegister src) { subps(dst, Operand(src)); }
975 void mulps(XMMRegister dst, const Operand& src);
976 void mulps(XMMRegister dst, XMMRegister src) { mulps(dst, Operand(src)); }
977 void divps(XMMRegister dst, const Operand& src);
978 void divps(XMMRegister dst, XMMRegister src) { divps(dst, Operand(src)); }
979
Steve Blocka7e24c12009-10-30 11:49:00 +0000980 // SSE2 instructions
981 void cvttss2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000982 void cvttss2si(Register dst, XMMRegister src) {
983 cvttss2si(dst, Operand(src));
984 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000985 void cvttsd2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 void cvttsd2si(Register dst, XMMRegister src) {
987 cvttsd2si(dst, Operand(src));
988 }
989 void cvtsd2si(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000990
Ben Murdoch097c5b22016-05-18 11:27:45 +0100991 void cvtsi2ss(XMMRegister dst, Register src) { cvtsi2ss(dst, Operand(src)); }
992 void cvtsi2ss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100993 void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000994 void cvtsi2sd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400995 void cvtss2sd(XMMRegister dst, const Operand& src);
996 void cvtss2sd(XMMRegister dst, XMMRegister src) {
997 cvtss2sd(dst, Operand(src));
998 }
999 void cvtsd2ss(XMMRegister dst, const Operand& src);
1000 void cvtsd2ss(XMMRegister dst, XMMRegister src) {
1001 cvtsd2ss(dst, Operand(src));
1002 }
1003 void addsd(XMMRegister dst, XMMRegister src) { addsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001004 void addsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001005 void subsd(XMMRegister dst, XMMRegister src) { subsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001006 void subsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001007 void mulsd(XMMRegister dst, XMMRegister src) { mulsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001008 void mulsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001009 void divsd(XMMRegister dst, XMMRegister src) { divsd(dst, Operand(src)); }
1010 void divsd(XMMRegister dst, const Operand& src);
Leon Clarkee46be812010-01-19 14:06:41 +00001011 void xorpd(XMMRegister dst, XMMRegister src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001012 void sqrtsd(XMMRegister dst, XMMRegister src) { sqrtsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001013 void sqrtsd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001014
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001015 void andpd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 void orpd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001017
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001018 void ucomisd(XMMRegister dst, XMMRegister src) { ucomisd(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001019 void ucomisd(XMMRegister dst, const Operand& src);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001020
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001021 void roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001022 void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
1023
Steve Block6ded16b2010-05-10 14:33:55 +01001024 void movmskpd(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001025 void movmskps(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001026
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001027 void cmpltsd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001028 void pcmpeqd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001030 void punpckldq(XMMRegister dst, XMMRegister src);
1031 void punpckhdq(XMMRegister dst, XMMRegister src);
1032
1033 void maxsd(XMMRegister dst, XMMRegister src) { maxsd(dst, Operand(src)); }
1034 void maxsd(XMMRegister dst, const Operand& src);
1035 void minsd(XMMRegister dst, XMMRegister src) { minsd(dst, Operand(src)); }
1036 void minsd(XMMRegister dst, const Operand& src);
1037
Leon Clarkee46be812010-01-19 14:06:41 +00001038 void movdqa(XMMRegister dst, const Operand& src);
1039 void movdqa(const Operand& dst, XMMRegister src);
1040 void movdqu(XMMRegister dst, const Operand& src);
1041 void movdqu(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001042 void movdq(bool aligned, XMMRegister dst, const Operand& src) {
1043 if (aligned) {
1044 movdqa(dst, src);
1045 } else {
1046 movdqu(dst, src);
1047 }
1048 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001049
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001050 void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
Steve Block6ded16b2010-05-10 14:33:55 +01001051 void movd(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001052 void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1053 void movd(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001054 void movsd(XMMRegister dst, XMMRegister src) { movsd(dst, Operand(src)); }
1055 void movsd(XMMRegister dst, const Operand& src);
1056 void movsd(const Operand& dst, XMMRegister src);
1057
Steve Block6ded16b2010-05-10 14:33:55 +01001058
Steve Block44f0eee2011-05-26 01:26:41 +01001059 void movss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001060 void movss(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001061 void movss(XMMRegister dst, XMMRegister src) { movss(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001062 void extractps(Register dst, XMMRegister src, byte imm8);
Steve Block44f0eee2011-05-26 01:26:41 +01001063
Ben Murdochb0fe1622011-05-05 13:52:32 +01001064 void pand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001065 void pxor(XMMRegister dst, XMMRegister src);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001066 void por(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001067 void ptest(XMMRegister dst, XMMRegister src);
1068
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001069 void pslld(XMMRegister reg, int8_t shift);
1070 void psrld(XMMRegister reg, int8_t shift);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001071 void psllq(XMMRegister reg, int8_t shift);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001072 void psllq(XMMRegister dst, XMMRegister src);
1073 void psrlq(XMMRegister reg, int8_t shift);
1074 void psrlq(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001075 void pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001076 void pextrd(Register dst, XMMRegister src, int8_t offset) {
1077 pextrd(Operand(dst), src, offset);
1078 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001079 void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001080 void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1081 pinsrd(dst, Operand(src), offset);
1082 }
Steve Block1e0659c2011-05-24 12:43:12 +01001083 void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001084
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001085 // AVX instructions
1086 void vfmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1087 vfmadd132sd(dst, src1, Operand(src2));
1088 }
1089 void vfmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1090 vfmadd213sd(dst, src1, Operand(src2));
1091 }
1092 void vfmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1093 vfmadd231sd(dst, src1, Operand(src2));
1094 }
1095 void vfmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1096 vfmasd(0x99, dst, src1, src2);
1097 }
1098 void vfmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1099 vfmasd(0xa9, dst, src1, src2);
1100 }
1101 void vfmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1102 vfmasd(0xb9, dst, src1, src2);
1103 }
1104 void vfmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1105 vfmsub132sd(dst, src1, Operand(src2));
1106 }
1107 void vfmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1108 vfmsub213sd(dst, src1, Operand(src2));
1109 }
1110 void vfmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1111 vfmsub231sd(dst, src1, Operand(src2));
1112 }
1113 void vfmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1114 vfmasd(0x9b, dst, src1, src2);
1115 }
1116 void vfmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1117 vfmasd(0xab, dst, src1, src2);
1118 }
1119 void vfmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1120 vfmasd(0xbb, dst, src1, src2);
1121 }
1122 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1123 vfnmadd132sd(dst, src1, Operand(src2));
1124 }
1125 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1126 vfnmadd213sd(dst, src1, Operand(src2));
1127 }
1128 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1129 vfnmadd231sd(dst, src1, Operand(src2));
1130 }
1131 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1132 vfmasd(0x9d, dst, src1, src2);
1133 }
1134 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1135 vfmasd(0xad, dst, src1, src2);
1136 }
1137 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1138 vfmasd(0xbd, dst, src1, src2);
1139 }
1140 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1141 vfnmsub132sd(dst, src1, Operand(src2));
1142 }
1143 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1144 vfnmsub213sd(dst, src1, Operand(src2));
1145 }
1146 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1147 vfnmsub231sd(dst, src1, Operand(src2));
1148 }
1149 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1150 vfmasd(0x9f, dst, src1, src2);
1151 }
1152 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1153 vfmasd(0xaf, dst, src1, src2);
1154 }
1155 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1156 vfmasd(0xbf, dst, src1, src2);
1157 }
1158 void vfmasd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1159
1160 void vfmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1161 vfmadd132ss(dst, src1, Operand(src2));
1162 }
1163 void vfmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1164 vfmadd213ss(dst, src1, Operand(src2));
1165 }
1166 void vfmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1167 vfmadd231ss(dst, src1, Operand(src2));
1168 }
1169 void vfmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1170 vfmass(0x99, dst, src1, src2);
1171 }
1172 void vfmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1173 vfmass(0xa9, dst, src1, src2);
1174 }
1175 void vfmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1176 vfmass(0xb9, dst, src1, src2);
1177 }
1178 void vfmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1179 vfmsub132ss(dst, src1, Operand(src2));
1180 }
1181 void vfmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1182 vfmsub213ss(dst, src1, Operand(src2));
1183 }
1184 void vfmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1185 vfmsub231ss(dst, src1, Operand(src2));
1186 }
1187 void vfmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1188 vfmass(0x9b, dst, src1, src2);
1189 }
1190 void vfmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1191 vfmass(0xab, dst, src1, src2);
1192 }
1193 void vfmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1194 vfmass(0xbb, dst, src1, src2);
1195 }
1196 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1197 vfnmadd132ss(dst, src1, Operand(src2));
1198 }
1199 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1200 vfnmadd213ss(dst, src1, Operand(src2));
1201 }
1202 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1203 vfnmadd231ss(dst, src1, Operand(src2));
1204 }
1205 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1206 vfmass(0x9d, dst, src1, src2);
1207 }
1208 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1209 vfmass(0xad, dst, src1, src2);
1210 }
1211 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1212 vfmass(0xbd, dst, src1, src2);
1213 }
1214 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1215 vfnmsub132ss(dst, src1, Operand(src2));
1216 }
1217 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1218 vfnmsub213ss(dst, src1, Operand(src2));
1219 }
1220 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1221 vfnmsub231ss(dst, src1, Operand(src2));
1222 }
1223 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1224 vfmass(0x9f, dst, src1, src2);
1225 }
1226 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1227 vfmass(0xaf, dst, src1, src2);
1228 }
1229 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1230 vfmass(0xbf, dst, src1, src2);
1231 }
1232 void vfmass(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1233
1234 void vaddsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1235 vaddsd(dst, src1, Operand(src2));
1236 }
1237 void vaddsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1238 vsd(0x58, dst, src1, src2);
1239 }
1240 void vsubsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1241 vsubsd(dst, src1, Operand(src2));
1242 }
1243 void vsubsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1244 vsd(0x5c, dst, src1, src2);
1245 }
1246 void vmulsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1247 vmulsd(dst, src1, Operand(src2));
1248 }
1249 void vmulsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1250 vsd(0x59, dst, src1, src2);
1251 }
1252 void vdivsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1253 vdivsd(dst, src1, Operand(src2));
1254 }
1255 void vdivsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1256 vsd(0x5e, dst, src1, src2);
1257 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001258 void vmaxsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1259 vmaxsd(dst, src1, Operand(src2));
1260 }
1261 void vmaxsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1262 vsd(0x5f, dst, src1, src2);
1263 }
1264 void vminsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1265 vminsd(dst, src1, Operand(src2));
1266 }
1267 void vminsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1268 vsd(0x5d, dst, src1, src2);
1269 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001270 void vsd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1271
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001272 void vaddss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1273 vaddss(dst, src1, Operand(src2));
1274 }
1275 void vaddss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1276 vss(0x58, dst, src1, src2);
1277 }
1278 void vsubss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1279 vsubss(dst, src1, Operand(src2));
1280 }
1281 void vsubss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1282 vss(0x5c, dst, src1, src2);
1283 }
1284 void vmulss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1285 vmulss(dst, src1, Operand(src2));
1286 }
1287 void vmulss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1288 vss(0x59, dst, src1, src2);
1289 }
1290 void vdivss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1291 vdivss(dst, src1, Operand(src2));
1292 }
1293 void vdivss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1294 vss(0x5e, dst, src1, src2);
1295 }
1296 void vmaxss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1297 vmaxss(dst, src1, Operand(src2));
1298 }
1299 void vmaxss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1300 vss(0x5f, dst, src1, src2);
1301 }
1302 void vminss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1303 vminss(dst, src1, Operand(src2));
1304 }
1305 void vminss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1306 vss(0x5d, dst, src1, src2);
1307 }
1308 void vss(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1309
1310 // BMI instruction
1311 void andn(Register dst, Register src1, Register src2) {
1312 andn(dst, src1, Operand(src2));
1313 }
1314 void andn(Register dst, Register src1, const Operand& src2) {
1315 bmi1(0xf2, dst, src1, src2);
1316 }
1317 void bextr(Register dst, Register src1, Register src2) {
1318 bextr(dst, Operand(src1), src2);
1319 }
1320 void bextr(Register dst, const Operand& src1, Register src2) {
1321 bmi1(0xf7, dst, src2, src1);
1322 }
1323 void blsi(Register dst, Register src) { blsi(dst, Operand(src)); }
1324 void blsi(Register dst, const Operand& src) {
1325 Register ireg = {3};
1326 bmi1(0xf3, ireg, dst, src);
1327 }
1328 void blsmsk(Register dst, Register src) { blsmsk(dst, Operand(src)); }
1329 void blsmsk(Register dst, const Operand& src) {
1330 Register ireg = {2};
1331 bmi1(0xf3, ireg, dst, src);
1332 }
1333 void blsr(Register dst, Register src) { blsr(dst, Operand(src)); }
1334 void blsr(Register dst, const Operand& src) {
1335 Register ireg = {1};
1336 bmi1(0xf3, ireg, dst, src);
1337 }
1338 void tzcnt(Register dst, Register src) { tzcnt(dst, Operand(src)); }
1339 void tzcnt(Register dst, const Operand& src);
1340
1341 void lzcnt(Register dst, Register src) { lzcnt(dst, Operand(src)); }
1342 void lzcnt(Register dst, const Operand& src);
1343
1344 void popcnt(Register dst, Register src) { popcnt(dst, Operand(src)); }
1345 void popcnt(Register dst, const Operand& src);
1346
1347 void bzhi(Register dst, Register src1, Register src2) {
1348 bzhi(dst, Operand(src1), src2);
1349 }
1350 void bzhi(Register dst, const Operand& src1, Register src2) {
1351 bmi2(kNone, 0xf5, dst, src2, src1);
1352 }
1353 void mulx(Register dst1, Register dst2, Register src) {
1354 mulx(dst1, dst2, Operand(src));
1355 }
1356 void mulx(Register dst1, Register dst2, const Operand& src) {
1357 bmi2(kF2, 0xf6, dst1, dst2, src);
1358 }
1359 void pdep(Register dst, Register src1, Register src2) {
1360 pdep(dst, src1, Operand(src2));
1361 }
1362 void pdep(Register dst, Register src1, const Operand& src2) {
1363 bmi2(kF2, 0xf5, dst, src1, src2);
1364 }
1365 void pext(Register dst, Register src1, Register src2) {
1366 pext(dst, src1, Operand(src2));
1367 }
1368 void pext(Register dst, Register src1, const Operand& src2) {
1369 bmi2(kF3, 0xf5, dst, src1, src2);
1370 }
1371 void sarx(Register dst, Register src1, Register src2) {
1372 sarx(dst, Operand(src1), src2);
1373 }
1374 void sarx(Register dst, const Operand& src1, Register src2) {
1375 bmi2(kF3, 0xf7, dst, src2, src1);
1376 }
1377 void shlx(Register dst, Register src1, Register src2) {
1378 shlx(dst, Operand(src1), src2);
1379 }
1380 void shlx(Register dst, const Operand& src1, Register src2) {
1381 bmi2(k66, 0xf7, dst, src2, src1);
1382 }
1383 void shrx(Register dst, Register src1, Register src2) {
1384 shrx(dst, Operand(src1), src2);
1385 }
1386 void shrx(Register dst, const Operand& src1, Register src2) {
1387 bmi2(kF2, 0xf7, dst, src2, src1);
1388 }
1389 void rorx(Register dst, Register src, byte imm8) {
1390 rorx(dst, Operand(src), imm8);
1391 }
1392 void rorx(Register dst, const Operand& src, byte imm8);
1393
1394#define PACKED_OP_LIST(V) \
1395 V(and, 0x54) \
1396 V(xor, 0x57)
1397
1398#define AVX_PACKED_OP_DECLARE(name, opcode) \
1399 void v##name##ps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1400 vps(opcode, dst, src1, Operand(src2)); \
1401 } \
1402 void v##name##ps(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1403 vps(opcode, dst, src1, src2); \
1404 } \
1405 void v##name##pd(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1406 vpd(opcode, dst, src1, Operand(src2)); \
1407 } \
1408 void v##name##pd(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1409 vpd(opcode, dst, src1, src2); \
1410 }
1411
1412 PACKED_OP_LIST(AVX_PACKED_OP_DECLARE);
1413 void vps(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1414 void vps(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1415 void vpd(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1416 void vpd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1417
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001418 // Prefetch src position into cache level.
1419 // Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a
1420 // non-temporal
1421 void prefetch(const Operand& src, int level);
1422 // TODO(lrn): Need SFENCE for movnt?
1423
Steve Blocka7e24c12009-10-30 11:49:00 +00001424 // Check the code size generated from label to here.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001425 int SizeOfCodeGeneratedSince(Label* label) {
1426 return pc_offset() - label->pos();
1427 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001428
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001429 // Mark generator continuation.
1430 void RecordGeneratorContinuation();
Steve Blocka7e24c12009-10-30 11:49:00 +00001431
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001432 // Mark address of a debug break slot.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001433 void RecordDebugBreakSlot(RelocInfo::Mode mode);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001434
Steve Blocka7e24c12009-10-30 11:49:00 +00001435 // Record a comment relocation entry that can be used by a disassembler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001436 // Use --code-comments to enable.
1437 void RecordComment(const char* msg);
1438
1439 // Record a deoptimization reason that can be used by a log or cpu profiler.
1440 // Use --trace-deopt to enable.
Ben Murdochc5610432016-08-08 18:44:38 +01001441 void RecordDeoptReason(const int reason, int raw_position, int id);
Steve Blocka7e24c12009-10-30 11:49:00 +00001442
Ben Murdochb0fe1622011-05-05 13:52:32 +01001443 // Writes a single byte or word of data in the code stream. Used for
1444 // inline tables, e.g., jump-tables.
1445 void db(uint8_t data);
1446 void dd(uint32_t data);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001447 void dq(uint64_t data);
1448 void dp(uintptr_t data) { dd(data); }
1449 void dd(Label* label);
Steve Blocka7e24c12009-10-30 11:49:00 +00001450
Steve Blocka7e24c12009-10-30 11:49:00 +00001451 // Check if there is less than kGap bytes available in the buffer.
1452 // If this is the case, we need to grow the buffer before emitting
1453 // an instruction or relocation information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001454 inline bool buffer_overflow() const {
1455 return pc_ >= reloc_info_writer.pos() - kGap;
1456 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001457
1458 // Get the number of bytes available in the buffer.
1459 inline int available_space() const { return reloc_info_writer.pos() - pc_; }
1460
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001461 static bool IsNop(Address addr);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001462
Ben Murdochda12d292016-06-02 14:46:10 +01001463 AssemblerPositionsRecorder* positions_recorder() {
1464 return &positions_recorder_;
1465 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001466
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001467 int relocation_writer_size() {
1468 return (buffer_ + buffer_size_) - reloc_info_writer.pos();
1469 }
1470
Steve Blocka7e24c12009-10-30 11:49:00 +00001471 // Avoid overflows for displacements etc.
1472 static const int kMaximalBufferSize = 512*MB;
Steve Blocka7e24c12009-10-30 11:49:00 +00001473
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001474 byte byte_at(int pos) { return buffer_[pos]; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001475 void set_byte_at(int pos, byte value) { buffer_[pos] = value; }
1476
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001477 void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1478 ConstantPoolEntry::Access access,
1479 ConstantPoolEntry::Type type) {
1480 // No embedded constant pool support.
1481 UNREACHABLE();
1482 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001483
Steve Blocka7e24c12009-10-30 11:49:00 +00001484 protected:
Steve Blocka7e24c12009-10-30 11:49:00 +00001485 void emit_sse_operand(XMMRegister reg, const Operand& adr);
1486 void emit_sse_operand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001487 void emit_sse_operand(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001488 void emit_sse_operand(XMMRegister dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001489
Steve Block44f0eee2011-05-26 01:26:41 +01001490 byte* addr_at(int pos) { return buffer_ + pos; }
1491
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001492
Ben Murdochb0fe1622011-05-05 13:52:32 +01001493 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00001494 uint32_t long_at(int pos) {
1495 return *reinterpret_cast<uint32_t*>(addr_at(pos));
1496 }
1497 void long_at_put(int pos, uint32_t x) {
1498 *reinterpret_cast<uint32_t*>(addr_at(pos)) = x;
1499 }
1500
1501 // code emission
1502 void GrowBuffer();
1503 inline void emit(uint32_t x);
1504 inline void emit(Handle<Object> handle);
Ben Murdoch257744e2011-11-30 15:57:28 +00001505 inline void emit(uint32_t x,
1506 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001507 TypeFeedbackId id = TypeFeedbackId::None());
1508 inline void emit(Handle<Code> code,
1509 RelocInfo::Mode rmode,
1510 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001511 inline void emit(const Immediate& x);
Ben Murdochda12d292016-06-02 14:46:10 +01001512 inline void emit_b(Immediate x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001513 inline void emit_w(const Immediate& x);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001514 inline void emit_q(uint64_t x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001515
1516 // Emit the code-object-relative offset of the label's position
1517 inline void emit_code_relative_offset(Label* label);
1518
1519 // instruction generation
1520 void emit_arith_b(int op1, int op2, Register dst, int imm8);
1521
1522 // Emit a basic arithmetic instruction (i.e. first byte of the family is 0x81)
1523 // with a given destination expression and an immediate operand. It attempts
1524 // to use the shortest encoding possible.
1525 // sel specifies the /n in the modrm byte (see the Intel PRM).
1526 void emit_arith(int sel, Operand dst, const Immediate& x);
1527
1528 void emit_operand(Register reg, const Operand& adr);
1529
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001530 void emit_label(Label* label);
1531
Steve Blocka7e24c12009-10-30 11:49:00 +00001532 void emit_farith(int b1, int b2, int i);
1533
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001534 // Emit vex prefix
1535 enum SIMDPrefix { kNone = 0x0, k66 = 0x1, kF3 = 0x2, kF2 = 0x3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001536 enum VectorLength { kL128 = 0x0, kL256 = 0x4, kLIG = kL128, kLZ = kL128 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001537 enum VexW { kW0 = 0x0, kW1 = 0x80, kWIG = kW0 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001538 enum LeadingOpcode { k0F = 0x1, k0F38 = 0x2, k0F3A = 0x3 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001539 inline void emit_vex_prefix(XMMRegister v, VectorLength l, SIMDPrefix pp,
1540 LeadingOpcode m, VexW w);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001541 inline void emit_vex_prefix(Register v, VectorLength l, SIMDPrefix pp,
1542 LeadingOpcode m, VexW w);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001543
Steve Blocka7e24c12009-10-30 11:49:00 +00001544 // labels
1545 void print(Label* L);
1546 void bind_to(Label* L, int pos);
Steve Blocka7e24c12009-10-30 11:49:00 +00001547
1548 // displacements
1549 inline Displacement disp_at(Label* L);
1550 inline void disp_at_put(Label* L, Displacement disp);
1551 inline void emit_disp(Label* L, Displacement::Type type);
Ben Murdoch257744e2011-11-30 15:57:28 +00001552 inline void emit_near_disp(Label* L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001553
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001554 // Most BMI instructions are similiar.
1555 void bmi1(byte op, Register reg, Register vreg, const Operand& rm);
1556 void bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
1557 const Operand& rm);
1558
Steve Blocka7e24c12009-10-30 11:49:00 +00001559 // record reloc info for current pc_
1560 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1561
1562 friend class CodePatcher;
1563 friend class EnsureSpace;
1564
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001565 // Internal reference positions, required for (potential) patching in
1566 // GrowBuffer(); contains only those internal references whose labels
1567 // are already bound.
1568 std::deque<int> internal_reference_positions_;
1569
Steve Blocka7e24c12009-10-30 11:49:00 +00001570 // code generation
Steve Blocka7e24c12009-10-30 11:49:00 +00001571 RelocInfoWriter reloc_info_writer;
1572
Ben Murdochda12d292016-06-02 14:46:10 +01001573 AssemblerPositionsRecorder positions_recorder_;
1574 friend class AssemblerPositionsRecorder;
Steve Blocka7e24c12009-10-30 11:49:00 +00001575};
1576
1577
1578// Helper class that ensures that there is enough space for generating
1579// instructions and relocation information. The constructor makes
1580// sure that there is enough space and (in debug mode) the destructor
1581// checks that we did not generate too much.
1582class EnsureSpace BASE_EMBEDDED {
1583 public:
1584 explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001585 if (assembler_->buffer_overflow()) assembler_->GrowBuffer();
Steve Blocka7e24c12009-10-30 11:49:00 +00001586#ifdef DEBUG
1587 space_before_ = assembler_->available_space();
1588#endif
1589 }
1590
1591#ifdef DEBUG
1592 ~EnsureSpace() {
1593 int bytes_generated = space_before_ - assembler_->available_space();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001594 DCHECK(bytes_generated < assembler_->kGap);
Steve Blocka7e24c12009-10-30 11:49:00 +00001595 }
1596#endif
1597
1598 private:
1599 Assembler* assembler_;
1600#ifdef DEBUG
1601 int space_before_;
1602#endif
1603};
1604
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001605} // namespace internal
1606} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001607
1608#endif // V8_IA32_ASSEMBLER_IA32_H_