blob: 5105ff5a4e0185304469ef8c32105c52dfe69013 [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
77#define ALLOCATABLE_DOUBLE_REGISTERS(V) \
78 V(xmm1) \
79 V(xmm2) \
80 V(xmm3) \
81 V(xmm4) \
82 V(xmm5) \
83 V(xmm6) \
84 V(xmm7)
85
Steve Blocka7e24c12009-10-30 11:49:00 +000086// CPU Registers.
87//
88// 1) We would prefer to use an enum, but enum values are assignment-
89// compatible with int, which has caused code-generation bugs.
90//
91// 2) We would prefer to use a class instead of a struct but we don't like
92// the register initialization to depend on the particular initialization
93// order (which appears to be different on OS X, Linux, and Windows for the
94// installed versions of C++ we tried). Using a struct permits C-style
95// "initialization". Also, the Register objects cannot be const as this
96// forces initialization stubs in MSVC, making us dependent on initialization
97// order.
98//
99// 3) By not using an enum, we are possibly preventing the compiler from
100// doing certain constant folds, which may significantly reduce the
101// code generated for some assembly instructions (because they boil down
102// to a few constants). If this is a problem, we could change the code
103// such that we use an enum in optimized mode, and the struct in debug
104// mode. This way we get the compile-time error checking in debug mode
105// and best performance in optimized code.
106//
107struct Register {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108 enum Code {
109#define REGISTER_CODE(R) kCode_##R,
110 GENERAL_REGISTERS(REGISTER_CODE)
111#undef REGISTER_CODE
112 kAfterLast,
113 kCode_no_reg = -1
114 };
Ben Murdochb0fe1622011-05-05 13:52:32 +0100115
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116 static const int kNumRegisters = Code::kAfterLast;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100117
118 static Register from_code(int code) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000119 DCHECK(code >= 0);
120 DCHECK(code < kNumRegisters);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000121 Register r = {code};
Ben Murdochb0fe1622011-05-05 13:52:32 +0100122 return r;
123 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124 const char* ToString();
125 bool IsAllocatable() const;
126 bool is_valid() const { return 0 <= reg_code && reg_code < kNumRegisters; }
127 bool is(Register reg) const { return reg_code == reg.reg_code; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100128 int code() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000130 return reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000131 }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100132 int bit() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000133 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000134 return 1 << reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000135 }
136
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 bool is_byte_register() const { return reg_code <= 3; }
138
Andrei Popescu31002712010-02-23 13:46:05 +0000139 // Unfortunately we can't make this private in a struct.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000141};
142
Steve Block1e0659c2011-05-24 12:43:12 +0100143
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144#define DECLARE_REGISTER(R) const Register R = {Register::kCode_##R};
145GENERAL_REGISTERS(DECLARE_REGISTER)
146#undef DECLARE_REGISTER
147const Register no_reg = {Register::kCode_no_reg};
Steve Blocka7e24c12009-10-30 11:49:00 +0000148
149
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000150struct DoubleRegister {
151 enum Code {
152#define REGISTER_CODE(R) kCode_##R,
153 DOUBLE_REGISTERS(REGISTER_CODE)
154#undef REGISTER_CODE
155 kAfterLast,
156 kCode_no_reg = -1
157 };
Steve Block1e0659c2011-05-24 12:43:12 +0100158
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000159 static const int kMaxNumRegisters = Code::kAfterLast;
Steve Block1e0659c2011-05-24 12:43:12 +0100160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161 static DoubleRegister from_code(int code) {
162 DoubleRegister result = {code};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000163 return result;
164 }
165
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000166 bool IsAllocatable() const;
167 bool is_valid() const { return 0 <= reg_code && reg_code < kMaxNumRegisters; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000168
169 int code() const {
170 DCHECK(is_valid());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 return reg_code;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172 }
173
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000174 bool is(DoubleRegister reg) const { return reg_code == reg.reg_code; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000176 const char* ToString();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100177
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000178 int reg_code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000179};
180
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000181#define DECLARE_REGISTER(R) \
182 const DoubleRegister R = {DoubleRegister::kCode_##R};
183DOUBLE_REGISTERS(DECLARE_REGISTER)
184#undef DECLARE_REGISTER
185const DoubleRegister no_double_reg = {DoubleRegister::kCode_no_reg};
Ben Murdochb0fe1622011-05-05 13:52:32 +0100186
Ben Murdoch097c5b22016-05-18 11:27:45 +0100187typedef DoubleRegister Simd128Register;
188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000189typedef DoubleRegister XMMRegister;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100190
Steve Blocka7e24c12009-10-30 11:49:00 +0000191enum Condition {
192 // any value < 0 is considered no_condition
193 no_condition = -1,
194
195 overflow = 0,
196 no_overflow = 1,
197 below = 2,
198 above_equal = 3,
199 equal = 4,
200 not_equal = 5,
201 below_equal = 6,
202 above = 7,
203 negative = 8,
204 positive = 9,
205 parity_even = 10,
206 parity_odd = 11,
207 less = 12,
208 greater_equal = 13,
209 less_equal = 14,
210 greater = 15,
211
212 // aliases
213 carry = below,
214 not_carry = above_equal,
215 zero = equal,
216 not_zero = not_equal,
217 sign = negative,
218 not_sign = positive
219};
220
221
222// Returns the equivalent of !cc.
223// Negation of the default no_condition (-1) results in a non-default
224// no_condition value (-2). As long as tests for no_condition check
225// for condition < 0, this will work as expected.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100226inline Condition NegateCondition(Condition cc) {
227 return static_cast<Condition>(cc ^ 1);
228}
229
Steve Blocka7e24c12009-10-30 11:49:00 +0000230
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000231// Commute a condition such that {a cond b == b cond' a}.
232inline Condition CommuteCondition(Condition cc) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 switch (cc) {
234 case below:
235 return above;
236 case above:
237 return below;
238 case above_equal:
239 return below_equal;
240 case below_equal:
241 return above_equal;
242 case less:
243 return greater;
244 case greater:
245 return less;
246 case greater_equal:
247 return less_equal;
248 case less_equal:
249 return greater_equal;
250 default:
251 return cc;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000253}
254
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100255
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000256enum RoundingMode {
257 kRoundToNearest = 0x0,
258 kRoundDown = 0x1,
259 kRoundUp = 0x2,
260 kRoundToZero = 0x3
261};
262
263
Steve Blocka7e24c12009-10-30 11:49:00 +0000264// -----------------------------------------------------------------------------
265// Machine instruction Immediates
266
267class Immediate BASE_EMBEDDED {
268 public:
269 inline explicit Immediate(int x);
Steve Blocka7e24c12009-10-30 11:49:00 +0000270 inline explicit Immediate(const ExternalReference& ext);
271 inline explicit Immediate(Handle<Object> handle);
272 inline explicit Immediate(Smi* value);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100273 inline explicit Immediate(Address addr);
Ben Murdochda12d292016-06-02 14:46:10 +0100274 inline explicit Immediate(Address x, RelocInfo::Mode rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000275
276 static Immediate CodeRelativeOffset(Label* label) {
277 return Immediate(label);
278 }
279
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280 bool is_zero() const { return x_ == 0 && RelocInfo::IsNone(rmode_); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 bool is_int8() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282 return -128 <= x_ && x_ < 128 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000283 }
Ben Murdochda12d292016-06-02 14:46:10 +0100284 bool is_uint8() const {
285 return v8::internal::is_uint8(x_) && RelocInfo::IsNone(rmode_);
286 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000287 bool is_int16() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000288 return -32768 <= x_ && x_ < 32768 && RelocInfo::IsNone(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000289 }
Ben Murdochda12d292016-06-02 14:46:10 +0100290 bool is_uint16() const {
291 return v8::internal::is_uint16(x_) && RelocInfo::IsNone(rmode_);
292 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
294 private:
295 inline explicit Immediate(Label* value);
296
297 int x_;
298 RelocInfo::Mode rmode_;
299
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000300 friend class Operand;
Steve Blocka7e24c12009-10-30 11:49:00 +0000301 friend class Assembler;
Steve Block053d10c2011-06-13 19:13:29 +0100302 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000303};
304
305
306// -----------------------------------------------------------------------------
307// Machine instruction Operands
308
309enum ScaleFactor {
310 times_1 = 0,
311 times_2 = 1,
312 times_4 = 2,
313 times_8 = 3,
Leon Clarke4515c472010-02-03 11:58:03 +0000314 times_int_size = times_4,
315 times_half_pointer_size = times_2,
Andrei Popescu402d9372010-02-26 13:31:12 +0000316 times_pointer_size = times_4,
317 times_twice_pointer_size = times_8
Steve Blocka7e24c12009-10-30 11:49:00 +0000318};
319
320
321class Operand BASE_EMBEDDED {
322 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000323 // reg
324 INLINE(explicit Operand(Register reg));
325
Steve Block6ded16b2010-05-10 14:33:55 +0100326 // XMM reg
327 INLINE(explicit Operand(XMMRegister xmm_reg));
328
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 // [disp/r]
330 INLINE(explicit Operand(int32_t disp, RelocInfo::Mode rmode));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331
332 // [disp/r]
333 INLINE(explicit Operand(Immediate imm));
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
335 // [base + disp/r]
336 explicit Operand(Register base, int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000337 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000338
339 // [base + index*scale + disp/r]
340 explicit Operand(Register base,
341 Register index,
342 ScaleFactor scale,
343 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000344 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000345
346 // [index*scale + disp/r]
347 explicit Operand(Register index,
348 ScaleFactor scale,
349 int32_t disp,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000350 RelocInfo::Mode rmode = RelocInfo::NONE32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000351
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000352 static Operand JumpTable(Register index, ScaleFactor scale, Label* table) {
353 return Operand(index, scale, reinterpret_cast<int32_t>(table),
354 RelocInfo::INTERNAL_REFERENCE);
355 }
356
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 static Operand StaticVariable(const ExternalReference& ext) {
358 return Operand(reinterpret_cast<int32_t>(ext.address()),
359 RelocInfo::EXTERNAL_REFERENCE);
360 }
361
362 static Operand StaticArray(Register index,
363 ScaleFactor scale,
364 const ExternalReference& arr) {
365 return Operand(index, scale, reinterpret_cast<int32_t>(arr.address()),
366 RelocInfo::EXTERNAL_REFERENCE);
367 }
368
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000369 static Operand ForCell(Handle<Cell> cell) {
370 AllowDeferredHandleDereference embedding_raw_address;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100371 return Operand(reinterpret_cast<int32_t>(cell.location()),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000372 RelocInfo::CELL);
373 }
374
375 static Operand ForRegisterPlusImmediate(Register base, Immediate imm) {
376 return Operand(base, imm.x_, imm.rmode_);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100377 }
378
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 // Returns true if this Operand is a wrapper for the specified register.
380 bool is_reg(Register reg) const;
381
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100382 // Returns true if this Operand is a wrapper for one register.
383 bool is_reg_only() const;
384
385 // Asserts that this Operand is a wrapper for one register and returns the
386 // register.
387 Register reg() const;
388
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 // Set the ModRM byte without an encoded 'reg' register. The
391 // register is encoded later as part of the emit_operand operation.
392 inline void set_modrm(int mod, Register rm);
393
394 inline void set_sib(ScaleFactor scale, Register index, Register base);
395 inline void set_disp8(int8_t disp);
396 inline void set_dispr(int32_t disp, RelocInfo::Mode rmode);
397
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100398 byte buf_[6];
399 // The number of bytes in buf_.
400 unsigned int len_;
401 // Only valid if len_ > 4.
402 RelocInfo::Mode rmode_;
403
Steve Blocka7e24c12009-10-30 11:49:00 +0000404 friend class Assembler;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100405 friend class MacroAssembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000406};
407
408
409// -----------------------------------------------------------------------------
410// A Displacement describes the 32bit immediate field of an instruction which
411// may be used together with a Label in order to refer to a yet unknown code
412// position. Displacements stored in the instruction stream are used to describe
413// the instruction and to chain a list of instructions using the same Label.
414// A Displacement contains 2 different fields:
415//
416// next field: position of next displacement in the chain (0 = end of list)
417// type field: instruction type
418//
419// A next value of null (0) indicates the end of a chain (note that there can
420// be no displacement at position zero, because there is always at least one
421// instruction byte before the displacement).
422//
423// Displacement _data field layout
424//
425// |31.....2|1......0|
426// [ next | type |
427
428class Displacement BASE_EMBEDDED {
429 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430 enum Type { UNCONDITIONAL_JUMP, CODE_RELATIVE, OTHER, CODE_ABSOLUTE };
Steve Blocka7e24c12009-10-30 11:49:00 +0000431
432 int data() const { return data_; }
433 Type type() const { return TypeField::decode(data_); }
434 void next(Label* L) const {
435 int n = NextField::decode(data_);
436 n > 0 ? L->link_to(n) : L->Unuse();
437 }
438 void link_to(Label* L) { init(L, type()); }
439
440 explicit Displacement(int data) { data_ = data; }
441
442 Displacement(Label* L, Type type) { init(L, type); }
443
444 void print() {
445 PrintF("%s (%x) ", (type() == UNCONDITIONAL_JUMP ? "jmp" : "[other]"),
446 NextField::decode(data_));
447 }
448
449 private:
450 int data_;
451
452 class TypeField: public BitField<Type, 0, 2> {};
453 class NextField: public BitField<int, 2, 32-2> {};
454
455 void init(Label* L, Type type);
456};
457
458
Steve Block44f0eee2011-05-26 01:26:41 +0100459class Assembler : public AssemblerBase {
Steve Blocka7e24c12009-10-30 11:49:00 +0000460 private:
461 // We check before assembling an instruction that there is sufficient
462 // space to write an instruction and its relocation information.
463 // The relocation writer's position must be kGap bytes above the end of
464 // the generated instructions. This leaves enough space for the
465 // longest possible ia32 instruction, 15 bytes, and the longest possible
466 // relocation information encoding, RelocInfoWriter::kMaxLength == 16.
467 // (There is a 15 byte limit on ia32 instruction length that rules out some
468 // otherwise valid instructions.)
469 // This allows for a single, fast space check per instruction.
470 static const int kGap = 32;
471
472 public:
473 // Create an assembler. Instructions and relocation information are emitted
474 // into a buffer, with the instructions starting from the beginning and the
475 // relocation information starting from the end of the buffer. See CodeDesc
476 // for a detailed comment on the layout (globals.h).
477 //
478 // If the provided buffer is NULL, the assembler allocates and grows its own
479 // buffer, and buffer_size determines the initial buffer size. The buffer is
480 // owned by the assembler and deallocated upon destruction of the assembler.
481 //
482 // If the provided buffer is not NULL, the assembler uses the provided buffer
483 // for code generation and assumes its size to be buffer_size. If the buffer
484 // is too small, a fatal error occurs. No deallocation of the buffer is done
485 // upon destruction of the assembler.
Ben Murdoch8b112d22011-06-08 16:22:53 +0100486 // TODO(vitalyr): the assembler does not need an isolate.
487 Assembler(Isolate* isolate, void* buffer, int buffer_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000488 virtual ~Assembler() { }
Steve Block44f0eee2011-05-26 01:26:41 +0100489
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 // GetCode emits any pending (non-emitted) code and fills the descriptor
491 // desc. GetCode() is idempotent; it returns the same result if no other
492 // Assembler functions are invoked in between GetCode() calls.
493 void GetCode(CodeDesc* desc);
494
495 // Read/Modify the code target in the branch/call instruction at pc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000496 inline static Address target_address_at(Address pc, Address constant_pool);
497 inline static void set_target_address_at(
498 Isolate* isolate, Address pc, Address constant_pool, Address target,
499 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000500 static inline Address target_address_at(Address pc, Code* code) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501 Address constant_pool = code ? code->constant_pool() : NULL;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000502 return target_address_at(pc, constant_pool);
503 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000504 static inline void set_target_address_at(
505 Isolate* isolate, Address pc, Code* code, Address target,
506 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED) {
507 Address constant_pool = code ? code->constant_pool() : NULL;
508 set_target_address_at(isolate, pc, constant_pool, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000509 }
510
511 // Return the code target address at a call site from the return address
512 // of that call in the instruction stream.
513 inline static Address target_address_from_return_address(Address pc);
514
Steve Blockd0582a62009-12-15 09:54:21 +0000515 // This sets the branch destination (which is in the instruction on x86).
516 // This is for calls and branches within generated code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100517 inline static void deserialization_set_special_target_at(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000518 Isolate* isolate, Address instruction_payload, Code* code,
519 Address target) {
520 set_target_address_at(isolate, instruction_payload, code, target);
Steve Blockd0582a62009-12-15 09:54:21 +0000521 }
522
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000523 // This sets the internal reference at the pc.
524 inline static void deserialization_set_target_internal_reference_at(
525 Isolate* isolate, Address pc, Address target,
526 RelocInfo::Mode mode = RelocInfo::INTERNAL_REFERENCE);
527
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100528 static const int kSpecialTargetSize = kPointerSize;
Steve Blockd0582a62009-12-15 09:54:21 +0000529
Steve Blocka7e24c12009-10-30 11:49:00 +0000530 // Distance between the address of the code target in the call instruction
531 // and the return address
532 static const int kCallTargetAddressOffset = kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000533
534 static const int kCallInstructionLength = 5;
535
536 // The debug break slot must be able to contain a call instruction.
537 static const int kDebugBreakSlotLength = kCallInstructionLength;
Steve Blocka7e24c12009-10-30 11:49:00 +0000538
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100539 // Distance between start of patched debug break slot and the emitted address
540 // to jump to.
541 static const int kPatchDebugBreakSlotAddressOffset = 1; // JMP imm32.
542
Ben Murdochb0fe1622011-05-05 13:52:32 +0100543 // One byte opcode for test al, 0xXX.
544 static const byte kTestAlByte = 0xA8;
545 // One byte opcode for nop.
546 static const byte kNopByte = 0x90;
547
548 // One byte opcode for a short unconditional jump.
549 static const byte kJmpShortOpcode = 0xEB;
550 // One byte prefix for a short conditional jump.
551 static const byte kJccShortPrefix = 0x70;
552 static const byte kJncShortOpcode = kJccShortPrefix | not_carry;
553 static const byte kJcShortOpcode = kJccShortPrefix | carry;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000554 static const byte kJnzShortOpcode = kJccShortPrefix | not_zero;
555 static const byte kJzShortOpcode = kJccShortPrefix | zero;
556
Ben Murdochb0fe1622011-05-05 13:52:32 +0100557
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 // ---------------------------------------------------------------------------
559 // Code generation
560 //
561 // - function names correspond one-to-one to ia32 instruction mnemonics
562 // - unless specified otherwise, instructions operate on 32bit operands
563 // - instructions on 8bit (byte) operands/registers have a trailing '_b'
564 // - instructions on 16bit (word) operands/registers have a trailing '_w'
565 // - naming conflicts with C++ keywords are resolved via a trailing '_'
566
567 // NOTE ON INTERFACE: Currently, the interface is not very consistent
568 // in the sense that some operations (e.g. mov()) can be called in more
569 // the one way to generate the same instruction: The Register argument
570 // can in some cases be replaced with an Operand(Register) argument.
571 // This should be cleaned up and made more orthogonal. The questions
572 // is: should we always use Operands instead of Registers where an
573 // Operand is possible, or should we have a Register (overloaded) form
574 // instead? We must be careful to make sure that the selected instruction
575 // is obvious from the parameters to avoid hard-to-find code generation
576 // bugs.
577
578 // Insert the smallest number of nop instructions
579 // possible to align the pc offset to a multiple
580 // of m. m must be a power of 2.
581 void Align(int m);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000582 // Insert the smallest number of zero bytes possible to align the pc offset
583 // to a mulitple of m. m must be a power of 2 (>= 2).
584 void DataAlign(int m);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100585 void Nop(int bytes = 1);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100586 // Aligns code to something that's optimal for a jump target for the platform.
587 void CodeTargetAlign();
Steve Blocka7e24c12009-10-30 11:49:00 +0000588
589 // Stack
590 void pushad();
591 void popad();
592
593 void pushfd();
594 void popfd();
595
596 void push(const Immediate& x);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100597 void push_imm32(int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000598 void push(Register src);
599 void push(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000600
601 void pop(Register dst);
602 void pop(const Operand& dst);
603
604 void enter(const Immediate& size);
605 void leave();
606
607 // Moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100608 void mov_b(Register dst, Register src) { mov_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000609 void mov_b(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100610 void mov_b(Register dst, int8_t imm8) { mov_b(Operand(dst), imm8); }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400611 void mov_b(const Operand& dst, int8_t src) { mov_b(dst, Immediate(src)); }
612 void mov_b(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000613 void mov_b(const Operand& dst, Register src);
614
615 void mov_w(Register dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400616 void mov_w(const Operand& dst, int16_t src) { mov_w(dst, Immediate(src)); }
617 void mov_w(const Operand& dst, const Immediate& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000618 void mov_w(const Operand& dst, Register src);
619
620 void mov(Register dst, int32_t imm32);
621 void mov(Register dst, const Immediate& x);
622 void mov(Register dst, Handle<Object> handle);
623 void mov(Register dst, const Operand& src);
624 void mov(Register dst, Register src);
625 void mov(const Operand& dst, const Immediate& x);
626 void mov(const Operand& dst, Handle<Object> handle);
627 void mov(const Operand& dst, Register src);
628
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100629 void movsx_b(Register dst, Register src) { movsx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000630 void movsx_b(Register dst, const Operand& src);
631
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100632 void movsx_w(Register dst, Register src) { movsx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000633 void movsx_w(Register dst, const Operand& src);
634
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100635 void movzx_b(Register dst, Register src) { movzx_b(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000636 void movzx_b(Register dst, const Operand& src);
637
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100638 void movzx_w(Register dst, Register src) { movzx_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000639 void movzx_w(Register dst, const Operand& src);
640
641 // Conditional moves
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100642 void cmov(Condition cc, Register dst, Register src) {
643 cmov(cc, dst, Operand(src));
644 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000645 void cmov(Condition cc, Register dst, const Operand& src);
646
Steve Block6ded16b2010-05-10 14:33:55 +0100647 // Flag management.
648 void cld();
649
Leon Clarkee46be812010-01-19 14:06:41 +0000650 // Repetitive string instructions.
651 void rep_movs();
Steve Block6ded16b2010-05-10 14:33:55 +0100652 void rep_stos();
Leon Clarkef7060e22010-06-03 12:02:55 +0100653 void stos();
Leon Clarkee46be812010-01-19 14:06:41 +0000654
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000655 // Exchange
Steve Blocka7e24c12009-10-30 11:49:00 +0000656 void xchg(Register dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000657 void xchg(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000658
659 // Arithmetics
660 void adc(Register dst, int32_t imm32);
661 void adc(Register dst, const Operand& src);
662
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100663 void add(Register dst, Register src) { add(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000664 void add(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100665 void add(const Operand& dst, Register src);
666 void add(Register dst, const Immediate& imm) { add(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000667 void add(const Operand& dst, const Immediate& x);
668
669 void and_(Register dst, int32_t imm32);
Steve Block59151502010-09-22 15:07:15 +0100670 void and_(Register dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100671 void and_(Register dst, Register src) { and_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000672 void and_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100673 void and_(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000674 void and_(const Operand& dst, const Immediate& x);
675
Ben Murdochda12d292016-06-02 14:46:10 +0100676 void cmpb(Register reg, Immediate imm8) { cmpb(Operand(reg), imm8); }
677 void cmpb(const Operand& op, Immediate imm8);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100678 void cmpb(Register reg, const Operand& op);
679 void cmpb(const Operand& op, Register reg);
Ben Murdochda12d292016-06-02 14:46:10 +0100680 void cmpb(Register dst, Register src) { cmpb(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000681 void cmpb_al(const Operand& op);
682 void cmpw_ax(const Operand& op);
Ben Murdochda12d292016-06-02 14:46:10 +0100683 void cmpw(const Operand& dst, Immediate src);
684 void cmpw(Register dst, Immediate src) { cmpw(Operand(dst), src); }
685 void cmpw(Register dst, const Operand& src);
686 void cmpw(Register dst, Register src) { cmpw(Operand(dst), src); }
687 void cmpw(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000688 void cmp(Register reg, int32_t imm32);
689 void cmp(Register reg, Handle<Object> handle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100690 void cmp(Register reg0, Register reg1) { cmp(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000691 void cmp(Register reg, const Operand& op);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100692 void cmp(Register reg, const Immediate& imm) { cmp(Operand(reg), imm); }
Ben Murdoch097c5b22016-05-18 11:27:45 +0100693 void cmp(const Operand& op, Register reg);
Steve Blocka7e24c12009-10-30 11:49:00 +0000694 void cmp(const Operand& op, const Immediate& imm);
695 void cmp(const Operand& op, Handle<Object> handle);
696
697 void dec_b(Register dst);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100698 void dec_b(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000699
700 void dec(Register dst);
701 void dec(const Operand& dst);
702
703 void cdq();
704
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000705 void idiv(Register src) { idiv(Operand(src)); }
706 void idiv(const Operand& src);
707 void div(Register src) { div(Operand(src)); }
708 void div(const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000709
710 // Signed multiply instructions.
711 void imul(Register src); // edx:eax = eax * src.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100712 void imul(Register dst, Register src) { imul(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000713 void imul(Register dst, const Operand& src); // dst = dst * src.
714 void imul(Register dst, Register src, int32_t imm32); // dst = src * imm32.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000715 void imul(Register dst, const Operand& src, int32_t imm32);
Steve Blocka7e24c12009-10-30 11:49:00 +0000716
717 void inc(Register dst);
718 void inc(const Operand& dst);
719
720 void lea(Register dst, const Operand& src);
721
722 // Unsigned multiply instruction.
723 void mul(Register src); // edx:eax = eax * reg.
724
725 void neg(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000726 void neg(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000727
728 void not_(Register dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000729 void not_(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000730
731 void or_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100732 void or_(Register dst, Register src) { or_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000733 void or_(Register dst, const Operand& src);
734 void or_(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100735 void or_(Register dst, const Immediate& imm) { or_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000736 void or_(const Operand& dst, const Immediate& x);
737
738 void rcl(Register dst, uint8_t imm8);
Iain Merrick75681382010-08-19 15:07:18 +0100739 void rcr(Register dst, uint8_t imm8);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400740
741 void ror(Register dst, uint8_t imm8) { ror(Operand(dst), imm8); }
742 void ror(const Operand& dst, uint8_t imm8);
743 void ror_cl(Register dst) { ror_cl(Operand(dst)); }
744 void ror_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000745
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000746 void sar(Register dst, uint8_t imm8) { sar(Operand(dst), imm8); }
747 void sar(const Operand& dst, uint8_t imm8);
748 void sar_cl(Register dst) { sar_cl(Operand(dst)); }
749 void sar_cl(const Operand& dst);
Steve Blocka7e24c12009-10-30 11:49:00 +0000750
751 void sbb(Register dst, const Operand& src);
752
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000753 void shl(Register dst, uint8_t imm8) { shl(Operand(dst), imm8); }
754 void shl(const Operand& dst, uint8_t imm8);
755 void shl_cl(Register dst) { shl_cl(Operand(dst)); }
756 void shl_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100757 void shld(Register dst, Register src, uint8_t shift);
758 void shld_cl(Register dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000759
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000760 void shr(Register dst, uint8_t imm8) { shr(Operand(dst), imm8); }
761 void shr(const Operand& dst, uint8_t imm8);
762 void shr_cl(Register dst) { shr_cl(Operand(dst)); }
763 void shr_cl(const Operand& dst);
Ben Murdochda12d292016-06-02 14:46:10 +0100764 void shrd(Register dst, Register src, uint8_t shift);
765 void shrd_cl(Register dst, Register src) { shrd_cl(Operand(dst), src); }
766 void shrd_cl(const Operand& dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000767
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100768 void sub(Register dst, const Immediate& imm) { sub(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000769 void sub(const Operand& dst, const Immediate& x);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100770 void sub(Register dst, Register src) { sub(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000771 void sub(Register dst, const Operand& src);
772 void sub(const Operand& dst, Register src);
773
774 void test(Register reg, const Immediate& imm);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100775 void test(Register reg0, Register reg1) { test(reg0, Operand(reg1)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000776 void test(Register reg, const Operand& op);
777 void test(const Operand& op, const Immediate& imm);
Ben Murdochda12d292016-06-02 14:46:10 +0100778 void test(const Operand& op, Register reg) { test(reg, op); }
779 void test_b(Register reg, const Operand& op);
780 void test_b(Register reg, Immediate imm8);
781 void test_b(const Operand& op, Immediate imm8);
782 void test_b(const Operand& op, Register reg) { test_b(reg, op); }
783 void test_b(Register dst, Register src) { test_b(dst, Operand(src)); }
784 void test_w(Register reg, const Operand& op);
785 void test_w(Register reg, Immediate imm16);
786 void test_w(const Operand& op, Immediate imm16);
787 void test_w(const Operand& op, Register reg) { test_w(reg, op); }
788 void test_w(Register dst, Register src) { test_w(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000789
790 void xor_(Register dst, int32_t imm32);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100791 void xor_(Register dst, Register src) { xor_(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000792 void xor_(Register dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100793 void xor_(const Operand& dst, Register src);
794 void xor_(Register dst, const Immediate& imm) { xor_(Operand(dst), imm); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000795 void xor_(const Operand& dst, const Immediate& x);
796
797 // Bit operations.
798 void bt(const Operand& dst, Register src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100799 void bts(Register dst, Register src) { bts(Operand(dst), src); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000800 void bts(const Operand& dst, Register src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000801 void bsr(Register dst, Register src) { bsr(dst, Operand(src)); }
802 void bsr(Register dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000803 void bsf(Register dst, Register src) { bsf(dst, Operand(src)); }
804 void bsf(Register dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000805
806 // Miscellaneous
807 void hlt();
808 void int3();
809 void nop();
Steve Blocka7e24c12009-10-30 11:49:00 +0000810 void ret(int imm16);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000811 void ud2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000812
813 // Label operations & relative jumps (PPUM Appendix D)
814 //
815 // Takes a branch opcode (cc) and a label (L) and generates
816 // either a backward branch or a forward branch and links it
817 // to the label fixup chain. Usage:
818 //
819 // Label L; // unbound label
820 // j(cc, &L); // forward branch to unbound label
821 // bind(&L); // bind label to the current pc
822 // j(cc, &L); // backward branch to bound label
823 // bind(&L); // illegal: a label may be bound only once
824 //
825 // Note: The same Label can be used for forward and backward branches
826 // but it may be bound only once.
827
828 void bind(Label* L); // binds an unbound label L to the current code position
829
830 // Calls
831 void call(Label* L);
832 void call(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch257744e2011-11-30 15:57:28 +0000833 int CallSize(const Operand& adr);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100834 void call(Register reg) { call(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000835 void call(const Operand& adr);
Ben Murdoch257744e2011-11-30 15:57:28 +0000836 int CallSize(Handle<Code> code, RelocInfo::Mode mode);
837 void call(Handle<Code> code,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000838 RelocInfo::Mode rmode,
839 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +0000840
841 // Jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000842 // unconditional jump to L
843 void jmp(Label* L, Label::Distance distance = Label::kFar);
Steve Blocka7e24c12009-10-30 11:49:00 +0000844 void jmp(byte* entry, RelocInfo::Mode rmode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100845 void jmp(Register reg) { jmp(Operand(reg)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000846 void jmp(const Operand& adr);
847 void jmp(Handle<Code> code, RelocInfo::Mode rmode);
848
849 // Conditional jumps
Ben Murdoch257744e2011-11-30 15:57:28 +0000850 void j(Condition cc,
851 Label* L,
852 Label::Distance distance = Label::kFar);
853 void j(Condition cc, byte* entry, RelocInfo::Mode rmode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000854 void j(Condition cc, Handle<Code> code,
855 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100856
Steve Blocka7e24c12009-10-30 11:49:00 +0000857 // Floating-point operations
858 void fld(int i);
Andrei Popescu402d9372010-02-26 13:31:12 +0000859 void fstp(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000860
861 void fld1();
862 void fldz();
Andrei Popescu402d9372010-02-26 13:31:12 +0000863 void fldpi();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100864 void fldln2();
Steve Blocka7e24c12009-10-30 11:49:00 +0000865
866 void fld_s(const Operand& adr);
867 void fld_d(const Operand& adr);
868
869 void fstp_s(const Operand& adr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870 void fst_s(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000871 void fstp_d(const Operand& adr);
Andrei Popescu402d9372010-02-26 13:31:12 +0000872 void fst_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000873
874 void fild_s(const Operand& adr);
875 void fild_d(const Operand& adr);
876
877 void fist_s(const Operand& adr);
878
879 void fistp_s(const Operand& adr);
880 void fistp_d(const Operand& adr);
881
Steve Block6ded16b2010-05-10 14:33:55 +0100882 // The fisttp instructions require SSE3.
Steve Blocka7e24c12009-10-30 11:49:00 +0000883 void fisttp_s(const Operand& adr);
Leon Clarkee46be812010-01-19 14:06:41 +0000884 void fisttp_d(const Operand& adr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000885
886 void fabs();
887 void fchs();
888 void fcos();
889 void fsin();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100890 void fptan();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100891 void fyl2x();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100892 void f2xm1();
893 void fscale();
894 void fninit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000895
896 void fadd(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000897 void fadd_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000898 void fsub(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000899 void fsub_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000900 void fmul(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000901 void fmul_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000902 void fdiv(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000903 void fdiv_i(int i);
Steve Blocka7e24c12009-10-30 11:49:00 +0000904
905 void fisub_s(const Operand& adr);
906
907 void faddp(int i = 1);
908 void fsubp(int i = 1);
909 void fsubrp(int i = 1);
910 void fmulp(int i = 1);
911 void fdivp(int i = 1);
912 void fprem();
913 void fprem1();
914
915 void fxch(int i = 1);
916 void fincstp();
917 void ffree(int i = 0);
918
919 void ftst();
920 void fucomp(int i);
921 void fucompp();
Steve Block3ce2e202009-11-05 08:53:23 +0000922 void fucomi(int i);
923 void fucomip();
Steve Blocka7e24c12009-10-30 11:49:00 +0000924 void fcompp();
925 void fnstsw_ax();
926 void fwait();
927 void fnclex();
928
929 void frndint();
930
931 void sahf();
932 void setcc(Condition cc, Register reg);
933
934 void cpuid();
935
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000936 // SSE instructions
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400937 void addss(XMMRegister dst, XMMRegister src) { addss(dst, Operand(src)); }
938 void addss(XMMRegister dst, const Operand& src);
939 void subss(XMMRegister dst, XMMRegister src) { subss(dst, Operand(src)); }
940 void subss(XMMRegister dst, const Operand& src);
941 void mulss(XMMRegister dst, XMMRegister src) { mulss(dst, Operand(src)); }
942 void mulss(XMMRegister dst, const Operand& src);
943 void divss(XMMRegister dst, XMMRegister src) { divss(dst, Operand(src)); }
944 void divss(XMMRegister dst, const Operand& src);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000945 void sqrtss(XMMRegister dst, XMMRegister src) { sqrtss(dst, Operand(src)); }
946 void sqrtss(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400947
948 void ucomiss(XMMRegister dst, XMMRegister src) { ucomiss(dst, Operand(src)); }
949 void ucomiss(XMMRegister dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000950 void movaps(XMMRegister dst, XMMRegister src);
951 void shufps(XMMRegister dst, XMMRegister src, byte imm8);
952
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000953 void maxss(XMMRegister dst, XMMRegister src) { maxss(dst, Operand(src)); }
954 void maxss(XMMRegister dst, const Operand& src);
955 void minss(XMMRegister dst, XMMRegister src) { minss(dst, Operand(src)); }
956 void minss(XMMRegister dst, const Operand& src);
957
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958 void andps(XMMRegister dst, const Operand& src);
959 void andps(XMMRegister dst, XMMRegister src) { andps(dst, Operand(src)); }
960 void xorps(XMMRegister dst, const Operand& src);
961 void xorps(XMMRegister dst, XMMRegister src) { xorps(dst, Operand(src)); }
962 void orps(XMMRegister dst, const Operand& src);
963 void orps(XMMRegister dst, XMMRegister src) { orps(dst, Operand(src)); }
964
965 void addps(XMMRegister dst, const Operand& src);
966 void addps(XMMRegister dst, XMMRegister src) { addps(dst, Operand(src)); }
967 void subps(XMMRegister dst, const Operand& src);
968 void subps(XMMRegister dst, XMMRegister src) { subps(dst, Operand(src)); }
969 void mulps(XMMRegister dst, const Operand& src);
970 void mulps(XMMRegister dst, XMMRegister src) { mulps(dst, Operand(src)); }
971 void divps(XMMRegister dst, const Operand& src);
972 void divps(XMMRegister dst, XMMRegister src) { divps(dst, Operand(src)); }
973
Steve Blocka7e24c12009-10-30 11:49:00 +0000974 // SSE2 instructions
975 void cvttss2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 void cvttss2si(Register dst, XMMRegister src) {
977 cvttss2si(dst, Operand(src));
978 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000979 void cvttsd2si(Register dst, const Operand& src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000980 void cvttsd2si(Register dst, XMMRegister src) {
981 cvttsd2si(dst, Operand(src));
982 }
983 void cvtsd2si(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000984
Ben Murdoch097c5b22016-05-18 11:27:45 +0100985 void cvtsi2ss(XMMRegister dst, Register src) { cvtsi2ss(dst, Operand(src)); }
986 void cvtsi2ss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100987 void cvtsi2sd(XMMRegister dst, Register src) { cvtsi2sd(dst, Operand(src)); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000988 void cvtsi2sd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400989 void cvtss2sd(XMMRegister dst, const Operand& src);
990 void cvtss2sd(XMMRegister dst, XMMRegister src) {
991 cvtss2sd(dst, Operand(src));
992 }
993 void cvtsd2ss(XMMRegister dst, const Operand& src);
994 void cvtsd2ss(XMMRegister dst, XMMRegister src) {
995 cvtsd2ss(dst, Operand(src));
996 }
997 void addsd(XMMRegister dst, XMMRegister src) { addsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000998 void addsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400999 void subsd(XMMRegister dst, XMMRegister src) { subsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001000 void subsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001001 void mulsd(XMMRegister dst, XMMRegister src) { mulsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001002 void mulsd(XMMRegister dst, const Operand& src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001003 void divsd(XMMRegister dst, XMMRegister src) { divsd(dst, Operand(src)); }
1004 void divsd(XMMRegister dst, const Operand& src);
Leon Clarkee46be812010-01-19 14:06:41 +00001005 void xorpd(XMMRegister dst, XMMRegister src);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001006 void sqrtsd(XMMRegister dst, XMMRegister src) { sqrtsd(dst, Operand(src)); }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001007 void sqrtsd(XMMRegister dst, const Operand& src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001008
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001009 void andpd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001010 void orpd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001011
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001012 void ucomisd(XMMRegister dst, XMMRegister src) { ucomisd(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001013 void ucomisd(XMMRegister dst, const Operand& src);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001014
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001015 void roundss(XMMRegister dst, XMMRegister src, RoundingMode mode);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001016 void roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode);
1017
Steve Block6ded16b2010-05-10 14:33:55 +01001018 void movmskpd(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001019 void movmskps(Register dst, XMMRegister src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001020
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001021 void cmpltsd(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001022 void pcmpeqd(XMMRegister dst, XMMRegister src);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001023
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001024 void punpckldq(XMMRegister dst, XMMRegister src);
1025 void punpckhdq(XMMRegister dst, XMMRegister src);
1026
1027 void maxsd(XMMRegister dst, XMMRegister src) { maxsd(dst, Operand(src)); }
1028 void maxsd(XMMRegister dst, const Operand& src);
1029 void minsd(XMMRegister dst, XMMRegister src) { minsd(dst, Operand(src)); }
1030 void minsd(XMMRegister dst, const Operand& src);
1031
Leon Clarkee46be812010-01-19 14:06:41 +00001032 void movdqa(XMMRegister dst, const Operand& src);
1033 void movdqa(const Operand& dst, XMMRegister src);
1034 void movdqu(XMMRegister dst, const Operand& src);
1035 void movdqu(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001036 void movdq(bool aligned, XMMRegister dst, const Operand& src) {
1037 if (aligned) {
1038 movdqa(dst, src);
1039 } else {
1040 movdqu(dst, src);
1041 }
1042 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001043
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001044 void movd(XMMRegister dst, Register src) { movd(dst, Operand(src)); }
Steve Block6ded16b2010-05-10 14:33:55 +01001045 void movd(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001046 void movd(Register dst, XMMRegister src) { movd(Operand(dst), src); }
1047 void movd(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001048 void movsd(XMMRegister dst, XMMRegister src) { movsd(dst, Operand(src)); }
1049 void movsd(XMMRegister dst, const Operand& src);
1050 void movsd(const Operand& dst, XMMRegister src);
1051
Steve Block6ded16b2010-05-10 14:33:55 +01001052
Steve Block44f0eee2011-05-26 01:26:41 +01001053 void movss(XMMRegister dst, const Operand& src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001054 void movss(const Operand& dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001055 void movss(XMMRegister dst, XMMRegister src) { movss(dst, Operand(src)); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001056 void extractps(Register dst, XMMRegister src, byte imm8);
Steve Block44f0eee2011-05-26 01:26:41 +01001057
Ben Murdochb0fe1622011-05-05 13:52:32 +01001058 void pand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001059 void pxor(XMMRegister dst, XMMRegister src);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001060 void por(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001061 void ptest(XMMRegister dst, XMMRegister src);
1062
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001063 void pslld(XMMRegister reg, int8_t shift);
1064 void psrld(XMMRegister reg, int8_t shift);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001065 void psllq(XMMRegister reg, int8_t shift);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001066 void psllq(XMMRegister dst, XMMRegister src);
1067 void psrlq(XMMRegister reg, int8_t shift);
1068 void psrlq(XMMRegister dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001069 void pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001070 void pextrd(Register dst, XMMRegister src, int8_t offset) {
1071 pextrd(Operand(dst), src, offset);
1072 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001073 void pextrd(const Operand& dst, XMMRegister src, int8_t offset);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001074 void pinsrd(XMMRegister dst, Register src, int8_t offset) {
1075 pinsrd(dst, Operand(src), offset);
1076 }
Steve Block1e0659c2011-05-24 12:43:12 +01001077 void pinsrd(XMMRegister dst, const Operand& src, int8_t offset);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001078
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001079 // AVX instructions
1080 void vfmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1081 vfmadd132sd(dst, src1, Operand(src2));
1082 }
1083 void vfmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1084 vfmadd213sd(dst, src1, Operand(src2));
1085 }
1086 void vfmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1087 vfmadd231sd(dst, src1, Operand(src2));
1088 }
1089 void vfmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1090 vfmasd(0x99, dst, src1, src2);
1091 }
1092 void vfmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1093 vfmasd(0xa9, dst, src1, src2);
1094 }
1095 void vfmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1096 vfmasd(0xb9, dst, src1, src2);
1097 }
1098 void vfmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1099 vfmsub132sd(dst, src1, Operand(src2));
1100 }
1101 void vfmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1102 vfmsub213sd(dst, src1, Operand(src2));
1103 }
1104 void vfmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1105 vfmsub231sd(dst, src1, Operand(src2));
1106 }
1107 void vfmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1108 vfmasd(0x9b, dst, src1, src2);
1109 }
1110 void vfmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1111 vfmasd(0xab, dst, src1, src2);
1112 }
1113 void vfmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1114 vfmasd(0xbb, dst, src1, src2);
1115 }
1116 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1117 vfnmadd132sd(dst, src1, Operand(src2));
1118 }
1119 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1120 vfnmadd213sd(dst, src1, Operand(src2));
1121 }
1122 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1123 vfnmadd231sd(dst, src1, Operand(src2));
1124 }
1125 void vfnmadd132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1126 vfmasd(0x9d, dst, src1, src2);
1127 }
1128 void vfnmadd213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1129 vfmasd(0xad, dst, src1, src2);
1130 }
1131 void vfnmadd231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1132 vfmasd(0xbd, dst, src1, src2);
1133 }
1134 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1135 vfnmsub132sd(dst, src1, Operand(src2));
1136 }
1137 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1138 vfnmsub213sd(dst, src1, Operand(src2));
1139 }
1140 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1141 vfnmsub231sd(dst, src1, Operand(src2));
1142 }
1143 void vfnmsub132sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1144 vfmasd(0x9f, dst, src1, src2);
1145 }
1146 void vfnmsub213sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1147 vfmasd(0xaf, dst, src1, src2);
1148 }
1149 void vfnmsub231sd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1150 vfmasd(0xbf, dst, src1, src2);
1151 }
1152 void vfmasd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1153
1154 void vfmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1155 vfmadd132ss(dst, src1, Operand(src2));
1156 }
1157 void vfmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1158 vfmadd213ss(dst, src1, Operand(src2));
1159 }
1160 void vfmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1161 vfmadd231ss(dst, src1, Operand(src2));
1162 }
1163 void vfmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1164 vfmass(0x99, dst, src1, src2);
1165 }
1166 void vfmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1167 vfmass(0xa9, dst, src1, src2);
1168 }
1169 void vfmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1170 vfmass(0xb9, dst, src1, src2);
1171 }
1172 void vfmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1173 vfmsub132ss(dst, src1, Operand(src2));
1174 }
1175 void vfmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1176 vfmsub213ss(dst, src1, Operand(src2));
1177 }
1178 void vfmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1179 vfmsub231ss(dst, src1, Operand(src2));
1180 }
1181 void vfmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1182 vfmass(0x9b, dst, src1, src2);
1183 }
1184 void vfmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1185 vfmass(0xab, dst, src1, src2);
1186 }
1187 void vfmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1188 vfmass(0xbb, dst, src1, src2);
1189 }
1190 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1191 vfnmadd132ss(dst, src1, Operand(src2));
1192 }
1193 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1194 vfnmadd213ss(dst, src1, Operand(src2));
1195 }
1196 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1197 vfnmadd231ss(dst, src1, Operand(src2));
1198 }
1199 void vfnmadd132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1200 vfmass(0x9d, dst, src1, src2);
1201 }
1202 void vfnmadd213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1203 vfmass(0xad, dst, src1, src2);
1204 }
1205 void vfnmadd231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1206 vfmass(0xbd, dst, src1, src2);
1207 }
1208 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1209 vfnmsub132ss(dst, src1, Operand(src2));
1210 }
1211 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1212 vfnmsub213ss(dst, src1, Operand(src2));
1213 }
1214 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1215 vfnmsub231ss(dst, src1, Operand(src2));
1216 }
1217 void vfnmsub132ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1218 vfmass(0x9f, dst, src1, src2);
1219 }
1220 void vfnmsub213ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1221 vfmass(0xaf, dst, src1, src2);
1222 }
1223 void vfnmsub231ss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1224 vfmass(0xbf, dst, src1, src2);
1225 }
1226 void vfmass(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1227
1228 void vaddsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1229 vaddsd(dst, src1, Operand(src2));
1230 }
1231 void vaddsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1232 vsd(0x58, dst, src1, src2);
1233 }
1234 void vsubsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1235 vsubsd(dst, src1, Operand(src2));
1236 }
1237 void vsubsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1238 vsd(0x5c, dst, src1, src2);
1239 }
1240 void vmulsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1241 vmulsd(dst, src1, Operand(src2));
1242 }
1243 void vmulsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1244 vsd(0x59, dst, src1, src2);
1245 }
1246 void vdivsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1247 vdivsd(dst, src1, Operand(src2));
1248 }
1249 void vdivsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1250 vsd(0x5e, dst, src1, src2);
1251 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001252 void vmaxsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1253 vmaxsd(dst, src1, Operand(src2));
1254 }
1255 void vmaxsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1256 vsd(0x5f, dst, src1, src2);
1257 }
1258 void vminsd(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1259 vminsd(dst, src1, Operand(src2));
1260 }
1261 void vminsd(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1262 vsd(0x5d, dst, src1, src2);
1263 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001264 void vsd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1265
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001266 void vaddss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1267 vaddss(dst, src1, Operand(src2));
1268 }
1269 void vaddss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1270 vss(0x58, dst, src1, src2);
1271 }
1272 void vsubss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1273 vsubss(dst, src1, Operand(src2));
1274 }
1275 void vsubss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1276 vss(0x5c, dst, src1, src2);
1277 }
1278 void vmulss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1279 vmulss(dst, src1, Operand(src2));
1280 }
1281 void vmulss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1282 vss(0x59, dst, src1, src2);
1283 }
1284 void vdivss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1285 vdivss(dst, src1, Operand(src2));
1286 }
1287 void vdivss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1288 vss(0x5e, dst, src1, src2);
1289 }
1290 void vmaxss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1291 vmaxss(dst, src1, Operand(src2));
1292 }
1293 void vmaxss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1294 vss(0x5f, dst, src1, src2);
1295 }
1296 void vminss(XMMRegister dst, XMMRegister src1, XMMRegister src2) {
1297 vminss(dst, src1, Operand(src2));
1298 }
1299 void vminss(XMMRegister dst, XMMRegister src1, const Operand& src2) {
1300 vss(0x5d, dst, src1, src2);
1301 }
1302 void vss(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1303
1304 // BMI instruction
1305 void andn(Register dst, Register src1, Register src2) {
1306 andn(dst, src1, Operand(src2));
1307 }
1308 void andn(Register dst, Register src1, const Operand& src2) {
1309 bmi1(0xf2, dst, src1, src2);
1310 }
1311 void bextr(Register dst, Register src1, Register src2) {
1312 bextr(dst, Operand(src1), src2);
1313 }
1314 void bextr(Register dst, const Operand& src1, Register src2) {
1315 bmi1(0xf7, dst, src2, src1);
1316 }
1317 void blsi(Register dst, Register src) { blsi(dst, Operand(src)); }
1318 void blsi(Register dst, const Operand& src) {
1319 Register ireg = {3};
1320 bmi1(0xf3, ireg, dst, src);
1321 }
1322 void blsmsk(Register dst, Register src) { blsmsk(dst, Operand(src)); }
1323 void blsmsk(Register dst, const Operand& src) {
1324 Register ireg = {2};
1325 bmi1(0xf3, ireg, dst, src);
1326 }
1327 void blsr(Register dst, Register src) { blsr(dst, Operand(src)); }
1328 void blsr(Register dst, const Operand& src) {
1329 Register ireg = {1};
1330 bmi1(0xf3, ireg, dst, src);
1331 }
1332 void tzcnt(Register dst, Register src) { tzcnt(dst, Operand(src)); }
1333 void tzcnt(Register dst, const Operand& src);
1334
1335 void lzcnt(Register dst, Register src) { lzcnt(dst, Operand(src)); }
1336 void lzcnt(Register dst, const Operand& src);
1337
1338 void popcnt(Register dst, Register src) { popcnt(dst, Operand(src)); }
1339 void popcnt(Register dst, const Operand& src);
1340
1341 void bzhi(Register dst, Register src1, Register src2) {
1342 bzhi(dst, Operand(src1), src2);
1343 }
1344 void bzhi(Register dst, const Operand& src1, Register src2) {
1345 bmi2(kNone, 0xf5, dst, src2, src1);
1346 }
1347 void mulx(Register dst1, Register dst2, Register src) {
1348 mulx(dst1, dst2, Operand(src));
1349 }
1350 void mulx(Register dst1, Register dst2, const Operand& src) {
1351 bmi2(kF2, 0xf6, dst1, dst2, src);
1352 }
1353 void pdep(Register dst, Register src1, Register src2) {
1354 pdep(dst, src1, Operand(src2));
1355 }
1356 void pdep(Register dst, Register src1, const Operand& src2) {
1357 bmi2(kF2, 0xf5, dst, src1, src2);
1358 }
1359 void pext(Register dst, Register src1, Register src2) {
1360 pext(dst, src1, Operand(src2));
1361 }
1362 void pext(Register dst, Register src1, const Operand& src2) {
1363 bmi2(kF3, 0xf5, dst, src1, src2);
1364 }
1365 void sarx(Register dst, Register src1, Register src2) {
1366 sarx(dst, Operand(src1), src2);
1367 }
1368 void sarx(Register dst, const Operand& src1, Register src2) {
1369 bmi2(kF3, 0xf7, dst, src2, src1);
1370 }
1371 void shlx(Register dst, Register src1, Register src2) {
1372 shlx(dst, Operand(src1), src2);
1373 }
1374 void shlx(Register dst, const Operand& src1, Register src2) {
1375 bmi2(k66, 0xf7, dst, src2, src1);
1376 }
1377 void shrx(Register dst, Register src1, Register src2) {
1378 shrx(dst, Operand(src1), src2);
1379 }
1380 void shrx(Register dst, const Operand& src1, Register src2) {
1381 bmi2(kF2, 0xf7, dst, src2, src1);
1382 }
1383 void rorx(Register dst, Register src, byte imm8) {
1384 rorx(dst, Operand(src), imm8);
1385 }
1386 void rorx(Register dst, const Operand& src, byte imm8);
1387
1388#define PACKED_OP_LIST(V) \
1389 V(and, 0x54) \
1390 V(xor, 0x57)
1391
1392#define AVX_PACKED_OP_DECLARE(name, opcode) \
1393 void v##name##ps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1394 vps(opcode, dst, src1, Operand(src2)); \
1395 } \
1396 void v##name##ps(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1397 vps(opcode, dst, src1, src2); \
1398 } \
1399 void v##name##pd(XMMRegister dst, XMMRegister src1, XMMRegister src2) { \
1400 vpd(opcode, dst, src1, Operand(src2)); \
1401 } \
1402 void v##name##pd(XMMRegister dst, XMMRegister src1, const Operand& src2) { \
1403 vpd(opcode, dst, src1, src2); \
1404 }
1405
1406 PACKED_OP_LIST(AVX_PACKED_OP_DECLARE);
1407 void vps(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1408 void vps(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1409 void vpd(byte op, XMMRegister dst, XMMRegister src1, XMMRegister src2);
1410 void vpd(byte op, XMMRegister dst, XMMRegister src1, const Operand& src2);
1411
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001412 // Prefetch src position into cache level.
1413 // Level 1, 2 or 3 specifies CPU cache level. Level 0 specifies a
1414 // non-temporal
1415 void prefetch(const Operand& src, int level);
1416 // TODO(lrn): Need SFENCE for movnt?
1417
Steve Blocka7e24c12009-10-30 11:49:00 +00001418 // Check the code size generated from label to here.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001419 int SizeOfCodeGeneratedSince(Label* label) {
1420 return pc_offset() - label->pos();
1421 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001422
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001423 // Mark generator continuation.
1424 void RecordGeneratorContinuation();
Steve Blocka7e24c12009-10-30 11:49:00 +00001425
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001426 // Mark address of a debug break slot.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001427 void RecordDebugBreakSlot(RelocInfo::Mode mode);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001428
Steve Blocka7e24c12009-10-30 11:49:00 +00001429 // Record a comment relocation entry that can be used by a disassembler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001430 // Use --code-comments to enable.
1431 void RecordComment(const char* msg);
1432
1433 // Record a deoptimization reason that can be used by a log or cpu profiler.
1434 // Use --trace-deopt to enable.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001435 void RecordDeoptReason(const int reason, int raw_position);
Steve Blocka7e24c12009-10-30 11:49:00 +00001436
Ben Murdochb0fe1622011-05-05 13:52:32 +01001437 // Writes a single byte or word of data in the code stream. Used for
1438 // inline tables, e.g., jump-tables.
1439 void db(uint8_t data);
1440 void dd(uint32_t data);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001441 void dq(uint64_t data);
1442 void dp(uintptr_t data) { dd(data); }
1443 void dd(Label* label);
Steve Blocka7e24c12009-10-30 11:49:00 +00001444
Steve Blocka7e24c12009-10-30 11:49:00 +00001445 // Check if there is less than kGap bytes available in the buffer.
1446 // If this is the case, we need to grow the buffer before emitting
1447 // an instruction or relocation information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001448 inline bool buffer_overflow() const {
1449 return pc_ >= reloc_info_writer.pos() - kGap;
1450 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001451
1452 // Get the number of bytes available in the buffer.
1453 inline int available_space() const { return reloc_info_writer.pos() - pc_; }
1454
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001455 static bool IsNop(Address addr);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001456
Ben Murdochda12d292016-06-02 14:46:10 +01001457 AssemblerPositionsRecorder* positions_recorder() {
1458 return &positions_recorder_;
1459 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001460
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001461 int relocation_writer_size() {
1462 return (buffer_ + buffer_size_) - reloc_info_writer.pos();
1463 }
1464
Steve Blocka7e24c12009-10-30 11:49:00 +00001465 // Avoid overflows for displacements etc.
1466 static const int kMaximalBufferSize = 512*MB;
Steve Blocka7e24c12009-10-30 11:49:00 +00001467
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001468 byte byte_at(int pos) { return buffer_[pos]; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001469 void set_byte_at(int pos, byte value) { buffer_[pos] = value; }
1470
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001471 void PatchConstantPoolAccessInstruction(int pc_offset, int offset,
1472 ConstantPoolEntry::Access access,
1473 ConstantPoolEntry::Type type) {
1474 // No embedded constant pool support.
1475 UNREACHABLE();
1476 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001477
Steve Blocka7e24c12009-10-30 11:49:00 +00001478 protected:
Steve Blocka7e24c12009-10-30 11:49:00 +00001479 void emit_sse_operand(XMMRegister reg, const Operand& adr);
1480 void emit_sse_operand(XMMRegister dst, XMMRegister src);
Steve Block6ded16b2010-05-10 14:33:55 +01001481 void emit_sse_operand(Register dst, XMMRegister src);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001482 void emit_sse_operand(XMMRegister dst, Register src);
Steve Blocka7e24c12009-10-30 11:49:00 +00001483
Steve Block44f0eee2011-05-26 01:26:41 +01001484 byte* addr_at(int pos) { return buffer_ + pos; }
1485
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001486
Ben Murdochb0fe1622011-05-05 13:52:32 +01001487 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00001488 uint32_t long_at(int pos) {
1489 return *reinterpret_cast<uint32_t*>(addr_at(pos));
1490 }
1491 void long_at_put(int pos, uint32_t x) {
1492 *reinterpret_cast<uint32_t*>(addr_at(pos)) = x;
1493 }
1494
1495 // code emission
1496 void GrowBuffer();
1497 inline void emit(uint32_t x);
1498 inline void emit(Handle<Object> handle);
Ben Murdoch257744e2011-11-30 15:57:28 +00001499 inline void emit(uint32_t x,
1500 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001501 TypeFeedbackId id = TypeFeedbackId::None());
1502 inline void emit(Handle<Code> code,
1503 RelocInfo::Mode rmode,
1504 TypeFeedbackId id = TypeFeedbackId::None());
Steve Blocka7e24c12009-10-30 11:49:00 +00001505 inline void emit(const Immediate& x);
Ben Murdochda12d292016-06-02 14:46:10 +01001506 inline void emit_b(Immediate x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001507 inline void emit_w(const Immediate& x);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001508 inline void emit_q(uint64_t x);
Steve Blocka7e24c12009-10-30 11:49:00 +00001509
1510 // Emit the code-object-relative offset of the label's position
1511 inline void emit_code_relative_offset(Label* label);
1512
1513 // instruction generation
1514 void emit_arith_b(int op1, int op2, Register dst, int imm8);
1515
1516 // Emit a basic arithmetic instruction (i.e. first byte of the family is 0x81)
1517 // with a given destination expression and an immediate operand. It attempts
1518 // to use the shortest encoding possible.
1519 // sel specifies the /n in the modrm byte (see the Intel PRM).
1520 void emit_arith(int sel, Operand dst, const Immediate& x);
1521
1522 void emit_operand(Register reg, const Operand& adr);
1523
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001524 void emit_label(Label* label);
1525
Steve Blocka7e24c12009-10-30 11:49:00 +00001526 void emit_farith(int b1, int b2, int i);
1527
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001528 // Emit vex prefix
1529 enum SIMDPrefix { kNone = 0x0, k66 = 0x1, kF3 = 0x2, kF2 = 0x3 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001530 enum VectorLength { kL128 = 0x0, kL256 = 0x4, kLIG = kL128, kLZ = kL128 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001531 enum VexW { kW0 = 0x0, kW1 = 0x80, kWIG = kW0 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001532 enum LeadingOpcode { k0F = 0x1, k0F38 = 0x2, k0F3A = 0x3 };
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001533 inline void emit_vex_prefix(XMMRegister v, VectorLength l, SIMDPrefix pp,
1534 LeadingOpcode m, VexW w);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001535 inline void emit_vex_prefix(Register v, VectorLength l, SIMDPrefix pp,
1536 LeadingOpcode m, VexW w);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001537
Steve Blocka7e24c12009-10-30 11:49:00 +00001538 // labels
1539 void print(Label* L);
1540 void bind_to(Label* L, int pos);
Steve Blocka7e24c12009-10-30 11:49:00 +00001541
1542 // displacements
1543 inline Displacement disp_at(Label* L);
1544 inline void disp_at_put(Label* L, Displacement disp);
1545 inline void emit_disp(Label* L, Displacement::Type type);
Ben Murdoch257744e2011-11-30 15:57:28 +00001546 inline void emit_near_disp(Label* L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001547
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001548 // Most BMI instructions are similiar.
1549 void bmi1(byte op, Register reg, Register vreg, const Operand& rm);
1550 void bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
1551 const Operand& rm);
1552
Steve Blocka7e24c12009-10-30 11:49:00 +00001553 // record reloc info for current pc_
1554 void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data = 0);
1555
1556 friend class CodePatcher;
1557 friend class EnsureSpace;
1558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001559 // Internal reference positions, required for (potential) patching in
1560 // GrowBuffer(); contains only those internal references whose labels
1561 // are already bound.
1562 std::deque<int> internal_reference_positions_;
1563
Steve Blocka7e24c12009-10-30 11:49:00 +00001564 // code generation
Steve Blocka7e24c12009-10-30 11:49:00 +00001565 RelocInfoWriter reloc_info_writer;
1566
Ben Murdochda12d292016-06-02 14:46:10 +01001567 AssemblerPositionsRecorder positions_recorder_;
1568 friend class AssemblerPositionsRecorder;
Steve Blocka7e24c12009-10-30 11:49:00 +00001569};
1570
1571
1572// Helper class that ensures that there is enough space for generating
1573// instructions and relocation information. The constructor makes
1574// sure that there is enough space and (in debug mode) the destructor
1575// checks that we did not generate too much.
1576class EnsureSpace BASE_EMBEDDED {
1577 public:
1578 explicit EnsureSpace(Assembler* assembler) : assembler_(assembler) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001579 if (assembler_->buffer_overflow()) assembler_->GrowBuffer();
Steve Blocka7e24c12009-10-30 11:49:00 +00001580#ifdef DEBUG
1581 space_before_ = assembler_->available_space();
1582#endif
1583 }
1584
1585#ifdef DEBUG
1586 ~EnsureSpace() {
1587 int bytes_generated = space_before_ - assembler_->available_space();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001588 DCHECK(bytes_generated < assembler_->kGap);
Steve Blocka7e24c12009-10-30 11:49:00 +00001589 }
1590#endif
1591
1592 private:
1593 Assembler* assembler_;
1594#ifdef DEBUG
1595 int space_before_;
1596#endif
1597};
1598
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001599} // namespace internal
1600} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001601
1602#endif // V8_IA32_ASSEMBLER_IA32_H_