Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 5 | #include "src/x64/assembler-x64.h" |
| 6 | |
| 7 | #if V8_OS_MACOSX |
| 8 | #include <sys/sysctl.h> |
| 9 | #endif |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 10 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 11 | #if V8_TARGET_ARCH_X64 |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 12 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 13 | #include "src/base/bits.h" |
| 14 | #include "src/macro-assembler.h" |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 15 | #include "src/v8.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | |
| 20 | // ----------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 21 | // Implementation of CpuFeatures |
| 22 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | namespace { |
| 24 | |
| 25 | bool EnableAVX() { |
| 26 | #if V8_OS_MACOSX |
| 27 | // Mac OS X 10.9 has a bug where AVX transitions were indeed being caused by |
| 28 | // ISRs, so we detect Mac OS X 10.9 here and disable AVX in that case. |
| 29 | char buffer[128]; |
| 30 | size_t buffer_size = arraysize(buffer); |
| 31 | int ctl_name[] = { CTL_KERN , KERN_OSRELEASE }; |
| 32 | if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { |
| 33 | V8_Fatal(__FILE__, __LINE__, "V8 failed to get kernel version"); |
| 34 | } |
| 35 | // The buffer now contains a string of the form XX.YY.ZZ, where |
| 36 | // XX is the major kernel version component. 13.x.x (Mavericks) is |
| 37 | // affected by this bug, so disable AVX there. |
| 38 | if (memcmp(buffer, "13.", 3) == 0) return false; |
| 39 | #endif // V8_OS_MACOSX |
| 40 | return FLAG_enable_avx; |
| 41 | } |
| 42 | |
| 43 | } // namespace |
| 44 | |
| 45 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 46 | void CpuFeatures::ProbeImpl(bool cross_compile) { |
| 47 | base::CPU cpu; |
| 48 | CHECK(cpu.has_sse2()); // SSE2 support is mandatory. |
| 49 | CHECK(cpu.has_cmov()); // CMOV support is mandatory. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 50 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 51 | // Only use statically determined features for cross compile (snapshot). |
| 52 | if (cross_compile) return; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 53 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 54 | if (cpu.has_sse41() && FLAG_enable_sse4_1) supported_ |= 1u << SSE4_1; |
| 55 | if (cpu.has_sse3() && FLAG_enable_sse3) supported_ |= 1u << SSE3; |
| 56 | // SAHF is not generally available in long mode. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 57 | if (cpu.has_sahf() && FLAG_enable_sahf) supported_ |= 1u << SAHF; |
| 58 | if (cpu.has_avx() && EnableAVX()) supported_ |= 1u << AVX; |
| 59 | if (cpu.has_fma3() && FLAG_enable_fma3) supported_ |= 1u << FMA3; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 63 | void CpuFeatures::PrintTarget() { } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 64 | void CpuFeatures::PrintFeatures() { |
| 65 | printf("SSE3=%d SSE4_1=%d SAHF=%d AVX=%d FMA3=%d\n", |
| 66 | CpuFeatures::IsSupported(SSE3), CpuFeatures::IsSupported(SSE4_1), |
| 67 | CpuFeatures::IsSupported(SAHF), CpuFeatures::IsSupported(AVX), |
| 68 | CpuFeatures::IsSupported(FMA3)); |
| 69 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 70 | |
| 71 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | // ----------------------------------------------------------------------------- |
| 73 | // Implementation of RelocInfo |
| 74 | |
| 75 | // Patch the code at the current PC with a call to the target address. |
| 76 | // Additional guard int3 instructions can be added if required. |
| 77 | void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 78 | int code_size = Assembler::kCallSequenceLength + guard_bytes; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 79 | |
| 80 | // Create a code patcher. |
| 81 | CodePatcher patcher(pc_, code_size); |
| 82 | |
| 83 | // Add a label for checking the size of the code used for returning. |
| 84 | #ifdef DEBUG |
| 85 | Label check_codesize; |
| 86 | patcher.masm()->bind(&check_codesize); |
| 87 | #endif |
| 88 | |
| 89 | // Patch the code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | patcher.masm()->movp(kScratchRegister, reinterpret_cast<void*>(target), |
| 91 | Assembler::RelocInfoNone()); |
| 92 | patcher.masm()->call(kScratchRegister); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 93 | |
| 94 | // Check that the size of the code generated is as expected. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 95 | DCHECK_EQ(Assembler::kCallSequenceLength, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 96 | patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize)); |
| 97 | |
| 98 | // Add the requested number of int3 instructions after the call. |
| 99 | for (int i = 0; i < guard_bytes; i++) { |
| 100 | patcher.masm()->int3(); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void RelocInfo::PatchCode(byte* instructions, int instruction_count) { |
| 106 | // Patch the code at the current address with the supplied instructions. |
| 107 | for (int i = 0; i < instruction_count; i++) { |
| 108 | *(pc_ + i) = *(instructions + i); |
| 109 | } |
| 110 | |
| 111 | // Indicate that code has changed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 112 | CpuFeatures::FlushICache(pc_, instruction_count); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 115 | |
| 116 | // ----------------------------------------------------------------------------- |
| 117 | // Register constants. |
| 118 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 119 | const int |
| 120 | Register::kRegisterCodeByAllocationIndex[kMaxNumAllocatableRegisters] = { |
| 121 | // rax, rbx, rdx, rcx, rsi, rdi, r8, r9, r11, r14, r15 |
| 122 | 0, 3, 2, 1, 6, 7, 8, 9, 11, 14, 15 |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 125 | const int Register::kAllocationIndexByRegisterCode[kNumRegisters] = { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | 0, 3, 2, 1, -1, -1, 4, 5, 6, 7, -1, 8, -1, -1, 9, 10 |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 130 | // ----------------------------------------------------------------------------- |
| 131 | // Implementation of Operand |
| 132 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 133 | Operand::Operand(Register base, int32_t disp) : rex_(0) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 134 | len_ = 1; |
| 135 | if (base.is(rsp) || base.is(r12)) { |
| 136 | // SIB byte is needed to encode (rsp + offset) or (r12 + offset). |
| 137 | set_sib(times_1, rsp, base); |
| 138 | } |
| 139 | |
| 140 | if (disp == 0 && !base.is(rbp) && !base.is(r13)) { |
| 141 | set_modrm(0, base); |
| 142 | } else if (is_int8(disp)) { |
| 143 | set_modrm(1, base); |
| 144 | set_disp8(disp); |
| 145 | } else { |
| 146 | set_modrm(2, base); |
| 147 | set_disp32(disp); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | |
| 152 | Operand::Operand(Register base, |
| 153 | Register index, |
| 154 | ScaleFactor scale, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 155 | int32_t disp) : rex_(0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 156 | DCHECK(!index.is(rsp)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 157 | len_ = 1; |
| 158 | set_sib(scale, index, base); |
| 159 | if (disp == 0 && !base.is(rbp) && !base.is(r13)) { |
| 160 | // This call to set_modrm doesn't overwrite the REX.B (or REX.X) bits |
| 161 | // possibly set by set_sib. |
| 162 | set_modrm(0, rsp); |
| 163 | } else if (is_int8(disp)) { |
| 164 | set_modrm(1, rsp); |
| 165 | set_disp8(disp); |
| 166 | } else { |
| 167 | set_modrm(2, rsp); |
| 168 | set_disp32(disp); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 173 | Operand::Operand(Register index, |
| 174 | ScaleFactor scale, |
| 175 | int32_t disp) : rex_(0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | DCHECK(!index.is(rsp)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 177 | len_ = 1; |
| 178 | set_modrm(0, rsp); |
| 179 | set_sib(scale, index, rbp); |
| 180 | set_disp32(disp); |
| 181 | } |
| 182 | |
| 183 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 184 | Operand::Operand(const Operand& operand, int32_t offset) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 185 | DCHECK(operand.len_ >= 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 186 | // Operand encodes REX ModR/M [SIB] [Disp]. |
| 187 | byte modrm = operand.buf_[0]; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 188 | DCHECK(modrm < 0xC0); // Disallow mode 3 (register target). |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 189 | bool has_sib = ((modrm & 0x07) == 0x04); |
| 190 | byte mode = modrm & 0xC0; |
| 191 | int disp_offset = has_sib ? 2 : 1; |
| 192 | int base_reg = (has_sib ? operand.buf_[1] : modrm) & 0x07; |
| 193 | // Mode 0 with rbp/r13 as ModR/M or SIB base register always has a 32-bit |
| 194 | // displacement. |
| 195 | bool is_baseless = (mode == 0) && (base_reg == 0x05); // No base or RIP base. |
| 196 | int32_t disp_value = 0; |
| 197 | if (mode == 0x80 || is_baseless) { |
| 198 | // Mode 2 or mode 0 with rbp/r13 as base: Word displacement. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 199 | disp_value = *bit_cast<const int32_t*>(&operand.buf_[disp_offset]); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 200 | } else if (mode == 0x40) { |
| 201 | // Mode 1: Byte displacement. |
| 202 | disp_value = static_cast<signed char>(operand.buf_[disp_offset]); |
| 203 | } |
| 204 | |
| 205 | // Write new operand with same registers, but with modified displacement. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 206 | DCHECK(offset >= 0 ? disp_value + offset > disp_value |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 207 | : disp_value + offset < disp_value); // No overflow. |
| 208 | disp_value += offset; |
| 209 | rex_ = operand.rex_; |
| 210 | if (!is_int8(disp_value) || is_baseless) { |
| 211 | // Need 32 bits of displacement, mode 2 or mode 1 with register rbp/r13. |
| 212 | buf_[0] = (modrm & 0x3f) | (is_baseless ? 0x00 : 0x80); |
| 213 | len_ = disp_offset + 4; |
| 214 | Memory::int32_at(&buf_[disp_offset]) = disp_value; |
| 215 | } else if (disp_value != 0 || (base_reg == 0x05)) { |
| 216 | // Need 8 bits of displacement. |
| 217 | buf_[0] = (modrm & 0x3f) | 0x40; // Mode 1. |
| 218 | len_ = disp_offset + 1; |
| 219 | buf_[disp_offset] = static_cast<byte>(disp_value); |
| 220 | } else { |
| 221 | // Need no displacement. |
| 222 | buf_[0] = (modrm & 0x3f); // Mode 0. |
| 223 | len_ = disp_offset; |
| 224 | } |
| 225 | if (has_sib) { |
| 226 | buf_[1] = operand.buf_[1]; |
| 227 | } |
| 228 | } |
| 229 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 230 | |
| 231 | bool Operand::AddressUsesRegister(Register reg) const { |
| 232 | int code = reg.code(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 233 | DCHECK((buf_[0] & 0xC0) != 0xC0); // Always a memory operand. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 234 | // Start with only low three bits of base register. Initial decoding doesn't |
| 235 | // distinguish on the REX.B bit. |
| 236 | int base_code = buf_[0] & 0x07; |
| 237 | if (base_code == rsp.code()) { |
| 238 | // SIB byte present in buf_[1]. |
| 239 | // Check the index register from the SIB byte + REX.X prefix. |
| 240 | int index_code = ((buf_[1] >> 3) & 0x07) | ((rex_ & 0x02) << 2); |
| 241 | // Index code (including REX.X) of 0x04 (rsp) means no index register. |
| 242 | if (index_code != rsp.code() && index_code == code) return true; |
| 243 | // Add REX.B to get the full base register code. |
| 244 | base_code = (buf_[1] & 0x07) | ((rex_ & 0x01) << 3); |
| 245 | // A base register of 0x05 (rbp) with mod = 0 means no base register. |
| 246 | if (base_code == rbp.code() && ((buf_[0] & 0xC0) == 0)) return false; |
| 247 | return code == base_code; |
| 248 | } else { |
| 249 | // A base register with low bits of 0x05 (rbp or r13) and mod = 0 means |
| 250 | // no base register. |
| 251 | if (base_code == rbp.code() && ((buf_[0] & 0xC0) == 0)) return false; |
| 252 | base_code |= ((rex_ & 0x01) << 3); |
| 253 | return code == base_code; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 258 | // ----------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 259 | // Implementation of Assembler. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 260 | |
| 261 | #ifdef GENERATED_CODE_COVERAGE |
| 262 | static void InitCoverageLog(); |
| 263 | #endif |
| 264 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
| 266 | : AssemblerBase(isolate, buffer, buffer_size), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 267 | code_targets_(100), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 268 | positions_recorder_(this) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 269 | // Clear the buffer in debug mode unless it was provided by the |
| 270 | // caller in which case we can't be sure it's okay to overwrite |
| 271 | // existing code in it. |
| 272 | #ifdef DEBUG |
| 273 | if (own_buffer_) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 274 | memset(buffer_, 0xCC, buffer_size_); // int3 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 275 | } |
| 276 | #endif |
| 277 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 278 | reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 279 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 280 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 281 | #ifdef GENERATED_CODE_COVERAGE |
| 282 | InitCoverageLog(); |
| 283 | #endif |
| 284 | } |
| 285 | |
| 286 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 287 | void Assembler::GetCode(CodeDesc* desc) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 288 | // Finalize code (at this point overflow() may be true, but the gap ensures |
| 289 | // that we are still not overlapping instructions and relocation info). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 290 | DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 291 | // Set up code descriptor. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 292 | desc->buffer = buffer_; |
| 293 | desc->buffer_size = buffer_size_; |
| 294 | desc->instr_size = pc_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 295 | DCHECK(desc->instr_size > 0); // Zero-size code objects upset the system. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 296 | desc->reloc_size = |
| 297 | static_cast<int>((buffer_ + buffer_size_) - reloc_info_writer.pos()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 298 | desc->origin = this; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
| 302 | void Assembler::Align(int m) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 303 | DCHECK(base::bits::IsPowerOfTwo32(m)); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 304 | int delta = (m - (pc_offset() & (m - 1))) & (m - 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 305 | Nop(delta); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 309 | void Assembler::CodeTargetAlign() { |
| 310 | Align(16); // Preferred alignment of jump targets on x64. |
| 311 | } |
| 312 | |
| 313 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 314 | bool Assembler::IsNop(Address addr) { |
| 315 | Address a = addr; |
| 316 | while (*a == 0x66) a++; |
| 317 | if (*a == 0x90) return true; |
| 318 | if (a[0] == 0xf && a[1] == 0x1f) return true; |
| 319 | return false; |
| 320 | } |
| 321 | |
| 322 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 323 | void Assembler::bind_to(Label* L, int pos) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 324 | DCHECK(!L->is_bound()); // Label may only be bound once. |
| 325 | DCHECK(0 <= pos && pos <= pc_offset()); // Position must be valid. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 326 | if (L->is_linked()) { |
| 327 | int current = L->pos(); |
| 328 | int next = long_at(current); |
| 329 | while (next != current) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 330 | // Relative address, relative to point after address. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 331 | int imm32 = pos - (current + sizeof(int32_t)); |
| 332 | long_at_put(current, imm32); |
| 333 | current = next; |
| 334 | next = long_at(next); |
| 335 | } |
| 336 | // Fix up last fixup on linked list. |
| 337 | int last_imm32 = pos - (current + sizeof(int32_t)); |
| 338 | long_at_put(current, last_imm32); |
| 339 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 340 | while (L->is_near_linked()) { |
| 341 | int fixup_pos = L->near_link_pos(); |
| 342 | int offset_to_next = |
| 343 | static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 344 | DCHECK(offset_to_next <= 0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 345 | int disp = pos - (fixup_pos + sizeof(int8_t)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 346 | CHECK(is_int8(disp)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 347 | set_byte_at(fixup_pos, disp); |
| 348 | if (offset_to_next < 0) { |
| 349 | L->link_to(fixup_pos + offset_to_next, Label::kNear); |
| 350 | } else { |
| 351 | L->UnuseNear(); |
| 352 | } |
| 353 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 354 | L->bind_to(pos); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void Assembler::bind(Label* L) { |
| 359 | bind_to(L, pc_offset()); |
| 360 | } |
| 361 | |
| 362 | |
| 363 | void Assembler::GrowBuffer() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 364 | DCHECK(buffer_overflow()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 365 | if (!own_buffer_) FATAL("external code buffer is too small"); |
| 366 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 367 | // Compute new buffer size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 368 | CodeDesc desc; // the new buffer |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 369 | desc.buffer_size = 2 * buffer_size_; |
| 370 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 371 | // Some internal data structures overflow for very large buffers, |
| 372 | // they must ensure that kMaximalBufferSize is not too large. |
| 373 | if ((desc.buffer_size > kMaximalBufferSize) || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 374 | (desc.buffer_size > isolate()->heap()->MaxOldGenerationSize())) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | V8::FatalProcessOutOfMemory("Assembler::GrowBuffer"); |
| 376 | } |
| 377 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 378 | // Set up new buffer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 379 | desc.buffer = NewArray<byte>(desc.buffer_size); |
| 380 | desc.instr_size = pc_offset(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 381 | desc.reloc_size = |
| 382 | static_cast<int>((buffer_ + buffer_size_) - (reloc_info_writer.pos())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 383 | |
| 384 | // Clear the buffer in debug mode. Use 'int3' instructions to make |
| 385 | // sure to get into problems if we ever run uninitialized code. |
| 386 | #ifdef DEBUG |
| 387 | memset(desc.buffer, 0xCC, desc.buffer_size); |
| 388 | #endif |
| 389 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 390 | // Copy the data. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | intptr_t pc_delta = desc.buffer - buffer_; |
| 392 | intptr_t rc_delta = (desc.buffer + desc.buffer_size) - |
| 393 | (buffer_ + buffer_size_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | MemMove(desc.buffer, buffer_, desc.instr_size); |
| 395 | MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(), |
| 396 | desc.reloc_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 397 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 398 | // Switch buffers. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 399 | DeleteArray(buffer_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 400 | buffer_ = desc.buffer; |
| 401 | buffer_size_ = desc.buffer_size; |
| 402 | pc_ += pc_delta; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
| 404 | reloc_info_writer.last_pc() + pc_delta); |
| 405 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 406 | // Relocate runtime entries. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 407 | for (RelocIterator it(desc); !it.done(); it.next()) { |
| 408 | RelocInfo::Mode rmode = it.rinfo()->rmode(); |
| 409 | if (rmode == RelocInfo::INTERNAL_REFERENCE) { |
| 410 | intptr_t* p = reinterpret_cast<intptr_t*>(it.rinfo()->pc()); |
| 411 | if (*p != 0) { // 0 means uninitialized. |
| 412 | *p += pc_delta; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 417 | DCHECK(!buffer_overflow()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | |
| 421 | void Assembler::emit_operand(int code, const Operand& adr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 422 | DCHECK(is_uint3(code)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 423 | const unsigned length = adr.len_; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 424 | DCHECK(length > 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 425 | |
| 426 | // Emit updated ModR/M byte containing the given register. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 427 | DCHECK((adr.buf_[0] & 0x38) == 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 428 | pc_[0] = adr.buf_[0] | code << 3; |
| 429 | |
| 430 | // Emit the rest of the encoded operand. |
| 431 | for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
| 432 | pc_ += length; |
| 433 | } |
| 434 | |
| 435 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 436 | // Assembler Instruction implementations. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 438 | void Assembler::arithmetic_op(byte opcode, |
| 439 | Register reg, |
| 440 | const Operand& op, |
| 441 | int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 442 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 443 | emit_rex(reg, op, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 444 | emit(opcode); |
| 445 | emit_operand(reg, op); |
| 446 | } |
| 447 | |
| 448 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 449 | void Assembler::arithmetic_op(byte opcode, |
| 450 | Register reg, |
| 451 | Register rm_reg, |
| 452 | int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 454 | DCHECK((opcode & 0xC6) == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 455 | if (rm_reg.low_bits() == 4) { // Forces SIB byte. |
| 456 | // Swap reg and rm_reg and change opcode operand order. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 457 | emit_rex(rm_reg, reg, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 458 | emit(opcode ^ 0x02); |
| 459 | emit_modrm(rm_reg, reg); |
| 460 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | emit_rex(reg, rm_reg, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 462 | emit(opcode); |
| 463 | emit_modrm(reg, rm_reg); |
| 464 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
| 468 | void Assembler::arithmetic_op_16(byte opcode, Register reg, Register rm_reg) { |
| 469 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 470 | DCHECK((opcode & 0xC6) == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 471 | if (rm_reg.low_bits() == 4) { // Forces SIB byte. |
| 472 | // Swap reg and rm_reg and change opcode operand order. |
| 473 | emit(0x66); |
| 474 | emit_optional_rex_32(rm_reg, reg); |
| 475 | emit(opcode ^ 0x02); |
| 476 | emit_modrm(rm_reg, reg); |
| 477 | } else { |
| 478 | emit(0x66); |
| 479 | emit_optional_rex_32(reg, rm_reg); |
| 480 | emit(opcode); |
| 481 | emit_modrm(reg, rm_reg); |
| 482 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
| 486 | void Assembler::arithmetic_op_16(byte opcode, |
| 487 | Register reg, |
| 488 | const Operand& rm_reg) { |
| 489 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | emit(0x66); |
| 491 | emit_optional_rex_32(reg, rm_reg); |
| 492 | emit(opcode); |
| 493 | emit_operand(reg, rm_reg); |
| 494 | } |
| 495 | |
| 496 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 497 | void Assembler::arithmetic_op_8(byte opcode, Register reg, const Operand& op) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 498 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 499 | if (!reg.is_byte_register()) { |
| 500 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 501 | emit_rex_32(reg); |
| 502 | } |
| 503 | emit(opcode); |
| 504 | emit_operand(reg, op); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | void Assembler::arithmetic_op_8(byte opcode, Register reg, Register rm_reg) { |
| 509 | EnsureSpace ensure_space(this); |
| 510 | DCHECK((opcode & 0xC6) == 2); |
| 511 | if (rm_reg.low_bits() == 4) { // Forces SIB byte. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 512 | // Swap reg and rm_reg and change opcode operand order. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 513 | if (!rm_reg.is_byte_register() || !reg.is_byte_register()) { |
| 514 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 515 | emit_rex_32(rm_reg, reg); |
| 516 | } |
| 517 | emit(opcode ^ 0x02); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 518 | emit_modrm(rm_reg, reg); |
| 519 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 520 | if (!reg.is_byte_register() || !rm_reg.is_byte_register()) { |
| 521 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 522 | emit_rex_32(reg, rm_reg); |
| 523 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 524 | emit(opcode); |
| 525 | emit_modrm(reg, rm_reg); |
| 526 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | void Assembler::immediate_arithmetic_op(byte subcode, |
| 531 | Register dst, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 532 | Immediate src, |
| 533 | int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 534 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 535 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | if (is_int8(src.value_)) { |
| 537 | emit(0x83); |
| 538 | emit_modrm(subcode, dst); |
| 539 | emit(src.value_); |
| 540 | } else if (dst.is(rax)) { |
| 541 | emit(0x05 | (subcode << 3)); |
| 542 | emitl(src.value_); |
| 543 | } else { |
| 544 | emit(0x81); |
| 545 | emit_modrm(subcode, dst); |
| 546 | emitl(src.value_); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | void Assembler::immediate_arithmetic_op(byte subcode, |
| 551 | const Operand& dst, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 552 | Immediate src, |
| 553 | int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 555 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 556 | if (is_int8(src.value_)) { |
| 557 | emit(0x83); |
| 558 | emit_operand(subcode, dst); |
| 559 | emit(src.value_); |
| 560 | } else { |
| 561 | emit(0x81); |
| 562 | emit_operand(subcode, dst); |
| 563 | emitl(src.value_); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | |
| 568 | void Assembler::immediate_arithmetic_op_16(byte subcode, |
| 569 | Register dst, |
| 570 | Immediate src) { |
| 571 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | emit(0x66); // Operand size override prefix. |
| 573 | emit_optional_rex_32(dst); |
| 574 | if (is_int8(src.value_)) { |
| 575 | emit(0x83); |
| 576 | emit_modrm(subcode, dst); |
| 577 | emit(src.value_); |
| 578 | } else if (dst.is(rax)) { |
| 579 | emit(0x05 | (subcode << 3)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 580 | emitw(src.value_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | } else { |
| 582 | emit(0x81); |
| 583 | emit_modrm(subcode, dst); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 584 | emitw(src.value_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
| 588 | |
| 589 | void Assembler::immediate_arithmetic_op_16(byte subcode, |
| 590 | const Operand& dst, |
| 591 | Immediate src) { |
| 592 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | emit(0x66); // Operand size override prefix. |
| 594 | emit_optional_rex_32(dst); |
| 595 | if (is_int8(src.value_)) { |
| 596 | emit(0x83); |
| 597 | emit_operand(subcode, dst); |
| 598 | emit(src.value_); |
| 599 | } else { |
| 600 | emit(0x81); |
| 601 | emit_operand(subcode, dst); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 602 | emitw(src.value_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 607 | void Assembler::immediate_arithmetic_op_8(byte subcode, |
| 608 | const Operand& dst, |
| 609 | Immediate src) { |
| 610 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 611 | emit_optional_rex_32(dst); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 612 | DCHECK(is_int8(src.value_) || is_uint8(src.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 613 | emit(0x80); |
| 614 | emit_operand(subcode, dst); |
| 615 | emit(src.value_); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | void Assembler::immediate_arithmetic_op_8(byte subcode, |
| 620 | Register dst, |
| 621 | Immediate src) { |
| 622 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 623 | if (!dst.is_byte_register()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 624 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 625 | emit_rex_32(dst); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 626 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 627 | DCHECK(is_int8(src.value_) || is_uint8(src.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | emit(0x80); |
| 629 | emit_modrm(subcode, dst); |
| 630 | emit(src.value_); |
| 631 | } |
| 632 | |
| 633 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 634 | void Assembler::shift(Register dst, |
| 635 | Immediate shift_amount, |
| 636 | int subcode, |
| 637 | int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 638 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 639 | DCHECK(size == kInt64Size ? is_uint6(shift_amount.value_) |
| 640 | : is_uint5(shift_amount.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 641 | if (shift_amount.value_ == 1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 642 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | emit(0xD1); |
| 644 | emit_modrm(subcode, dst); |
| 645 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 646 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 647 | emit(0xC1); |
| 648 | emit_modrm(subcode, dst); |
| 649 | emit(shift_amount.value_); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 654 | void Assembler::shift(Operand dst, Immediate shift_amount, int subcode, |
| 655 | int size) { |
| 656 | EnsureSpace ensure_space(this); |
| 657 | DCHECK(size == kInt64Size ? is_uint6(shift_amount.value_) |
| 658 | : is_uint5(shift_amount.value_)); |
| 659 | if (shift_amount.value_ == 1) { |
| 660 | emit_rex(dst, size); |
| 661 | emit(0xD1); |
| 662 | emit_operand(subcode, dst); |
| 663 | } else { |
| 664 | emit_rex(dst, size); |
| 665 | emit(0xC1); |
| 666 | emit_operand(subcode, dst); |
| 667 | emit(shift_amount.value_); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 672 | void Assembler::shift(Register dst, int subcode, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 673 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 674 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | emit(0xD3); |
| 676 | emit_modrm(subcode, dst); |
| 677 | } |
| 678 | |
| 679 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 680 | void Assembler::shift(Operand dst, int subcode, int size) { |
| 681 | EnsureSpace ensure_space(this); |
| 682 | emit_rex(dst, size); |
| 683 | emit(0xD3); |
| 684 | emit_operand(subcode, dst); |
| 685 | } |
| 686 | |
| 687 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 688 | void Assembler::bt(const Operand& dst, Register src) { |
| 689 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 690 | emit_rex_64(src, dst); |
| 691 | emit(0x0F); |
| 692 | emit(0xA3); |
| 693 | emit_operand(src, dst); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | void Assembler::bts(const Operand& dst, Register src) { |
| 698 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 699 | emit_rex_64(src, dst); |
| 700 | emit(0x0F); |
| 701 | emit(0xAB); |
| 702 | emit_operand(src, dst); |
| 703 | } |
| 704 | |
| 705 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 706 | void Assembler::bsrl(Register dst, Register src) { |
| 707 | EnsureSpace ensure_space(this); |
| 708 | emit_optional_rex_32(dst, src); |
| 709 | emit(0x0F); |
| 710 | emit(0xBD); |
| 711 | emit_modrm(dst, src); |
| 712 | } |
| 713 | |
| 714 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 715 | void Assembler::call(Label* L) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 716 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 717 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 718 | // 1110 1000 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | emit(0xE8); |
| 720 | if (L->is_bound()) { |
| 721 | int offset = L->pos() - pc_offset() - sizeof(int32_t); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 722 | DCHECK(offset <= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 723 | emitl(offset); |
| 724 | } else if (L->is_linked()) { |
| 725 | emitl(L->pos()); |
| 726 | L->link_to(pc_offset() - sizeof(int32_t)); |
| 727 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 728 | DCHECK(L->is_unused()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 729 | int32_t current = pc_offset(); |
| 730 | emitl(current); |
| 731 | L->link_to(current); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 736 | void Assembler::call(Address entry, RelocInfo::Mode rmode) { |
| 737 | DCHECK(RelocInfo::IsRuntimeEntry(rmode)); |
| 738 | positions_recorder()->WriteRecordedPositions(); |
| 739 | EnsureSpace ensure_space(this); |
| 740 | // 1110 1000 #32-bit disp. |
| 741 | emit(0xE8); |
| 742 | emit_runtime_entry(entry, rmode); |
| 743 | } |
| 744 | |
| 745 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 746 | void Assembler::call(Handle<Code> target, |
| 747 | RelocInfo::Mode rmode, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 748 | TypeFeedbackId ast_id) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 749 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 750 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 751 | // 1110 1000 #32-bit disp. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 752 | emit(0xE8); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 753 | emit_code_target(target, rmode, ast_id); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 757 | void Assembler::call(Register adr) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 758 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 759 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 760 | // Opcode: FF /2 r64. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 761 | emit_optional_rex_32(adr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 762 | emit(0xFF); |
| 763 | emit_modrm(0x2, adr); |
| 764 | } |
| 765 | |
| 766 | |
| 767 | void Assembler::call(const Operand& op) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 768 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 769 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 770 | // Opcode: FF /2 m64. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 771 | emit_optional_rex_32(op); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 772 | emit(0xFF); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 773 | emit_operand(0x2, op); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 777 | // Calls directly to the given address using a relative offset. |
| 778 | // Should only ever be used in Code objects for calls within the |
| 779 | // same Code object. Should not be used when generating new code (use labels), |
| 780 | // but only when patching existing code. |
| 781 | void Assembler::call(Address target) { |
| 782 | positions_recorder()->WriteRecordedPositions(); |
| 783 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 784 | // 1110 1000 #32-bit disp. |
| 785 | emit(0xE8); |
| 786 | Address source = pc_ + 4; |
| 787 | intptr_t displacement = target - source; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 788 | DCHECK(is_int32(displacement)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 789 | emitl(static_cast<int32_t>(displacement)); |
| 790 | } |
| 791 | |
| 792 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 793 | void Assembler::clc() { |
| 794 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 795 | emit(0xF8); |
| 796 | } |
| 797 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 798 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 799 | void Assembler::cld() { |
| 800 | EnsureSpace ensure_space(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 801 | emit(0xFC); |
| 802 | } |
| 803 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 804 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 805 | void Assembler::cdq() { |
| 806 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 807 | emit(0x99); |
| 808 | } |
| 809 | |
| 810 | |
| 811 | void Assembler::cmovq(Condition cc, Register dst, Register src) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 812 | if (cc == always) { |
| 813 | movq(dst, src); |
| 814 | } else if (cc == never) { |
| 815 | return; |
| 816 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 817 | // No need to check CpuInfo for CMOV support, it's a required part of the |
| 818 | // 64-bit architecture. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 819 | DCHECK(cc >= 0); // Use mov for unconditional moves. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 820 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 821 | // Opcode: REX.W 0f 40 + cc /r. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 822 | emit_rex_64(dst, src); |
| 823 | emit(0x0f); |
| 824 | emit(0x40 + cc); |
| 825 | emit_modrm(dst, src); |
| 826 | } |
| 827 | |
| 828 | |
| 829 | void Assembler::cmovq(Condition cc, Register dst, const Operand& src) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 830 | if (cc == always) { |
| 831 | movq(dst, src); |
| 832 | } else if (cc == never) { |
| 833 | return; |
| 834 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 835 | DCHECK(cc >= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 837 | // Opcode: REX.W 0f 40 + cc /r. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 838 | emit_rex_64(dst, src); |
| 839 | emit(0x0f); |
| 840 | emit(0x40 + cc); |
| 841 | emit_operand(dst, src); |
| 842 | } |
| 843 | |
| 844 | |
| 845 | void Assembler::cmovl(Condition cc, Register dst, Register src) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 846 | if (cc == always) { |
| 847 | movl(dst, src); |
| 848 | } else if (cc == never) { |
| 849 | return; |
| 850 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 851 | DCHECK(cc >= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 852 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 853 | // Opcode: 0f 40 + cc /r. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 854 | emit_optional_rex_32(dst, src); |
| 855 | emit(0x0f); |
| 856 | emit(0x40 + cc); |
| 857 | emit_modrm(dst, src); |
| 858 | } |
| 859 | |
| 860 | |
| 861 | void Assembler::cmovl(Condition cc, Register dst, const Operand& src) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 862 | if (cc == always) { |
| 863 | movl(dst, src); |
| 864 | } else if (cc == never) { |
| 865 | return; |
| 866 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 867 | DCHECK(cc >= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 868 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 869 | // Opcode: 0f 40 + cc /r. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 870 | emit_optional_rex_32(dst, src); |
| 871 | emit(0x0f); |
| 872 | emit(0x40 + cc); |
| 873 | emit_operand(dst, src); |
| 874 | } |
| 875 | |
| 876 | |
| 877 | void Assembler::cmpb_al(Immediate imm8) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 878 | DCHECK(is_int8(imm8.value_) || is_uint8(imm8.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 879 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 880 | emit(0x3c); |
| 881 | emit(imm8.value_); |
| 882 | } |
| 883 | |
| 884 | |
| 885 | void Assembler::cpuid() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 886 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 887 | emit(0x0F); |
| 888 | emit(0xA2); |
| 889 | } |
| 890 | |
| 891 | |
| 892 | void Assembler::cqo() { |
| 893 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 894 | emit_rex_64(); |
| 895 | emit(0x99); |
| 896 | } |
| 897 | |
| 898 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 899 | void Assembler::emit_dec(Register dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 900 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 901 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 902 | emit(0xFF); |
| 903 | emit_modrm(0x1, dst); |
| 904 | } |
| 905 | |
| 906 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 907 | void Assembler::emit_dec(const Operand& dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 908 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 909 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 910 | emit(0xFF); |
| 911 | emit_operand(1, dst); |
| 912 | } |
| 913 | |
| 914 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 915 | void Assembler::decb(Register dst) { |
| 916 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 917 | if (!dst.is_byte_register()) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 918 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 919 | emit_rex_32(dst); |
| 920 | } |
| 921 | emit(0xFE); |
| 922 | emit_modrm(0x1, dst); |
| 923 | } |
| 924 | |
| 925 | |
| 926 | void Assembler::decb(const Operand& dst) { |
| 927 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 928 | emit_optional_rex_32(dst); |
| 929 | emit(0xFE); |
| 930 | emit_operand(1, dst); |
| 931 | } |
| 932 | |
| 933 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | void Assembler::enter(Immediate size) { |
| 935 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 936 | emit(0xC8); |
| 937 | emitw(size.value_); // 16 bit operand, always. |
| 938 | emit(0); |
| 939 | } |
| 940 | |
| 941 | |
| 942 | void Assembler::hlt() { |
| 943 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 944 | emit(0xF4); |
| 945 | } |
| 946 | |
| 947 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 948 | void Assembler::emit_idiv(Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 949 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 950 | emit_rex(src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | emit(0xF7); |
| 952 | emit_modrm(0x7, src); |
| 953 | } |
| 954 | |
| 955 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 956 | void Assembler::emit_div(Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 957 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 958 | emit_rex(src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 959 | emit(0xF7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 960 | emit_modrm(0x6, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 964 | void Assembler::emit_imul(Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 965 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 966 | emit_rex(src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 967 | emit(0xF7); |
| 968 | emit_modrm(0x5, src); |
| 969 | } |
| 970 | |
| 971 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 972 | void Assembler::emit_imul(const Operand& src, int size) { |
| 973 | EnsureSpace ensure_space(this); |
| 974 | emit_rex(src, size); |
| 975 | emit(0xF7); |
| 976 | emit_operand(0x5, src); |
| 977 | } |
| 978 | |
| 979 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 980 | void Assembler::emit_imul(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 982 | emit_rex(dst, src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 983 | emit(0x0F); |
| 984 | emit(0xAF); |
| 985 | emit_modrm(dst, src); |
| 986 | } |
| 987 | |
| 988 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 989 | void Assembler::emit_imul(Register dst, const Operand& src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 990 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 991 | emit_rex(dst, src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 992 | emit(0x0F); |
| 993 | emit(0xAF); |
| 994 | emit_operand(dst, src); |
| 995 | } |
| 996 | |
| 997 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 998 | void Assembler::emit_imul(Register dst, Register src, Immediate imm, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 999 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1000 | emit_rex(dst, src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1001 | if (is_int8(imm.value_)) { |
| 1002 | emit(0x6B); |
| 1003 | emit_modrm(dst, src); |
| 1004 | emit(imm.value_); |
| 1005 | } else { |
| 1006 | emit(0x69); |
| 1007 | emit_modrm(dst, src); |
| 1008 | emitl(imm.value_); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1013 | void Assembler::emit_imul(Register dst, const Operand& src, Immediate imm, |
| 1014 | int size) { |
| 1015 | EnsureSpace ensure_space(this); |
| 1016 | emit_rex(dst, src, size); |
| 1017 | if (is_int8(imm.value_)) { |
| 1018 | emit(0x6B); |
| 1019 | emit_operand(dst, src); |
| 1020 | emit(imm.value_); |
| 1021 | } else { |
| 1022 | emit(0x69); |
| 1023 | emit_operand(dst, src); |
| 1024 | emitl(imm.value_); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1029 | void Assembler::emit_inc(Register dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1030 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1031 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1032 | emit(0xFF); |
| 1033 | emit_modrm(0x0, dst); |
| 1034 | } |
| 1035 | |
| 1036 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1037 | void Assembler::emit_inc(const Operand& dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1038 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1039 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1040 | emit(0xFF); |
| 1041 | emit_operand(0, dst); |
| 1042 | } |
| 1043 | |
| 1044 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1045 | void Assembler::int3() { |
| 1046 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1047 | emit(0xCC); |
| 1048 | } |
| 1049 | |
| 1050 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1051 | void Assembler::j(Condition cc, Label* L, Label::Distance distance) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1052 | if (cc == always) { |
| 1053 | jmp(L); |
| 1054 | return; |
| 1055 | } else if (cc == never) { |
| 1056 | return; |
| 1057 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1058 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1059 | DCHECK(is_uint4(cc)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1060 | if (L->is_bound()) { |
| 1061 | const int short_size = 2; |
| 1062 | const int long_size = 6; |
| 1063 | int offs = L->pos() - pc_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1064 | DCHECK(offs <= 0); |
| 1065 | // Determine whether we can use 1-byte offsets for backwards branches, |
| 1066 | // which have a max range of 128 bytes. |
| 1067 | |
| 1068 | // We also need to check predictable_code_size() flag here, because on x64, |
| 1069 | // when the full code generator recompiles code for debugging, some places |
| 1070 | // need to be padded out to a certain size. The debugger is keeping track of |
| 1071 | // how often it did this so that it can adjust return addresses on the |
| 1072 | // stack, but if the size of jump instructions can also change, that's not |
| 1073 | // enough and the calculated offsets would be incorrect. |
| 1074 | if (is_int8(offs - short_size) && !predictable_code_size()) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1075 | // 0111 tttn #8-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1076 | emit(0x70 | cc); |
| 1077 | emit((offs - short_size) & 0xFF); |
| 1078 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1079 | // 0000 1111 1000 tttn #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1080 | emit(0x0F); |
| 1081 | emit(0x80 | cc); |
| 1082 | emitl(offs - long_size); |
| 1083 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1084 | } else if (distance == Label::kNear) { |
| 1085 | // 0111 tttn #8-bit disp |
| 1086 | emit(0x70 | cc); |
| 1087 | byte disp = 0x00; |
| 1088 | if (L->is_near_linked()) { |
| 1089 | int offset = L->near_link_pos() - pc_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1090 | DCHECK(is_int8(offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1091 | disp = static_cast<byte>(offset & 0xFF); |
| 1092 | } |
| 1093 | L->link_to(pc_offset(), Label::kNear); |
| 1094 | emit(disp); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1095 | } else if (L->is_linked()) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1096 | // 0000 1111 1000 tttn #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1097 | emit(0x0F); |
| 1098 | emit(0x80 | cc); |
| 1099 | emitl(L->pos()); |
| 1100 | L->link_to(pc_offset() - sizeof(int32_t)); |
| 1101 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1102 | DCHECK(L->is_unused()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1103 | emit(0x0F); |
| 1104 | emit(0x80 | cc); |
| 1105 | int32_t current = pc_offset(); |
| 1106 | emitl(current); |
| 1107 | L->link_to(current); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1112 | void Assembler::j(Condition cc, Address entry, RelocInfo::Mode rmode) { |
| 1113 | DCHECK(RelocInfo::IsRuntimeEntry(rmode)); |
| 1114 | EnsureSpace ensure_space(this); |
| 1115 | DCHECK(is_uint4(cc)); |
| 1116 | emit(0x0F); |
| 1117 | emit(0x80 | cc); |
| 1118 | emit_runtime_entry(entry, rmode); |
| 1119 | } |
| 1120 | |
| 1121 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1122 | void Assembler::j(Condition cc, |
| 1123 | Handle<Code> target, |
| 1124 | RelocInfo::Mode rmode) { |
| 1125 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1126 | DCHECK(is_uint4(cc)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1127 | // 0000 1111 1000 tttn #32-bit disp. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1128 | emit(0x0F); |
| 1129 | emit(0x80 | cc); |
| 1130 | emit_code_target(target, rmode); |
| 1131 | } |
| 1132 | |
| 1133 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1134 | void Assembler::jmp(Label* L, Label::Distance distance) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1135 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1136 | const int short_size = sizeof(int8_t); |
| 1137 | const int long_size = sizeof(int32_t); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1138 | if (L->is_bound()) { |
| 1139 | int offs = L->pos() - pc_offset() - 1; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1140 | DCHECK(offs <= 0); |
| 1141 | if (is_int8(offs - short_size) && !predictable_code_size()) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1142 | // 1110 1011 #8-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1143 | emit(0xEB); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1144 | emit((offs - short_size) & 0xFF); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1146 | // 1110 1001 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1147 | emit(0xE9); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1148 | emitl(offs - long_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1149 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1150 | } else if (distance == Label::kNear) { |
| 1151 | emit(0xEB); |
| 1152 | byte disp = 0x00; |
| 1153 | if (L->is_near_linked()) { |
| 1154 | int offset = L->near_link_pos() - pc_offset(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1155 | DCHECK(is_int8(offset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1156 | disp = static_cast<byte>(offset & 0xFF); |
| 1157 | } |
| 1158 | L->link_to(pc_offset(), Label::kNear); |
| 1159 | emit(disp); |
| 1160 | } else if (L->is_linked()) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1161 | // 1110 1001 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1162 | emit(0xE9); |
| 1163 | emitl(L->pos()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1164 | L->link_to(pc_offset() - long_size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1165 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1166 | // 1110 1001 #32-bit disp. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1167 | DCHECK(L->is_unused()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1168 | emit(0xE9); |
| 1169 | int32_t current = pc_offset(); |
| 1170 | emitl(current); |
| 1171 | L->link_to(current); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1176 | void Assembler::jmp(Handle<Code> target, RelocInfo::Mode rmode) { |
| 1177 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1178 | // 1110 1001 #32-bit disp. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1179 | emit(0xE9); |
| 1180 | emit_code_target(target, rmode); |
| 1181 | } |
| 1182 | |
| 1183 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1184 | void Assembler::jmp(Address entry, RelocInfo::Mode rmode) { |
| 1185 | DCHECK(RelocInfo::IsRuntimeEntry(rmode)); |
| 1186 | EnsureSpace ensure_space(this); |
| 1187 | DCHECK(RelocInfo::IsRuntimeEntry(rmode)); |
| 1188 | emit(0xE9); |
| 1189 | emit_runtime_entry(entry, rmode); |
| 1190 | } |
| 1191 | |
| 1192 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1193 | void Assembler::jmp(Register target) { |
| 1194 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1195 | // Opcode FF/4 r64. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1196 | emit_optional_rex_32(target); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1197 | emit(0xFF); |
| 1198 | emit_modrm(0x4, target); |
| 1199 | } |
| 1200 | |
| 1201 | |
| 1202 | void Assembler::jmp(const Operand& src) { |
| 1203 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1204 | // Opcode FF/4 m64. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1205 | emit_optional_rex_32(src); |
| 1206 | emit(0xFF); |
| 1207 | emit_operand(0x4, src); |
| 1208 | } |
| 1209 | |
| 1210 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1211 | void Assembler::emit_lea(Register dst, const Operand& src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1212 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1213 | emit_rex(dst, src, size); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1214 | emit(0x8D); |
| 1215 | emit_operand(dst, src); |
| 1216 | } |
| 1217 | |
| 1218 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1219 | void Assembler::load_rax(void* value, RelocInfo::Mode mode) { |
| 1220 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1221 | if (kPointerSize == kInt64Size) { |
| 1222 | emit(0x48); // REX.W |
| 1223 | emit(0xA1); |
| 1224 | emitp(value, mode); |
| 1225 | } else { |
| 1226 | DCHECK(kPointerSize == kInt32Size); |
| 1227 | emit(0xA1); |
| 1228 | emitp(value, mode); |
| 1229 | // In 64-bit mode, need to zero extend the operand to 8 bytes. |
| 1230 | // See 2.2.1.4 in Intel64 and IA32 Architectures Software |
| 1231 | // Developer's Manual Volume 2. |
| 1232 | emitl(0); |
| 1233 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | |
| 1237 | void Assembler::load_rax(ExternalReference ref) { |
| 1238 | load_rax(ref.address(), RelocInfo::EXTERNAL_REFERENCE); |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | void Assembler::leave() { |
| 1243 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1244 | emit(0xC9); |
| 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | void Assembler::movb(Register dst, const Operand& src) { |
| 1249 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1250 | if (!dst.is_byte_register()) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1251 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1252 | emit_rex_32(dst, src); |
| 1253 | } else { |
| 1254 | emit_optional_rex_32(dst, src); |
| 1255 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1256 | emit(0x8A); |
| 1257 | emit_operand(dst, src); |
| 1258 | } |
| 1259 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1260 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1261 | void Assembler::movb(Register dst, Immediate imm) { |
| 1262 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1263 | if (!dst.is_byte_register()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1264 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1265 | emit_rex_32(dst); |
| 1266 | } |
| 1267 | emit(0xB0 + dst.low_bits()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1268 | emit(imm.value_); |
| 1269 | } |
| 1270 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1271 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1272 | void Assembler::movb(const Operand& dst, Register src) { |
| 1273 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1274 | if (!src.is_byte_register()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1275 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1276 | emit_rex_32(src, dst); |
| 1277 | } else { |
| 1278 | emit_optional_rex_32(src, dst); |
| 1279 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1280 | emit(0x88); |
| 1281 | emit_operand(src, dst); |
| 1282 | } |
| 1283 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1284 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1285 | void Assembler::movb(const Operand& dst, Immediate imm) { |
| 1286 | EnsureSpace ensure_space(this); |
| 1287 | emit_optional_rex_32(dst); |
| 1288 | emit(0xC6); |
| 1289 | emit_operand(0x0, dst); |
| 1290 | emit(static_cast<byte>(imm.value_)); |
| 1291 | } |
| 1292 | |
| 1293 | |
| 1294 | void Assembler::movw(Register dst, const Operand& src) { |
| 1295 | EnsureSpace ensure_space(this); |
| 1296 | emit(0x66); |
| 1297 | emit_optional_rex_32(dst, src); |
| 1298 | emit(0x8B); |
| 1299 | emit_operand(dst, src); |
| 1300 | } |
| 1301 | |
| 1302 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1303 | void Assembler::movw(const Operand& dst, Register src) { |
| 1304 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1305 | emit(0x66); |
| 1306 | emit_optional_rex_32(src, dst); |
| 1307 | emit(0x89); |
| 1308 | emit_operand(src, dst); |
| 1309 | } |
| 1310 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1311 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1312 | void Assembler::movw(const Operand& dst, Immediate imm) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1313 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1314 | emit(0x66); |
| 1315 | emit_optional_rex_32(dst); |
| 1316 | emit(0xC7); |
| 1317 | emit_operand(0x0, dst); |
| 1318 | emit(static_cast<byte>(imm.value_ & 0xff)); |
| 1319 | emit(static_cast<byte>(imm.value_ >> 8)); |
| 1320 | } |
| 1321 | |
| 1322 | |
| 1323 | void Assembler::emit_mov(Register dst, const Operand& src, int size) { |
| 1324 | EnsureSpace ensure_space(this); |
| 1325 | emit_rex(dst, src, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1326 | emit(0x8B); |
| 1327 | emit_operand(dst, src); |
| 1328 | } |
| 1329 | |
| 1330 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1331 | void Assembler::emit_mov(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1332 | EnsureSpace ensure_space(this); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1333 | if (src.low_bits() == 4) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1334 | emit_rex(src, dst, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1335 | emit(0x89); |
| 1336 | emit_modrm(src, dst); |
| 1337 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1338 | emit_rex(dst, src, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1339 | emit(0x8B); |
| 1340 | emit_modrm(dst, src); |
| 1341 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1345 | void Assembler::emit_mov(const Operand& dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1346 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1347 | emit_rex(src, dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1348 | emit(0x89); |
| 1349 | emit_operand(src, dst); |
| 1350 | } |
| 1351 | |
| 1352 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1353 | void Assembler::emit_mov(Register dst, Immediate value, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1354 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1355 | emit_rex(dst, size); |
| 1356 | if (size == kInt64Size) { |
| 1357 | emit(0xC7); |
| 1358 | emit_modrm(0x0, dst); |
| 1359 | } else { |
| 1360 | DCHECK(size == kInt32Size); |
| 1361 | emit(0xB8 + dst.low_bits()); |
| 1362 | } |
| 1363 | emit(value); |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | void Assembler::emit_mov(const Operand& dst, Immediate value, int size) { |
| 1368 | EnsureSpace ensure_space(this); |
| 1369 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1370 | emit(0xC7); |
| 1371 | emit_operand(0x0, dst); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1372 | emit(value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1376 | void Assembler::movp(Register dst, void* value, RelocInfo::Mode rmode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1377 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1378 | emit_rex(dst, kPointerSize); |
| 1379 | emit(0xB8 | dst.low_bits()); |
| 1380 | emitp(value, rmode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1384 | void Assembler::movq(Register dst, int64_t value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1385 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1386 | emit_rex_64(dst); |
| 1387 | emit(0xB8 | dst.low_bits()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1388 | emitq(value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1392 | void Assembler::movq(Register dst, uint64_t value) { |
| 1393 | movq(dst, static_cast<int64_t>(value)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1397 | // Loads the ip-relative location of the src label into the target location |
| 1398 | // (as a 32-bit offset sign extended to 64-bit). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1399 | void Assembler::movl(const Operand& dst, Label* src) { |
| 1400 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1401 | emit_optional_rex_32(dst); |
| 1402 | emit(0xC7); |
| 1403 | emit_operand(0, dst); |
| 1404 | if (src->is_bound()) { |
| 1405 | int offset = src->pos() - pc_offset() - sizeof(int32_t); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1406 | DCHECK(offset <= 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1407 | emitl(offset); |
| 1408 | } else if (src->is_linked()) { |
| 1409 | emitl(src->pos()); |
| 1410 | src->link_to(pc_offset() - sizeof(int32_t)); |
| 1411 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1412 | DCHECK(src->is_unused()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1413 | int32_t current = pc_offset(); |
| 1414 | emitl(current); |
| 1415 | src->link_to(current); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1420 | void Assembler::movsxbl(Register dst, Register src) { |
| 1421 | EnsureSpace ensure_space(this); |
| 1422 | if (!src.is_byte_register()) { |
| 1423 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1424 | emit_rex_32(dst, src); |
| 1425 | } else { |
| 1426 | emit_optional_rex_32(dst, src); |
| 1427 | } |
| 1428 | emit(0x0F); |
| 1429 | emit(0xBE); |
| 1430 | emit_modrm(dst, src); |
| 1431 | } |
| 1432 | |
| 1433 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1434 | void Assembler::movsxbl(Register dst, const Operand& src) { |
| 1435 | EnsureSpace ensure_space(this); |
| 1436 | emit_optional_rex_32(dst, src); |
| 1437 | emit(0x0F); |
| 1438 | emit(0xBE); |
| 1439 | emit_operand(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1443 | void Assembler::movsxbq(Register dst, const Operand& src) { |
| 1444 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1445 | emit_rex_64(dst, src); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1446 | emit(0x0F); |
| 1447 | emit(0xBE); |
| 1448 | emit_operand(dst, src); |
| 1449 | } |
| 1450 | |
| 1451 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1452 | void Assembler::movsxwl(Register dst, Register src) { |
| 1453 | EnsureSpace ensure_space(this); |
| 1454 | emit_optional_rex_32(dst, src); |
| 1455 | emit(0x0F); |
| 1456 | emit(0xBF); |
| 1457 | emit_modrm(dst, src); |
| 1458 | } |
| 1459 | |
| 1460 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1461 | void Assembler::movsxwl(Register dst, const Operand& src) { |
| 1462 | EnsureSpace ensure_space(this); |
| 1463 | emit_optional_rex_32(dst, src); |
| 1464 | emit(0x0F); |
| 1465 | emit(0xBF); |
| 1466 | emit_operand(dst, src); |
| 1467 | } |
| 1468 | |
| 1469 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1470 | void Assembler::movsxwq(Register dst, const Operand& src) { |
| 1471 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1472 | emit_rex_64(dst, src); |
| 1473 | emit(0x0F); |
| 1474 | emit(0xBF); |
| 1475 | emit_operand(dst, src); |
| 1476 | } |
| 1477 | |
| 1478 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1479 | void Assembler::movsxlq(Register dst, Register src) { |
| 1480 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1481 | emit_rex_64(dst, src); |
| 1482 | emit(0x63); |
| 1483 | emit_modrm(dst, src); |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | void Assembler::movsxlq(Register dst, const Operand& src) { |
| 1488 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1489 | emit_rex_64(dst, src); |
| 1490 | emit(0x63); |
| 1491 | emit_operand(dst, src); |
| 1492 | } |
| 1493 | |
| 1494 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1495 | void Assembler::emit_movzxb(Register dst, const Operand& src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1496 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1497 | // 32 bit operations zero the top 32 bits of 64 bit registers. Therefore |
| 1498 | // there is no need to make this a 64 bit operation. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1499 | emit_optional_rex_32(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1500 | emit(0x0F); |
| 1501 | emit(0xB6); |
| 1502 | emit_operand(dst, src); |
| 1503 | } |
| 1504 | |
| 1505 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1506 | void Assembler::emit_movzxb(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1507 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1508 | // 32 bit operations zero the top 32 bits of 64 bit registers. Therefore |
| 1509 | // there is no need to make this a 64 bit operation. |
| 1510 | if (!src.is_byte_register()) { |
| 1511 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1512 | emit_rex_32(dst, src); |
| 1513 | } else { |
| 1514 | emit_optional_rex_32(dst, src); |
| 1515 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1516 | emit(0x0F); |
| 1517 | emit(0xB6); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1518 | emit_modrm(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1522 | void Assembler::emit_movzxw(Register dst, const Operand& src, int size) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1523 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1524 | // 32 bit operations zero the top 32 bits of 64 bit registers. Therefore |
| 1525 | // there is no need to make this a 64 bit operation. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1526 | emit_optional_rex_32(dst, src); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1527 | emit(0x0F); |
| 1528 | emit(0xB7); |
| 1529 | emit_operand(dst, src); |
| 1530 | } |
| 1531 | |
| 1532 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1533 | void Assembler::emit_movzxw(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1534 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1535 | // 32 bit operations zero the top 32 bits of 64 bit registers. Therefore |
| 1536 | // there is no need to make this a 64 bit operation. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1537 | emit_optional_rex_32(dst, src); |
| 1538 | emit(0x0F); |
| 1539 | emit(0xB7); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1540 | emit_modrm(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1544 | void Assembler::repmovsb() { |
| 1545 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1546 | emit(0xF3); |
| 1547 | emit(0xA4); |
| 1548 | } |
| 1549 | |
| 1550 | |
| 1551 | void Assembler::repmovsw() { |
| 1552 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1553 | emit(0x66); // Operand size override. |
| 1554 | emit(0xF3); |
| 1555 | emit(0xA4); |
| 1556 | } |
| 1557 | |
| 1558 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1559 | void Assembler::emit_repmovs(int size) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1560 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1561 | emit(0xF3); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1562 | emit_rex(size); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1563 | emit(0xA5); |
| 1564 | } |
| 1565 | |
| 1566 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1567 | void Assembler::mull(Register src) { |
| 1568 | EnsureSpace ensure_space(this); |
| 1569 | emit_optional_rex_32(src); |
| 1570 | emit(0xF7); |
| 1571 | emit_modrm(0x4, src); |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | void Assembler::mull(const Operand& src) { |
| 1576 | EnsureSpace ensure_space(this); |
| 1577 | emit_optional_rex_32(src); |
| 1578 | emit(0xF7); |
| 1579 | emit_operand(0x4, src); |
| 1580 | } |
| 1581 | |
| 1582 | |
| 1583 | void Assembler::mulq(Register src) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1584 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1585 | emit_rex_64(src); |
| 1586 | emit(0xF7); |
| 1587 | emit_modrm(0x4, src); |
| 1588 | } |
| 1589 | |
| 1590 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1591 | void Assembler::emit_neg(Register dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1592 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1593 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1594 | emit(0xF7); |
| 1595 | emit_modrm(0x3, dst); |
| 1596 | } |
| 1597 | |
| 1598 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1599 | void Assembler::emit_neg(const Operand& dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1600 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1601 | emit_rex_64(dst); |
| 1602 | emit(0xF7); |
| 1603 | emit_operand(3, dst); |
| 1604 | } |
| 1605 | |
| 1606 | |
| 1607 | void Assembler::nop() { |
| 1608 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1609 | emit(0x90); |
| 1610 | } |
| 1611 | |
| 1612 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1613 | void Assembler::emit_not(Register dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1614 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1615 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1616 | emit(0xF7); |
| 1617 | emit_modrm(0x2, dst); |
| 1618 | } |
| 1619 | |
| 1620 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1621 | void Assembler::emit_not(const Operand& dst, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1622 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1623 | emit_rex(dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1624 | emit(0xF7); |
| 1625 | emit_operand(2, dst); |
| 1626 | } |
| 1627 | |
| 1628 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1629 | void Assembler::Nop(int n) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1630 | // The recommended muti-byte sequences of NOP instructions from the Intel 64 |
| 1631 | // and IA-32 Architectures Software Developer's Manual. |
| 1632 | // |
| 1633 | // Length Assembly Byte Sequence |
| 1634 | // 2 bytes 66 NOP 66 90H |
| 1635 | // 3 bytes NOP DWORD ptr [EAX] 0F 1F 00H |
| 1636 | // 4 bytes NOP DWORD ptr [EAX + 00H] 0F 1F 40 00H |
| 1637 | // 5 bytes NOP DWORD ptr [EAX + EAX*1 + 00H] 0F 1F 44 00 00H |
| 1638 | // 6 bytes 66 NOP DWORD ptr [EAX + EAX*1 + 00H] 66 0F 1F 44 00 00H |
| 1639 | // 7 bytes NOP DWORD ptr [EAX + 00000000H] 0F 1F 80 00 00 00 00H |
| 1640 | // 8 bytes NOP DWORD ptr [EAX + EAX*1 + 00000000H] 0F 1F 84 00 00 00 00 00H |
| 1641 | // 9 bytes 66 NOP DWORD ptr [EAX + EAX*1 + 66 0F 1F 84 00 00 00 00 |
| 1642 | // 00000000H] 00H |
| 1643 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1644 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1645 | while (n > 0) { |
| 1646 | switch (n) { |
| 1647 | case 2: |
| 1648 | emit(0x66); |
| 1649 | case 1: |
| 1650 | emit(0x90); |
| 1651 | return; |
| 1652 | case 3: |
| 1653 | emit(0x0f); |
| 1654 | emit(0x1f); |
| 1655 | emit(0x00); |
| 1656 | return; |
| 1657 | case 4: |
| 1658 | emit(0x0f); |
| 1659 | emit(0x1f); |
| 1660 | emit(0x40); |
| 1661 | emit(0x00); |
| 1662 | return; |
| 1663 | case 6: |
| 1664 | emit(0x66); |
| 1665 | case 5: |
| 1666 | emit(0x0f); |
| 1667 | emit(0x1f); |
| 1668 | emit(0x44); |
| 1669 | emit(0x00); |
| 1670 | emit(0x00); |
| 1671 | return; |
| 1672 | case 7: |
| 1673 | emit(0x0f); |
| 1674 | emit(0x1f); |
| 1675 | emit(0x80); |
| 1676 | emit(0x00); |
| 1677 | emit(0x00); |
| 1678 | emit(0x00); |
| 1679 | emit(0x00); |
| 1680 | return; |
| 1681 | default: |
| 1682 | case 11: |
| 1683 | emit(0x66); |
| 1684 | n--; |
| 1685 | case 10: |
| 1686 | emit(0x66); |
| 1687 | n--; |
| 1688 | case 9: |
| 1689 | emit(0x66); |
| 1690 | n--; |
| 1691 | case 8: |
| 1692 | emit(0x0f); |
| 1693 | emit(0x1f); |
| 1694 | emit(0x84); |
| 1695 | emit(0x00); |
| 1696 | emit(0x00); |
| 1697 | emit(0x00); |
| 1698 | emit(0x00); |
| 1699 | emit(0x00); |
| 1700 | n -= 8; |
| 1701 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1706 | void Assembler::popq(Register dst) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1707 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1708 | emit_optional_rex_32(dst); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1709 | emit(0x58 | dst.low_bits()); |
| 1710 | } |
| 1711 | |
| 1712 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1713 | void Assembler::popq(const Operand& dst) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1714 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1715 | emit_optional_rex_32(dst); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1716 | emit(0x8F); |
| 1717 | emit_operand(0, dst); |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | void Assembler::popfq() { |
| 1722 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1723 | emit(0x9D); |
| 1724 | } |
| 1725 | |
| 1726 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1727 | void Assembler::pushq(Register src) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1728 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1729 | emit_optional_rex_32(src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1730 | emit(0x50 | src.low_bits()); |
| 1731 | } |
| 1732 | |
| 1733 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1734 | void Assembler::pushq(const Operand& src) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1735 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 1736 | emit_optional_rex_32(src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1737 | emit(0xFF); |
| 1738 | emit_operand(6, src); |
| 1739 | } |
| 1740 | |
| 1741 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1742 | void Assembler::pushq(Immediate value) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1743 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1744 | if (is_int8(value.value_)) { |
| 1745 | emit(0x6A); |
| 1746 | emit(value.value_); // Emit low byte of value. |
| 1747 | } else { |
| 1748 | emit(0x68); |
| 1749 | emitl(value.value_); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1754 | void Assembler::pushq_imm32(int32_t imm32) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1755 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1756 | emit(0x68); |
| 1757 | emitl(imm32); |
| 1758 | } |
| 1759 | |
| 1760 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1761 | void Assembler::pushfq() { |
| 1762 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1763 | emit(0x9C); |
| 1764 | } |
| 1765 | |
| 1766 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1767 | void Assembler::ret(int imm16) { |
| 1768 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1769 | DCHECK(is_uint16(imm16)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1770 | if (imm16 == 0) { |
| 1771 | emit(0xC3); |
| 1772 | } else { |
| 1773 | emit(0xC2); |
| 1774 | emit(imm16 & 0xFF); |
| 1775 | emit((imm16 >> 8) & 0xFF); |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | |
| 1780 | void Assembler::setcc(Condition cc, Register reg) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1781 | if (cc > last_condition) { |
| 1782 | movb(reg, Immediate(cc == always ? 1 : 0)); |
| 1783 | return; |
| 1784 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1785 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1786 | DCHECK(is_uint4(cc)); |
| 1787 | if (!reg.is_byte_register()) { |
| 1788 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1789 | emit_rex_32(reg); |
| 1790 | } |
| 1791 | emit(0x0F); |
| 1792 | emit(0x90 | cc); |
| 1793 | emit_modrm(0x0, reg); |
| 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | void Assembler::shld(Register dst, Register src) { |
| 1798 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1799 | emit_rex_64(src, dst); |
| 1800 | emit(0x0F); |
| 1801 | emit(0xA5); |
| 1802 | emit_modrm(src, dst); |
| 1803 | } |
| 1804 | |
| 1805 | |
| 1806 | void Assembler::shrd(Register dst, Register src) { |
| 1807 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1808 | emit_rex_64(src, dst); |
| 1809 | emit(0x0F); |
| 1810 | emit(0xAD); |
| 1811 | emit_modrm(src, dst); |
| 1812 | } |
| 1813 | |
| 1814 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1815 | void Assembler::emit_xchg(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1816 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1817 | if (src.is(rax) || dst.is(rax)) { // Single-byte encoding |
| 1818 | Register other = src.is(rax) ? dst : src; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1819 | emit_rex(other, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1820 | emit(0x90 | other.low_bits()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1821 | } else if (dst.low_bits() == 4) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1822 | emit_rex(dst, src, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1823 | emit(0x87); |
| 1824 | emit_modrm(dst, src); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1825 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1826 | emit_rex(src, dst, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1827 | emit(0x87); |
| 1828 | emit_modrm(src, dst); |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1833 | void Assembler::emit_xchg(Register dst, const Operand& src, int size) { |
| 1834 | EnsureSpace ensure_space(this); |
| 1835 | emit_rex(dst, src, size); |
| 1836 | emit(0x87); |
| 1837 | emit_operand(dst, src); |
| 1838 | } |
| 1839 | |
| 1840 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1841 | void Assembler::store_rax(void* dst, RelocInfo::Mode mode) { |
| 1842 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1843 | if (kPointerSize == kInt64Size) { |
| 1844 | emit(0x48); // REX.W |
| 1845 | emit(0xA3); |
| 1846 | emitp(dst, mode); |
| 1847 | } else { |
| 1848 | DCHECK(kPointerSize == kInt32Size); |
| 1849 | emit(0xA3); |
| 1850 | emitp(dst, mode); |
| 1851 | // In 64-bit mode, need to zero extend the operand to 8 bytes. |
| 1852 | // See 2.2.1.4 in Intel64 and IA32 Architectures Software |
| 1853 | // Developer's Manual Volume 2. |
| 1854 | emitl(0); |
| 1855 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | |
| 1859 | void Assembler::store_rax(ExternalReference ref) { |
| 1860 | store_rax(ref.address(), RelocInfo::EXTERNAL_REFERENCE); |
| 1861 | } |
| 1862 | |
| 1863 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1864 | void Assembler::testb(Register dst, Register src) { |
| 1865 | EnsureSpace ensure_space(this); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1866 | if (src.low_bits() == 4) { |
| 1867 | emit_rex_32(src, dst); |
| 1868 | emit(0x84); |
| 1869 | emit_modrm(src, dst); |
| 1870 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1871 | if (!dst.is_byte_register() || !src.is_byte_register()) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1872 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1873 | emit_rex_32(dst, src); |
| 1874 | } |
| 1875 | emit(0x84); |
| 1876 | emit_modrm(dst, src); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1877 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1881 | void Assembler::testb(Register reg, Immediate mask) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1882 | DCHECK(is_int8(mask.value_) || is_uint8(mask.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1883 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1884 | if (reg.is(rax)) { |
| 1885 | emit(0xA8); |
| 1886 | emit(mask.value_); // Low byte emitted. |
| 1887 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1888 | if (!reg.is_byte_register()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1889 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1890 | emit_rex_32(reg); |
| 1891 | } |
| 1892 | emit(0xF6); |
| 1893 | emit_modrm(0x0, reg); |
| 1894 | emit(mask.value_); // Low byte emitted. |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | |
| 1899 | void Assembler::testb(const Operand& op, Immediate mask) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1900 | DCHECK(is_int8(mask.value_) || is_uint8(mask.value_)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1901 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1902 | emit_optional_rex_32(rax, op); |
| 1903 | emit(0xF6); |
| 1904 | emit_operand(rax, op); // Operation code 0 |
| 1905 | emit(mask.value_); // Low byte emitted. |
| 1906 | } |
| 1907 | |
| 1908 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1909 | void Assembler::testb(const Operand& op, Register reg) { |
| 1910 | EnsureSpace ensure_space(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1911 | if (!reg.is_byte_register()) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1912 | // Register is not one of al, bl, cl, dl. Its encoding needs REX. |
| 1913 | emit_rex_32(reg, op); |
| 1914 | } else { |
| 1915 | emit_optional_rex_32(reg, op); |
| 1916 | } |
| 1917 | emit(0x84); |
| 1918 | emit_operand(reg, op); |
| 1919 | } |
| 1920 | |
| 1921 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1922 | void Assembler::emit_test(Register dst, Register src, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1923 | EnsureSpace ensure_space(this); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1924 | if (src.low_bits() == 4) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1925 | emit_rex(src, dst, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1926 | emit(0x85); |
| 1927 | emit_modrm(src, dst); |
| 1928 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1929 | emit_rex(dst, src, size); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1930 | emit(0x85); |
| 1931 | emit_modrm(dst, src); |
| 1932 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1936 | void Assembler::emit_test(Register reg, Immediate mask, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1937 | // testl with a mask that fits in the low byte is exactly testb. |
| 1938 | if (is_uint8(mask.value_)) { |
| 1939 | testb(reg, mask); |
| 1940 | return; |
| 1941 | } |
| 1942 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1943 | if (reg.is(rax)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1944 | emit_rex(rax, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1945 | emit(0xA9); |
| 1946 | emit(mask); |
| 1947 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1948 | emit_rex(reg, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1949 | emit(0xF7); |
| 1950 | emit_modrm(0x0, reg); |
| 1951 | emit(mask); |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1956 | void Assembler::emit_test(const Operand& op, Immediate mask, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1957 | // testl with a mask that fits in the low byte is exactly testb. |
| 1958 | if (is_uint8(mask.value_)) { |
| 1959 | testb(op, mask); |
| 1960 | return; |
| 1961 | } |
| 1962 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1963 | emit_rex(rax, op, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1964 | emit(0xF7); |
| 1965 | emit_operand(rax, op); // Operation code 0 |
| 1966 | emit(mask); |
| 1967 | } |
| 1968 | |
| 1969 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1970 | void Assembler::emit_test(const Operand& op, Register reg, int size) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1971 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1972 | emit_rex(reg, op, size); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1973 | emit(0x85); |
| 1974 | emit_operand(reg, op); |
| 1975 | } |
| 1976 | |
| 1977 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1978 | // FPU instructions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1979 | |
| 1980 | |
| 1981 | void Assembler::fld(int i) { |
| 1982 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1983 | emit_farith(0xD9, 0xC0, i); |
| 1984 | } |
| 1985 | |
| 1986 | |
| 1987 | void Assembler::fld1() { |
| 1988 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1989 | emit(0xD9); |
| 1990 | emit(0xE8); |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | void Assembler::fldz() { |
| 1995 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1996 | emit(0xD9); |
| 1997 | emit(0xEE); |
| 1998 | } |
| 1999 | |
| 2000 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2001 | void Assembler::fldpi() { |
| 2002 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2003 | emit(0xD9); |
| 2004 | emit(0xEB); |
| 2005 | } |
| 2006 | |
| 2007 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2008 | void Assembler::fldln2() { |
| 2009 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2010 | emit(0xD9); |
| 2011 | emit(0xED); |
| 2012 | } |
| 2013 | |
| 2014 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2015 | void Assembler::fld_s(const Operand& adr) { |
| 2016 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2017 | emit_optional_rex_32(adr); |
| 2018 | emit(0xD9); |
| 2019 | emit_operand(0, adr); |
| 2020 | } |
| 2021 | |
| 2022 | |
| 2023 | void Assembler::fld_d(const Operand& adr) { |
| 2024 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2025 | emit_optional_rex_32(adr); |
| 2026 | emit(0xDD); |
| 2027 | emit_operand(0, adr); |
| 2028 | } |
| 2029 | |
| 2030 | |
| 2031 | void Assembler::fstp_s(const Operand& adr) { |
| 2032 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2033 | emit_optional_rex_32(adr); |
| 2034 | emit(0xD9); |
| 2035 | emit_operand(3, adr); |
| 2036 | } |
| 2037 | |
| 2038 | |
| 2039 | void Assembler::fstp_d(const Operand& adr) { |
| 2040 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2041 | emit_optional_rex_32(adr); |
| 2042 | emit(0xDD); |
| 2043 | emit_operand(3, adr); |
| 2044 | } |
| 2045 | |
| 2046 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2047 | void Assembler::fstp(int index) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2048 | DCHECK(is_uint3(index)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2049 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2050 | emit_farith(0xDD, 0xD8, index); |
| 2051 | } |
| 2052 | |
| 2053 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2054 | void Assembler::fild_s(const Operand& adr) { |
| 2055 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2056 | emit_optional_rex_32(adr); |
| 2057 | emit(0xDB); |
| 2058 | emit_operand(0, adr); |
| 2059 | } |
| 2060 | |
| 2061 | |
| 2062 | void Assembler::fild_d(const Operand& adr) { |
| 2063 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2064 | emit_optional_rex_32(adr); |
| 2065 | emit(0xDF); |
| 2066 | emit_operand(5, adr); |
| 2067 | } |
| 2068 | |
| 2069 | |
| 2070 | void Assembler::fistp_s(const Operand& adr) { |
| 2071 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2072 | emit_optional_rex_32(adr); |
| 2073 | emit(0xDB); |
| 2074 | emit_operand(3, adr); |
| 2075 | } |
| 2076 | |
| 2077 | |
| 2078 | void Assembler::fisttp_s(const Operand& adr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2079 | DCHECK(IsEnabled(SSE3)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2080 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2081 | emit_optional_rex_32(adr); |
| 2082 | emit(0xDB); |
| 2083 | emit_operand(1, adr); |
| 2084 | } |
| 2085 | |
| 2086 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2087 | void Assembler::fisttp_d(const Operand& adr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2088 | DCHECK(IsEnabled(SSE3)); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2089 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2090 | emit_optional_rex_32(adr); |
| 2091 | emit(0xDD); |
| 2092 | emit_operand(1, adr); |
| 2093 | } |
| 2094 | |
| 2095 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2096 | void Assembler::fist_s(const Operand& adr) { |
| 2097 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2098 | emit_optional_rex_32(adr); |
| 2099 | emit(0xDB); |
| 2100 | emit_operand(2, adr); |
| 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | void Assembler::fistp_d(const Operand& adr) { |
| 2105 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2106 | emit_optional_rex_32(adr); |
| 2107 | emit(0xDF); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2108 | emit_operand(7, adr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | void Assembler::fabs() { |
| 2113 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2114 | emit(0xD9); |
| 2115 | emit(0xE1); |
| 2116 | } |
| 2117 | |
| 2118 | |
| 2119 | void Assembler::fchs() { |
| 2120 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2121 | emit(0xD9); |
| 2122 | emit(0xE0); |
| 2123 | } |
| 2124 | |
| 2125 | |
| 2126 | void Assembler::fcos() { |
| 2127 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2128 | emit(0xD9); |
| 2129 | emit(0xFF); |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | void Assembler::fsin() { |
| 2134 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2135 | emit(0xD9); |
| 2136 | emit(0xFE); |
| 2137 | } |
| 2138 | |
| 2139 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2140 | void Assembler::fptan() { |
| 2141 | EnsureSpace ensure_space(this); |
| 2142 | emit(0xD9); |
| 2143 | emit(0xF2); |
| 2144 | } |
| 2145 | |
| 2146 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2147 | void Assembler::fyl2x() { |
| 2148 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2149 | emit(0xD9); |
| 2150 | emit(0xF1); |
| 2151 | } |
| 2152 | |
| 2153 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2154 | void Assembler::f2xm1() { |
| 2155 | EnsureSpace ensure_space(this); |
| 2156 | emit(0xD9); |
| 2157 | emit(0xF0); |
| 2158 | } |
| 2159 | |
| 2160 | |
| 2161 | void Assembler::fscale() { |
| 2162 | EnsureSpace ensure_space(this); |
| 2163 | emit(0xD9); |
| 2164 | emit(0xFD); |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | void Assembler::fninit() { |
| 2169 | EnsureSpace ensure_space(this); |
| 2170 | emit(0xDB); |
| 2171 | emit(0xE3); |
| 2172 | } |
| 2173 | |
| 2174 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2175 | void Assembler::fadd(int i) { |
| 2176 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2177 | emit_farith(0xDC, 0xC0, i); |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | void Assembler::fsub(int i) { |
| 2182 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2183 | emit_farith(0xDC, 0xE8, i); |
| 2184 | } |
| 2185 | |
| 2186 | |
| 2187 | void Assembler::fisub_s(const Operand& adr) { |
| 2188 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2189 | emit_optional_rex_32(adr); |
| 2190 | emit(0xDA); |
| 2191 | emit_operand(4, adr); |
| 2192 | } |
| 2193 | |
| 2194 | |
| 2195 | void Assembler::fmul(int i) { |
| 2196 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2197 | emit_farith(0xDC, 0xC8, i); |
| 2198 | } |
| 2199 | |
| 2200 | |
| 2201 | void Assembler::fdiv(int i) { |
| 2202 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2203 | emit_farith(0xDC, 0xF8, i); |
| 2204 | } |
| 2205 | |
| 2206 | |
| 2207 | void Assembler::faddp(int i) { |
| 2208 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2209 | emit_farith(0xDE, 0xC0, i); |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | void Assembler::fsubp(int i) { |
| 2214 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2215 | emit_farith(0xDE, 0xE8, i); |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | void Assembler::fsubrp(int i) { |
| 2220 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2221 | emit_farith(0xDE, 0xE0, i); |
| 2222 | } |
| 2223 | |
| 2224 | |
| 2225 | void Assembler::fmulp(int i) { |
| 2226 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2227 | emit_farith(0xDE, 0xC8, i); |
| 2228 | } |
| 2229 | |
| 2230 | |
| 2231 | void Assembler::fdivp(int i) { |
| 2232 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2233 | emit_farith(0xDE, 0xF8, i); |
| 2234 | } |
| 2235 | |
| 2236 | |
| 2237 | void Assembler::fprem() { |
| 2238 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2239 | emit(0xD9); |
| 2240 | emit(0xF8); |
| 2241 | } |
| 2242 | |
| 2243 | |
| 2244 | void Assembler::fprem1() { |
| 2245 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2246 | emit(0xD9); |
| 2247 | emit(0xF5); |
| 2248 | } |
| 2249 | |
| 2250 | |
| 2251 | void Assembler::fxch(int i) { |
| 2252 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2253 | emit_farith(0xD9, 0xC8, i); |
| 2254 | } |
| 2255 | |
| 2256 | |
| 2257 | void Assembler::fincstp() { |
| 2258 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2259 | emit(0xD9); |
| 2260 | emit(0xF7); |
| 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | void Assembler::ffree(int i) { |
| 2265 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2266 | emit_farith(0xDD, 0xC0, i); |
| 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | void Assembler::ftst() { |
| 2271 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2272 | emit(0xD9); |
| 2273 | emit(0xE4); |
| 2274 | } |
| 2275 | |
| 2276 | |
| 2277 | void Assembler::fucomp(int i) { |
| 2278 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2279 | emit_farith(0xDD, 0xE8, i); |
| 2280 | } |
| 2281 | |
| 2282 | |
| 2283 | void Assembler::fucompp() { |
| 2284 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2285 | emit(0xDA); |
| 2286 | emit(0xE9); |
| 2287 | } |
| 2288 | |
| 2289 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2290 | void Assembler::fucomi(int i) { |
| 2291 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2292 | emit(0xDB); |
| 2293 | emit(0xE8 + i); |
| 2294 | } |
| 2295 | |
| 2296 | |
| 2297 | void Assembler::fucomip() { |
| 2298 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2299 | emit(0xDF); |
| 2300 | emit(0xE9); |
| 2301 | } |
| 2302 | |
| 2303 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2304 | void Assembler::fcompp() { |
| 2305 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2306 | emit(0xDE); |
| 2307 | emit(0xD9); |
| 2308 | } |
| 2309 | |
| 2310 | |
| 2311 | void Assembler::fnstsw_ax() { |
| 2312 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2313 | emit(0xDF); |
| 2314 | emit(0xE0); |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | void Assembler::fwait() { |
| 2319 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2320 | emit(0x9B); |
| 2321 | } |
| 2322 | |
| 2323 | |
| 2324 | void Assembler::frndint() { |
| 2325 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2326 | emit(0xD9); |
| 2327 | emit(0xFC); |
| 2328 | } |
| 2329 | |
| 2330 | |
| 2331 | void Assembler::fnclex() { |
| 2332 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2333 | emit(0xDB); |
| 2334 | emit(0xE2); |
| 2335 | } |
| 2336 | |
| 2337 | |
| 2338 | void Assembler::sahf() { |
| 2339 | // TODO(X64): Test for presence. Not all 64-bit intel CPU's have sahf |
| 2340 | // in 64-bit mode. Test CpuID. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2341 | DCHECK(IsEnabled(SAHF)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2342 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2343 | emit(0x9E); |
| 2344 | } |
| 2345 | |
| 2346 | |
| 2347 | void Assembler::emit_farith(int b1, int b2, int i) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2348 | DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
| 2349 | DCHECK(is_uint3(i)); // illegal stack offset |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2350 | emit(b1); |
| 2351 | emit(b2 + i); |
| 2352 | } |
| 2353 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2354 | |
| 2355 | // SSE operations. |
| 2356 | |
| 2357 | void Assembler::andps(XMMRegister dst, XMMRegister src) { |
| 2358 | EnsureSpace ensure_space(this); |
| 2359 | emit_optional_rex_32(dst, src); |
| 2360 | emit(0x0F); |
| 2361 | emit(0x54); |
| 2362 | emit_sse_operand(dst, src); |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | void Assembler::andps(XMMRegister dst, const Operand& src) { |
| 2367 | EnsureSpace ensure_space(this); |
| 2368 | emit_optional_rex_32(dst, src); |
| 2369 | emit(0x0F); |
| 2370 | emit(0x54); |
| 2371 | emit_sse_operand(dst, src); |
| 2372 | } |
| 2373 | |
| 2374 | |
| 2375 | void Assembler::orps(XMMRegister dst, XMMRegister src) { |
| 2376 | EnsureSpace ensure_space(this); |
| 2377 | emit_optional_rex_32(dst, src); |
| 2378 | emit(0x0F); |
| 2379 | emit(0x56); |
| 2380 | emit_sse_operand(dst, src); |
| 2381 | } |
| 2382 | |
| 2383 | |
| 2384 | void Assembler::orps(XMMRegister dst, const Operand& src) { |
| 2385 | EnsureSpace ensure_space(this); |
| 2386 | emit_optional_rex_32(dst, src); |
| 2387 | emit(0x0F); |
| 2388 | emit(0x56); |
| 2389 | emit_sse_operand(dst, src); |
| 2390 | } |
| 2391 | |
| 2392 | |
| 2393 | void Assembler::xorps(XMMRegister dst, XMMRegister src) { |
| 2394 | EnsureSpace ensure_space(this); |
| 2395 | emit_optional_rex_32(dst, src); |
| 2396 | emit(0x0F); |
| 2397 | emit(0x57); |
| 2398 | emit_sse_operand(dst, src); |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | void Assembler::xorps(XMMRegister dst, const Operand& src) { |
| 2403 | EnsureSpace ensure_space(this); |
| 2404 | emit_optional_rex_32(dst, src); |
| 2405 | emit(0x0F); |
| 2406 | emit(0x57); |
| 2407 | emit_sse_operand(dst, src); |
| 2408 | } |
| 2409 | |
| 2410 | |
| 2411 | void Assembler::addps(XMMRegister dst, XMMRegister src) { |
| 2412 | EnsureSpace ensure_space(this); |
| 2413 | emit_optional_rex_32(dst, src); |
| 2414 | emit(0x0F); |
| 2415 | emit(0x58); |
| 2416 | emit_sse_operand(dst, src); |
| 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | void Assembler::addps(XMMRegister dst, const Operand& src) { |
| 2421 | EnsureSpace ensure_space(this); |
| 2422 | emit_optional_rex_32(dst, src); |
| 2423 | emit(0x0F); |
| 2424 | emit(0x58); |
| 2425 | emit_sse_operand(dst, src); |
| 2426 | } |
| 2427 | |
| 2428 | |
| 2429 | void Assembler::subps(XMMRegister dst, XMMRegister src) { |
| 2430 | EnsureSpace ensure_space(this); |
| 2431 | emit_optional_rex_32(dst, src); |
| 2432 | emit(0x0F); |
| 2433 | emit(0x5C); |
| 2434 | emit_sse_operand(dst, src); |
| 2435 | } |
| 2436 | |
| 2437 | |
| 2438 | void Assembler::subps(XMMRegister dst, const Operand& src) { |
| 2439 | EnsureSpace ensure_space(this); |
| 2440 | emit_optional_rex_32(dst, src); |
| 2441 | emit(0x0F); |
| 2442 | emit(0x5C); |
| 2443 | emit_sse_operand(dst, src); |
| 2444 | } |
| 2445 | |
| 2446 | |
| 2447 | void Assembler::mulps(XMMRegister dst, XMMRegister src) { |
| 2448 | EnsureSpace ensure_space(this); |
| 2449 | emit_optional_rex_32(dst, src); |
| 2450 | emit(0x0F); |
| 2451 | emit(0x59); |
| 2452 | emit_sse_operand(dst, src); |
| 2453 | } |
| 2454 | |
| 2455 | |
| 2456 | void Assembler::mulps(XMMRegister dst, const Operand& src) { |
| 2457 | EnsureSpace ensure_space(this); |
| 2458 | emit_optional_rex_32(dst, src); |
| 2459 | emit(0x0F); |
| 2460 | emit(0x59); |
| 2461 | emit_sse_operand(dst, src); |
| 2462 | } |
| 2463 | |
| 2464 | |
| 2465 | void Assembler::divps(XMMRegister dst, XMMRegister src) { |
| 2466 | EnsureSpace ensure_space(this); |
| 2467 | emit_optional_rex_32(dst, src); |
| 2468 | emit(0x0F); |
| 2469 | emit(0x5E); |
| 2470 | emit_sse_operand(dst, src); |
| 2471 | } |
| 2472 | |
| 2473 | |
| 2474 | void Assembler::divps(XMMRegister dst, const Operand& src) { |
| 2475 | EnsureSpace ensure_space(this); |
| 2476 | emit_optional_rex_32(dst, src); |
| 2477 | emit(0x0F); |
| 2478 | emit(0x5E); |
| 2479 | emit_sse_operand(dst, src); |
| 2480 | } |
| 2481 | |
| 2482 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2483 | // SSE 2 operations. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2484 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2485 | void Assembler::movd(XMMRegister dst, Register src) { |
| 2486 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2487 | emit(0x66); |
| 2488 | emit_optional_rex_32(dst, src); |
| 2489 | emit(0x0F); |
| 2490 | emit(0x6E); |
| 2491 | emit_sse_operand(dst, src); |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | void Assembler::movd(Register dst, XMMRegister src) { |
| 2496 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2497 | emit(0x66); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2498 | emit_optional_rex_32(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2499 | emit(0x0F); |
| 2500 | emit(0x7E); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2501 | emit_sse_operand(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | |
| 2505 | void Assembler::movq(XMMRegister dst, Register src) { |
| 2506 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2507 | emit(0x66); |
| 2508 | emit_rex_64(dst, src); |
| 2509 | emit(0x0F); |
| 2510 | emit(0x6E); |
| 2511 | emit_sse_operand(dst, src); |
| 2512 | } |
| 2513 | |
| 2514 | |
| 2515 | void Assembler::movq(Register dst, XMMRegister src) { |
| 2516 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2517 | emit(0x66); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2518 | emit_rex_64(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2519 | emit(0x0F); |
| 2520 | emit(0x7E); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 2521 | emit_sse_operand(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2525 | void Assembler::movq(XMMRegister dst, XMMRegister src) { |
| 2526 | EnsureSpace ensure_space(this); |
| 2527 | if (dst.low_bits() == 4) { |
| 2528 | // Avoid unnecessary SIB byte. |
| 2529 | emit(0xf3); |
| 2530 | emit_optional_rex_32(dst, src); |
| 2531 | emit(0x0F); |
| 2532 | emit(0x7e); |
| 2533 | emit_sse_operand(dst, src); |
| 2534 | } else { |
| 2535 | emit(0x66); |
| 2536 | emit_optional_rex_32(src, dst); |
| 2537 | emit(0x0F); |
| 2538 | emit(0xD6); |
| 2539 | emit_sse_operand(src, dst); |
| 2540 | } |
| 2541 | } |
| 2542 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2543 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2544 | void Assembler::movdqa(const Operand& dst, XMMRegister src) { |
| 2545 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2546 | emit(0x66); |
| 2547 | emit_rex_64(src, dst); |
| 2548 | emit(0x0F); |
| 2549 | emit(0x7F); |
| 2550 | emit_sse_operand(src, dst); |
| 2551 | } |
| 2552 | |
| 2553 | |
| 2554 | void Assembler::movdqa(XMMRegister dst, const Operand& src) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2555 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2556 | emit(0x66); |
| 2557 | emit_rex_64(dst, src); |
| 2558 | emit(0x0F); |
| 2559 | emit(0x6F); |
| 2560 | emit_sse_operand(dst, src); |
| 2561 | } |
| 2562 | |
| 2563 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2564 | void Assembler::movdqu(const Operand& dst, XMMRegister src) { |
| 2565 | EnsureSpace ensure_space(this); |
| 2566 | emit(0xF3); |
| 2567 | emit_rex_64(src, dst); |
| 2568 | emit(0x0F); |
| 2569 | emit(0x7F); |
| 2570 | emit_sse_operand(src, dst); |
| 2571 | } |
| 2572 | |
| 2573 | |
| 2574 | void Assembler::movdqu(XMMRegister dst, const Operand& src) { |
| 2575 | EnsureSpace ensure_space(this); |
| 2576 | emit(0xF3); |
| 2577 | emit_rex_64(dst, src); |
| 2578 | emit(0x0F); |
| 2579 | emit(0x6F); |
| 2580 | emit_sse_operand(dst, src); |
| 2581 | } |
| 2582 | |
| 2583 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2584 | void Assembler::extractps(Register dst, XMMRegister src, byte imm8) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2585 | DCHECK(IsEnabled(SSE4_1)); |
| 2586 | DCHECK(is_uint8(imm8)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2587 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2588 | emit(0x66); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2589 | emit_optional_rex_32(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2590 | emit(0x0F); |
| 2591 | emit(0x3A); |
| 2592 | emit(0x17); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2593 | emit_sse_operand(src, dst); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2594 | emit(imm8); |
| 2595 | } |
| 2596 | |
| 2597 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2598 | void Assembler::movsd(const Operand& dst, XMMRegister src) { |
| 2599 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2600 | emit(0xF2); // double |
| 2601 | emit_optional_rex_32(src, dst); |
| 2602 | emit(0x0F); |
| 2603 | emit(0x11); // store |
| 2604 | emit_sse_operand(src, dst); |
| 2605 | } |
| 2606 | |
| 2607 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2608 | void Assembler::movsd(XMMRegister dst, XMMRegister src) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2609 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2610 | emit(0xF2); // double |
| 2611 | emit_optional_rex_32(dst, src); |
| 2612 | emit(0x0F); |
| 2613 | emit(0x10); // load |
| 2614 | emit_sse_operand(dst, src); |
| 2615 | } |
| 2616 | |
| 2617 | |
| 2618 | void Assembler::movsd(XMMRegister dst, const Operand& src) { |
| 2619 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2620 | emit(0xF2); // double |
| 2621 | emit_optional_rex_32(dst, src); |
| 2622 | emit(0x0F); |
| 2623 | emit(0x10); // load |
| 2624 | emit_sse_operand(dst, src); |
| 2625 | } |
| 2626 | |
| 2627 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2628 | void Assembler::movaps(XMMRegister dst, XMMRegister src) { |
| 2629 | EnsureSpace ensure_space(this); |
| 2630 | if (src.low_bits() == 4) { |
| 2631 | // Try to avoid an unnecessary SIB byte. |
| 2632 | emit_optional_rex_32(src, dst); |
| 2633 | emit(0x0F); |
| 2634 | emit(0x29); |
| 2635 | emit_sse_operand(src, dst); |
| 2636 | } else { |
| 2637 | emit_optional_rex_32(dst, src); |
| 2638 | emit(0x0F); |
| 2639 | emit(0x28); |
| 2640 | emit_sse_operand(dst, src); |
| 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2645 | void Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) { |
| 2646 | DCHECK(is_uint8(imm8)); |
| 2647 | EnsureSpace ensure_space(this); |
| 2648 | emit_optional_rex_32(src, dst); |
| 2649 | emit(0x0F); |
| 2650 | emit(0xC6); |
| 2651 | emit_sse_operand(dst, src); |
| 2652 | emit(imm8); |
| 2653 | } |
| 2654 | |
| 2655 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2656 | void Assembler::movapd(XMMRegister dst, XMMRegister src) { |
| 2657 | EnsureSpace ensure_space(this); |
| 2658 | if (src.low_bits() == 4) { |
| 2659 | // Try to avoid an unnecessary SIB byte. |
| 2660 | emit(0x66); |
| 2661 | emit_optional_rex_32(src, dst); |
| 2662 | emit(0x0F); |
| 2663 | emit(0x29); |
| 2664 | emit_sse_operand(src, dst); |
| 2665 | } else { |
| 2666 | emit(0x66); |
| 2667 | emit_optional_rex_32(dst, src); |
| 2668 | emit(0x0F); |
| 2669 | emit(0x28); |
| 2670 | emit_sse_operand(dst, src); |
| 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2675 | void Assembler::addss(XMMRegister dst, XMMRegister src) { |
| 2676 | EnsureSpace ensure_space(this); |
| 2677 | emit(0xF3); |
| 2678 | emit_optional_rex_32(dst, src); |
| 2679 | emit(0x0F); |
| 2680 | emit(0x58); |
| 2681 | emit_sse_operand(dst, src); |
| 2682 | } |
| 2683 | |
| 2684 | |
| 2685 | void Assembler::addss(XMMRegister dst, const Operand& src) { |
| 2686 | EnsureSpace ensure_space(this); |
| 2687 | emit(0xF3); |
| 2688 | emit_optional_rex_32(dst, src); |
| 2689 | emit(0x0F); |
| 2690 | emit(0x58); |
| 2691 | emit_sse_operand(dst, src); |
| 2692 | } |
| 2693 | |
| 2694 | |
| 2695 | void Assembler::subss(XMMRegister dst, XMMRegister src) { |
| 2696 | EnsureSpace ensure_space(this); |
| 2697 | emit(0xF3); |
| 2698 | emit_optional_rex_32(dst, src); |
| 2699 | emit(0x0F); |
| 2700 | emit(0x5C); |
| 2701 | emit_sse_operand(dst, src); |
| 2702 | } |
| 2703 | |
| 2704 | |
| 2705 | void Assembler::subss(XMMRegister dst, const Operand& src) { |
| 2706 | EnsureSpace ensure_space(this); |
| 2707 | emit(0xF3); |
| 2708 | emit_optional_rex_32(dst, src); |
| 2709 | emit(0x0F); |
| 2710 | emit(0x5C); |
| 2711 | emit_sse_operand(dst, src); |
| 2712 | } |
| 2713 | |
| 2714 | |
| 2715 | void Assembler::mulss(XMMRegister dst, XMMRegister src) { |
| 2716 | EnsureSpace ensure_space(this); |
| 2717 | emit(0xF3); |
| 2718 | emit_optional_rex_32(dst, src); |
| 2719 | emit(0x0F); |
| 2720 | emit(0x59); |
| 2721 | emit_sse_operand(dst, src); |
| 2722 | } |
| 2723 | |
| 2724 | |
| 2725 | void Assembler::mulss(XMMRegister dst, const Operand& src) { |
| 2726 | EnsureSpace ensure_space(this); |
| 2727 | emit(0xF3); |
| 2728 | emit_optional_rex_32(dst, src); |
| 2729 | emit(0x0F); |
| 2730 | emit(0x59); |
| 2731 | emit_sse_operand(dst, src); |
| 2732 | } |
| 2733 | |
| 2734 | |
| 2735 | void Assembler::divss(XMMRegister dst, XMMRegister src) { |
| 2736 | EnsureSpace ensure_space(this); |
| 2737 | emit(0xF3); |
| 2738 | emit_optional_rex_32(dst, src); |
| 2739 | emit(0x0F); |
| 2740 | emit(0x5E); |
| 2741 | emit_sse_operand(dst, src); |
| 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | void Assembler::divss(XMMRegister dst, const Operand& src) { |
| 2746 | EnsureSpace ensure_space(this); |
| 2747 | emit(0xF3); |
| 2748 | emit_optional_rex_32(dst, src); |
| 2749 | emit(0x0F); |
| 2750 | emit(0x5E); |
| 2751 | emit_sse_operand(dst, src); |
| 2752 | } |
| 2753 | |
| 2754 | |
| 2755 | void Assembler::ucomiss(XMMRegister dst, XMMRegister src) { |
| 2756 | EnsureSpace ensure_space(this); |
| 2757 | emit_optional_rex_32(dst, src); |
| 2758 | emit(0x0f); |
| 2759 | emit(0x2e); |
| 2760 | emit_sse_operand(dst, src); |
| 2761 | } |
| 2762 | |
| 2763 | |
| 2764 | void Assembler::ucomiss(XMMRegister dst, const Operand& src) { |
| 2765 | EnsureSpace ensure_space(this); |
| 2766 | emit_optional_rex_32(dst, src); |
| 2767 | emit(0x0f); |
| 2768 | emit(0x2e); |
| 2769 | emit_sse_operand(dst, src); |
| 2770 | } |
| 2771 | |
| 2772 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2773 | void Assembler::movss(XMMRegister dst, const Operand& src) { |
| 2774 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2775 | emit(0xF3); // single |
| 2776 | emit_optional_rex_32(dst, src); |
| 2777 | emit(0x0F); |
| 2778 | emit(0x10); // load |
| 2779 | emit_sse_operand(dst, src); |
| 2780 | } |
| 2781 | |
| 2782 | |
| 2783 | void Assembler::movss(const Operand& src, XMMRegister dst) { |
| 2784 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2785 | emit(0xF3); // single |
| 2786 | emit_optional_rex_32(dst, src); |
| 2787 | emit(0x0F); |
| 2788 | emit(0x11); // store |
| 2789 | emit_sse_operand(dst, src); |
| 2790 | } |
| 2791 | |
| 2792 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2793 | void Assembler::psllq(XMMRegister reg, byte imm8) { |
| 2794 | EnsureSpace ensure_space(this); |
| 2795 | emit(0x66); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2796 | emit_optional_rex_32(reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2797 | emit(0x0F); |
| 2798 | emit(0x73); |
| 2799 | emit_sse_operand(rsi, reg); // rsi == 6 |
| 2800 | emit(imm8); |
| 2801 | } |
| 2802 | |
| 2803 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2804 | void Assembler::psrlq(XMMRegister reg, byte imm8) { |
| 2805 | EnsureSpace ensure_space(this); |
| 2806 | emit(0x66); |
| 2807 | emit_optional_rex_32(reg); |
| 2808 | emit(0x0F); |
| 2809 | emit(0x73); |
| 2810 | emit_sse_operand(rdx, reg); // rdx == 2 |
| 2811 | emit(imm8); |
| 2812 | } |
| 2813 | |
| 2814 | |
| 2815 | void Assembler::pslld(XMMRegister reg, byte imm8) { |
| 2816 | EnsureSpace ensure_space(this); |
| 2817 | emit(0x66); |
| 2818 | emit_optional_rex_32(reg); |
| 2819 | emit(0x0F); |
| 2820 | emit(0x72); |
| 2821 | emit_sse_operand(rsi, reg); // rsi == 6 |
| 2822 | emit(imm8); |
| 2823 | } |
| 2824 | |
| 2825 | |
| 2826 | void Assembler::psrld(XMMRegister reg, byte imm8) { |
| 2827 | EnsureSpace ensure_space(this); |
| 2828 | emit(0x66); |
| 2829 | emit_optional_rex_32(reg); |
| 2830 | emit(0x0F); |
| 2831 | emit(0x72); |
| 2832 | emit_sse_operand(rdx, reg); // rdx == 2 |
| 2833 | emit(imm8); |
| 2834 | } |
| 2835 | |
| 2836 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2837 | void Assembler::cvttss2si(Register dst, const Operand& src) { |
| 2838 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2839 | emit(0xF3); |
| 2840 | emit_optional_rex_32(dst, src); |
| 2841 | emit(0x0F); |
| 2842 | emit(0x2C); |
| 2843 | emit_operand(dst, src); |
| 2844 | } |
| 2845 | |
| 2846 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2847 | void Assembler::cvttss2si(Register dst, XMMRegister src) { |
| 2848 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2849 | emit(0xF3); |
| 2850 | emit_optional_rex_32(dst, src); |
| 2851 | emit(0x0F); |
| 2852 | emit(0x2C); |
| 2853 | emit_sse_operand(dst, src); |
| 2854 | } |
| 2855 | |
| 2856 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2857 | void Assembler::cvttsd2si(Register dst, const Operand& src) { |
| 2858 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2859 | emit(0xF2); |
| 2860 | emit_optional_rex_32(dst, src); |
| 2861 | emit(0x0F); |
| 2862 | emit(0x2C); |
| 2863 | emit_operand(dst, src); |
| 2864 | } |
| 2865 | |
| 2866 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2867 | void Assembler::cvttsd2si(Register dst, XMMRegister src) { |
| 2868 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2869 | emit(0xF2); |
| 2870 | emit_optional_rex_32(dst, src); |
| 2871 | emit(0x0F); |
| 2872 | emit(0x2C); |
| 2873 | emit_sse_operand(dst, src); |
| 2874 | } |
| 2875 | |
| 2876 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2877 | void Assembler::cvttsd2siq(Register dst, XMMRegister src) { |
| 2878 | EnsureSpace ensure_space(this); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 2879 | emit(0xF2); |
| 2880 | emit_rex_64(dst, src); |
| 2881 | emit(0x0F); |
| 2882 | emit(0x2C); |
| 2883 | emit_sse_operand(dst, src); |
| 2884 | } |
| 2885 | |
| 2886 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2887 | void Assembler::cvttsd2siq(Register dst, const Operand& src) { |
| 2888 | EnsureSpace ensure_space(this); |
| 2889 | emit(0xF2); |
| 2890 | emit_rex_64(dst, src); |
| 2891 | emit(0x0F); |
| 2892 | emit(0x2C); |
| 2893 | emit_sse_operand(dst, src); |
| 2894 | } |
| 2895 | |
| 2896 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2897 | void Assembler::cvtlsi2sd(XMMRegister dst, const Operand& src) { |
| 2898 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2899 | emit(0xF2); |
| 2900 | emit_optional_rex_32(dst, src); |
| 2901 | emit(0x0F); |
| 2902 | emit(0x2A); |
| 2903 | emit_sse_operand(dst, src); |
| 2904 | } |
| 2905 | |
| 2906 | |
| 2907 | void Assembler::cvtlsi2sd(XMMRegister dst, Register src) { |
| 2908 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2909 | emit(0xF2); |
| 2910 | emit_optional_rex_32(dst, src); |
| 2911 | emit(0x0F); |
| 2912 | emit(0x2A); |
| 2913 | emit_sse_operand(dst, src); |
| 2914 | } |
| 2915 | |
| 2916 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2917 | void Assembler::cvtlsi2ss(XMMRegister dst, Register src) { |
| 2918 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2919 | emit(0xF3); |
| 2920 | emit_optional_rex_32(dst, src); |
| 2921 | emit(0x0F); |
| 2922 | emit(0x2A); |
| 2923 | emit_sse_operand(dst, src); |
| 2924 | } |
| 2925 | |
| 2926 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2927 | void Assembler::cvtqsi2sd(XMMRegister dst, const Operand& src) { |
| 2928 | EnsureSpace ensure_space(this); |
| 2929 | emit(0xF2); |
| 2930 | emit_rex_64(dst, src); |
| 2931 | emit(0x0F); |
| 2932 | emit(0x2A); |
| 2933 | emit_sse_operand(dst, src); |
| 2934 | } |
| 2935 | |
| 2936 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2937 | void Assembler::cvtqsi2sd(XMMRegister dst, Register src) { |
| 2938 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2939 | emit(0xF2); |
| 2940 | emit_rex_64(dst, src); |
| 2941 | emit(0x0F); |
| 2942 | emit(0x2A); |
| 2943 | emit_sse_operand(dst, src); |
| 2944 | } |
| 2945 | |
| 2946 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2947 | void Assembler::cvtss2sd(XMMRegister dst, XMMRegister src) { |
| 2948 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2949 | emit(0xF3); |
| 2950 | emit_optional_rex_32(dst, src); |
| 2951 | emit(0x0F); |
| 2952 | emit(0x5A); |
| 2953 | emit_sse_operand(dst, src); |
| 2954 | } |
| 2955 | |
| 2956 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2957 | void Assembler::cvtss2sd(XMMRegister dst, const Operand& src) { |
| 2958 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2959 | emit(0xF3); |
| 2960 | emit_optional_rex_32(dst, src); |
| 2961 | emit(0x0F); |
| 2962 | emit(0x5A); |
| 2963 | emit_sse_operand(dst, src); |
| 2964 | } |
| 2965 | |
| 2966 | |
| 2967 | void Assembler::cvtsd2ss(XMMRegister dst, XMMRegister src) { |
| 2968 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2969 | emit(0xF2); |
| 2970 | emit_optional_rex_32(dst, src); |
| 2971 | emit(0x0F); |
| 2972 | emit(0x5A); |
| 2973 | emit_sse_operand(dst, src); |
| 2974 | } |
| 2975 | |
| 2976 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2977 | void Assembler::cvtsd2ss(XMMRegister dst, const Operand& src) { |
| 2978 | EnsureSpace ensure_space(this); |
| 2979 | emit(0xF2); |
| 2980 | emit_optional_rex_32(dst, src); |
| 2981 | emit(0x0F); |
| 2982 | emit(0x5A); |
| 2983 | emit_sse_operand(dst, src); |
| 2984 | } |
| 2985 | |
| 2986 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2987 | void Assembler::cvtsd2si(Register dst, XMMRegister src) { |
| 2988 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2989 | emit(0xF2); |
| 2990 | emit_optional_rex_32(dst, src); |
| 2991 | emit(0x0F); |
| 2992 | emit(0x2D); |
| 2993 | emit_sse_operand(dst, src); |
| 2994 | } |
| 2995 | |
| 2996 | |
| 2997 | void Assembler::cvtsd2siq(Register dst, XMMRegister src) { |
| 2998 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 2999 | emit(0xF2); |
| 3000 | emit_rex_64(dst, src); |
| 3001 | emit(0x0F); |
| 3002 | emit(0x2D); |
| 3003 | emit_sse_operand(dst, src); |
| 3004 | } |
| 3005 | |
| 3006 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3007 | void Assembler::addsd(XMMRegister dst, XMMRegister src) { |
| 3008 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3009 | emit(0xF2); |
| 3010 | emit_optional_rex_32(dst, src); |
| 3011 | emit(0x0F); |
| 3012 | emit(0x58); |
| 3013 | emit_sse_operand(dst, src); |
| 3014 | } |
| 3015 | |
| 3016 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3017 | void Assembler::addsd(XMMRegister dst, const Operand& src) { |
| 3018 | EnsureSpace ensure_space(this); |
| 3019 | emit(0xF2); |
| 3020 | emit_optional_rex_32(dst, src); |
| 3021 | emit(0x0F); |
| 3022 | emit(0x58); |
| 3023 | emit_sse_operand(dst, src); |
| 3024 | } |
| 3025 | |
| 3026 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3027 | void Assembler::mulsd(XMMRegister dst, XMMRegister src) { |
| 3028 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3029 | emit(0xF2); |
| 3030 | emit_optional_rex_32(dst, src); |
| 3031 | emit(0x0F); |
| 3032 | emit(0x59); |
| 3033 | emit_sse_operand(dst, src); |
| 3034 | } |
| 3035 | |
| 3036 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3037 | void Assembler::mulsd(XMMRegister dst, const Operand& src) { |
| 3038 | EnsureSpace ensure_space(this); |
| 3039 | emit(0xF2); |
| 3040 | emit_optional_rex_32(dst, src); |
| 3041 | emit(0x0F); |
| 3042 | emit(0x59); |
| 3043 | emit_sse_operand(dst, src); |
| 3044 | } |
| 3045 | |
| 3046 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3047 | void Assembler::subsd(XMMRegister dst, XMMRegister src) { |
| 3048 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3049 | emit(0xF2); |
| 3050 | emit_optional_rex_32(dst, src); |
| 3051 | emit(0x0F); |
| 3052 | emit(0x5C); |
| 3053 | emit_sse_operand(dst, src); |
| 3054 | } |
| 3055 | |
| 3056 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3057 | void Assembler::subsd(XMMRegister dst, const Operand& src) { |
| 3058 | EnsureSpace ensure_space(this); |
| 3059 | emit(0xF2); |
| 3060 | emit_optional_rex_32(dst, src); |
| 3061 | emit(0x0F); |
| 3062 | emit(0x5C); |
| 3063 | emit_sse_operand(dst, src); |
| 3064 | } |
| 3065 | |
| 3066 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3067 | void Assembler::divsd(XMMRegister dst, XMMRegister src) { |
| 3068 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3069 | emit(0xF2); |
| 3070 | emit_optional_rex_32(dst, src); |
| 3071 | emit(0x0F); |
| 3072 | emit(0x5E); |
| 3073 | emit_sse_operand(dst, src); |
| 3074 | } |
| 3075 | |
| 3076 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3077 | void Assembler::divsd(XMMRegister dst, const Operand& src) { |
| 3078 | EnsureSpace ensure_space(this); |
| 3079 | emit(0xF2); |
| 3080 | emit_optional_rex_32(dst, src); |
| 3081 | emit(0x0F); |
| 3082 | emit(0x5E); |
| 3083 | emit_sse_operand(dst, src); |
| 3084 | } |
| 3085 | |
| 3086 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3087 | void Assembler::andpd(XMMRegister dst, XMMRegister src) { |
| 3088 | EnsureSpace ensure_space(this); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3089 | emit(0x66); |
| 3090 | emit_optional_rex_32(dst, src); |
| 3091 | emit(0x0F); |
| 3092 | emit(0x54); |
| 3093 | emit_sse_operand(dst, src); |
| 3094 | } |
| 3095 | |
| 3096 | |
| 3097 | void Assembler::orpd(XMMRegister dst, XMMRegister src) { |
| 3098 | EnsureSpace ensure_space(this); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3099 | emit(0x66); |
| 3100 | emit_optional_rex_32(dst, src); |
| 3101 | emit(0x0F); |
| 3102 | emit(0x56); |
| 3103 | emit_sse_operand(dst, src); |
| 3104 | } |
| 3105 | |
| 3106 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3107 | void Assembler::xorpd(XMMRegister dst, XMMRegister src) { |
| 3108 | EnsureSpace ensure_space(this); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3109 | emit(0x66); |
| 3110 | emit_optional_rex_32(dst, src); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3111 | emit(0x0F); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3112 | emit(0x57); |
| 3113 | emit_sse_operand(dst, src); |
| 3114 | } |
| 3115 | |
| 3116 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3117 | void Assembler::sqrtsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3118 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3119 | emit(0xF2); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3120 | emit_optional_rex_32(dst, src); |
| 3121 | emit(0x0F); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3122 | emit(0x51); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3123 | emit_sse_operand(dst, src); |
| 3124 | } |
| 3125 | |
| 3126 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3127 | void Assembler::sqrtsd(XMMRegister dst, const Operand& src) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3128 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3129 | emit(0xF2); |
| 3130 | emit_optional_rex_32(dst, src); |
| 3131 | emit(0x0F); |
| 3132 | emit(0x51); |
| 3133 | emit_sse_operand(dst, src); |
| 3134 | } |
| 3135 | |
| 3136 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3137 | void Assembler::ucomisd(XMMRegister dst, XMMRegister src) { |
| 3138 | EnsureSpace ensure_space(this); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 3139 | emit(0x66); |
| 3140 | emit_optional_rex_32(dst, src); |
| 3141 | emit(0x0f); |
| 3142 | emit(0x2e); |
| 3143 | emit_sse_operand(dst, src); |
| 3144 | } |
| 3145 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3146 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3147 | void Assembler::ucomisd(XMMRegister dst, const Operand& src) { |
| 3148 | EnsureSpace ensure_space(this); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3149 | emit(0x66); |
| 3150 | emit_optional_rex_32(dst, src); |
| 3151 | emit(0x0f); |
| 3152 | emit(0x2e); |
| 3153 | emit_sse_operand(dst, src); |
| 3154 | } |
| 3155 | |
| 3156 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3157 | void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) { |
| 3158 | EnsureSpace ensure_space(this); |
| 3159 | emit(0xF2); |
| 3160 | emit_optional_rex_32(dst, src); |
| 3161 | emit(0x0F); |
| 3162 | emit(0xC2); |
| 3163 | emit_sse_operand(dst, src); |
| 3164 | emit(0x01); // LT == 1 |
| 3165 | } |
| 3166 | |
| 3167 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3168 | void Assembler::roundsd(XMMRegister dst, XMMRegister src, |
| 3169 | Assembler::RoundingMode mode) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3170 | DCHECK(IsEnabled(SSE4_1)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3171 | EnsureSpace ensure_space(this); |
| 3172 | emit(0x66); |
| 3173 | emit_optional_rex_32(dst, src); |
| 3174 | emit(0x0f); |
| 3175 | emit(0x3a); |
| 3176 | emit(0x0b); |
| 3177 | emit_sse_operand(dst, src); |
| 3178 | // Mask precision exeption. |
| 3179 | emit(static_cast<byte>(mode) | 0x8); |
| 3180 | } |
| 3181 | |
| 3182 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3183 | void Assembler::movmskpd(Register dst, XMMRegister src) { |
| 3184 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3185 | emit(0x66); |
| 3186 | emit_optional_rex_32(dst, src); |
| 3187 | emit(0x0f); |
| 3188 | emit(0x50); |
| 3189 | emit_sse_operand(dst, src); |
| 3190 | } |
| 3191 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 3192 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3193 | void Assembler::movmskps(Register dst, XMMRegister src) { |
| 3194 | EnsureSpace ensure_space(this); |
| 3195 | emit_optional_rex_32(dst, src); |
| 3196 | emit(0x0f); |
| 3197 | emit(0x50); |
| 3198 | emit_sse_operand(dst, src); |
| 3199 | } |
| 3200 | |
| 3201 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3202 | void Assembler::pcmpeqd(XMMRegister dst, XMMRegister src) { |
| 3203 | EnsureSpace ensure_space(this); |
| 3204 | emit(0x66); |
| 3205 | emit_optional_rex_32(dst, src); |
| 3206 | emit(0x0F); |
| 3207 | emit(0x76); |
| 3208 | emit_sse_operand(dst, src); |
| 3209 | } |
| 3210 | |
| 3211 | |
| 3212 | // AVX instructions |
| 3213 | void Assembler::vfmasd(byte op, XMMRegister dst, XMMRegister src1, |
| 3214 | XMMRegister src2) { |
| 3215 | DCHECK(IsEnabled(FMA3)); |
| 3216 | EnsureSpace ensure_space(this); |
| 3217 | emit_vex_prefix(dst, src1, src2, kLIG, k66, k0F38, kW1); |
| 3218 | emit(op); |
| 3219 | emit_sse_operand(dst, src2); |
| 3220 | } |
| 3221 | |
| 3222 | |
| 3223 | void Assembler::vfmasd(byte op, XMMRegister dst, XMMRegister src1, |
| 3224 | const Operand& src2) { |
| 3225 | DCHECK(IsEnabled(FMA3)); |
| 3226 | EnsureSpace ensure_space(this); |
| 3227 | emit_vex_prefix(dst, src1, src2, kLIG, k66, k0F38, kW1); |
| 3228 | emit(op); |
| 3229 | emit_sse_operand(dst, src2); |
| 3230 | } |
| 3231 | |
| 3232 | |
| 3233 | void Assembler::vfmass(byte op, XMMRegister dst, XMMRegister src1, |
| 3234 | XMMRegister src2) { |
| 3235 | DCHECK(IsEnabled(FMA3)); |
| 3236 | EnsureSpace ensure_space(this); |
| 3237 | emit_vex_prefix(dst, src1, src2, kLIG, k66, k0F38, kW0); |
| 3238 | emit(op); |
| 3239 | emit_sse_operand(dst, src2); |
| 3240 | } |
| 3241 | |
| 3242 | |
| 3243 | void Assembler::vfmass(byte op, XMMRegister dst, XMMRegister src1, |
| 3244 | const Operand& src2) { |
| 3245 | DCHECK(IsEnabled(FMA3)); |
| 3246 | EnsureSpace ensure_space(this); |
| 3247 | emit_vex_prefix(dst, src1, src2, kLIG, k66, k0F38, kW0); |
| 3248 | emit(op); |
| 3249 | emit_sse_operand(dst, src2); |
| 3250 | } |
| 3251 | |
| 3252 | |
| 3253 | void Assembler::vsd(byte op, XMMRegister dst, XMMRegister src1, |
| 3254 | XMMRegister src2) { |
| 3255 | DCHECK(IsEnabled(AVX)); |
| 3256 | EnsureSpace ensure_space(this); |
| 3257 | emit_vex_prefix(dst, src1, src2, kLIG, kF2, k0F, kWIG); |
| 3258 | emit(op); |
| 3259 | emit_sse_operand(dst, src2); |
| 3260 | } |
| 3261 | |
| 3262 | |
| 3263 | void Assembler::vsd(byte op, XMMRegister dst, XMMRegister src1, |
| 3264 | const Operand& src2) { |
| 3265 | DCHECK(IsEnabled(AVX)); |
| 3266 | EnsureSpace ensure_space(this); |
| 3267 | emit_vex_prefix(dst, src1, src2, kLIG, kF2, k0F, kWIG); |
| 3268 | emit(op); |
| 3269 | emit_sse_operand(dst, src2); |
| 3270 | } |
| 3271 | |
| 3272 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3273 | void Assembler::emit_sse_operand(XMMRegister reg, const Operand& adr) { |
| 3274 | Register ireg = { reg.code() }; |
| 3275 | emit_operand(ireg, adr); |
| 3276 | } |
| 3277 | |
| 3278 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3279 | void Assembler::emit_sse_operand(Register reg, const Operand& adr) { |
| 3280 | Register ireg = {reg.code()}; |
| 3281 | emit_operand(ireg, adr); |
| 3282 | } |
| 3283 | |
| 3284 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3285 | void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) { |
| 3286 | emit(0xC0 | (dst.low_bits() << 3) | src.low_bits()); |
| 3287 | } |
| 3288 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3289 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3290 | void Assembler::emit_sse_operand(XMMRegister dst, Register src) { |
| 3291 | emit(0xC0 | (dst.low_bits() << 3) | src.low_bits()); |
| 3292 | } |
| 3293 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3294 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 3295 | void Assembler::emit_sse_operand(Register dst, XMMRegister src) { |
| 3296 | emit(0xC0 | (dst.low_bits() << 3) | src.low_bits()); |
| 3297 | } |
| 3298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3299 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 3300 | void Assembler::db(uint8_t data) { |
| 3301 | EnsureSpace ensure_space(this); |
| 3302 | emit(data); |
| 3303 | } |
| 3304 | |
| 3305 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3306 | void Assembler::dd(uint32_t data) { |
| 3307 | EnsureSpace ensure_space(this); |
| 3308 | emitl(data); |
| 3309 | } |
| 3310 | |
| 3311 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 3312 | // Relocation information implementations. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3313 | |
| 3314 | void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3315 | DCHECK(!RelocInfo::IsNone(rmode)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3316 | // Don't record external references unless the heap will be serialized. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3317 | if (rmode == RelocInfo::EXTERNAL_REFERENCE && |
| 3318 | !serializer_enabled() && !emit_debug_code()) { |
| 3319 | return; |
| 3320 | } else if (rmode == RelocInfo::CODE_AGE_SEQUENCE) { |
| 3321 | // Don't record psuedo relocation info for code age sequence mode. |
| 3322 | return; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3323 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3324 | RelocInfo rinfo(pc_, rmode, data, NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3325 | reloc_info_writer.Write(&rinfo); |
| 3326 | } |
| 3327 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3328 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3329 | void Assembler::RecordJSReturn() { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 3330 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3331 | EnsureSpace ensure_space(this); |
| 3332 | RecordRelocInfo(RelocInfo::JS_RETURN); |
| 3333 | } |
| 3334 | |
| 3335 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3336 | void Assembler::RecordDebugBreakSlot() { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 3337 | positions_recorder()->WriteRecordedPositions(); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3338 | EnsureSpace ensure_space(this); |
| 3339 | RecordRelocInfo(RelocInfo::DEBUG_BREAK_SLOT); |
| 3340 | } |
| 3341 | |
| 3342 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3343 | void Assembler::RecordComment(const char* msg, bool force) { |
| 3344 | if (FLAG_code_comments || force) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3345 | EnsureSpace ensure_space(this); |
| 3346 | RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3351 | Handle<ConstantPoolArray> Assembler::NewConstantPool(Isolate* isolate) { |
| 3352 | // No out-of-line constant pool support. |
| 3353 | DCHECK(!FLAG_enable_ool_constant_pool); |
| 3354 | return isolate->factory()->empty_constant_pool_array(); |
| 3355 | } |
| 3356 | |
| 3357 | |
| 3358 | void Assembler::PopulateConstantPool(ConstantPoolArray* constant_pool) { |
| 3359 | // No out-of-line constant pool support. |
| 3360 | DCHECK(!FLAG_enable_ool_constant_pool); |
| 3361 | return; |
| 3362 | } |
| 3363 | |
| 3364 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3365 | const int RelocInfo::kApplyMask = RelocInfo::kCodeTargetMask | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3366 | 1 << RelocInfo::RUNTIME_ENTRY | |
| 3367 | 1 << RelocInfo::INTERNAL_REFERENCE | |
| 3368 | 1 << RelocInfo::CODE_AGE_SEQUENCE; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3369 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3370 | |
| 3371 | bool RelocInfo::IsCodedSpecially() { |
| 3372 | // The deserializer needs to know whether a pointer is specially coded. Being |
| 3373 | // specially coded on x64 means that it is a relative 32 bit address, as used |
| 3374 | // by branch instructions. |
| 3375 | return (1 << rmode_) & kApplyMask; |
| 3376 | } |
| 3377 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3378 | |
| 3379 | bool RelocInfo::IsInConstantPool() { |
| 3380 | return false; |
| 3381 | } |
| 3382 | |
| 3383 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 3384 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3385 | |
| 3386 | #endif // V8_TARGET_ARCH_X64 |