Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions |
| 6 | // are met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // |
| 16 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 17 | // be used to endorse or promote products derived from this software without |
| 18 | // specific prior written permission. |
| 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | |
| 33 | // The original source code covered by the above license above has been modified |
| 34 | // significantly by Google Inc. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 35 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 36 | |
| 37 | #include "v8.h" |
| 38 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 39 | #if defined(V8_TARGET_ARCH_IA32) |
| 40 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 41 | #include "disassembler.h" |
| 42 | #include "macro-assembler.h" |
| 43 | #include "serialize.h" |
| 44 | |
| 45 | namespace v8 { |
| 46 | namespace internal { |
| 47 | |
| 48 | // ----------------------------------------------------------------------------- |
| 49 | // Implementation of CpuFeatures |
| 50 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 51 | #ifdef DEBUG |
| 52 | bool CpuFeatures::initialized_ = false; |
| 53 | #endif |
| 54 | uint64_t CpuFeatures::supported_ = 0; |
| 55 | uint64_t CpuFeatures::found_by_runtime_probing_ = 0; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 56 | |
| 57 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 58 | void CpuFeatures::Probe() { |
| 59 | ASSERT(!initialized_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 60 | ASSERT(supported_ == 0); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 61 | #ifdef DEBUG |
| 62 | initialized_ = true; |
| 63 | #endif |
| 64 | if (Serializer::enabled()) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 65 | supported_ |= OS::CpuFeaturesImpliedByPlatform(); |
| 66 | return; // No features if we might serialize. |
| 67 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 68 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 69 | const int kBufferSize = 4 * KB; |
| 70 | VirtualMemory* memory = new VirtualMemory(kBufferSize); |
| 71 | if (!memory->IsReserved()) { |
| 72 | delete memory; |
| 73 | return; |
| 74 | } |
| 75 | ASSERT(memory->size() >= static_cast<size_t>(kBufferSize)); |
| 76 | if (!memory->Commit(memory->address(), kBufferSize, true/*executable*/)) { |
| 77 | delete memory; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | Assembler assm(NULL, memory->address(), kBufferSize); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | Label cpuid, done; |
| 83 | #define __ assm. |
| 84 | // Save old esp, since we are going to modify the stack. |
| 85 | __ push(ebp); |
| 86 | __ pushfd(); |
| 87 | __ push(ecx); |
| 88 | __ push(ebx); |
| 89 | __ mov(ebp, Operand(esp)); |
| 90 | |
| 91 | // If we can modify bit 21 of the EFLAGS register, then CPUID is supported. |
| 92 | __ pushfd(); |
| 93 | __ pop(eax); |
| 94 | __ mov(edx, Operand(eax)); |
| 95 | __ xor_(eax, 0x200000); // Flip bit 21. |
| 96 | __ push(eax); |
| 97 | __ popfd(); |
| 98 | __ pushfd(); |
| 99 | __ pop(eax); |
| 100 | __ xor_(eax, Operand(edx)); // Different if CPUID is supported. |
| 101 | __ j(not_zero, &cpuid); |
| 102 | |
| 103 | // CPUID not supported. Clear the supported features in edx:eax. |
| 104 | __ xor_(eax, Operand(eax)); |
| 105 | __ xor_(edx, Operand(edx)); |
| 106 | __ jmp(&done); |
| 107 | |
| 108 | // Invoke CPUID with 1 in eax to get feature information in |
| 109 | // ecx:edx. Temporarily enable CPUID support because we know it's |
| 110 | // safe here. |
| 111 | __ bind(&cpuid); |
| 112 | __ mov(eax, 1); |
| 113 | supported_ = (1 << CPUID); |
| 114 | { Scope fscope(CPUID); |
| 115 | __ cpuid(); |
| 116 | } |
| 117 | supported_ = 0; |
| 118 | |
| 119 | // Move the result from ecx:edx to edx:eax and make sure to mark the |
| 120 | // CPUID feature as supported. |
| 121 | __ mov(eax, Operand(edx)); |
| 122 | __ or_(eax, 1 << CPUID); |
| 123 | __ mov(edx, Operand(ecx)); |
| 124 | |
| 125 | // Done. |
| 126 | __ bind(&done); |
| 127 | __ mov(esp, Operand(ebp)); |
| 128 | __ pop(ebx); |
| 129 | __ pop(ecx); |
| 130 | __ popfd(); |
| 131 | __ pop(ebp); |
| 132 | __ ret(0); |
| 133 | #undef __ |
| 134 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | typedef uint64_t (*F0)(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 136 | F0 probe = FUNCTION_CAST<F0>(reinterpret_cast<Address>(memory->address())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 137 | supported_ = probe(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 138 | found_by_runtime_probing_ = supported_; |
| 139 | uint64_t os_guarantees = OS::CpuFeaturesImpliedByPlatform(); |
| 140 | supported_ |= os_guarantees; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 141 | found_by_runtime_probing_ &= ~os_guarantees; |
| 142 | |
| 143 | delete memory; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
| 147 | // ----------------------------------------------------------------------------- |
| 148 | // Implementation of Displacement |
| 149 | |
| 150 | void Displacement::init(Label* L, Type type) { |
| 151 | ASSERT(!L->is_bound()); |
| 152 | int next = 0; |
| 153 | if (L->is_linked()) { |
| 154 | next = L->pos(); |
| 155 | ASSERT(next > 0); // Displacements must be at positions > 0 |
| 156 | } |
| 157 | // Ensure that we _never_ overflow the next field. |
| 158 | ASSERT(NextField::is_valid(Assembler::kMaximalBufferSize)); |
| 159 | data_ = NextField::encode(next) | TypeField::encode(type); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | // ----------------------------------------------------------------------------- |
| 164 | // Implementation of RelocInfo |
| 165 | |
| 166 | |
| 167 | const int RelocInfo::kApplyMask = |
| 168 | RelocInfo::kCodeTargetMask | 1 << RelocInfo::RUNTIME_ENTRY | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 169 | 1 << RelocInfo::JS_RETURN | 1 << RelocInfo::INTERNAL_REFERENCE | |
| 170 | 1 << RelocInfo::DEBUG_BREAK_SLOT; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 171 | |
| 172 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 173 | bool RelocInfo::IsCodedSpecially() { |
| 174 | // The deserializer needs to know whether a pointer is specially coded. Being |
| 175 | // specially coded on IA32 means that it is a relative address, as used by |
| 176 | // branch instructions. These are also the ones that need changing when a |
| 177 | // code object moves. |
| 178 | return (1 << rmode_) & kApplyMask; |
| 179 | } |
| 180 | |
| 181 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 182 | void RelocInfo::PatchCode(byte* instructions, int instruction_count) { |
| 183 | // Patch the code at the current address with the supplied instructions. |
| 184 | for (int i = 0; i < instruction_count; i++) { |
| 185 | *(pc_ + i) = *(instructions + i); |
| 186 | } |
| 187 | |
| 188 | // Indicate that code has changed. |
| 189 | CPU::FlushICache(pc_, instruction_count); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | // Patch the code at the current PC with a call to the target address. |
| 194 | // Additional guard int3 instructions can be added if required. |
| 195 | void RelocInfo::PatchCodeWithCall(Address target, int guard_bytes) { |
| 196 | // Call instruction takes up 5 bytes and int3 takes up one byte. |
| 197 | static const int kCallCodeSize = 5; |
| 198 | int code_size = kCallCodeSize + guard_bytes; |
| 199 | |
| 200 | // Create a code patcher. |
| 201 | CodePatcher patcher(pc_, code_size); |
| 202 | |
| 203 | // Add a label for checking the size of the code used for returning. |
| 204 | #ifdef DEBUG |
| 205 | Label check_codesize; |
| 206 | patcher.masm()->bind(&check_codesize); |
| 207 | #endif |
| 208 | |
| 209 | // Patch the code. |
| 210 | patcher.masm()->call(target, RelocInfo::NONE); |
| 211 | |
| 212 | // Check that the size of the code generated is as expected. |
| 213 | ASSERT_EQ(kCallCodeSize, |
| 214 | patcher.masm()->SizeOfCodeGeneratedSince(&check_codesize)); |
| 215 | |
| 216 | // Add the requested number of int3 instructions after the call. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 217 | ASSERT_GE(guard_bytes, 0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 218 | for (int i = 0; i < guard_bytes; i++) { |
| 219 | patcher.masm()->int3(); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | |
| 224 | // ----------------------------------------------------------------------------- |
| 225 | // Implementation of Operand |
| 226 | |
| 227 | Operand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) { |
| 228 | // [base + disp/r] |
| 229 | if (disp == 0 && rmode == RelocInfo::NONE && !base.is(ebp)) { |
| 230 | // [base] |
| 231 | set_modrm(0, base); |
| 232 | if (base.is(esp)) set_sib(times_1, esp, base); |
| 233 | } else if (is_int8(disp) && rmode == RelocInfo::NONE) { |
| 234 | // [base + disp8] |
| 235 | set_modrm(1, base); |
| 236 | if (base.is(esp)) set_sib(times_1, esp, base); |
| 237 | set_disp8(disp); |
| 238 | } else { |
| 239 | // [base + disp/r] |
| 240 | set_modrm(2, base); |
| 241 | if (base.is(esp)) set_sib(times_1, esp, base); |
| 242 | set_dispr(disp, rmode); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | |
| 247 | Operand::Operand(Register base, |
| 248 | Register index, |
| 249 | ScaleFactor scale, |
| 250 | int32_t disp, |
| 251 | RelocInfo::Mode rmode) { |
| 252 | ASSERT(!index.is(esp)); // illegal addressing mode |
| 253 | // [base + index*scale + disp/r] |
| 254 | if (disp == 0 && rmode == RelocInfo::NONE && !base.is(ebp)) { |
| 255 | // [base + index*scale] |
| 256 | set_modrm(0, esp); |
| 257 | set_sib(scale, index, base); |
| 258 | } else if (is_int8(disp) && rmode == RelocInfo::NONE) { |
| 259 | // [base + index*scale + disp8] |
| 260 | set_modrm(1, esp); |
| 261 | set_sib(scale, index, base); |
| 262 | set_disp8(disp); |
| 263 | } else { |
| 264 | // [base + index*scale + disp/r] |
| 265 | set_modrm(2, esp); |
| 266 | set_sib(scale, index, base); |
| 267 | set_dispr(disp, rmode); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | |
| 272 | Operand::Operand(Register index, |
| 273 | ScaleFactor scale, |
| 274 | int32_t disp, |
| 275 | RelocInfo::Mode rmode) { |
| 276 | ASSERT(!index.is(esp)); // illegal addressing mode |
| 277 | // [index*scale + disp/r] |
| 278 | set_modrm(0, esp); |
| 279 | set_sib(scale, index, ebp); |
| 280 | set_dispr(disp, rmode); |
| 281 | } |
| 282 | |
| 283 | |
| 284 | bool Operand::is_reg(Register reg) const { |
| 285 | return ((buf_[0] & 0xF8) == 0xC0) // addressing mode is register only. |
| 286 | && ((buf_[0] & 0x07) == reg.code()); // register codes match. |
| 287 | } |
| 288 | |
| 289 | // ----------------------------------------------------------------------------- |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 290 | // Implementation of Assembler. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 291 | |
| 292 | // Emit a single byte. Must always be inlined. |
| 293 | #define EMIT(x) \ |
| 294 | *pc_++ = (x) |
| 295 | |
| 296 | |
| 297 | #ifdef GENERATED_CODE_COVERAGE |
| 298 | static void InitCoverageLog(); |
| 299 | #endif |
| 300 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 301 | Assembler::Assembler(Isolate* arg_isolate, void* buffer, int buffer_size) |
| 302 | : AssemblerBase(arg_isolate), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 303 | positions_recorder_(this), |
| 304 | emit_debug_code_(FLAG_debug_code) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 305 | if (buffer == NULL) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 306 | // Do our own buffer management. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 307 | if (buffer_size <= kMinimalBufferSize) { |
| 308 | buffer_size = kMinimalBufferSize; |
| 309 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 310 | if (isolate()->assembler_spare_buffer() != NULL) { |
| 311 | buffer = isolate()->assembler_spare_buffer(); |
| 312 | isolate()->set_assembler_spare_buffer(NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | if (buffer == NULL) { |
| 316 | buffer_ = NewArray<byte>(buffer_size); |
| 317 | } else { |
| 318 | buffer_ = static_cast<byte*>(buffer); |
| 319 | } |
| 320 | buffer_size_ = buffer_size; |
| 321 | own_buffer_ = true; |
| 322 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 323 | // Use externally provided buffer instead. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 324 | ASSERT(buffer_size > 0); |
| 325 | buffer_ = static_cast<byte*>(buffer); |
| 326 | buffer_size_ = buffer_size; |
| 327 | own_buffer_ = false; |
| 328 | } |
| 329 | |
| 330 | // Clear the buffer in debug mode unless it was provided by the |
| 331 | // caller in which case we can't be sure it's okay to overwrite |
| 332 | // existing code in it; see CodePatcher::CodePatcher(...). |
| 333 | #ifdef DEBUG |
| 334 | if (own_buffer_) { |
| 335 | memset(buffer_, 0xCC, buffer_size); // int3 |
| 336 | } |
| 337 | #endif |
| 338 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 339 | // Setup buffer pointers. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 340 | ASSERT(buffer_ != NULL); |
| 341 | pc_ = buffer_; |
| 342 | reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); |
| 343 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | #ifdef GENERATED_CODE_COVERAGE |
| 345 | InitCoverageLog(); |
| 346 | #endif |
| 347 | } |
| 348 | |
| 349 | |
| 350 | Assembler::~Assembler() { |
| 351 | if (own_buffer_) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 352 | if (isolate()->assembler_spare_buffer() == NULL && |
| 353 | buffer_size_ == kMinimalBufferSize) { |
| 354 | isolate()->set_assembler_spare_buffer(buffer_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 355 | } else { |
| 356 | DeleteArray(buffer_); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | void Assembler::GetCode(CodeDesc* desc) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 363 | // Finalize code (at this point overflow() may be true, but the gap ensures |
| 364 | // that we are still not overlapping instructions and relocation info). |
| 365 | ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. |
| 366 | // Setup code descriptor. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | desc->buffer = buffer_; |
| 368 | desc->buffer_size = buffer_size_; |
| 369 | desc->instr_size = pc_offset(); |
| 370 | desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| 371 | desc->origin = this; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
| 375 | void Assembler::Align(int m) { |
| 376 | ASSERT(IsPowerOf2(m)); |
| 377 | while ((pc_offset() & (m - 1)) != 0) { |
| 378 | nop(); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 383 | void Assembler::CodeTargetAlign() { |
| 384 | Align(16); // Preferred alignment of jump targets on ia32. |
| 385 | } |
| 386 | |
| 387 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 388 | void Assembler::cpuid() { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 389 | ASSERT(CpuFeatures::IsEnabled(CPUID)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 390 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | EMIT(0x0F); |
| 392 | EMIT(0xA2); |
| 393 | } |
| 394 | |
| 395 | |
| 396 | void Assembler::pushad() { |
| 397 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | EMIT(0x60); |
| 399 | } |
| 400 | |
| 401 | |
| 402 | void Assembler::popad() { |
| 403 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 404 | EMIT(0x61); |
| 405 | } |
| 406 | |
| 407 | |
| 408 | void Assembler::pushfd() { |
| 409 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 410 | EMIT(0x9C); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | void Assembler::popfd() { |
| 415 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 416 | EMIT(0x9D); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | void Assembler::push(const Immediate& x) { |
| 421 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 422 | if (x.is_int8()) { |
| 423 | EMIT(0x6a); |
| 424 | EMIT(x.x_); |
| 425 | } else { |
| 426 | EMIT(0x68); |
| 427 | emit(x); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 432 | void Assembler::push_imm32(int32_t imm32) { |
| 433 | EnsureSpace ensure_space(this); |
| 434 | EMIT(0x68); |
| 435 | emit(imm32); |
| 436 | } |
| 437 | |
| 438 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 439 | void Assembler::push(Register src) { |
| 440 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 441 | EMIT(0x50 | src.code()); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | void Assembler::push(const Operand& src) { |
| 446 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | EMIT(0xFF); |
| 448 | emit_operand(esi, src); |
| 449 | } |
| 450 | |
| 451 | |
| 452 | void Assembler::pop(Register dst) { |
| 453 | ASSERT(reloc_info_writer.last_pc() != NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 454 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 455 | EMIT(0x58 | dst.code()); |
| 456 | } |
| 457 | |
| 458 | |
| 459 | void Assembler::pop(const Operand& dst) { |
| 460 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 461 | EMIT(0x8F); |
| 462 | emit_operand(eax, dst); |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void Assembler::enter(const Immediate& size) { |
| 467 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | EMIT(0xC8); |
| 469 | emit_w(size); |
| 470 | EMIT(0); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | void Assembler::leave() { |
| 475 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 476 | EMIT(0xC9); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | void Assembler::mov_b(Register dst, const Operand& src) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 481 | ASSERT(dst.code() < 4); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 482 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 483 | EMIT(0x8A); |
| 484 | emit_operand(dst, src); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | void Assembler::mov_b(const Operand& dst, int8_t imm8) { |
| 489 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 490 | EMIT(0xC6); |
| 491 | emit_operand(eax, dst); |
| 492 | EMIT(imm8); |
| 493 | } |
| 494 | |
| 495 | |
| 496 | void Assembler::mov_b(const Operand& dst, Register src) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 497 | ASSERT(src.code() < 4); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 498 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | EMIT(0x88); |
| 500 | emit_operand(src, dst); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | void Assembler::mov_w(Register dst, const Operand& src) { |
| 505 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 506 | EMIT(0x66); |
| 507 | EMIT(0x8B); |
| 508 | emit_operand(dst, src); |
| 509 | } |
| 510 | |
| 511 | |
| 512 | void Assembler::mov_w(const Operand& dst, Register src) { |
| 513 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 514 | EMIT(0x66); |
| 515 | EMIT(0x89); |
| 516 | emit_operand(src, dst); |
| 517 | } |
| 518 | |
| 519 | |
| 520 | void Assembler::mov(Register dst, int32_t imm32) { |
| 521 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 522 | EMIT(0xB8 | dst.code()); |
| 523 | emit(imm32); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void Assembler::mov(Register dst, const Immediate& x) { |
| 528 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 529 | EMIT(0xB8 | dst.code()); |
| 530 | emit(x); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | void Assembler::mov(Register dst, Handle<Object> handle) { |
| 535 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | EMIT(0xB8 | dst.code()); |
| 537 | emit(handle); |
| 538 | } |
| 539 | |
| 540 | |
| 541 | void Assembler::mov(Register dst, const Operand& src) { |
| 542 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 543 | EMIT(0x8B); |
| 544 | emit_operand(dst, src); |
| 545 | } |
| 546 | |
| 547 | |
| 548 | void Assembler::mov(Register dst, Register src) { |
| 549 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | EMIT(0x89); |
| 551 | EMIT(0xC0 | src.code() << 3 | dst.code()); |
| 552 | } |
| 553 | |
| 554 | |
| 555 | void Assembler::mov(const Operand& dst, const Immediate& x) { |
| 556 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | EMIT(0xC7); |
| 558 | emit_operand(eax, dst); |
| 559 | emit(x); |
| 560 | } |
| 561 | |
| 562 | |
| 563 | void Assembler::mov(const Operand& dst, Handle<Object> handle) { |
| 564 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 565 | EMIT(0xC7); |
| 566 | emit_operand(eax, dst); |
| 567 | emit(handle); |
| 568 | } |
| 569 | |
| 570 | |
| 571 | void Assembler::mov(const Operand& dst, Register src) { |
| 572 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | EMIT(0x89); |
| 574 | emit_operand(src, dst); |
| 575 | } |
| 576 | |
| 577 | |
| 578 | void Assembler::movsx_b(Register dst, const Operand& src) { |
| 579 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | EMIT(0x0F); |
| 581 | EMIT(0xBE); |
| 582 | emit_operand(dst, src); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | void Assembler::movsx_w(Register dst, const Operand& src) { |
| 587 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 588 | EMIT(0x0F); |
| 589 | EMIT(0xBF); |
| 590 | emit_operand(dst, src); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | void Assembler::movzx_b(Register dst, const Operand& src) { |
| 595 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | EMIT(0x0F); |
| 597 | EMIT(0xB6); |
| 598 | emit_operand(dst, src); |
| 599 | } |
| 600 | |
| 601 | |
| 602 | void Assembler::movzx_w(Register dst, const Operand& src) { |
| 603 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | EMIT(0x0F); |
| 605 | EMIT(0xB7); |
| 606 | emit_operand(dst, src); |
| 607 | } |
| 608 | |
| 609 | |
| 610 | void Assembler::cmov(Condition cc, Register dst, int32_t imm32) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 611 | ASSERT(CpuFeatures::IsEnabled(CMOV)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 612 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 613 | UNIMPLEMENTED(); |
| 614 | USE(cc); |
| 615 | USE(dst); |
| 616 | USE(imm32); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | void Assembler::cmov(Condition cc, Register dst, Handle<Object> handle) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 621 | ASSERT(CpuFeatures::IsEnabled(CMOV)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 622 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 623 | UNIMPLEMENTED(); |
| 624 | USE(cc); |
| 625 | USE(dst); |
| 626 | USE(handle); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | void Assembler::cmov(Condition cc, Register dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 631 | ASSERT(CpuFeatures::IsEnabled(CMOV)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 632 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 633 | // Opcode: 0f 40 + cc /r. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 634 | EMIT(0x0F); |
| 635 | EMIT(0x40 + cc); |
| 636 | emit_operand(dst, src); |
| 637 | } |
| 638 | |
| 639 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 640 | void Assembler::cld() { |
| 641 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 642 | EMIT(0xFC); |
| 643 | } |
| 644 | |
| 645 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 646 | void Assembler::rep_movs() { |
| 647 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 648 | EMIT(0xF3); |
| 649 | EMIT(0xA5); |
| 650 | } |
| 651 | |
| 652 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 653 | void Assembler::rep_stos() { |
| 654 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 655 | EMIT(0xF3); |
| 656 | EMIT(0xAB); |
| 657 | } |
| 658 | |
| 659 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 660 | void Assembler::stos() { |
| 661 | EnsureSpace ensure_space(this); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 662 | EMIT(0xAB); |
| 663 | } |
| 664 | |
| 665 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 666 | void Assembler::xchg(Register dst, Register src) { |
| 667 | EnsureSpace ensure_space(this); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 668 | if (src.is(eax) || dst.is(eax)) { // Single-byte encoding. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 669 | EMIT(0x90 | (src.is(eax) ? dst.code() : src.code())); |
| 670 | } else { |
| 671 | EMIT(0x87); |
| 672 | EMIT(0xC0 | src.code() << 3 | dst.code()); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | |
| 677 | void Assembler::adc(Register dst, int32_t imm32) { |
| 678 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 679 | emit_arith(2, Operand(dst), Immediate(imm32)); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | void Assembler::adc(Register dst, const Operand& src) { |
| 684 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 685 | EMIT(0x13); |
| 686 | emit_operand(dst, src); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | void Assembler::add(Register dst, const Operand& src) { |
| 691 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 692 | EMIT(0x03); |
| 693 | emit_operand(dst, src); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | void Assembler::add(const Operand& dst, const Immediate& x) { |
| 698 | ASSERT(reloc_info_writer.last_pc() != NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 699 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | emit_arith(0, dst, x); |
| 701 | } |
| 702 | |
| 703 | |
| 704 | void Assembler::and_(Register dst, int32_t imm32) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 705 | and_(dst, Immediate(imm32)); |
| 706 | } |
| 707 | |
| 708 | |
| 709 | void Assembler::and_(Register dst, const Immediate& x) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 710 | EnsureSpace ensure_space(this); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 711 | emit_arith(4, Operand(dst), x); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | |
| 715 | void Assembler::and_(Register dst, const Operand& src) { |
| 716 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 717 | EMIT(0x23); |
| 718 | emit_operand(dst, src); |
| 719 | } |
| 720 | |
| 721 | |
| 722 | void Assembler::and_(const Operand& dst, const Immediate& x) { |
| 723 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 724 | emit_arith(4, dst, x); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | void Assembler::and_(const Operand& dst, Register src) { |
| 729 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 730 | EMIT(0x21); |
| 731 | emit_operand(src, dst); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | void Assembler::cmpb(const Operand& op, int8_t imm8) { |
| 736 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 737 | EMIT(0x80); |
| 738 | emit_operand(edi, op); // edi == 7 |
| 739 | EMIT(imm8); |
| 740 | } |
| 741 | |
| 742 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 743 | void Assembler::cmpb(const Operand& dst, Register src) { |
| 744 | ASSERT(src.is_byte_register()); |
| 745 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 746 | EMIT(0x38); |
| 747 | emit_operand(src, dst); |
| 748 | } |
| 749 | |
| 750 | |
| 751 | void Assembler::cmpb(Register dst, const Operand& src) { |
| 752 | ASSERT(dst.is_byte_register()); |
| 753 | EnsureSpace ensure_space(this); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 754 | EMIT(0x3A); |
| 755 | emit_operand(dst, src); |
| 756 | } |
| 757 | |
| 758 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 759 | void Assembler::cmpw(const Operand& op, Immediate imm16) { |
| 760 | ASSERT(imm16.is_int16()); |
| 761 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 762 | EMIT(0x66); |
| 763 | EMIT(0x81); |
| 764 | emit_operand(edi, op); |
| 765 | emit_w(imm16); |
| 766 | } |
| 767 | |
| 768 | |
| 769 | void Assembler::cmp(Register reg, int32_t imm32) { |
| 770 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | emit_arith(7, Operand(reg), Immediate(imm32)); |
| 772 | } |
| 773 | |
| 774 | |
| 775 | void Assembler::cmp(Register reg, Handle<Object> handle) { |
| 776 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | emit_arith(7, Operand(reg), Immediate(handle)); |
| 778 | } |
| 779 | |
| 780 | |
| 781 | void Assembler::cmp(Register reg, const Operand& op) { |
| 782 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 783 | EMIT(0x3B); |
| 784 | emit_operand(reg, op); |
| 785 | } |
| 786 | |
| 787 | |
| 788 | void Assembler::cmp(const Operand& op, const Immediate& imm) { |
| 789 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 790 | emit_arith(7, op, imm); |
| 791 | } |
| 792 | |
| 793 | |
| 794 | void Assembler::cmp(const Operand& op, Handle<Object> handle) { |
| 795 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 796 | emit_arith(7, op, Immediate(handle)); |
| 797 | } |
| 798 | |
| 799 | |
| 800 | void Assembler::cmpb_al(const Operand& op) { |
| 801 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 802 | EMIT(0x38); // CMP r/m8, r8 |
| 803 | emit_operand(eax, op); // eax has same code as register al. |
| 804 | } |
| 805 | |
| 806 | |
| 807 | void Assembler::cmpw_ax(const Operand& op) { |
| 808 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 809 | EMIT(0x66); |
| 810 | EMIT(0x39); // CMP r/m16, r16 |
| 811 | emit_operand(eax, op); // eax has same code as register ax. |
| 812 | } |
| 813 | |
| 814 | |
| 815 | void Assembler::dec_b(Register dst) { |
| 816 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 817 | EMIT(0xFE); |
| 818 | EMIT(0xC8 | dst.code()); |
| 819 | } |
| 820 | |
| 821 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 822 | void Assembler::dec_b(const Operand& dst) { |
| 823 | EnsureSpace ensure_space(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 824 | EMIT(0xFE); |
| 825 | emit_operand(ecx, dst); |
| 826 | } |
| 827 | |
| 828 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 829 | void Assembler::dec(Register dst) { |
| 830 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 831 | EMIT(0x48 | dst.code()); |
| 832 | } |
| 833 | |
| 834 | |
| 835 | void Assembler::dec(const Operand& dst) { |
| 836 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 837 | EMIT(0xFF); |
| 838 | emit_operand(ecx, dst); |
| 839 | } |
| 840 | |
| 841 | |
| 842 | void Assembler::cdq() { |
| 843 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 844 | EMIT(0x99); |
| 845 | } |
| 846 | |
| 847 | |
| 848 | void Assembler::idiv(Register src) { |
| 849 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 850 | EMIT(0xF7); |
| 851 | EMIT(0xF8 | src.code()); |
| 852 | } |
| 853 | |
| 854 | |
| 855 | void Assembler::imul(Register reg) { |
| 856 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 857 | EMIT(0xF7); |
| 858 | EMIT(0xE8 | reg.code()); |
| 859 | } |
| 860 | |
| 861 | |
| 862 | void Assembler::imul(Register dst, const Operand& src) { |
| 863 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 864 | EMIT(0x0F); |
| 865 | EMIT(0xAF); |
| 866 | emit_operand(dst, src); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | void Assembler::imul(Register dst, Register src, int32_t imm32) { |
| 871 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 872 | if (is_int8(imm32)) { |
| 873 | EMIT(0x6B); |
| 874 | EMIT(0xC0 | dst.code() << 3 | src.code()); |
| 875 | EMIT(imm32); |
| 876 | } else { |
| 877 | EMIT(0x69); |
| 878 | EMIT(0xC0 | dst.code() << 3 | src.code()); |
| 879 | emit(imm32); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | |
| 884 | void Assembler::inc(Register dst) { |
| 885 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 886 | EMIT(0x40 | dst.code()); |
| 887 | } |
| 888 | |
| 889 | |
| 890 | void Assembler::inc(const Operand& dst) { |
| 891 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 892 | EMIT(0xFF); |
| 893 | emit_operand(eax, dst); |
| 894 | } |
| 895 | |
| 896 | |
| 897 | void Assembler::lea(Register dst, const Operand& src) { |
| 898 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 899 | EMIT(0x8D); |
| 900 | emit_operand(dst, src); |
| 901 | } |
| 902 | |
| 903 | |
| 904 | void Assembler::mul(Register src) { |
| 905 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 906 | EMIT(0xF7); |
| 907 | EMIT(0xE0 | src.code()); |
| 908 | } |
| 909 | |
| 910 | |
| 911 | void Assembler::neg(Register dst) { |
| 912 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 913 | EMIT(0xF7); |
| 914 | EMIT(0xD8 | dst.code()); |
| 915 | } |
| 916 | |
| 917 | |
| 918 | void Assembler::not_(Register dst) { |
| 919 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 920 | EMIT(0xF7); |
| 921 | EMIT(0xD0 | dst.code()); |
| 922 | } |
| 923 | |
| 924 | |
| 925 | void Assembler::or_(Register dst, int32_t imm32) { |
| 926 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 927 | emit_arith(1, Operand(dst), Immediate(imm32)); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | void Assembler::or_(Register dst, const Operand& src) { |
| 932 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 933 | EMIT(0x0B); |
| 934 | emit_operand(dst, src); |
| 935 | } |
| 936 | |
| 937 | |
| 938 | void Assembler::or_(const Operand& dst, const Immediate& x) { |
| 939 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 940 | emit_arith(1, dst, x); |
| 941 | } |
| 942 | |
| 943 | |
| 944 | void Assembler::or_(const Operand& dst, Register src) { |
| 945 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 946 | EMIT(0x09); |
| 947 | emit_operand(src, dst); |
| 948 | } |
| 949 | |
| 950 | |
| 951 | void Assembler::rcl(Register dst, uint8_t imm8) { |
| 952 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 953 | ASSERT(is_uint5(imm8)); // illegal shift count |
| 954 | if (imm8 == 1) { |
| 955 | EMIT(0xD1); |
| 956 | EMIT(0xD0 | dst.code()); |
| 957 | } else { |
| 958 | EMIT(0xC1); |
| 959 | EMIT(0xD0 | dst.code()); |
| 960 | EMIT(imm8); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 965 | void Assembler::rcr(Register dst, uint8_t imm8) { |
| 966 | EnsureSpace ensure_space(this); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 967 | ASSERT(is_uint5(imm8)); // illegal shift count |
| 968 | if (imm8 == 1) { |
| 969 | EMIT(0xD1); |
| 970 | EMIT(0xD8 | dst.code()); |
| 971 | } else { |
| 972 | EMIT(0xC1); |
| 973 | EMIT(0xD8 | dst.code()); |
| 974 | EMIT(imm8); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 979 | void Assembler::sar(Register dst, uint8_t imm8) { |
| 980 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | ASSERT(is_uint5(imm8)); // illegal shift count |
| 982 | if (imm8 == 1) { |
| 983 | EMIT(0xD1); |
| 984 | EMIT(0xF8 | dst.code()); |
| 985 | } else { |
| 986 | EMIT(0xC1); |
| 987 | EMIT(0xF8 | dst.code()); |
| 988 | EMIT(imm8); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 993 | void Assembler::sar_cl(Register dst) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 994 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 995 | EMIT(0xD3); |
| 996 | EMIT(0xF8 | dst.code()); |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | void Assembler::sbb(Register dst, const Operand& src) { |
| 1001 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1002 | EMIT(0x1B); |
| 1003 | emit_operand(dst, src); |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | void Assembler::shld(Register dst, const Operand& src) { |
| 1008 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1009 | EMIT(0x0F); |
| 1010 | EMIT(0xA5); |
| 1011 | emit_operand(dst, src); |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | void Assembler::shl(Register dst, uint8_t imm8) { |
| 1016 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1017 | ASSERT(is_uint5(imm8)); // illegal shift count |
| 1018 | if (imm8 == 1) { |
| 1019 | EMIT(0xD1); |
| 1020 | EMIT(0xE0 | dst.code()); |
| 1021 | } else { |
| 1022 | EMIT(0xC1); |
| 1023 | EMIT(0xE0 | dst.code()); |
| 1024 | EMIT(imm8); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1029 | void Assembler::shl_cl(Register dst) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1030 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1031 | EMIT(0xD3); |
| 1032 | EMIT(0xE0 | dst.code()); |
| 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | void Assembler::shrd(Register dst, const Operand& src) { |
| 1037 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1038 | EMIT(0x0F); |
| 1039 | EMIT(0xAD); |
| 1040 | emit_operand(dst, src); |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | void Assembler::shr(Register dst, uint8_t imm8) { |
| 1045 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1046 | ASSERT(is_uint5(imm8)); // illegal shift count |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1047 | if (imm8 == 1) { |
| 1048 | EMIT(0xD1); |
| 1049 | EMIT(0xE8 | dst.code()); |
| 1050 | } else { |
| 1051 | EMIT(0xC1); |
| 1052 | EMIT(0xE8 | dst.code()); |
| 1053 | EMIT(imm8); |
| 1054 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | void Assembler::shr_cl(Register dst) { |
| 1059 | EnsureSpace ensure_space(this); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1060 | EMIT(0xD3); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1061 | EMIT(0xE8 | dst.code()); |
| 1062 | } |
| 1063 | |
| 1064 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1065 | void Assembler::subb(const Operand& op, int8_t imm8) { |
| 1066 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1067 | if (op.is_reg(eax)) { |
| 1068 | EMIT(0x2c); |
| 1069 | } else { |
| 1070 | EMIT(0x80); |
| 1071 | emit_operand(ebp, op); // ebp == 5 |
| 1072 | } |
| 1073 | EMIT(imm8); |
| 1074 | } |
| 1075 | |
| 1076 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1077 | void Assembler::sub(const Operand& dst, const Immediate& x) { |
| 1078 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1079 | emit_arith(5, dst, x); |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | void Assembler::sub(Register dst, const Operand& src) { |
| 1084 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1085 | EMIT(0x2B); |
| 1086 | emit_operand(dst, src); |
| 1087 | } |
| 1088 | |
| 1089 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1090 | void Assembler::subb(Register dst, const Operand& src) { |
| 1091 | ASSERT(dst.code() < 4); |
| 1092 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1093 | EMIT(0x2A); |
| 1094 | emit_operand(dst, src); |
| 1095 | } |
| 1096 | |
| 1097 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1098 | void Assembler::sub(const Operand& dst, Register src) { |
| 1099 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1100 | EMIT(0x29); |
| 1101 | emit_operand(src, dst); |
| 1102 | } |
| 1103 | |
| 1104 | |
| 1105 | void Assembler::test(Register reg, const Immediate& imm) { |
| 1106 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1107 | // Only use test against byte for registers that have a byte |
| 1108 | // variant: eax, ebx, ecx, and edx. |
| 1109 | if (imm.rmode_ == RelocInfo::NONE && is_uint8(imm.x_) && reg.code() < 4) { |
| 1110 | uint8_t imm8 = imm.x_; |
| 1111 | if (reg.is(eax)) { |
| 1112 | EMIT(0xA8); |
| 1113 | EMIT(imm8); |
| 1114 | } else { |
| 1115 | emit_arith_b(0xF6, 0xC0, reg, imm8); |
| 1116 | } |
| 1117 | } else { |
| 1118 | // This is not using emit_arith because test doesn't support |
| 1119 | // sign-extension of 8-bit operands. |
| 1120 | if (reg.is(eax)) { |
| 1121 | EMIT(0xA9); |
| 1122 | } else { |
| 1123 | EMIT(0xF7); |
| 1124 | EMIT(0xC0 | reg.code()); |
| 1125 | } |
| 1126 | emit(imm); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | void Assembler::test(Register reg, const Operand& op) { |
| 1132 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1133 | EMIT(0x85); |
| 1134 | emit_operand(reg, op); |
| 1135 | } |
| 1136 | |
| 1137 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1138 | void Assembler::test_b(Register reg, const Operand& op) { |
| 1139 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1140 | EMIT(0x84); |
| 1141 | emit_operand(reg, op); |
| 1142 | } |
| 1143 | |
| 1144 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1145 | void Assembler::test(const Operand& op, const Immediate& imm) { |
| 1146 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1147 | EMIT(0xF7); |
| 1148 | emit_operand(eax, op); |
| 1149 | emit(imm); |
| 1150 | } |
| 1151 | |
| 1152 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1153 | void Assembler::test_b(const Operand& op, uint8_t imm8) { |
| 1154 | EnsureSpace ensure_space(this); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 1155 | EMIT(0xF6); |
| 1156 | emit_operand(eax, op); |
| 1157 | EMIT(imm8); |
| 1158 | } |
| 1159 | |
| 1160 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1161 | void Assembler::xor_(Register dst, int32_t imm32) { |
| 1162 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1163 | emit_arith(6, Operand(dst), Immediate(imm32)); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | void Assembler::xor_(Register dst, const Operand& src) { |
| 1168 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1169 | EMIT(0x33); |
| 1170 | emit_operand(dst, src); |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | void Assembler::xor_(const Operand& src, Register dst) { |
| 1175 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1176 | EMIT(0x31); |
| 1177 | emit_operand(dst, src); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | void Assembler::xor_(const Operand& dst, const Immediate& x) { |
| 1182 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1183 | emit_arith(6, dst, x); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | void Assembler::bt(const Operand& dst, Register src) { |
| 1188 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1189 | EMIT(0x0F); |
| 1190 | EMIT(0xA3); |
| 1191 | emit_operand(src, dst); |
| 1192 | } |
| 1193 | |
| 1194 | |
| 1195 | void Assembler::bts(const Operand& dst, Register src) { |
| 1196 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1197 | EMIT(0x0F); |
| 1198 | EMIT(0xAB); |
| 1199 | emit_operand(src, dst); |
| 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | void Assembler::hlt() { |
| 1204 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1205 | EMIT(0xF4); |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | void Assembler::int3() { |
| 1210 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1211 | EMIT(0xCC); |
| 1212 | } |
| 1213 | |
| 1214 | |
| 1215 | void Assembler::nop() { |
| 1216 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1217 | EMIT(0x90); |
| 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | void Assembler::rdtsc() { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1222 | ASSERT(CpuFeatures::IsEnabled(RDTSC)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1223 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1224 | EMIT(0x0F); |
| 1225 | EMIT(0x31); |
| 1226 | } |
| 1227 | |
| 1228 | |
| 1229 | void Assembler::ret(int imm16) { |
| 1230 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1231 | ASSERT(is_uint16(imm16)); |
| 1232 | if (imm16 == 0) { |
| 1233 | EMIT(0xC3); |
| 1234 | } else { |
| 1235 | EMIT(0xC2); |
| 1236 | EMIT(imm16 & 0xFF); |
| 1237 | EMIT((imm16 >> 8) & 0xFF); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | // Labels refer to positions in the (to be) generated code. |
| 1243 | // There are bound, linked, and unused labels. |
| 1244 | // |
| 1245 | // Bound labels refer to known positions in the already |
| 1246 | // generated code. pos() is the position the label refers to. |
| 1247 | // |
| 1248 | // Linked labels refer to unknown positions in the code |
| 1249 | // to be generated; pos() is the position of the 32bit |
| 1250 | // Displacement of the last instruction using the label. |
| 1251 | |
| 1252 | |
| 1253 | void Assembler::print(Label* L) { |
| 1254 | if (L->is_unused()) { |
| 1255 | PrintF("unused label\n"); |
| 1256 | } else if (L->is_bound()) { |
| 1257 | PrintF("bound label to %d\n", L->pos()); |
| 1258 | } else if (L->is_linked()) { |
| 1259 | Label l = *L; |
| 1260 | PrintF("unbound label"); |
| 1261 | while (l.is_linked()) { |
| 1262 | Displacement disp = disp_at(&l); |
| 1263 | PrintF("@ %d ", l.pos()); |
| 1264 | disp.print(); |
| 1265 | PrintF("\n"); |
| 1266 | disp.next(&l); |
| 1267 | } |
| 1268 | } else { |
| 1269 | PrintF("label in inconsistent state (pos = %d)\n", L->pos_); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | |
| 1274 | void Assembler::bind_to(Label* L, int pos) { |
| 1275 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1276 | ASSERT(0 <= pos && pos <= pc_offset()); // must have a valid binding position |
| 1277 | while (L->is_linked()) { |
| 1278 | Displacement disp = disp_at(L); |
| 1279 | int fixup_pos = L->pos(); |
| 1280 | if (disp.type() == Displacement::CODE_RELATIVE) { |
| 1281 | // Relative to Code* heap object pointer. |
| 1282 | long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag); |
| 1283 | } else { |
| 1284 | if (disp.type() == Displacement::UNCONDITIONAL_JUMP) { |
| 1285 | ASSERT(byte_at(fixup_pos - 1) == 0xE9); // jmp expected |
| 1286 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1287 | // Relative address, relative to point after address. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1288 | int imm32 = pos - (fixup_pos + sizeof(int32_t)); |
| 1289 | long_at_put(fixup_pos, imm32); |
| 1290 | } |
| 1291 | disp.next(L); |
| 1292 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1293 | while (L->is_near_linked()) { |
| 1294 | int fixup_pos = L->near_link_pos(); |
| 1295 | int offset_to_next = |
| 1296 | static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos))); |
| 1297 | ASSERT(offset_to_next <= 0); |
| 1298 | // Relative address, relative to point after address. |
| 1299 | int disp = pos - fixup_pos - sizeof(int8_t); |
| 1300 | ASSERT(0 <= disp && disp <= 127); |
| 1301 | set_byte_at(fixup_pos, disp); |
| 1302 | if (offset_to_next < 0) { |
| 1303 | L->link_to(fixup_pos + offset_to_next, Label::kNear); |
| 1304 | } else { |
| 1305 | L->UnuseNear(); |
| 1306 | } |
| 1307 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1308 | L->bind_to(pos); |
| 1309 | } |
| 1310 | |
| 1311 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1312 | void Assembler::bind(Label* L) { |
| 1313 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1314 | ASSERT(!L->is_bound()); // label can only be bound once |
| 1315 | bind_to(L, pc_offset()); |
| 1316 | } |
| 1317 | |
| 1318 | |
| 1319 | void Assembler::call(Label* L) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1320 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1321 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1322 | if (L->is_bound()) { |
| 1323 | const int long_size = 5; |
| 1324 | int offs = L->pos() - pc_offset(); |
| 1325 | ASSERT(offs <= 0); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1326 | // 1110 1000 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1327 | EMIT(0xE8); |
| 1328 | emit(offs - long_size); |
| 1329 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1330 | // 1110 1000 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1331 | EMIT(0xE8); |
| 1332 | emit_disp(L, Displacement::OTHER); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | void Assembler::call(byte* entry, RelocInfo::Mode rmode) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1338 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1339 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1340 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 1341 | EMIT(0xE8); |
| 1342 | emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1343 | } |
| 1344 | |
| 1345 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1346 | int Assembler::CallSize(const Operand& adr) { |
| 1347 | // Call size is 1 (opcode) + adr.len_ (operand). |
| 1348 | return 1 + adr.len_; |
| 1349 | } |
| 1350 | |
| 1351 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1352 | void Assembler::call(const Operand& adr) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1353 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1354 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1355 | EMIT(0xFF); |
| 1356 | emit_operand(edx, adr); |
| 1357 | } |
| 1358 | |
| 1359 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1360 | int Assembler::CallSize(Handle<Code> code, RelocInfo::Mode rmode) { |
| 1361 | return 1 /* EMIT */ + sizeof(uint32_t) /* emit */; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1365 | void Assembler::call(Handle<Code> code, |
| 1366 | RelocInfo::Mode rmode, |
| 1367 | unsigned ast_id) { |
| 1368 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1369 | EnsureSpace ensure_space(this); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1370 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 1371 | EMIT(0xE8); |
| 1372 | emit(reinterpret_cast<intptr_t>(code.location()), rmode, ast_id); |
| 1373 | } |
| 1374 | |
| 1375 | |
| 1376 | void Assembler::jmp(Label* L, Label::Distance distance) { |
| 1377 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1378 | if (L->is_bound()) { |
| 1379 | const int short_size = 2; |
| 1380 | const int long_size = 5; |
| 1381 | int offs = L->pos() - pc_offset(); |
| 1382 | ASSERT(offs <= 0); |
| 1383 | if (is_int8(offs - short_size)) { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1384 | // 1110 1011 #8-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1385 | EMIT(0xEB); |
| 1386 | EMIT((offs - short_size) & 0xFF); |
| 1387 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1388 | // 1110 1001 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1389 | EMIT(0xE9); |
| 1390 | emit(offs - long_size); |
| 1391 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1392 | } else if (distance == Label::kNear) { |
| 1393 | EMIT(0xEB); |
| 1394 | emit_near_disp(L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1395 | } else { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1396 | // 1110 1001 #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1397 | EMIT(0xE9); |
| 1398 | emit_disp(L, Displacement::UNCONDITIONAL_JUMP); |
| 1399 | } |
| 1400 | } |
| 1401 | |
| 1402 | |
| 1403 | void Assembler::jmp(byte* entry, RelocInfo::Mode rmode) { |
| 1404 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1405 | ASSERT(!RelocInfo::IsCodeTarget(rmode)); |
| 1406 | EMIT(0xE9); |
| 1407 | emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | void Assembler::jmp(const Operand& adr) { |
| 1412 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1413 | EMIT(0xFF); |
| 1414 | emit_operand(esp, adr); |
| 1415 | } |
| 1416 | |
| 1417 | |
| 1418 | void Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) { |
| 1419 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1420 | ASSERT(RelocInfo::IsCodeTarget(rmode)); |
| 1421 | EMIT(0xE9); |
| 1422 | emit(reinterpret_cast<intptr_t>(code.location()), rmode); |
| 1423 | } |
| 1424 | |
| 1425 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1426 | void Assembler::j(Condition cc, Label* L, Label::Distance distance) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1427 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1428 | ASSERT(0 <= cc && cc < 16); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1429 | if (L->is_bound()) { |
| 1430 | const int short_size = 2; |
| 1431 | const int long_size = 6; |
| 1432 | int offs = L->pos() - pc_offset(); |
| 1433 | ASSERT(offs <= 0); |
| 1434 | if (is_int8(offs - short_size)) { |
| 1435 | // 0111 tttn #8-bit disp |
| 1436 | EMIT(0x70 | cc); |
| 1437 | EMIT((offs - short_size) & 0xFF); |
| 1438 | } else { |
| 1439 | // 0000 1111 1000 tttn #32-bit disp |
| 1440 | EMIT(0x0F); |
| 1441 | EMIT(0x80 | cc); |
| 1442 | emit(offs - long_size); |
| 1443 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1444 | } else if (distance == Label::kNear) { |
| 1445 | EMIT(0x70 | cc); |
| 1446 | emit_near_disp(L); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1447 | } else { |
| 1448 | // 0000 1111 1000 tttn #32-bit disp |
| 1449 | // Note: could eliminate cond. jumps to this jump if condition |
| 1450 | // is the same however, seems to be rather unlikely case. |
| 1451 | EMIT(0x0F); |
| 1452 | EMIT(0x80 | cc); |
| 1453 | emit_disp(L, Displacement::OTHER); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1458 | void Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1459 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1460 | ASSERT((0 <= cc) && (cc < 16)); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1461 | // 0000 1111 1000 tttn #32-bit disp. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1462 | EMIT(0x0F); |
| 1463 | EMIT(0x80 | cc); |
| 1464 | emit(entry - (pc_ + sizeof(int32_t)), rmode); |
| 1465 | } |
| 1466 | |
| 1467 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1468 | void Assembler::j(Condition cc, Handle<Code> code) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1469 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1470 | // 0000 1111 1000 tttn #32-bit disp |
| 1471 | EMIT(0x0F); |
| 1472 | EMIT(0x80 | cc); |
| 1473 | emit(reinterpret_cast<intptr_t>(code.location()), RelocInfo::CODE_TARGET); |
| 1474 | } |
| 1475 | |
| 1476 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 1477 | // FPU instructions. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1478 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1479 | void Assembler::fld(int i) { |
| 1480 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1481 | emit_farith(0xD9, 0xC0, i); |
| 1482 | } |
| 1483 | |
| 1484 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1485 | void Assembler::fstp(int i) { |
| 1486 | EnsureSpace ensure_space(this); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1487 | emit_farith(0xDD, 0xD8, i); |
| 1488 | } |
| 1489 | |
| 1490 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1491 | void Assembler::fld1() { |
| 1492 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1493 | EMIT(0xD9); |
| 1494 | EMIT(0xE8); |
| 1495 | } |
| 1496 | |
| 1497 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1498 | void Assembler::fldpi() { |
| 1499 | EnsureSpace ensure_space(this); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1500 | EMIT(0xD9); |
| 1501 | EMIT(0xEB); |
| 1502 | } |
| 1503 | |
| 1504 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1505 | void Assembler::fldz() { |
| 1506 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1507 | EMIT(0xD9); |
| 1508 | EMIT(0xEE); |
| 1509 | } |
| 1510 | |
| 1511 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1512 | void Assembler::fldln2() { |
| 1513 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1514 | EMIT(0xD9); |
| 1515 | EMIT(0xED); |
| 1516 | } |
| 1517 | |
| 1518 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1519 | void Assembler::fld_s(const Operand& adr) { |
| 1520 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1521 | EMIT(0xD9); |
| 1522 | emit_operand(eax, adr); |
| 1523 | } |
| 1524 | |
| 1525 | |
| 1526 | void Assembler::fld_d(const Operand& adr) { |
| 1527 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1528 | EMIT(0xDD); |
| 1529 | emit_operand(eax, adr); |
| 1530 | } |
| 1531 | |
| 1532 | |
| 1533 | void Assembler::fstp_s(const Operand& adr) { |
| 1534 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1535 | EMIT(0xD9); |
| 1536 | emit_operand(ebx, adr); |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | void Assembler::fstp_d(const Operand& adr) { |
| 1541 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1542 | EMIT(0xDD); |
| 1543 | emit_operand(ebx, adr); |
| 1544 | } |
| 1545 | |
| 1546 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1547 | void Assembler::fst_d(const Operand& adr) { |
| 1548 | EnsureSpace ensure_space(this); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1549 | EMIT(0xDD); |
| 1550 | emit_operand(edx, adr); |
| 1551 | } |
| 1552 | |
| 1553 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1554 | void Assembler::fild_s(const Operand& adr) { |
| 1555 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1556 | EMIT(0xDB); |
| 1557 | emit_operand(eax, adr); |
| 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | void Assembler::fild_d(const Operand& adr) { |
| 1562 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1563 | EMIT(0xDF); |
| 1564 | emit_operand(ebp, adr); |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | void Assembler::fistp_s(const Operand& adr) { |
| 1569 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1570 | EMIT(0xDB); |
| 1571 | emit_operand(ebx, adr); |
| 1572 | } |
| 1573 | |
| 1574 | |
| 1575 | void Assembler::fisttp_s(const Operand& adr) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1576 | ASSERT(CpuFeatures::IsEnabled(SSE3)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1577 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1578 | EMIT(0xDB); |
| 1579 | emit_operand(ecx, adr); |
| 1580 | } |
| 1581 | |
| 1582 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1583 | void Assembler::fisttp_d(const Operand& adr) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1584 | ASSERT(CpuFeatures::IsEnabled(SSE3)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1585 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1586 | EMIT(0xDD); |
| 1587 | emit_operand(ecx, adr); |
| 1588 | } |
| 1589 | |
| 1590 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1591 | void Assembler::fist_s(const Operand& adr) { |
| 1592 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1593 | EMIT(0xDB); |
| 1594 | emit_operand(edx, adr); |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | void Assembler::fistp_d(const Operand& adr) { |
| 1599 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1600 | EMIT(0xDF); |
| 1601 | emit_operand(edi, adr); |
| 1602 | } |
| 1603 | |
| 1604 | |
| 1605 | void Assembler::fabs() { |
| 1606 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1607 | EMIT(0xD9); |
| 1608 | EMIT(0xE1); |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | void Assembler::fchs() { |
| 1613 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1614 | EMIT(0xD9); |
| 1615 | EMIT(0xE0); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | void Assembler::fcos() { |
| 1620 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1621 | EMIT(0xD9); |
| 1622 | EMIT(0xFF); |
| 1623 | } |
| 1624 | |
| 1625 | |
| 1626 | void Assembler::fsin() { |
| 1627 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1628 | EMIT(0xD9); |
| 1629 | EMIT(0xFE); |
| 1630 | } |
| 1631 | |
| 1632 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1633 | void Assembler::fyl2x() { |
| 1634 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1635 | EMIT(0xD9); |
| 1636 | EMIT(0xF1); |
| 1637 | } |
| 1638 | |
| 1639 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1640 | void Assembler::fadd(int i) { |
| 1641 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1642 | emit_farith(0xDC, 0xC0, i); |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | void Assembler::fsub(int i) { |
| 1647 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1648 | emit_farith(0xDC, 0xE8, i); |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | void Assembler::fisub_s(const Operand& adr) { |
| 1653 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1654 | EMIT(0xDA); |
| 1655 | emit_operand(esp, adr); |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | void Assembler::fmul(int i) { |
| 1660 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1661 | emit_farith(0xDC, 0xC8, i); |
| 1662 | } |
| 1663 | |
| 1664 | |
| 1665 | void Assembler::fdiv(int i) { |
| 1666 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1667 | emit_farith(0xDC, 0xF8, i); |
| 1668 | } |
| 1669 | |
| 1670 | |
| 1671 | void Assembler::faddp(int i) { |
| 1672 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1673 | emit_farith(0xDE, 0xC0, i); |
| 1674 | } |
| 1675 | |
| 1676 | |
| 1677 | void Assembler::fsubp(int i) { |
| 1678 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1679 | emit_farith(0xDE, 0xE8, i); |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | void Assembler::fsubrp(int i) { |
| 1684 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1685 | emit_farith(0xDE, 0xE0, i); |
| 1686 | } |
| 1687 | |
| 1688 | |
| 1689 | void Assembler::fmulp(int i) { |
| 1690 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1691 | emit_farith(0xDE, 0xC8, i); |
| 1692 | } |
| 1693 | |
| 1694 | |
| 1695 | void Assembler::fdivp(int i) { |
| 1696 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1697 | emit_farith(0xDE, 0xF8, i); |
| 1698 | } |
| 1699 | |
| 1700 | |
| 1701 | void Assembler::fprem() { |
| 1702 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1703 | EMIT(0xD9); |
| 1704 | EMIT(0xF8); |
| 1705 | } |
| 1706 | |
| 1707 | |
| 1708 | void Assembler::fprem1() { |
| 1709 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1710 | EMIT(0xD9); |
| 1711 | EMIT(0xF5); |
| 1712 | } |
| 1713 | |
| 1714 | |
| 1715 | void Assembler::fxch(int i) { |
| 1716 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1717 | emit_farith(0xD9, 0xC8, i); |
| 1718 | } |
| 1719 | |
| 1720 | |
| 1721 | void Assembler::fincstp() { |
| 1722 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1723 | EMIT(0xD9); |
| 1724 | EMIT(0xF7); |
| 1725 | } |
| 1726 | |
| 1727 | |
| 1728 | void Assembler::ffree(int i) { |
| 1729 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1730 | emit_farith(0xDD, 0xC0, i); |
| 1731 | } |
| 1732 | |
| 1733 | |
| 1734 | void Assembler::ftst() { |
| 1735 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1736 | EMIT(0xD9); |
| 1737 | EMIT(0xE4); |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | void Assembler::fucomp(int i) { |
| 1742 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1743 | emit_farith(0xDD, 0xE8, i); |
| 1744 | } |
| 1745 | |
| 1746 | |
| 1747 | void Assembler::fucompp() { |
| 1748 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1749 | EMIT(0xDA); |
| 1750 | EMIT(0xE9); |
| 1751 | } |
| 1752 | |
| 1753 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1754 | void Assembler::fucomi(int i) { |
| 1755 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1756 | EMIT(0xDB); |
| 1757 | EMIT(0xE8 + i); |
| 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | void Assembler::fucomip() { |
| 1762 | EnsureSpace ensure_space(this); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1763 | EMIT(0xDF); |
| 1764 | EMIT(0xE9); |
| 1765 | } |
| 1766 | |
| 1767 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1768 | void Assembler::fcompp() { |
| 1769 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1770 | EMIT(0xDE); |
| 1771 | EMIT(0xD9); |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | void Assembler::fnstsw_ax() { |
| 1776 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1777 | EMIT(0xDF); |
| 1778 | EMIT(0xE0); |
| 1779 | } |
| 1780 | |
| 1781 | |
| 1782 | void Assembler::fwait() { |
| 1783 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1784 | EMIT(0x9B); |
| 1785 | } |
| 1786 | |
| 1787 | |
| 1788 | void Assembler::frndint() { |
| 1789 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1790 | EMIT(0xD9); |
| 1791 | EMIT(0xFC); |
| 1792 | } |
| 1793 | |
| 1794 | |
| 1795 | void Assembler::fnclex() { |
| 1796 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1797 | EMIT(0xDB); |
| 1798 | EMIT(0xE2); |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | void Assembler::sahf() { |
| 1803 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1804 | EMIT(0x9E); |
| 1805 | } |
| 1806 | |
| 1807 | |
| 1808 | void Assembler::setcc(Condition cc, Register reg) { |
| 1809 | ASSERT(reg.is_byte_register()); |
| 1810 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1811 | EMIT(0x0F); |
| 1812 | EMIT(0x90 | cc); |
| 1813 | EMIT(0xC0 | reg.code()); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | void Assembler::cvttss2si(Register dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1818 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1819 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1820 | EMIT(0xF3); |
| 1821 | EMIT(0x0F); |
| 1822 | EMIT(0x2C); |
| 1823 | emit_operand(dst, src); |
| 1824 | } |
| 1825 | |
| 1826 | |
| 1827 | void Assembler::cvttsd2si(Register dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1828 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1829 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1830 | EMIT(0xF2); |
| 1831 | EMIT(0x0F); |
| 1832 | EMIT(0x2C); |
| 1833 | emit_operand(dst, src); |
| 1834 | } |
| 1835 | |
| 1836 | |
| 1837 | void Assembler::cvtsi2sd(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1838 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1839 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1840 | EMIT(0xF2); |
| 1841 | EMIT(0x0F); |
| 1842 | EMIT(0x2A); |
| 1843 | emit_sse_operand(dst, src); |
| 1844 | } |
| 1845 | |
| 1846 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1847 | void Assembler::cvtss2sd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1848 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1849 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1850 | EMIT(0xF3); |
| 1851 | EMIT(0x0F); |
| 1852 | EMIT(0x5A); |
| 1853 | emit_sse_operand(dst, src); |
| 1854 | } |
| 1855 | |
| 1856 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1857 | void Assembler::cvtsd2ss(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1858 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1859 | EnsureSpace ensure_space(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1860 | EMIT(0xF2); |
| 1861 | EMIT(0x0F); |
| 1862 | EMIT(0x5A); |
| 1863 | emit_sse_operand(dst, src); |
| 1864 | } |
| 1865 | |
| 1866 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1867 | void Assembler::addsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1868 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1869 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1870 | EMIT(0xF2); |
| 1871 | EMIT(0x0F); |
| 1872 | EMIT(0x58); |
| 1873 | emit_sse_operand(dst, src); |
| 1874 | } |
| 1875 | |
| 1876 | |
| 1877 | void Assembler::mulsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1878 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1879 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1880 | EMIT(0xF2); |
| 1881 | EMIT(0x0F); |
| 1882 | EMIT(0x59); |
| 1883 | emit_sse_operand(dst, src); |
| 1884 | } |
| 1885 | |
| 1886 | |
| 1887 | void Assembler::subsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1888 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1889 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1890 | EMIT(0xF2); |
| 1891 | EMIT(0x0F); |
| 1892 | EMIT(0x5C); |
| 1893 | emit_sse_operand(dst, src); |
| 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | void Assembler::divsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1898 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1899 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1900 | EMIT(0xF2); |
| 1901 | EMIT(0x0F); |
| 1902 | EMIT(0x5E); |
| 1903 | emit_sse_operand(dst, src); |
| 1904 | } |
| 1905 | |
| 1906 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1907 | void Assembler::xorpd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1908 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1909 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1910 | EMIT(0x66); |
| 1911 | EMIT(0x0F); |
| 1912 | EMIT(0x57); |
| 1913 | emit_sse_operand(dst, src); |
| 1914 | } |
| 1915 | |
| 1916 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame^] | 1917 | void Assembler::xorps(XMMRegister dst, XMMRegister src) { |
| 1918 | EnsureSpace ensure_space(this); |
| 1919 | EMIT(0x0F); |
| 1920 | EMIT(0x57); |
| 1921 | emit_sse_operand(dst, src); |
| 1922 | } |
| 1923 | |
| 1924 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1925 | void Assembler::sqrtsd(XMMRegister dst, XMMRegister src) { |
| 1926 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1927 | EMIT(0xF2); |
| 1928 | EMIT(0x0F); |
| 1929 | EMIT(0x51); |
| 1930 | emit_sse_operand(dst, src); |
| 1931 | } |
| 1932 | |
| 1933 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1934 | void Assembler::andpd(XMMRegister dst, XMMRegister src) { |
| 1935 | EnsureSpace ensure_space(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1936 | EMIT(0x66); |
| 1937 | EMIT(0x0F); |
| 1938 | EMIT(0x54); |
| 1939 | emit_sse_operand(dst, src); |
| 1940 | } |
| 1941 | |
| 1942 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1943 | void Assembler::ucomisd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1944 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1945 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1946 | EMIT(0x66); |
| 1947 | EMIT(0x0F); |
| 1948 | EMIT(0x2E); |
| 1949 | emit_sse_operand(dst, src); |
| 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | void Assembler::movmskpd(Register dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1954 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1955 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1956 | EMIT(0x66); |
| 1957 | EMIT(0x0F); |
| 1958 | EMIT(0x50); |
| 1959 | emit_sse_operand(dst, src); |
| 1960 | } |
| 1961 | |
| 1962 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1963 | void Assembler::cmpltsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1964 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1965 | EnsureSpace ensure_space(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1966 | EMIT(0xF2); |
| 1967 | EMIT(0x0F); |
| 1968 | EMIT(0xC2); |
| 1969 | emit_sse_operand(dst, src); |
| 1970 | EMIT(1); // LT == 1 |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | void Assembler::movaps(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1975 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1976 | EnsureSpace ensure_space(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1977 | EMIT(0x0F); |
| 1978 | EMIT(0x28); |
| 1979 | emit_sse_operand(dst, src); |
| 1980 | } |
| 1981 | |
| 1982 | |
| 1983 | void Assembler::movdqa(const Operand& dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1984 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1985 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1986 | EMIT(0x66); |
| 1987 | EMIT(0x0F); |
| 1988 | EMIT(0x7F); |
| 1989 | emit_sse_operand(src, dst); |
| 1990 | } |
| 1991 | |
| 1992 | |
| 1993 | void Assembler::movdqa(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1994 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1995 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1996 | EMIT(0x66); |
| 1997 | EMIT(0x0F); |
| 1998 | EMIT(0x6F); |
| 1999 | emit_sse_operand(dst, src); |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | void Assembler::movdqu(const Operand& dst, XMMRegister src ) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2004 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2005 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2006 | EMIT(0xF3); |
| 2007 | EMIT(0x0F); |
| 2008 | EMIT(0x7F); |
| 2009 | emit_sse_operand(src, dst); |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | void Assembler::movdqu(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2014 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2015 | EnsureSpace ensure_space(this); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2016 | EMIT(0xF3); |
| 2017 | EMIT(0x0F); |
| 2018 | EMIT(0x6F); |
| 2019 | emit_sse_operand(dst, src); |
| 2020 | } |
| 2021 | |
| 2022 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2023 | void Assembler::movntdqa(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2024 | ASSERT(CpuFeatures::IsEnabled(SSE4_1)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2025 | EnsureSpace ensure_space(this); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2026 | EMIT(0x66); |
| 2027 | EMIT(0x0F); |
| 2028 | EMIT(0x38); |
| 2029 | EMIT(0x2A); |
| 2030 | emit_sse_operand(dst, src); |
| 2031 | } |
| 2032 | |
| 2033 | |
| 2034 | void Assembler::movntdq(const Operand& dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2035 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2036 | EnsureSpace ensure_space(this); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2037 | EMIT(0x66); |
| 2038 | EMIT(0x0F); |
| 2039 | EMIT(0xE7); |
| 2040 | emit_sse_operand(src, dst); |
| 2041 | } |
| 2042 | |
| 2043 | |
| 2044 | void Assembler::prefetch(const Operand& src, int level) { |
| 2045 | ASSERT(is_uint2(level)); |
| 2046 | EnsureSpace ensure_space(this); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2047 | EMIT(0x0F); |
| 2048 | EMIT(0x18); |
| 2049 | XMMRegister code = { level }; // Emit hint number in Reg position of RegR/M. |
| 2050 | emit_sse_operand(code, src); |
| 2051 | } |
| 2052 | |
| 2053 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2054 | void Assembler::movdbl(XMMRegister dst, const Operand& src) { |
| 2055 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2056 | movsd(dst, src); |
| 2057 | } |
| 2058 | |
| 2059 | |
| 2060 | void Assembler::movdbl(const Operand& dst, XMMRegister src) { |
| 2061 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2062 | movsd(dst, src); |
| 2063 | } |
| 2064 | |
| 2065 | |
| 2066 | void Assembler::movsd(const Operand& dst, XMMRegister src ) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2067 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2068 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2069 | EMIT(0xF2); // double |
| 2070 | EMIT(0x0F); |
| 2071 | EMIT(0x11); // store |
| 2072 | emit_sse_operand(src, dst); |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | void Assembler::movsd(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2077 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2078 | EnsureSpace ensure_space(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2079 | EMIT(0xF2); // double |
| 2080 | EMIT(0x0F); |
| 2081 | EMIT(0x10); // load |
| 2082 | emit_sse_operand(dst, src); |
| 2083 | } |
| 2084 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2085 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2086 | void Assembler::movsd(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2087 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2088 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2089 | EMIT(0xF2); |
| 2090 | EMIT(0x0F); |
| 2091 | EMIT(0x10); |
| 2092 | emit_sse_operand(dst, src); |
| 2093 | } |
| 2094 | |
| 2095 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2096 | void Assembler::movss(const Operand& dst, XMMRegister src ) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2097 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2098 | EnsureSpace ensure_space(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2099 | EMIT(0xF3); // float |
| 2100 | EMIT(0x0F); |
| 2101 | EMIT(0x11); // store |
| 2102 | emit_sse_operand(src, dst); |
| 2103 | } |
| 2104 | |
| 2105 | |
| 2106 | void Assembler::movss(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2107 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2108 | EnsureSpace ensure_space(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2109 | EMIT(0xF3); // float |
| 2110 | EMIT(0x0F); |
| 2111 | EMIT(0x10); // load |
| 2112 | emit_sse_operand(dst, src); |
| 2113 | } |
| 2114 | |
| 2115 | |
| 2116 | void Assembler::movss(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2117 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2118 | EnsureSpace ensure_space(this); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2119 | EMIT(0xF3); |
| 2120 | EMIT(0x0F); |
| 2121 | EMIT(0x10); |
| 2122 | emit_sse_operand(dst, src); |
| 2123 | } |
| 2124 | |
| 2125 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2126 | void Assembler::movd(XMMRegister dst, const Operand& src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2127 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2128 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2129 | EMIT(0x66); |
| 2130 | EMIT(0x0F); |
| 2131 | EMIT(0x6E); |
| 2132 | emit_sse_operand(dst, src); |
| 2133 | } |
| 2134 | |
| 2135 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2136 | void Assembler::movd(const Operand& dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2137 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2138 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2139 | EMIT(0x66); |
| 2140 | EMIT(0x0F); |
| 2141 | EMIT(0x7E); |
| 2142 | emit_sse_operand(src, dst); |
| 2143 | } |
| 2144 | |
| 2145 | |
| 2146 | void Assembler::pand(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2147 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2148 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2149 | EMIT(0x66); |
| 2150 | EMIT(0x0F); |
| 2151 | EMIT(0xDB); |
| 2152 | emit_sse_operand(dst, src); |
| 2153 | } |
| 2154 | |
| 2155 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2156 | void Assembler::pxor(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2157 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2158 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2159 | EMIT(0x66); |
| 2160 | EMIT(0x0F); |
| 2161 | EMIT(0xEF); |
| 2162 | emit_sse_operand(dst, src); |
| 2163 | } |
| 2164 | |
| 2165 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2166 | void Assembler::por(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2167 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2168 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2169 | EMIT(0x66); |
| 2170 | EMIT(0x0F); |
| 2171 | EMIT(0xEB); |
| 2172 | emit_sse_operand(dst, src); |
| 2173 | } |
| 2174 | |
| 2175 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2176 | void Assembler::ptest(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2177 | ASSERT(CpuFeatures::IsEnabled(SSE4_1)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2178 | EnsureSpace ensure_space(this); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2179 | EMIT(0x66); |
| 2180 | EMIT(0x0F); |
| 2181 | EMIT(0x38); |
| 2182 | EMIT(0x17); |
| 2183 | emit_sse_operand(dst, src); |
| 2184 | } |
| 2185 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2186 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2187 | void Assembler::psllq(XMMRegister reg, int8_t shift) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2188 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2189 | EnsureSpace ensure_space(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2190 | EMIT(0x66); |
| 2191 | EMIT(0x0F); |
| 2192 | EMIT(0x73); |
| 2193 | emit_sse_operand(esi, reg); // esi == 6 |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2194 | EMIT(shift); |
| 2195 | } |
| 2196 | |
| 2197 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2198 | void Assembler::psllq(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2199 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2200 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2201 | EMIT(0x66); |
| 2202 | EMIT(0x0F); |
| 2203 | EMIT(0xF3); |
| 2204 | emit_sse_operand(dst, src); |
| 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | void Assembler::psrlq(XMMRegister reg, int8_t shift) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2209 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2210 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2211 | EMIT(0x66); |
| 2212 | EMIT(0x0F); |
| 2213 | EMIT(0x73); |
| 2214 | emit_sse_operand(edx, reg); // edx == 2 |
| 2215 | EMIT(shift); |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | void Assembler::psrlq(XMMRegister dst, XMMRegister src) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2220 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2221 | EnsureSpace ensure_space(this); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 2222 | EMIT(0x66); |
| 2223 | EMIT(0x0F); |
| 2224 | EMIT(0xD3); |
| 2225 | emit_sse_operand(dst, src); |
| 2226 | } |
| 2227 | |
| 2228 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2229 | void Assembler::pshufd(XMMRegister dst, XMMRegister src, int8_t shuffle) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2230 | ASSERT(CpuFeatures::IsEnabled(SSE2)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2231 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2232 | EMIT(0x66); |
| 2233 | EMIT(0x0F); |
| 2234 | EMIT(0x70); |
| 2235 | emit_sse_operand(dst, src); |
| 2236 | EMIT(shuffle); |
| 2237 | } |
| 2238 | |
| 2239 | |
| 2240 | void Assembler::pextrd(const Operand& dst, XMMRegister src, int8_t offset) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2241 | ASSERT(CpuFeatures::IsEnabled(SSE4_1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2242 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2243 | EMIT(0x66); |
| 2244 | EMIT(0x0F); |
| 2245 | EMIT(0x3A); |
| 2246 | EMIT(0x16); |
| 2247 | emit_sse_operand(src, dst); |
| 2248 | EMIT(offset); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2252 | void Assembler::pinsrd(XMMRegister dst, const Operand& src, int8_t offset) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2253 | ASSERT(CpuFeatures::IsEnabled(SSE4_1)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2254 | EnsureSpace ensure_space(this); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2255 | EMIT(0x66); |
| 2256 | EMIT(0x0F); |
| 2257 | EMIT(0x3A); |
| 2258 | EMIT(0x22); |
| 2259 | emit_sse_operand(dst, src); |
| 2260 | EMIT(offset); |
| 2261 | } |
| 2262 | |
| 2263 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2264 | void Assembler::emit_sse_operand(XMMRegister reg, const Operand& adr) { |
| 2265 | Register ireg = { reg.code() }; |
| 2266 | emit_operand(ireg, adr); |
| 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) { |
| 2271 | EMIT(0xC0 | dst.code() << 3 | src.code()); |
| 2272 | } |
| 2273 | |
| 2274 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 2275 | void Assembler::emit_sse_operand(Register dst, XMMRegister src) { |
| 2276 | EMIT(0xC0 | dst.code() << 3 | src.code()); |
| 2277 | } |
| 2278 | |
| 2279 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2280 | void Assembler::Print() { |
| 2281 | Disassembler::Decode(stdout, buffer_, pc_); |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | void Assembler::RecordJSReturn() { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2286 | positions_recorder()->WriteRecordedPositions(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2287 | EnsureSpace ensure_space(this); |
| 2288 | RecordRelocInfo(RelocInfo::JS_RETURN); |
| 2289 | } |
| 2290 | |
| 2291 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2292 | void Assembler::RecordDebugBreakSlot() { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2293 | positions_recorder()->WriteRecordedPositions(); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2294 | EnsureSpace ensure_space(this); |
| 2295 | RecordRelocInfo(RelocInfo::DEBUG_BREAK_SLOT); |
| 2296 | } |
| 2297 | |
| 2298 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2299 | void Assembler::RecordComment(const char* msg, bool force) { |
| 2300 | if (FLAG_code_comments || force) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2301 | EnsureSpace ensure_space(this); |
| 2302 | RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); |
| 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2307 | void Assembler::GrowBuffer() { |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2308 | ASSERT(overflow()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2309 | if (!own_buffer_) FATAL("external code buffer is too small"); |
| 2310 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2311 | // Compute new buffer size. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2312 | CodeDesc desc; // the new buffer |
| 2313 | if (buffer_size_ < 4*KB) { |
| 2314 | desc.buffer_size = 4*KB; |
| 2315 | } else { |
| 2316 | desc.buffer_size = 2*buffer_size_; |
| 2317 | } |
| 2318 | // Some internal data structures overflow for very large buffers, |
| 2319 | // they must ensure that kMaximalBufferSize is not too large. |
| 2320 | if ((desc.buffer_size > kMaximalBufferSize) || |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2321 | (desc.buffer_size > isolate()->heap()->MaxOldGenerationSize())) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2322 | V8::FatalProcessOutOfMemory("Assembler::GrowBuffer"); |
| 2323 | } |
| 2324 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2325 | // Setup new buffer. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2326 | desc.buffer = NewArray<byte>(desc.buffer_size); |
| 2327 | desc.instr_size = pc_offset(); |
| 2328 | desc.reloc_size = (buffer_ + buffer_size_) - (reloc_info_writer.pos()); |
| 2329 | |
| 2330 | // Clear the buffer in debug mode. Use 'int3' instructions to make |
| 2331 | // sure to get into problems if we ever run uninitialized code. |
| 2332 | #ifdef DEBUG |
| 2333 | memset(desc.buffer, 0xCC, desc.buffer_size); |
| 2334 | #endif |
| 2335 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2336 | // Copy the data. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2337 | int pc_delta = desc.buffer - buffer_; |
| 2338 | int rc_delta = (desc.buffer + desc.buffer_size) - (buffer_ + buffer_size_); |
| 2339 | memmove(desc.buffer, buffer_, desc.instr_size); |
| 2340 | memmove(rc_delta + reloc_info_writer.pos(), |
| 2341 | reloc_info_writer.pos(), desc.reloc_size); |
| 2342 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2343 | // Switch buffers. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2344 | if (isolate()->assembler_spare_buffer() == NULL && |
| 2345 | buffer_size_ == kMinimalBufferSize) { |
| 2346 | isolate()->set_assembler_spare_buffer(buffer_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2347 | } else { |
| 2348 | DeleteArray(buffer_); |
| 2349 | } |
| 2350 | buffer_ = desc.buffer; |
| 2351 | buffer_size_ = desc.buffer_size; |
| 2352 | pc_ += pc_delta; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2353 | reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, |
| 2354 | reloc_info_writer.last_pc() + pc_delta); |
| 2355 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 2356 | // Relocate runtime entries. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2357 | for (RelocIterator it(desc); !it.done(); it.next()) { |
| 2358 | RelocInfo::Mode rmode = it.rinfo()->rmode(); |
| 2359 | if (rmode == RelocInfo::RUNTIME_ENTRY) { |
| 2360 | int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); |
| 2361 | *p -= pc_delta; // relocate entry |
| 2362 | } else if (rmode == RelocInfo::INTERNAL_REFERENCE) { |
| 2363 | int32_t* p = reinterpret_cast<int32_t*>(it.rinfo()->pc()); |
| 2364 | if (*p != 0) { // 0 means uninitialized. |
| 2365 | *p += pc_delta; |
| 2366 | } |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | ASSERT(!overflow()); |
| 2371 | } |
| 2372 | |
| 2373 | |
| 2374 | void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) { |
| 2375 | ASSERT(is_uint8(op1) && is_uint8(op2)); // wrong opcode |
| 2376 | ASSERT(is_uint8(imm8)); |
| 2377 | ASSERT((op1 & 0x01) == 0); // should be 8bit operation |
| 2378 | EMIT(op1); |
| 2379 | EMIT(op2 | dst.code()); |
| 2380 | EMIT(imm8); |
| 2381 | } |
| 2382 | |
| 2383 | |
| 2384 | void Assembler::emit_arith(int sel, Operand dst, const Immediate& x) { |
| 2385 | ASSERT((0 <= sel) && (sel <= 7)); |
| 2386 | Register ireg = { sel }; |
| 2387 | if (x.is_int8()) { |
| 2388 | EMIT(0x83); // using a sign-extended 8-bit immediate. |
| 2389 | emit_operand(ireg, dst); |
| 2390 | EMIT(x.x_ & 0xFF); |
| 2391 | } else if (dst.is_reg(eax)) { |
| 2392 | EMIT((sel << 3) | 0x05); // short form if the destination is eax. |
| 2393 | emit(x); |
| 2394 | } else { |
| 2395 | EMIT(0x81); // using a literal 32-bit immediate. |
| 2396 | emit_operand(ireg, dst); |
| 2397 | emit(x); |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | void Assembler::emit_operand(Register reg, const Operand& adr) { |
| 2403 | const unsigned length = adr.len_; |
| 2404 | ASSERT(length > 0); |
| 2405 | |
| 2406 | // Emit updated ModRM byte containing the given register. |
| 2407 | pc_[0] = (adr.buf_[0] & ~0x38) | (reg.code() << 3); |
| 2408 | |
| 2409 | // Emit the rest of the encoded operand. |
| 2410 | for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
| 2411 | pc_ += length; |
| 2412 | |
| 2413 | // Emit relocation information if necessary. |
| 2414 | if (length >= sizeof(int32_t) && adr.rmode_ != RelocInfo::NONE) { |
| 2415 | pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 |
| 2416 | RecordRelocInfo(adr.rmode_); |
| 2417 | pc_ += sizeof(int32_t); |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | |
| 2422 | void Assembler::emit_farith(int b1, int b2, int i) { |
| 2423 | ASSERT(is_uint8(b1) && is_uint8(b2)); // wrong opcode |
| 2424 | ASSERT(0 <= i && i < 8); // illegal stack offset |
| 2425 | EMIT(b1); |
| 2426 | EMIT(b2 + i); |
| 2427 | } |
| 2428 | |
| 2429 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2430 | void Assembler::db(uint8_t data) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2431 | EnsureSpace ensure_space(this); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2432 | EMIT(data); |
| 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | void Assembler::dd(uint32_t data) { |
| 2437 | EnsureSpace ensure_space(this); |
| 2438 | emit(data); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | |
| 2442 | void Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { |
| 2443 | ASSERT(rmode != RelocInfo::NONE); |
| 2444 | // Don't record external references unless the heap will be serialized. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2445 | if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
| 2446 | #ifdef DEBUG |
| 2447 | if (!Serializer::enabled()) { |
| 2448 | Serializer::TooLateToEnableNow(); |
| 2449 | } |
| 2450 | #endif |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2451 | if (!Serializer::enabled() && !emit_debug_code()) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2452 | return; |
| 2453 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2454 | } |
| 2455 | RelocInfo rinfo(pc_, rmode, data); |
| 2456 | reloc_info_writer.Write(&rinfo); |
| 2457 | } |
| 2458 | |
| 2459 | |
| 2460 | #ifdef GENERATED_CODE_COVERAGE |
| 2461 | static FILE* coverage_log = NULL; |
| 2462 | |
| 2463 | |
| 2464 | static void InitCoverageLog() { |
| 2465 | char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); |
| 2466 | if (file_name != NULL) { |
| 2467 | coverage_log = fopen(file_name, "aw+"); |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | |
| 2472 | void LogGeneratedCodeCoverage(const char* file_line) { |
| 2473 | const char* return_address = (&file_line)[-1]; |
| 2474 | char* push_insn = const_cast<char*>(return_address - 12); |
| 2475 | push_insn[0] = 0xeb; // Relative branch insn. |
| 2476 | push_insn[1] = 13; // Skip over coverage insns. |
| 2477 | if (coverage_log != NULL) { |
| 2478 | fprintf(coverage_log, "%s\n", file_line); |
| 2479 | fflush(coverage_log); |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | #endif |
| 2484 | |
| 2485 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2486 | |
| 2487 | #endif // V8_TARGET_ARCH_IA32 |