blob: 925ae48c5e8659b3a619a51d1eab16420219c15a [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
Ben Murdochc5610432016-08-08 18:44:38 +0100189Address RelocInfo::wasm_memory_reference() {
190 DCHECK(IsWasmMemoryReference(rmode_));
191 return Memory::Address_at(pc_);
192}
193
Ben Murdoch61f157c2016-09-16 13:49:30 +0100194Address RelocInfo::wasm_global_reference() {
195 DCHECK(IsWasmGlobalReference(rmode_));
196 return Memory::Address_at(pc_);
197}
198
Ben Murdochc5610432016-08-08 18:44:38 +0100199uint32_t RelocInfo::wasm_memory_size_reference() {
200 DCHECK(IsWasmMemorySizeReference(rmode_));
201 return Memory::uint32_at(pc_);
202}
203
Ben Murdoch61f157c2016-09-16 13:49:30 +0100204void RelocInfo::unchecked_update_wasm_memory_reference(
205 Address address, ICacheFlushMode flush_mode) {
206 Memory::Address_at(pc_) = address;
207}
208
209void RelocInfo::unchecked_update_wasm_memory_size(uint32_t size,
210 ICacheFlushMode flush_mode) {
211 Memory::uint32_at(pc_) = size;
Ben Murdochc5610432016-08-08 18:44:38 +0100212}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000213
Steve Blocka7e24c12009-10-30 11:49:00 +0000214// -----------------------------------------------------------------------------
215// Implementation of Operand
216
217Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) {
218 // [base + disp/r]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000219 if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 // [base]
221 set_modrm(0, base);
222 if (base.is(esp)) set_sib(times_1, esp, base);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000223 } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000224 // [base + disp8]
225 set_modrm(1, base);
226 if (base.is(esp)) set_sib(times_1, esp, base);
227 set_disp8(disp);
228 } else {
229 // [base + disp/r]
230 set_modrm(2, base);
231 if (base.is(esp)) set_sib(times_1, esp, base);
232 set_dispr(disp, rmode);
233 }
234}
235
236
237Operand::Operand(Register base,
238 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 // [base + index*scale + disp/r]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244 if (disp == 0 && RelocInfo::IsNone(rmode) && !base.is(ebp)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000245 // [base + index*scale]
246 set_modrm(0, esp);
247 set_sib(scale, index, base);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 } else if (is_int8(disp) && RelocInfo::IsNone(rmode)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 // [base + index*scale + disp8]
250 set_modrm(1, esp);
251 set_sib(scale, index, base);
252 set_disp8(disp);
253 } else {
254 // [base + index*scale + disp/r]
255 set_modrm(2, esp);
256 set_sib(scale, index, base);
257 set_dispr(disp, rmode);
258 }
259}
260
261
262Operand::Operand(Register index,
263 ScaleFactor scale,
264 int32_t disp,
265 RelocInfo::Mode rmode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266 DCHECK(!index.is(esp)); // illegal addressing mode
Steve Blocka7e24c12009-10-30 11:49:00 +0000267 // [index*scale + disp/r]
268 set_modrm(0, esp);
269 set_sib(scale, index, ebp);
270 set_dispr(disp, rmode);
271}
272
273
274bool Operand::is_reg(Register reg) const {
275 return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only.
276 && ((buf_[0] & 0x07) == reg.code()); // register codes match.
277}
278
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100279
280bool Operand::is_reg_only() const {
281 return (buf_[0] & 0xF8) == 0xC0; // Addressing mode is register only.
282}
283
284
285Register Operand::reg() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 DCHECK(is_reg_only());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100287 return Register::from_code(buf_[0] & 0x07);
288}
289
290
Steve Blocka7e24c12009-10-30 11:49:00 +0000291// -----------------------------------------------------------------------------
Andrei Popescu31002712010-02-23 13:46:05 +0000292// Implementation of Assembler.
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
294// Emit a single byte. Must always be inlined.
295#define EMIT(x) \
296 *pc_++ = (x)
297
298
299#ifdef GENERATED_CODE_COVERAGE
300static void InitCoverageLog();
301#endif
302
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
304 : AssemblerBase(isolate, buffer, buffer_size),
305 positions_recorder_(this) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 // Clear the buffer in debug mode unless it was provided by the
307 // caller in which case we can't be sure it's okay to overwrite
308 // existing code in it; see CodePatcher::CodePatcher(...).
309#ifdef DEBUG
310 if (own_buffer_) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 memset(buffer_, 0xCC, buffer_size_); // int3
Steve Blocka7e24c12009-10-30 11:49:00 +0000312 }
313#endif
314
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000315 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000316
Steve Blocka7e24c12009-10-30 11:49:00 +0000317#ifdef GENERATED_CODE_COVERAGE
318 InitCoverageLog();
319#endif
320}
321
322
Steve Blocka7e24c12009-10-30 11:49:00 +0000323void Assembler::GetCode(CodeDesc* desc) {
Andrei Popescu31002712010-02-23 13:46:05 +0000324 // Finalize code (at this point overflow() may be true, but the gap ensures
325 // that we are still not overlapping instructions and relocation info).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326 reloc_info_writer.Finish();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100328 // Set up code descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 desc->buffer = buffer_;
330 desc->buffer_size = buffer_size_;
331 desc->instr_size = pc_offset();
332 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
333 desc->origin = this;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000334 desc->constant_pool_size = 0;
Ben Murdoch61f157c2016-09-16 13:49:30 +0100335 desc->unwinding_info_size = 0;
336 desc->unwinding_info = nullptr;
Steve Blocka7e24c12009-10-30 11:49:00 +0000337}
338
339
340void Assembler::Align(int m) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000341 DCHECK(base::bits::IsPowerOfTwo32(m));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100342 int mask = m - 1;
343 int addr = pc_offset();
344 Nop((m - (addr & mask)) & mask);
345}
346
347
348bool Assembler::IsNop(Address addr) {
349 Address a = addr;
350 while (*a == 0x66) a++;
351 if (*a == 0x90) return true;
352 if (a[0] == 0xf && a[1] == 0x1f) return true;
353 return false;
354}
355
356
357void Assembler::Nop(int bytes) {
358 EnsureSpace ensure_space(this);
359
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100360 // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf
361 while (bytes > 0) {
362 switch (bytes) {
363 case 2:
364 EMIT(0x66);
365 case 1:
366 EMIT(0x90);
367 return;
368 case 3:
369 EMIT(0xf);
370 EMIT(0x1f);
371 EMIT(0);
372 return;
373 case 4:
374 EMIT(0xf);
375 EMIT(0x1f);
376 EMIT(0x40);
377 EMIT(0);
378 return;
379 case 6:
380 EMIT(0x66);
381 case 5:
382 EMIT(0xf);
383 EMIT(0x1f);
384 EMIT(0x44);
385 EMIT(0);
386 EMIT(0);
387 return;
388 case 7:
389 EMIT(0xf);
390 EMIT(0x1f);
391 EMIT(0x80);
392 EMIT(0);
393 EMIT(0);
394 EMIT(0);
395 EMIT(0);
396 return;
397 default:
398 case 11:
399 EMIT(0x66);
400 bytes--;
401 case 10:
402 EMIT(0x66);
403 bytes--;
404 case 9:
405 EMIT(0x66);
406 bytes--;
407 case 8:
408 EMIT(0xf);
409 EMIT(0x1f);
410 EMIT(0x84);
411 EMIT(0);
412 EMIT(0);
413 EMIT(0);
414 EMIT(0);
415 EMIT(0);
416 bytes -= 8;
417 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000418 }
419}
420
421
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100422void Assembler::CodeTargetAlign() {
423 Align(16); // Preferred alignment of jump targets on ia32.
424}
425
426
Steve Blocka7e24c12009-10-30 11:49:00 +0000427void Assembler::cpuid() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000429 EMIT(0x0F);
430 EMIT(0xA2);
431}
432
433
434void Assembler::pushad() {
435 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000436 EMIT(0x60);
437}
438
439
440void Assembler::popad() {
441 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000442 EMIT(0x61);
443}
444
445
446void Assembler::pushfd() {
447 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 EMIT(0x9C);
449}
450
451
452void Assembler::popfd() {
453 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 EMIT(0x9D);
455}
456
457
458void Assembler::push(const Immediate& x) {
459 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000460 if (x.is_int8()) {
461 EMIT(0x6a);
462 EMIT(x.x_);
463 } else {
464 EMIT(0x68);
465 emit(x);
466 }
467}
468
469
Ben Murdochb0fe1622011-05-05 13:52:32 +0100470void Assembler::push_imm32(int32_t imm32) {
471 EnsureSpace ensure_space(this);
472 EMIT(0x68);
473 emit(imm32);
474}
475
476
Steve Blocka7e24c12009-10-30 11:49:00 +0000477void Assembler::push(Register src) {
478 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000479 EMIT(0x50 | src.code());
480}
481
482
483void Assembler::push(const Operand& src) {
484 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000485 EMIT(0xFF);
486 emit_operand(esi, src);
487}
488
489
490void Assembler::pop(Register dst) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000491 DCHECK(reloc_info_writer.last_pc() != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000492 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 EMIT(0x58 | dst.code());
494}
495
496
497void Assembler::pop(const Operand& dst) {
498 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 EMIT(0x8F);
500 emit_operand(eax, dst);
501}
502
503
504void Assembler::enter(const Immediate& size) {
505 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000506 EMIT(0xC8);
507 emit_w(size);
508 EMIT(0);
509}
510
511
512void Assembler::leave() {
513 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 EMIT(0xC9);
515}
516
517
518void Assembler::mov_b(Register dst, const Operand& src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100519 CHECK(dst.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000520 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000521 EMIT(0x8A);
522 emit_operand(dst, src);
523}
524
525
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400526void Assembler::mov_b(const Operand& dst, const Immediate& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000527 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 EMIT(0xC6);
529 emit_operand(eax, dst);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400530 EMIT(static_cast<int8_t>(src.x_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000531}
532
533
534void Assembler::mov_b(const Operand& dst, Register src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100535 CHECK(src.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000536 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 EMIT(0x88);
538 emit_operand(src, dst);
539}
540
541
542void Assembler::mov_w(Register dst, const Operand& src) {
543 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000544 EMIT(0x66);
545 EMIT(0x8B);
546 emit_operand(dst, src);
547}
548
549
550void Assembler::mov_w(const Operand& dst, Register src) {
551 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000552 EMIT(0x66);
553 EMIT(0x89);
554 emit_operand(src, dst);
555}
556
557
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400558void Assembler::mov_w(const Operand& dst, const Immediate& src) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000559 EnsureSpace ensure_space(this);
560 EMIT(0x66);
561 EMIT(0xC7);
562 emit_operand(eax, dst);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400563 EMIT(static_cast<int8_t>(src.x_ & 0xff));
564 EMIT(static_cast<int8_t>(src.x_ >> 8));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565}
566
567
Steve Blocka7e24c12009-10-30 11:49:00 +0000568void Assembler::mov(Register dst, int32_t imm32) {
569 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000570 EMIT(0xB8 | dst.code());
571 emit(imm32);
572}
573
574
575void Assembler::mov(Register dst, const Immediate& x) {
576 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000577 EMIT(0xB8 | dst.code());
578 emit(x);
579}
580
581
582void Assembler::mov(Register dst, Handle<Object> handle) {
583 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000584 EMIT(0xB8 | dst.code());
585 emit(handle);
586}
587
588
589void Assembler::mov(Register dst, const Operand& src) {
590 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000591 EMIT(0x8B);
592 emit_operand(dst, src);
593}
594
595
596void Assembler::mov(Register dst, Register src) {
597 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000598 EMIT(0x89);
599 EMIT(0xC0 | src.code() << 3 | dst.code());
600}
601
602
603void Assembler::mov(const Operand& dst, const Immediate& x) {
604 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000605 EMIT(0xC7);
606 emit_operand(eax, dst);
607 emit(x);
608}
609
610
611void Assembler::mov(const Operand& dst, Handle<Object> handle) {
612 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000613 EMIT(0xC7);
614 emit_operand(eax, dst);
615 emit(handle);
616}
617
618
619void Assembler::mov(const Operand& dst, Register src) {
620 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000621 EMIT(0x89);
622 emit_operand(src, dst);
623}
624
625
626void Assembler::movsx_b(Register dst, const Operand& src) {
627 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000628 EMIT(0x0F);
629 EMIT(0xBE);
630 emit_operand(dst, src);
631}
632
633
634void Assembler::movsx_w(Register dst, const Operand& src) {
635 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000636 EMIT(0x0F);
637 EMIT(0xBF);
638 emit_operand(dst, src);
639}
640
641
642void Assembler::movzx_b(Register dst, const Operand& src) {
643 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000644 EMIT(0x0F);
645 EMIT(0xB6);
646 emit_operand(dst, src);
647}
648
649
650void Assembler::movzx_w(Register dst, const Operand& src) {
651 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000652 EMIT(0x0F);
653 EMIT(0xB7);
654 emit_operand(dst, src);
655}
656
657
Steve Blocka7e24c12009-10-30 11:49:00 +0000658void Assembler::cmov(Condition cc, Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000659 EnsureSpace ensure_space(this);
Andrei Popescu31002712010-02-23 13:46:05 +0000660 // Opcode: 0f 40 + cc /r.
Steve Blocka7e24c12009-10-30 11:49:00 +0000661 EMIT(0x0F);
662 EMIT(0x40 + cc);
663 emit_operand(dst, src);
664}
665
666
Steve Block6ded16b2010-05-10 14:33:55 +0100667void Assembler::cld() {
668 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +0100669 EMIT(0xFC);
670}
671
672
Leon Clarkee46be812010-01-19 14:06:41 +0000673void Assembler::rep_movs() {
674 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +0000675 EMIT(0xF3);
676 EMIT(0xA5);
677}
678
679
Steve Block6ded16b2010-05-10 14:33:55 +0100680void Assembler::rep_stos() {
681 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +0100682 EMIT(0xF3);
683 EMIT(0xAB);
684}
685
686
Leon Clarkef7060e22010-06-03 12:02:55 +0100687void Assembler::stos() {
688 EnsureSpace ensure_space(this);
Leon Clarkef7060e22010-06-03 12:02:55 +0100689 EMIT(0xAB);
690}
691
692
Steve Blocka7e24c12009-10-30 11:49:00 +0000693void Assembler::xchg(Register dst, Register src) {
694 EnsureSpace ensure_space(this);
Andrei Popescu31002712010-02-23 13:46:05 +0000695 if (src.is(eax) || dst.is(eax)) { // Single-byte encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000696 EMIT(0x90 | (src.is(eax) ? dst.code() : src.code()));
697 } else {
698 EMIT(0x87);
699 EMIT(0xC0 | src.code() << 3 | dst.code());
700 }
701}
702
703
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000704void Assembler::xchg(Register dst, const Operand& src) {
705 EnsureSpace ensure_space(this);
706 EMIT(0x87);
707 emit_operand(dst, src);
708}
709
Ben Murdochc5610432016-08-08 18:44:38 +0100710void Assembler::xchg_b(Register reg, const Operand& op) {
711 EnsureSpace ensure_space(this);
712 EMIT(0x86);
713 emit_operand(reg, op);
714}
715
716void Assembler::xchg_w(Register reg, const Operand& op) {
717 EnsureSpace ensure_space(this);
718 EMIT(0x66);
719 EMIT(0x87);
720 emit_operand(reg, op);
721}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000722
Ben Murdoch61f157c2016-09-16 13:49:30 +0100723void Assembler::lock() {
724 EnsureSpace ensure_space(this);
725 EMIT(0xF0);
726}
727
728void Assembler::cmpxchg(const Operand& dst, Register src) {
729 EnsureSpace ensure_space(this);
730 EMIT(0x0F);
731 EMIT(0xB1);
732 emit_operand(src, dst);
733}
734
735void Assembler::cmpxchg_b(const Operand& dst, Register src) {
736 EnsureSpace ensure_space(this);
737 EMIT(0x0F);
738 EMIT(0xB0);
739 emit_operand(src, dst);
740}
741
742void Assembler::cmpxchg_w(const Operand& dst, Register src) {
743 EnsureSpace ensure_space(this);
744 EMIT(0x66);
745 EMIT(0x0F);
746 EMIT(0xB1);
747 emit_operand(src, dst);
748}
749
Steve Blocka7e24c12009-10-30 11:49:00 +0000750void Assembler::adc(Register dst, int32_t imm32) {
751 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000752 emit_arith(2, Operand(dst), Immediate(imm32));
753}
754
755
756void Assembler::adc(Register dst, const Operand& src) {
757 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000758 EMIT(0x13);
759 emit_operand(dst, src);
760}
761
762
763void Assembler::add(Register dst, const Operand& src) {
764 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000765 EMIT(0x03);
766 emit_operand(dst, src);
767}
768
769
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100770void Assembler::add(const Operand& dst, Register src) {
771 EnsureSpace ensure_space(this);
772 EMIT(0x01);
773 emit_operand(src, dst);
774}
775
776
Steve Blocka7e24c12009-10-30 11:49:00 +0000777void Assembler::add(const Operand& dst, const Immediate& x) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000778 DCHECK(reloc_info_writer.last_pc() != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000779 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000780 emit_arith(0, dst, x);
781}
782
783
784void Assembler::and_(Register dst, int32_t imm32) {
Steve Block59151502010-09-22 15:07:15 +0100785 and_(dst, Immediate(imm32));
786}
787
788
789void Assembler::and_(Register dst, const Immediate& x) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000790 EnsureSpace ensure_space(this);
Steve Block59151502010-09-22 15:07:15 +0100791 emit_arith(4, Operand(dst), x);
Steve Blocka7e24c12009-10-30 11:49:00 +0000792}
793
794
795void Assembler::and_(Register dst, const Operand& src) {
796 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000797 EMIT(0x23);
798 emit_operand(dst, src);
799}
800
801
802void Assembler::and_(const Operand& dst, const Immediate& x) {
803 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000804 emit_arith(4, dst, x);
805}
806
807
808void Assembler::and_(const Operand& dst, Register src) {
809 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000810 EMIT(0x21);
811 emit_operand(src, dst);
812}
813
Ben Murdochda12d292016-06-02 14:46:10 +0100814void Assembler::cmpb(const Operand& op, Immediate imm8) {
815 DCHECK(imm8.is_int8() || imm8.is_uint8());
Steve Blocka7e24c12009-10-30 11:49:00 +0000816 EnsureSpace ensure_space(this);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100817 if (op.is_reg(eax)) {
818 EMIT(0x3C);
819 } else {
820 EMIT(0x80);
821 emit_operand(edi, op); // edi == 7
822 }
Ben Murdochda12d292016-06-02 14:46:10 +0100823 emit_b(imm8);
Steve Blocka7e24c12009-10-30 11:49:00 +0000824}
825
826
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100827void Assembler::cmpb(const Operand& op, Register reg) {
828 CHECK(reg.is_byte_register());
Leon Clarked91b9f72010-01-27 17:25:45 +0000829 EnsureSpace ensure_space(this);
Leon Clarked91b9f72010-01-27 17:25:45 +0000830 EMIT(0x38);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100831 emit_operand(reg, op);
Leon Clarked91b9f72010-01-27 17:25:45 +0000832}
833
834
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100835void Assembler::cmpb(Register reg, const Operand& op) {
836 CHECK(reg.is_byte_register());
Leon Clarked91b9f72010-01-27 17:25:45 +0000837 EnsureSpace ensure_space(this);
Leon Clarked91b9f72010-01-27 17:25:45 +0000838 EMIT(0x3A);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100839 emit_operand(reg, op);
Leon Clarked91b9f72010-01-27 17:25:45 +0000840}
841
842
Steve Blocka7e24c12009-10-30 11:49:00 +0000843void Assembler::cmpw(const Operand& op, Immediate imm16) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000844 DCHECK(imm16.is_int16());
Steve Blocka7e24c12009-10-30 11:49:00 +0000845 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000846 EMIT(0x66);
847 EMIT(0x81);
848 emit_operand(edi, op);
849 emit_w(imm16);
850}
851
Ben Murdochda12d292016-06-02 14:46:10 +0100852void Assembler::cmpw(Register reg, const Operand& op) {
853 EnsureSpace ensure_space(this);
854 EMIT(0x66);
Ben Murdochc5610432016-08-08 18:44:38 +0100855 EMIT(0x3B);
Ben Murdochda12d292016-06-02 14:46:10 +0100856 emit_operand(reg, op);
857}
858
859void Assembler::cmpw(const Operand& op, Register reg) {
860 EnsureSpace ensure_space(this);
861 EMIT(0x66);
Ben Murdochc5610432016-08-08 18:44:38 +0100862 EMIT(0x39);
Ben Murdochda12d292016-06-02 14:46:10 +0100863 emit_operand(reg, op);
864}
Steve Blocka7e24c12009-10-30 11:49:00 +0000865
866void Assembler::cmp(Register reg, int32_t imm32) {
867 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000868 emit_arith(7, Operand(reg), Immediate(imm32));
869}
870
871
872void Assembler::cmp(Register reg, Handle<Object> handle) {
873 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000874 emit_arith(7, Operand(reg), Immediate(handle));
875}
876
877
878void Assembler::cmp(Register reg, const Operand& op) {
879 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000880 EMIT(0x3B);
881 emit_operand(reg, op);
882}
883
Ben Murdoch097c5b22016-05-18 11:27:45 +0100884void Assembler::cmp(const Operand& op, Register reg) {
885 EnsureSpace ensure_space(this);
886 EMIT(0x39);
887 emit_operand(reg, op);
888}
Steve Blocka7e24c12009-10-30 11:49:00 +0000889
890void Assembler::cmp(const Operand& op, const Immediate& imm) {
891 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000892 emit_arith(7, op, imm);
893}
894
895
896void Assembler::cmp(const Operand& op, Handle<Object> handle) {
897 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000898 emit_arith(7, op, Immediate(handle));
899}
900
901
902void Assembler::cmpb_al(const Operand& op) {
903 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000904 EMIT(0x38); // CMP r/m8, r8
905 emit_operand(eax, op); // eax has same code as register al.
906}
907
908
909void Assembler::cmpw_ax(const Operand& op) {
910 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000911 EMIT(0x66);
912 EMIT(0x39); // CMP r/m16, r16
913 emit_operand(eax, op); // eax has same code as register ax.
914}
915
916
917void Assembler::dec_b(Register dst) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100918 CHECK(dst.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +0000919 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000920 EMIT(0xFE);
921 EMIT(0xC8 | dst.code());
922}
923
924
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100925void Assembler::dec_b(const Operand& dst) {
926 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100927 EMIT(0xFE);
928 emit_operand(ecx, dst);
929}
930
931
Steve Blocka7e24c12009-10-30 11:49:00 +0000932void Assembler::dec(Register dst) {
933 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000934 EMIT(0x48 | dst.code());
935}
936
937
938void Assembler::dec(const Operand& dst) {
939 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000940 EMIT(0xFF);
941 emit_operand(ecx, dst);
942}
943
944
945void Assembler::cdq() {
946 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000947 EMIT(0x99);
948}
949
950
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000951void Assembler::idiv(const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000952 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000953 EMIT(0xF7);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000954 emit_operand(edi, src);
955}
956
957
958void Assembler::div(const Operand& src) {
959 EnsureSpace ensure_space(this);
960 EMIT(0xF7);
961 emit_operand(esi, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000962}
963
964
965void Assembler::imul(Register reg) {
966 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000967 EMIT(0xF7);
968 EMIT(0xE8 | reg.code());
969}
970
971
972void Assembler::imul(Register dst, const Operand& src) {
973 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000974 EMIT(0x0F);
975 EMIT(0xAF);
976 emit_operand(dst, src);
977}
978
979
980void Assembler::imul(Register dst, Register src, int32_t imm32) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000981 imul(dst, Operand(src), imm32);
982}
983
984
985void Assembler::imul(Register dst, const Operand& src, int32_t imm32) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000986 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +0000987 if (is_int8(imm32)) {
988 EMIT(0x6B);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000989 emit_operand(dst, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000990 EMIT(imm32);
991 } else {
992 EMIT(0x69);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000993 emit_operand(dst, src);
Steve Blocka7e24c12009-10-30 11:49:00 +0000994 emit(imm32);
995 }
996}
997
998
999void Assembler::inc(Register dst) {
1000 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001001 EMIT(0x40 | dst.code());
1002}
1003
1004
1005void Assembler::inc(const Operand& dst) {
1006 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001007 EMIT(0xFF);
1008 emit_operand(eax, dst);
1009}
1010
1011
1012void Assembler::lea(Register dst, const Operand& src) {
1013 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001014 EMIT(0x8D);
1015 emit_operand(dst, src);
1016}
1017
1018
1019void Assembler::mul(Register src) {
1020 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001021 EMIT(0xF7);
1022 EMIT(0xE0 | src.code());
1023}
1024
1025
1026void Assembler::neg(Register dst) {
1027 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001028 EMIT(0xF7);
1029 EMIT(0xD8 | dst.code());
1030}
1031
1032
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001033void Assembler::neg(const Operand& dst) {
1034 EnsureSpace ensure_space(this);
1035 EMIT(0xF7);
1036 emit_operand(ebx, dst);
1037}
1038
1039
Steve Blocka7e24c12009-10-30 11:49:00 +00001040void Assembler::not_(Register dst) {
1041 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001042 EMIT(0xF7);
1043 EMIT(0xD0 | dst.code());
1044}
1045
1046
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001047void Assembler::not_(const Operand& dst) {
1048 EnsureSpace ensure_space(this);
1049 EMIT(0xF7);
1050 emit_operand(edx, dst);
1051}
1052
1053
Steve Blocka7e24c12009-10-30 11:49:00 +00001054void Assembler::or_(Register dst, int32_t imm32) {
1055 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001056 emit_arith(1, Operand(dst), Immediate(imm32));
1057}
1058
1059
1060void Assembler::or_(Register dst, const Operand& src) {
1061 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001062 EMIT(0x0B);
1063 emit_operand(dst, src);
1064}
1065
1066
1067void Assembler::or_(const Operand& dst, const Immediate& x) {
1068 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001069 emit_arith(1, dst, x);
1070}
1071
1072
1073void Assembler::or_(const Operand& dst, Register src) {
1074 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001075 EMIT(0x09);
1076 emit_operand(src, dst);
1077}
1078
1079
1080void Assembler::rcl(Register dst, uint8_t imm8) {
1081 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001082 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001083 if (imm8 == 1) {
1084 EMIT(0xD1);
1085 EMIT(0xD0 | dst.code());
1086 } else {
1087 EMIT(0xC1);
1088 EMIT(0xD0 | dst.code());
1089 EMIT(imm8);
1090 }
1091}
1092
1093
Iain Merrick75681382010-08-19 15:07:18 +01001094void Assembler::rcr(Register dst, uint8_t imm8) {
1095 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001096 DCHECK(is_uint5(imm8)); // illegal shift count
Iain Merrick75681382010-08-19 15:07:18 +01001097 if (imm8 == 1) {
1098 EMIT(0xD1);
1099 EMIT(0xD8 | dst.code());
1100 } else {
1101 EMIT(0xC1);
1102 EMIT(0xD8 | dst.code());
1103 EMIT(imm8);
1104 }
1105}
1106
1107
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001108void Assembler::ror(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001109 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001110 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001111 if (imm8 == 1) {
1112 EMIT(0xD1);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001113 emit_operand(ecx, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001114 } else {
1115 EMIT(0xC1);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001116 emit_operand(ecx, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001117 EMIT(imm8);
1118 }
1119}
1120
1121
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001122void Assembler::ror_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001123 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001124 EMIT(0xD3);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001125 emit_operand(ecx, dst);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001126}
1127
1128
1129void Assembler::sar(const Operand& dst, uint8_t imm8) {
1130 EnsureSpace ensure_space(this);
1131 DCHECK(is_uint5(imm8)); // illegal shift count
1132 if (imm8 == 1) {
1133 EMIT(0xD1);
1134 emit_operand(edi, dst);
1135 } else {
1136 EMIT(0xC1);
1137 emit_operand(edi, dst);
1138 EMIT(imm8);
1139 }
1140}
1141
1142
1143void Assembler::sar_cl(const Operand& dst) {
1144 EnsureSpace ensure_space(this);
1145 EMIT(0xD3);
1146 emit_operand(edi, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001147}
1148
Steve Blocka7e24c12009-10-30 11:49:00 +00001149void Assembler::sbb(Register dst, const Operand& src) {
1150 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001151 EMIT(0x1B);
1152 emit_operand(dst, src);
1153}
1154
Ben Murdochda12d292016-06-02 14:46:10 +01001155void Assembler::shld(Register dst, Register src, uint8_t shift) {
1156 DCHECK(is_uint5(shift));
1157 EnsureSpace ensure_space(this);
1158 EMIT(0x0F);
1159 EMIT(0xA4);
1160 emit_operand(src, Operand(dst));
1161 EMIT(shift);
1162}
Steve Blocka7e24c12009-10-30 11:49:00 +00001163
Ben Murdochda12d292016-06-02 14:46:10 +01001164void Assembler::shld_cl(Register dst, Register src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001165 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001166 EMIT(0x0F);
1167 EMIT(0xA5);
Ben Murdochda12d292016-06-02 14:46:10 +01001168 emit_operand(src, Operand(dst));
Steve Blocka7e24c12009-10-30 11:49:00 +00001169}
1170
1171
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001172void Assembler::shl(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001173 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001174 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blocka7e24c12009-10-30 11:49:00 +00001175 if (imm8 == 1) {
1176 EMIT(0xD1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001177 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001178 } else {
1179 EMIT(0xC1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001180 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001181 EMIT(imm8);
1182 }
1183}
1184
1185
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001186void Assembler::shl_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001187 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001188 EMIT(0xD3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001189 emit_operand(esp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001190}
1191
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001192void Assembler::shr(const Operand& dst, uint8_t imm8) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001193 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001194 DCHECK(is_uint5(imm8)); // illegal shift count
Steve Blockd0582a62009-12-15 09:54:21 +00001195 if (imm8 == 1) {
1196 EMIT(0xD1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001197 emit_operand(ebp, dst);
Steve Blockd0582a62009-12-15 09:54:21 +00001198 } else {
1199 EMIT(0xC1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001200 emit_operand(ebp, dst);
Steve Blockd0582a62009-12-15 09:54:21 +00001201 EMIT(imm8);
1202 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001203}
1204
1205
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001206void Assembler::shr_cl(const Operand& dst) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001207 EnsureSpace ensure_space(this);
Steve Blockd0582a62009-12-15 09:54:21 +00001208 EMIT(0xD3);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001209 emit_operand(ebp, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001210}
1211
Ben Murdochda12d292016-06-02 14:46:10 +01001212void Assembler::shrd(Register dst, Register src, uint8_t shift) {
1213 DCHECK(is_uint5(shift));
1214 EnsureSpace ensure_space(this);
1215 EMIT(0x0F);
1216 EMIT(0xAC);
1217 emit_operand(dst, Operand(src));
1218 EMIT(shift);
1219}
1220
1221void Assembler::shrd_cl(const Operand& dst, Register src) {
1222 EnsureSpace ensure_space(this);
1223 EMIT(0x0F);
1224 EMIT(0xAD);
1225 emit_operand(src, dst);
1226}
Steve Blocka7e24c12009-10-30 11:49:00 +00001227
1228void Assembler::sub(const Operand& dst, const Immediate& x) {
1229 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001230 emit_arith(5, dst, x);
1231}
1232
1233
1234void Assembler::sub(Register dst, const Operand& src) {
1235 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001236 EMIT(0x2B);
1237 emit_operand(dst, src);
1238}
1239
1240
1241void Assembler::sub(const Operand& dst, Register src) {
1242 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001243 EMIT(0x29);
1244 emit_operand(src, dst);
1245}
1246
1247
1248void Assembler::test(Register reg, const Immediate& imm) {
Ben Murdochda12d292016-06-02 14:46:10 +01001249 if (imm.is_uint8()) {
1250 test_b(reg, imm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001251 return;
Steve Blocka7e24c12009-10-30 11:49:00 +00001252 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001253
1254 EnsureSpace ensure_space(this);
1255 // This is not using emit_arith because test doesn't support
1256 // sign-extension of 8-bit operands.
1257 if (reg.is(eax)) {
1258 EMIT(0xA9);
1259 } else {
1260 EMIT(0xF7);
1261 EMIT(0xC0 | reg.code());
1262 }
1263 emit(imm);
Steve Blocka7e24c12009-10-30 11:49:00 +00001264}
1265
1266
1267void Assembler::test(Register reg, const Operand& op) {
1268 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001269 EMIT(0x85);
1270 emit_operand(reg, op);
1271}
1272
1273
Leon Clarkee46be812010-01-19 14:06:41 +00001274void Assembler::test_b(Register reg, const Operand& op) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001275 CHECK(reg.is_byte_register());
Leon Clarkee46be812010-01-19 14:06:41 +00001276 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00001277 EMIT(0x84);
1278 emit_operand(reg, op);
1279}
1280
1281
Steve Blocka7e24c12009-10-30 11:49:00 +00001282void Assembler::test(const Operand& op, const Immediate& imm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001283 if (op.is_reg_only()) {
1284 test(op.reg(), imm);
1285 return;
1286 }
Ben Murdochda12d292016-06-02 14:46:10 +01001287 if (imm.is_uint8()) {
1288 return test_b(op, imm);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001289 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001290 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001291 EMIT(0xF7);
1292 emit_operand(eax, op);
1293 emit(imm);
1294}
1295
Ben Murdochda12d292016-06-02 14:46:10 +01001296void Assembler::test_b(Register reg, Immediate imm8) {
1297 DCHECK(imm8.is_uint8());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001298 EnsureSpace ensure_space(this);
1299 // Only use test against byte for registers that have a byte
1300 // variant: eax, ebx, ecx, and edx.
1301 if (reg.is(eax)) {
1302 EMIT(0xA8);
Ben Murdochda12d292016-06-02 14:46:10 +01001303 emit_b(imm8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001304 } else if (reg.is_byte_register()) {
Ben Murdochda12d292016-06-02 14:46:10 +01001305 emit_arith_b(0xF6, 0xC0, reg, static_cast<uint8_t>(imm8.x_));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001306 } else {
Ben Murdochda12d292016-06-02 14:46:10 +01001307 EMIT(0x66);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001308 EMIT(0xF7);
1309 EMIT(0xC0 | reg.code());
Ben Murdochda12d292016-06-02 14:46:10 +01001310 emit_w(imm8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001311 }
1312}
1313
Ben Murdochda12d292016-06-02 14:46:10 +01001314void Assembler::test_b(const Operand& op, Immediate imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001315 if (op.is_reg_only()) {
1316 test_b(op.reg(), imm8);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001317 return;
1318 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001319 EnsureSpace ensure_space(this);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001320 EMIT(0xF6);
1321 emit_operand(eax, op);
Ben Murdochda12d292016-06-02 14:46:10 +01001322 emit_b(imm8);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001323}
1324
Ben Murdochda12d292016-06-02 14:46:10 +01001325void Assembler::test_w(Register reg, Immediate imm16) {
1326 DCHECK(imm16.is_int16() || imm16.is_uint16());
1327 EnsureSpace ensure_space(this);
1328 if (reg.is(eax)) {
1329 EMIT(0xA9);
1330 emit_w(imm16);
1331 } else {
1332 EMIT(0x66);
1333 EMIT(0xF7);
1334 EMIT(0xc0 | reg.code());
1335 emit_w(imm16);
1336 }
1337}
1338
1339void Assembler::test_w(Register reg, const Operand& op) {
1340 EnsureSpace ensure_space(this);
1341 EMIT(0x66);
1342 EMIT(0x85);
1343 emit_operand(reg, op);
1344}
1345
1346void Assembler::test_w(const Operand& op, Immediate imm16) {
1347 DCHECK(imm16.is_int16() || imm16.is_uint16());
1348 if (op.is_reg_only()) {
1349 test_w(op.reg(), imm16);
1350 return;
1351 }
1352 EnsureSpace ensure_space(this);
1353 EMIT(0x66);
1354 EMIT(0xF7);
1355 emit_operand(eax, op);
1356 emit_w(imm16);
1357}
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001358
Steve Blocka7e24c12009-10-30 11:49:00 +00001359void Assembler::xor_(Register dst, int32_t imm32) {
1360 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001361 emit_arith(6, Operand(dst), Immediate(imm32));
1362}
1363
1364
1365void Assembler::xor_(Register dst, const Operand& src) {
1366 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001367 EMIT(0x33);
1368 emit_operand(dst, src);
1369}
1370
1371
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001372void Assembler::xor_(const Operand& dst, Register src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001373 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001374 EMIT(0x31);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001375 emit_operand(src, dst);
Steve Blocka7e24c12009-10-30 11:49:00 +00001376}
1377
1378
1379void Assembler::xor_(const Operand& dst, const Immediate& x) {
1380 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001381 emit_arith(6, dst, x);
1382}
1383
1384
1385void Assembler::bt(const Operand& dst, Register src) {
1386 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001387 EMIT(0x0F);
1388 EMIT(0xA3);
1389 emit_operand(src, dst);
1390}
1391
1392
1393void Assembler::bts(const Operand& dst, Register src) {
1394 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001395 EMIT(0x0F);
1396 EMIT(0xAB);
1397 emit_operand(src, dst);
1398}
1399
1400
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001401void Assembler::bsr(Register dst, const Operand& src) {
1402 EnsureSpace ensure_space(this);
1403 EMIT(0x0F);
1404 EMIT(0xBD);
1405 emit_operand(dst, src);
1406}
1407
1408
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001409void Assembler::bsf(Register dst, const Operand& src) {
1410 EnsureSpace ensure_space(this);
1411 EMIT(0x0F);
1412 EMIT(0xBC);
1413 emit_operand(dst, src);
1414}
1415
1416
Steve Blocka7e24c12009-10-30 11:49:00 +00001417void Assembler::hlt() {
1418 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001419 EMIT(0xF4);
1420}
1421
1422
1423void Assembler::int3() {
1424 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001425 EMIT(0xCC);
1426}
1427
1428
1429void Assembler::nop() {
1430 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001431 EMIT(0x90);
1432}
1433
1434
Steve Blocka7e24c12009-10-30 11:49:00 +00001435void Assembler::ret(int imm16) {
1436 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001437 DCHECK(is_uint16(imm16));
Steve Blocka7e24c12009-10-30 11:49:00 +00001438 if (imm16 == 0) {
1439 EMIT(0xC3);
1440 } else {
1441 EMIT(0xC2);
1442 EMIT(imm16 & 0xFF);
1443 EMIT((imm16 >> 8) & 0xFF);
1444 }
1445}
1446
1447
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001448void Assembler::ud2() {
1449 EnsureSpace ensure_space(this);
1450 EMIT(0x0F);
1451 EMIT(0x0B);
1452}
1453
1454
Steve Blocka7e24c12009-10-30 11:49:00 +00001455// Labels refer to positions in the (to be) generated code.
1456// There are bound, linked, and unused labels.
1457//
1458// Bound labels refer to known positions in the already
1459// generated code. pos() is the position the label refers to.
1460//
1461// Linked labels refer to unknown positions in the code
1462// to be generated; pos() is the position of the 32bit
1463// Displacement of the last instruction using the label.
1464
1465
1466void Assembler::print(Label* L) {
1467 if (L->is_unused()) {
1468 PrintF("unused label\n");
1469 } else if (L->is_bound()) {
1470 PrintF("bound label to %d\n", L->pos());
1471 } else if (L->is_linked()) {
1472 Label l = *L;
1473 PrintF("unbound label");
1474 while (l.is_linked()) {
1475 Displacement disp = disp_at(&l);
1476 PrintF("@ %d ", l.pos());
1477 disp.print();
1478 PrintF("\n");
1479 disp.next(&l);
1480 }
1481 } else {
1482 PrintF("label in inconsistent state (pos = %d)\n", L->pos_);
1483 }
1484}
1485
1486
1487void Assembler::bind_to(Label* L, int pos) {
1488 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001489 DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position
Steve Blocka7e24c12009-10-30 11:49:00 +00001490 while (L->is_linked()) {
1491 Displacement disp = disp_at(L);
1492 int fixup_pos = L->pos();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001493 if (disp.type() == Displacement::CODE_ABSOLUTE) {
1494 long_at_put(fixup_pos, reinterpret_cast<int>(buffer_ + pos));
1495 internal_reference_positions_.push_back(fixup_pos);
1496 } else if (disp.type() == Displacement::CODE_RELATIVE) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001497 // Relative to Code* heap object pointer.
1498 long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag);
1499 } else {
1500 if (disp.type() == Displacement::UNCONDITIONAL_JUMP) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001501 DCHECK(byte_at(fixup_pos - 1) == 0xE9); // jmp expected
Steve Blocka7e24c12009-10-30 11:49:00 +00001502 }
Andrei Popescu31002712010-02-23 13:46:05 +00001503 // Relative address, relative to point after address.
Steve Blocka7e24c12009-10-30 11:49:00 +00001504 int imm32 = pos - (fixup_pos + sizeof(int32_t));
1505 long_at_put(fixup_pos, imm32);
1506 }
1507 disp.next(L);
1508 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001509 while (L->is_near_linked()) {
1510 int fixup_pos = L->near_link_pos();
1511 int offset_to_next =
1512 static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos)));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001513 DCHECK(offset_to_next <= 0);
Ben Murdoch257744e2011-11-30 15:57:28 +00001514 // Relative address, relative to point after address.
1515 int disp = pos - fixup_pos - sizeof(int8_t);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001516 CHECK(0 <= disp && disp <= 127);
Ben Murdoch257744e2011-11-30 15:57:28 +00001517 set_byte_at(fixup_pos, disp);
1518 if (offset_to_next < 0) {
1519 L->link_to(fixup_pos + offset_to_next, Label::kNear);
1520 } else {
1521 L->UnuseNear();
1522 }
1523 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001524 L->bind_to(pos);
1525}
1526
1527
Steve Blocka7e24c12009-10-30 11:49:00 +00001528void Assembler::bind(Label* L) {
1529 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001530 DCHECK(!L->is_bound()); // label can only be bound once
Steve Blocka7e24c12009-10-30 11:49:00 +00001531 bind_to(L, pc_offset());
1532}
1533
1534
1535void Assembler::call(Label* L) {
1536 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001537 if (L->is_bound()) {
1538 const int long_size = 5;
1539 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001540 DCHECK(offs <= 0);
Andrei Popescu31002712010-02-23 13:46:05 +00001541 // 1110 1000 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001542 EMIT(0xE8);
1543 emit(offs - long_size);
1544 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001545 // 1110 1000 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001546 EMIT(0xE8);
1547 emit_disp(L, Displacement::OTHER);
1548 }
1549}
1550
1551
1552void Assembler::call(byte* entry, RelocInfo::Mode rmode) {
1553 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001554 DCHECK(!RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001555 EMIT(0xE8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001556 if (RelocInfo::IsRuntimeEntry(rmode)) {
1557 emit(reinterpret_cast<uint32_t>(entry), rmode);
1558 } else {
1559 emit(entry - (pc_ + sizeof(int32_t)), rmode);
1560 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001561}
1562
1563
Ben Murdoch257744e2011-11-30 15:57:28 +00001564int Assembler::CallSize(const Operand& adr) {
1565 // Call size is 1 (opcode) + adr.len_ (operand).
1566 return 1 + adr.len_;
1567}
1568
1569
Steve Blocka7e24c12009-10-30 11:49:00 +00001570void Assembler::call(const Operand& adr) {
1571 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001572 EMIT(0xFF);
1573 emit_operand(edx, adr);
1574}
1575
1576
Ben Murdoch257744e2011-11-30 15:57:28 +00001577int Assembler::CallSize(Handle<Code> code, RelocInfo::Mode rmode) {
1578 return 1 /* EMIT */ + sizeof(uint32_t) /* emit */;
Steve Blocka7e24c12009-10-30 11:49:00 +00001579}
1580
1581
Ben Murdoch257744e2011-11-30 15:57:28 +00001582void Assembler::call(Handle<Code> code,
1583 RelocInfo::Mode rmode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001584 TypeFeedbackId ast_id) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001585 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001586 DCHECK(RelocInfo::IsCodeTarget(rmode)
1587 || rmode == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch257744e2011-11-30 15:57:28 +00001588 EMIT(0xE8);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001589 emit(code, rmode, ast_id);
Ben Murdoch257744e2011-11-30 15:57:28 +00001590}
1591
1592
1593void Assembler::jmp(Label* L, Label::Distance distance) {
1594 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001595 if (L->is_bound()) {
1596 const int short_size = 2;
1597 const int long_size = 5;
1598 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001599 DCHECK(offs <= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001600 if (is_int8(offs - short_size)) {
Andrei Popescu31002712010-02-23 13:46:05 +00001601 // 1110 1011 #8-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001602 EMIT(0xEB);
1603 EMIT((offs - short_size) & 0xFF);
1604 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001605 // 1110 1001 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001606 EMIT(0xE9);
1607 emit(offs - long_size);
1608 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001609 } else if (distance == Label::kNear) {
1610 EMIT(0xEB);
1611 emit_near_disp(L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001612 } else {
Andrei Popescu31002712010-02-23 13:46:05 +00001613 // 1110 1001 #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001614 EMIT(0xE9);
1615 emit_disp(L, Displacement::UNCONDITIONAL_JUMP);
1616 }
1617}
1618
1619
1620void Assembler::jmp(byte* entry, RelocInfo::Mode rmode) {
1621 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001622 DCHECK(!RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001623 EMIT(0xE9);
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
1632void Assembler::jmp(const Operand& adr) {
1633 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001634 EMIT(0xFF);
1635 emit_operand(esp, adr);
1636}
1637
1638
1639void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) {
1640 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001641 DCHECK(RelocInfo::IsCodeTarget(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00001642 EMIT(0xE9);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001643 emit(code, rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001644}
1645
1646
Ben Murdoch257744e2011-11-30 15:57:28 +00001647void Assembler::j(Condition cc, Label* L, Label::Distance distance) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001648 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001649 DCHECK(0 <= cc && static_cast<int>(cc) < 16);
Steve Blocka7e24c12009-10-30 11:49:00 +00001650 if (L->is_bound()) {
1651 const int short_size = 2;
1652 const int long_size = 6;
1653 int offs = L->pos() - pc_offset();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001654 DCHECK(offs <= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001655 if (is_int8(offs - short_size)) {
1656 // 0111 tttn #8-bit disp
1657 EMIT(0x70 | cc);
1658 EMIT((offs - short_size) & 0xFF);
1659 } else {
1660 // 0000 1111 1000 tttn #32-bit disp
1661 EMIT(0x0F);
1662 EMIT(0x80 | cc);
1663 emit(offs - long_size);
1664 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001665 } else if (distance == Label::kNear) {
1666 EMIT(0x70 | cc);
1667 emit_near_disp(L);
Steve Blocka7e24c12009-10-30 11:49:00 +00001668 } else {
1669 // 0000 1111 1000 tttn #32-bit disp
1670 // Note: could eliminate cond. jumps to this jump if condition
1671 // is the same however, seems to be rather unlikely case.
1672 EMIT(0x0F);
1673 EMIT(0x80 | cc);
1674 emit_disp(L, Displacement::OTHER);
1675 }
1676}
1677
1678
Ben Murdoch257744e2011-11-30 15:57:28 +00001679void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001680 EnsureSpace ensure_space(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001681 DCHECK((0 <= cc) && (static_cast<int>(cc) < 16));
Andrei Popescu31002712010-02-23 13:46:05 +00001682 // 0000 1111 1000 tttn #32-bit disp.
Steve Blocka7e24c12009-10-30 11:49:00 +00001683 EMIT(0x0F);
1684 EMIT(0x80 | cc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001685 if (RelocInfo::IsRuntimeEntry(rmode)) {
1686 emit(reinterpret_cast<uint32_t>(entry), rmode);
1687 } else {
1688 emit(entry - (pc_ + sizeof(int32_t)), rmode);
1689 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001690}
1691
1692
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001693void Assembler::j(Condition cc, Handle<Code> code, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001694 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001695 // 0000 1111 1000 tttn #32-bit disp
1696 EMIT(0x0F);
1697 EMIT(0x80 | cc);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001698 emit(code, rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001699}
1700
1701
Andrei Popescu31002712010-02-23 13:46:05 +00001702// FPU instructions.
Steve Blocka7e24c12009-10-30 11:49:00 +00001703
Steve Blocka7e24c12009-10-30 11:49:00 +00001704void Assembler::fld(int i) {
1705 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001706 emit_farith(0xD9, 0xC0, i);
1707}
1708
1709
Andrei Popescu402d9372010-02-26 13:31:12 +00001710void Assembler::fstp(int i) {
1711 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001712 emit_farith(0xDD, 0xD8, i);
1713}
1714
1715
Steve Blocka7e24c12009-10-30 11:49:00 +00001716void Assembler::fld1() {
1717 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001718 EMIT(0xD9);
1719 EMIT(0xE8);
1720}
1721
1722
Andrei Popescu402d9372010-02-26 13:31:12 +00001723void Assembler::fldpi() {
1724 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001725 EMIT(0xD9);
1726 EMIT(0xEB);
1727}
1728
1729
Steve Blocka7e24c12009-10-30 11:49:00 +00001730void Assembler::fldz() {
1731 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001732 EMIT(0xD9);
1733 EMIT(0xEE);
1734}
1735
1736
Ben Murdochb0fe1622011-05-05 13:52:32 +01001737void Assembler::fldln2() {
1738 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001739 EMIT(0xD9);
1740 EMIT(0xED);
1741}
1742
1743
Steve Blocka7e24c12009-10-30 11:49:00 +00001744void Assembler::fld_s(const Operand& adr) {
1745 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001746 EMIT(0xD9);
1747 emit_operand(eax, adr);
1748}
1749
1750
1751void Assembler::fld_d(const Operand& adr) {
1752 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001753 EMIT(0xDD);
1754 emit_operand(eax, adr);
1755}
1756
1757
1758void Assembler::fstp_s(const Operand& adr) {
1759 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001760 EMIT(0xD9);
1761 emit_operand(ebx, adr);
1762}
1763
1764
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001765void Assembler::fst_s(const Operand& adr) {
1766 EnsureSpace ensure_space(this);
1767 EMIT(0xD9);
1768 emit_operand(edx, adr);
1769}
1770
1771
Steve Blocka7e24c12009-10-30 11:49:00 +00001772void Assembler::fstp_d(const Operand& adr) {
1773 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001774 EMIT(0xDD);
1775 emit_operand(ebx, adr);
1776}
1777
1778
Andrei Popescu402d9372010-02-26 13:31:12 +00001779void Assembler::fst_d(const Operand& adr) {
1780 EnsureSpace ensure_space(this);
Andrei Popescu402d9372010-02-26 13:31:12 +00001781 EMIT(0xDD);
1782 emit_operand(edx, adr);
1783}
1784
1785
Steve Blocka7e24c12009-10-30 11:49:00 +00001786void Assembler::fild_s(const Operand& adr) {
1787 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001788 EMIT(0xDB);
1789 emit_operand(eax, adr);
1790}
1791
1792
1793void Assembler::fild_d(const Operand& adr) {
1794 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001795 EMIT(0xDF);
1796 emit_operand(ebp, adr);
1797}
1798
1799
1800void Assembler::fistp_s(const Operand& adr) {
1801 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001802 EMIT(0xDB);
1803 emit_operand(ebx, adr);
1804}
1805
1806
1807void Assembler::fisttp_s(const Operand& adr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001808 DCHECK(IsEnabled(SSE3));
Steve Blocka7e24c12009-10-30 11:49:00 +00001809 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001810 EMIT(0xDB);
1811 emit_operand(ecx, adr);
1812}
1813
1814
Leon Clarkee46be812010-01-19 14:06:41 +00001815void Assembler::fisttp_d(const Operand& adr) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001816 DCHECK(IsEnabled(SSE3));
Leon Clarkee46be812010-01-19 14:06:41 +00001817 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00001818 EMIT(0xDD);
1819 emit_operand(ecx, adr);
1820}
1821
1822
Steve Blocka7e24c12009-10-30 11:49:00 +00001823void Assembler::fist_s(const Operand& adr) {
1824 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001825 EMIT(0xDB);
1826 emit_operand(edx, adr);
1827}
1828
1829
1830void Assembler::fistp_d(const Operand& adr) {
1831 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001832 EMIT(0xDF);
1833 emit_operand(edi, adr);
1834}
1835
1836
1837void Assembler::fabs() {
1838 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001839 EMIT(0xD9);
1840 EMIT(0xE1);
1841}
1842
1843
1844void Assembler::fchs() {
1845 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001846 EMIT(0xD9);
1847 EMIT(0xE0);
1848}
1849
1850
1851void Assembler::fcos() {
1852 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001853 EMIT(0xD9);
1854 EMIT(0xFF);
1855}
1856
1857
1858void Assembler::fsin() {
1859 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001860 EMIT(0xD9);
1861 EMIT(0xFE);
1862}
1863
1864
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001865void Assembler::fptan() {
1866 EnsureSpace ensure_space(this);
1867 EMIT(0xD9);
1868 EMIT(0xF2);
1869}
1870
1871
Ben Murdochb0fe1622011-05-05 13:52:32 +01001872void Assembler::fyl2x() {
1873 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001874 EMIT(0xD9);
1875 EMIT(0xF1);
1876}
1877
1878
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001879void Assembler::f2xm1() {
1880 EnsureSpace ensure_space(this);
1881 EMIT(0xD9);
1882 EMIT(0xF0);
1883}
1884
1885
1886void Assembler::fscale() {
1887 EnsureSpace ensure_space(this);
1888 EMIT(0xD9);
1889 EMIT(0xFD);
1890}
1891
1892
1893void Assembler::fninit() {
1894 EnsureSpace ensure_space(this);
1895 EMIT(0xDB);
1896 EMIT(0xE3);
1897}
1898
1899
Steve Blocka7e24c12009-10-30 11:49:00 +00001900void Assembler::fadd(int i) {
1901 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001902 emit_farith(0xDC, 0xC0, i);
1903}
1904
1905
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001906void Assembler::fadd_i(int i) {
1907 EnsureSpace ensure_space(this);
1908 emit_farith(0xD8, 0xC0, i);
1909}
1910
1911
Steve Blocka7e24c12009-10-30 11:49:00 +00001912void Assembler::fsub(int i) {
1913 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001914 emit_farith(0xDC, 0xE8, i);
1915}
1916
1917
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001918void Assembler::fsub_i(int i) {
1919 EnsureSpace ensure_space(this);
1920 emit_farith(0xD8, 0xE0, i);
1921}
1922
1923
Steve Blocka7e24c12009-10-30 11:49:00 +00001924void Assembler::fisub_s(const Operand& adr) {
1925 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001926 EMIT(0xDA);
1927 emit_operand(esp, adr);
1928}
1929
1930
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001931void Assembler::fmul_i(int i) {
1932 EnsureSpace ensure_space(this);
1933 emit_farith(0xD8, 0xC8, i);
1934}
1935
1936
Steve Blocka7e24c12009-10-30 11:49:00 +00001937void Assembler::fmul(int i) {
1938 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001939 emit_farith(0xDC, 0xC8, i);
1940}
1941
1942
1943void Assembler::fdiv(int i) {
1944 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001945 emit_farith(0xDC, 0xF8, i);
1946}
1947
1948
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001949void Assembler::fdiv_i(int i) {
1950 EnsureSpace ensure_space(this);
1951 emit_farith(0xD8, 0xF0, i);
1952}
1953
1954
Steve Blocka7e24c12009-10-30 11:49:00 +00001955void Assembler::faddp(int i) {
1956 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001957 emit_farith(0xDE, 0xC0, i);
1958}
1959
1960
1961void Assembler::fsubp(int i) {
1962 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001963 emit_farith(0xDE, 0xE8, i);
1964}
1965
1966
1967void Assembler::fsubrp(int i) {
1968 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001969 emit_farith(0xDE, 0xE0, i);
1970}
1971
1972
1973void Assembler::fmulp(int i) {
1974 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001975 emit_farith(0xDE, 0xC8, i);
1976}
1977
1978
1979void Assembler::fdivp(int i) {
1980 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001981 emit_farith(0xDE, 0xF8, i);
1982}
1983
1984
1985void Assembler::fprem() {
1986 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001987 EMIT(0xD9);
1988 EMIT(0xF8);
1989}
1990
1991
1992void Assembler::fprem1() {
1993 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00001994 EMIT(0xD9);
1995 EMIT(0xF5);
1996}
1997
1998
1999void Assembler::fxch(int i) {
2000 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002001 emit_farith(0xD9, 0xC8, i);
2002}
2003
2004
2005void Assembler::fincstp() {
2006 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002007 EMIT(0xD9);
2008 EMIT(0xF7);
2009}
2010
2011
2012void Assembler::ffree(int i) {
2013 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002014 emit_farith(0xDD, 0xC0, i);
2015}
2016
2017
2018void Assembler::ftst() {
2019 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002020 EMIT(0xD9);
2021 EMIT(0xE4);
2022}
2023
2024
2025void Assembler::fucomp(int i) {
2026 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002027 emit_farith(0xDD, 0xE8, i);
2028}
2029
2030
2031void Assembler::fucompp() {
2032 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002033 EMIT(0xDA);
2034 EMIT(0xE9);
2035}
2036
2037
Steve Block3ce2e202009-11-05 08:53:23 +00002038void Assembler::fucomi(int i) {
2039 EnsureSpace ensure_space(this);
Steve Block3ce2e202009-11-05 08:53:23 +00002040 EMIT(0xDB);
2041 EMIT(0xE8 + i);
2042}
2043
2044
2045void Assembler::fucomip() {
2046 EnsureSpace ensure_space(this);
Steve Block3ce2e202009-11-05 08:53:23 +00002047 EMIT(0xDF);
2048 EMIT(0xE9);
2049}
2050
2051
Steve Blocka7e24c12009-10-30 11:49:00 +00002052void Assembler::fcompp() {
2053 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002054 EMIT(0xDE);
2055 EMIT(0xD9);
2056}
2057
2058
2059void Assembler::fnstsw_ax() {
2060 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002061 EMIT(0xDF);
2062 EMIT(0xE0);
2063}
2064
2065
2066void Assembler::fwait() {
2067 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002068 EMIT(0x9B);
2069}
2070
2071
2072void Assembler::frndint() {
2073 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002074 EMIT(0xD9);
2075 EMIT(0xFC);
2076}
2077
2078
2079void Assembler::fnclex() {
2080 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002081 EMIT(0xDB);
2082 EMIT(0xE2);
2083}
2084
2085
2086void Assembler::sahf() {
2087 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002088 EMIT(0x9E);
2089}
2090
2091
2092void Assembler::setcc(Condition cc, Register reg) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002093 DCHECK(reg.is_byte_register());
Steve Blocka7e24c12009-10-30 11:49:00 +00002094 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002095 EMIT(0x0F);
2096 EMIT(0x90 | cc);
2097 EMIT(0xC0 | reg.code());
2098}
2099
2100
2101void Assembler::cvttss2si(Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002102 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002103 EMIT(0xF3);
2104 EMIT(0x0F);
2105 EMIT(0x2C);
2106 emit_operand(dst, src);
2107}
2108
2109
2110void Assembler::cvttsd2si(Register dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002111 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002112 EMIT(0xF2);
2113 EMIT(0x0F);
2114 EMIT(0x2C);
2115 emit_operand(dst, src);
2116}
2117
2118
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002119void Assembler::cvtsd2si(Register dst, XMMRegister src) {
2120 EnsureSpace ensure_space(this);
2121 EMIT(0xF2);
2122 EMIT(0x0F);
2123 EMIT(0x2D);
2124 emit_sse_operand(dst, src);
2125}
2126
2127
Ben Murdoch097c5b22016-05-18 11:27:45 +01002128void Assembler::cvtsi2ss(XMMRegister dst, const Operand& src) {
2129 EnsureSpace ensure_space(this);
2130 EMIT(0xF3);
2131 EMIT(0x0F);
2132 EMIT(0x2A);
2133 emit_sse_operand(dst, src);
2134}
2135
2136
Steve Blocka7e24c12009-10-30 11:49:00 +00002137void Assembler::cvtsi2sd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002138 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002139 EMIT(0xF2);
2140 EMIT(0x0F);
2141 EMIT(0x2A);
2142 emit_sse_operand(dst, src);
2143}
2144
2145
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002146void Assembler::cvtss2sd(XMMRegister dst, const Operand& src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002147 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002148 EMIT(0xF3);
2149 EMIT(0x0F);
2150 EMIT(0x5A);
2151 emit_sse_operand(dst, src);
2152}
2153
2154
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002155void Assembler::cvtsd2ss(XMMRegister dst, const Operand& src) {
Steve Block44f0eee2011-05-26 01:26:41 +01002156 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002157 EMIT(0xF2);
2158 EMIT(0x0F);
2159 EMIT(0x5A);
2160 emit_sse_operand(dst, src);
2161}
2162
2163
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002164void Assembler::addsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002165 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002166 EMIT(0xF2);
2167 EMIT(0x0F);
2168 EMIT(0x58);
2169 emit_sse_operand(dst, src);
2170}
2171
2172
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002173void Assembler::mulsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002174 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002175 EMIT(0xF2);
2176 EMIT(0x0F);
2177 EMIT(0x59);
2178 emit_sse_operand(dst, src);
2179}
2180
2181
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002182void Assembler::subsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002183 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002184 EMIT(0xF2);
2185 EMIT(0x0F);
2186 EMIT(0x5C);
2187 emit_sse_operand(dst, src);
2188}
2189
2190
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002191void Assembler::divsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002192 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002193 EMIT(0xF2);
2194 EMIT(0x0F);
2195 EMIT(0x5E);
2196 emit_sse_operand(dst, src);
2197}
2198
2199
Leon Clarkee46be812010-01-19 14:06:41 +00002200void Assembler::xorpd(XMMRegister dst, XMMRegister src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002201 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002202 EMIT(0x66);
2203 EMIT(0x0F);
2204 EMIT(0x57);
2205 emit_sse_operand(dst, src);
2206}
2207
2208
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002209void Assembler::andps(XMMRegister dst, const Operand& src) {
2210 EnsureSpace ensure_space(this);
2211 EMIT(0x0F);
2212 EMIT(0x54);
2213 emit_sse_operand(dst, src);
2214}
2215
2216
2217void Assembler::orps(XMMRegister dst, const Operand& src) {
2218 EnsureSpace ensure_space(this);
2219 EMIT(0x0F);
2220 EMIT(0x56);
2221 emit_sse_operand(dst, src);
2222}
2223
2224
2225void Assembler::xorps(XMMRegister dst, const Operand& src) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002226 EnsureSpace ensure_space(this);
2227 EMIT(0x0F);
2228 EMIT(0x57);
2229 emit_sse_operand(dst, src);
2230}
2231
2232
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002233void Assembler::addps(XMMRegister dst, const Operand& src) {
2234 EnsureSpace ensure_space(this);
2235 EMIT(0x0F);
2236 EMIT(0x58);
2237 emit_sse_operand(dst, src);
2238}
2239
2240
2241void Assembler::subps(XMMRegister dst, const Operand& src) {
2242 EnsureSpace ensure_space(this);
2243 EMIT(0x0F);
2244 EMIT(0x5C);
2245 emit_sse_operand(dst, src);
2246}
2247
2248
2249void Assembler::mulps(XMMRegister dst, const Operand& src) {
2250 EnsureSpace ensure_space(this);
2251 EMIT(0x0F);
2252 EMIT(0x59);
2253 emit_sse_operand(dst, src);
2254}
2255
2256
2257void Assembler::divps(XMMRegister dst, const Operand& src) {
2258 EnsureSpace ensure_space(this);
2259 EMIT(0x0F);
2260 EMIT(0x5E);
2261 emit_sse_operand(dst, src);
2262}
2263
2264
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002265void Assembler::sqrtsd(XMMRegister dst, const Operand& src) {
2266 EnsureSpace ensure_space(this);
2267 EMIT(0xF2);
2268 EMIT(0x0F);
2269 EMIT(0x51);
2270 emit_sse_operand(dst, src);
2271}
2272
2273
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002274void Assembler::andpd(XMMRegister dst, XMMRegister src) {
2275 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002276 EMIT(0x66);
2277 EMIT(0x0F);
2278 EMIT(0x54);
2279 emit_sse_operand(dst, src);
2280}
2281
2282
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002283void Assembler::orpd(XMMRegister dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002284 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002285 EMIT(0x66);
2286 EMIT(0x0F);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002287 EMIT(0x56);
Steve Block6ded16b2010-05-10 14:33:55 +01002288 emit_sse_operand(dst, src);
2289}
2290
2291
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002292void Assembler::ucomisd(XMMRegister dst, const Operand& src) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002293 EnsureSpace ensure_space(this);
2294 EMIT(0x66);
2295 EMIT(0x0F);
2296 EMIT(0x2E);
2297 emit_sse_operand(dst, src);
2298}
2299
2300
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002301void Assembler::roundss(XMMRegister dst, XMMRegister src, RoundingMode mode) {
2302 DCHECK(IsEnabled(SSE4_1));
2303 EnsureSpace ensure_space(this);
2304 EMIT(0x66);
2305 EMIT(0x0F);
2306 EMIT(0x3A);
2307 EMIT(0x0A);
2308 emit_sse_operand(dst, src);
2309 // Mask precision exeption.
2310 EMIT(static_cast<byte>(mode) | 0x8);
2311}
2312
2313
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002314void Assembler::roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002315 DCHECK(IsEnabled(SSE4_1));
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002316 EnsureSpace ensure_space(this);
2317 EMIT(0x66);
2318 EMIT(0x0F);
2319 EMIT(0x3A);
2320 EMIT(0x0B);
2321 emit_sse_operand(dst, src);
2322 // Mask precision exeption.
2323 EMIT(static_cast<byte>(mode) | 0x8);
2324}
2325
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002326
Steve Block6ded16b2010-05-10 14:33:55 +01002327void Assembler::movmskpd(Register dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002328 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002329 EMIT(0x66);
2330 EMIT(0x0F);
2331 EMIT(0x50);
2332 emit_sse_operand(dst, src);
2333}
2334
2335
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002336void Assembler::movmskps(Register dst, XMMRegister src) {
2337 EnsureSpace ensure_space(this);
2338 EMIT(0x0F);
2339 EMIT(0x50);
2340 emit_sse_operand(dst, src);
2341}
2342
2343
2344void Assembler::pcmpeqd(XMMRegister dst, XMMRegister src) {
2345 EnsureSpace ensure_space(this);
2346 EMIT(0x66);
2347 EMIT(0x0F);
2348 EMIT(0x76);
2349 emit_sse_operand(dst, src);
2350}
2351
2352
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002353void Assembler::punpckldq(XMMRegister dst, XMMRegister src) {
2354 EnsureSpace ensure_space(this);
2355 EMIT(0x66);
2356 EMIT(0x0F);
2357 EMIT(0x62);
2358 emit_sse_operand(dst, src);
2359}
2360
2361
2362void Assembler::punpckhdq(XMMRegister dst, XMMRegister src) {
2363 EnsureSpace ensure_space(this);
2364 EMIT(0x66);
2365 EMIT(0x0F);
2366 EMIT(0x6A);
2367 emit_sse_operand(dst, src);
2368}
2369
2370
2371void Assembler::maxsd(XMMRegister dst, const Operand& src) {
2372 EnsureSpace ensure_space(this);
2373 EMIT(0xF2);
2374 EMIT(0x0F);
2375 EMIT(0x5F);
2376 emit_sse_operand(dst, src);
2377}
2378
2379
2380void Assembler::minsd(XMMRegister dst, const Operand& src) {
2381 EnsureSpace ensure_space(this);
2382 EMIT(0xF2);
2383 EMIT(0x0F);
2384 EMIT(0x5D);
2385 emit_sse_operand(dst, src);
2386}
2387
2388
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002389void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002390 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002391 EMIT(0xF2);
2392 EMIT(0x0F);
2393 EMIT(0xC2);
2394 emit_sse_operand(dst, src);
2395 EMIT(1); // LT == 1
2396}
2397
2398
2399void Assembler::movaps(XMMRegister dst, XMMRegister src) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002400 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002401 EMIT(0x0F);
2402 EMIT(0x28);
2403 emit_sse_operand(dst, src);
2404}
2405
2406
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002407void Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) {
2408 DCHECK(is_uint8(imm8));
2409 EnsureSpace ensure_space(this);
2410 EMIT(0x0F);
2411 EMIT(0xC6);
2412 emit_sse_operand(dst, src);
2413 EMIT(imm8);
2414}
2415
2416
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002417void Assembler::movdqa(const Operand& dst, XMMRegister src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002418 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002419 EMIT(0x66);
2420 EMIT(0x0F);
2421 EMIT(0x7F);
2422 emit_sse_operand(src, dst);
2423}
2424
2425
2426void Assembler::movdqa(XMMRegister dst, const Operand& src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002427 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002428 EMIT(0x66);
2429 EMIT(0x0F);
2430 EMIT(0x6F);
2431 emit_sse_operand(dst, src);
2432}
2433
2434
2435void Assembler::movdqu(const Operand& dst, XMMRegister src ) {
Leon Clarkee46be812010-01-19 14:06:41 +00002436 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002437 EMIT(0xF3);
2438 EMIT(0x0F);
2439 EMIT(0x7F);
2440 emit_sse_operand(src, dst);
2441}
2442
2443
2444void Assembler::movdqu(XMMRegister dst, const Operand& src) {
Leon Clarkee46be812010-01-19 14:06:41 +00002445 EnsureSpace ensure_space(this);
Leon Clarkee46be812010-01-19 14:06:41 +00002446 EMIT(0xF3);
2447 EMIT(0x0F);
2448 EMIT(0x6F);
2449 emit_sse_operand(dst, src);
2450}
2451
2452
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002453void Assembler::prefetch(const Operand& src, int level) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002454 DCHECK(is_uint2(level));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002455 EnsureSpace ensure_space(this);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002456 EMIT(0x0F);
2457 EMIT(0x18);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002458 // Emit hint number in Reg position of RegR/M.
2459 XMMRegister code = XMMRegister::from_code(level);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01002460 emit_sse_operand(code, src);
2461}
2462
2463
Steve Blocka7e24c12009-10-30 11:49:00 +00002464void Assembler::movsd(const Operand& dst, XMMRegister src ) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002465 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002466 EMIT(0xF2); // double
2467 EMIT(0x0F);
2468 EMIT(0x11); // store
2469 emit_sse_operand(src, dst);
2470}
2471
2472
2473void Assembler::movsd(XMMRegister dst, const Operand& src) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002474 EnsureSpace ensure_space(this);
Steve Blocka7e24c12009-10-30 11:49:00 +00002475 EMIT(0xF2); // double
2476 EMIT(0x0F);
2477 EMIT(0x10); // load
2478 emit_sse_operand(dst, src);
2479}
2480
Ben Murdochb0fe1622011-05-05 13:52:32 +01002481
Steve Block44f0eee2011-05-26 01:26:41 +01002482void Assembler::movss(const Operand& dst, XMMRegister src ) {
Steve Block44f0eee2011-05-26 01:26:41 +01002483 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002484 EMIT(0xF3); // float
2485 EMIT(0x0F);
2486 EMIT(0x11); // store
2487 emit_sse_operand(src, dst);
2488}
2489
2490
2491void Assembler::movss(XMMRegister dst, const Operand& src) {
Steve Block44f0eee2011-05-26 01:26:41 +01002492 EnsureSpace ensure_space(this);
Steve Block44f0eee2011-05-26 01:26:41 +01002493 EMIT(0xF3); // float
2494 EMIT(0x0F);
2495 EMIT(0x10); // load
2496 emit_sse_operand(dst, src);
2497}
2498
2499
Steve Block6ded16b2010-05-10 14:33:55 +01002500void Assembler::movd(XMMRegister dst, const Operand& src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002501 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002502 EMIT(0x66);
2503 EMIT(0x0F);
2504 EMIT(0x6E);
2505 emit_sse_operand(dst, src);
2506}
2507
2508
Ben Murdochb0fe1622011-05-05 13:52:32 +01002509void Assembler::movd(const Operand& dst, XMMRegister src) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002510 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002511 EMIT(0x66);
2512 EMIT(0x0F);
2513 EMIT(0x7E);
2514 emit_sse_operand(src, dst);
2515}
2516
2517
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002518void Assembler::extractps(Register dst, XMMRegister src, byte imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002519 DCHECK(IsEnabled(SSE4_1));
2520 DCHECK(is_uint8(imm8));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002521 EnsureSpace ensure_space(this);
2522 EMIT(0x66);
2523 EMIT(0x0F);
2524 EMIT(0x3A);
2525 EMIT(0x17);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002526 emit_sse_operand(src, dst);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002527 EMIT(imm8);
2528}
2529
2530
Ben Murdochb0fe1622011-05-05 13:52:32 +01002531void Assembler::pand(XMMRegister dst, XMMRegister src) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002532 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002533 EMIT(0x66);
2534 EMIT(0x0F);
2535 EMIT(0xDB);
2536 emit_sse_operand(dst, src);
2537}
2538
2539
Steve Block6ded16b2010-05-10 14:33:55 +01002540void Assembler::pxor(XMMRegister dst, XMMRegister src) {
Steve Block6ded16b2010-05-10 14:33:55 +01002541 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002542 EMIT(0x66);
2543 EMIT(0x0F);
2544 EMIT(0xEF);
2545 emit_sse_operand(dst, src);
2546}
2547
2548
Ben Murdochb8e0da22011-05-16 14:20:40 +01002549void Assembler::por(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002550 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002551 EMIT(0x66);
2552 EMIT(0x0F);
2553 EMIT(0xEB);
2554 emit_sse_operand(dst, src);
2555}
2556
2557
Steve Block6ded16b2010-05-10 14:33:55 +01002558void Assembler::ptest(XMMRegister dst, XMMRegister src) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002559 DCHECK(IsEnabled(SSE4_1));
Steve Block6ded16b2010-05-10 14:33:55 +01002560 EnsureSpace ensure_space(this);
Steve Block6ded16b2010-05-10 14:33:55 +01002561 EMIT(0x66);
2562 EMIT(0x0F);
2563 EMIT(0x38);
2564 EMIT(0x17);
2565 emit_sse_operand(dst, src);
2566}
2567
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002568
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002569void Assembler::pslld(XMMRegister reg, int8_t shift) {
2570 EnsureSpace ensure_space(this);
2571 EMIT(0x66);
2572 EMIT(0x0F);
2573 EMIT(0x72);
2574 emit_sse_operand(esi, reg); // esi == 6
2575 EMIT(shift);
2576}
2577
2578
2579void Assembler::psrld(XMMRegister reg, int8_t shift) {
2580 EnsureSpace ensure_space(this);
2581 EMIT(0x66);
2582 EMIT(0x0F);
2583 EMIT(0x72);
2584 emit_sse_operand(edx, reg); // edx == 2
2585 EMIT(shift);
2586}
2587
2588
Ben Murdochb0fe1622011-05-05 13:52:32 +01002589void Assembler::psllq(XMMRegister reg, int8_t shift) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002590 EnsureSpace ensure_space(this);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002591 EMIT(0x66);
2592 EMIT(0x0F);
2593 EMIT(0x73);
2594 emit_sse_operand(esi, reg); // esi == 6
Ben Murdochb0fe1622011-05-05 13:52:32 +01002595 EMIT(shift);
2596}
2597
2598
Ben Murdochb8e0da22011-05-16 14:20:40 +01002599void Assembler::psllq(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002600 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002601 EMIT(0x66);
2602 EMIT(0x0F);
2603 EMIT(0xF3);
2604 emit_sse_operand(dst, src);
2605}
2606
2607
2608void Assembler::psrlq(XMMRegister reg, int8_t shift) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002609 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002610 EMIT(0x66);
2611 EMIT(0x0F);
2612 EMIT(0x73);
2613 emit_sse_operand(edx, reg); // edx == 2
2614 EMIT(shift);
2615}
2616
2617
2618void Assembler::psrlq(XMMRegister dst, XMMRegister src) {
Ben Murdochb8e0da22011-05-16 14:20:40 +01002619 EnsureSpace ensure_space(this);
Ben Murdochb8e0da22011-05-16 14:20:40 +01002620 EMIT(0x66);
2621 EMIT(0x0F);
2622 EMIT(0xD3);
2623 emit_sse_operand(dst, src);
2624}
2625
2626
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002627void Assembler::pshufd(XMMRegister dst, XMMRegister src, uint8_t shuffle) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01002628 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002629 EMIT(0x66);
2630 EMIT(0x0F);
2631 EMIT(0x70);
2632 emit_sse_operand(dst, src);
2633 EMIT(shuffle);
2634}
2635
2636
2637void Assembler::pextrd(const Operand& dst, XMMRegister src, int8_t offset) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002638 DCHECK(IsEnabled(SSE4_1));
Ben Murdochb0fe1622011-05-05 13:52:32 +01002639 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002640 EMIT(0x66);
2641 EMIT(0x0F);
2642 EMIT(0x3A);
2643 EMIT(0x16);
2644 emit_sse_operand(src, dst);
2645 EMIT(offset);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002646}
2647
2648
Steve Block1e0659c2011-05-24 12:43:12 +01002649void Assembler::pinsrd(XMMRegister dst, const Operand& src, int8_t offset) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002650 DCHECK(IsEnabled(SSE4_1));
Steve Block1e0659c2011-05-24 12:43:12 +01002651 EnsureSpace ensure_space(this);
Steve Block1e0659c2011-05-24 12:43:12 +01002652 EMIT(0x66);
2653 EMIT(0x0F);
2654 EMIT(0x3A);
2655 EMIT(0x22);
2656 emit_sse_operand(dst, src);
2657 EMIT(offset);
2658}
2659
2660
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002661void Assembler::addss(XMMRegister dst, const Operand& src) {
2662 EnsureSpace ensure_space(this);
2663 EMIT(0xF3);
2664 EMIT(0x0F);
2665 EMIT(0x58);
2666 emit_sse_operand(dst, src);
2667}
2668
2669
2670void Assembler::subss(XMMRegister dst, const Operand& src) {
2671 EnsureSpace ensure_space(this);
2672 EMIT(0xF3);
2673 EMIT(0x0F);
2674 EMIT(0x5C);
2675 emit_sse_operand(dst, src);
2676}
2677
2678
2679void Assembler::mulss(XMMRegister dst, const Operand& src) {
2680 EnsureSpace ensure_space(this);
2681 EMIT(0xF3);
2682 EMIT(0x0F);
2683 EMIT(0x59);
2684 emit_sse_operand(dst, src);
2685}
2686
2687
2688void Assembler::divss(XMMRegister dst, const Operand& src) {
2689 EnsureSpace ensure_space(this);
2690 EMIT(0xF3);
2691 EMIT(0x0F);
2692 EMIT(0x5E);
2693 emit_sse_operand(dst, src);
2694}
2695
2696
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002697void Assembler::sqrtss(XMMRegister dst, const Operand& src) {
2698 EnsureSpace ensure_space(this);
2699 EMIT(0xF3);
2700 EMIT(0x0F);
2701 EMIT(0x51);
2702 emit_sse_operand(dst, src);
2703}
2704
2705
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002706void Assembler::ucomiss(XMMRegister dst, const Operand& src) {
2707 EnsureSpace ensure_space(this);
2708 EMIT(0x0f);
2709 EMIT(0x2e);
2710 emit_sse_operand(dst, src);
2711}
2712
2713
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002714void Assembler::maxss(XMMRegister dst, const Operand& src) {
2715 EnsureSpace ensure_space(this);
2716 EMIT(0xF3);
2717 EMIT(0x0F);
2718 EMIT(0x5F);
2719 emit_sse_operand(dst, src);
2720}
2721
2722
2723void Assembler::minss(XMMRegister dst, const Operand& src) {
2724 EnsureSpace ensure_space(this);
2725 EMIT(0xF3);
2726 EMIT(0x0F);
2727 EMIT(0x5D);
2728 emit_sse_operand(dst, src);
2729}
2730
2731
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002732// AVX instructions
2733void Assembler::vfmasd(byte op, XMMRegister dst, XMMRegister src1,
2734 const Operand& src2) {
2735 DCHECK(IsEnabled(FMA3));
2736 EnsureSpace ensure_space(this);
2737 emit_vex_prefix(src1, kLIG, k66, k0F38, kW1);
2738 EMIT(op);
2739 emit_sse_operand(dst, src2);
2740}
2741
2742
2743void Assembler::vfmass(byte op, XMMRegister dst, XMMRegister src1,
2744 const Operand& src2) {
2745 DCHECK(IsEnabled(FMA3));
2746 EnsureSpace ensure_space(this);
2747 emit_vex_prefix(src1, kLIG, k66, k0F38, kW0);
2748 EMIT(op);
2749 emit_sse_operand(dst, src2);
2750}
2751
2752
2753void Assembler::vsd(byte op, XMMRegister dst, XMMRegister src1,
2754 const Operand& src2) {
2755 DCHECK(IsEnabled(AVX));
2756 EnsureSpace ensure_space(this);
2757 emit_vex_prefix(src1, kLIG, kF2, k0F, kWIG);
2758 EMIT(op);
2759 emit_sse_operand(dst, src2);
2760}
2761
2762
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002763void Assembler::vss(byte op, XMMRegister dst, XMMRegister src1,
2764 const Operand& src2) {
2765 DCHECK(IsEnabled(AVX));
2766 EnsureSpace ensure_space(this);
2767 emit_vex_prefix(src1, kLIG, kF3, k0F, kWIG);
2768 EMIT(op);
2769 emit_sse_operand(dst, src2);
2770}
2771
2772
2773void Assembler::vps(byte op, XMMRegister dst, XMMRegister src1,
2774 const Operand& src2) {
2775 DCHECK(IsEnabled(AVX));
2776 EnsureSpace ensure_space(this);
2777 emit_vex_prefix(src1, kL128, kNone, k0F, kWIG);
2778 EMIT(op);
2779 emit_sse_operand(dst, src2);
2780}
2781
2782
2783void Assembler::vpd(byte op, XMMRegister dst, XMMRegister src1,
2784 const Operand& src2) {
2785 DCHECK(IsEnabled(AVX));
2786 EnsureSpace ensure_space(this);
2787 emit_vex_prefix(src1, kL128, k66, k0F, kWIG);
2788 EMIT(op);
2789 emit_sse_operand(dst, src2);
2790}
2791
2792
2793void Assembler::bmi1(byte op, Register reg, Register vreg, const Operand& rm) {
2794 DCHECK(IsEnabled(BMI1));
2795 EnsureSpace ensure_space(this);
2796 emit_vex_prefix(vreg, kLZ, kNone, k0F38, kW0);
2797 EMIT(op);
2798 emit_operand(reg, rm);
2799}
2800
2801
2802void Assembler::tzcnt(Register dst, const Operand& src) {
2803 DCHECK(IsEnabled(BMI1));
2804 EnsureSpace ensure_space(this);
2805 EMIT(0xF3);
2806 EMIT(0x0F);
2807 EMIT(0xBC);
2808 emit_operand(dst, src);
2809}
2810
2811
2812void Assembler::lzcnt(Register dst, const Operand& src) {
2813 DCHECK(IsEnabled(LZCNT));
2814 EnsureSpace ensure_space(this);
2815 EMIT(0xF3);
2816 EMIT(0x0F);
2817 EMIT(0xBD);
2818 emit_operand(dst, src);
2819}
2820
2821
2822void Assembler::popcnt(Register dst, const Operand& src) {
2823 DCHECK(IsEnabled(POPCNT));
2824 EnsureSpace ensure_space(this);
2825 EMIT(0xF3);
2826 EMIT(0x0F);
2827 EMIT(0xB8);
2828 emit_operand(dst, src);
2829}
2830
2831
2832void Assembler::bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg,
2833 const Operand& rm) {
2834 DCHECK(IsEnabled(BMI2));
2835 EnsureSpace ensure_space(this);
2836 emit_vex_prefix(vreg, kLZ, pp, k0F38, kW0);
2837 EMIT(op);
2838 emit_operand(reg, rm);
2839}
2840
2841
2842void Assembler::rorx(Register dst, const Operand& src, byte imm8) {
2843 DCHECK(IsEnabled(BMI2));
2844 DCHECK(is_uint8(imm8));
2845 Register vreg = {0}; // VEX.vvvv unused
2846 EnsureSpace ensure_space(this);
2847 emit_vex_prefix(vreg, kLZ, kF2, k0F3A, kW0);
2848 EMIT(0xF0);
2849 emit_operand(dst, src);
2850 EMIT(imm8);
2851}
2852
2853
Steve Blocka7e24c12009-10-30 11:49:00 +00002854void Assembler::emit_sse_operand(XMMRegister reg, const Operand& adr) {
2855 Register ireg = { reg.code() };
2856 emit_operand(ireg, adr);
2857}
2858
2859
2860void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
2861 EMIT(0xC0 | dst.code() << 3 | src.code());
2862}
2863
2864
Steve Block6ded16b2010-05-10 14:33:55 +01002865void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
2866 EMIT(0xC0 | dst.code() << 3 | src.code());
2867}
2868
2869
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002870void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
2871 EMIT(0xC0 | (dst.code() << 3) | src.code());
2872}
2873
2874
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002875void Assembler::emit_vex_prefix(XMMRegister vreg, VectorLength l, SIMDPrefix pp,
2876 LeadingOpcode mm, VexW w) {
2877 if (mm != k0F || w != kW0) {
2878 EMIT(0xc4);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002879 // Change RXB from "110" to "111" to align with gdb disassembler.
2880 EMIT(0xe0 | mm);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002881 EMIT(w | ((~vreg.code() & 0xf) << 3) | l | pp);
2882 } else {
2883 EMIT(0xc5);
2884 EMIT(((~vreg.code()) << 3) | l | pp);
2885 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002886}
2887
2888
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002889void Assembler::emit_vex_prefix(Register vreg, VectorLength l, SIMDPrefix pp,
2890 LeadingOpcode mm, VexW w) {
2891 XMMRegister ivreg = {vreg.code()};
2892 emit_vex_prefix(ivreg, l, pp, mm, w);
Steve Blocka7e24c12009-10-30 11:49:00 +00002893}
2894
2895
Steve Blocka7e24c12009-10-30 11:49:00 +00002896void Assembler::GrowBuffer() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002897 DCHECK(buffer_overflow());
Steve Blocka7e24c12009-10-30 11:49:00 +00002898 if (!own_buffer_) FATAL("external code buffer is too small");
2899
Andrei Popescu31002712010-02-23 13:46:05 +00002900 // Compute new buffer size.
Steve Blocka7e24c12009-10-30 11:49:00 +00002901 CodeDesc desc; // the new buffer
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002902 desc.buffer_size = 2 * buffer_size_;
2903
Steve Blocka7e24c12009-10-30 11:49:00 +00002904 // Some internal data structures overflow for very large buffers,
2905 // they must ensure that kMaximalBufferSize is not too large.
2906 if ((desc.buffer_size > kMaximalBufferSize) ||
Steve Block44f0eee2011-05-26 01:26:41 +01002907 (desc.buffer_size > isolate()->heap()->MaxOldGenerationSize())) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002908 V8::FatalProcessOutOfMemory("Assembler::GrowBuffer");
2909 }
2910
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002911 // Set up new buffer.
Steve Blocka7e24c12009-10-30 11:49:00 +00002912 desc.buffer = NewArray<byte>(desc.buffer_size);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002913 desc.origin = this;
Steve Blocka7e24c12009-10-30 11:49:00 +00002914 desc.instr_size = pc_offset();
2915 desc.reloc_size = (buffer_ + buffer_size_) - (reloc_info_writer.pos());
2916
2917 // Clear the buffer in debug mode. Use 'int3' instructions to make
2918 // sure to get into problems if we ever run uninitialized code.
2919#ifdef DEBUG
2920 memset(desc.buffer, 0xCC, desc.buffer_size);
2921#endif
2922
Andrei Popescu31002712010-02-23 13:46:05 +00002923 // Copy the data.
Steve Blocka7e24c12009-10-30 11:49:00 +00002924 int pc_delta = desc.buffer - buffer_;
2925 int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002926 MemMove(desc.buffer, buffer_, desc.instr_size);
2927 MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(),
2928 desc.reloc_size);
Steve Blocka7e24c12009-10-30 11:49:00 +00002929
Andrei Popescu31002712010-02-23 13:46:05 +00002930 // Switch buffers.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002931 DeleteArray(buffer_);
Steve Blocka7e24c12009-10-30 11:49:00 +00002932 buffer_ = desc.buffer;
2933 buffer_size_ = desc.buffer_size;
2934 pc_ += pc_delta;
Steve Blocka7e24c12009-10-30 11:49:00 +00002935 reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta,
2936 reloc_info_writer.last_pc() + pc_delta);
2937
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002938 // Relocate internal references.
2939 for (auto pos : internal_reference_positions_) {
2940 int32_t* p = reinterpret_cast<int32_t*>(buffer_ + pos);
2941 *p += pc_delta;
Steve Blocka7e24c12009-10-30 11:49:00 +00002942 }
2943
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002944 DCHECK(!buffer_overflow());
Steve Blocka7e24c12009-10-30 11:49:00 +00002945}
2946
2947
2948void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002949 DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode
2950 DCHECK(is_uint8(imm8));
2951 DCHECK((op1 & 0x01) == 0); // should be 8bit operation
Steve Blocka7e24c12009-10-30 11:49:00 +00002952 EMIT(op1);
2953 EMIT(op2 | dst.code());
2954 EMIT(imm8);
2955}
2956
2957
2958void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002959 DCHECK((0 <= sel) && (sel <= 7));
Steve Blocka7e24c12009-10-30 11:49:00 +00002960 Register ireg = { sel };
2961 if (x.is_int8()) {
2962 EMIT(0x83); // using a sign-extended 8-bit immediate.
2963 emit_operand(ireg, dst);
2964 EMIT(x.x_ & 0xFF);
2965 } else if (dst.is_reg(eax)) {
2966 EMIT((sel << 3) | 0x05); // short form if the destination is eax.
2967 emit(x);
2968 } else {
2969 EMIT(0x81); // using a literal 32-bit immediate.
2970 emit_operand(ireg, dst);
2971 emit(x);
2972 }
2973}
2974
2975
2976void Assembler::emit_operand(Register reg, const Operand& adr) {
2977 const unsigned length = adr.len_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002978 DCHECK(length > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00002979
2980 // Emit updated ModRM byte containing the given register.
2981 pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3);
2982
2983 // Emit the rest of the encoded operand.
2984 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i];
2985 pc_ += length;
2986
2987 // Emit relocation information if necessary.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002988 if (length >= sizeof(int32_t) && !RelocInfo::IsNone(adr.rmode_)) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002989 pc_ -= sizeof(int32_t); // pc_ must be *at* disp32
2990 RecordRelocInfo(adr.rmode_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002991 if (adr.rmode_ == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels
2992 emit_label(*reinterpret_cast<Label**>(pc_));
2993 } else {
2994 pc_ += sizeof(int32_t);
2995 }
2996 }
2997}
2998
2999
3000void Assembler::emit_label(Label* label) {
3001 if (label->is_bound()) {
3002 internal_reference_positions_.push_back(pc_offset());
3003 emit(reinterpret_cast<uint32_t>(buffer_ + label->pos()));
3004 } else {
3005 emit_disp(label, Displacement::CODE_ABSOLUTE);
Steve Blocka7e24c12009-10-30 11:49:00 +00003006 }
3007}
3008
3009
3010void Assembler::emit_farith(int b1, int b2, int i) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003011 DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode
3012 DCHECK(0 <= i && i < 8); // illegal stack offset
Steve Blocka7e24c12009-10-30 11:49:00 +00003013 EMIT(b1);
3014 EMIT(b2 + i);
3015}
3016
3017
Ben Murdochb0fe1622011-05-05 13:52:32 +01003018void Assembler::db(uint8_t data) {
Steve Blocka7e24c12009-10-30 11:49:00 +00003019 EnsureSpace ensure_space(this);
Ben Murdochb0fe1622011-05-05 13:52:32 +01003020 EMIT(data);
3021}
3022
3023
3024void Assembler::dd(uint32_t data) {
3025 EnsureSpace ensure_space(this);
3026 emit(data);
Steve Blocka7e24c12009-10-30 11:49:00 +00003027}
3028
3029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003030void Assembler::dq(uint64_t data) {
3031 EnsureSpace ensure_space(this);
3032 emit_q(data);
3033}
3034
3035
3036void Assembler::dd(Label* label) {
3037 EnsureSpace ensure_space(this);
3038 RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE);
3039 emit_label(label);
3040}
3041
3042
Steve Blocka7e24c12009-10-30 11:49:00 +00003043void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003044 DCHECK(!RelocInfo::IsNone(rmode));
Steve Blocka7e24c12009-10-30 11:49:00 +00003045 // Don't record external references unless the heap will be serialized.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003046 if (rmode == RelocInfo::EXTERNAL_REFERENCE &&
3047 !serializer_enabled() && !emit_debug_code()) {
3048 return;
Steve Blocka7e24c12009-10-30 11:49:00 +00003049 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003050 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +00003051 reloc_info_writer.Write(&rinfo);
3052}
3053
3054
3055#ifdef GENERATED_CODE_COVERAGE
3056static FILE* coverage_log = NULL;
3057
3058
3059static void InitCoverageLog() {
3060 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG");
3061 if (file_name != NULL) {
3062 coverage_log = fopen(file_name, "aw+");
3063 }
3064}
3065
3066
3067void LogGeneratedCodeCoverage(const char* file_line) {
3068 const char* return_address = (&file_line)[-1];
3069 char* push_insn = const_cast<char*>(return_address - 12);
3070 push_insn[0] = 0xeb; // Relative branch insn.
3071 push_insn[1] = 13; // Skip over coverage insns.
3072 if (coverage_log != NULL) {
3073 fprintf(coverage_log, "%s\n", file_line);
3074 fflush(coverage_log);
3075 }
3076}
3077
3078#endif
3079
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003080} // namespace internal
3081} // namespace v8
Leon Clarkef7060e22010-06-03 12:02:55 +01003082
3083#endif // V8_TARGET_ARCH_IA32