blob: 150131cdbc0e66cf3a65616013fe715d8ec565eb [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
6// are 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
14// distribution.
15//
16// - Neither the name of Sun Microsystems or the names of contributors may
17// be used to endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31// OF THE POSSIBILITY OF SUCH DAMAGE.
32
33// The original source code covered by the above license above has been modified
34// significantly by Google Inc.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010035// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000036
Emily Bernierd0a1eb72015-03-24 16:35:39 -040037#include "src/ia32/assembler-ia32.h"
38
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039#include <cstring>
40
41#if V8_TARGET_ARCH_IA32
42
43#if V8_LIBC_MSVCRT
44#include <intrin.h> // _xgetbv()
45#endif
Emily Bernierd0a1eb72015-03-24 16:35:39 -040046#if V8_OS_MACOSX
47#include <sys/sysctl.h>
48#endif
Steve Blocka7e24c12009-10-30 11:49:00 +000049
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050#include "src/base/bits.h"
51#include "src/base/cpu.h"
52#include "src/disassembler.h"
53#include "src/macro-assembler.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040054#include "src/v8.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000055
56namespace v8 {
57namespace internal {
58
59// -----------------------------------------------------------------------------
60// Implementation of CpuFeatures
61
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062namespace {
63
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064#if !V8_LIBC_MSVCRT
65
66V8_INLINE uint64_t _xgetbv(unsigned int xcr) {
67 unsigned eax, edx;
68 // Check xgetbv; this uses a .byte sequence instead of the instruction
69 // directly because older assemblers do not include support for xgetbv and
70 // there is no easy way to conditionally compile based on the assembler
71 // used.
72 __asm__ volatile(".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(xcr));
73 return static_cast<uint64_t>(eax) | (static_cast<uint64_t>(edx) << 32);
74}
75
76#define _XCR_XFEATURE_ENABLED_MASK 0
77
78#endif // !V8_LIBC_MSVCRT
79
80
81bool OSHasAVXSupport() {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040082#if V8_OS_MACOSX
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083 // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being
84 // caused by ISRs, so we detect that here and disable AVX in that case.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040085 char buffer[128];
86 size_t buffer_size = arraysize(buffer);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000087 int ctl_name[] = {CTL_KERN, KERN_OSRELEASE};
Emily Bernierd0a1eb72015-03-24 16:35:39 -040088 if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) {
89 V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version");
90 }
91 // The buffer now contains a string of the form XX.YY.ZZ, where
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092 // XX is the major kernel version component.
93 char* period_pos = strchr(buffer, '.');
94 DCHECK_NOT_NULL(period_pos);
95 *period_pos = '\0';
96 long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT
97 if (kernel_version_major <= 13) return false;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040098#endif // V8_OS_MACOSX
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000099 // Check whether OS claims to support AVX.
100 uint64_t feature_mask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK);
101 return (feature_mask & 0x6) == 0x6;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400102}
103
104} // namespace
105
106
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107void CpuFeatures::ProbeImpl(bool cross_compile) {
108 base::CPU cpu;
109 CHECK(cpu.has_sse2()); // SSE2 support is mandatory.
110 CHECK(cpu.has_cmov()); // CMOV support is mandatory.
Steve Blocka7e24c12009-10-30 11:49:00 +0000111
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112 // Only use statically determined features for cross compile (snapshot).
113 if (cross_compile) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000114
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000115 if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1;
116 if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 if (cpu.has_avx() && FLAG_enable_avx && cpu.has_osxsave() &&
118 OSHasAVXSupport()) {
119 supported_ |= 1u << AVX;
120 }
121 if (cpu.has_fma3() && FLAG_enable_fma3 && cpu.has_osxsave() &&
122 OSHasAVXSupport()) {
123 supported_ |= 1u << FMA3;
124 }
125 if (cpu.has_bmi1() && FLAG_enable_bmi1) supported_ |= 1u << BMI1;
126 if (cpu.has_bmi2() && FLAG_enable_bmi2) supported_ |= 1u << BMI2;
127 if (cpu.has_lzcnt() && FLAG_enable_lzcnt) supported_ |= 1u << LZCNT;
128 if (cpu.has_popcnt() && FLAG_enable_popcnt) supported_ |= 1u << POPCNT;
129 if (strcmp(FLAG_mcpu, "auto") == 0) {
130 if (cpu.is_atom()) supported_ |= 1u << ATOM;
131 } else if (strcmp(FLAG_mcpu, "atom") == 0) {
132 supported_ |= 1u << ATOM;
133 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000134}
135
136
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137void CpuFeatures::PrintTarget() { }
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400138void CpuFeatures::PrintFeatures() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000139 printf(
140 "SSE3=%d SSE4_1=%d AVX=%d FMA3=%d BMI1=%d BMI2=%d LZCNT=%d POPCNT=%d "
141 "ATOM=%d\n",
142 CpuFeatures::IsSupported(SSE3), CpuFeatures::IsSupported(SSE4_1),
143 CpuFeatures::IsSupported(AVX), CpuFeatures::IsSupported(FMA3),
144 CpuFeatures::IsSupported(BMI1), CpuFeatures::IsSupported(BMI2),
145 CpuFeatures::IsSupported(LZCNT), CpuFeatures::IsSupported(POPCNT),
146 CpuFeatures::IsSupported(ATOM));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400147}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148
149
Steve Blocka7e24c12009-10-30 11:49:00 +0000150// -----------------------------------------------------------------------------
151// Implementation of Displacement
152
153void Displacement::init(Label* L, Type type) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154 DCHECK(!L->is_bound());
Steve Blocka7e24c12009-10-30 11:49:00 +0000155 int next = 0;
156 if (L->is_linked()) {
157 next = L->pos();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158 DCHECK(next > 0); // Displacements must be at positions > 0
Steve Blocka7e24c12009-10-30 11:49:00 +0000159 }
160 // Ensure that we _never_ overflow the next field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161 DCHECK(NextField::is_valid(Assembler::kMaximalBufferSize));
Steve Blocka7e24c12009-10-30 11:49:00 +0000162 data_ = NextField::encode(next) | TypeField::encode(type);
163}
164
165
166// -----------------------------------------------------------------------------
167// Implementation of RelocInfo
168
169
170const int RelocInfo::kApplyMask =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 RelocInfo::kCodeTargetMask | 1 << RelocInfo::RUNTIME_ENTRY |
172 1 << RelocInfo::INTERNAL_REFERENCE | 1 << RelocInfo::CODE_AGE_SEQUENCE |
173 RelocInfo::kDebugBreakSlotMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000174
175
Leon Clarkef7060e22010-06-03 12:02:55 +0100176bool RelocInfo::IsCodedSpecially() {
177 // The deserializer needs to know whether a pointer is specially coded. Being
178 // specially coded on IA32 means that it is a relative address, as used by
179 // branch instructions. These are also the ones that need changing when a
180 // code object moves.
181 return (1 << rmode_) & kApplyMask;
182}
183
184
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185bool RelocInfo::IsInConstantPool() {
186 return false;
187}
188
189
Steve Blocka7e24c12009-10-30 11:49:00 +0000190// -----------------------------------------------------------------------------
191// Implementation of Operand
192
193Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) {
194 // [base + disp/r]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195 if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000196 // [base]
197 set_modrm(0, base);
198 if (base.is(esp)) set_sib(times_1, esp, base);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000199 } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000200 // [base + disp8]
201 set_modrm(1, base);
202 if (base.is(esp)) set_sib(times_1, esp, base);
203 set_disp8(disp);
204 } else {
205 // [base + disp/r]
206 set_modrm(2, base);
207 if (base.is(esp)) set_sib(times_1, esp, base);
208 set_dispr(disp, rmode);
209 }
210}
211
212
213Operand::Operand(Register base,
214 Register index,
215 ScaleFactor scale,
216 int32_t disp,
217 RelocInfo::Mode rmode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 DCHECK(!index.is(esp)); // illegal addressing mode
Steve Blocka7e24c12009-10-30 11:49:00 +0000219 // [base + index*scale + disp/r]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220 if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 // [base + index*scale]
222 set_modrm(0, esp);
223 set_sib(scale, index, base);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224 } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 // [base + index*scale + disp8]
226 set_modrm(1, esp);
227 set_sib(scale, index, base);
228 set_disp8(disp);
229 } else {
230 // [base + index*scale + disp/r]
231 set_modrm(2, esp);
232 set_sib(scale, index, base);
233 set_dispr(disp, rmode);
234 }
235}
236
237
238Operand::Operand(Register index,
239 ScaleFactor scale,
240 int32_t disp,
241 RelocInfo::Mode rmode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 DCHECK(!index.is(esp)); // illegal addressing mode
Steve Blocka7e24c12009-10-30 11:49:00 +0000243 // [index*scale + disp/r]
244 set_modrm(0, esp);
245 set_sib(scale, index, ebp);
246 set_dispr(disp, rmode);
247}
248
249
250bool Operand::is_reg(Register reg) const {
251 return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only.
252 && ((buf_[0] & 0x07) == reg.code()); // register codes match.
253}
254
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100255
256bool Operand::is_reg_only() const {
257 return (buf_[0] & 0xF8) == 0xC0; // Addressing mode is register only.
258}
259
260
261Register Operand::reg() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262 DCHECK(is_reg_only());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100263 return Register::from_code(buf_[0] & 0x07);
264}
265
266
Steve Blocka7e24c12009-10-30 11:49:00 +0000267// -----------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000268// Implementation of Assembler.
Steve Blocka7e24c12009-10-30 11:49:00 +0000269
270// Emit a single byte. Must always be inlined.
271#define EMIT(x) \
272 *pc_++ = (x)
273
274
275#ifdef GENERATED_CODE_COVERAGE
276static void InitCoverageLog();
277#endif
278
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000279Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
280 : AssemblerBase(isolate, buffer, buffer_size),
281 positions_recorder_(this) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000282 // Clear the buffer in debug mode unless it was provided by the
283 // caller in which case we can't be sure it's okay to overwrite
284 // existing code in it; see CodePatcher::CodePatcher(...).
285#ifdef DEBUG
286 if (own_buffer_) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000287 memset(buffer_, 0xCC, buffer_size_); // int3
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 }
289#endif
290
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000291 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000292
Steve Blocka7e24c12009-10-30 11:49:00 +0000293#ifdef GENERATED_CODE_COVERAGE
294 InitCoverageLog();
295#endif
296}
297
298
Steve Blocka7e24c12009-10-30 11:49:00 +0000299void Assembler::GetCode(CodeDesc* desc) {
Andrei Popescu31002712010-02-23 13:46:05 +0000300 // Finalize code (at this point overflow() may be true, but the gap ensures
301 // that we are still not overlapping instructions and relocation info).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000302 reloc_info_writer.Finish();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100304 // Set up code descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000305 desc->buffer = buffer_;
306 desc->buffer_size = buffer_size_;
307 desc->instr_size = pc_offset();
308 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
309 desc->origin = this;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000310 desc->constant_pool_size = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000311}
312
313
314void Assembler::Align(int m) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315 DCHECK(base::bits::IsPowerOfTwo32(m));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100316 int mask = m - 1;
317 int addr = pc_offset();
318 Nop((m - (addr & mask)) & mask);
319}
320
321
322bool Assembler::IsNop(Address addr) {
323 Address a = addr;
324 while (*a == 0x66) a++;
325 if (*a == 0x90) return true;
326 if (a[0] == 0xf && a[1] == 0x1f) return true;
327 return false;
328}
329
330
331void Assembler::Nop(int bytes) {
332 EnsureSpace ensure_space(this);
333
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100334 // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf
335 while (bytes > 0) {
336 switch (bytes) {
337 case 2:
338 EMIT(0x66);
339 case 1:
340 EMIT(0x90);
341 return;
342 case 3:
343 EMIT(0xf);
344 EMIT(0x1f);
345 EMIT(0);
346 return;
347 case 4:
348 EMIT(0xf);
349 EMIT(0x1f);
350 EMIT(0x40);
351 EMIT(0);
352 return;
353 case 6:
354 EMIT(0x66);
355 case 5:
356 EMIT(0xf);
357 EMIT(0x1f);
358 EMIT(0x44);
359 EMIT(0);
360 EMIT(0);
361 return;
362 case 7:
363 EMIT(0xf);
364 EMIT(0x1f);
365 EMIT(0x80);
366 EMIT(0);
367 EMIT(0);
368 EMIT(0);
369 EMIT(0);
370 return;
371 default:
372 case 11:
373 EMIT(0x66);
374 bytes--;
375 case 10:
376 EMIT(0x66);
377 bytes--;
378 case 9:
379 EMIT(0x66);
380 bytes--;
381 case 8:
382 EMIT(0xf);
383 EMIT(0x1f);
384 EMIT(0x84);
385 EMIT(0);
386 EMIT(0);
387 EMIT(0);
388 EMIT(0);
389 EMIT(0);
390 bytes -= 8;
391 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 }
393}
394
395
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100396void Assembler::CodeTargetAlign() {
397 Align(16); // Preferred alignment of jump targets on ia32.
398}
399
400
Steve Blocka7e24c12009-10-30 11:49:00 +0000401void Assembler::cpuid() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000402 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 EMIT(0x0F);
404 EMIT(0xA2);
405}
406
407
408void Assembler::pushad() {
409 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 EMIT(0x60);
411}
412
413
414void Assembler::popad() {
415 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 EMIT(0x61);
417}
418
419
420void Assembler::pushfd() {
421 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 EMIT(0x9C);
423}
424
425
426void Assembler::popfd() {
427 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 EMIT(0x9D);
429}
430
431
432void Assembler::push(const Immediate& x) {
433 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 if (x.is_int8()) {
435 EMIT(0x6a);
436 EMIT(x.x_);
437 } else {
438 EMIT(0x68);
439 emit(x);
440 }
441}
442
443
Ben Murdochb0fe1622011-05-05 13:52:32 +0100444void Assembler::push_imm32(int32_t imm32) {
445 EnsureSpace ensure_space(this);
446 EMIT(0x68);
447 emit(imm32);
448}
449
450
Steve Blocka7e24c12009-10-30 11:49:00 +0000451void Assembler::push(Register src) {
452 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 EMIT(0x50 | src.code());
454}
455
456
457void Assembler::push(const Operand& src) {
458 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000459 EMIT(0xFF);
460 emit_operand(esi, src);
461}
462
463
464void Assembler::pop(Register dst) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000465 DCHECK(reloc_info_writer.last_pc() != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000467 EMIT(0x58 | dst.code());
468}
469
470
471void Assembler::pop(const Operand& dst) {
472 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000473 EMIT(0x8F);
474 emit_operand(eax, dst);
475}
476
477
478void Assembler::enter(const Immediate& size) {
479 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 EMIT(0xC8);
481 emit_w(size);
482 EMIT(0);
483}
484
485
486void Assembler::leave() {
487 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000488 EMIT(0xC9);
489}
490
491
492void Assembler::mov_b(Register dst, const Operand& src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100493 CHECK(dst.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000494 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000495 EMIT(0x8A);
496 emit_operand(dst, src);
497}
498
499
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400500void Assembler::mov_b(const Operand& dst, const Immediate& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000501 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000502 EMIT(0xC6);
503 emit_operand(eax, dst);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400504 EMIT(static_cast<int8_t>(src.x_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000505}
506
507
508void Assembler::mov_b(const Operand& dst, Register src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100509 CHECK(src.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000510 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000511 EMIT(0x88);
512 emit_operand(src, dst);
513}
514
515
516void Assembler::mov_w(Register dst, const Operand& src) {
517 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000518 EMIT(0x66);
519 EMIT(0x8B);
520 emit_operand(dst, src);
521}
522
523
524void Assembler::mov_w(const Operand& dst, Register src) {
525 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000526 EMIT(0x66);
527 EMIT(0x89);
528 emit_operand(src, dst);
529}
530
531
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400532void Assembler::mov_w(const Operand& dst, const Immediate& src) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000533 EnsureSpace ensure_space(this);
534 EMIT(0x66);
535 EMIT(0xC7);
536 emit_operand(eax, dst);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400537 EMIT(static_cast<int8_t>(src.x_ & 0xff));
538 EMIT(static_cast<int8_t>(src.x_ >> 8));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000539}
540
541
Steve Blocka7e24c12009-10-30 11:49:00 +0000542void Assembler::mov(Register dst, int32_t imm32) {
543 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000544 EMIT(0xB8 | dst.code());
545 emit(imm32);
546}
547
548
549void Assembler::mov(Register dst, const Immediate& x) {
550 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000551 EMIT(0xB8 | dst.code());
552 emit(x);
553}
554
555
556void Assembler::mov(Register dst, Handle<Object> handle) {
557 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 EMIT(0xB8 | dst.code());
559 emit(handle);
560}
561
562
563void Assembler::mov(Register dst, const Operand& src) {
564 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000565 EMIT(0x8B);
566 emit_operand(dst, src);
567}
568
569
570void Assembler::mov(Register dst, Register src) {
571 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000572 EMIT(0x89);
573 EMIT(0xC0 | src.code() << 3 | dst.code());
574}
575
576
577void Assembler::mov(const Operand& dst, const Immediate& x) {
578 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 EMIT(0xC7);
580 emit_operand(eax, dst);
581 emit(x);
582}
583
584
585void Assembler::mov(const Operand& dst, Handle<Object> handle) {
586 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 EMIT(0xC7);
588 emit_operand(eax, dst);
589 emit(handle);
590}
591
592
593void Assembler::mov(const Operand& dst, Register src) {
594 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 EMIT(0x89);
596 emit_operand(src, dst);
597}
598
599
600void Assembler::movsx_b(Register dst, const Operand& src) {
601 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000602 EMIT(0x0F);
603 EMIT(0xBE);
604 emit_operand(dst, src);
605}
606
607
608void Assembler::movsx_w(Register dst, const Operand& src) {
609 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000610 EMIT(0x0F);
611 EMIT(0xBF);
612 emit_operand(dst, src);
613}
614
615
616void Assembler::movzx_b(Register dst, const Operand& src) {
617 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000618 EMIT(0x0F);
619 EMIT(0xB6);
620 emit_operand(dst, src);
621}
622
623
624void Assembler::movzx_w(Register dst, const Operand& src) {
625 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000626 EMIT(0x0F);
627 EMIT(0xB7);
628 emit_operand(dst, src);
629}
630
631
Steve Blocka7e24c12009-10-30 11:49:00 +0000632void Assembler::cmov(Condition cc, Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000633 EnsureSpace ensure_space(this);
Andrei Popescu31002712010-02-23 13:46:05 +0000634 // Opcode: 0f 40 + cc /r.
Steve Blocka7e24c12009-10-30 11:49:00 +0000635 EMIT(0x0F);
636 EMIT(0x40 + cc);
637 emit_operand(dst, src);
638}
639
640
Steve Block6ded16b2010-05-10 14:33:55 +0100641void Assembler::cld() {
642 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +0100643 EMIT(0xFC);
644}
645
646
Leon Clarkee46be812010-01-19 14:06:41 +0000647void Assembler::rep_movs() {
648 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +0000649 EMIT(0xF3);
650 EMIT(0xA5);
651}
652
653
Steve Block6ded16b2010-05-10 14:33:55 +0100654void Assembler::rep_stos() {
655 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +0100656 EMIT(0xF3);
657 EMIT(0xAB);
658}
659
660
Leon Clarkef7060e22010-06-03 12:02:55 +0100661void Assembler::stos() {
662 EnsureSpace ensure_space(this);
Leon Clarkef7060e22010-06-03 12:02:55 +0100663 EMIT(0xAB);
664}
665
666
Steve Blocka7e24c12009-10-30 11:49:00 +0000667void Assembler::xchg(Register dst, Register src) {
668 EnsureSpace ensure_space(this);
Andrei Popescu31002712010-02-23 13:46:05 +0000669 if (src.is(eax) || dst.is(eax)) { // Single-byte encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000670 EMIT(0x90 | (src.is(eax) ? dst.code() : src.code()));
671 } else {
672 EMIT(0x87);
673 EMIT(0xC0 | src.code() << 3 | dst.code());
674 }
675}
676
677
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000678void Assembler::xchg(Register dst, const Operand& src) {
679 EnsureSpace ensure_space(this);
680 EMIT(0x87);
681 emit_operand(dst, src);
682}
683
684
Steve Blocka7e24c12009-10-30 11:49:00 +0000685void Assembler::adc(Register dst, int32_t imm32) {
686 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000687 emit_arith(2, Operand(dst), Immediate(imm32));
688}
689
690
691void Assembler::adc(Register dst, const Operand& src) {
692 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000693 EMIT(0x13);
694 emit_operand(dst, src);
695}
696
697
698void Assembler::add(Register dst, const Operand& src) {
699 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000700 EMIT(0x03);
701 emit_operand(dst, src);
702}
703
704
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100705void Assembler::add(const Operand& dst, Register src) {
706 EnsureSpace ensure_space(this);
707 EMIT(0x01);
708 emit_operand(src, dst);
709}
710
711
Steve Blocka7e24c12009-10-30 11:49:00 +0000712void Assembler::add(const Operand& dst, const Immediate& x) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000713 DCHECK(reloc_info_writer.last_pc() != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000714 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000715 emit_arith(0, dst, x);
716}
717
718
719void Assembler::and_(Register dst, int32_t imm32) {
Steve Block59151502010-09-22 15:07:15 +0100720 and_(dst, Immediate(imm32));
721}
722
723
724void Assembler::and_(Register dst, const Immediate& x) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000725 EnsureSpace ensure_space(this);
Steve Block59151502010-09-22 15:07:15 +0100726 emit_arith(4, Operand(dst), x);
Steve Blocka7e24c12009-10-30 11:49:00 +0000727}
728
729
730void Assembler::and_(Register dst, const Operand& src) {
731 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000732 EMIT(0x23);
733 emit_operand(dst, src);
734}
735
736
737void Assembler::and_(const Operand& dst, const Immediate& x) {
738 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000739 emit_arith(4, dst, x);
740}
741
742
743void Assembler::and_(const Operand& dst, Register src) {
744 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000745 EMIT(0x21);
746 emit_operand(src, dst);
747}
748
Ben Murdochda12d292016-06-02 14:46:10 +0100749void Assembler::cmpb(const Operand& op, Immediate imm8) {
750 DCHECK(imm8.is_int8() || imm8.is_uint8());
Steve Blocka7e24c12009-10-30 11:49:00 +0000751 EnsureSpace ensure_space(this);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100752 if (op.is_reg(eax)) {
753 EMIT(0x3C);
754 } else {
755 EMIT(0x80);
756 emit_operand(edi, op); // edi == 7
757 }
Ben Murdochda12d292016-06-02 14:46:10 +0100758 emit_b(imm8);
Steve Blocka7e24c12009-10-30 11:49:00 +0000759}
760
761
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100762void Assembler::cmpb(const Operand& op, Register reg) {
763 CHECK(reg.is_byte_register());
Leon Clarked91b9f72010-01-27 17:25:45 +0000764 EnsureSpace ensure_space(this);
Leon Clarked91b9f72010-01-27 17:25:45 +0000765 EMIT(0x38);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100766 emit_operand(reg, op);
Leon Clarked91b9f72010-01-27 17:25:45 +0000767}
768
769
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100770void Assembler::cmpb(Register reg, const Operand& op) {
771 CHECK(reg.is_byte_register());
Leon Clarked91b9f72010-01-27 17:25:45 +0000772 EnsureSpace ensure_space(this);
Leon Clarked91b9f72010-01-27 17:25:45 +0000773 EMIT(0x3A);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100774 emit_operand(reg, op);
Leon Clarked91b9f72010-01-27 17:25:45 +0000775}
776
777
Steve Blocka7e24c12009-10-30 11:49:00 +0000778void Assembler::cmpw(const Operand& op, Immediate imm16) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000779 DCHECK(imm16.is_int16());
Steve Blocka7e24c12009-10-30 11:49:00 +0000780 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000781 EMIT(0x66);
782 EMIT(0x81);
783 emit_operand(edi, op);
784 emit_w(imm16);
785}
786
Ben Murdochda12d292016-06-02 14:46:10 +0100787void Assembler::cmpw(Register reg, const Operand& op) {
788 EnsureSpace ensure_space(this);
789 EMIT(0x66);
790 EMIT(0x39);
791 emit_operand(reg, op);
792}
793
794void Assembler::cmpw(const Operand& op, Register reg) {
795 EnsureSpace ensure_space(this);
796 EMIT(0x66);
797 EMIT(0x3B);
798 emit_operand(reg, op);
799}
Steve Blocka7e24c12009-10-30 11:49:00 +0000800
801void Assembler::cmp(Register reg, int32_t imm32) {
802 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000803 emit_arith(7, Operand(reg), Immediate(imm32));
804}
805
806
807void Assembler::cmp(Register reg, Handle<Object> handle) {
808 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000809 emit_arith(7, Operand(reg), Immediate(handle));
810}
811
812
813void Assembler::cmp(Register reg, const Operand& op) {
814 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000815 EMIT(0x3B);
816 emit_operand(reg, op);
817}
818
Ben Murdoch097c5b22016-05-18 11:27:45 +0100819void Assembler::cmp(const Operand& op, Register reg) {
820 EnsureSpace ensure_space(this);
821 EMIT(0x39);
822 emit_operand(reg, op);
823}
Steve Blocka7e24c12009-10-30 11:49:00 +0000824
825void Assembler::cmp(const Operand& op, const Immediate& imm) {
826 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000827 emit_arith(7, op, imm);
828}
829
830
831void Assembler::cmp(const Operand& op, Handle<Object> handle) {
832 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000833 emit_arith(7, op, Immediate(handle));
834}
835
836
837void Assembler::cmpb_al(const Operand& op) {
838 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000839 EMIT(0x38); // CMP r/m8, r8
840 emit_operand(eax, op); // eax has same code as register al.
841}
842
843
844void Assembler::cmpw_ax(const Operand& op) {
845 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000846 EMIT(0x66);
847 EMIT(0x39); // CMP r/m16, r16
848 emit_operand(eax, op); // eax has same code as register ax.
849}
850
851
852void Assembler::dec_b(Register dst) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100853 CHECK(dst.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000855 EMIT(0xFE);
856 EMIT(0xC8 | dst.code());
857}
858
859
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100860void Assembler::dec_b(const Operand& dst) {
861 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100862 EMIT(0xFE);
863 emit_operand(ecx, dst);
864}
865
866
Steve Blocka7e24c12009-10-30 11:49:00 +0000867void Assembler::dec(Register dst) {
868 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000869 EMIT(0x48 | dst.code());
870}
871
872
873void Assembler::dec(const Operand& dst) {
874 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000875 EMIT(0xFF);
876 emit_operand(ecx, dst);
877}
878
879
880void Assembler::cdq() {
881 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000882 EMIT(0x99);
883}
884
885
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886void Assembler::idiv(const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000887 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000888 EMIT(0xF7);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000889 emit_operand(edi, src);
890}
891
892
893void Assembler::div(const Operand& src) {
894 EnsureSpace ensure_space(this);
895 EMIT(0xF7);
896 emit_operand(esi, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000897}
898
899
900void Assembler::imul(Register reg) {
901 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000902 EMIT(0xF7);
903 EMIT(0xE8 | reg.code());
904}
905
906
907void Assembler::imul(Register dst, const Operand& src) {
908 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000909 EMIT(0x0F);
910 EMIT(0xAF);
911 emit_operand(dst, src);
912}
913
914
915void Assembler::imul(Register dst, Register src, int32_t imm32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000916 imul(dst, Operand(src), imm32);
917}
918
919
920void Assembler::imul(Register dst, const Operand& src, int32_t imm32) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000921 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000922 if (is_int8(imm32)) {
923 EMIT(0x6B);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000924 emit_operand(dst, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000925 EMIT(imm32);
926 } else {
927 EMIT(0x69);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000928 emit_operand(dst, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000929 emit(imm32);
930 }
931}
932
933
934void Assembler::inc(Register dst) {
935 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000936 EMIT(0x40 | dst.code());
937}
938
939
940void Assembler::inc(const Operand& dst) {
941 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000942 EMIT(0xFF);
943 emit_operand(eax, dst);
944}
945
946
947void Assembler::lea(Register dst, const Operand& src) {
948 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000949 EMIT(0x8D);
950 emit_operand(dst, src);
951}
952
953
954void Assembler::mul(Register src) {
955 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000956 EMIT(0xF7);
957 EMIT(0xE0 | src.code());
958}
959
960
961void Assembler::neg(Register dst) {
962 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000963 EMIT(0xF7);
964 EMIT(0xD8 | dst.code());
965}
966
967
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000968void Assembler::neg(const Operand& dst) {
969 EnsureSpace ensure_space(this);
970 EMIT(0xF7);
971 emit_operand(ebx, dst);
972}
973
974
Steve Blocka7e24c12009-10-30 11:49:00 +0000975void Assembler::not_(Register dst) {
976 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000977 EMIT(0xF7);
978 EMIT(0xD0 | dst.code());
979}
980
981
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000982void Assembler::not_(const Operand& dst) {
983 EnsureSpace ensure_space(this);
984 EMIT(0xF7);
985 emit_operand(edx, dst);
986}
987
988
Steve Blocka7e24c12009-10-30 11:49:00 +0000989void Assembler::or_(Register dst, int32_t imm32) {
990 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000991 emit_arith(1, Operand(dst), Immediate(imm32));
992}
993
994
995void Assembler::or_(Register dst, const Operand& src) {
996 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000997 EMIT(0x0B);
998 emit_operand(dst, src);
999}
1000
1001
1002void Assembler::or_(const Operand& dst, const Immediate& x) {
1003 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001004 emit_arith(1, dst, x);
1005}
1006
1007
1008void Assembler::or_(const Operand& dst, Register src) {
1009 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001010 EMIT(0x09);
1011 emit_operand(src, dst);
1012}
1013
1014
1015void Assembler::rcl(Register dst, uint8_t imm8) {
1016 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001017 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001018 if (imm8 == 1) {
1019 EMIT(0xD1);
1020 EMIT(0xD0 | dst.code());
1021 } else {
1022 EMIT(0xC1);
1023 EMIT(0xD0 | dst.code());
1024 EMIT(imm8);
1025 }
1026}
1027
1028
Iain Merrick75681382010-08-19 15:07:18 +01001029void Assembler::rcr(Register dst, uint8_t imm8) {
1030 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001031 DCHECK(is_uint5(imm8)); // illegal shift count
Iain Merrick75681382010-08-19 15:07:18 +01001032 if (imm8 == 1) {
1033 EMIT(0xD1);
1034 EMIT(0xD8 | dst.code());
1035 } else {
1036 EMIT(0xC1);
1037 EMIT(0xD8 | dst.code());
1038 EMIT(imm8);
1039 }
1040}
1041
1042
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001043void Assembler::ror(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001044 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001045 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001046 if (imm8 == 1) {
1047 EMIT(0xD1);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001048 emit_operand(ecx, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001049 } else {
1050 EMIT(0xC1);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001051 emit_operand(ecx, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001052 EMIT(imm8);
1053 }
1054}
1055
1056
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001057void Assembler::ror_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001058 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001059 EMIT(0xD3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001060 emit_operand(ecx, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001061}
1062
1063
1064void Assembler::sar(const Operand& dst, uint8_t imm8) {
1065 EnsureSpace ensure_space(this);
1066 DCHECK(is_uint5(imm8)); // illegal shift count
1067 if (imm8 == 1) {
1068 EMIT(0xD1);
1069 emit_operand(edi, dst);
1070 } else {
1071 EMIT(0xC1);
1072 emit_operand(edi, dst);
1073 EMIT(imm8);
1074 }
1075}
1076
1077
1078void Assembler::sar_cl(const Operand& dst) {
1079 EnsureSpace ensure_space(this);
1080 EMIT(0xD3);
1081 emit_operand(edi, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001082}
1083
Steve Blocka7e24c12009-10-30 11:49:00 +00001084void Assembler::sbb(Register dst, const Operand& src) {
1085 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001086 EMIT(0x1B);
1087 emit_operand(dst, src);
1088}
1089
Ben Murdochda12d292016-06-02 14:46:10 +01001090void Assembler::shld(Register dst, Register src, uint8_t shift) {
1091 DCHECK(is_uint5(shift));
1092 EnsureSpace ensure_space(this);
1093 EMIT(0x0F);
1094 EMIT(0xA4);
1095 emit_operand(src, Operand(dst));
1096 EMIT(shift);
1097}
Steve Blocka7e24c12009-10-30 11:49:00 +00001098
Ben Murdochda12d292016-06-02 14:46:10 +01001099void Assembler::shld_cl(Register dst, Register src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001100 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001101 EMIT(0x0F);
1102 EMIT(0xA5);
Ben Murdochda12d292016-06-02 14:46:10 +01001103 emit_operand(src, Operand(dst));
Steve Blocka7e24c12009-10-30 11:49:00 +00001104}
1105
1106
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001107void Assembler::shl(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001108 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001109 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001110 if (imm8 == 1) {
1111 EMIT(0xD1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001112 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001113 } else {
1114 EMIT(0xC1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001115 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001116 EMIT(imm8);
1117 }
1118}
1119
1120
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001121void Assembler::shl_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001122 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001123 EMIT(0xD3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001124 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001125}
1126
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001127void Assembler::shr(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001128 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blockd0582a62009-12-15 09:54:21 +00001130 if (imm8 == 1) {
1131 EMIT(0xD1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001132 emit_operand(ebp, dst);
Steve Blockd0582a62009-12-15 09:54:21 +00001133 } else {
1134 EMIT(0xC1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001135 emit_operand(ebp, dst);
Steve Blockd0582a62009-12-15 09:54:21 +00001136 EMIT(imm8);
1137 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001138}
1139
1140
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001141void Assembler::shr_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001142 EnsureSpace ensure_space(this);
Steve Blockd0582a62009-12-15 09:54:21 +00001143 EMIT(0xD3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001144 emit_operand(ebp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001145}
1146
Ben Murdochda12d292016-06-02 14:46:10 +01001147void Assembler::shrd(Register dst, Register src, uint8_t shift) {
1148 DCHECK(is_uint5(shift));
1149 EnsureSpace ensure_space(this);
1150 EMIT(0x0F);
1151 EMIT(0xAC);
1152 emit_operand(dst, Operand(src));
1153 EMIT(shift);
1154}
1155
1156void Assembler::shrd_cl(const Operand& dst, Register src) {
1157 EnsureSpace ensure_space(this);
1158 EMIT(0x0F);
1159 EMIT(0xAD);
1160 emit_operand(src, dst);
1161}
Steve Blocka7e24c12009-10-30 11:49:00 +00001162
1163void Assembler::sub(const Operand& dst, const Immediate& x) {
1164 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001165 emit_arith(5, dst, x);
1166}
1167
1168
1169void Assembler::sub(Register dst, const Operand& src) {
1170 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001171 EMIT(0x2B);
1172 emit_operand(dst, src);
1173}
1174
1175
1176void Assembler::sub(const Operand& dst, Register src) {
1177 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001178 EMIT(0x29);
1179 emit_operand(src, dst);
1180}
1181
1182
1183void Assembler::test(Register reg, const Immediate& imm) {
Ben Murdochda12d292016-06-02 14:46:10 +01001184 if (imm.is_uint8()) {
1185 test_b(reg, imm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001186 return;
Steve Blocka7e24c12009-10-30 11:49:00 +00001187 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001188
1189 EnsureSpace ensure_space(this);
1190 // This is not using emit_arith because test doesn't support
1191 // sign-extension of 8-bit operands.
1192 if (reg.is(eax)) {
1193 EMIT(0xA9);
1194 } else {
1195 EMIT(0xF7);
1196 EMIT(0xC0 | reg.code());
1197 }
1198 emit(imm);
Steve Blocka7e24c12009-10-30 11:49:00 +00001199}
1200
1201
1202void Assembler::test(Register reg, const Operand& op) {
1203 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001204 EMIT(0x85);
1205 emit_operand(reg, op);
1206}
1207
1208
Leon Clarkee46be812010-01-19 14:06:41 +00001209void Assembler::test_b(Register reg, const Operand& op) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001210 CHECK(reg.is_byte_register());
Leon Clarkee46be812010-01-19 14:06:41 +00001211 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00001212 EMIT(0x84);
1213 emit_operand(reg, op);
1214}
1215
1216
Steve Blocka7e24c12009-10-30 11:49:00 +00001217void Assembler::test(const Operand& op, const Immediate& imm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001218 if (op.is_reg_only()) {
1219 test(op.reg(), imm);
1220 return;
1221 }
Ben Murdochda12d292016-06-02 14:46:10 +01001222 if (imm.is_uint8()) {
1223 return test_b(op, imm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001224 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001225 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001226 EMIT(0xF7);
1227 emit_operand(eax, op);
1228 emit(imm);
1229}
1230
Ben Murdochda12d292016-06-02 14:46:10 +01001231void Assembler::test_b(Register reg, Immediate imm8) {
1232 DCHECK(imm8.is_uint8());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001233 EnsureSpace ensure_space(this);
1234 // Only use test against byte for registers that have a byte
1235 // variant: eax, ebx, ecx, and edx.
1236 if (reg.is(eax)) {
1237 EMIT(0xA8);
Ben Murdochda12d292016-06-02 14:46:10 +01001238 emit_b(imm8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001239 } else if (reg.is_byte_register()) {
Ben Murdochda12d292016-06-02 14:46:10 +01001240 emit_arith_b(0xF6, 0xC0, reg, static_cast<uint8_t>(imm8.x_));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001241 } else {
Ben Murdochda12d292016-06-02 14:46:10 +01001242 EMIT(0x66);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001243 EMIT(0xF7);
1244 EMIT(0xC0 | reg.code());
Ben Murdochda12d292016-06-02 14:46:10 +01001245 emit_w(imm8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001246 }
1247}
1248
Ben Murdochda12d292016-06-02 14:46:10 +01001249void Assembler::test_b(const Operand& op, Immediate imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001250 if (op.is_reg_only()) {
1251 test_b(op.reg(), imm8);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001252 return;
1253 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001254 EnsureSpace ensure_space(this);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001255 EMIT(0xF6);
1256 emit_operand(eax, op);
Ben Murdochda12d292016-06-02 14:46:10 +01001257 emit_b(imm8);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001258}
1259
Ben Murdochda12d292016-06-02 14:46:10 +01001260void Assembler::test_w(Register reg, Immediate imm16) {
1261 DCHECK(imm16.is_int16() || imm16.is_uint16());
1262 EnsureSpace ensure_space(this);
1263 if (reg.is(eax)) {
1264 EMIT(0xA9);
1265 emit_w(imm16);
1266 } else {
1267 EMIT(0x66);
1268 EMIT(0xF7);
1269 EMIT(0xc0 | reg.code());
1270 emit_w(imm16);
1271 }
1272}
1273
1274void Assembler::test_w(Register reg, const Operand& op) {
1275 EnsureSpace ensure_space(this);
1276 EMIT(0x66);
1277 EMIT(0x85);
1278 emit_operand(reg, op);
1279}
1280
1281void Assembler::test_w(const Operand& op, Immediate imm16) {
1282 DCHECK(imm16.is_int16() || imm16.is_uint16());
1283 if (op.is_reg_only()) {
1284 test_w(op.reg(), imm16);
1285 return;
1286 }
1287 EnsureSpace ensure_space(this);
1288 EMIT(0x66);
1289 EMIT(0xF7);
1290 emit_operand(eax, op);
1291 emit_w(imm16);
1292}
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001293
Steve Blocka7e24c12009-10-30 11:49:00 +00001294void Assembler::xor_(Register dst, int32_t imm32) {
1295 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001296 emit_arith(6, Operand(dst), Immediate(imm32));
1297}
1298
1299
1300void Assembler::xor_(Register dst, const Operand& src) {
1301 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001302 EMIT(0x33);
1303 emit_operand(dst, src);
1304}
1305
1306
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001307void Assembler::xor_(const Operand& dst, Register src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001308 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001309 EMIT(0x31);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001310 emit_operand(src, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001311}
1312
1313
1314void Assembler::xor_(const Operand& dst, const Immediate& x) {
1315 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001316 emit_arith(6, dst, x);
1317}
1318
1319
1320void Assembler::bt(const Operand& dst, Register src) {
1321 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001322 EMIT(0x0F);
1323 EMIT(0xA3);
1324 emit_operand(src, dst);
1325}
1326
1327
1328void Assembler::bts(const Operand& dst, Register src) {
1329 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001330 EMIT(0x0F);
1331 EMIT(0xAB);
1332 emit_operand(src, dst);
1333}
1334
1335
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001336void Assembler::bsr(Register dst, const Operand& src) {
1337 EnsureSpace ensure_space(this);
1338 EMIT(0x0F);
1339 EMIT(0xBD);
1340 emit_operand(dst, src);
1341}
1342
1343
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001344void Assembler::bsf(Register dst, const Operand& src) {
1345 EnsureSpace ensure_space(this);
1346 EMIT(0x0F);
1347 EMIT(0xBC);
1348 emit_operand(dst, src);
1349}
1350
1351
Steve Blocka7e24c12009-10-30 11:49:00 +00001352void Assembler::hlt() {
1353 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001354 EMIT(0xF4);
1355}
1356
1357
1358void Assembler::int3() {
1359 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001360 EMIT(0xCC);
1361}
1362
1363
1364void Assembler::nop() {
1365 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001366 EMIT(0x90);
1367}
1368
1369
Steve Blocka7e24c12009-10-30 11:49:00 +00001370void Assembler::ret(int imm16) {
1371 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001372 DCHECK(is_uint16(imm16));
Steve Blocka7e24c12009-10-30 11:49:00 +00001373 if (imm16 == 0) {
1374 EMIT(0xC3);
1375 } else {
1376 EMIT(0xC2);
1377 EMIT(imm16 & 0xFF);
1378 EMIT((imm16 >> 8) & 0xFF);
1379 }
1380}
1381
1382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001383void Assembler::ud2() {
1384 EnsureSpace ensure_space(this);
1385 EMIT(0x0F);
1386 EMIT(0x0B);
1387}
1388
1389
Steve Blocka7e24c12009-10-30 11:49:00 +00001390// Labels refer to positions in the (to be) generated code.
1391// There are bound, linked, and unused labels.
1392//
1393// Bound labels refer to known positions in the already
1394// generated code. pos() is the position the label refers to.
1395//
1396// Linked labels refer to unknown positions in the code
1397// to be generated; pos() is the position of the 32bit
1398// Displacement of the last instruction using the label.
1399
1400
1401void Assembler::print(Label* L) {
1402 if (L->is_unused()) {
1403 PrintF("unused label\n");
1404 } else if (L->is_bound()) {
1405 PrintF("bound label to %d\n", L->pos());
1406 } else if (L->is_linked()) {
1407 Label l = *L;
1408 PrintF("unbound label");
1409 while (l.is_linked()) {
1410 Displacement disp = disp_at(&l);
1411 PrintF("@ %d ", l.pos());
1412 disp.print();
1413 PrintF("\n");
1414 disp.next(&l);
1415 }
1416 } else {
1417 PrintF("label in inconsistent state (pos = %d)\n", L->pos_);
1418 }
1419}
1420
1421
1422void Assembler::bind_to(Label* L, int pos) {
1423 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001424 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position
Steve Blocka7e24c12009-10-30 11:49:00 +00001425 while (L->is_linked()) {
1426 Displacement disp = disp_at(L);
1427 int fixup_pos = L->pos();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001428 if (disp.type() == Displacement::CODE_ABSOLUTE) {
1429 long_at_put(fixup_pos, reinterpret_cast<int>(buffer_ + pos));
1430 internal_reference_positions_.push_back(fixup_pos);
1431 } else if (disp.type() == Displacement::CODE_RELATIVE) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001432 // Relative to Code* heap object pointer.
1433 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag);
1434 } else {
1435 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001436 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected
Steve Blocka7e24c12009-10-30 11:49:00 +00001437 }
Andrei Popescu31002712010-02-23 13:46:05 +00001438 // Relative address, relative to point after address.
Steve Blocka7e24c12009-10-30 11:49:00 +00001439 int imm32 = pos - (fixup_pos + sizeof(int32_t));
1440 long_at_put(fixup_pos, imm32);
1441 }
1442 disp.next(L);
1443 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001444 while (L->is_near_linked()) {
1445 int fixup_pos = L->near_link_pos();
1446 int offset_to_next =
1447 static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001448 DCHECK(offset_to_next <= 0);
Ben Murdoch257744e2011-11-30 15:57:28 +00001449 // Relative address, relative to point after address.
1450 int disp = pos - fixup_pos - sizeof(int8_t);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001451 CHECK(0 <= disp && disp <= 127);
Ben Murdoch257744e2011-11-30 15:57:28 +00001452 set_byte_at(fixup_pos, disp);
1453 if (offset_to_next < 0) {
1454 L->link_to(fixup_pos + offset_to_next, Label::kNear);
1455 } else {
1456 L->UnuseNear();
1457 }
1458 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001459 L->bind_to(pos);
1460}
1461
1462
Steve Blocka7e24c12009-10-30 11:49:00 +00001463void Assembler::bind(Label* L) {
1464 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001465 DCHECK(!L->is_bound()); // label can only be bound once
Steve Blocka7e24c12009-10-30 11:49:00 +00001466 bind_to(L, pc_offset());
1467}
1468
1469
1470void Assembler::call(Label* L) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001471 positions_recorder()->WriteRecordedPositions();
Steve Blocka7e24c12009-10-30 11:49:00 +00001472 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001473 if (L->is_bound()) {
1474 const int long_size = 5;
1475 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001476 DCHECK(offs <= 0);
Andrei Popescu31002712010-02-23 13:46:05 +00001477 // 1110 1000 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001478 EMIT(0xE8);
1479 emit(offs - long_size);
1480 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001481 // 1110 1000 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001482 EMIT(0xE8);
1483 emit_disp(L, Displacement::OTHER);
1484 }
1485}
1486
1487
1488void Assembler::call(byte* entry, RelocInfo::Mode rmode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001489 positions_recorder()->WriteRecordedPositions();
Steve Blocka7e24c12009-10-30 11:49:00 +00001490 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001491 DCHECK(!RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001492 EMIT(0xE8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001493 if (RelocInfo::IsRuntimeEntry(rmode)) {
1494 emit(reinterpret_cast<uint32_t>(entry), rmode);
1495 } else {
1496 emit(entry - (pc_ + sizeof(int32_t)), rmode);
1497 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001498}
1499
1500
Ben Murdoch257744e2011-11-30 15:57:28 +00001501int Assembler::CallSize(const Operand& adr) {
1502 // Call size is 1 (opcode) + adr.len_ (operand).
1503 return 1 + adr.len_;
1504}
1505
1506
Steve Blocka7e24c12009-10-30 11:49:00 +00001507void Assembler::call(const Operand& adr) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001508 positions_recorder()->WriteRecordedPositions();
Steve Blocka7e24c12009-10-30 11:49:00 +00001509 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001510 EMIT(0xFF);
1511 emit_operand(edx, adr);
1512}
1513
1514
Ben Murdoch257744e2011-11-30 15:57:28 +00001515int Assembler::CallSize(Handle<Code> code, RelocInfo::Mode rmode) {
1516 return 1 /* EMIT */ + sizeof(uint32_t) /* emit */;
Steve Blocka7e24c12009-10-30 11:49:00 +00001517}
1518
1519
Ben Murdoch257744e2011-11-30 15:57:28 +00001520void Assembler::call(Handle<Code> code,
1521 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001522 TypeFeedbackId ast_id) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001523 positions_recorder()->WriteRecordedPositions();
Steve Blocka7e24c12009-10-30 11:49:00 +00001524 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001525 DCHECK(RelocInfo::IsCodeTarget(rmode)
1526 || rmode == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch257744e2011-11-30 15:57:28 +00001527 EMIT(0xE8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528 emit(code, rmode, ast_id);
Ben Murdoch257744e2011-11-30 15:57:28 +00001529}
1530
1531
1532void Assembler::jmp(Label* L, Label::Distance distance) {
1533 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001534 if (L->is_bound()) {
1535 const int short_size = 2;
1536 const int long_size = 5;
1537 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001538 DCHECK(offs <= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001539 if (is_int8(offs - short_size)) {
Andrei Popescu31002712010-02-23 13:46:05 +00001540 // 1110 1011 #8-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001541 EMIT(0xEB);
1542 EMIT((offs - short_size) & 0xFF);
1543 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001544 // 1110 1001 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001545 EMIT(0xE9);
1546 emit(offs - long_size);
1547 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001548 } else if (distance == Label::kNear) {
1549 EMIT(0xEB);
1550 emit_near_disp(L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001551 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001552 // 1110 1001 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001553 EMIT(0xE9);
1554 emit_disp(L, Displacement::UNCONDITIONAL_JUMP);
1555 }
1556}
1557
1558
1559void Assembler::jmp(byte* entry, RelocInfo::Mode rmode) {
1560 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001561 DCHECK(!RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001562 EMIT(0xE9);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001563 if (RelocInfo::IsRuntimeEntry(rmode)) {
1564 emit(reinterpret_cast<uint32_t>(entry), rmode);
1565 } else {
1566 emit(entry - (pc_ + sizeof(int32_t)), rmode);
1567 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001568}
1569
1570
1571void Assembler::jmp(const Operand& adr) {
1572 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001573 EMIT(0xFF);
1574 emit_operand(esp, adr);
1575}
1576
1577
1578void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) {
1579 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001580 DCHECK(RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001581 EMIT(0xE9);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001582 emit(code, rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001583}
1584
1585
Ben Murdoch257744e2011-11-30 15:57:28 +00001586void Assembler::j(Condition cc, Label* L, Label::Distance distance) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001587 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001588 DCHECK(0 <= cc && static_cast<int>(cc) < 16);
Steve Blocka7e24c12009-10-30 11:49:00 +00001589 if (L->is_bound()) {
1590 const int short_size = 2;
1591 const int long_size = 6;
1592 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001593 DCHECK(offs <= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001594 if (is_int8(offs - short_size)) {
1595 // 0111 tttn #8-bit disp
1596 EMIT(0x70 | cc);
1597 EMIT((offs - short_size) & 0xFF);
1598 } else {
1599 // 0000 1111 1000 tttn #32-bit disp
1600 EMIT(0x0F);
1601 EMIT(0x80 | cc);
1602 emit(offs - long_size);
1603 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001604 } else if (distance == Label::kNear) {
1605 EMIT(0x70 | cc);
1606 emit_near_disp(L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001607 } else {
1608 // 0000 1111 1000 tttn #32-bit disp
1609 // Note: could eliminate cond. jumps to this jump if condition
1610 // is the same however, seems to be rather unlikely case.
1611 EMIT(0x0F);
1612 EMIT(0x80 | cc);
1613 emit_disp(L, Displacement::OTHER);
1614 }
1615}
1616
1617
Ben Murdoch257744e2011-11-30 15:57:28 +00001618void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001619 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001620 DCHECK((0 <= cc) && (static_cast<int>(cc) < 16));
Andrei Popescu31002712010-02-23 13:46:05 +00001621 // 0000 1111 1000 tttn #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001622 EMIT(0x0F);
1623 EMIT(0x80 | cc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001624 if (RelocInfo::IsRuntimeEntry(rmode)) {
1625 emit(reinterpret_cast<uint32_t>(entry), rmode);
1626 } else {
1627 emit(entry - (pc_ + sizeof(int32_t)), rmode);
1628 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001629}
1630
1631
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001632void Assembler::j(Condition cc, Handle<Code> code, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001633 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001634 // 0000 1111 1000 tttn #32-bit disp
1635 EMIT(0x0F);
1636 EMIT(0x80 | cc);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001637 emit(code, rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001638}
1639
1640
Andrei Popescu31002712010-02-23 13:46:05 +00001641// FPU instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +00001642
Steve Blocka7e24c12009-10-30 11:49:00 +00001643void Assembler::fld(int i) {
1644 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001645 emit_farith(0xD9, 0xC0, i);
1646}
1647
1648
Andrei Popescu402d9372010-02-26 13:31:12 +00001649void Assembler::fstp(int i) {
1650 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001651 emit_farith(0xDD, 0xD8, i);
1652}
1653
1654
Steve Blocka7e24c12009-10-30 11:49:00 +00001655void Assembler::fld1() {
1656 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001657 EMIT(0xD9);
1658 EMIT(0xE8);
1659}
1660
1661
Andrei Popescu402d9372010-02-26 13:31:12 +00001662void Assembler::fldpi() {
1663 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001664 EMIT(0xD9);
1665 EMIT(0xEB);
1666}
1667
1668
Steve Blocka7e24c12009-10-30 11:49:00 +00001669void Assembler::fldz() {
1670 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001671 EMIT(0xD9);
1672 EMIT(0xEE);
1673}
1674
1675
Ben Murdochb0fe1622011-05-05 13:52:32 +01001676void Assembler::fldln2() {
1677 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001678 EMIT(0xD9);
1679 EMIT(0xED);
1680}
1681
1682
Steve Blocka7e24c12009-10-30 11:49:00 +00001683void Assembler::fld_s(const Operand& adr) {
1684 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001685 EMIT(0xD9);
1686 emit_operand(eax, adr);
1687}
1688
1689
1690void Assembler::fld_d(const Operand& adr) {
1691 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001692 EMIT(0xDD);
1693 emit_operand(eax, adr);
1694}
1695
1696
1697void Assembler::fstp_s(const Operand& adr) {
1698 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001699 EMIT(0xD9);
1700 emit_operand(ebx, adr);
1701}
1702
1703
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001704void Assembler::fst_s(const Operand& adr) {
1705 EnsureSpace ensure_space(this);
1706 EMIT(0xD9);
1707 emit_operand(edx, adr);
1708}
1709
1710
Steve Blocka7e24c12009-10-30 11:49:00 +00001711void Assembler::fstp_d(const Operand& adr) {
1712 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001713 EMIT(0xDD);
1714 emit_operand(ebx, adr);
1715}
1716
1717
Andrei Popescu402d9372010-02-26 13:31:12 +00001718void Assembler::fst_d(const Operand& adr) {
1719 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001720 EMIT(0xDD);
1721 emit_operand(edx, adr);
1722}
1723
1724
Steve Blocka7e24c12009-10-30 11:49:00 +00001725void Assembler::fild_s(const Operand& adr) {
1726 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001727 EMIT(0xDB);
1728 emit_operand(eax, adr);
1729}
1730
1731
1732void Assembler::fild_d(const Operand& adr) {
1733 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001734 EMIT(0xDF);
1735 emit_operand(ebp, adr);
1736}
1737
1738
1739void Assembler::fistp_s(const Operand& adr) {
1740 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001741 EMIT(0xDB);
1742 emit_operand(ebx, adr);
1743}
1744
1745
1746void Assembler::fisttp_s(const Operand& adr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001747 DCHECK(IsEnabled(SSE3));
Steve Blocka7e24c12009-10-30 11:49:00 +00001748 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001749 EMIT(0xDB);
1750 emit_operand(ecx, adr);
1751}
1752
1753
Leon Clarkee46be812010-01-19 14:06:41 +00001754void Assembler::fisttp_d(const Operand& adr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001755 DCHECK(IsEnabled(SSE3));
Leon Clarkee46be812010-01-19 14:06:41 +00001756 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00001757 EMIT(0xDD);
1758 emit_operand(ecx, adr);
1759}
1760
1761
Steve Blocka7e24c12009-10-30 11:49:00 +00001762void Assembler::fist_s(const Operand& adr) {
1763 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001764 EMIT(0xDB);
1765 emit_operand(edx, adr);
1766}
1767
1768
1769void Assembler::fistp_d(const Operand& adr) {
1770 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001771 EMIT(0xDF);
1772 emit_operand(edi, adr);
1773}
1774
1775
1776void Assembler::fabs() {
1777 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001778 EMIT(0xD9);
1779 EMIT(0xE1);
1780}
1781
1782
1783void Assembler::fchs() {
1784 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001785 EMIT(0xD9);
1786 EMIT(0xE0);
1787}
1788
1789
1790void Assembler::fcos() {
1791 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001792 EMIT(0xD9);
1793 EMIT(0xFF);
1794}
1795
1796
1797void Assembler::fsin() {
1798 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001799 EMIT(0xD9);
1800 EMIT(0xFE);
1801}
1802
1803
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001804void Assembler::fptan() {
1805 EnsureSpace ensure_space(this);
1806 EMIT(0xD9);
1807 EMIT(0xF2);
1808}
1809
1810
Ben Murdochb0fe1622011-05-05 13:52:32 +01001811void Assembler::fyl2x() {
1812 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001813 EMIT(0xD9);
1814 EMIT(0xF1);
1815}
1816
1817
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001818void Assembler::f2xm1() {
1819 EnsureSpace ensure_space(this);
1820 EMIT(0xD9);
1821 EMIT(0xF0);
1822}
1823
1824
1825void Assembler::fscale() {
1826 EnsureSpace ensure_space(this);
1827 EMIT(0xD9);
1828 EMIT(0xFD);
1829}
1830
1831
1832void Assembler::fninit() {
1833 EnsureSpace ensure_space(this);
1834 EMIT(0xDB);
1835 EMIT(0xE3);
1836}
1837
1838
Steve Blocka7e24c12009-10-30 11:49:00 +00001839void Assembler::fadd(int i) {
1840 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001841 emit_farith(0xDC, 0xC0, i);
1842}
1843
1844
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001845void Assembler::fadd_i(int i) {
1846 EnsureSpace ensure_space(this);
1847 emit_farith(0xD8, 0xC0, i);
1848}
1849
1850
Steve Blocka7e24c12009-10-30 11:49:00 +00001851void Assembler::fsub(int i) {
1852 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001853 emit_farith(0xDC, 0xE8, i);
1854}
1855
1856
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001857void Assembler::fsub_i(int i) {
1858 EnsureSpace ensure_space(this);
1859 emit_farith(0xD8, 0xE0, i);
1860}
1861
1862
Steve Blocka7e24c12009-10-30 11:49:00 +00001863void Assembler::fisub_s(const Operand& adr) {
1864 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001865 EMIT(0xDA);
1866 emit_operand(esp, adr);
1867}
1868
1869
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001870void Assembler::fmul_i(int i) {
1871 EnsureSpace ensure_space(this);
1872 emit_farith(0xD8, 0xC8, i);
1873}
1874
1875
Steve Blocka7e24c12009-10-30 11:49:00 +00001876void Assembler::fmul(int i) {
1877 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001878 emit_farith(0xDC, 0xC8, i);
1879}
1880
1881
1882void Assembler::fdiv(int i) {
1883 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001884 emit_farith(0xDC, 0xF8, i);
1885}
1886
1887
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001888void Assembler::fdiv_i(int i) {
1889 EnsureSpace ensure_space(this);
1890 emit_farith(0xD8, 0xF0, i);
1891}
1892
1893
Steve Blocka7e24c12009-10-30 11:49:00 +00001894void Assembler::faddp(int i) {
1895 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001896 emit_farith(0xDE, 0xC0, i);
1897}
1898
1899
1900void Assembler::fsubp(int i) {
1901 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001902 emit_farith(0xDE, 0xE8, i);
1903}
1904
1905
1906void Assembler::fsubrp(int i) {
1907 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001908 emit_farith(0xDE, 0xE0, i);
1909}
1910
1911
1912void Assembler::fmulp(int i) {
1913 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001914 emit_farith(0xDE, 0xC8, i);
1915}
1916
1917
1918void Assembler::fdivp(int i) {
1919 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001920 emit_farith(0xDE, 0xF8, i);
1921}
1922
1923
1924void Assembler::fprem() {
1925 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001926 EMIT(0xD9);
1927 EMIT(0xF8);
1928}
1929
1930
1931void Assembler::fprem1() {
1932 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001933 EMIT(0xD9);
1934 EMIT(0xF5);
1935}
1936
1937
1938void Assembler::fxch(int i) {
1939 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001940 emit_farith(0xD9, 0xC8, i);
1941}
1942
1943
1944void Assembler::fincstp() {
1945 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001946 EMIT(0xD9);
1947 EMIT(0xF7);
1948}
1949
1950
1951void Assembler::ffree(int i) {
1952 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001953 emit_farith(0xDD, 0xC0, i);
1954}
1955
1956
1957void Assembler::ftst() {
1958 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001959 EMIT(0xD9);
1960 EMIT(0xE4);
1961}
1962
1963
1964void Assembler::fucomp(int i) {
1965 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001966 emit_farith(0xDD, 0xE8, i);
1967}
1968
1969
1970void Assembler::fucompp() {
1971 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001972 EMIT(0xDA);
1973 EMIT(0xE9);
1974}
1975
1976
Steve Block3ce2e202009-11-05 08:53:23 +00001977void Assembler::fucomi(int i) {
1978 EnsureSpace ensure_space(this);
Steve Block3ce2e202009-11-05 08:53:23 +00001979 EMIT(0xDB);
1980 EMIT(0xE8 + i);
1981}
1982
1983
1984void Assembler::fucomip() {
1985 EnsureSpace ensure_space(this);
Steve Block3ce2e202009-11-05 08:53:23 +00001986 EMIT(0xDF);
1987 EMIT(0xE9);
1988}
1989
1990
Steve Blocka7e24c12009-10-30 11:49:00 +00001991void Assembler::fcompp() {
1992 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001993 EMIT(0xDE);
1994 EMIT(0xD9);
1995}
1996
1997
1998void Assembler::fnstsw_ax() {
1999 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002000 EMIT(0xDF);
2001 EMIT(0xE0);
2002}
2003
2004
2005void Assembler::fwait() {
2006 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002007 EMIT(0x9B);
2008}
2009
2010
2011void Assembler::frndint() {
2012 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002013 EMIT(0xD9);
2014 EMIT(0xFC);
2015}
2016
2017
2018void Assembler::fnclex() {
2019 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002020 EMIT(0xDB);
2021 EMIT(0xE2);
2022}
2023
2024
2025void Assembler::sahf() {
2026 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002027 EMIT(0x9E);
2028}
2029
2030
2031void Assembler::setcc(Condition cc, Register reg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002032 DCHECK(reg.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +00002033 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002034 EMIT(0x0F);
2035 EMIT(0x90 | cc);
2036 EMIT(0xC0 | reg.code());
2037}
2038
2039
2040void Assembler::cvttss2si(Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002041 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002042 EMIT(0xF3);
2043 EMIT(0x0F);
2044 EMIT(0x2C);
2045 emit_operand(dst, src);
2046}
2047
2048
2049void Assembler::cvttsd2si(Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002050 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002051 EMIT(0xF2);
2052 EMIT(0x0F);
2053 EMIT(0x2C);
2054 emit_operand(dst, src);
2055}
2056
2057
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002058void Assembler::cvtsd2si(Register dst, XMMRegister src) {
2059 EnsureSpace ensure_space(this);
2060 EMIT(0xF2);
2061 EMIT(0x0F);
2062 EMIT(0x2D);
2063 emit_sse_operand(dst, src);
2064}
2065
2066
Ben Murdoch097c5b22016-05-18 11:27:45 +01002067void Assembler::cvtsi2ss(XMMRegister dst, const Operand& src) {
2068 EnsureSpace ensure_space(this);
2069 EMIT(0xF3);
2070 EMIT(0x0F);
2071 EMIT(0x2A);
2072 emit_sse_operand(dst, src);
2073}
2074
2075
Steve Blocka7e24c12009-10-30 11:49:00 +00002076void Assembler::cvtsi2sd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002077 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002078 EMIT(0xF2);
2079 EMIT(0x0F);
2080 EMIT(0x2A);
2081 emit_sse_operand(dst, src);
2082}
2083
2084
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002085void Assembler::cvtss2sd(XMMRegister dst, const Operand& src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002086 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002087 EMIT(0xF3);
2088 EMIT(0x0F);
2089 EMIT(0x5A);
2090 emit_sse_operand(dst, src);
2091}
2092
2093
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002094void Assembler::cvtsd2ss(XMMRegister dst, const Operand& src) {
Steve Block44f0eee2011-05-26 01:26:41 +01002095 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002096 EMIT(0xF2);
2097 EMIT(0x0F);
2098 EMIT(0x5A);
2099 emit_sse_operand(dst, src);
2100}
2101
2102
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002103void Assembler::addsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002104 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002105 EMIT(0xF2);
2106 EMIT(0x0F);
2107 EMIT(0x58);
2108 emit_sse_operand(dst, src);
2109}
2110
2111
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002112void Assembler::mulsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002113 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002114 EMIT(0xF2);
2115 EMIT(0x0F);
2116 EMIT(0x59);
2117 emit_sse_operand(dst, src);
2118}
2119
2120
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002121void Assembler::subsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002122 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002123 EMIT(0xF2);
2124 EMIT(0x0F);
2125 EMIT(0x5C);
2126 emit_sse_operand(dst, src);
2127}
2128
2129
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002130void Assembler::divsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002131 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002132 EMIT(0xF2);
2133 EMIT(0x0F);
2134 EMIT(0x5E);
2135 emit_sse_operand(dst, src);
2136}
2137
2138
Leon Clarkee46be812010-01-19 14:06:41 +00002139void Assembler::xorpd(XMMRegister dst, XMMRegister src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002140 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002141 EMIT(0x66);
2142 EMIT(0x0F);
2143 EMIT(0x57);
2144 emit_sse_operand(dst, src);
2145}
2146
2147
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002148void Assembler::andps(XMMRegister dst, const Operand& src) {
2149 EnsureSpace ensure_space(this);
2150 EMIT(0x0F);
2151 EMIT(0x54);
2152 emit_sse_operand(dst, src);
2153}
2154
2155
2156void Assembler::orps(XMMRegister dst, const Operand& src) {
2157 EnsureSpace ensure_space(this);
2158 EMIT(0x0F);
2159 EMIT(0x56);
2160 emit_sse_operand(dst, src);
2161}
2162
2163
2164void Assembler::xorps(XMMRegister dst, const Operand& src) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002165 EnsureSpace ensure_space(this);
2166 EMIT(0x0F);
2167 EMIT(0x57);
2168 emit_sse_operand(dst, src);
2169}
2170
2171
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002172void Assembler::addps(XMMRegister dst, const Operand& src) {
2173 EnsureSpace ensure_space(this);
2174 EMIT(0x0F);
2175 EMIT(0x58);
2176 emit_sse_operand(dst, src);
2177}
2178
2179
2180void Assembler::subps(XMMRegister dst, const Operand& src) {
2181 EnsureSpace ensure_space(this);
2182 EMIT(0x0F);
2183 EMIT(0x5C);
2184 emit_sse_operand(dst, src);
2185}
2186
2187
2188void Assembler::mulps(XMMRegister dst, const Operand& src) {
2189 EnsureSpace ensure_space(this);
2190 EMIT(0x0F);
2191 EMIT(0x59);
2192 emit_sse_operand(dst, src);
2193}
2194
2195
2196void Assembler::divps(XMMRegister dst, const Operand& src) {
2197 EnsureSpace ensure_space(this);
2198 EMIT(0x0F);
2199 EMIT(0x5E);
2200 emit_sse_operand(dst, src);
2201}
2202
2203
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002204void Assembler::sqrtsd(XMMRegister dst, const Operand& src) {
2205 EnsureSpace ensure_space(this);
2206 EMIT(0xF2);
2207 EMIT(0x0F);
2208 EMIT(0x51);
2209 emit_sse_operand(dst, src);
2210}
2211
2212
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002213void Assembler::andpd(XMMRegister dst, XMMRegister src) {
2214 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002215 EMIT(0x66);
2216 EMIT(0x0F);
2217 EMIT(0x54);
2218 emit_sse_operand(dst, src);
2219}
2220
2221
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002222void Assembler::orpd(XMMRegister dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002223 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002224 EMIT(0x66);
2225 EMIT(0x0F);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002226 EMIT(0x56);
Steve Block6ded16b2010-05-10 14:33:55 +01002227 emit_sse_operand(dst, src);
2228}
2229
2230
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002231void Assembler::ucomisd(XMMRegister dst, const Operand& src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002232 EnsureSpace ensure_space(this);
2233 EMIT(0x66);
2234 EMIT(0x0F);
2235 EMIT(0x2E);
2236 emit_sse_operand(dst, src);
2237}
2238
2239
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002240void Assembler::roundss(XMMRegister dst, XMMRegister src, RoundingMode mode) {
2241 DCHECK(IsEnabled(SSE4_1));
2242 EnsureSpace ensure_space(this);
2243 EMIT(0x66);
2244 EMIT(0x0F);
2245 EMIT(0x3A);
2246 EMIT(0x0A);
2247 emit_sse_operand(dst, src);
2248 // Mask precision exeption.
2249 EMIT(static_cast<byte>(mode) | 0x8);
2250}
2251
2252
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002253void Assembler::roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002254 DCHECK(IsEnabled(SSE4_1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002255 EnsureSpace ensure_space(this);
2256 EMIT(0x66);
2257 EMIT(0x0F);
2258 EMIT(0x3A);
2259 EMIT(0x0B);
2260 emit_sse_operand(dst, src);
2261 // Mask precision exeption.
2262 EMIT(static_cast<byte>(mode) | 0x8);
2263}
2264
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002265
Steve Block6ded16b2010-05-10 14:33:55 +01002266void Assembler::movmskpd(Register dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002267 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002268 EMIT(0x66);
2269 EMIT(0x0F);
2270 EMIT(0x50);
2271 emit_sse_operand(dst, src);
2272}
2273
2274
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002275void Assembler::movmskps(Register dst, XMMRegister src) {
2276 EnsureSpace ensure_space(this);
2277 EMIT(0x0F);
2278 EMIT(0x50);
2279 emit_sse_operand(dst, src);
2280}
2281
2282
2283void Assembler::pcmpeqd(XMMRegister dst, XMMRegister src) {
2284 EnsureSpace ensure_space(this);
2285 EMIT(0x66);
2286 EMIT(0x0F);
2287 EMIT(0x76);
2288 emit_sse_operand(dst, src);
2289}
2290
2291
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002292void Assembler::punpckldq(XMMRegister dst, XMMRegister src) {
2293 EnsureSpace ensure_space(this);
2294 EMIT(0x66);
2295 EMIT(0x0F);
2296 EMIT(0x62);
2297 emit_sse_operand(dst, src);
2298}
2299
2300
2301void Assembler::punpckhdq(XMMRegister dst, XMMRegister src) {
2302 EnsureSpace ensure_space(this);
2303 EMIT(0x66);
2304 EMIT(0x0F);
2305 EMIT(0x6A);
2306 emit_sse_operand(dst, src);
2307}
2308
2309
2310void Assembler::maxsd(XMMRegister dst, const Operand& src) {
2311 EnsureSpace ensure_space(this);
2312 EMIT(0xF2);
2313 EMIT(0x0F);
2314 EMIT(0x5F);
2315 emit_sse_operand(dst, src);
2316}
2317
2318
2319void Assembler::minsd(XMMRegister dst, const Operand& src) {
2320 EnsureSpace ensure_space(this);
2321 EMIT(0xF2);
2322 EMIT(0x0F);
2323 EMIT(0x5D);
2324 emit_sse_operand(dst, src);
2325}
2326
2327
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002328void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002329 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002330 EMIT(0xF2);
2331 EMIT(0x0F);
2332 EMIT(0xC2);
2333 emit_sse_operand(dst, src);
2334 EMIT(1); // LT == 1
2335}
2336
2337
2338void Assembler::movaps(XMMRegister dst, XMMRegister src) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002339 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002340 EMIT(0x0F);
2341 EMIT(0x28);
2342 emit_sse_operand(dst, src);
2343}
2344
2345
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002346void Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) {
2347 DCHECK(is_uint8(imm8));
2348 EnsureSpace ensure_space(this);
2349 EMIT(0x0F);
2350 EMIT(0xC6);
2351 emit_sse_operand(dst, src);
2352 EMIT(imm8);
2353}
2354
2355
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002356void Assembler::movdqa(const Operand& dst, XMMRegister src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002357 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002358 EMIT(0x66);
2359 EMIT(0x0F);
2360 EMIT(0x7F);
2361 emit_sse_operand(src, dst);
2362}
2363
2364
2365void Assembler::movdqa(XMMRegister dst, const Operand& src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002366 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002367 EMIT(0x66);
2368 EMIT(0x0F);
2369 EMIT(0x6F);
2370 emit_sse_operand(dst, src);
2371}
2372
2373
2374void Assembler::movdqu(const Operand& dst, XMMRegister src ) {
Leon Clarkee46be812010-01-19 14:06:41 +00002375 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002376 EMIT(0xF3);
2377 EMIT(0x0F);
2378 EMIT(0x7F);
2379 emit_sse_operand(src, dst);
2380}
2381
2382
2383void Assembler::movdqu(XMMRegister dst, const Operand& src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002384 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002385 EMIT(0xF3);
2386 EMIT(0x0F);
2387 EMIT(0x6F);
2388 emit_sse_operand(dst, src);
2389}
2390
2391
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002392void Assembler::prefetch(const Operand& src, int level) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002393 DCHECK(is_uint2(level));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002394 EnsureSpace ensure_space(this);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002395 EMIT(0x0F);
2396 EMIT(0x18);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002397 // Emit hint number in Reg position of RegR/M.
2398 XMMRegister code = XMMRegister::from_code(level);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002399 emit_sse_operand(code, src);
2400}
2401
2402
Steve Blocka7e24c12009-10-30 11:49:00 +00002403void Assembler::movsd(const Operand& dst, XMMRegister src ) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002404 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002405 EMIT(0xF2); // double
2406 EMIT(0x0F);
2407 EMIT(0x11); // store
2408 emit_sse_operand(src, dst);
2409}
2410
2411
2412void Assembler::movsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002413 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002414 EMIT(0xF2); // double
2415 EMIT(0x0F);
2416 EMIT(0x10); // load
2417 emit_sse_operand(dst, src);
2418}
2419
Ben Murdochb0fe1622011-05-05 13:52:32 +01002420
Steve Block44f0eee2011-05-26 01:26:41 +01002421void Assembler::movss(const Operand& dst, XMMRegister src ) {
Steve Block44f0eee2011-05-26 01:26:41 +01002422 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002423 EMIT(0xF3); // float
2424 EMIT(0x0F);
2425 EMIT(0x11); // store
2426 emit_sse_operand(src, dst);
2427}
2428
2429
2430void Assembler::movss(XMMRegister dst, const Operand& src) {
Steve Block44f0eee2011-05-26 01:26:41 +01002431 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002432 EMIT(0xF3); // float
2433 EMIT(0x0F);
2434 EMIT(0x10); // load
2435 emit_sse_operand(dst, src);
2436}
2437
2438
Steve Block6ded16b2010-05-10 14:33:55 +01002439void Assembler::movd(XMMRegister dst, const Operand& src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002440 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002441 EMIT(0x66);
2442 EMIT(0x0F);
2443 EMIT(0x6E);
2444 emit_sse_operand(dst, src);
2445}
2446
2447
Ben Murdochb0fe1622011-05-05 13:52:32 +01002448void Assembler::movd(const Operand& dst, XMMRegister src) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002449 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002450 EMIT(0x66);
2451 EMIT(0x0F);
2452 EMIT(0x7E);
2453 emit_sse_operand(src, dst);
2454}
2455
2456
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002457void Assembler::extractps(Register dst, XMMRegister src, byte imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002458 DCHECK(IsEnabled(SSE4_1));
2459 DCHECK(is_uint8(imm8));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002460 EnsureSpace ensure_space(this);
2461 EMIT(0x66);
2462 EMIT(0x0F);
2463 EMIT(0x3A);
2464 EMIT(0x17);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002465 emit_sse_operand(src, dst);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002466 EMIT(imm8);
2467}
2468
2469
Ben Murdochb0fe1622011-05-05 13:52:32 +01002470void Assembler::pand(XMMRegister dst, XMMRegister src) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002471 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002472 EMIT(0x66);
2473 EMIT(0x0F);
2474 EMIT(0xDB);
2475 emit_sse_operand(dst, src);
2476}
2477
2478
Steve Block6ded16b2010-05-10 14:33:55 +01002479void Assembler::pxor(XMMRegister dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002480 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002481 EMIT(0x66);
2482 EMIT(0x0F);
2483 EMIT(0xEF);
2484 emit_sse_operand(dst, src);
2485}
2486
2487
Ben Murdochb8e0da22011-05-16 14:20:40 +01002488void Assembler::por(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002489 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002490 EMIT(0x66);
2491 EMIT(0x0F);
2492 EMIT(0xEB);
2493 emit_sse_operand(dst, src);
2494}
2495
2496
Steve Block6ded16b2010-05-10 14:33:55 +01002497void Assembler::ptest(XMMRegister dst, XMMRegister src) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002498 DCHECK(IsEnabled(SSE4_1));
Steve Block6ded16b2010-05-10 14:33:55 +01002499 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002500 EMIT(0x66);
2501 EMIT(0x0F);
2502 EMIT(0x38);
2503 EMIT(0x17);
2504 emit_sse_operand(dst, src);
2505}
2506
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002507
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002508void Assembler::pslld(XMMRegister reg, int8_t shift) {
2509 EnsureSpace ensure_space(this);
2510 EMIT(0x66);
2511 EMIT(0x0F);
2512 EMIT(0x72);
2513 emit_sse_operand(esi, reg); // esi == 6
2514 EMIT(shift);
2515}
2516
2517
2518void Assembler::psrld(XMMRegister reg, int8_t shift) {
2519 EnsureSpace ensure_space(this);
2520 EMIT(0x66);
2521 EMIT(0x0F);
2522 EMIT(0x72);
2523 emit_sse_operand(edx, reg); // edx == 2
2524 EMIT(shift);
2525}
2526
2527
Ben Murdochb0fe1622011-05-05 13:52:32 +01002528void Assembler::psllq(XMMRegister reg, int8_t shift) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002529 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002530 EMIT(0x66);
2531 EMIT(0x0F);
2532 EMIT(0x73);
2533 emit_sse_operand(esi, reg); // esi == 6
Ben Murdochb0fe1622011-05-05 13:52:32 +01002534 EMIT(shift);
2535}
2536
2537
Ben Murdochb8e0da22011-05-16 14:20:40 +01002538void Assembler::psllq(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002539 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002540 EMIT(0x66);
2541 EMIT(0x0F);
2542 EMIT(0xF3);
2543 emit_sse_operand(dst, src);
2544}
2545
2546
2547void Assembler::psrlq(XMMRegister reg, int8_t shift) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002548 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002549 EMIT(0x66);
2550 EMIT(0x0F);
2551 EMIT(0x73);
2552 emit_sse_operand(edx, reg); // edx == 2
2553 EMIT(shift);
2554}
2555
2556
2557void Assembler::psrlq(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002558 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002559 EMIT(0x66);
2560 EMIT(0x0F);
2561 EMIT(0xD3);
2562 emit_sse_operand(dst, src);
2563}
2564
2565
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002566void Assembler::pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002567 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002568 EMIT(0x66);
2569 EMIT(0x0F);
2570 EMIT(0x70);
2571 emit_sse_operand(dst, src);
2572 EMIT(shuffle);
2573}
2574
2575
2576void Assembler::pextrd(const Operand& dst, XMMRegister src, int8_t offset) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002577 DCHECK(IsEnabled(SSE4_1));
Ben Murdochb0fe1622011-05-05 13:52:32 +01002578 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002579 EMIT(0x66);
2580 EMIT(0x0F);
2581 EMIT(0x3A);
2582 EMIT(0x16);
2583 emit_sse_operand(src, dst);
2584 EMIT(offset);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002585}
2586
2587
Steve Block1e0659c2011-05-24 12:43:12 +01002588void Assembler::pinsrd(XMMRegister dst, const Operand& src, int8_t offset) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002589 DCHECK(IsEnabled(SSE4_1));
Steve Block1e0659c2011-05-24 12:43:12 +01002590 EnsureSpace ensure_space(this);
Steve Block1e0659c2011-05-24 12:43:12 +01002591 EMIT(0x66);
2592 EMIT(0x0F);
2593 EMIT(0x3A);
2594 EMIT(0x22);
2595 emit_sse_operand(dst, src);
2596 EMIT(offset);
2597}
2598
2599
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002600void Assembler::addss(XMMRegister dst, const Operand& src) {
2601 EnsureSpace ensure_space(this);
2602 EMIT(0xF3);
2603 EMIT(0x0F);
2604 EMIT(0x58);
2605 emit_sse_operand(dst, src);
2606}
2607
2608
2609void Assembler::subss(XMMRegister dst, const Operand& src) {
2610 EnsureSpace ensure_space(this);
2611 EMIT(0xF3);
2612 EMIT(0x0F);
2613 EMIT(0x5C);
2614 emit_sse_operand(dst, src);
2615}
2616
2617
2618void Assembler::mulss(XMMRegister dst, const Operand& src) {
2619 EnsureSpace ensure_space(this);
2620 EMIT(0xF3);
2621 EMIT(0x0F);
2622 EMIT(0x59);
2623 emit_sse_operand(dst, src);
2624}
2625
2626
2627void Assembler::divss(XMMRegister dst, const Operand& src) {
2628 EnsureSpace ensure_space(this);
2629 EMIT(0xF3);
2630 EMIT(0x0F);
2631 EMIT(0x5E);
2632 emit_sse_operand(dst, src);
2633}
2634
2635
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002636void Assembler::sqrtss(XMMRegister dst, const Operand& src) {
2637 EnsureSpace ensure_space(this);
2638 EMIT(0xF3);
2639 EMIT(0x0F);
2640 EMIT(0x51);
2641 emit_sse_operand(dst, src);
2642}
2643
2644
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002645void Assembler::ucomiss(XMMRegister dst, const Operand& src) {
2646 EnsureSpace ensure_space(this);
2647 EMIT(0x0f);
2648 EMIT(0x2e);
2649 emit_sse_operand(dst, src);
2650}
2651
2652
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002653void Assembler::maxss(XMMRegister dst, const Operand& src) {
2654 EnsureSpace ensure_space(this);
2655 EMIT(0xF3);
2656 EMIT(0x0F);
2657 EMIT(0x5F);
2658 emit_sse_operand(dst, src);
2659}
2660
2661
2662void Assembler::minss(XMMRegister dst, const Operand& src) {
2663 EnsureSpace ensure_space(this);
2664 EMIT(0xF3);
2665 EMIT(0x0F);
2666 EMIT(0x5D);
2667 emit_sse_operand(dst, src);
2668}
2669
2670
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002671// AVX instructions
2672void Assembler::vfmasd(byte op, XMMRegister dst, XMMRegister src1,
2673 const Operand& src2) {
2674 DCHECK(IsEnabled(FMA3));
2675 EnsureSpace ensure_space(this);
2676 emit_vex_prefix(src1, kLIG, k66, k0F38, kW1);
2677 EMIT(op);
2678 emit_sse_operand(dst, src2);
2679}
2680
2681
2682void Assembler::vfmass(byte op, XMMRegister dst, XMMRegister src1,
2683 const Operand& src2) {
2684 DCHECK(IsEnabled(FMA3));
2685 EnsureSpace ensure_space(this);
2686 emit_vex_prefix(src1, kLIG, k66, k0F38, kW0);
2687 EMIT(op);
2688 emit_sse_operand(dst, src2);
2689}
2690
2691
2692void Assembler::vsd(byte op, XMMRegister dst, XMMRegister src1,
2693 const Operand& src2) {
2694 DCHECK(IsEnabled(AVX));
2695 EnsureSpace ensure_space(this);
2696 emit_vex_prefix(src1, kLIG, kF2, k0F, kWIG);
2697 EMIT(op);
2698 emit_sse_operand(dst, src2);
2699}
2700
2701
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002702void Assembler::vss(byte op, XMMRegister dst, XMMRegister src1,
2703 const Operand& src2) {
2704 DCHECK(IsEnabled(AVX));
2705 EnsureSpace ensure_space(this);
2706 emit_vex_prefix(src1, kLIG, kF3, k0F, kWIG);
2707 EMIT(op);
2708 emit_sse_operand(dst, src2);
2709}
2710
2711
2712void Assembler::vps(byte op, XMMRegister dst, XMMRegister src1,
2713 const Operand& src2) {
2714 DCHECK(IsEnabled(AVX));
2715 EnsureSpace ensure_space(this);
2716 emit_vex_prefix(src1, kL128, kNone, k0F, kWIG);
2717 EMIT(op);
2718 emit_sse_operand(dst, src2);
2719}
2720
2721
2722void Assembler::vpd(byte op, XMMRegister dst, XMMRegister src1,
2723 const Operand& src2) {
2724 DCHECK(IsEnabled(AVX));
2725 EnsureSpace ensure_space(this);
2726 emit_vex_prefix(src1, kL128, k66, k0F, kWIG);
2727 EMIT(op);
2728 emit_sse_operand(dst, src2);
2729}
2730
2731
2732void Assembler::bmi1(byte op, Register reg, Register vreg, const Operand& rm) {
2733 DCHECK(IsEnabled(BMI1));
2734 EnsureSpace ensure_space(this);
2735 emit_vex_prefix(vreg, kLZ, kNone, k0F38, kW0);
2736 EMIT(op);
2737 emit_operand(reg, rm);
2738}
2739
2740
2741void Assembler::tzcnt(Register dst, const Operand& src) {
2742 DCHECK(IsEnabled(BMI1));
2743 EnsureSpace ensure_space(this);
2744 EMIT(0xF3);
2745 EMIT(0x0F);
2746 EMIT(0xBC);
2747 emit_operand(dst, src);
2748}
2749
2750
2751void Assembler::lzcnt(Register dst, const Operand& src) {
2752 DCHECK(IsEnabled(LZCNT));
2753 EnsureSpace ensure_space(this);
2754 EMIT(0xF3);
2755 EMIT(0x0F);
2756 EMIT(0xBD);
2757 emit_operand(dst, src);
2758}
2759
2760
2761void Assembler::popcnt(Register dst, const Operand& src) {
2762 DCHECK(IsEnabled(POPCNT));
2763 EnsureSpace ensure_space(this);
2764 EMIT(0xF3);
2765 EMIT(0x0F);
2766 EMIT(0xB8);
2767 emit_operand(dst, src);
2768}
2769
2770
2771void Assembler::bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
2772 const Operand& rm) {
2773 DCHECK(IsEnabled(BMI2));
2774 EnsureSpace ensure_space(this);
2775 emit_vex_prefix(vreg, kLZ, pp, k0F38, kW0);
2776 EMIT(op);
2777 emit_operand(reg, rm);
2778}
2779
2780
2781void Assembler::rorx(Register dst, const Operand& src, byte imm8) {
2782 DCHECK(IsEnabled(BMI2));
2783 DCHECK(is_uint8(imm8));
2784 Register vreg = {0}; // VEX.vvvv unused
2785 EnsureSpace ensure_space(this);
2786 emit_vex_prefix(vreg, kLZ, kF2, k0F3A, kW0);
2787 EMIT(0xF0);
2788 emit_operand(dst, src);
2789 EMIT(imm8);
2790}
2791
2792
Steve Blocka7e24c12009-10-30 11:49:00 +00002793void Assembler::emit_sse_operand(XMMRegister reg, const Operand& adr) {
2794 Register ireg = { reg.code() };
2795 emit_operand(ireg, adr);
2796}
2797
2798
2799void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
2800 EMIT(0xC0 | dst.code() << 3 | src.code());
2801}
2802
2803
Steve Block6ded16b2010-05-10 14:33:55 +01002804void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
2805 EMIT(0xC0 | dst.code() << 3 | src.code());
2806}
2807
2808
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002809void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
2810 EMIT(0xC0 | (dst.code() << 3) | src.code());
2811}
2812
2813
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002814void Assembler::emit_vex_prefix(XMMRegister vreg, VectorLength l, SIMDPrefix pp,
2815 LeadingOpcode mm, VexW w) {
2816 if (mm != k0F || w != kW0) {
2817 EMIT(0xc4);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002818 // Change RXB from "110" to "111" to align with gdb disassembler.
2819 EMIT(0xe0 | mm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002820 EMIT(w | ((~vreg.code() & 0xf) << 3) | l | pp);
2821 } else {
2822 EMIT(0xc5);
2823 EMIT(((~vreg.code()) << 3) | l | pp);
2824 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002825}
2826
2827
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002828void Assembler::emit_vex_prefix(Register vreg, VectorLength l, SIMDPrefix pp,
2829 LeadingOpcode mm, VexW w) {
2830 XMMRegister ivreg = {vreg.code()};
2831 emit_vex_prefix(ivreg, l, pp, mm, w);
Steve Blocka7e24c12009-10-30 11:49:00 +00002832}
2833
2834
Steve Blocka7e24c12009-10-30 11:49:00 +00002835void Assembler::GrowBuffer() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002836 DCHECK(buffer_overflow());
Steve Blocka7e24c12009-10-30 11:49:00 +00002837 if (!own_buffer_) FATAL("external code buffer is too small");
2838
Andrei Popescu31002712010-02-23 13:46:05 +00002839 // Compute new buffer size.
Steve Blocka7e24c12009-10-30 11:49:00 +00002840 CodeDesc desc; // the new buffer
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002841 desc.buffer_size = 2 * buffer_size_;
2842
Steve Blocka7e24c12009-10-30 11:49:00 +00002843 // Some internal data structures overflow for very large buffers,
2844 // they must ensure that kMaximalBufferSize is not too large.
2845 if ((desc.buffer_size > kMaximalBufferSize) ||
Steve Block44f0eee2011-05-26 01:26:41 +01002846 (desc.buffer_size > isolate()->heap()->MaxOldGenerationSize())) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002847 V8::FatalProcessOutOfMemory("Assembler::GrowBuffer");
2848 }
2849
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002850 // Set up new buffer.
Steve Blocka7e24c12009-10-30 11:49:00 +00002851 desc.buffer = NewArray<byte>(desc.buffer_size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002852 desc.origin = this;
Steve Blocka7e24c12009-10-30 11:49:00 +00002853 desc.instr_size = pc_offset();
2854 desc.reloc_size = (buffer_ + buffer_size_) - (reloc_info_writer.pos());
2855
2856 // Clear the buffer in debug mode. Use 'int3' instructions to make
2857 // sure to get into problems if we ever run uninitialized code.
2858#ifdef DEBUG
2859 memset(desc.buffer, 0xCC, desc.buffer_size);
2860#endif
2861
Andrei Popescu31002712010-02-23 13:46:05 +00002862 // Copy the data.
Steve Blocka7e24c12009-10-30 11:49:00 +00002863 int pc_delta = desc.buffer - buffer_;
2864 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002865 MemMove(desc.buffer, buffer_, desc.instr_size);
2866 MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(),
2867 desc.reloc_size);
Steve Blocka7e24c12009-10-30 11:49:00 +00002868
Andrei Popescu31002712010-02-23 13:46:05 +00002869 // Switch buffers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002870 DeleteArray(buffer_);
Steve Blocka7e24c12009-10-30 11:49:00 +00002871 buffer_ = desc.buffer;
2872 buffer_size_ = desc.buffer_size;
2873 pc_ += pc_delta;
Steve Blocka7e24c12009-10-30 11:49:00 +00002874 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
2875 reloc_info_writer.last_pc() + pc_delta);
2876
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002877 // Relocate internal references.
2878 for (auto pos : internal_reference_positions_) {
2879 int32_t* p = reinterpret_cast<int32_t*>(buffer_ + pos);
2880 *p += pc_delta;
Steve Blocka7e24c12009-10-30 11:49:00 +00002881 }
2882
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002883 DCHECK(!buffer_overflow());
Steve Blocka7e24c12009-10-30 11:49:00 +00002884}
2885
2886
2887void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002888 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode
2889 DCHECK(is_uint8(imm8));
2890 DCHECK((op1 & 0x01) == 0); // should be 8bit operation
Steve Blocka7e24c12009-10-30 11:49:00 +00002891 EMIT(op1);
2892 EMIT(op2 | dst.code());
2893 EMIT(imm8);
2894}
2895
2896
2897void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002898 DCHECK((0 <= sel) && (sel <= 7));
Steve Blocka7e24c12009-10-30 11:49:00 +00002899 Register ireg = { sel };
2900 if (x.is_int8()) {
2901 EMIT(0x83); // using a sign-extended 8-bit immediate.
2902 emit_operand(ireg, dst);
2903 EMIT(x.x_ & 0xFF);
2904 } else if (dst.is_reg(eax)) {
2905 EMIT((sel << 3) | 0x05); // short form if the destination is eax.
2906 emit(x);
2907 } else {
2908 EMIT(0x81); // using a literal 32-bit immediate.
2909 emit_operand(ireg, dst);
2910 emit(x);
2911 }
2912}
2913
2914
2915void Assembler::emit_operand(Register reg, const Operand& adr) {
2916 const unsigned length = adr.len_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002917 DCHECK(length > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00002918
2919 // Emit updated ModRM byte containing the given register.
2920 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3);
2921
2922 // Emit the rest of the encoded operand.
2923 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
2924 pc_ += length;
2925
2926 // Emit relocation information if necessary.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002927 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002928 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32
2929 RecordRelocInfo(adr.rmode_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002930 if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels
2931 emit_label(*reinterpret_cast<Label**>(pc_));
2932 } else {
2933 pc_ += sizeof(int32_t);
2934 }
2935 }
2936}
2937
2938
2939void Assembler::emit_label(Label* label) {
2940 if (label->is_bound()) {
2941 internal_reference_positions_.push_back(pc_offset());
2942 emit(reinterpret_cast<uint32_t>(buffer_ + label->pos()));
2943 } else {
2944 emit_disp(label, Displacement::CODE_ABSOLUTE);
Steve Blocka7e24c12009-10-30 11:49:00 +00002945 }
2946}
2947
2948
2949void Assembler::emit_farith(int b1, int b2, int i) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002950 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode
2951 DCHECK(0 <= i && i < 8); // illegal stack offset
Steve Blocka7e24c12009-10-30 11:49:00 +00002952 EMIT(b1);
2953 EMIT(b2 + i);
2954}
2955
2956
Ben Murdochb0fe1622011-05-05 13:52:32 +01002957void Assembler::db(uint8_t data) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002958 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002959 EMIT(data);
2960}
2961
2962
2963void Assembler::dd(uint32_t data) {
2964 EnsureSpace ensure_space(this);
2965 emit(data);
Steve Blocka7e24c12009-10-30 11:49:00 +00002966}
2967
2968
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002969void Assembler::dq(uint64_t data) {
2970 EnsureSpace ensure_space(this);
2971 emit_q(data);
2972}
2973
2974
2975void Assembler::dd(Label* label) {
2976 EnsureSpace ensure_space(this);
2977 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE);
2978 emit_label(label);
2979}
2980
2981
Steve Blocka7e24c12009-10-30 11:49:00 +00002982void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002983 DCHECK(!RelocInfo::IsNone(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00002984 // Don't record external references unless the heap will be serialized.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002985 if (rmode == RelocInfo::EXTERNAL_REFERENCE &&
2986 !serializer_enabled() && !emit_debug_code()) {
2987 return;
Steve Blocka7e24c12009-10-30 11:49:00 +00002988 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002989 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +00002990 reloc_info_writer.Write(&rinfo);
2991}
2992
2993
2994#ifdef GENERATED_CODE_COVERAGE
2995static FILE* coverage_log = NULL;
2996
2997
2998static void InitCoverageLog() {
2999 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG");
3000 if (file_name != NULL) {
3001 coverage_log = fopen(file_name, "aw+");
3002 }
3003}
3004
3005
3006void LogGeneratedCodeCoverage(const char* file_line) {
3007 const char* return_address = (&file_line)[-1];
3008 char* push_insn = const_cast<char*>(return_address - 12);
3009 push_insn[0] = 0xeb; // Relative branch insn.
3010 push_insn[1] = 13; // Skip over coverage insns.
3011 if (coverage_log != NULL) {
3012 fprintf(coverage_log, "%s\n", file_line);
3013 fflush(coverage_log);
3014 }
3015}
3016
3017#endif
3018
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003019} // namespace internal
3020} // namespace v8
Leon Clarkef7060e22010-06-03 12:02:55 +01003021
3022#endif // V8_TARGET_ARCH_IA32